-
Notifications
You must be signed in to change notification settings - Fork 16
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
MNT: space_packet_parser update #1007
MNT: space_packet_parser update #1007
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have some questions about the types that are returned as part of CcsdsPacket
....
value = ( | ||
item.derived_value if item.derived_value is not None else item.raw_value | ||
) | ||
for key, value in packet_header.items(): | ||
if key in attributes: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we still need to get value.raw_value
here... won't value be of type packets.IntParameter
instead of int
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understood the original if statement, it seems like we want to get derived value if it's available or else get raw value. Now with new changes, we get derived value if it's available or else we get raw value. so getting the value
will do what the if statement was doing before, if I understood correctly. That's how I understood at least when Gavin explain in the Slack thread. should we double check to be safe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you could just print out the type and validate that it's a python type, that's good enough for me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
packets.IntParameter
is a subclass of int
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in this case, are we good with current change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, if it's a different type, that's going to mess with some code, right? Some of my code depends on the types being accurate because of MyPy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess, if you make the change and all the tests pass, then it's probably fine... but I'm just worried about changing all the types out from underneath everyone like this, even if they're basically the same as the original types. But perhaps that is just Python offending my delicate, type-loving sensibilities again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, then I think you can change the types to IntParameter
now. But note that raw_value
is not the same as derived_value
which was being used before if it was present.
imap_processing/codice/utils.py
Outdated
@@ -88,7 +88,7 @@ def add_metadata_to_array(packet: space_packet_parser, metadata_arrays: dict) -> | |||
for key, value in packet.header.items(): | |||
metadata_arrays.setdefault(key, []).append(value.raw_value) | |||
|
|||
for key, value in packet.data.items(): | |||
for key, value in packet.user_data.items(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, are the types here correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we check with Gavin?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to get clarification from him
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't this be removed entirely because it is in packet_file_to_datasets()
now? I thought codice was using that...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. you are right Greg. I can delete this function. It's not used anymore. Sorry for including you to this PR by mistake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To your question Maxine, data type of both header
and user_data
are dict from this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But what is inside the dicts? Python types? I did go look at that code but I'm still confused about the parameter types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be a Gavin question :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
subclasses of built-in types.
An IntParameter
is simply an int
with a raw_value
attribute attached to it. You should be able to use it exactly like an int, it just has an extra attribute to help you get at the raw_value if you really want it.
else item.raw_value | ||
for item in packet.data.values() | ||
] | ||
values = [item for item in packet.user_data.values()] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
values = [item for item in packet.user_data.values()] | |
values = [item.raw_value for item in packet.user_data.values()] |
Missed that one! Sorry about that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above. I think this shouldn't be raw_value
based on the previous logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was giving me errors before because it was assigning everything as packet.IntParameter
and messing with the types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nvm, you did explain here.
imap_processing/idex/idex_l1a.py
Outdated
event_number = packet.data["IDX__SCI0EVTNUM"].derived_value | ||
if "IDX__SCI0TYPE" in packet.user_data: | ||
scitype = packet.user_data["IDX__SCI0TYPE"].raw_value | ||
event_number = packet.user_data["IDX__SCI0EVTNUM"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
event_number = packet.user_data["IDX__SCI0EVTNUM"] | |
event_number = packet.user_data["IDX__SCI0EVTNUM"].raw_value |
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The packet items are the derived value now. If there was no "derived" / "calibration" going on, then it is identical to the raw_value. So this should be left without the raw_value
attribute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is my understanding as well. That's why I removed .derived_value
where it was used before.
imap_processing/idex/idex_l1a.py
Outdated
@@ -312,9 +312,9 @@ def _set_impact_time(self, packet: space_packet_parser.parser.Packet) -> None: | |||
testing. | |||
""" | |||
# Number of seconds since epoch (nominally the launch time) | |||
seconds_since_launch = packet.data["SHCOARSE"].derived_value | |||
seconds_since_launch = packet.user_data["SHCOARSE"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need .raw_value
or .derived_value
here? I don't fully understand when the _Parameter
type is returned...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The _Parameter
is the derived value. But, SHCOARSE is never derived it is just a counter, so it is the same as the raw value too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to remove almost all .header
and .user_data
attribute accessors and rely on just the packet[lookup_value]
directly instead.
else item.raw_value | ||
for item in packet.data.values() | ||
] | ||
values = [item.raw_value for item in packet.user_data.values()] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before this was getting the derived value if it is not None. The if item.derived_value is not None else item.raw_value
is taken care of for you by space_packet_parser now.
I'm pretty sure this is the equivalent to before now:
values = [item.raw_value for item in packet.user_data.values()] | |
values = list(packet.user_data.values()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maxinelasp what do you think here? I thought same as Greg but you helped me debug some of GLOWS' error and I saw that you had to get raw_value
. Is that right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, when I printed out the types here it was all IntParameter
(etc) instead of int
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class IntParameter(int):
IntParameter
is a subclass of int
so if you type it as int
IntParameter
should be acceptable as well? Alternatively, could you type it as IntParameter
where this is needed?
item.raw_value
is very different from item
.
item.derived_value
from v4.x is the same as item
in v5.x
else item.raw_value | ||
for item in packet.data.values() | ||
] | ||
values = [item for item in packet.user_data.values()] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above. I think this shouldn't be raw_value
based on the previous logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@laspsandoval After reverting some of "
changes, I came across this error similar to what we saw couple days ago.
E ValueError: Unable to convert data to CDF format, data object cannot be of type string.
I did make changes to this file again since it seems like you did want your data in derived value. Please do revisit this in future PR if that's not what you want. It seems to involve more changes and I am worried I will mess something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I understand why it failed last time. It needed support_data
type instead of metadata
type since that's what it was. That's why I made that change in this PR.
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
3fe722f
into
IMAP-Science-Operations-Center:dev
Change Summary
closes #1008
Overview
This PR updates
space_packet_parser
to new release of space_packet_parser==5.0.0. Gavin helped fix bug and release patch version5.0.1
. This PR is large but very important to get this done early to clear roadblocks for all of us. Almost all instrument code had to change due to the new release.This new release includes tons of breaking changes. Please see its release notes for more details. It's posted on
xtce
Slack channel as well. These changes effect us most:my_parser.generator
, usemy_packet_definition.packet_generator
ParsedDataItem
class has been removed and the derived values are being returned now.The
raw_value
is stored as an attribute on the returned object. (My clarification of what this means to us) - The returned "value" defaults to raw value if there is no different derived value but if there is derived value then it uses that as default value. Therefore, we need to specificvalue.raw_value
if we do want raw value of variable that also has derived value. Please reach out to Gavin and me if you have question.bitstring
objects with native Python bytes objects. (My clarification of how this effects us) - This means that it returns<class bytes>
instead of binary string. Before it was returning binary string and many of our algorithm was written with that information. Now, we need to be aware of this new change. I tried to keep lot of your code same by adding below code blocks that converts bytes to binary string. We will need to revisit as needed. This allowed me to keep scope of this PR to only cdflib update.value.header
andvalue.data
. In new release, it has changed tovalue.user_data
instead ofvalue.data
.Updated Files
Testing