Invalid argument error when writing ephemeris to file

I am getting the following error when trying to write an ephemeris file to disk:

Traceback (most recent call last):
  File "/Users/guest/Documents/script.py", line 464, in <module>
    main()
  File "/Users/guest/Documents/script.py", line 450, in main
    pv_bls_df, pv_iod_df, residual_df = sat.propagate_orbit()
  File "/Users/guest/Documents/script.py", line 349, in propagate_orbit
    writer.write(oem_file_path, oerFile)
orekit.InvalidArgsError: (<class 'org.orekit.files.ccsds.ndm.odm.oem.EphemerisWriter'>, 'write', ('/Users/guest/Documents/test.oem', <OrekitEphemerisFile: org.orekit.files.general.OrekitEphemerisFile@727b3b0>))

Here is the code:

oerFile = OrekitEphemerisFile()
        satellite = oerFile.addSatellite(self.name)
        #add segments to satellite
        satellite.addNewSegment(states)
        output_dir = os.getcwd()
        oem_file_path = os.path.join(output_dir, "test" + ".oem")
        #setup oem metadata
        oemMetadata = OemMetadata(2)
        oemMetadata.setObjectID(self.name)
        oemMetadata.setObjectName(self.name)
        oemMetadata.setCenter(BodyFacade("EARTH", CelestialBodyFactory.getCelestialBodies().getEarth()))
        oemMetadata.setReferenceFrame(FrameFacade.map(eme2000))
        oemMetadata.setStartTime(ephemeris_start)
        oemMetadata.setStopTime(ephemeris_end)
        oemMetadata.setTimeSystem(TimeSystem.UTC)

        #write ephemeris file
        writer = EphemerisWriter(WriterBuilder().buildOemWriter(),None, oemMetadata, FileFormat.KVN, "oem_writer", 60);
        writer.write(oem_file_path, oerFile)

Any help is appreciated.

Hi @tru3anomaly,

I don’t know if you have to cast a parameter or if this is an error in the code. But, I don’t see any error.

To help you, please find an example of OEM writing just here: setInterpolationDegree in OEM Template - #3 by Kozak

Best regards,
Bryan

I quickly compare your code with the above example. You set the file header to None. I think you must define one:

header = Header(3.0) 
header.setCreationDate(date) 
... 
EphemerisWriter(WriterBuilder().buildOemWriter(), header, oemMetadata, FileFormat.KVN, "oem_writer", 60);

The date parameter is an AbsoluteDate.

Bryan

Thanks Bryan, unfortunately that was not it. Could it be the file path? It says that it should be a Appendable java object but not sure if that translates to python correctly because python strings are technically not appendable if I remember correctly.

Just tried it with Windows and got the same issue so it does not seem to be operating system dependent (I was using a Mac).

Figured it out, you must use the StringWriter() java class for the writer in Python. Now it runs but there is no file produced…