Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

packet_file_to_datasets *NOT* in IDEX #743

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions imap_processing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,11 @@ def packet_file_to_datasets(
packet definition, the ``derived_value`` will be the converted value.
The dimension of the dataset will be the time field in J2000 nanoseconds.

Note: While this is a general function intended to work for all
instruments, this cannot be used for IDEX due to the complex nature of
the xml file. IDEX will continue to use PacketParser and RawDustEvents
found in idex_l1.py.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be either a Notes section in numpydoc, https://numpydoc.readthedocs.io/en/latest/format.html#notes or a .. note:: rst callout.
https://sublime-and-sphinx-guide.readthedocs.io/en/latest/notes_warnings.html

Some minor wordsmithing, where I'd avoid saying what we'll do with the specific classes in idex_l1.py in case someone refactors that later and forgets to update this docstring.

Suggested change
Note: While this is a general function intended to work for all
instruments, this cannot be used for IDEX due to the complex nature of
the xml file. IDEX will continue to use PacketParser and RawDustEvents
found in idex_l1.py.
.. note::
This function only handles packet definitions with the same variable structure across
all packets with the same ApId. For example, this cannot be used for IDEX due to the
conditional XML structure defined for their science packet.

One other thought that occurred to me is whether we could catch this and print out a nice warning message here so others don't also hit this roadblock. Something like creating a new dictionary that keeps track of apid: variables. Around l365 below I think something like this might work?

            if apid not in data_dict:
                # This is the first packet for this APID
                data_dict[apid] = collections.defaultdict(list)
                datatype_mapping[apid] = dict()
                variable_mapping[apid] = packet.data.keys()
             if packet.data.keys() != apid_variable_mapping[apid]:
                 raise ValueError(f"Cannot parse apid {apid} which has different variables defined across the same packet type")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet! Yeah, I agree with you. I changed the comment to a "Notes" section in the doc-string.

I didn't end up implementing the dimension check in this PR (I just don't quite understand the code yet, and I feel like I should before I add it and test it). Would you like me to write another issue ticket?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that'd be great. I think the code above is close to working, so if you copy that over to another issue and work from that it might be a good thing. Additionally, add a test trying to parse IDEX and showing that your ValueError is raised with pytest.raises(ValueError, match="Cannot prase apid").


Parameters
----------
packet_file : str
Expand Down
Loading