Skip to content

Smooth log-uniform spectra on their native samples in smooth_vel_fft - #51

Open
Nikhil0504 wants to merge 3 commits into
bd-j:mainfrom
Nikhil0504:fix/smooth-vel-fft-native-grid
Open

Nikhil0504 wants to merge 3 commits into
bd-j:mainfrom
Nikhil0504:fix/smooth-vel-fft-native-grid

Conversation

@Nikhil0504

Copy link
Copy Markdown

smooth_vel_fft always resamples the input onto a power-of-two log grid with np.interp
(resample_wave) before the FFT. For spectra that are only just sampled, the linear interpolation alters absorption lines before the kernel is applied, so fftsmooth=True no longer agrees with the direct convolution of smooth_vel.

Changes

  • smooth_vel_fft: if the input is already uniform in log wavelength, smooth the native samples
    and skip resample_wave. Other grids take the existing path unchanged.
  • smooth_fft: pass n=len(spec) to irfft, so odd-length input keeps its length (needed once
    native grids are used; even lengths give identical results).

Tests

New tests/test_smoothing.py: FFT vs direct convolution on a barely sampled log-uniform spectrum
(agree to 1e-6; ~1e-15 measured), odd-length input, and a non-uniform grid that still takes the
resampled path. Two of these fail on current main (odd length, FFT vs direct).
Note: CI runs only tests/tests.py; changing the workflow to pytest tests/ would include them.

@bd-j

bd-j commented Nov 13, 2026

Copy link
Copy Markdown
Owner

Hi @Nikhil0504 thanks. Yes I've recently gone over sedpy smoothing and noticed some issues. Barely critically sampled spectra are certainly a concern, there's an (inelegant) attempt to handle it in prospector (https://github.com/bd-j/prospector/blob/main/prospect/observation/observation.py#L557)

I am working on a wholesale replacement (with gradients), but I will try to give this a look soon.

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.

2 participants