specutils icon indicating copy to clipboard operation
specutils copied to clipboard

Spline interpolation no longer works for binning on velocity grid

Open StuartLittlefair opened this issue 1 year ago • 2 comments

Due to changes added in https://github.com/astropy/specutils/pull/1121, the SplineInterpolatedResampler is no longer suitable for binning a spectrum onto a spectral axis which is uniform in velocity space. Prior to this, the following code would work (e.g works in 1.12.0 but not in 1.17.0):

rest_wavelength = 656.2 * u.nm

# make a fake spectrum
wavelengths = np.linspace(640, 672, 1000) * u.nm
flux = np.random.normal(1.0, 0.1, 1000) * u.mJy
spec1d = Spectrum1D(spectral_axis=wavelengths, velocity_convention="optical", flux=flux)
spec1d.spectral_axis.doppler_rest = rest_wavelength

velocities = np.linspace(-1000, 1000, 500) * u.km/u.s
velocity_grid = SpectralAxis(
        velocities, doppler_rest=rest_wavelength, doppler_convention="optical"
)
resample_fn = SplineInterpolatedResampler()
velocity_binned = resample_fn(spec1d, velocity_grid)

This now fails because the line below

https://github.com/astropy/specutils/blob/a859dd6c9b540b6f651a3b0d882be6b418aecde7/specutils/manipulation/resample.py#L465

assumes that the bin edges and the fin_spec_axis are both in wavelength units. The only resampler that works for this use case is the LinearInterpolatedResampler, but this is not accurate enough for velocity binning.

StuartLittlefair avatar Oct 15 '24 14:10 StuartLittlefair

Thanks for pinpointing what broke this - should be a simple fix, I'll get it in before the next release (hopefully in the next week or so).

rosteen avatar Oct 15 '24 15:10 rosteen

Amazing service @rosteen , thanks!

StuartLittlefair avatar Oct 15 '24 15:10 StuartLittlefair

My simple fix ran into an error in astropy, still trying to figure out if that's a problem with my fix or a bug in astropy.

rosteen avatar Oct 29 '24 18:10 rosteen

Oops! Let me know if I can help in any way.

StuartLittlefair avatar Oct 29 '24 18:10 StuartLittlefair