Skip to content

Conversation

@rosteen
Copy link
Contributor

@rosteen rosteen commented Nov 26, 2025

Fixes #1268, and additionally improves the behavior of the shift_spectrum_to method.

Previously, the spectral axis was updated when applying a redshift with shift_spectrum_to, but the original WCS was kept on the Spectrum, which led to some annoying behavior and workarounds (and was potentially confusing to the user). Now the WCS will be updated along with the spectral axis - in the case of a FITS WCS, the relevant header values will be updated in place, while a GWCS will be replaced with a new lookup table GWCS. In the latter case, the original WCS will be stored in an _original_wcs attribute so no information is lost (e.g., spatial coordinates for a cube). This obviously isn't an ideal solution for the GWCS case but I hope it suffices while I investigate better ways to handle the GWCS case.

@rosteen rosteen added this to the 2.3 milestone Nov 26, 2025
@rosteen rosteen added bug data objects Core data objects like Spectrum1D or SpectralCollection labels Nov 26, 2025
@codecov
Copy link

codecov bot commented Nov 26, 2025

Codecov Report

❌ Patch coverage is 45.00000% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.79%. Comparing base (4c82582) to head (6608158).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
specutils/spectra/spectrum.py 45.00% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1287      +/-   ##
==========================================
- Coverage   86.98%   86.79%   -0.20%     
==========================================
  Files          63       63              
  Lines        4857     4870      +13     
==========================================
+ Hits         4225     4227       +2     
- Misses        632      643      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rosteen rosteen marked this pull request as ready for review November 28, 2025 21:46
wcs_spectral_index = self.wcs.naxis - self.spectral_axis_index
h = self.wcs.to_header()
z_factor = (1 + redshift) / (1 + old_redshift)
h[f'CRVAL_{wcs_spectral_index}'] *= z_factor
Copy link
Contributor

Choose a reason for hiding this comment

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

this relies on ctype being wavelength

Copy link
Contributor Author

@rosteen rosteen Dec 2, 2025

Choose a reason for hiding this comment

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

Good call - the factor would just be the inverse of this for frequency, right? Then of course there's energy and wavenumber, but perhaps I don't worry about those for now 😅 .

Edit: wait, those two are also the inverse I think, not that complicated.

@rosteen
Copy link
Contributor Author

rosteen commented Dec 3, 2025

Test failures are unrelated timeouts.

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

Labels

bug data objects Core data objects like Spectrum1D or SpectralCollection

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unexpected Behavior for Arithmetic with Spectrum Objects

2 participants