epyr.baseline.selection
Region selection utilities for baseline correction.
This module provides functions for creating and managing baseline regions for both 1D and 2D EPR data.
Functions
|
Combine multiple boolean masks using logical AND. |
|
Create a mask that excludes the center portion of 1D data. |
|
Create a mask that excludes the center portion of 2D data. |
|
Create a mask that excludes points at the beginning and end of 1D data. |
|
Boolean mask for 1D data, marking which points to keep for a fit. |
|
Boolean mask for 2D data, marking which points to keep for a fit. |
|
Build a 1D baseline mask combining all exclusion criteria. |
|
Build a 2D baseline mask combining all exclusion criteria. |
|
Validate that 1D regions are within data bounds and properly formatted. |
|
Validate that 2D regions are within data bounds and properly formatted. |
- epyr.baseline.selection.create_region_mask_1d(x, regions, mode='exclude')[source]
Boolean mask for 1D data, marking which points to keep for a fit.
- Parameters:
- Returns:
Truewhere the point should be used for fitting.- Return type:
np.ndarray of bool
Examples
>>> import numpy as np >>> from epyr.baseline import create_region_mask_1d >>> x = np.arange(10) >>> mask = create_region_mask_1d(x, [(3, 5)], mode="exclude") >>> mask.astype(int) array([1, 1, 1, 0, 0, 0, 1, 1, 1, 1])
- epyr.baseline.selection.create_region_mask_2d(X, Y, regions, mode='exclude')[source]
Boolean mask for 2D data, marking which points to keep for a fit.
- Parameters:
X (np.ndarray) – Coordinate meshgrids, identical shape.
Y (np.ndarray) – Coordinate meshgrids, identical shape.
regions (list of ((float, float), (float, float))) –
[((x_lo, x_hi), (y_lo, y_hi)), ...]. Inclusive bounds.mode ({'exclude', 'include'}, optional) –
'exclude'masks out the listed rectangles (default);'include'keeps only those rectangles.
- Returns:
Same shape as
X.Truewhere the point should be used.- Return type:
np.ndarray of bool
Examples
>>> import numpy as np >>> from epyr.baseline import create_region_mask_2d >>> X, Y = np.meshgrid(np.arange(5), np.arange(5)) >>> mask = create_region_mask_2d(X, Y, [((1, 3), (1, 3))], mode="exclude") >>> int(mask.sum()) # 25 - 3*3 inner block 16
- epyr.baseline.selection.create_center_exclusion_mask_1d(x, center_fraction=0.3)[source]
Create a mask that excludes the center portion of 1D data.
This is useful for CW EPR spectra where the signal is in the center and we want to fit the baseline using the wings.
- epyr.baseline.selection.create_center_exclusion_mask_2d(X, Y, center_fraction=0.3)[source]
Create a mask that excludes the center portion of 2D data.
- epyr.baseline.selection.create_edge_exclusion_mask_1d(x, exclude_initial=0, exclude_final=0)[source]
Create a mask that excludes points at the beginning and end of 1D data.
This is useful for time-series data where initial/final points may have artifacts or noise.
- epyr.baseline.selection.combine_masks(*masks)[source]
Combine multiple boolean masks using logical AND.
- epyr.baseline.selection.get_baseline_regions_1d(x, y, exclude_center=True, center_fraction=0.3, exclude_initial=0, exclude_final=0, manual_regions=None, region_mode='exclude')[source]
Build a 1D baseline mask combining all exclusion criteria.
- Parameters:
x (ndarray) – X-coordinate array
y (ndarray) – Y-data array
exclude_center (bool) – Whether to exclude center region
center_fraction (float) – Fraction of center to exclude
exclude_initial (int) – Number of initial points to exclude
exclude_final (int) – Number of final points to exclude
manual_regions (List[Tuple[float, float]] | None) – List of manually specified regions
region_mode (str) – How to handle manual_regions (‘exclude’ or ‘include’)
- Returns:
Boolean mask array for baseline fitting
- Return type:
- epyr.baseline.selection.get_baseline_regions_2d(X, Y, Z, exclude_center=True, center_fraction=0.3, manual_regions=None, region_mode='exclude')[source]
Build a 2D baseline mask combining all exclusion criteria.
- Parameters:
X (ndarray) – X-coordinate meshgrid
Y (ndarray) – Y-coordinate meshgrid
Z (ndarray) – Z-data array
exclude_center (bool) – Whether to exclude center region
center_fraction (float) – Fraction of center to exclude
manual_regions (List[Tuple[Tuple[float, float], Tuple[float, float]]] | None) – List of manually specified regions
region_mode (str) – How to handle manual_regions (‘exclude’ or ‘include’)
- Returns:
Boolean mask array for baseline fitting
- Return type:
- epyr.baseline.selection.validate_regions_1d(regions, x_min, x_max)[source]
Validate that 1D regions are within data bounds and properly formatted.
- epyr.baseline.selection.validate_regions_2d(regions, x_min, x_max, y_min, y_max)[source]
Validate that 2D regions are within data bounds and properly formatted.
- Parameters:
- Returns:
True if all regions are valid
- Raises:
ValueError – If regions are invalid
- Return type: