use of org.orekit.files.general.EphemerisFile in project Orekit by CS-SI.
the class OEMWriterTest method testMultisatelliteFile.
@Test
public void testMultisatelliteFile() throws OrekitException, IOException {
final String id1 = "ID1";
final String id2 = "ID2";
StandInEphemerisFile file = new StandInEphemerisFile();
file.getSatellites().put(id1, new StandInSatelliteEphemeris(id1));
file.getSatellites().put(id2, new StandInSatelliteEphemeris(id2));
EphemerisFile ephemerisFile = (EphemerisFile) file;
String tempOEMFilePath = tempFolder.newFile("TestOEMMultisatellite-1.oem").toString();
OEMWriter writer1 = new OEMWriter();
try {
writer1.write(tempOEMFilePath, ephemerisFile);
fail("Should have thrown OrekitIllegalArgumentException due to multiple satellites");
} catch (OrekitIllegalArgumentException e) {
assertEquals(OrekitMessages.EPHEMERIS_FILE_NO_MULTI_SUPPORT, e.getSpecifier());
}
tempOEMFilePath = tempFolder.newFile("TestOEMMultisatellite-2.oem").toString();
OEMWriter writer2 = new OEMWriter(OEMWriter.DEFAULT_INTERPOLATION_METHOD, null, id1, null);
writer2.write(tempOEMFilePath, ephemerisFile);
}
use of org.orekit.files.general.EphemerisFile in project Orekit by CS-SI.
the class OEMWriterTest method testNullFile.
@Test
public void testNullFile() throws OrekitException, IOException {
final String ex = "/ccsds/OEMExample.txt";
final InputStream inEntry = getClass().getResourceAsStream(ex);
final OEMParser parser = new OEMParser().withMu(CelestialBodyFactory.getEarth().getGM()).withConventions(IERSConventions.IERS_2010);
final OEMFile oemFile = parser.parse(inEntry, "OEMExample.txt");
final EphemerisFile ephemerisFile = (EphemerisFile) oemFile;
String originator = oemFile.getOriginator();
String objectName = oemFile.getEphemeridesBlocks().get(0).getMetaData().getObjectName();
String objectID = oemFile.getEphemeridesBlocks().get(0).getMetaData().getObjectID();
String interpolationMethodString = oemFile.getEphemeridesBlocks().get(0).getInterpolationMethod();
InterpolationMethod interpolationMethod = Enum.valueOf(InterpolationMethod.class, interpolationMethodString);
OEMWriter writer = new OEMWriter(interpolationMethod, originator, objectID, objectName);
try {
writer.write((BufferedWriter) null, ephemerisFile);
fail("an exception should have been thrown");
} catch (OrekitIllegalArgumentException oiae) {
assertEquals(OrekitMessages.NULL_ARGUMENT, oiae.getSpecifier());
assertEquals("writer", oiae.getParts()[0]);
}
}
use of org.orekit.files.general.EphemerisFile in project Orekit by CS-SI.
the class OEMWriterTest method testUnisatelliteFileWithDefault.
@Test
public void testUnisatelliteFileWithDefault() throws OrekitException, IOException {
final String ex = "/ccsds/OEMExample.txt";
final InputStream inEntry = getClass().getResourceAsStream(ex);
final OEMParser parser = new OEMParser().withMu(CelestialBodyFactory.getEarth().getGM()).withConventions(IERSConventions.IERS_2010);
final OEMFile oemFile = parser.parse(inEntry, "OEMExample.txt");
final EphemerisFile ephemerisFile = (EphemerisFile) oemFile;
String tempOEMFilePath = tempFolder.newFile("TestOEMUnisatelliteWithDefault.oem").toString();
OEMWriter writer = new OEMWriter();
writer.write(tempOEMFilePath, ephemerisFile);
final OEMFile generatedOemFile = parser.parse(tempOEMFilePath);
assertEquals(oemFile.getEphemeridesBlocks().get(0).getMetaData().getObjectID(), generatedOemFile.getEphemeridesBlocks().get(0).getMetaData().getObjectID());
}
use of org.orekit.files.general.EphemerisFile in project Orekit by CS-SI.
the class OEMWriter method write.
/**
* {@inheritDoc}
*/
@Override
public void write(final Appendable writer, final EphemerisFile ephemerisFile) throws OrekitException, IOException {
if (writer == null) {
throw new OrekitIllegalArgumentException(OrekitMessages.NULL_ARGUMENT, "writer");
}
if (ephemerisFile == null) {
return;
}
final String idToProcess;
if (spaceObjectId != null) {
if (ephemerisFile.getSatellites().containsKey(spaceObjectId)) {
idToProcess = spaceObjectId;
} else {
throw new OrekitIllegalArgumentException(OrekitMessages.VALUE_NOT_FOUND, spaceObjectId, "ephemerisFile");
}
} else if (ephemerisFile.getSatellites().keySet().size() == 1) {
idToProcess = ephemerisFile.getSatellites().keySet().iterator().next();
} else {
throw new OrekitIllegalArgumentException(OrekitMessages.EPHEMERIS_FILE_NO_MULTI_SUPPORT);
}
// Get satellite and ephemeris segments to output.
final EphemerisFile.SatelliteEphemeris satEphem = ephemerisFile.getSatellites().get(idToProcess);
final List<? extends EphemerisSegment> segments = satEphem.getSegments();
if (segments.isEmpty()) {
// no data -> no output
return;
}
final EphemerisSegment firstSegment = segments.get(0);
final String objectName = this.spaceObjectName == null ? idToProcess : this.spaceObjectName;
// Only one time scale per OEM file, see Section 5.2.4.5
final TimeScale timeScale = firstSegment.getTimeScale();
// metadata that is constant for the whole OEM file
final Map<Keyword, String> metadata = new LinkedHashMap<>();
metadata.put(Keyword.TIME_SYSTEM, firstSegment.getTimeScaleString());
metadata.put(Keyword.ORIGINATOR, this.originator);
// Only one object in an OEM file, see Section 2.1
metadata.put(Keyword.OBJECT_ID, idToProcess);
metadata.put(Keyword.OBJECT_NAME, objectName);
metadata.put(Keyword.INTERPOLATION, this.interpolationMethod.toString());
final StreamingOemWriter oemWriter = new StreamingOemWriter(writer, timeScale, metadata);
oemWriter.writeHeader();
for (final EphemerisSegment segment : segments) {
// segment specific metadata
metadata.clear();
metadata.put(Keyword.CENTER_NAME, segment.getFrameCenterString());
metadata.put(Keyword.REF_FRAME, segment.getFrameString());
metadata.put(Keyword.START_TIME, segment.getStart().toString(timeScale));
metadata.put(Keyword.STOP_TIME, segment.getStop().toString(timeScale));
metadata.put(Keyword.INTERPOLATION_DEGREE, String.valueOf(segment.getInterpolationSamples() - 1));
final Segment segmentWriter = oemWriter.newSegment(null, metadata);
segmentWriter.writeMetadata();
for (final TimeStampedPVCoordinates coordinates : segment.getCoordinates()) {
segmentWriter.writeEphemerisLine(coordinates);
}
}
}
use of org.orekit.files.general.EphemerisFile in project Orekit by CS-SI.
the class OEMWriterTest method testUnfoundSpaceId.
@Test
public void testUnfoundSpaceId() throws OrekitException, IOException {
final String ex = "/ccsds/OEMExample.txt";
final InputStream inEntry = getClass().getResourceAsStream(ex);
final OEMParser parser = new OEMParser().withMu(CelestialBodyFactory.getEarth().getGM()).withConventions(IERSConventions.IERS_2010);
final OEMFile oemFile = parser.parse(inEntry, "OEMExample.txt");
final EphemerisFile ephemerisFile = (EphemerisFile) oemFile;
String badObjectId = "12345";
String interpolationMethodString = oemFile.getEphemeridesBlocks().get(0).getInterpolationMethod();
InterpolationMethod interpolationMethod = Enum.valueOf(InterpolationMethod.class, interpolationMethodString);
String tempOEMFilePath = tempFolder.newFile("TestOEMUnfoundSpaceId.oem").toString();
OEMWriter writer = new OEMWriter(interpolationMethod, null, badObjectId, null);
try {
writer.write(tempOEMFilePath, ephemerisFile);
fail("an exception should have been thrown");
} catch (OrekitIllegalArgumentException oiae) {
assertEquals(OrekitMessages.VALUE_NOT_FOUND, oiae.getSpecifier());
assertEquals(badObjectId, oiae.getParts()[0]);
}
}
Aggregations