Help with EphemerisOemWriter

Hi,
I am trying to use the EphemerisOemWriter to generate a ephemeris file similar to what STK produces with CCSDS Ephemeris output.
The inspiration is taken from:

Everything goes well until writer.write. I think I am unable to create the ephemerisFile: [write_C,write_S] input to the second argument in the write method for EphemerisOemWriter.

A section of the code:

    states = ArrayList()
    for tt in t:
        states.add(predict.propagate(tt))

    oem_metadata = OemMetadata(2)
    oem_metadata.setObjectID("DUMMY")
    oem_metadata.setTimeSystem(TimeSystem.UTC)
    oem_metadata.setObjectName("DUMMY")
    oem_metadata.setCenter(BodyFacade("EARTH", CelestialBodyFactory.getCelestialBodies().getEarth()))
    oem_metadata.setReferenceFrame(FrameFacade.map(FramesFactory.getEME2000()))
    oem_header = OdmHeader()
    oem_header.setFormatVersion(1.0)

    ep = OrekitEphemerisFile()
    satellite = ep.addSatellite("DUMMY")
    satellite.addNewSegment(states)

    print("\n****************************************************\n")
    print(ep.getSatellites().get("DUMMY").getSegments().get(0).getCoordinates())
    print("\n****************************************************\n")
    
    
    fp = open("test_oem.txt", "w")
    writer = EphemerisOemWriter(WriterBuilder().buildOemWriter(), oem_header, oem_metadata,  FileFormat.KVN, "dummy", Constants.JULIAN_DAY, 60)
    satellites = ep.getSatellites().get("DUMMY")
    segment = satellites.getSegments().get(0)
    coord = segment.getCoordinates().get(0)
    writer.write("testfile", [coord, segment])

The output:

[{2026-06-21T20:00:00.000, P(762243.7723760772, -3994957.6029958026, -5786906.597939492), V(5311.266351069576, -4003.3962487160857, 3472.301267576075), A(-0.8559780304198243, 4.486142612074137, 6.515575635249745)}, {2026-06-21T20:01:00.000, P(1079164.5256378597, -4226925.822429085, -5566983.209371222), V(5249.193444930876, -3726.248296151372, 3856.03423165803), A(-1.2124854075165339, 4.749067886339631, 6.271178748524097)}, {2026-06-21T20:02:00.000, P(1391721.6864763675, -4441803.058305083, -5324491.257142647), V(5165.858435317981, -3433.8854686544387, 4224.3307639308505), A(-1.5644763778080193, 4.993127064927353, 6.001187783326421)}, {2026-06-21T20:03:00.000, P(1698648.5152050823, -4638711.00784675, -5060402.404864325), V(5061.575132440182, -3127.471098098501, 4575.6850700336245), A(-1.9105251495120668, 5.217286152946639, 5.706615562906133)}, {2026-06-21T20:04:00.000, P(1998699.6600736252, -4816842.987050543, -4775776.776928879), V(4936.742523399186, -2808.2284257925553, 4908.655308455248), A(-2.2492192618008158, 5.420583034947355, 5.388580628962805)}]

********************************

Traceback (most recent call last):
  File "test_propagate.py", line 247, in <module>
    ephemeris(data)
  File "test_propagate.py", line 230, in ephemeris
    writer.write("testfile", [coord, segment])
orekit.InvalidArgsError: (<class 'org.orekit.files.ccsds.ndm.odm.oem.EphemerisOemWriter'>, 'write', ('testfile', [<TimeStampedPVCoordinates: {2026-06-21T20:00:00.000, P(762243.7723760772, -3994957.6029958026, -5786906.597939492), V(5311.266351069576, -4003.3962487160857, 3472.301267576075), A(-0.8559780304198243, 4.486142612074137, 6.515575635249745)}>, <OrekitEphemerisFile$OrekitEphemerisSegment: org.orekit.files.general.OrekitEphemerisFile$OrekitEphemerisSegment@3b46dd8>]))

I have tried every combination of input I can think of. I have not used python interfaces before. I am probably struggeling with a combination of python and orekit understanding.
Could someone guide me in the right direction?

  • Tommy

Hi @tommysa,

Welcome to the forum!

Looking at the Python signature of the “write” method, it’s waiting for an EphemerisFile as second argument.

So you probably have to use your object ep which is an OrekitEphemerisFile and cast it to EphemerisFile as the second argument of the write function.

Hope this helps,
Maxime

Thanks for the answer.
I found no way to cast in python, but it turned out the the second parameter was not the problem. Or it could not be used the way I tried in the posted code. But just like all the examples online, just use the OrekitEphemerisFile object.

The solution was in the first parameter. Use StringWriter like this:

oem_string = StringWriter()
writer = EphemerisOemWriter(WriterBuilder().buildOemWriter(), oem_header, oem_metadata,  
       FileFormat.KVN, "dummy",  Constants.JULIAN_DAY, 60)
writer.write(oem_string, ep)
fp = open("test_oem.txt", "w")
fp.write(oem_string.toString())
fp.close()

I found this code here https://forum.orekit.org/t/setinterpolationdegree-in-oem-template/1916

-Tommy

1 Like