Skip to content

Commit 27b6c86

Browse files
authored
Merge pull request #114 from florisvb/who-can-say-only-time
in search of lost time
2 parents 926901a + 728ed66 commit 27b6c86

7 files changed

Lines changed: 58 additions & 58 deletions

File tree

pynumdiff/finite_difference/_finite_difference.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
def first_order(x, dt, params=None, options={}, num_iterations=None):
77
"""First-order centered difference method
88
9-
:param np.array[float] x: array of time series to differentiate
10-
:param float dt: time step size
9+
:param np.array[float] x: data to differentiate
10+
:param float dt: step size
1111
:param list[float] or float params: (**deprecated**, prefer :code:`num_iterations`)
1212
:param dict options: (**deprecated**, prefer :code:`num_iterations`) a dictionary consisting of {'iterate': (bool)}
1313
:param int num_iterations: If performing iterated FD to smooth the estimates, give the number of iterations.
@@ -34,8 +34,8 @@ def first_order(x, dt, params=None, options={}, num_iterations=None):
3434
def second_order(x, dt):
3535
"""Second-order centered difference method
3636
37-
:param np.array[float] x: array of time series to differentiate
38-
:param float dt: time step size
37+
:param np.array[float] x: data to differentiate
38+
:param float dt: step size
3939
4040
:return: tuple[np.array, np.array] of\n
4141
- **x_hat** -- estimated (smoothed) x
@@ -60,8 +60,8 @@ def _x_hat_using_finite_difference(x, dt):
6060
def _iterate_first_order(x, dt, num_iterations):
6161
"""Iterative first order centered finite difference.
6262
63-
:param np.array[float] x: array of time series to differentiate
64-
:param float dt: time step size
63+
:param np.array[float] x: data to differentiate
64+
:param float dt: step size
6565
:param int num_iterations: number of iterations
6666
6767
:return: tuple[np.array, np.array] of\n

pynumdiff/kalman_smooth/_kalman_smooth.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def constant_velocity(x, dt, params=None, options=None, r=None, q=None, forwardb
109109
"""Run a forward-backward constant velocity RTS Kalman smoother to estimate the derivative.
110110
111111
:param np.array[float] x: data series to differentiate
112-
:param float dt: time step size
112+
:param float dt: step size
113113
:param list[float] params: (**deprecated**, prefer :code:`r` and :code:`q`)
114114
:param options: (**deprecated**, prefer :code:`forwardbackward`)
115115
a dictionary consisting of {'forwardbackward': (bool)}
@@ -144,7 +144,7 @@ def constant_acceleration(x, dt, params=None, options=None, r=None, q=None, forw
144144
"""Run a forward-backward constant acceleration RTS Kalman smoother to estimate the derivative.
145145
146146
:param np.array[float] x: data series to differentiate
147-
:param float dt: time step size
147+
:param float dt: step size
148148
:param list[float] params: (**deprecated**, prefer :code:`r` and :code:`q`)
149149
:param options: (**deprecated**, prefer :code:`forwardbackward`)
150150
a dictionary consisting of {'forwardbackward': (bool)}
@@ -183,7 +183,7 @@ def constant_jerk(x, dt, params=None, options=None, r=None, q=None, forwardbackw
183183
"""Run a forward-backward constant jerk RTS Kalman smoother to estimate the derivative.
184184
185185
:param np.array[float] x: data series to differentiate
186-
:param float dt: time step size
186+
:param float dt: step size
187187
:param list[float] params: (**deprecated**, prefer :code:`r` and :code:`q`)
188188
:param options: (**deprecated**, prefer :code:`forwardbackward`)
189189
a dictionary consisting of {'forwardbackward': (bool)}

pynumdiff/linear_model/_linear_model.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def _slide_function(func, x, dt, args, window_size, step_size, kernel_name):
1919
"""Slide a smoothing derivative function across a timeseries with specified window size.
2020
2121
:param callable func: name of the function to slide
22-
:param np.array[float] x: time series to differentiate
22+
:param np.array[float] x: data to differentiate
2323
:param float dt: time step
2424
:param dict args: see func for requirements
2525
:param int window_size: size of the sliding window
@@ -97,8 +97,8 @@ def _slide_function(func, x, dt, args, window_size, step_size, kernel_name):
9797
def savgoldiff(x, dt, params=None, options=None, polynomial_order=None, window_size=None, smoothing_win=None):
9898
"""Use the Savitzky-Golay to smooth the data and calculate the first derivative. It wses scipy.signal.savgol_filter. The Savitzky-Golay is very similar to the sliding polynomial fit, but slightly noisier, and much faster
9999
100-
:param np.array[float] x: array of time series to differentiate
101-
:param float dt: time step size
100+
:param np.array[float] x: data to differentiate
101+
:param float dt: step size
102102
:param list params: (**deprecated**, prefer :code:`polynomial_order`, :code:`window_size`, and :code:`smoothing_win`)
103103
:param dict options: (**deprecated**)
104104
:param int polynomial_order: order of the polynomial
@@ -146,7 +146,7 @@ def savgoldiff(x, dt, params=None, options=None, polynomial_order=None, window_s
146146
def _polydiff(x, dt, polynomial_order, weights=None):
147147
"""Fit polynomials to the timeseries, and differentiate the polynomials.
148148
149-
:param np.array[float] x: time series to differentiate
149+
:param np.array[float] x: data to differentiate
150150
:param float dt: time step
151151
:param int polynomial_order: order of the polynomial
152152
:param np.array[float] weights: weights applied to each point in calculating the polynomial fit.
@@ -172,10 +172,10 @@ def _polydiff(x, dt, polynomial_order, weights=None):
172172

173173
def polydiff(x, dt, params=None, options=None, polynomial_order=None, window_size=None,
174174
sliding=True, step_size=1, kernel='friedrichs'):
175-
"""Fit polynomials to the time series, and differentiate the polynomials.
175+
"""Fit polynomials to the data, and differentiate the polynomials.
176176
177-
:param np.array[float] x: array of time series to differentiate
178-
:param float dt: time step size
177+
:param np.array[float] x: data to differentiate
178+
:param float dt: step size
179179
:param list[int] params: (**deprecated**, prefer :code:`polynomial_order` and :code:`window_size`)
180180
:param dict options: (**deprecated**, prefer :code:`sliding`, :code:`step_size`, and :code:`kernel`)
181181
a dictionary consisting of {'sliding': (bool), 'step_size': (int), 'kernel_name': (str)}
@@ -219,7 +219,7 @@ def polydiff(x, dt, params=None, options=None, polynomial_order=None, window_siz
219219
# """
220220
# Fit the timeseries with chebyshev polynomials, and differentiate this model.
221221

222-
# :param x: (np.array of floats, 1xN) time series to differentiate
222+
# :param x: (np.array of floats, 1xN) data to differentiate
223223
# :param dt: (float) time step
224224
# :param params: (list) [N] : (int) order of the polynomial
225225
# :param options:
@@ -253,10 +253,10 @@ def polydiff(x, dt, params=None, options=None, polynomial_order=None, window_siz
253253
# """
254254
# Slide a smoothing derivative function across a times eries with specified window size.
255255

256-
# :param x: array of time series to differentiate
256+
# :param x: data to differentiate
257257
# :type x: np.array (float)
258258

259-
# :param dt: time step size
259+
# :param dt: step size
260260
# :type dt: float
261261

262262
# :param params: a list of 2 elements:
@@ -356,7 +356,7 @@ def __integrate_dxdt_hat_matrix__(dxdt_hat, dt):
356356
def _lineardiff(x, dt, N, gamma, solver=None, weights=None):
357357
"""Estimate the parameters for a system xdot = Ax, and use that to calculate the derivative
358358
359-
:param np.array[float] x: time series to differentiate
359+
:param np.array[float] x: data to differentiate
360360
:param float dt: time step
361361
:param int > 1 N: order (e.g. 2: velocity; 3: acceleration)
362362
:param float gamma: regularization term
@@ -404,10 +404,10 @@ def _lineardiff(x, dt, N, gamma, solver=None, weights=None):
404404

405405
def lineardiff(x, dt, params=None, options=None, order=None, gamma=None, window_size=None,
406406
sliding=True, step_size=10, kernel='friedrichs', solver=None):
407-
"""Slide a smoothing derivative function across a time series with specified window size.
407+
"""Slide a smoothing derivative function across data, with specified window size.
408408
409-
:param np.array[float] x: array of time series to differentiate
410-
:param float dt: time step size
409+
:param np.array[float] x: data to differentiate
410+
:param float dt: step size
411411
:param list[int, float, int] params: (**deprecated**, prefer :code:`order`, :code:`gamma`, and :code:`window_size`)
412412
:param dict options: (**deprecated**, prefer :code:`sliding`, :code:`step_size`, :code:`kernel`, and :code:`solver`
413413
a dictionary consisting of {'sliding': (bool), 'step_size': (int), 'kernel_name': (str), 'solver': (str)}
@@ -466,14 +466,14 @@ def lineardiff(x, dt, params=None, options=None, order=None, gamma=None, window_
466466
def spectraldiff(x, dt, params=None, options=None, high_freq_cutoff=None, even_extension=True, pad_to_zero_dxdt=True):
467467
"""Take a derivative in the fourier domain, with high frequency attentuation.
468468
469-
:param np.array[float] x: array of time series to differentiate
470-
:param float dt: time step size
469+
:param np.array[float] x: data to differentiate
470+
:param float dt: step size
471471
:param list[float] or float params: (**deprecated**, prefer :code:`high_freq_cutoff`)
472472
:param dict options: (**deprecated**, prefer :code:`even_extension`
473473
and :code:`pad_to_zero_dxdt`) a dictionary consisting of {'even_extension': (bool), 'pad_to_zero_dxdt': (bool)}
474474
:param float high_freq_cutoff: The high frequency cutoff. Frequencies below this threshold will be kept, and above will be zeroed.
475-
:param bool even_extension: if True, extend the time series with an even extension so signal starts and ends at the same value.
476-
:param bool pad_to_zero_dxdt: if True, extend the time series with extensions that smoothly force the derivative to zero. This
475+
:param bool even_extension: if True, extend the data with an even extension so signal starts and ends at the same value.
476+
:param bool pad_to_zero_dxdt: if True, extend the data with extensions that smoothly force the derivative to zero. This
477477
allows the spectral derivative to fit data which does not start and end with derivatives equal to zero.
478478
479479
:return: tuple[np.array, np.array] of\n

pynumdiff/smooth_finite_difference/_smooth_finite_difference.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
def mediandiff(x, dt, params=None, options={}, window_size=5, num_iterations=1):
1414
"""Perform median smoothing using scipy.signal.medfilt followed by first order finite difference
1515
16-
:param np.array[float] x: array of time series to differentiate
17-
:param float dt: time step size
16+
:param np.array[float] x: data to differentiate
17+
:param float dt: step size
1818
:param list[int] params: (**deprecated**, prefer :code:`window_size` and :code:`num_iterations`)
1919
:param dict options: (**deprecated**, prefer :code:`num_iterations`) an empty dictionary or {'iterate': (bool)}
2020
:param int window_size: filter window size
@@ -46,8 +46,8 @@ def mediandiff(x, dt, params=None, options={}, window_size=5, num_iterations=1):
4646
def meandiff(x, dt, params=None, options={}, window_size=5, num_iterations=1):
4747
"""Perform mean smoothing by convolving mean kernel with x followed by first order finite difference
4848
49-
:param np.ndarray[float] x: array of time series to differentiate
50-
:param float dt: time step size
49+
:param np.ndarray[float] x: data to differentiate
50+
:param float dt: step size
5151
5252
:param list[int] params: (**deprecated**, prefer :code:`window_size` and :code:`num_iterations`)
5353
:code:`[window_size]` or, :code:`if 'iterate' in options`, :code:`[window_size, num_iterations]`
@@ -76,8 +76,8 @@ def meandiff(x, dt, params=None, options={}, window_size=5, num_iterations=1):
7676
def gaussiandiff(x, dt, params=None, options={}, window_size=5, num_iterations=1):
7777
"""Perform gaussian smoothing by convolving gaussian kernel with x followed by first order finite difference
7878
79-
:param np.array[float] x: array of time series to differentiate
80-
:param float dt: time step size
79+
:param np.array[float] x: data to differentiate
80+
:param float dt: step size
8181
:param list[int] params: (**deprecated**, prefer :code:`window_size` and :code:`num_iterations`)
8282
:code:`[window_size]` or, :code:`if 'iterate' in options`, :code:`[window_size, num_iterations]`
8383
:param dict options: (**deprecated**, prefer :code:`num_iterations`) an empty dictionary or {'iterate': (bool)}
@@ -105,8 +105,8 @@ def gaussiandiff(x, dt, params=None, options={}, window_size=5, num_iterations=1
105105
def friedrichsdiff(x, dt, params=None, options={}, window_size=5, num_iterations=1):
106106
"""Perform friedrichs smoothing by convolving friedrichs kernel with x followed by first order finite difference
107107
108-
:param np.array[float] x: array of time series to differentiate
109-
:param float dt: time step size
108+
:param np.array[float] x: data to differentiate
109+
:param float dt: step size
110110
:param list[int] params: (**deprecated**, prefer :code:`window_size` and :code:`num_iterations`)
111111
:code:`[window_size]` or, :code:`if 'iterate' in options`, :code:`[window_size, num_iterations]`
112112
:param dict options: (**deprecated**, prefer :code:`num_iterations`) an empty dictionary or {'iterate': (bool)}
@@ -134,14 +134,14 @@ def friedrichsdiff(x, dt, params=None, options={}, window_size=5, num_iterations
134134
def butterdiff(x, dt, params=None, options={}, filter_order=2, cutoff_freq=0.5, num_iterations=1):
135135
"""Perform butterworth smoothing on x with scipy.signal.filtfilt followed by first order finite difference
136136
137-
:param np.array[float] x: array of time series to differentiate
138-
:param float dt: time step size
137+
:param np.array[float] x: data to differentiate
138+
:param float dt: step size
139139
:param list[int] params: (**deprecated**, prefer :code:`filter_order`, :code:`cutoff_freq`,
140140
and :code:`num_iterations`)
141141
:param dict options: (**deprecated**, prefer :code:`num_iterations`) an empty dictionary or {'iterate': (bool)}
142142
:param int filter_order: order of the filter
143-
:param float cutoff_freq: cutoff frequency :math:`\\in [0, 1]`. For a discrete timeseries,
144-
the value is normalized to the range 0-1, where 1 is the Nyquist frequency.
143+
:param float cutoff_freq: cutoff frequency :math:`\\in [0, 1]`. For a discrete vector, the
144+
value is normalized to the range 0-1, where 1 is the Nyquist frequency.
145145
:param int num_iterations: how many times to apply smoothing
146146
147147
:return: tuple[np.array, np.array] of\n
@@ -173,8 +173,8 @@ def butterdiff(x, dt, params=None, options={}, filter_order=2, cutoff_freq=0.5,
173173
def splinediff(x, dt, params=None, options={}, order=3, s=None, num_iterations=1):
174174
"""Perform spline smoothing on x with scipy.interpolate.UnivariateSpline followed by first order finite difference
175175
176-
:param np.array[float] x: array of time series to differentiate
177-
:param float dt: time step size
176+
:param np.array[float] x: data to differentiate
177+
:param float dt: step size
178178
:param list params: (**deprecated**, prefer :code:`order`, :code:`cutoff_freq`, and :code:`num_iterations`)
179179
:param dict options: (**deprecated**, prefer :code:`num_iterations`) an empty dictionary or {'iterate': (bool)}
180180
:param int order: polynomial order of the spline. A kth order spline can be differentiated k times.

pynumdiff/total_variation_regularization/_total_variation_regularization.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ def iterative_velocity(x, dt, params=None, options=None, num_iterations=None, ga
1414
Rick Chartrand, "Numerical differentiation of noisy, nonsmooth data," ISRN Applied Mathematics,
1515
Vol. 2011, Article ID 164564, 2011. Original code at https://sites.google.com/site/dnartrahckcir/home/tvdiff-code
1616
17-
:param np.array[float] x: array of time series to differentiate
18-
:param float dt: time step size
17+
:param np.array[float] x: data to differentiate
18+
:param float dt: step size
1919
:param list params: (**deprecated**, prefer :code:`num_iterations` and :code:`gamma`)
2020
:param dict options: (**deprecated**, prefer :code:`cg_maxiter` and :code:`scale`)
2121
a dictionary consisting of {'cg_maxiter': (int), 'scale': (str)}
@@ -59,7 +59,7 @@ def _total_variation_regularized_derivative(x, dt, order, gamma, solver=None):
5959
total variation regularized derivative.
6060
6161
:param np.array[float] x: data to differentiate
62-
:param float dt: time step
62+
:param float dt: step size
6363
:param int order: 1, 2, or 3, the derivative to regularize
6464
:param float gamma: regularization parameter
6565
:param str solver: Solver to use. Solver options include: 'MOSEK', 'CVXOPT', 'CLARABEL', 'ECOS'.
@@ -113,7 +113,7 @@ def velocity(x, dt, params=None, options=None, gamma=None, solver=None):
113113
"""Use convex optimization (cvxpy) to solve for the velocity total variation regularized derivative.
114114
115115
:param np.array[float] x: data to differentiate
116-
:param float dt: time step size
116+
:param float dt: step size
117117
:param params: (**deprecated**, prefer :code:`gamma`)
118118
:param dict options: (**deprecated**, prefer :code:`solver`) a dictionary consisting of {'solver': (str)}
119119
:param float gamma: the regularization parameter
@@ -140,7 +140,7 @@ def acceleration(x, dt, params=None, options=None, gamma=None, solver=None):
140140
"""Use convex optimization (cvxpy) to solve for the acceleration total variation regularized derivative.
141141
142142
:param np.array[float] x: data to differentiate
143-
:param float dt: time step size
143+
:param float dt: step size
144144
:param params: (**deprecated**, prefer :code:`gamma`)
145145
:param dict options: (**deprecated**, prefer :code:`solver`) a dictionary consisting of {'solver': (str)}
146146
:param float gamma: the regularization parameter
@@ -167,7 +167,7 @@ def jerk(x, dt, params=None, options=None, gamma=None, solver=None):
167167
"""Use convex optimization (cvxpy) to solve for the jerk total variation regularized derivative.
168168
169169
:param np.array[float] x: data to differentiate
170-
:param float dt: time step size
170+
:param float dt: step size
171171
:param params: (**deprecated**, prefer :code:`gamma`)
172172
:param dict options: (**deprecated**, prefer :code:`solver`) a dictionary consisting of {'solver': (str)}
173173
:param float gamma: the regularization parameter
@@ -196,7 +196,7 @@ def smooth_acceleration(x, dt, params=None, options=None, gamma=None, window_siz
196196
The end result is similar to the jerk method, but can be more time-efficient.
197197
198198
:param np.array[float] x: data to differentiate
199-
:param float dt: time step size
199+
:param float dt: step size
200200
:param params: (**deprecated**, prefer :code:`gamma` and :code:`window_size`)
201201
:param dict options: (**deprecated**, prefer :code:`solver`) a dictionary consisting of {'solver': (str)}
202202
:param float gamma: the regularization parameter
@@ -233,7 +233,7 @@ def jerk_sliding(x, dt, params=None, options=None, gamma=None, solver=None):
233233
"""Use convex optimization (cvxpy) to solve for the jerk total variation regularized derivative.
234234
235235
:param np.array[float] x: data to differentiate
236-
:param float dt: time step size
236+
:param float dt: step size
237237
:param params: (**deprecated**, prefer :code:`gamma`)
238238
:param dict options: (**deprecated**, prefer :code:`solver`) a dictionary consisting of {'solver': (str)}
239239
:param float gamma: the regularization parameter

pynumdiff/utils/evaluate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def plot(x, dt, x_hat, dxdt_hat, x_truth, dxdt_truth, xlim=None, ax_x=None, ax_d
2020
:param x: array of noisy time series
2121
:type x: np.array (float)
2222
23-
:param dt: a float number representing the time step size
23+
:param dt: a float number representing the step size
2424
:type dt: float
2525
2626
:param x_hat: array of smoothed estimation of x

0 commit comments

Comments
 (0)