use of org.orekit.files.ccsds.OEMParser 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);
}
}
Aggregations