-
-
Notifications
You must be signed in to change notification settings - Fork 53
Add support for ASDF serialisation and deserialisation #776
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
base: main
Are you sure you want to change the base?
Conversation
[asdf] Add some documentation
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.
Initial partial review
key_value_pairs = list(zip(node["keys"], node["value"])) | ||
aligned_axes = list(node.get("aligned_axes").values()) | ||
aligned_axes = tuple(tuple(lst) for lst in aligned_axes) | ||
return NDCollection(key_value_pairs, meta=node.get("meta"), aligned_axes=aligned_axes) |
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.
Does this mean that every future metadata object needs its own schema to be saved and read?
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 yes and no, anything custom will need one.
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 also goes for unsaveable values in meta. i.e. if you put a dask array in your meta dict it will break.
|
||
return node | ||
|
||
|
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.
Got this far.
anyOf: | ||
- tag: "tag:stsci.edu:asdf/core/ndarray-1.*" | ||
- type: object | ||
- type: boolean |
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.
@DanRyanIrish Is having a single boolean as a mask something that's actually logical? We have some test fixtures which do this so I added this here.
@@ -184,11 +184,11 @@ def _sanitize_axis_value(self, axis, value, key): | |||
if isinstance(axis, numbers.Integral): | |||
axis = (axis,) | |||
if len(axis) == 0: | |||
return ValueError(axis_err_msg) | |||
raise ValueError(axis_err_msg) |
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 a fun bug to discover. I ended up with a dict with ValueErrors as the 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.
In that case, this probably deserves a bugfix changelog file.
type: object | ||
patternProperties: | ||
".*": | ||
oneOf: |
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.
Strictly speaking, I think NDCollection
can allow any type of item
, not just NDCube
and NDCubeSequence
, more like dict
. Items included in aligned_axes
must be sliceable and have enough axes for them to include the designated aligned one. But I think other items can be any object...?
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 it can, but the question is do we want it to? We are more strict in a bunch of these schemas than the code strictly requires.
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 from a personal perspective keeping it looser here would let me put dkist Dataset objects in, and maybe the same logic for some other subclasses.
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 it can, but the question is do we want it to?
Saving aside, I don't see why we would restrict it.
We are more strict in a bunch of these schemas than the code strictly requires.
Which would mean that NDCollection
can only be saved for the standard use cases, but not all possible?
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.
@braingram you got thoughts on how lax or strict we should be in the schemas? ndcube
is a little different from dkist
for example where we are often subclassed so I'm hesitant to be too strict about things in these schemas?
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.
Left a couple small comments that may require changes. Didn't look through the tests. Not an ASDF expert, but didn't see anything obvious that I didn't comment on.
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.
A few comments on the schemas.
"astropy>=5.3.0", | ||
"gwcs>=0.20", | ||
"numpy>=1.25.0", | ||
"scipy>=1.11.1", |
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 this have asdf and asdf-astropy?
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.
We should probably add an asdf extra.
Co-authored-by: Brett Graham <[email protected]>
unit: | ||
anyOf: | ||
- tag: "tag:stsci.edu:asdf/unit/unit-*" | ||
- tag: "tag:astropy.org:astropy/units/unit-1.*" |
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.
- tag: "tag:astropy.org:astropy/units/unit-1.*" | |
- tag: "tag:astropy.org:astropy/units/unit-*" |
type: object | ||
patternProperties: | ||
".*": | ||
oneOf: |
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.
oneOf: | |
anyOf: |
items: | ||
- type: string | ||
- type: object | ||
oneOf: |
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.
oneOf: | |
anyOf: |
items: | ||
type: array | ||
items: | ||
- oneOf: |
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.
- oneOf: | |
- anyOf: |
- oneOf: | ||
- type: number | ||
- type: array | ||
- oneOf: |
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.
- oneOf: | |
- anyOf: |
".*": | ||
oneOf: | ||
- tag: "tag:sunpy.org:ndcube/ndcube/ndcube-*" | ||
- tag: "tag:sunpy.org:ndcube/ndcube/ndcube_sequence-*" |
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.
- tag: "tag:sunpy.org:ndcube/ndcube/ndcube_sequence-*" | |
- tag: "tag:sunpy.org:ndcube/ndcube/ndcube_sequence-*" | |
# Allow any other objects here as we don't want to restrict what people can save | |
- {} |
This PR adds support for saving and loading the vast majority of
ndcube
objects to/from ASDF files.Thanks to @ViciousEagle03 who did the majority of this work.
MultipleTableCoordinate