Search in sources :

Example 1 with OEMWriter

use of org.orekit.files.ccsds.OEMWriter 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)

Aggregations

ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 CelestialBody (org.orekit.bodies.CelestialBody)1 GeodeticPoint (org.orekit.bodies.GeodeticPoint)1 OneAxisEllipsoid (org.orekit.bodies.OneAxisEllipsoid)1 OrekitException (org.orekit.errors.OrekitException)1 OEMParser (org.orekit.files.ccsds.OEMParser)1 OEMWriter (org.orekit.files.ccsds.OEMWriter)1 EphemerisSegment (org.orekit.files.general.EphemerisFile.EphemerisSegment)1 OrekitSatelliteEphemeris (org.orekit.files.general.OrekitEphemerisFile.OrekitSatelliteEphemeris)1 Frame (org.orekit.frames.Frame)1 TopocentricFrame (org.orekit.frames.TopocentricFrame)1 CartesianOrbit (org.orekit.orbits.CartesianOrbit)1 KeplerianOrbit (org.orekit.orbits.KeplerianOrbit)1 Propagator (org.orekit.propagation.Propagator)1 SpacecraftState (org.orekit.propagation.SpacecraftState)1 Ephemeris (org.orekit.propagation.analytical.Ephemeris)1 KeplerianPropagator (org.orekit.propagation.analytical.KeplerianPropagator)1 ElevationDetector (org.orekit.propagation.events.ElevationDetector)1 EventsLogger (org.orekit.propagation.events.EventsLogger)1