Skip to content

Conversation

Cadair
Copy link
Member

@Cadair Cadair commented Nov 6, 2024

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.


@Cadair Cadair mentioned this pull request Jul 2, 2025
4 tasks
Copy link

@braingram braingram left a 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.

Comment on lines 40 to 41
>>> with asdf.AsdfFile(tree=my_tree) as f: # doctest: +SKIP
... f.write_to("somefile.asdf") # doctest: +SKIP

Choose a reason for hiding this comment

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

Suggested change
>>> 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.

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]

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?

Copy link
Member Author

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())

Choose a reason for hiding this comment

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

Suggested change
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"]

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]

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]

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"]

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"]

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?

Copy link
Member

@DanRyanIrish DanRyanIrish left a 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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
`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.

Copy link
Member

@DanRyanIrish DanRyanIrish left a 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
Copy link
Member

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?

Copy link
Member Author

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.

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants