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 []. 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.setCenter(BodyFacade("EARTH", earth))
oemMetaData.addComment('This file was generated for trial')

# Header
oemHeader = OdmHeader()

# Ephemeris File
eph = OrekitEphemerisFile()
satellite = eph.addSatellite(
statesList = ArrayList()
for i in range(len(States)):

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

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, can be used. It worked in StreamingCpfWriter.

from import PrintStream

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


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, 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(

Please try the following changes:

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


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?