Trouble with Ephemeris File (OEM) Generation

Hi. I am fairly new to Orekit and have primarily relied on the forum for support and help with my code. Thanks for being an active community!

I have a set of spacecraft states that I propagate using NumericalPropogator and want to convert this into an ephemeris file. I seem stuck with the part where I can’t write the ephemeris file with an invalid argument error when I try to use the ’ writer.write(StringWriter(), eph) ’ command. I am trying to follow the process mentioned in [https://forum.orekit.org/t/help-with-ephemerisoemwriter/3373]. I would also like to add the state covariance information in my ephemeris. Any help with this is greatly appreciated.

I have attached my code snippet below:

# Propogate
time      = [initialEpoch.shiftedBy(float(dt)) for dt in np.arange(0, 86400, 60)]
States    = [propagator.propagate(k) for k in time]

# Ephemeris Generation
# Meta Data
oemMetaData = OemMetadata(2)
oemMetaData.setObjectID(mySat.objectID)
oemMetaData.setTimeSystem(TimeSystem.UTC)
oemMetaData.setObjectName(mySat.name)
oemMetaData.setCenter(BodyFacade("EARTH", earth))
oemMetaData.setReferenceFrame(FrameFacade.map(FramesFactory.getEME2000()))
oemMetaData.addComment('This file was generated for trial')

# Header
oemHeader = OdmHeader()
oemHeader.setFormatVersion(1.0)

# Ephemeris File
eph = OrekitEphemerisFile()
satellite = eph.addSatellite(mySat.name)
statesList = ArrayList()
for i in range(len(States)):
      statesList.add(States[i])
satellite.addNewSegment(statesList)

# Write Ephemeris
writer = EphemerisOemWriter(WriterBuilder().buildOemWriter(), oemHeader, oemMetaData, FileFormat.KVN, 'OEM', 10.0, 60)
writer.write(StringWriter(), eph)
fp = open("test_oem.txt", "w")
fp.write(StringWriter().toString())
fp.close()

Hi @msv ,

Maybe there are some better solutions. Here is a candidate one.

The raw type of the first parameter of method write is final Appendable appendable, java.io.PrintStream can be used. It worked in StreamingCpfWriter.

from java.io import PrintStream

ps = PrintStream("test_oem.txt")
writer.write(ps, eph)
ps.close()

Best,
lirw

Hi, I tried this. It seems to be throwing this error for me. I’m guessing 1961-001A is the ID of the first Sat. The ephemeris of my test sat is of the ID 99999’. I changed this to ‘1961-001A’ and that didn’t help still.

Can you help me with this? Thank you.

Hi @msv

I am not very sure.
In line 132 of EphemerisOemWriter.java, the satellite ephem is get by the key metadata.getObjectID(), but name is used when the satellite ephem is added in your code.

final SatelliteEphemeris<C, S> satEphem = ephemerisFile.getSatellites().get(metadata.getObjectID());
satellite = eph.addSatellite(mySat.name)

Please try the following changes:

satellite = eph.addSatellite(oemMetaData.getObjectID())

Best,
Rowan

Setting the satellite to the Object ID instead of the Name fixed the issue, as you suggested.

satellite = eph.addSatellite(oemMetaData.getObjectID())

Thank you.

On a side note, is there an easy way to also add the covariance to this Ephemeris file given I have a list of StateCovariance? Or would this require me to add each segment individually?