Skip to content

Adding redshift and radial velocity properties to SpectrumCollection#1332

Open
rosteen wants to merge 6 commits into
astropy:mainfrom
rosteen:redshift-for-spectrum-collection
Open

Adding redshift and radial velocity properties to SpectrumCollection#1332
rosteen wants to merge 6 commits into
astropy:mainfrom
rosteen:redshift-for-spectrum-collection

Conversation

@rosteen

@rosteen rosteen commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Currently only allow scalar values (rather than an array of values matching the number of spectra), and allows shifting the spectral axes with shift_spectrum_to like Spectrum does. I also added some clarification to the narrative docs about what exactly is happening when you access a single spectrum from a SpectrumCollection. Allowing array redshifts (one per spectrum in the collection) requires some upstream work in Astropy first.

Closes #1318.

@rosteen rosteen added this to the 2.5.0 milestone Jun 10, 2026
@rosteen rosteen requested a review from eteq as a code owner June 10, 2026 21:31
@rosteen rosteen added the data objects Core data objects like Spectrum1D or SpectralCollection label Jun 10, 2026
@rosteen rosteen requested a review from keflavich as a code owner June 10, 2026 21:31

@keflavich keflavich left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I have some minor wording suggestions.

I'm not sure it is ever right to adopt the first redshift out of a collection if they're not all equal

Comment thread docs/spectrum_collection.rst Outdated
Comment thread specutils/spectra/spectrum_collection.py Outdated
Comment thread specutils/spectra/spectrum_collection.py Outdated
Comment on lines +81 to +83
if redshift is not None and not (isinstance(redshift, (int, float)) or
(isinstance(redshift, u.Quantity) and redshift.ndim == 0)):
raise ValueError("Only single-value redshifts are supported at this time.")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe np.isscalar can replace this logic?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately it doesn't work on Quantities, so it can't replace everything here.

Comment on lines +226 to +228
redshift = spectra[0].redshift
if (not all((x.redshift == redshift for x in spectra))):
warnings.warn("Not all redshifts are equal, using redshift of first spectrum.")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe this should raise an exception? I'm not sure when using the first would be acceptable

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was iffy on this, I'll change it to an exception.

@rosteen rosteen Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, turns out this already would have been caught by an earlier check of radial_velocity (which raises an exception), I removed this.

Co-authored-by: Adam Ginsburg <keflavich@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data objects Core data objects like Spectrum1D or SpectralCollection enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How do I apply shift_spectrum_to(radial_velocity=...) to a SpectrumCollection?

2 participants