egemenimre / ccsds-ndm

CCSDS Navigation Data Messages Read/Write Library
GNU General Public License v3.0
35 stars 4 forks source link

Cannot write KVN file (`'Ndm' object has no attribute 'id'`) #16

Closed astrojuanlu closed 3 years ago

astrojuanlu commented 3 years ago

I tried the following:

ndm = NdmIo().from_path("omm_combined.xml")  # omm_combined.xml from the repository
NdmIo().to_file(ndm, NDMFileFormats.KVN, Path("new.kvn"))

but it failed with this error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-23-60823d5a4046> in <module>
----> 1 NdmIo().to_file(ndm, NDMFileFormats.KVN, Path("new.kvn"))

~/Projects/LSF/opensatcom/constellation-designer/.venv/lib/python3.9/site-packages/ccsds_ndm/ndm_io.py in to_file(self, ndm_obj, data_format, xml_write_file_path, **kwargs)
    158 
    159         if data_format is NDMFileFormats.KVN:
--> 160             return NdmKvnIo().to_file(ndm_obj, xml_write_file_path)
    161 
    162         if data_format is NDMFileFormats.JSON:

~/Projects/LSF/opensatcom/constellation-designer/.venv/lib/python3.9/site-packages/ccsds_ndm/ndm_kvn_io.py in to_file(self, ndm_obj, kvn_write_file_path)
    226             Path of the XML file to be written
    227         """
--> 228         kvn_write_file_path.write_text(self.to_string(ndm_obj))
    229 
    230     def to_string(self, ndm_obj):

~/Projects/LSF/opensatcom/constellation-designer/.venv/lib/python3.9/site-packages/ccsds_ndm/ndm_kvn_io.py in to_string(self, ndm_obj)
    242             given object tree as KVN string
    243         """
--> 244         out_str = [_fill_str_out_kvn(ndm_obj.id, ndm_obj.version)]
    245         self._collate_str_out("", ndm_obj, out_str)
    246 

AttributeError: 'Ndm' object has no attribute 'id'

Am I doing anything wrong?

egemenimre commented 3 years ago

Well, yes and no. This is a "combined" omm file where there are multiple omm data within a single file. Currently ccsds-ndm does not support read and write of these combined files.

As a minimum, I should add a nicer error message. Even better, I should add write support to kvn, though I'm not sure it is defined in the standard. Read support is more difficult.

That said, other OMM files (e.g. those you can download from celestrak) should work.

I cannot attend to this right now, but rest assured that I will. :)

On Mon, 14 Jun 2021, 03:42 Juan Luis Cano Rodríguez < @.***> wrote:

I tried the following:

ndm = NdmIo().from_path("omm_combined.xml") # omm_combined.xml from the repositoryNdmIo().to_file(ndm, NDMFileFormats.KVN, Path("new.kvn"))

but it failed with this error:


AttributeError Traceback (most recent call last)

in ----> 1 NdmIo().to_file(ndm, NDMFileFormats.KVN, Path("new.kvn")) ~/Projects/LSF/opensatcom/constellation-designer/.venv/lib/python3.9/site-packages/ccsds_ndm/ndm_io.py in to_file(self, ndm_obj, data_format, xml_write_file_path, **kwargs) 158 159 if data_format is NDMFileFormats.KVN: --> 160 return NdmKvnIo().to_file(ndm_obj, xml_write_file_path) 161 162 if data_format is NDMFileFormats.JSON: ~/Projects/LSF/opensatcom/constellation-designer/.venv/lib/python3.9/site-packages/ccsds_ndm/ndm_kvn_io.py in to_file(self, ndm_obj, kvn_write_file_path) 226 Path of the XML file to be written 227 """ --> 228 kvn_write_file_path.write_text(self.to_string(ndm_obj)) 229 230 def to_string(self, ndm_obj): ~/Projects/LSF/opensatcom/constellation-designer/.venv/lib/python3.9/site-packages/ccsds_ndm/ndm_kvn_io.py in to_string(self, ndm_obj) 242 given object tree as KVN string 243 """ --> 244 out_str = [_fill_str_out_kvn(ndm_obj.id, ndm_obj.version)] 245 self._collate_str_out("", ndm_obj, out_str) 246 AttributeError: 'Ndm' object has no attribute 'id' Am I doing anything wrong? — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub , or unsubscribe .
astrojuanlu commented 3 years ago

Thanks @egemenimre ! I have been able to write an OMM combined file in XML though, and reading it works fine too. I guess you mean that KVN is not supported for combined files?

egemenimre commented 3 years ago

Yes, precisely. Combined Xml is supported, but combined kvn is not. I have to check the standard to see whether you can stack multiple omms (or other types) in a single file.

My general feeling is that complicated and/or multiple (but small) data belong to xml, whereas monolithic large data (such as a satellite ephemeris) belong to kvn.

I will keep this issue open to check the standard later. As said, I should implement a minimum civility (such as a proper error message), or perhaps write support.

On Mon, 14 Jun 2021, 10:38 Juan Luis Cano Rodríguez < @.***> wrote:

Thanks @egemenimre https://github.com/egemenimre ! I have been able to write an OMM combined file in XML though, and reading it works fine too. I guess you mean that KVN is not supported for combined files?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/egemenimre/ccsds-ndm/issues/16#issuecomment-860458685, or unsubscribe https://github.com/notifications/unsubscribe-auth/AO7QEKZT4VCXI6TCFAYWWP3TSWWXJANCNFSM46UH7QYQ .

egemenimre commented 3 years ago

Eventually chaos on my end has let up a bit and I was able to look at this.

I checked the standard and couldn't find a Combined NDM in KVN format at first glance.

I have now added a proper NotImplementedError and a meaningful error message if you try to output a Combined NDM to KVN. I will issue a new version in a couple of days. Closing this for now.