Search in sources :

Example 1 with EphemeridesBlock

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

the class OEMParserTest method testParseOEM2.

@Test
public void testParseOEM2() throws OrekitException, URISyntaxException {
    final String name = getClass().getResource("/ccsds/OEMExample2.txt").toURI().getPath();
    OEMParser parser = new OEMParser().withConventions(IERSConventions.IERS_2010).withSimpleEOP(true).withMu(CelestialBodyFactory.getMars().getGM()).withInternationalDesignator(1996, 2, "A").withMissionReferenceDate(new AbsoluteDate("1996-12-17T00:00:00.000", TimeScalesFactory.getUTC()));
    final OEMFile file = parser.parse(name);
    final List<String> headerComment = new ArrayList<String>();
    headerComment.add("comment");
    Assert.assertEquals(headerComment, file.getHeaderComment());
    final List<String> metadataComment = new ArrayList<String>();
    metadataComment.add("comment 1");
    metadataComment.add("comment 2");
    Assert.assertEquals(metadataComment, file.getEphemeridesBlocks().get(0).getMetaData().getComment());
    Assert.assertEquals("TOD", file.getEphemeridesBlocks().get(0).getFrameString());
    Assert.assertEquals("EME2000", file.getEphemeridesBlocks().get(1).getFrameString());
    List<EphemeridesBlock> blocks = file.getEphemeridesBlocks();
    Assert.assertEquals(2, blocks.size());
    Assert.assertTrue(blocks.get(0).getHasRefFrameEpoch());
    Assert.assertEquals(129600.331, blocks.get(0).getStartTime().durationFrom(file.getMissionReferenceDate()), 1.0e-15);
    Assert.assertEquals(941347.267, blocks.get(1).getStartTime().durationFrom(file.getMissionReferenceDate()), 1.0e-15);
}
Also used : ArrayList(java.util.ArrayList) EphemeridesBlock(org.orekit.files.ccsds.OEMFile.EphemeridesBlock) AbsoluteDate(org.orekit.time.AbsoluteDate) Test(org.junit.Test)

Example 2 with EphemeridesBlock

use of org.orekit.files.ccsds.OEMFile.EphemeridesBlock 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 3 with EphemeridesBlock

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

the class OEMParserTest method testITRFFrames.

/**
 * Check the parser can parse several ITRF frames. Test case for #361.
 *
 * @throws OrekitException on error.
 */
@Test
public void testITRFFrames() throws OrekitException {
    // setup
    Charset utf8 = StandardCharsets.UTF_8;
    IERSConventions conventions = IERSConventions.IERS_2010;
    boolean simpleEop = true;
    Frame itrf2008 = FramesFactory.getITRF(conventions, simpleEop);
    OEMParser parser = new OEMParser().withSimpleEOP(simpleEop).withConventions(conventions);
    // frames to check
    List<Pair<String, Frame>> frames = new ArrayList<>();
    frames.add(new Pair<>("ITRF-93", Predefined.ITRF_2008_TO_ITRF_93.createTransformedITRF(itrf2008, "ITRF93")));
    frames.add(new Pair<>("ITRF-97", Predefined.ITRF_2008_TO_ITRF_97.createTransformedITRF(itrf2008, "ITRF97")));
    frames.add(new Pair<>("ITRF2000", Predefined.ITRF_2008_TO_ITRF_2000.createTransformedITRF(itrf2008, "ITRF2000")));
    frames.add(new Pair<>("ITRF2005", Predefined.ITRF_2008_TO_ITRF_2005.createTransformedITRF(itrf2008, "ITRF2005")));
    frames.add(new Pair<>("ITRF2008", itrf2008));
    for (Pair<String, Frame> frame : frames) {
        final String frameName = frame.getFirst();
        InputStream pre = OEMParserTest.class.getResourceAsStream("/ccsds/OEMExample7.txt.pre");
        InputStream middle = new ByteArrayInputStream(("REF_FRAME = " + frameName).getBytes(utf8));
        InputStream post = OEMParserTest.class.getResourceAsStream("/ccsds/OEMExample7.txt.post");
        InputStream input = new SequenceInputStream(pre, new SequenceInputStream(middle, post));
        // action
        OEMFile actual = parser.parse(input);
        // verify
        EphemeridesBlock actualBlock = actual.getEphemeridesBlocks().get(0);
        Assert.assertEquals(actualBlock.getFrameString(), frameName);
        // check expected frame
        Frame actualFrame = actualBlock.getFrame();
        Frame expectedFrame = frame.getSecond();
        Assert.assertEquals(actualFrame.getName(), expectedFrame.getName());
        Assert.assertEquals(actualFrame.getTransformProvider(), expectedFrame.getTransformProvider());
    }
}
Also used : Frame(org.orekit.frames.Frame) FactoryManagedFrame(org.orekit.frames.FactoryManagedFrame) ByteArrayInputStream(java.io.ByteArrayInputStream) SequenceInputStream(java.io.SequenceInputStream) InputStream(java.io.InputStream) IERSConventions(org.orekit.utils.IERSConventions) ArrayList(java.util.ArrayList) Charset(java.nio.charset.Charset) EphemeridesBlock(org.orekit.files.ccsds.OEMFile.EphemeridesBlock) SequenceInputStream(java.io.SequenceInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) Pair(org.hipparchus.util.Pair) Test(org.junit.Test)

Example 4 with EphemeridesBlock

use of org.orekit.files.ccsds.OEMFile.EphemeridesBlock 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 5 with EphemeridesBlock

use of org.orekit.files.ccsds.OEMFile.EphemeridesBlock 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

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