-
-
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
Refactor gwcs_from_array to provide ND GWCS in ND flux case #1211
Conversation
…tral axis provided
…ve more control, rather than in astropy ndarithmetic
…think was unneeded and was causing errors
…s Spectrum even in 1D case
…, fix order of WCS
Bump min asdf Bump min astropy Bump min scipy Bump min asdf-astropy
a9d0923
to
55cbb3e
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## v2.0-dev #1211 +/- ##
============================================
- Coverage 86.99% 86.94% -0.06%
============================================
Files 63 63
Lines 4637 4687 +50
============================================
+ Hits 4034 4075 +41
- Misses 603 612 +9 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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 a few minor comments but after taking a first look I realized one major concern/confusion so I'm going to start there and give another more thorough review depending on the outcome.
Specifically, it looks to me like the outcome of this change is essentially breaking the conceptual "link" between the spectral_axis
and the wcs
. What I mean is that in my head the way Spectrum1D is supposed to work is exactly as shown in this diagram:
https://specutils.readthedocs.io/en/latest/_images/specutils_classes_diagrams.png
in that diagram, the spectral_axis is basically just exactly what you'd get if you do spectrum.wcs.pixel_to_world(all_of_the_pixels_in_the_spectrum)
. (I know that's not literally how it's implemented but in my mind the API "contract" is that this is so) This would seem to break that link because now the dimensionality of wcs
and spectral_axis
are different. Is that the intent? If so, I have to ask: why not instead use SpectrumCollection
for use cases where that's what's needed?
(observer to target: | ||
radial_velocity=0.0 km / s | ||
redshift=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.
Why was this removed? Is it an incidental thing you noticed at the time (no prob if so) or a result of this change somehow?
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 don't recall, I'll double check.
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 this was due to creating the new collapsed Spectrum
with self.spectral_axis
rather than self.wcs
now, and is actually probably more correct than the previously printed out repr
, which was replacing None
values for these quantities with 0
in the process of collapsing (implying information we actually don't have).
# We now raise an error if the spectra aren't on the same spectral axis | ||
with pytest.raises(ValueError, match="Spectral axis of both operands must match"): | ||
spec3 = simulated_spectra.s1_um_mJy_e1 + simulated_spectra.s1_AA_mJy_e3 # noqa |
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'm confused by this - I would have thought this failed previously - i.e. the shapes did not change. So is this also an incidental improvement that comes from these changes that's not strictly about the gwcs?
If so, that's good, but should be in the changelog as an API change I think (since users might encounter this as an error where they didn't before)
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.
Agreed that this should be in the changelog too. Previously spectrum arithmetic didn't care if the spectral axis values were different, only that the shape of the arrays were the same. It now checks to see that the values actually match as well.
This is already not the case for things like JWST cubes, which provide a full 3D GWCS solution that encodes both the spectral axis and spatial coordinates. The issue is that My goal here is to bring the case where we generate a dummy GWCS for a spectrum created with a |
@eteq I'm going to go ahead and merge this into the v2.0-dev branch so I can release an RC for people to start testing 2.0. I'll start a discussion issue where people can post concerns about 2.0 to address before an actual release, we can continue the discussion of this here or take it to that issue if my replies didn't alleviate your concerns. |
…1211) * Working on constructing N dimensional GWCS for ND flux with only spectral axis provided * Get forward transform working for ND case * Convert other operator to Spectrum if needed in specutils where we have more control, rather than in astropy ndarithmetic * Don't pass extra arg to ndarithmetic * Use dimensionless instead of pix, remove unit conversion code that I think was unneeded and was causing errors * Fix two tests for multidimensional GWCS, remove debugging print * Working on debugging SpectrumCollection * Check for Spectrum specifically before arithmetic * Remove incorrect index from spectrum collection slice, cast operand as Spectrum even in 1D case * Don't pass multi-d WCS to collapsed spectrum * Fixing more test failures * Revamp arithmetic * Add changelog * remove debugging print * Handle creating dummy WCS and spectral axis when neither are provided, fix order of WCS * Codestyle * Remove debugging prints * Fixes for compatibility with up to date gwcs * Bump min version pins Bump min asdf Bump min astropy Bump min scipy Bump min asdf-astropy * Need gwcs 0.24 * Add note about arithmetic to changelog * Fix Spectrum1D references in doc page
…1211) * Working on constructing N dimensional GWCS for ND flux with only spectral axis provided * Get forward transform working for ND case * Convert other operator to Spectrum if needed in specutils where we have more control, rather than in astropy ndarithmetic * Don't pass extra arg to ndarithmetic * Use dimensionless instead of pix, remove unit conversion code that I think was unneeded and was causing errors * Fix two tests for multidimensional GWCS, remove debugging print * Working on debugging SpectrumCollection * Check for Spectrum specifically before arithmetic * Remove incorrect index from spectrum collection slice, cast operand as Spectrum even in 1D case * Don't pass multi-d WCS to collapsed spectrum * Fixing more test failures * Revamp arithmetic * Add changelog * remove debugging print * Handle creating dummy WCS and spectral axis when neither are provided, fix order of WCS * Codestyle * Remove debugging prints * Fixes for compatibility with up to date gwcs * Bump min version pins Bump min asdf Bump min astropy Bump min scipy Bump min asdf-astropy * Need gwcs 0.24 * Add note about arithmetic to changelog * Fix Spectrum1D references in doc page Fix skips in doc file
Currently,
gwcs_from_array
always gives a 1D purely spectral GWCS, even in the case where the flux array is multi-dimensional. This PR updates that function to return an ND GWCS, so that the dimensionality of aSpectrum
's GWCS always matches that of the flux array, even if the spatial dimensions are simply returning the pixel values. This will simplify and solve a lot of problems down stream in e.g.glue-astronomy
andjdaviz
.There were a lot of changes here that were needed to accommodate this change, but I think it's all improvements. I have one final failing test that I need to debug, so I'm opening this as a draft while I resolve that.