-
-
Notifications
You must be signed in to change notification settings - Fork 128
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
Compatibility with ASDF v3 #1042
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.
Some thoughts to maybe get this working.
specutils/io/asdf/schemas/astropy.org/specutils/spectra/spectrum1d-1.0.0.yaml
Show resolved
Hide resolved
specutils/io/asdf/schemas/astropy.org/specutils/spectra/spectrum_list-1.0.0.yaml
Show resolved
Hide resolved
and move ASDF schemas a few level up. Co-authored-by: William Jamieson <[email protected]>
This comment was marked as resolved.
This comment was marked as resolved.
* Fix the schema * Fix tags to be the ones listed in the manifest * Remove uncecessary tree packing/upacking. asdf converters no longer need to return a completely valid ASDF sub-tree. ASDF will recursively parse the tree until everything is converted automatically. * Add `spectral_axis-1.0.0` tag for `SpectralAxis` objects * Add `SpectralAxisConverter` * Fix broken tests * Rename converters to reflect new ASDF language * Better organize asdf extension * Rename `spectra` module to `converters` to better describe its contents * tmp fix jsonschema bug
@@ -19,7 +18,7 @@ properties: | |||
description: | | |||
SpectralCoord that represents the spectral axis of the spectrum | |||
anyOf: | |||
- $ref: "spectral_coord-1.0.0" | |||
- tag: tag:astropy.org:specutils/spectra/spectral_axis-1.0.0 |
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.
@WilliamJamieson , can you please explain why there is a need to change $ref
to tag
here but not in spectrum_list-1.0.0.yaml
? Thanks!
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.
There is no change from a $ref to a tag here.
The $ref that I removed was a local reference which pointed at the schema that was removed as part of this PR. Meaning this schema was broken by that removal. However, the removed schema was nearly identical to a schema in asdf-coordinates-schemas (I'll address the difference below). In fact, it duplicated the URI, which means one of the two versions would override the other. Which in general can cause confusion (no schemas should have the same URI). Indeed, looking at how ASDF loaded the schemas the asdf-coordinates-schema would always be discovered first meaning the procided here would never be used (except in the test generated by the pytest-asdf plug-in). The one difference was that it included a tag within the schema, which I will discuss why this is unnecessary below.
Instead, what is going on here is I generated a new tag for an existing schema (multiple tags can point to the same schema), using the manifest. Moreover, the schema that tag points to is the one from asdf-coordinates schemas discussed above.
In point of fact, this tag is "redundant" because the difference between a tag and a $ref, assuming the tag points to the same schema as the $ref, is that in addition addition to validating the data against the schema, the tag is on that sub tree is also checked. Note that the tag is also checked if the schema lists a tag; however, doing so is strongly discouraged because it prevents reuse of the schema by new tags (for new objects which have the same representation but different behaviors like the difference between SpectralAxis and SpectralCoord). That is it prevents the ability to have multiple tags pointing at the same schema, which is exactly what I did here to avoid unnecessary duplications.
To explicitly see the redundancy, observe the anyOf statement being applied to the list of statements This means any of the listed things is acceptable. Since the spectral_axis points to the schema which is referenced by the $ref on the next line. This means that spectral_axis tags would validate against the $ref anyways. As any tagged object (regardless of the tag itself) which satisfies the $ref will pass that line. Thus the tag added is purely of documentation value (this spectral axis tag is one possibility). Really, the spectralcood tag should be added for completeness.
Note that in general, it is better to use a tag than a $ref in this situation because it makes explicit the object type(s) one expects, unless you are working with something which can accept a broad category of similar objects (in terms of how you actually write them down).
This means I would prefer to remove the $ref all together in this schema, but as this asdf extension was poorly maintained I fear existing files may fail to validate under these tighter restrictions. Meaning I did not do that (for now). Similarly, the spectral_list really ought to be of the tag for this schema not the $ref, but again the same caution is advised.
I suggest that once this PR is merged, a second PR be opened. In this new PR new versions of the existing schemas be introduced (alongside a new manifest). These schemas would have the $ref to tag changes I discussed above. This would allow for reading/validating existing files via the old manifest, but strictly enforce things on any new files as ASDF will default to writing under the latest available tags/schema.
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.
Thank you very much for the very detailed explanation!
|
because the pin will happen upstream anyway and should not be in our install pins. Other nitpicks.
assert_spectrum1d_equal(af["spectrum"], spectrum) | ||
|
||
|
||
def test_asdf_spectralaxis(tmp_path): |
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.
Note to maintainer: This no longer xfail
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1042 +/- ##
==========================================
+ Coverage 70.01% 70.14% +0.12%
==========================================
Files 64 64
Lines 4346 4401 +55
==========================================
+ Hits 3043 3087 +44
- Misses 1303 1314 +11 ☔ View full report in Codecov by Sentry. |
William has been an invaluable help to get things to really work here. Thanks, William! |
Co-authored-by: William Jamieson <[email protected]>
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 this @pllim and @WilliamJamieson, sorry for taking so long to get around to reviewing it. I was able to install and run the tests locally with dev asdf
, so that's a good sign. The only concern I have on my initial read-through of the code is with two things in Spectrum1DConverter
:
- We should round-trip the
mask
attribute as well as theuncertainty
. - I think it would be better to round-trip the
wcs
rather than thespectral_axis
, so that any spatial information in a multi-dimensionalSpectrum1D
also gets preserved (and thespectral_axis
will be reconstructed from thewcs
). I assume thatasdf
can encode both FITS WCS and GWCS, but I don't actually know that for sure off the top of my head/remember which direction dependencies go - isasdf
only applicable in the GWCS case anyway? We currently aren't actually preserving spatial information from JWST cubes right now anyway, but it's at the top of my listspecutils
of to-dos in the next couple weeks.
The SpectrumListConverter
looks like magic to me, but judging by the tests it works 😆.
The roundtrip comments -- Was it happening with old version of asdf but not anymore, or is this more like a new feature request? I don't recall that this PR would remove any existing features. |
I wasn't familiar with the old asdf code here, but it looks like these were also missing from the old code based on the diff. Still, this is a good chance to fix either of those if they are simple to add, but it could also be a follow-up PR if you don't want to implement here. |
It would not be simple for me, as I am unfamiliar with ASDF and cannot get to it in the next 2 weeks. I would prefer it to be a new ticket, especially since William has already rotated off the ASDF work and might not have time to jump in. |
Alright, I opened a followup issue for that. I'll approve and merge this. |
Thank you! |
* WIP: Compat with asdf v3 * Fix schema references and move ASDF schemas a few level up. Co-authored-by: William Jamieson <[email protected]> * TST: Stop using roundtrip_object * Fixes and cleanups (astropy#1) * Fix the schema * Fix tags to be the ones listed in the manifest * Remove uncecessary tree packing/upacking. asdf converters no longer need to return a completely valid ASDF sub-tree. ASDF will recursively parse the tree until everything is converted automatically. * Add `spectral_axis-1.0.0` tag for `SpectralAxis` objects * Add `SpectralAxisConverter` * Fix broken tests * Rename converters to reflect new ASDF language * Better organize asdf extension * Rename `spectra` module to `converters` to better describe its contents * tmp fix jsonschema bug * Move jsonschema pin to test section because the pin will happen upstream anyway and should not be in our install pins. Other nitpicks. * Simplify create_spectrum1d in testing * Undo jsonschema pinning, update asdf pin Co-authored-by: William Jamieson <[email protected]> --------- Co-authored-by: William Jamieson <[email protected]>
Fix #1011 and fix #664
cc @braingram
TODO
🐶 🐱