I’m trying to create a python script that is able to create a TDM file in KVN format using latest Orekit version (11.1).
To be able to create this kind of file I need to create an object of type
KvnGenerator. The problem is that it takes as an argument a class that implements Java’s
Appendable interface (classes like:
StringBuilder, etc.). Is it possible to instantiate such object in Python?
Hi @thekozak ,
Take a look at this post.. To subclass you can only do it on a Java class that’s already been wrapped by python (see the list at the link for classes that have this already).
If you don’t see exactly what you need in the list you can probably get around it another way, as a lot of the most essential Java classes are covered.
As noted above, if you want to implement the Appendable interface yourself in Python we need to create a wrapping class “PythonAppendable” for that. If you want to use java classes that already implements that interface it should be no problem initiating that object from python (should )
If you want a python wrapper for that interface, please put a ticket at the issue and I’ll include it in some upcoming update.
I went through this pretty recently - fairly simple to get an appendable for writing out CCSDS stuff. Here is how I did it for an OEM (should be similar for a TDM).
TL:DR: use a
# Imports for this to work
from java.lang import StringBuilder
from org.orekit.files.ccsds.ndm import WriterBuilder
# At this point I already have build the following:
# oem_header -> Header from org.orekit.files.ccsds.section
# oem_segment -> OemSegment
writer = WriterBuilder().buildOemWriter() # TDM writer for you
oem_output_java_string = StringBuilder()
kvn_gen = KvnGenerator(oem_output_java_string, 1, 'ephemeris', 0)
# Write header and segment
writer.writeSegmentContent(kvn_gen, 2.0, oem_segment)
# Write the file
with open(ephem_output_path, 'w') as fp:
That output will be a string in the KVN format with
\n delimiters. So if you wanted it back in a python list or whatnot, could just do a string split.