Skip to content

Commit

Permalink
Remove extrapolation from resample_spline
Browse files Browse the repository at this point in the history
Closes #146
  • Loading branch information
georgievgeorgi committed Sep 17, 2024
1 parent 02c76ae commit cb2490d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/ramanchada2/spectrum/filters/resampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def resample_spline(spe: Spectrum, /,
kw_args: Dict[str, Any] = {}
if spline == 'pchip':
spline_fn = PchipInterpolator
kw_args['extrapolate'] = False
elif spline == 'akima':
spline_fn = Akima1DInterpolator
elif spline == 'makima':
Expand All @@ -158,6 +159,7 @@ def resample_spline(spe: Spectrum, /,
elif spline == 'cubic_spline':
spline_fn = CubicSpline
kw_args['bc_type'] = 'natural'
kw_args['extrapolate'] = False

if interp_kw_args is not None:
kw_args.update(interp_kw_args)
Expand Down
11 changes: 10 additions & 1 deletion tests/spectrum/filters/test_resample_spline.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import ramanchada2 as rc2
import numpy as np
from scipy.interpolate import CubicSpline

import ramanchada2 as rc2


def test_resample_spline():
spe = rc2.spectrum.from_test_spe(2, laser_wl=['785'], sample=['PST']).normalize()
Expand All @@ -10,3 +11,11 @@ def test_resample_spline():
aaa = CubicSpline(spe_tr.x, spe_tr.y)(np.linspace(400, 2000, 1000, endpoint=False))
assert np.all(res_spe.x == np.linspace(400, 2000, 1000, endpoint=False))
assert np.allclose(aaa, res_spe.y, rtol=.05)

spe = rc2.spectrum.from_delta_lines({500: 100, 600: 200})
spe = spe.add_gaussian_noise_drift(sigma=2, coef=.3)

for s in 'pchip', 'akima', 'makima', 'cubic_spline':
tt = spe.resample_spline_filter(x_range=(0, 1000), xnew_bins=1000, spline=s)
assert np.all(tt.y[:450] == 0)
assert np.all(tt.y[650:] == 0)

0 comments on commit cb2490d

Please sign in to comment.