_smooth_finite_difference

Apply smoothing method before finite difference

pynumdiff.smooth_finite_difference._smooth_finite_difference.butterdiff(x, dt, params, options={})

Perform butterworth smoothing on x with scipy.signal.filtfilt followed by first order finite difference

Parameters
  • x (np.array (float)) – array of time series to differentiate

  • dt (float) – time step size

  • params (list (int)) – [n, wn], n = order of the filter; wn = Cutoff frequency. For a discrete timeseries, the value is normalized to the range 0-1, where 1 is the Nyquist frequency.

  • options (dict {'iterate': (boolean), 'padmethod': string}) –

    an empty dictionary or a dictionary with 2 key value pair

    • ’iterate’: whether to run multiple iterations of the smoother. Note: iterate does nothing for median smoother.

    • ’padmethod’: “pad” or “gust”, see scipy.signal.filtfilt

Returns

a tuple consisting of:

  • x_hat: estimated (smoothed) x

  • dxdt_hat: estimated derivative of x

Return type

tuple -> (np.array, np.array)

pynumdiff.smooth_finite_difference._smooth_finite_difference.friedrichsdiff(x, dt, params, options={})

Perform friedrichs smoothing by convolving friedrichs kernel with x followed by first order finite difference

Parameters
  • x (np.array (float)) – array of time series to differentiate

  • dt (float) – time step size

  • params (list (int)) – [filter_window_size] or if ‘iterate’ in options: [filter_window_size, num_iterations]

  • options (dict {'iterate': (boolean)}) –

    an empty dictionary or a dictionary with 1 key value pair

    • ’iterate’: whether to run multiple iterations of the smoother. Note: iterate does nothing for median smoother.

Returns

a tuple consisting of:

  • x_hat: estimated (smoothed) x

  • dxdt_hat: estimated derivative of x

Return type

tuple -> (np.array, np.array)

pynumdiff.smooth_finite_difference._smooth_finite_difference.gaussiandiff(x, dt, params, options={})

Perform gaussian smoothing by convolving gaussian kernel with x followed by first order finite difference

Parameters
  • x (np.array (float)) – array of time series to differentiate

  • dt (float) – time step size

  • params (list (int)) – [filter_window_size] or if ‘iterate’ in options: [filter_window_size, num_iterations]

  • options (dict {'iterate': (boolean)}) –

    an empty dictionary or a dictionary with 1 key value pair

    • ’iterate’: whether to run multiple iterations of the smoother. Note: iterate does nothing for median smoother.

Returns

a tuple consisting of:

  • x_hat: estimated (smoothed) x

  • dxdt_hat: estimated derivative of x

Return type

tuple -> (np.array, np.array)

pynumdiff.smooth_finite_difference._smooth_finite_difference.meandiff(x, dt, params, options={})

Perform mean smoothing by convolving mean kernel with x followed by first order finite difference

Parameters
  • x (np.array (float)) – array of time series to differentiate

  • dt (float) – time step size

  • params (list (int)) – [filter_window_size] or if ‘iterate’ in options: [filter_window_size, num_iterations]

  • options (dict {'iterate': (boolean)}) –

    an empty dictionary or a dictionary with 1 key value pair

    • ’iterate’: whether to run multiple iterations of the smoother. Note: iterate does nothing for median smoother.

Returns

a tuple consisting of:

  • x_hat: estimated (smoothed) x

  • dxdt_hat: estimated derivative of x

Return type

tuple -> (np.array, np.array)

pynumdiff.smooth_finite_difference._smooth_finite_difference.mediandiff(x, dt, params, options={})

Perform median smoothing using scipy.signal.medfilt followed by first order finite difference

Parameters
  • x (np.array (float)) – array of time series to differentiate

  • dt (float) – time step size

  • params (list (int) or int) – filter window size

  • options (dict {'iterate': (boolean)}) –

    an empty dictionary or a dictionary with 1 key value pair

    • ’iterate’: whether to run multiple iterations of the smoother. Note: iterate does nothing for median smoother.

Returns

a tuple consisting of:

  • x_hat: estimated (smoothed) x

  • dxdt_hat: estimated derivative of x

Return type

tuple -> (np.array, np.array)

pynumdiff.smooth_finite_difference._smooth_finite_difference.splinediff(x, dt, params, options={})

Perform spline smoothing on x with scipy.interpolate.UnivariateSpline followed by first order finite difference

Parameters
  • x (np.array (float)) – array of time series to differentiate

  • dt (float) – time step size

  • params (list (int)) – [k, s], k: Order of the spline. A kth order spline can be differentiated k times. s: Positive smoothing factor used to choose the number of knots. Number of knots will be increased until the smoothing condition is satisfied: sum((w[i] * (y[i]-spl(x[i])))**2, axis=0) <= s

  • options (dict {'iterate': (boolean)}) –

    an empty dictionary or a dictionary with 1 key value pair

    • ’iterate’: whether to run multiple iterations of the smoother. Note: iterate does nothing for median smoother.

Returns

a tuple consisting of:

  • x_hat: estimated (smoothed) x

  • dxdt_hat: estimated derivative of x

Return type

tuple -> (np.array, np.array)