pyprobe.analysis.smoothing module#

Module containing methods for smoothing noisy experimental data.

spline_smoothing(input_data, target_column, smoothing_lambda=None, x='Time [s]')#

A method for smoothing noisy data using a spline.

Parameters:
  • input_data (RawData | Procedure | Experiment | Cycle | Step | Result) – The input data to smooth.

  • target_column (str) – The name of the target variable to smooth.

  • smoothing_lambda (float | None) – The smoothing parameter. Default is None.

  • x (str) – The name of the x variable for the spline curve fit. Default is “Time [s]”.

Returns:

A result object containing the data from input data with the target column smoothed using a spline, and the gradient of the smoothed data with respect to the x variable.

Return type:

Result

downsample(input_data, target_column, sampling_interval, monotonic=True, occurrence='first')#

Downsample a DataFrame to a specified interval.

This function uses two different methods for downsampling depending on whether the target column is monotonic or not. - If the target column is monotonic, the data is binned into intervals of the specified size and the desired occurrence within each bin is selected. - If the target column is not monotonic, the data is looped through and compared to the previously sampled point to determine if the interval condition is met.

The monotonic algorithm is faster and more efficient, while the non-monotonic guarantees that the interval condition is met.

Parameters:
  • input_data (RawData | Procedure | Experiment | Cycle | Step | Result) – The input data to downsample.

  • target_column (str) – The target column to downsample.

  • sampling_interval (float) – The desired minimum interval between points.

  • monotonic (bool) – If True, the target_column is assumed to be monotonic. Default is True. If False, the target_column is assumed to be non-monotonic. Each point in the target column is compared to the previously sampled point to determine if the interval condition is met.

  • occurrence (Literal['first', 'last', 'middle']) – The occurrence to take when downsampling. Default is ‘first’. This argument is only used when the target column is monotonic, otherwise the first occurrence when the interval condition is met is taken.

Returns:

A result object containing the downsampled DataFrame.

Return type:

Result

savgol_smoothing(input_data, target_column, window_length, polyorder, derivative=0)#

Smooth noisy data using a Savitzky-Golay filter.

Parameters:
  • input_data (RawData | Procedure | Experiment | Cycle | Step | Result) – The input data to smooth.

  • target_column (str) – The name of the target variable to smooth.

  • window_length (int) – The length of the filter window. Must be a positive odd integer.

  • polynomial_order – The order of the polynomial used to fit the samples.

  • derivative (int) – The order of the derivative to compute. Default is 0.

  • polyorder (int)

Returns:

A result object containing all of the columns of input_data smoothed using the Savitzky-Golay filter.

Return type:

Result

linear_interpolator(x, y, **kwargs)#

Create a linear interpolator.

Parameters:
  • x (NDArray[np.float64]) – The x data.

  • y (NDArray[np.float64]) – The y data.

  • kwargs (Any)

Returns:

The linear interpolator.

Return type:

Callable[[NDArray[np.float64]], NDArray[np.float64]]

cubic_interpolator(x, y, **kwargs)#

Create a Scipy cubic spline interpolator.

Parameters:
  • x (NDArray[np.float64]) – The x data.

  • y (NDArray[np.float64]) – The y data.

  • kwargs (Any)

Returns:

The cubic spline interpolator.

Return type:

Callable[[NDArray[np.float64]], NDArray[np.float64]]

pchip_interpolator(x, y, **kwargs)#

Create a Scipy Pchip interpolator.

Parameters:
  • x (NDArray[np.float64]) – The x data.

  • y (NDArray[np.float64]) – The y data.

  • kwargs (Any)

Returns:

The Pchip interpolator.

Return type:

Callable[[NDArray[np.float64]], NDArray[np.float64]]

akima_interpolator(x, y, **kwargs)#

Create a Scipy Akima interpolator.

Parameters:
  • x (NDArray[np.float64]) – The x data.

  • y (NDArray[np.float64]) – The y data.

  • kwargs (Any)

Returns:

The Akima interpolator.

Return type:

Callable[[NDArray[np.float64]], NDArray[np.float64]]

pydantic model Smoothing(*, input_data)#

Bases: BaseModel

A class for smoothing noisy experimental data.

Smoothing methods return result objects containing the same columns as the input data, but with the target column smoothed using the specified method.

Parameters:

input_data (Result)

Return type:

None

field input_data: Result [Required]#

The input data for the smoothing.

spline_smoothing(target_column, smoothing_lambda=None, x='Time [s]')#

A method for smoothing noisy data using a spline.

Parameters:
  • target_column (str) – The name of the target variable to smooth.

  • smoothing_lambda (float, optional) – The smoothing parameter. Default is None.

  • x (str, optional) – The name of the x variable for the spline curve fit. Default is “Time [s]”.

Returns:

A result object containing the data from input data with the target column smoothed using a spline, and the gradient of the smoothed data with respect to the x variable.

Return type:

Result

downsample(target_column, sampling_interval, occurrence='first')#

Downsample a DataFrame to a specified interval.

Requires the target column to be monotonic.

Parameters:
  • target_column (str) – The target column to downsample.

  • sampling_interval (float) – The desired minimum interval between points.

  • occurrence (Literal['first', 'last', 'middle'], optional) – The occurrence to take when downsampling. Default is ‘first’.

  • time_column (str, optional) – The time column to use for downsampling. Default is ‘Time [s]’.

Returns:

A result object containing the downsampled DataFrame.

Return type:

Result

level_smoothing(target_column, interval, monotonic=False)#

Smooth noisy data by resampling to a specified interval.

Parameters:
  • target_column (str) – The name of the target variable to smooth.

  • interval (float) – The desired minimum interval between points.

  • monotonic (bool, optional) – If True, the target_column is assumed to be monotonic. Default is False.

Returns:

A result object containing all of the columns of input_data resampled to the specified interval for the target column.

Return type:

Result

savgol_smoothing(target_column, window_length, polyorder, derivative=0)#

Smooth noisy data using a Savitzky-Golay filter.

Parameters:
  • target_column (str) – The name of the target variable to smooth.

  • window_length (int) – The length of the filter window. Must be a positive odd integer.

  • polynomial_order (int) – The order of the polynomial used to fit the samples.

  • derivative (int, optional) – The order of the derivative to compute. Default is 0.

  • polyorder (int)

Returns:

A result object containing all of the columns of input_data smoothed using the Savitzky-Golay filter.

Return type:

Result