pysdic.apply_central_finite_difference#

apply_central_finite_difference(data, order, axis=-1, spacing=1.0, accuracy=2, mode='reflect', value=0.0)[source]#

Apply the central finite difference operator to a time series data array along a specified axis.

A convolution operation is performed between the input data and the central finite difference kernel to approximate the temporal derivative of the specified order.

The available modes for handling borders are: ‘reflect’, ‘constant’, ‘nearest’, ‘mirror’, ‘wrap’.

Mode

Description

‘reflect’

\((d c b a | a b c d | d c b a)\)

‘constant’

\((k k k k | a b c d | k k k k)\)

‘nearest’

\((a a a a | a b c d | d d d d)\)

‘mirror’

\((d c b | a b c d | c b a)\)

‘wrap’

\((a b c d | a b c d | a b c d)\)

Note

The input data will be converted to numpy.float64.

Parameters:
  • data (ArrayLike) – The input time series data array.

  • order (Integral) – The order of the derivative to approximate (e.g., 1 for first derivative, 2 for second derivative).

  • axis (Optional[Integral], optional) – The axis along which to apply the finite difference operator. Default is -1.

  • spacing (Number, optional) – The time step size \(h\). Default is 1.0.

  • accuracy (Integral, optional) – The desired accuracy order of the approximation. Must be a even integer. Default is 2.

  • mode (str, optional) – The mode parameter determines how the input array is extended when the filter overlaps a border. Default is 'reflect'.

  • value (Number, optional) – The value to use for padding when mode is set to 'constant'. Default is 0.0.

Returns:

The resulting array after applying the central finite difference operator with the same shape as the input data.

Return type:

numpy.ndarray

Raises:

ValueError – If the order or accuracy are not positive integers. If the accuracy is not an even integer. If the spacing is not a strictly positive number. If the mode is not a valid string option for scipy.ndimage.correlate1d().

See also

compute_central_finite_difference_coefficients()

To compute the central finite difference coefficients.

apply_forward_finite_difference()

To apply the forward finite difference operator.

apply_backward_finite_difference()

To apply the backward finite difference operator.

Examples

>>> data = numpy.array([0.0, 1.0, 4.0, 9.0, 16.0])
>>> apply_central_finite_difference(data, order=1, spacing=1.0, accuracy=2)
array([0.5, 2., 4., 6., 3.5])