Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/1_basic_tutorial.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions examples/2a_optimizing_parameters_with_dxdt_known.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions examples/2b_optimizing_parameters_with_dxdt_unknown.ipynb

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions pynumdiff/smooth_finite_difference/_smooth_finite_difference.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# Smoothing finite differences #
################################
def mediandiff(x, dt, params=None, options={}, window_size=5, num_iterations=1):
"""Perform median smoothing using scipy.signal.medfilt followed by first order finite difference
"""Perform median smoothing using scipy.signal.medfilt followed by second order finite difference

:param np.array[float] x: data to differentiate
:param float dt: step size
Expand Down Expand Up @@ -44,7 +44,7 @@ def mediandiff(x, dt, params=None, options={}, window_size=5, num_iterations=1):


def meandiff(x, dt, params=None, options={}, window_size=5, num_iterations=1):
"""Perform mean smoothing by convolving mean kernel with x followed by first order finite difference
"""Perform mean smoothing by convolving mean kernel with x followed by second order finite difference

:param np.ndarray[float] x: data to differentiate
:param float dt: step size
Expand Down Expand Up @@ -74,7 +74,7 @@ def meandiff(x, dt, params=None, options={}, window_size=5, num_iterations=1):


def gaussiandiff(x, dt, params=None, options={}, window_size=5, num_iterations=1):
"""Perform gaussian smoothing by convolving gaussian kernel with x followed by first order finite difference
"""Perform gaussian smoothing by convolving gaussian kernel with x followed by second order finite difference

:param np.array[float] x: data to differentiate
:param float dt: step size
Expand Down Expand Up @@ -103,7 +103,7 @@ def gaussiandiff(x, dt, params=None, options={}, window_size=5, num_iterations=1


def friedrichsdiff(x, dt, params=None, options={}, window_size=5, num_iterations=1):
"""Perform friedrichs smoothing by convolving friedrichs kernel with x followed by first order finite difference
"""Perform friedrichs smoothing by convolving friedrichs kernel with x followed by second order finite difference

:param np.array[float] x: data to differentiate
:param float dt: step size
Expand Down Expand Up @@ -132,7 +132,7 @@ def friedrichsdiff(x, dt, params=None, options={}, window_size=5, num_iterations


def butterdiff(x, dt, params=None, options={}, filter_order=2, cutoff_freq=0.5, num_iterations=1):
"""Perform butterworth smoothing on x with scipy.signal.filtfilt followed by first order finite difference
"""Perform butterworth smoothing on x with scipy.signal.filtfilt followed by second order finite difference

:param np.array[float] x: data to differentiate
:param float dt: step size
Expand Down Expand Up @@ -171,7 +171,8 @@ def butterdiff(x, dt, params=None, options={}, filter_order=2, cutoff_freq=0.5,


def splinediff(x, dt, params=None, options={}, order=3, s=None, num_iterations=1):
"""Perform spline smoothing on x with scipy.interpolate.UnivariateSpline followed by first order finite difference
"""Find smoothed data and derivative estimates by fitting a smoothing spline to the data with
scipy.interpolate.UnivariateSpline.

:param np.array[float] x: data to differentiate
:param float dt: step size
Expand Down Expand Up @@ -200,6 +201,7 @@ def splinediff(x, dt, params=None, options={}, order=3, s=None, num_iterations=1
spline = scipy.interpolate.UnivariateSpline(t, x_hat, k=order, s=s)
x_hat = spline(t)

x_hat, dxdt_hat = finite_difference(x_hat, dt)
dspline = spline.derivative()
dxdt_hat = dspline(t)

return x_hat, dxdt_hat
2 changes: 1 addition & 1 deletion pynumdiff/tests/test_diff_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def iterated_first_order(*args, **kwargs): return first_order(*args, **kwargs)
[(1, 0), (1, 1), (1, 0), (1, 1)],
[(2, 2), (3, 2), (2, 2), (3, 2)],
[(2, 1), (3, 3), (2, 1), (3, 3)]],
splinediff: [[(-14, -15), (-14, -14), (-1, -1), (0, 0)],
splinediff: [[(-14, -15), (-14, -15), (-1, -1), (0, 0)],
[(-14, -14), (-13, -14), (-1, -1), (0, 0)],
[(-14, -14), (-13, -13), (-1, -1), (0, 0)],
[(0, 0), (1, 1), (0, 0), (1, 1)],
Expand Down