use of org.orekit.frames.Frame 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.frames.Frame in project Orekit by CS-SI.
the class SP3ParserTest method testSP3Propagator.
@Test
public void testSP3Propagator() throws Exception {
// setup
final String ex = "/sp3/example-a-2.sp3";
final Frame frame = FramesFactory.getITRF(IERSConventions.IERS_2003, true);
final SP3Parser parser = new SP3Parser(Constants.EIGEN5C_EARTH_MU, 3, s -> frame);
final InputStream inEntry = getClass().getResourceAsStream(ex);
TimeScale gps = TimeScalesFactory.getGPS();
// action
final SP3File file = parser.parse(inEntry);
// verify
SP3Ephemeris ephemeris = file.getSatellites().get("1");
BoundedPropagator propagator = ephemeris.getPropagator();
Assert.assertEquals(propagator.getMinDate(), new AbsoluteDate(1994, 12, 17, gps));
Assert.assertEquals(propagator.getMaxDate(), new AbsoluteDate(1994, 12, 17, 23, 45, 0, gps));
SP3Coordinate expected = ephemeris.getCoordinates().get(0);
checkPVEntry(propagator.getPVCoordinates(propagator.getMinDate(), frame), expected);
expected = ephemeris.getCoordinates().get(1);
checkPVEntry(propagator.getPVCoordinates(expected.getDate(), frame), expected);
expected = ephemeris.getCoordinates().get(2);
checkPVEntry(propagator.getPVCoordinates(propagator.getMaxDate(), frame), expected);
ephemeris = file.getSatellites().get("31");
propagator = ephemeris.getPropagator();
Assert.assertEquals(propagator.getMinDate(), new AbsoluteDate(1994, 12, 17, gps));
Assert.assertEquals(propagator.getMaxDate(), new AbsoluteDate(1994, 12, 17, 23, 45, 0, gps));
expected = ephemeris.getCoordinates().get(0);
checkPVEntry(propagator.propagate(propagator.getMinDate()).getPVCoordinates(frame), expected);
expected = ephemeris.getCoordinates().get(1);
checkPVEntry(propagator.propagate(expected.getDate()).getPVCoordinates(frame), expected);
expected = ephemeris.getCoordinates().get(2);
checkPVEntry(propagator.propagate(propagator.getMaxDate()).getPVCoordinates(frame), expected);
}
use of org.orekit.frames.Frame in project Orekit by CS-SI.
the class SP3ParserTest method testWrongNumberOfEpochs.
@Test
public void testWrongNumberOfEpochs() throws IOException {
try {
final String ex = "/sp3/wrong-number-of-epochs.sp3";
final Frame frame = FramesFactory.getITRF(IERSConventions.IERS_2003, true);
final SP3Parser parser = new SP3Parser(Constants.EIGEN5C_EARTH_MU, 3, s -> frame);
final InputStream inEntry = getClass().getResourceAsStream(ex);
parser.parse(inEntry);
Assert.fail("an exception should have been thrown");
} catch (OrekitException oe) {
Assert.assertEquals(OrekitMessages.SP3_NUMBER_OF_EPOCH_MISMATCH, oe.getSpecifier());
Assert.assertEquals(2, ((Integer) oe.getParts()[0]).intValue());
Assert.assertEquals(192, ((Integer) oe.getParts()[2]).intValue());
}
}
use of org.orekit.frames.Frame in project Orekit by CS-SI.
the class SP3ParserTest method testTruncatedLine.
@Test
public void testTruncatedLine() throws IOException {
try {
final String ex = "/sp3/truncated-line.sp3";
final Frame frame = FramesFactory.getITRF(IERSConventions.IERS_2003, true);
final SP3Parser parser = new SP3Parser(Constants.EIGEN5C_EARTH_MU, 3, s -> frame);
final InputStream inEntry = getClass().getResourceAsStream(ex);
parser.parse(inEntry);
Assert.fail("an exception should have been thrown");
} catch (OrekitException oe) {
Assert.assertEquals(OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE, oe.getSpecifier());
Assert.assertEquals(27, ((Integer) oe.getParts()[0]).intValue());
}
}
use of org.orekit.frames.Frame in project Orekit by CS-SI.
the class SP3ParserTest method testMissingEOF.
@Test
public void testMissingEOF() throws IOException {
try {
final String ex = "/sp3/missing-eof.sp3";
final Frame frame = FramesFactory.getITRF(IERSConventions.IERS_2003, true);
final SP3Parser parser = new SP3Parser(Constants.EIGEN5C_EARTH_MU, 3, s -> frame);
final InputStream inEntry = getClass().getResourceAsStream(ex);
parser.parse(inEntry);
Assert.fail("an exception should have been thrown");
} catch (OrekitException oe) {
Assert.assertEquals(OrekitMessages.SP3_UNEXPECTED_END_OF_FILE, oe.getSpecifier());
Assert.assertEquals(24, ((Integer) oe.getParts()[0]).intValue());
}
}
Aggregations