post_treaters module
Define various smoothing functions for measured data.
- CONVOLUTION_MODES_T
Available modes for the running mean routine.
alias of
Literal[‘reflect’, ‘constant’, ‘nearest’, ‘mirror’, ‘wrap’]
- DEPRECATED_CONVOLUTION_MODES = ('full', 'same', 'valid')
Deprecated modes for the running mean routine.
- running_mean(input_data, n_mean, mode='nearest', **kwargs)[source]
Compute the running mean.
Deprecated since version 1.9.0: The modes listed in
DEPRECATED_CONVOLUTION_MODESwill call thenumpy.convolve()function. Prefer theCONVOLUTION_MODES_T, which will callscipy.ndimage.uniform_filter1d().See also
- Parameters:
input_data (
ndarray[tuple[Any,...],dtype[double]]) – Data to smooth of shapeN.n_mean (
int) – Number of points on which running mean is ran.mode (
Literal['reflect','constant','nearest','mirror','wrap'] |Literal['full','same','valid'], default:'nearest') – Convolution modes. Refer toscipy.ndimage.uniform_filter1d()documentation, which is the actual function that is called.
- Return type:
- Returns:
Smoothed data.
- lower_envelope(input_data, envelope_window, mode='nearest')[source]
Compute the lower envelope, i.e. the signal minimum without the bumps.
Todo
Illustration in documentation.
Todo
May also use
scipy.ndimage.percentile_filter(). May be more robust with noisy data or occasional downward spikes. To test.- Parameters:
input_data (
ndarray[tuple[Any,...],dtype[double]]) – Data to smooth of shapeN.envelope_window (
int) – Number of points on which lower envelope is taken.mode (
Literal['reflect','constant','nearest','mirror','wrap'], default:'nearest') – Convolution modes. Refer toscipy.ndimage.minimum_filter1d()documentation, which is the actual function that is called.
- Return type:
- Returns:
Smoothed data.
- average_y_for_nearby_x_within_distance(y_values, x_values, tol=1e-06, max_index_distance=1, keep_shape=True)[source]
Average
y_valuesmeasured at nearly identicalx_valuesThis function groups values in
y_valuesthat correspond tox_valueswhich are numerically close (withintol) and occur withinmax_index_distanceof each other. These groupedy_valuesare averaged, and the result is returned either in a shape-preserving format or as a compact array, depending onkeep_shape.- Parameters:
y_values (
ndarray[tuple[Any,...],dtype[double]]) – The dependent variable values to average.x_values (
ndarray[tuple[Any,...],dtype[double]]) – The independent variable values used to group correspondingy_values.tol (
float, default:1e-06) – Maximum absolute difference under whichx_valuesare considered equal.max_index_distance (
int, default:1) – Maximum index separation allowed when grouping similarx_values. Prevents averaging across distant, unrelated measurements.keep_shape (
bool, default:True) – IfTrue, the returned array has the same shape as the input, with only the first element of each group containing the average and others filled withnp.nan. IfFalse(not recommended), returns a compact array with only the averaged values.
- Return type:
- Returns:
The averaged
y_values, either shape-preserving or compact.- Raises:
ValueError – If
x_valuesandy_valuesdo not have the same shape.
Examples
>>> x = np.array([100.0, 100.0, 200.0, 200.0]) >>> y = np.array([1.0, 3.0, 10.0, 14.0]) >>> average_y_for_nearby_x_within_distance(y, x) array([2.0, nan, 12.0, nan])
>>> average_y_for_nearby_x_within_distance(y, x, keep_shape=False) array([2.0, 12.0])
- drop_x_where_y_is_nan(x_values, y_values)[source]
Return
x_valueswithout indexes wherey_valuesisnp.nan.This can be used in for
RPAwhen some current data is dropped (keep_shape = False) but we still want the same shape for potential.
- replace_data_under_threshold(input_data, threshold, replace_value, min_consecutive=1)[source]
Replace data where
min_consecutivevalues are belowthreshold.Data is replaced by
replace_value.- Parameters:
input_data (
ndarray[tuple[Any,...],dtype[double]]) – Data to filter.threshold (
float) – Threshold under which data is considered noise.replace_value (
float) – Value to replace the data with.min_consecutive (
int, default:1) – Minimum number of consecutive values below the threshold required for replacement.
- Return type:
- Returns:
Modified data array.
- get_data_above_noise(data, noise_level=None, level=None)[source]
Detect signal above noise, return it.
- Parameters:
data (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – Array of data in pulsed shape, such as power pulse or synch.noise_level (
float|None, default:None) – Absolute level of noise. If not provided, we uselevelto compute it.level (
float|None, default:None) – Noise percentile wrtdata, in \(\mathrm{%}\).
- Returns:
Only the widest pulse detected in the signal.
- Return type:
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]