mioXpektron.baseline.baseline_base
Functions
|
Baseline-correct a 1‑D spectrum with pybaselines or custom filters. |
Return a sorted list of available baseline algorithms. |
|
|
Compute RFZN, NAR, SNR, BBI, BR, NBC for a single corrected spectrum. |
|
Read a ToF‑SIMS table from CSV/TSV/TXT with flexible separators. |
|
A compact parameter grid for common methods. |
Classes
|
- mioXpektron.baseline.baseline_base.baseline_method_names()[source]
Return a sorted list of available baseline algorithms.
Based on pybaselines.Baseline public callables, plus two custom filters (“median_filter”, “adaptive_window”) and a ‘poly’ alias. A few methods that are not 1‑D safe or impractically slow are removed.
- mioXpektron.baseline.baseline_base.small_param_grid_preset(n_points=None)[source]
A compact parameter grid for common methods.
Keys must match pybaselines.Baseline method names (plus ‘poly’ and our two filters).
- Parameters:
n_points (int, optional) – Number of data points in spectrum. If provided, window_size will be calculated adaptively as a percentage of data size. If None, uses moderate defaults suitable for ~100K point spectra.
- Returns:
Parameter grid with method names as keys
- Return type:
Notes
Window sizes are calculated as: - Small: 0.05% of data (min 51) - Medium: 0.10% of data (min 101) - Large: 0.20% of data (min 501)
This adaptive scaling ensures that filter methods perform consistently across datasets of different sizes. Fixed window sizes work poorly: - For 10K points: window=101 is 1.0% (OK) - For 1M points: window=101 is 0.01% (too small, causes jagged baselines)
Examples
>>> # Auto-scale for 938K point spectrum >>> grid = small_param_grid_preset(n_points=938000) >>> grid['median_filter'] [{'window_size': 469}, {'window_size': 938}, {'window_size': 1876}]
>>> # Use defaults for unknown size >>> grid = small_param_grid_preset() >>> grid['median_filter'] [{'window_size': 501}, {'window_size': 1001}, {'window_size': 2001}]
- mioXpektron.baseline.baseline_base.baseline_correction(intensities, method='airpls', window_size=101, poly_order=4, clip_negative=True, return_baseline=False, **kwargs)[source]
Baseline-correct a 1‑D spectrum with pybaselines or custom filters.
- Parameters:
intensities (array-like) – Raw y values.
method (str) – Algorithm name; see
baseline_method_names().window_size (int) – Kernel width for the two custom filters.
poly_order (int) – Polynomial order for the ‘poly’ alias.
clip_negative (bool) – If True, negative corrected values are set to 0.
return_baseline (bool) – If True, also return the estimated baseline.
**kwargs – Forwarded to the chosen algorithm (e.g. lam=1e6, p=0.01).
- Return type:
corrected or (corrected, baseline)
- mioXpektron.baseline.baseline_base.read_spectrum_table(path)[source]
Read a ToF‑SIMS table from CSV/TSV/TXT with flexible separators.
- class mioXpektron.baseline.baseline_base.MetricResult(rfzn: 'float', nar: 'float', snr: 'float', bbi: 'float', br: 'float', nbc: 'float')[source]
Bases:
object
- mioXpektron.baseline.baseline_base.compute_metrics(y_corr, y_raw, baseline, x, noise_mask=None, topk=5, raw_noise_quantile=0.2)[source]
Compute RFZN, NAR, SNR, BBI, BR, NBC for a single corrected spectrum.
Notes
RFZN: RMS of y_corr in baseline-only region (noise_mask). If mask is not supplied, it is derived from the raw intensities (bottom-q).
NAR: sum(-y_corr[y<0]) / sum(|y_corr|); lower is better.
SNR: median prominence of top-K peaks divided by noise sigma.
BBI: median(y_corr[noise_mask]); lower magnitude is better.
BR: RMS of d²(baseline)/dx² in baseline-only regions; requires baseline and x.
NBC: fraction of points where y_corr < 0 (before clipping).