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:
- 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:
- 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.
polyorder (int) – The order of the polynomial used to fit the samples.
derivative (int) – The order of the derivative to compute. Default is 0.
- Returns:
A result object containing all of the columns of input_data smoothed using the Savitzky-Golay filter.
- Return type:
- 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) – Additional keyword arguments for the interpolator.
- 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) – Additional keyword arguments for the interpolator.
- 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) – Additional keyword arguments for the interpolator.
- 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) – Additional keyword arguments for the interpolator.
- Returns:
The Akima interpolator.
- Return type:
Callable[[NDArray[np.float64]], NDArray[np.float64]]