Skip to content

Commit

Permalink
Fix spline interpolation between different unit physical types (astro…
Browse files Browse the repository at this point in the history
…py#1190)

* Use edges in new unit for comparison

* Fix changelog

* Add test
  • Loading branch information
rosteen authored Nov 5, 2024
1 parent 36afc8a commit 4bcf381
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
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

0 comments on commit 4bcf381

Please sign in to comment.