Skip to content

Conversation

harry353
Copy link

@harry353 harry353 commented Aug 7, 2025

This update addresses issues #1261 and #1262, changing how the extract_region function behaves in two ways:

  • When preserve_wcs=True, the WCS is now kept for single-region extractions.
  • Velocity regions can now be extracted from spectra with a frequency axis (and the other way around).

It also includes a new test script to cover these cases.

Copy link
Contributor

@keflavich keflavich left a comment

Choose a reason for hiding this comment

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

My changes are minor - documentation and variable names. I'm basically approving, but consider my suggestions.

Comment on lines 15 to 16
except Exception:
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems a little overly aggressive to catch all exceptions here. Can we limit this to UnitConversionError?

preserve_wcs: `bool`
If True, the WCS will be adjusted and retained in the output spectrum(s).
If False (default), WCS will be dropped.
Copy link
Contributor

Choose a reason for hiding this comment

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

The current False behavior does keep a WCS, it just turns it into a lookuptable WCS - so it doesn't exactly drop the WCS, it changes it.

Comment on lines 192 to 200
original_wcs = spectrum.wcs.deepcopy()

# Set CRPIX = 1.0 (FITS convention: reference pixel is 1-indexed)
original_wcs.wcs.crpix[0] = 1.0

# Set CRVAL to match the first spectral axis value in the sliced spectrum
original_wcs.wcs.crval[0] = sliced.spectral_axis[0].to_value(original_wcs.wcs.cunit[0])

sliced._wcs = original_wcs
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe call this new_wcs instead, since you're modifying it? Functionally I think this looks fine, but I find the variable name a little confusing

Copy link
Contributor

Choose a reason for hiding this comment

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

I see the intent, though - on the first line, you're copying the wcs from the unsliced spectrum, so there it's the original, but after you modify it, it's not.

…se now actually drops WCS entirely, rename WCS variable
@harry353
Copy link
Author

harry353 commented Aug 8, 2025

Thanks for the quick feedback. Applied your suggestions in a new push.

Copy link
Contributor

@rosteen rosteen 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 the contribution. I updated one of the code comments based on @keflavich's suggestion, other than that this looks good.

@rosteen rosteen self-requested a review August 26, 2025 16:57
@rosteen
Copy link
Contributor

rosteen commented Aug 26, 2025

Hmm, retracting my approval for now since tests are failing, I had forgotten or didn't realize that. @harry353 do you have time to address the test failures? From a quick glance my initial suspicion is that something was previously treating upper bounds as inclusive and is now treating them as exclusive.

@harry353
Copy link
Author

Yes, currently taking a look at this.

@harry353 harry353 force-pushed the extract-region-test-branch branch from 21a5e85 to 4cdb853 Compare August 31, 2025 21:59
@harry353
Copy link
Author

Fixed the off by one issue in region extraction (upper bound was including an extra bin). Now it lines up with normal Python slicing. Tests should all be passing now.

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.

3 participants