Search in sources :

Example 6 with OrekitIllegalArgumentException

use of org.orekit.errors.OrekitIllegalArgumentException in project Orekit by CS-SI.

the class OEMWriter method write.

/**
 * {@inheritDoc}
 */
@Override
public void write(final Appendable writer, final EphemerisFile ephemerisFile) throws OrekitException, IOException {
    if (writer == null) {
        throw new OrekitIllegalArgumentException(OrekitMessages.NULL_ARGUMENT, "writer");
    }
    if (ephemerisFile == null) {
        return;
    }
    final String idToProcess;
    if (spaceObjectId != null) {
        if (ephemerisFile.getSatellites().containsKey(spaceObjectId)) {
            idToProcess = spaceObjectId;
        } else {
            throw new OrekitIllegalArgumentException(OrekitMessages.VALUE_NOT_FOUND, spaceObjectId, "ephemerisFile");
        }
    } else if (ephemerisFile.getSatellites().keySet().size() == 1) {
        idToProcess = ephemerisFile.getSatellites().keySet().iterator().next();
    } else {
        throw new OrekitIllegalArgumentException(OrekitMessages.EPHEMERIS_FILE_NO_MULTI_SUPPORT);
    }
    // Get satellite and ephemeris segments to output.
    final EphemerisFile.SatelliteEphemeris satEphem = ephemerisFile.getSatellites().get(idToProcess);
    final List<? extends EphemerisSegment> segments = satEphem.getSegments();
    if (segments.isEmpty()) {
        // no data -> no output
        return;
    }
    final EphemerisSegment firstSegment = segments.get(0);
    final String objectName = this.spaceObjectName == null ? idToProcess : this.spaceObjectName;
    // Only one time scale per OEM file, see Section 5.2.4.5
    final TimeScale timeScale = firstSegment.getTimeScale();
    // metadata that is constant for the whole OEM file
    final Map<Keyword, String> metadata = new LinkedHashMap<>();
    metadata.put(Keyword.TIME_SYSTEM, firstSegment.getTimeScaleString());
    metadata.put(Keyword.ORIGINATOR, this.originator);
    // Only one object in an OEM file, see Section 2.1
    metadata.put(Keyword.OBJECT_ID, idToProcess);
    metadata.put(Keyword.OBJECT_NAME, objectName);
    metadata.put(Keyword.INTERPOLATION, this.interpolationMethod.toString());
    final StreamingOemWriter oemWriter = new StreamingOemWriter(writer, timeScale, metadata);
    oemWriter.writeHeader();
    for (final EphemerisSegment segment : segments) {
        // segment specific metadata
        metadata.clear();
        metadata.put(Keyword.CENTER_NAME, segment.getFrameCenterString());
        metadata.put(Keyword.REF_FRAME, segment.getFrameString());
        metadata.put(Keyword.START_TIME, segment.getStart().toString(timeScale));
        metadata.put(Keyword.STOP_TIME, segment.getStop().toString(timeScale));
        metadata.put(Keyword.INTERPOLATION_DEGREE, String.valueOf(segment.getInterpolationSamples() - 1));
        final Segment segmentWriter = oemWriter.newSegment(null, metadata);
        segmentWriter.writeMetadata();
        for (final TimeStampedPVCoordinates coordinates : segment.getCoordinates()) {
            segmentWriter.writeEphemerisLine(coordinates);
        }
    }
}
Also used : TimeStampedPVCoordinates(org.orekit.utils.TimeStampedPVCoordinates) TimeScale(org.orekit.time.TimeScale) EphemerisSegment(org.orekit.files.general.EphemerisFile.EphemerisSegment) Segment(org.orekit.files.ccsds.StreamingOemWriter.Segment) OrekitIllegalArgumentException(org.orekit.errors.OrekitIllegalArgumentException) LinkedHashMap(java.util.LinkedHashMap) EphemerisSegment(org.orekit.files.general.EphemerisFile.EphemerisSegment) EphemerisFile(org.orekit.files.general.EphemerisFile)

Example 7 with OrekitIllegalArgumentException

use of org.orekit.errors.OrekitIllegalArgumentException in project Orekit by CS-SI.

the class TimeComponents method parseTime.

/**
 * Parse a string in ISO-8601 format to build a time.
 * <p>The supported formats are:
 * <ul>
 *   <li>basic and extended format local time: hhmmss, hh:mm:ss (with optional decimals in seconds)</li>
 *   <li>optional UTC time: hhmmssZ, hh:mm:ssZ</li>
 *   <li>optional signed hours UTC offset: hhmmss+HH, hhmmss-HH, hh:mm:ss+HH, hh:mm:ss-HH</li>
 *   <li>optional signed basic hours and minutes UTC offset: hhmmss+HHMM, hhmmss-HHMM, hh:mm:ss+HHMM, hh:mm:ss-HHMM</li>
 *   <li>optional signed extended hours and minutes UTC offset: hhmmss+HH:MM, hhmmss-HH:MM, hh:mm:ss+HH:MM, hh:mm:ss-HH:MM</li>
 * </ul>
 *
 * <p> As shown by the list above, only the complete representations defined in section 4.2
 * of ISO-8601 standard are supported, neither expended representations nor representations
 * with reduced accuracy are supported.
 *
 * @param string string to parse
 * @return a parsed time
 * @exception IllegalArgumentException if string cannot be parsed
 */
public static TimeComponents parseTime(final String string) {
    // is the date a calendar date ?
    final Matcher timeMatcher = ISO8601_FORMATS.matcher(string);
    if (timeMatcher.matches()) {
        final int hour = Integer.parseInt(timeMatcher.group(1));
        final int minute = Integer.parseInt(timeMatcher.group(2));
        final double second = timeMatcher.group(3) == null ? 0.0 : Double.parseDouble(timeMatcher.group(3).replace(',', '.'));
        final String offset = timeMatcher.group(4);
        final int minutesFromUTC;
        if (offset == null) {
            // no offset from UTC is given
            minutesFromUTC = 0;
        } else {
            // we need to parse an offset from UTC
            // the sign is mandatory and the ':' separator is optional
            // so we can have offsets given as -06:00 or +0100
            final int sign = offset.codePointAt(0) == '-' ? -1 : +1;
            final int hourOffset = Integer.parseInt(offset.substring(1, 3));
            final int minutesOffset = offset.length() <= 3 ? 0 : Integer.parseInt(offset.substring(offset.length() - 2));
            minutesFromUTC = sign * (minutesOffset + 60 * hourOffset);
        }
        return new TimeComponents(hour, minute, second, minutesFromUTC);
    }
    throw new OrekitIllegalArgumentException(OrekitMessages.NON_EXISTENT_TIME, string);
}
Also used : Matcher(java.util.regex.Matcher) OrekitIllegalArgumentException(org.orekit.errors.OrekitIllegalArgumentException)

Example 8 with OrekitIllegalArgumentException

use of org.orekit.errors.OrekitIllegalArgumentException in project Orekit by CS-SI.

the class DateComponents method parseDate.

/**
 * Parse a string in ISO-8601 format to build a date.
 * <p>The supported formats are:
 * <ul>
 *   <li>basic format calendar date: YYYYMMDD</li>
 *   <li>extended format calendar date: YYYY-MM-DD</li>
 *   <li>basic format ordinal date: YYYYDDD</li>
 *   <li>extended format ordinal date: YYYY-DDD</li>
 *   <li>basic format week date: YYYYWwwD</li>
 *   <li>extended format week date: YYYY-Www-D</li>
 * </ul>
 *
 * <p> As shown by the list above, only the complete representations defined in section 4.1
 * of ISO-8601 standard are supported, neither expended representations nor representations
 * with reduced accuracy are supported.
 *
 * <p>
 * Parsing a single integer as a julian day is <em>not</em> supported as it may be ambiguous
 * with either the basic format calendar date or the basic format ordinal date depending
 * on the number of digits.
 * </p>
 * @param string string to parse
 * @return a parsed date
 * @exception IllegalArgumentException if string cannot be parsed
 */
public static DateComponents parseDate(final String string) {
    // is the date a calendar date ?
    final Matcher calendarMatcher = CALENDAR_FORMAT.matcher(string);
    if (calendarMatcher.matches()) {
        return new DateComponents(Integer.parseInt(calendarMatcher.group(1)), Integer.parseInt(calendarMatcher.group(2)), Integer.parseInt(calendarMatcher.group(3)));
    }
    // is the date an ordinal date ?
    final Matcher ordinalMatcher = ORDINAL_FORMAT.matcher(string);
    if (ordinalMatcher.matches()) {
        return new DateComponents(Integer.parseInt(ordinalMatcher.group(1)), Integer.parseInt(ordinalMatcher.group(2)));
    }
    // is the date a week date ?
    final Matcher weekMatcher = WEEK_FORMAT.matcher(string);
    if (weekMatcher.matches()) {
        return createFromWeekComponents(Integer.parseInt(weekMatcher.group(1)), Integer.parseInt(weekMatcher.group(2)), Integer.parseInt(weekMatcher.group(3)));
    }
    throw new OrekitIllegalArgumentException(OrekitMessages.NON_EXISTENT_DATE, string);
}
Also used : Matcher(java.util.regex.Matcher) OrekitIllegalArgumentException(org.orekit.errors.OrekitIllegalArgumentException)

Example 9 with OrekitIllegalArgumentException

use of org.orekit.errors.OrekitIllegalArgumentException in project Orekit by CS-SI.

the class OEMWriterTest method testUnfoundSpaceId.

@Test
public void testUnfoundSpaceId() throws OrekitException, IOException {
    final String ex = "/ccsds/OEMExample.txt";
    final InputStream inEntry = getClass().getResourceAsStream(ex);
    final OEMParser parser = new OEMParser().withMu(CelestialBodyFactory.getEarth().getGM()).withConventions(IERSConventions.IERS_2010);
    final OEMFile oemFile = parser.parse(inEntry, "OEMExample.txt");
    final EphemerisFile ephemerisFile = (EphemerisFile) oemFile;
    String badObjectId = "12345";
    String interpolationMethodString = oemFile.getEphemeridesBlocks().get(0).getInterpolationMethod();
    InterpolationMethod interpolationMethod = Enum.valueOf(InterpolationMethod.class, interpolationMethodString);
    String tempOEMFilePath = tempFolder.newFile("TestOEMUnfoundSpaceId.oem").toString();
    OEMWriter writer = new OEMWriter(interpolationMethod, null, badObjectId, null);
    try {
        writer.write(tempOEMFilePath, ephemerisFile);
        fail("an exception should have been thrown");
    } catch (OrekitIllegalArgumentException oiae) {
        assertEquals(OrekitMessages.VALUE_NOT_FOUND, oiae.getSpecifier());
        assertEquals(badObjectId, oiae.getParts()[0]);
    }
}
Also used : InterpolationMethod(org.orekit.files.ccsds.OEMWriter.InterpolationMethod) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) EphemerisFile(org.orekit.files.general.EphemerisFile) OrekitIllegalArgumentException(org.orekit.errors.OrekitIllegalArgumentException) Test(org.junit.Test)

Example 10 with OrekitIllegalArgumentException

use of org.orekit.errors.OrekitIllegalArgumentException in project Orekit by CS-SI.

the class IonoModifierTest method testRangeIonoModifier.

@Test
public void testRangeIonoModifier() throws OrekitException {
    Context context = EstimationTestUtils.eccentricContext("regular-data:potential:tides");
    final NumericalPropagatorBuilder propagatorBuilder = context.createBuilder(OrbitType.KEPLERIAN, PositionAngle.TRUE, true, 1.0e-6, 60.0, 0.001);
    // create perfect range measurements
    for (final GroundStation station : context.stations) {
        station.getEastOffsetDriver().setSelected(true);
        station.getNorthOffsetDriver().setSelected(true);
        station.getZenithOffsetDriver().setSelected(true);
    }
    final Propagator propagator = EstimationTestUtils.createPropagator(context.initialOrbit, propagatorBuilder);
    final List<ObservedMeasurement<?>> measurements = EstimationTestUtils.createMeasurements(propagator, new RangeMeasurementCreator(context), 1.0, 3.0, 300.0);
    propagator.setSlaveMode();
    final RangeIonosphericDelayModifier modifier = new RangeIonosphericDelayModifier(model);
    for (final ObservedMeasurement<?> measurement : measurements) {
        final AbsoluteDate date = measurement.getDate();
        final SpacecraftState refstate = propagator.propagate(date);
        Range range = (Range) measurement;
        EstimatedMeasurement<Range> evalNoMod = range.estimate(12, 17, new SpacecraftState[] { refstate });
        Assert.assertEquals(12, evalNoMod.getIteration());
        Assert.assertEquals(17, evalNoMod.getCount());
        // add modifier
        range.addModifier(modifier);
        boolean found = false;
        for (final EstimationModifier<Range> existing : range.getModifiers()) {
            found = found || existing == modifier;
        }
        Assert.assertTrue(found);
        // 
        EstimatedMeasurement<Range> eval = range.estimate(0, 0, new SpacecraftState[] { refstate });
        Assert.assertEquals(evalNoMod.getStatus(), eval.getStatus());
        eval.setStatus(EstimatedMeasurement.Status.REJECTED);
        Assert.assertEquals(EstimatedMeasurement.Status.REJECTED, eval.getStatus());
        eval.setStatus(evalNoMod.getStatus());
        try {
            eval.getParameterDerivatives(new ParameterDriver("extra", 0, 1, -1, +1));
            Assert.fail("an exception should have been thrown");
        } catch (OrekitIllegalArgumentException oiae) {
            Assert.assertEquals(OrekitMessages.UNSUPPORTED_PARAMETER_NAME, oiae.getSpecifier());
        }
        final double diffMeters = eval.getEstimatedValue()[0] - evalNoMod.getEstimatedValue()[0];
        // TODO: check threshold
        Assert.assertEquals(0.0, diffMeters, 30.0);
    }
}
Also used : Context(org.orekit.estimation.Context) GroundStation(org.orekit.estimation.measurements.GroundStation) TurnAroundRangeIonosphericDelayModifier(org.orekit.estimation.measurements.modifiers.TurnAroundRangeIonosphericDelayModifier) RangeIonosphericDelayModifier(org.orekit.estimation.measurements.modifiers.RangeIonosphericDelayModifier) TurnAroundRange(org.orekit.estimation.measurements.TurnAroundRange) Range(org.orekit.estimation.measurements.Range) ParameterDriver(org.orekit.utils.ParameterDriver) AbsoluteDate(org.orekit.time.AbsoluteDate) OrekitIllegalArgumentException(org.orekit.errors.OrekitIllegalArgumentException) SpacecraftState(org.orekit.propagation.SpacecraftState) NumericalPropagatorBuilder(org.orekit.propagation.conversion.NumericalPropagatorBuilder) Propagator(org.orekit.propagation.Propagator) RangeMeasurementCreator(org.orekit.estimation.measurements.RangeMeasurementCreator) TurnAroundRangeMeasurementCreator(org.orekit.estimation.measurements.TurnAroundRangeMeasurementCreator) ObservedMeasurement(org.orekit.estimation.measurements.ObservedMeasurement) Test(org.junit.Test)

Aggregations

OrekitIllegalArgumentException (org.orekit.errors.OrekitIllegalArgumentException)11 Test (org.junit.Test)6 EphemerisFile (org.orekit.files.general.EphemerisFile)4 InputStream (java.io.InputStream)3 AbsoluteDate (org.orekit.time.AbsoluteDate)3 FileInputStream (java.io.FileInputStream)2 Matcher (java.util.regex.Matcher)2 Context (org.orekit.estimation.Context)2 GroundStation (org.orekit.estimation.measurements.GroundStation)2 ObservedMeasurement (org.orekit.estimation.measurements.ObservedMeasurement)2 TurnAroundRange (org.orekit.estimation.measurements.TurnAroundRange)2 TurnAroundRangeMeasurementCreator (org.orekit.estimation.measurements.TurnAroundRangeMeasurementCreator)2 TurnAroundRangeIonosphericDelayModifier (org.orekit.estimation.measurements.modifiers.TurnAroundRangeIonosphericDelayModifier)2 InterpolationMethod (org.orekit.files.ccsds.OEMWriter.InterpolationMethod)2 Propagator (org.orekit.propagation.Propagator)2 SpacecraftState (org.orekit.propagation.SpacecraftState)2 NumericalPropagatorBuilder (org.orekit.propagation.conversion.NumericalPropagatorBuilder)2 ParameterDriver (org.orekit.utils.ParameterDriver)2 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1