-
-
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
ndcube/asdf/resources/schemas/multipletablecoordinate-1.0.0.yaml
Outdated
Show resolved
Hide resolved
ndcube/asdf/resources/schemas/quantitytablecoordinate-1.0.0.yaml
Outdated
Show resolved
Hide resolved
ndcube/asdf/resources/schemas/skycoordtablecoordinate-1.0.0.yaml
Outdated
Show resolved
Hide resolved
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.
Thanks for pushing this forward. Overall I think it looks great. I left a few comments:
- 1 possible bug in the collection converter (which might instead be a schema bug where
aligned_axes
should be required) - a few comments about schema required items vs values filled in by converter
I mostly did not review the test changes.
>>> with asdf.AsdfFile(tree=my_tree) as f: # doctest: +SKIP | ||
... f.write_to("somefile.asdf") # doctest: +SKIP |
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.
>>> with asdf.AsdfFile(tree=my_tree) as f: # doctest: +SKIP | |
... f.write_to("somefile.asdf") # doctest: +SKIP | |
>>> asdf.AsdfFile(tree=my_tree).write_to("somefile.asdf"): # doctest: +SKIP |
No need for the with
here since the AsdfFile
instance isn't holding onto a file.
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.
Minor nitpick but maybe order the tags alphabetically? That way it's easier to:
- find a tag definition
- match tag definitions to other things (like listed schema files)
ndcube: | ||
tag: "tag:sunpy.org:ndcube/ndcube-1.*" | ||
|
||
required: [ndcube] |
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 looks like the converter always writes dropped_tables
should this be required?
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 converter is wrong
def from_yaml_tree(self, node, tag, ctx): | ||
from ndcube.ndcollection import NDCollection | ||
|
||
aligned_axes = list(node.get("aligned_axes").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.
aligned_axes = list(node.get("aligned_axes").values()) | |
aligned_axes = list(node.get("aligned_axes").values()) |
Won't this raise an exception if "aligned_axes" is missing?
physical_types: | ||
type: array | ||
|
||
required: ["table", "unit"] |
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 looks like the converter always writes "mesh". Should this be required or perhaps "mesh" conditionally written (since the from_yaml_tree
uses get
to access it).
world_order: | ||
type: array | ||
|
||
required: [wcs] |
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.
Similar to the other comments, the converter appears to always write "pixel_order" and "world_order". Should these be required?
offset: | ||
tag: "tag:stsci.edu:asdf/core/ndarray-1.*" | ||
|
||
required: [wcs] |
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.
Similar to other comments. Should factor
and offset
be required?
physical_types: | ||
type: array | ||
|
||
required: ["table"] |
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.
Similar to other comments, should mesh
be required?
reference_time: | ||
tag: "tag:stsci.edu:asdf/time/time-*" | ||
|
||
required: ["table"] |
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.
Similar to the other comments, should reference_time
be required?
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.
More review to follow
************************* | ||
|
||
:ref:`asdf` is an extensible format for validating and saving complex scientific data along with its metadata. | ||
`ndcube` provides schemas and converters for all the ND objects (`~ndcube.NDCube`, `~ndcube.NDCubeSequence` and `~ndcube.NDCollection`) as well as for various WCS and table objects required by them. |
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.
`ndcube` provides schemas and converters for all the ND objects (`~ndcube.NDCube`, `~ndcube.NDCubeSequence` and `~ndcube.NDCollection`) as well as for various WCS and table objects required by them. | |
`ndcube` provides schemas and converters for all the ND objects (`~ndcube.NDCube`, `~ndcube.NDCubeSequence`, `~ndcube.NDCollection` and `~ndcube,NDMeta`) as well as for various WCS and table objects required by them. |
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 didn't see any problems that jumped out. So as long as the tests pass, and those more qualified to review this also approve, I'm happy to see this merged
types = ["ndcube.wcs.wrappers.compound_wcs.CompoundLowLevelWCS"] | ||
|
||
def from_yaml_tree(self, node, tag, ctx): | ||
from ndcube.wcs.wrappers import CompoundLowLevelWCS |
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.
Why are imports inside from_yaml...
methods through PR?
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.
Because these files are imported at import asdf
time so by moving them into these methods these imports are only triggered when actually reading a file, i.e. if you read a non-ndcube asdf these imports are never run.
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 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.
This PR is now ready for review, to save every possible ndcube object there's still two PRs to asdf-astropy which need to be merged, some tests are skipped here for that. However, this is now ready for review.
MultipleTableCoordinate
SlicedLowLevelWCS
support all the wrappers: Fix two WCS bugs astropy/asdf-astropy#276