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);
}
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);
}
}
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());
}
}
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));
}
}
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);
}
}
Aggregations