epyr.baseline.correction
Core baseline correction algorithms for EPR data.
This module contains the main baseline correction functions that work directly with data from epyr.eprload().
Functions
|
Bi-exponential baseline correction for 1D EPR data. |
|
Polynomial baseline correction for 1D EPR data. |
|
Polynomial baseline correction for 2D EPR data. |
|
Stretched-exponential baseline correction for 1D EPR data. |
- epyr.baseline.correction.baseline_polynomial_1d(x, y, params=None, order=2, exclude_center=True, center_fraction=0.3, manual_regions=None, region_mode='exclude', interactive=False)[source]
Polynomial baseline correction for 1D EPR data.
Fits a polynomial to selected baseline regions and subtracts it from the full dataset. Suited to CW EPR spectra with smooth drift.
- Parameters:
x (np.ndarray or None) – Field axis from
epyr.eprload(). If None or length mismatch, falls back to point indices.y (np.ndarray) – 1D spectrum from
epyr.eprload().params (dict, optional) – Parameter dictionary from
epyr.eprload()(unused for the fit itself; reserved for future axis-aware extensions).order (int, optional) – Polynomial order. Typical range 1-4. Default 2.
exclude_center (bool, optional) – Exclude a centred fraction of the data from fitting (where the signal is expected). Default True.
center_fraction (float, optional) – Width of the excluded central window, as a fraction of the data. Default 0.3.
manual_regions (list of (float, float), optional) – Explicit (x_low, x_high) regions. Combined with
region_mode.region_mode ({'exclude', 'include'}, optional) –
'exclude'removesmanual_regionsfrom the fit;'include'keeps only those regions. Default'exclude'.interactive (bool, optional) – Launch the matplotlib region selector. Requires an interactive backend. Default False.
- Returns:
corrected (np.ndarray) – Baseline-subtracted spectrum.
baseline (np.ndarray) – Fitted polynomial evaluated on the full axis.
- Return type:
Examples
>>> from epyr import eprload, baseline_polynomial_1d >>> x, y, params, _ = eprload("examples/data/130406SB_CaWO4_Er_CW_5K_20.DSC") >>> corrected, baseline = baseline_polynomial_1d(x, y, params, order=3) >>> corrected.shape == y.shape True
Fit only on user-defined wings (exclude resonance region):
>>> wings = [(3300, 3400), (3550, 3700)] >>> corrected, _ = baseline_polynomial_1d( ... x, y, params, order=2, ... manual_regions=wings, region_mode="include", ... )
- epyr.baseline.correction.baseline_polynomial_2d(x, y, params=None, order=1, exclude_center=True, center_fraction=0.3, manual_regions=None, region_mode='exclude', interactive=False, use_real_part=False)[source]
Polynomial baseline correction for 2D EPR data.
Fits a 2D polynomial surface to selected regions and subtracts it from the full dataset. Useful for 2D experiments (DEER, Rabi 2D, etc.).
- Parameters:
x (np.ndarray, list of np.ndarray, or None) – Axis data from
epyr.eprload(). A two-element list[xa, ya]sets both axes. None falls back to indices.y (np.ndarray) – 2D spectrum, shape
(ny, nx).params (dict, optional) – Parameter dictionary from
epyr.eprload().order (int or (int, int), optional) – Polynomial order.
intapplies the same order to both axes; a tuple sets(order_x, order_y)independently. Default 1.exclude_center (bool, optional) – Exclude a centred rectangular block of the data from the fit. Default True.
center_fraction (float, optional) – Width of that block along each axis, as a fraction. Default 0.3.
manual_regions (list of ((x1, x2), (y1, y2)), optional) – Explicit rectangular regions.
region_mode ({'exclude', 'include'}, optional) – How to combine
manual_regionswith the fit mask. Default'exclude'.interactive (bool, optional) – Launch the matplotlib 2D region selector. Default False.
use_real_part (bool, optional) – For complex data, fit on
y.real. Default False.
- Returns:
corrected (np.ndarray) – Baseline-subtracted surface.
baseline (np.ndarray) – Fitted polynomial evaluated on the full grid.
- Return type:
Examples
>>> from epyr import eprload, baseline_polynomial_2d >>> x, y, params, _ = eprload("examples/data/Rabi2D_GdCaWO4_13dB_3057G.DSC") >>> corrected, baseline = baseline_polynomial_2d(x, y, params, order=(2, 1)) >>> corrected.shape == y.shape True
- epyr.baseline.correction.baseline_stretched_exponential_1d(x, y, params=None, use_real_part=True, exclude_initial=0, exclude_final=0, manual_regions=None, region_mode='exclude', interactive=False, beta_range=(0.01, 5.0), initial_guess=None)[source]
Stretched-exponential baseline correction for 1D EPR data.
Fits and removes a baseline of the form
\[b(x) = \mathrm{offset} + A \exp\!\left[-(x/\tau)^{\beta}\right]\]Typical use: T2 echo decay envelope removal before peak analysis.
- Parameters:
x (np.ndarray or None) – Time axis from
epyr.eprload(). Falls back to indices if None or length mismatch.y (np.ndarray) – 1D signal from
epyr.eprload().params (dict, optional) – Parameter dictionary from
epyr.eprload().use_real_part (bool, optional) – For complex
y, fit ony.real. Default True.exclude_initial (int, optional) – Drop the first / last N points from the fit. Default 0.
exclude_final (int, optional) – Drop the first / last N points from the fit. Default 0.
manual_regions (list of (float, float), optional) – Explicit (x_low, x_high) windows.
region_mode ({'exclude', 'include'}, optional) – Combine
manual_regionswith the fit mask. Default'exclude'.interactive (bool, optional) – Launch the matplotlib region selector. Default False.
beta_range ((float, float), optional) – Bounds on the stretching exponent. Default
(0.01, 5.0).initial_guess (dict, optional) – Seed values, any subset of
{'A', 'tau', 'beta', 'offset'}.
- Returns:
corrected (np.ndarray) – Baseline-subtracted signal.
baseline (np.ndarray) – Fitted baseline on the full axis.
- Return type:
Examples
>>> from epyr import eprload, baseline_stretched_exponential_1d >>> path = "examples/data/ESEdecay_2D_rotgon_035_07.3K_h80_9.73687GHz_B3.DSC" >>> x, y, params, _ = eprload(path) >>> # take a single trace from the 2D dataset >>> trace = y[0] >>> corrected, baseline = baseline_stretched_exponential_1d( ... x[0], trace, params, exclude_initial=5, ... ) >>> corrected.shape == trace.shape True
- epyr.baseline.correction.baseline_bi_exponential_1d(x, y, params=None, use_real_part=True, exclude_initial=0, exclude_final=0, manual_regions=None, region_mode='exclude', interactive=False, tau_ratio_min=2.5, initial_guess=None)[source]
Bi-exponential baseline correction for 1D EPR data.
Fits and removes a baseline of the form
\[b(x) = \mathrm{offset} + A_1 e^{-x/\tau_1} + A_2 e^{-x/\tau_2}\]Suited to decays with two well-separated relaxation channels.
- Parameters:
x (np.ndarray or None) – Time axis from
epyr.eprload(). Falls back to indices if None.y (np.ndarray) – 1D signal from
epyr.eprload().params (dict, optional) – Parameter dictionary from
epyr.eprload().use_real_part (bool, optional) – For complex
y, fit ony.real. Default True.exclude_initial (int, optional) – Drop the first / last N points from the fit. Default 0.
exclude_final (int, optional) – Drop the first / last N points from the fit. Default 0.
manual_regions (list of (float, float), optional) – Explicit (x_low, x_high) windows.
region_mode ({'exclude', 'include'}, optional) – How to combine
manual_regionswith the fit mask.interactive (bool, optional) – Launch the matplotlib region selector. Default False.
tau_ratio_min (float, optional) – Minimum ratio
tau2 / tau1enforced during fitting to keep the two components separable. Default 2.5.initial_guess (dict, optional) – Seed values, any subset of
{'A1', 'tau1', 'A2', 'tau2', 'offset'}.
- Returns:
corrected (np.ndarray) – Baseline-subtracted signal.
baseline (np.ndarray) – Fitted baseline on the full axis.
- Return type:
Examples
>>> from epyr import eprload, baseline_bi_exponential_1d >>> path = "examples/data/ESEdecay_2D_rotgon_035_07.3K_h80_9.73687GHz_B3.DSC" >>> x, y, params, _ = eprload(path) >>> trace = y[0] >>> corrected, baseline = baseline_bi_exponential_1d( ... x[0], trace, params, tau_ratio_min=3.0, ... ) >>> corrected.shape == trace.shape True