Search in sources :

Example 1 with EphemerisSegment

use of org.orekit.files.general.EphemerisFile.EphemerisSegment 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 2 with EphemerisSegment

use of org.orekit.files.general.EphemerisFile.EphemerisSegment in project Orekit by CS-SI.

the class OrekitEphemerisFileTest method testWritingToOEM.

@Test
public void testWritingToOEM() throws OrekitException, IOException {
    final double muTolerance = 1e-12;
    final double positionTolerance = 1e-8;
    final double velocityTolerance = 1e-8;
    final String satId = "SATELLITE1";
    final double sma = 10000000;
    final double inc = Math.toRadians(45.0);
    final double ecc = 0.001;
    final double raan = 0.0;
    final double pa = 0.0;
    final double ta = 0.0;
    final AbsoluteDate date = new AbsoluteDate();
    final Frame frame = FramesFactory.getGCRF();
    final CelestialBody body = CelestialBodyFactory.getEarth();
    final double mu = body.getGM();
    KeplerianOrbit initialOrbit = new KeplerianOrbit(sma, ecc, inc, pa, raan, ta, PositionAngle.TRUE, frame, date, mu);
    KeplerianPropagator propagator = new KeplerianPropagator(initialOrbit);
    final double propagationDurationSeconds = 86400.0;
    final double stepSizeSeconds = 60.0;
    List<SpacecraftState> states = new ArrayList<SpacecraftState>();
    for (double dt = 0.0; dt < propagationDurationSeconds; dt += stepSizeSeconds) {
        states.add(propagator.propagate(date.shiftedBy(dt)));
    }
    OrekitEphemerisFile ephemerisFile = new OrekitEphemerisFile();
    OrekitSatelliteEphemeris satellite = ephemerisFile.addSatellite(satId);
    satellite.addNewSegment(states);
    String tempOemFile = Files.createTempFile("OrekitEphemerisFileTest", ".oem").toString();
    new OEMWriter().write(tempOemFile, ephemerisFile);
    EphemerisFile ephemerisFromFile = new OEMParser().parse(tempOemFile);
    Files.delete(Paths.get(tempOemFile));
    EphemerisSegment segment = ephemerisFromFile.getSatellites().get(satId).getSegments().get(0);
    assertEquals(states.get(0).getDate(), segment.getStart());
    assertEquals(states.get(states.size() - 1).getDate(), segment.getStop());
    assertEquals(states.size(), segment.getCoordinates().size());
    assertEquals(frame, segment.getFrame());
    assertEquals(body.getName().toUpperCase(), segment.getFrameCenterString());
    assertEquals(body.getGM(), segment.getMu(), muTolerance);
    for (int i = 0; i < states.size(); i++) {
        TimeStampedPVCoordinates expected = states.get(i).getPVCoordinates();
        TimeStampedPVCoordinates actual = segment.getCoordinates().get(i);
        assertEquals(expected.getDate(), actual.getDate());
        assertEquals(0.0, Vector3D.distance(expected.getPosition(), actual.getPosition()), positionTolerance);
        assertEquals(0.0, Vector3D.distance(expected.getVelocity(), actual.getVelocity()), velocityTolerance);
    }
    // test ingested ephemeris generates access intervals
    final OneAxisEllipsoid parentShape = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, Constants.WGS84_EARTH_FLATTENING, FramesFactory.getITRF(IERSConventions.IERS_2010, true));
    final double latitude = 0.0;
    final double longitude = 0.0;
    final double altitude = 0.0;
    final GeodeticPoint point = new GeodeticPoint(latitude, longitude, altitude);
    final TopocentricFrame topo = new TopocentricFrame(parentShape, point, "testPoint1");
    final ElevationDetector elevationDetector = new ElevationDetector(topo);
    final EphemerisSegmentPropagator ephemerisSegmentPropagator = new EphemerisSegmentPropagator(segment);
    final EventsLogger lookupLogger = new EventsLogger();
    ephemerisSegmentPropagator.addEventDetector(lookupLogger.monitorDetector(elevationDetector));
    final EventsLogger referenceLogger = new EventsLogger();
    propagator.clearEventsDetectors();
    propagator.addEventDetector(referenceLogger.monitorDetector(elevationDetector));
    propagator.propagate(segment.getStart(), segment.getStop());
    ephemerisSegmentPropagator.propagate(segment.getStart(), segment.getStop());
    final double dateEpsilon = 1.0e-9;
    assertTrue(referenceLogger.getLoggedEvents().size() > 0);
    assertEquals(referenceLogger.getLoggedEvents().size(), lookupLogger.getLoggedEvents().size());
    for (int i = 0; i < referenceLogger.getLoggedEvents().size(); i++) {
        LoggedEvent reference = referenceLogger.getLoggedEvents().get(i);
        LoggedEvent actual = lookupLogger.getLoggedEvents().get(i);
        assertEquals(0.0, FastMath.abs(reference.getState().getDate().durationFrom(actual.getState().getDate())), dateEpsilon);
    }
    final Propagator embeddedPropagator = segment.getPropagator();
    final EventsLogger embeddedPropLogger = new EventsLogger();
    embeddedPropagator.addEventDetector(embeddedPropLogger.monitorDetector(elevationDetector));
    embeddedPropagator.propagate(segment.getStart(), segment.getStop());
    assertEquals(referenceLogger.getLoggedEvents().size(), embeddedPropLogger.getLoggedEvents().size());
    for (int i = 0; i < referenceLogger.getLoggedEvents().size(); i++) {
        LoggedEvent reference = referenceLogger.getLoggedEvents().get(i);
        LoggedEvent actual = embeddedPropLogger.getLoggedEvents().get(i);
        assertEquals(0.0, FastMath.abs(reference.getState().getDate().durationFrom(actual.getState().getDate())), dateEpsilon);
    }
    final List<SpacecraftState> readInStates = new ArrayList<SpacecraftState>();
    segment.getCoordinates().forEach(c -> {
        try {
            readInStates.add(new SpacecraftState(new CartesianOrbit(c, frame, mu)));
        } catch (IllegalArgumentException | OrekitException e) {
            fail(e.getLocalizedMessage());
        }
    });
    final int interpolationPoints = 5;
    Ephemeris directEphemProp = new Ephemeris(readInStates, interpolationPoints);
    final EventsLogger directEphemPropLogger = new EventsLogger();
    directEphemProp.addEventDetector(directEphemPropLogger.monitorDetector(elevationDetector));
    directEphemProp.propagate(segment.getStart(), segment.getStop());
    assertEquals(referenceLogger.getLoggedEvents().size(), directEphemPropLogger.getLoggedEvents().size());
    for (int i = 0; i < referenceLogger.getLoggedEvents().size(); i++) {
        LoggedEvent reference = referenceLogger.getLoggedEvents().get(i);
        LoggedEvent actual = directEphemPropLogger.getLoggedEvents().get(i);
        assertEquals(0.0, FastMath.abs(reference.getState().getDate().durationFrom(actual.getState().getDate())), dateEpsilon);
    }
}
Also used : Frame(org.orekit.frames.Frame) TopocentricFrame(org.orekit.frames.TopocentricFrame) CartesianOrbit(org.orekit.orbits.CartesianOrbit) OneAxisEllipsoid(org.orekit.bodies.OneAxisEllipsoid) LoggedEvent(org.orekit.propagation.events.EventsLogger.LoggedEvent) ElevationDetector(org.orekit.propagation.events.ElevationDetector) ArrayList(java.util.ArrayList) TopocentricFrame(org.orekit.frames.TopocentricFrame) TimeStampedPVCoordinates(org.orekit.utils.TimeStampedPVCoordinates) AbsoluteDate(org.orekit.time.AbsoluteDate) SpacecraftState(org.orekit.propagation.SpacecraftState) OrekitSatelliteEphemeris(org.orekit.files.general.OrekitEphemerisFile.OrekitSatelliteEphemeris) EphemerisSegment(org.orekit.files.general.EphemerisFile.EphemerisSegment) Propagator(org.orekit.propagation.Propagator) KeplerianPropagator(org.orekit.propagation.analytical.KeplerianPropagator) CelestialBody(org.orekit.bodies.CelestialBody) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) OrekitException(org.orekit.errors.OrekitException) GeodeticPoint(org.orekit.bodies.GeodeticPoint) OEMParser(org.orekit.files.ccsds.OEMParser) GeodeticPoint(org.orekit.bodies.GeodeticPoint) KeplerianPropagator(org.orekit.propagation.analytical.KeplerianPropagator) OEMWriter(org.orekit.files.ccsds.OEMWriter) EventsLogger(org.orekit.propagation.events.EventsLogger) OrekitSatelliteEphemeris(org.orekit.files.general.OrekitEphemerisFile.OrekitSatelliteEphemeris) Ephemeris(org.orekit.propagation.analytical.Ephemeris) Test(org.junit.Test)

Example 3 with EphemerisSegment

use of org.orekit.files.general.EphemerisFile.EphemerisSegment in project Orekit by CS-SI.

the class EphemerisSegmentPropagatorTest method testPropagator.

/**
 * Check {@link EphemerisSegmentPropagator} and {@link EphemerisSegment#getPropagator()}.
 *
 * @throws Exception on error.
 */
@Test
public void testPropagator() throws Exception {
    // setup
    AbsoluteDate start = AbsoluteDate.J2000_EPOCH, end = start.shiftedBy(60);
    Frame frame = FramesFactory.getEME2000();
    List<TimeStampedPVCoordinates> coordinates = Arrays.asList(new TimeStampedPVCoordinates(start, new Vector3D(6778137, 0, 0), new Vector3D(0, 7.5e3, 0)), new TimeStampedPVCoordinates(start.shiftedBy(30), new Vector3D(6778137 + 1, 0, 0), new Vector3D(0, 7.5e3, 0)), new TimeStampedPVCoordinates(end, new Vector3D(6778137 + 3, 0, 0), new Vector3D(0, 7.5e3, 0)));
    EphemerisSegment ephemeris = new EphemerisSegment() {

        @Override
        public double getMu() {
            return Constants.EGM96_EARTH_MU;
        }

        @Override
        public String getFrameCenterString() {
            return null;
        }

        @Override
        public String getFrameString() {
            return null;
        }

        @Override
        public Frame getFrame() throws OrekitException {
            return frame;
        }

        @Override
        public String getTimeScaleString() {
            return null;
        }

        @Override
        public TimeScale getTimeScale() throws OrekitException {
            return null;
        }

        @Override
        public int getInterpolationSamples() {
            return 2;
        }

        @Override
        public CartesianDerivativesFilter getAvailableDerivatives() {
            return CartesianDerivativesFilter.USE_P;
        }

        @Override
        public List<TimeStampedPVCoordinates> getCoordinates() {
            return coordinates;
        }

        @Override
        public AbsoluteDate getStart() {
            return start;
        }

        @Override
        public AbsoluteDate getStop() {
            return end;
        }
    };
    // action
    BoundedPropagator propagator = ephemeris.getPropagator();
    // verify
    Assert.assertThat(propagator.getMinDate(), CoreMatchers.is(start));
    Assert.assertThat(propagator.getMaxDate(), CoreMatchers.is(end));
    Assert.assertThat(propagator.getFrame(), CoreMatchers.is(frame));
    int ulps = 0;
    PVCoordinates expected = new PVCoordinates(new Vector3D(6778137, 0, 0), new Vector3D(1.0 / 30, 0, 0));
    Assert.assertThat(propagator.propagate(start).getPVCoordinates(), OrekitMatchers.pvCloseTo(expected, ulps));
    Assert.assertThat(propagator.getPVCoordinates(start, frame), OrekitMatchers.pvCloseTo(expected, ulps));
    expected = new PVCoordinates(new Vector3D(6778137 + 2, 0, 0), new Vector3D(2 / 30.0, 0, 0));
    Assert.assertThat(propagator.propagate(start.shiftedBy(45)).getPVCoordinates(), OrekitMatchers.pvCloseTo(expected, ulps));
    Assert.assertThat(propagator.getPVCoordinates(start.shiftedBy(45), frame), OrekitMatchers.pvCloseTo(expected, ulps));
    expected = new PVCoordinates(new Vector3D(6778137 + 3, 0, 0), new Vector3D(2 / 30.0, 0, 0));
    Assert.assertThat(propagator.propagate(end).getPVCoordinates(), OrekitMatchers.pvCloseTo(expected, ulps));
    Assert.assertThat(propagator.getPVCoordinates(end, frame), OrekitMatchers.pvCloseTo(expected, ulps));
    // check reset state is prohibited
    SpacecraftState ic = propagator.propagate(start);
    try {
        propagator.resetInitialState(ic);
        Assert.fail("Expected Exception");
    } catch (OrekitException e) {
    // expected
    }
}
Also used : SpacecraftState(org.orekit.propagation.SpacecraftState) Frame(org.orekit.frames.Frame) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) EphemerisSegment(org.orekit.files.general.EphemerisFile.EphemerisSegment) TimeStampedPVCoordinates(org.orekit.utils.TimeStampedPVCoordinates) PVCoordinates(org.orekit.utils.PVCoordinates) OrekitException(org.orekit.errors.OrekitException) TimeStampedPVCoordinates(org.orekit.utils.TimeStampedPVCoordinates) BoundedPropagator(org.orekit.propagation.BoundedPropagator) AbsoluteDate(org.orekit.time.AbsoluteDate) Test(org.junit.Test)

Aggregations

EphemerisSegment (org.orekit.files.general.EphemerisFile.EphemerisSegment)3 TimeStampedPVCoordinates (org.orekit.utils.TimeStampedPVCoordinates)3 Test (org.junit.Test)2 OrekitException (org.orekit.errors.OrekitException)2 Frame (org.orekit.frames.Frame)2 SpacecraftState (org.orekit.propagation.SpacecraftState)2 AbsoluteDate (org.orekit.time.AbsoluteDate)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Vector3D (org.hipparchus.geometry.euclidean.threed.Vector3D)1 CelestialBody (org.orekit.bodies.CelestialBody)1 GeodeticPoint (org.orekit.bodies.GeodeticPoint)1 OneAxisEllipsoid (org.orekit.bodies.OneAxisEllipsoid)1 OrekitIllegalArgumentException (org.orekit.errors.OrekitIllegalArgumentException)1 OEMParser (org.orekit.files.ccsds.OEMParser)1 OEMWriter (org.orekit.files.ccsds.OEMWriter)1 Segment (org.orekit.files.ccsds.StreamingOemWriter.Segment)1 EphemerisFile (org.orekit.files.general.EphemerisFile)1 OrekitSatelliteEphemeris (org.orekit.files.general.OrekitEphemerisFile.OrekitSatelliteEphemeris)1 TopocentricFrame (org.orekit.frames.TopocentricFrame)1