Search in sources :

Example 1 with OemSatelliteEphemeris

use of org.orekit.files.ccsds.OEMFile.OemSatelliteEphemeris in project Orekit by CS-SI.

the class StreamingOemWriterTest method testWriteOemStepHandler.

/**
 * Check reading and writing an OEM both with and without using the step handler
 * methods.
 *
 * @throws Exception on error.
 */
@Test
public void testWriteOemStepHandler() throws Exception {
    // setup
    TimeScale utc = TimeScalesFactory.getUTC();
    List<String> files = Arrays.asList("/ccsds/OEMExample5.txt", "/ccsds/OEMExample4.txt");
    for (String ex : files) {
        InputStream inEntry = getClass().getResourceAsStream(ex);
        OEMParser parser = new OEMParser().withMu(CelestialBodyFactory.getEarth().getGM()).withConventions(IERSConventions.IERS_2010);
        OEMFile oemFile = parser.parse(inEntry, "OEMExample.txt");
        OemSatelliteEphemeris satellite = oemFile.getSatellites().values().iterator().next();
        EphemeridesBlock ephemerisBlock = satellite.getSegments().get(0);
        Frame frame = ephemerisBlock.getFrame();
        double step = ephemerisBlock.getStopTime().durationFrom(ephemerisBlock.getStartTime()) / (ephemerisBlock.getCoordinates().size() - 1);
        String originator = oemFile.getOriginator();
        EphemeridesBlock block = oemFile.getEphemeridesBlocks().get(0);
        String objectName = block.getMetaData().getObjectName();
        String objectID = block.getMetaData().getObjectID();
        Map<Keyword, String> metadata = new LinkedHashMap<>();
        metadata.put(Keyword.ORIGINATOR, originator);
        metadata.put(Keyword.OBJECT_NAME, "will be overwritten");
        metadata.put(Keyword.OBJECT_ID, objectID);
        Map<Keyword, String> segmentData = new LinkedHashMap<>();
        segmentData.put(Keyword.OBJECT_NAME, objectName);
        // check using the Propagator / StepHandler interface
        StringBuilder buffer = new StringBuilder();
        StreamingOemWriter writer = new StreamingOemWriter(buffer, utc, metadata);
        writer.writeHeader();
        Segment segment = writer.newSegment(frame, segmentData);
        BoundedPropagator propagator = satellite.getPropagator();
        propagator.setMasterMode(step, segment);
        propagator.propagate(propagator.getMinDate(), propagator.getMaxDate());
        // verify
        BufferedReader reader = new BufferedReader(new StringReader(buffer.toString()));
        OEMFile generatedOemFile = parser.parse(reader, "buffer");
        compareOemFiles(oemFile, generatedOemFile, 1e-7, 1e-7);
        // check calling the methods directly
        buffer = new StringBuilder();
        writer = new StreamingOemWriter(buffer, utc, metadata);
        writer.writeHeader();
        // set start and stop date manually
        segmentData.put(Keyword.START_TIME, StreamingOemWriter.dateToString(block.getStart().getComponents(utc)));
        segmentData.put(Keyword.STOP_TIME, StreamingOemWriter.dateToString(block.getStop().getComponents(utc)));
        segment = writer.newSegment(frame, segmentData);
        segment.writeMetadata();
        for (TimeStampedPVCoordinates coordinate : block.getCoordinates()) {
            segment.writeEphemerisLine(coordinate);
        }
        // verify
        reader = new BufferedReader(new StringReader(buffer.toString()));
        generatedOemFile = parser.parse(reader, "buffer");
        compareOemFiles(oemFile, generatedOemFile, 1e-7, 1e-7);
    }
}
Also used : Frame(org.orekit.frames.Frame) InputStream(java.io.InputStream) EphemeridesBlock(org.orekit.files.ccsds.OEMFile.EphemeridesBlock) TimeStampedPVCoordinates(org.orekit.utils.TimeStampedPVCoordinates) TimeScale(org.orekit.time.TimeScale) Segment(org.orekit.files.ccsds.StreamingOemWriter.Segment) LinkedHashMap(java.util.LinkedHashMap) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) OemSatelliteEphemeris(org.orekit.files.ccsds.OEMFile.OemSatelliteEphemeris) BoundedPropagator(org.orekit.propagation.BoundedPropagator) Test(org.junit.Test)

Example 2 with OemSatelliteEphemeris

use of org.orekit.files.ccsds.OEMFile.OemSatelliteEphemeris in project Orekit by CS-SI.

the class OEMParserTest method testParseOemMissingOptionalData.

@Test
public void testParseOemMissingOptionalData() throws OrekitException, IOException {
    final String ex = "/ccsds/OEMExample6.txt";
    final InputStream inEntry = getClass().getResourceAsStream(ex);
    final OEMParser parser = new OEMParser().withMu(CelestialBodyFactory.getEarth().getGM()).withConventions(IERSConventions.IERS_2010);
    final OEMFile file = parser.parse(inEntry);
    Assert.assertEquals(CcsdsTimeScale.UTC, file.getEphemeridesBlocks().get(0).getMetaData().getTimeSystem());
    Assert.assertEquals("MARS GLOBAL SURVEYOR", file.getEphemeridesBlocks().get(0).getMetaData().getObjectName());
    Assert.assertEquals("1996-062A", file.getEphemeridesBlocks().get(0).getMetaData().getObjectID());
    Assert.assertEquals(1, file.getSatellites().size());
    Assert.assertEquals(true, file.getSatellites().containsKey("1996-062A"));
    Assert.assertEquals(false, file.getSatellites().containsKey("MARS GLOBAL SURVEYOR"));
    Assert.assertEquals(1, file.getSatellites().size());
    Assert.assertEquals("1996-062A", file.getSatellites().values().iterator().next().getId());
    Assert.assertEquals(new AbsoluteDate("2002-12-18T12:00:00.331", TimeScalesFactory.getUTC()), file.getEphemeridesBlocks().get(0).getStartTime());
    OemSatelliteEphemeris satellite = file.getSatellites().get("1996-062A");
    Assert.assertEquals(satellite.getId(), "1996-062A");
    Assert.assertEquals(satellite.getMu(), file.getMuUsed(), 0);
    EphemeridesBlock actualBlock = satellite.getSegments().get(0);
    Assert.assertEquals(actualBlock.getMu(), file.getMuUsed(), 0);
    FactoryManagedFrame eme2000 = FramesFactory.getEME2000();
    Frame actualFrame = actualBlock.getFrame();
    AbsoluteDate actualStart = satellite.getStart();
    Transform actualTransform = eme2000.getTransformTo(actualFrame, actualStart);
    CelestialBody mars = CelestialBodyFactory.getMars();
    TimeStampedPVCoordinates marsPV = mars.getPVCoordinates(actualStart, eme2000);
    Assert.assertEquals(actualTransform.getTranslation(), marsPV.getPosition());
    Assert.assertEquals(actualTransform.getVelocity(), marsPV.getVelocity());
    Assert.assertEquals(actualTransform.getAcceleration(), marsPV.getAcceleration());
    Assert.assertEquals(Rotation.distance(actualTransform.getRotation(), Rotation.IDENTITY), 0.0, 0.0);
    Assert.assertEquals(actualTransform.getRotationRate(), Vector3D.ZERO);
    Assert.assertEquals(actualTransform.getRotationAcceleration(), Vector3D.ZERO);
    Assert.assertEquals(actualFrame.getName(), "Mars/EME2000");
    Assert.assertEquals(actualBlock.getFrameString(), "EME2000");
    Assert.assertEquals(actualBlock.getTimeScaleString(), "UTC");
    Assert.assertEquals(actualBlock.getTimeScale(), TimeScalesFactory.getUTC());
    Assert.assertEquals(actualBlock.getAvailableDerivatives(), CartesianDerivativesFilter.USE_PV);
    Assert.assertEquals(satellite.getSegments().get(0).getStartTime(), actualStart);
    Assert.assertEquals(satellite.getSegments().get(2).getStopTime(), satellite.getStop());
    final BoundedPropagator propagator = satellite.getPropagator();
    Assert.assertEquals(propagator.getMinDate(), satellite.getStart());
    Assert.assertEquals(propagator.getMinDate(), satellite.getSegments().get(0).getStart());
    Assert.assertEquals(propagator.getMaxDate(), satellite.getStop());
    Assert.assertEquals(propagator.getMaxDate(), satellite.getSegments().get(2).getStop());
    final List<TimeStampedPVCoordinates> dataLines = new ArrayList<>();
    for (EphemeridesBlock block : file.getEphemeridesBlocks()) {
        for (TimeStampedPVCoordinates dataLine : block.getEphemeridesDataLines()) {
            if (dataLine.getDate().compareTo(satellite.getStart()) >= 0) {
                dataLines.add(dataLine);
            }
        }
    }
    final int ulps = 12;
    for (TimeStampedPVCoordinates coord : dataLines) {
        Assert.assertThat(propagator.getPVCoordinates(coord.getDate(), actualFrame), OrekitMatchers.pvCloseTo(coord, ulps));
        Assert.assertThat(propagator.propagate(coord.getDate()).getPVCoordinates(), OrekitMatchers.pvCloseTo(coord, ulps));
    }
}
Also used : Frame(org.orekit.frames.Frame) FactoryManagedFrame(org.orekit.frames.FactoryManagedFrame) ByteArrayInputStream(java.io.ByteArrayInputStream) SequenceInputStream(java.io.SequenceInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) EphemeridesBlock(org.orekit.files.ccsds.OEMFile.EphemeridesBlock) FactoryManagedFrame(org.orekit.frames.FactoryManagedFrame) TimeStampedPVCoordinates(org.orekit.utils.TimeStampedPVCoordinates) AbsoluteDate(org.orekit.time.AbsoluteDate) CelestialBody(org.orekit.bodies.CelestialBody) OemSatelliteEphemeris(org.orekit.files.ccsds.OEMFile.OemSatelliteEphemeris) Transform(org.orekit.frames.Transform) BoundedPropagator(org.orekit.propagation.BoundedPropagator) Test(org.junit.Test)

Example 3 with OemSatelliteEphemeris

use of org.orekit.files.ccsds.OEMFile.OemSatelliteEphemeris in project Orekit by CS-SI.

the class OEMParserTest method testParseOEM1OrbitFile.

@Test
public void testParseOEM1OrbitFile() throws OrekitException, IOException {
    final String ex = "/ccsds/OEMExample3.txt";
    final InputStream inEntry = getClass().getResourceAsStream(ex);
    final OEMParser parser = new OEMParser().withMu(CelestialBodyFactory.getEarth().getGM()).withConventions(IERSConventions.IERS_2010);
    final OEMFile file = parser.parse(inEntry);
    Assert.assertEquals(CcsdsTimeScale.UTC, file.getEphemeridesBlocks().get(0).getMetaData().getTimeSystem());
    Assert.assertEquals("MARS GLOBAL SURVEYOR", file.getEphemeridesBlocks().get(0).getMetaData().getObjectName());
    Assert.assertEquals("1996-062A", file.getEphemeridesBlocks().get(0).getMetaData().getObjectID());
    Assert.assertEquals(1, file.getSatellites().size());
    Assert.assertEquals(true, file.getSatellites().containsKey("1996-062A"));
    Assert.assertEquals(false, file.getSatellites().containsKey("MARS GLOBAL SURVEYOR"));
    Assert.assertEquals(1, file.getSatellites().size());
    Assert.assertEquals("1996-062A", file.getSatellites().values().iterator().next().getId());
    Assert.assertEquals(new AbsoluteDate("1996-12-18T12:00:00.331", TimeScalesFactory.getUTC()), file.getEphemeridesBlocks().get(0).getStartTime());
    final OemSatelliteEphemeris satellite = file.getSatellites().get("1996-062A");
    Assert.assertEquals(satellite.getId(), "1996-062A");
    Assert.assertEquals(satellite.getMu(), file.getMuUsed(), 0);
    final EphemeridesBlock actualBlock = satellite.getSegments().get(0);
    Assert.assertEquals(actualBlock.getMu(), file.getMuUsed(), 0);
    Assert.assertEquals(actualBlock.getFrameString(), "EME2000");
    Assert.assertEquals(actualBlock.getFrameCenterString(), "MARS BARYCENTER");
    Assert.assertEquals(actualBlock.getMetaData().getHasCreatableBody(), false);
    // Frame not creatable since it's center can't be created.
    try {
        actualBlock.getFrame();
        Assert.fail("Expected Exception");
    } catch (OrekitException e) {
        Assert.assertEquals(e.getSpecifier(), OrekitMessages.NO_DATA_LOADED_FOR_CELESTIAL_BODY);
    }
    Assert.assertEquals(actualBlock.getTimeScaleString(), "UTC");
    Assert.assertEquals(actualBlock.getTimeScale(), TimeScalesFactory.getUTC());
    Assert.assertEquals(actualBlock.getInterpolationSamples(), 3);
    Assert.assertEquals(actualBlock.getAvailableDerivatives(), CartesianDerivativesFilter.USE_PV);
    // propagator can't be created since frame can't be created
    try {
        satellite.getPropagator();
        Assert.fail("Expected Exception");
    } catch (OrekitException e) {
        Assert.assertEquals(e.getSpecifier(), OrekitMessages.NO_DATA_LOADED_FOR_CELESTIAL_BODY);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SequenceInputStream(java.io.SequenceInputStream) InputStream(java.io.InputStream) OemSatelliteEphemeris(org.orekit.files.ccsds.OEMFile.OemSatelliteEphemeris) EphemeridesBlock(org.orekit.files.ccsds.OEMFile.EphemeridesBlock) OrekitException(org.orekit.errors.OrekitException) AbsoluteDate(org.orekit.time.AbsoluteDate) Test(org.junit.Test)

Aggregations

InputStream (java.io.InputStream)3 Test (org.junit.Test)3 EphemeridesBlock (org.orekit.files.ccsds.OEMFile.EphemeridesBlock)3 OemSatelliteEphemeris (org.orekit.files.ccsds.OEMFile.OemSatelliteEphemeris)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 SequenceInputStream (java.io.SequenceInputStream)2 Frame (org.orekit.frames.Frame)2 BoundedPropagator (org.orekit.propagation.BoundedPropagator)2 AbsoluteDate (org.orekit.time.AbsoluteDate)2 TimeStampedPVCoordinates (org.orekit.utils.TimeStampedPVCoordinates)2 BufferedReader (java.io.BufferedReader)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 CelestialBody (org.orekit.bodies.CelestialBody)1 OrekitException (org.orekit.errors.OrekitException)1 Segment (org.orekit.files.ccsds.StreamingOemWriter.Segment)1 FactoryManagedFrame (org.orekit.frames.FactoryManagedFrame)1 Transform (org.orekit.frames.Transform)1 TimeScale (org.orekit.time.TimeScale)1