Skip to content
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

Fix spline interpolation between different unit physical types #1190

Merged
merged 3 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Bug Fixes

- Fixed automatic format detection for SDSS-V ``SpectrumList`` default loaders. [#1185]

- Fixed ``SplineInterpolatedResampler`` when input and output spectral axes are different
physical types, e.g. wavelength and velocity. [#1190]

Other Changes and Additions
^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -35,7 +38,6 @@ Bug Fixes
- Fixed extracting a spectral region when one of spectrum/region is in wavelength
and the other is in frequency units. [#1187]


Other Changes and Additions
^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
2 changes: 1 addition & 1 deletion specutils/manipulation/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def resample1d(self, orig_spectrum, fin_spec_axis):
if self.extrapolation_treatment == 'zero_fill':
fill_val = 0

orig_edges = orig_spectrum.spectral_axis.bin_edges
orig_edges = orig_axis_in_new.bin_edges
off_edges = (fin_spec_axis < np.min(orig_edges)) | (np.max(orig_edges) < fin_spec_axis)
out_flux_val[off_edges] = fill_val
if new_unc is not None:
Expand Down
18 changes: 17 additions & 1 deletion specutils/tests/test_resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from astropy.nddata import VarianceUncertainty, InverseVariance, StdDevUncertainty
from astropy.tests.helper import assert_quantity_allclose

from ..spectra.spectrum1d import Spectrum1D
from ..spectra.spectrum1d import Spectrum1D, SpectralAxis
from ..manipulation.resample import FluxConservingResampler, LinearInterpolatedResampler, SplineInterpolatedResampler


Expand Down Expand Up @@ -214,6 +214,22 @@ def test_resample_different_units(all_resamplers):
resampled = resampler(input_spectrum, resamp_grid)
assert not np.any(np.isnan(resampled.flux))

resamp_grid = [550, 650]*u.nm
resampled = resampler(input_spectrum, resamp_grid)

# Test conversion to velocity grid
rest_wavelength = 656.2 * u.nm
wavelengths = np.linspace(640, 672, 10) * u.nm
flux = np.ones(10) * u.mJy
spec1d = Spectrum1D(spectral_axis=wavelengths, velocity_convention="optical", flux=flux)
spec1d.spectral_axis.doppler_rest = rest_wavelength

velocities = np.linspace(-1000, 1000, 5) * u.km/u.s
velocity_grid = SpectralAxis(velocities, doppler_rest=rest_wavelength,
doppler_convention="optical")
velocity_binned = resampler(spec1d, velocity_grid)
assert not np.any(np.isnan(velocity_binned.flux))


def test_resample_uncs(all_resamplers):
sdunc = StdDevUncertainty([0.1, 0.2, 0.3]*u.mJy)
Expand Down