epyr.signalprocessing.preprocessing
Preprocessing utilities for time-domain EPR signal analysis.
Standalone, chainable functions for ESEEM, HYSCORE, and Rabi pipelines: remove_baseline, apodize, zero_pad.
Functions
|
Apply an apodization window to reduce spectral leakage from signal truncation. |
|
Fit and subtract a slowly-varying background from a time-domain EPR signal. |
|
Pad a signal with trailing zeros to increase FFT frequency resolution. |
- epyr.signalprocessing.preprocessing.remove_baseline(time, signal, method='polynomial', order=3, end_fraction=0.15, axis=1, plot=False)[source]
Fit and subtract a slowly-varying background from a time-domain EPR signal.
- Parameters:
time (np.ndarray) – Time axis, 1D array, any unit. For 2D data, must match the length of the signal along
axis.signal (np.ndarray) – Signal array, 1D or 2D.
method (str) –
'polynomial'or'exponential'.order (int) – Polynomial degree; ignored when
method='exponential'.end_fraction (float) – Fraction of trailing points used to anchor the polynomial fit. For exponential fits, the full time axis is used.
axis (int) – For 2D data: axis along which baseline is fitted and removed (0 = column-wise, 1 = row-wise). Default 1.
plot (bool) – Show a before/after figure.
- Returns:
signal_corrected (np.ndarray) – Signal with baseline subtracted, same shape as
signal.baseline (np.ndarray) – Fitted baseline array, same shape as
signal.
- Raises:
ValueError – If
methodis not recognised, ifsignalis not 1D or 2D, or ifaxisis invalid for 2D data.RuntimeError – If the exponential fit fails to converge.
- Return type:
Examples
>>> time = np.linspace(0, 500, 256) >>> signal = np.exp(-time / 200) + 0.05 * np.random.randn(256) >>> corrected, baseline = remove_baseline(time, signal, method='exponential')
- epyr.signalprocessing.preprocessing.apodize(signal, window='hann', alpha=None, half_window=None, axis='both', plot=False)[source]
Apply an apodization window to reduce spectral leakage from signal truncation.
- Parameters:
signal (np.ndarray) – Signal array, 1D or 2D.
window (str) – Window type: any key accepted by
apowin():'hann','hamming','blackman','kaiser','gaussian','exponential', etc.alpha (float, optional) – Shape parameter for
kaiserandgaussianwindows.half_window (str, optional) –
None(symmetric window),'left'(first half only), or'right'(second half only).axis (int or str) – For 2D data:
0,1, or'both'. When'both', a 2D window is built as the outer product of two 1D windows, one per axis. Ignored for 1D input.plot (bool) – Show a figure with the original signal, window shape, and windowed signal.
- Returns:
signal_windowed – Windowed signal, same shape as
signal.- Return type:
np.ndarray
- Raises:
ValueError – If
signalis not 1D or 2D, or ifaxisis invalid for 2D.
Examples
>>> signal = np.exp(-t / 120) * np.sin(2 * np.pi * 8.5e-3 * t) >>> windowed = apodize(signal, window='hann', half_window='right')
- epyr.signalprocessing.preprocessing.zero_pad(signal, factor=None, n_points=None, axis=-1, plot=False)[source]
Pad a signal with trailing zeros to increase FFT frequency resolution.
Exactly one of
factororn_pointsmust be supplied.- Parameters:
signal (np.ndarray) – Signal array, 1D or 2D.
factor (int, optional) – Multiplicative factor: output length =
factor * Nalongaxis.n_points (int, optional) – Absolute output length along
axis.axis (int or str) – Axis to pad. For 1D input this parameter is ignored. For 2D input:
0,1,-1(equivalent to1), or'both'(pad each axis independently with the same factor or n_points). Default-1.plot (bool) – Show a before/after figure.
- Returns:
signal_padded – Zero-padded signal, same dtype as
signal.- Return type:
np.ndarray
- Raises:
ValueError – If both or neither of
factor/n_pointsare given, ifn_pointsis shorter than the signal length, ifsignalis not 1D or 2D, or ifaxisis invalid for 2D.
Examples
>>> signal = np.ones(256) >>> padded = zero_pad(signal, factor=4) # 1024 points >>> padded = zero_pad(signal, n_points=1024)