Skip to content

Commit 00dfac4

Browse files
authored
Merge pull request #137 from florisvb/make-spline-not-FD
splines already have a derivative implemented, so there isn't necessarily a need to FD on top of them
2 parents 74cebba + bd280b3 commit 00dfac4

5 files changed

Lines changed: 15 additions & 13 deletions

File tree

examples/1_basic_tutorial.ipynb

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

examples/2a_optimizing_parameters_with_dxdt_known.ipynb

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

examples/2b_optimizing_parameters_with_dxdt_unknown.ipynb

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

pynumdiff/smooth_finite_difference/_smooth_finite_difference.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# Smoothing finite differences #
1212
################################
1313
def mediandiff(x, dt, params=None, options={}, window_size=5, num_iterations=1):
14-
"""Perform median smoothing using scipy.signal.medfilt followed by first order finite difference
14+
"""Perform median smoothing using scipy.signal.medfilt followed by second order finite difference
1515
1616
:param np.array[float] x: data to differentiate
1717
:param float dt: step size
@@ -44,7 +44,7 @@ def mediandiff(x, dt, params=None, options={}, window_size=5, num_iterations=1):
4444

4545

4646
def meandiff(x, dt, params=None, options={}, window_size=5, num_iterations=1):
47-
"""Perform mean smoothing by convolving mean kernel with x followed by first order finite difference
47+
"""Perform mean smoothing by convolving mean kernel with x followed by second order finite difference
4848
4949
:param np.ndarray[float] x: data to differentiate
5050
:param float dt: step size
@@ -74,7 +74,7 @@ def meandiff(x, dt, params=None, options={}, window_size=5, num_iterations=1):
7474

7575

7676
def gaussiandiff(x, dt, params=None, options={}, window_size=5, num_iterations=1):
77-
"""Perform gaussian smoothing by convolving gaussian kernel with x followed by first order finite difference
77+
"""Perform gaussian smoothing by convolving gaussian kernel with x followed by second order finite difference
7878
7979
:param np.array[float] x: data to differentiate
8080
:param float dt: step size
@@ -103,7 +103,7 @@ def gaussiandiff(x, dt, params=None, options={}, window_size=5, num_iterations=1
103103

104104

105105
def friedrichsdiff(x, dt, params=None, options={}, window_size=5, num_iterations=1):
106-
"""Perform friedrichs smoothing by convolving friedrichs kernel with x followed by first order finite difference
106+
"""Perform friedrichs smoothing by convolving friedrichs kernel with x followed by second order finite difference
107107
108108
:param np.array[float] x: data to differentiate
109109
:param float dt: step size
@@ -132,7 +132,7 @@ def friedrichsdiff(x, dt, params=None, options={}, window_size=5, num_iterations
132132

133133

134134
def butterdiff(x, dt, params=None, options={}, filter_order=2, cutoff_freq=0.5, num_iterations=1):
135-
"""Perform butterworth smoothing on x with scipy.signal.filtfilt followed by first order finite difference
135+
"""Perform butterworth smoothing on x with scipy.signal.filtfilt followed by second order finite difference
136136
137137
:param np.array[float] x: data to differentiate
138138
:param float dt: step size
@@ -171,7 +171,8 @@ def butterdiff(x, dt, params=None, options={}, filter_order=2, cutoff_freq=0.5,
171171

172172

173173
def splinediff(x, dt, params=None, options={}, order=3, s=None, num_iterations=1):
174-
"""Perform spline smoothing on x with scipy.interpolate.UnivariateSpline followed by first order finite difference
174+
"""Find smoothed data and derivative estimates by fitting a smoothing spline to the data with
175+
scipy.interpolate.UnivariateSpline.
175176
176177
:param np.array[float] x: data to differentiate
177178
:param float dt: step size
@@ -200,6 +201,7 @@ def splinediff(x, dt, params=None, options={}, order=3, s=None, num_iterations=1
200201
spline = scipy.interpolate.UnivariateSpline(t, x_hat, k=order, s=s)
201202
x_hat = spline(t)
202203

203-
x_hat, dxdt_hat = finite_difference(x_hat, dt)
204+
dspline = spline.derivative()
205+
dxdt_hat = dspline(t)
204206

205207
return x_hat, dxdt_hat

pynumdiff/tests/test_diff_methods.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def iterated_first_order(*args, **kwargs): return first_order(*args, **kwargs)
137137
[(1, 0), (1, 1), (1, 0), (1, 1)],
138138
[(2, 2), (3, 2), (2, 2), (3, 2)],
139139
[(2, 1), (3, 3), (2, 1), (3, 3)]],
140-
splinediff: [[(-14, -15), (-14, -14), (-1, -1), (0, 0)],
140+
splinediff: [[(-14, -15), (-14, -15), (-1, -1), (0, 0)],
141141
[(-14, -14), (-13, -14), (-1, -1), (0, 0)],
142142
[(-14, -14), (-13, -13), (-1, -1), (0, 0)],
143143
[(0, 0), (1, 1), (0, 0), (1, 1)],

0 commit comments

Comments
 (0)