mioXpektron.recalibrate

Recalibration utilities for the Xpektron toolkit.

class mioXpektron.recalibrate.FlexibleCalibrator(config=None)[source]

Bases: object

Single-model calibrator with user-selected method.

Unlike AutoCalibrator, this calibrator fits exactly one model and provides more control over outlier rejection, quality thresholds, and per-model parameters.

Parameters:

config (FlexibleCalibConfig | None)

last_autodetect_methods: Dict[str, List[str]]
last_reference_masses_initial: List[float]
last_reference_masses_used: List[float]
last_reference_masses_screened_out: List[float]
last_reference_mass_screening: DataFrame
last_failed_or_excluded_files: DataFrame
calibrate(files, calib_channels_dict=None)[source]

Calibrate all files using the selected calibration method.

Parameters:
Return type:

DataFrame

class mioXpektron.recalibrate.FlexibleCalibConfig(reference_masses, calibration_method='quad_sqrt', output_folder='calibrated_spectra', output_mz_range=None, max_workers=None, autodetect_tol_da=None, autodetect_tol_ppm=None, autodetect_method='gaussian', autodetect_fallback_policy='max', autodetect_strategy='mz', prefer_recompute_from_channel=False, outlier_threshold=3.0, use_outlier_rejection=True, max_iterations=3, min_calibrants=3, max_ppm_threshold=100.0, fail_on_high_error=False, retry_high_error_with_pruning=False, retry_high_error_with_mz_fallback=False, retry_high_error_max_removals=5, exclude_reference_masses=<factory>, auto_screen_reference_masses=False, screen_max_mean_abs_ppm=50.0, screen_max_median_abs_ppm=None, screen_min_valid_fraction=0.8, screen_min_count=3, screen_exclude_below_mz=1.5, spline_smoothing=None, multisegment_breakpoints=<factory>, instrument_params=<factory>, save_diagnostic_plots=False, verbose=True, auto_tune=False)[source]

Bases: object

Configuration for flexible calibration with a single user-selected method.

Parameters:
  • reference_masses (List[float])

  • calibration_method (Literal['quad_sqrt', 'linear_sqrt', 'poly2', 'reflectron', 'multisegment', 'spline', 'physical'])

  • output_folder (str)

  • output_mz_range (Tuple[float | None, float | None] | None)

  • max_workers (int | None)

  • autodetect_tol_da (float | Sequence[float] | None)

  • autodetect_tol_ppm (float | None)

  • autodetect_method (str)

  • autodetect_fallback_policy (str)

  • autodetect_strategy (str)

  • prefer_recompute_from_channel (bool)

  • outlier_threshold (float)

  • use_outlier_rejection (bool)

  • max_iterations (int)

  • min_calibrants (int)

  • max_ppm_threshold (float | None)

  • fail_on_high_error (bool)

  • retry_high_error_with_pruning (bool)

  • retry_high_error_with_mz_fallback (bool)

  • retry_high_error_max_removals (int)

  • exclude_reference_masses (List[float])

  • auto_screen_reference_masses (bool)

  • screen_max_mean_abs_ppm (float)

  • screen_max_median_abs_ppm (float | None)

  • screen_min_valid_fraction (float)

  • screen_min_count (int)

  • screen_exclude_below_mz (float)

  • spline_smoothing (float | None)

  • multisegment_breakpoints (List[float])

  • instrument_params (Dict[str, float])

  • save_diagnostic_plots (bool)

  • verbose (bool)

  • auto_tune (bool)

reference_masses: List[float]
calibration_method: Literal['quad_sqrt', 'linear_sqrt', 'poly2', 'reflectron', 'multisegment', 'spline', 'physical'] = 'quad_sqrt'
output_folder: str = 'calibrated_spectra'
output_mz_range: Tuple[float | None, float | None] | None = None
max_workers: int | None = None
autodetect_tol_da: float | Sequence[float] | None = None
autodetect_tol_ppm: float | None = None
autodetect_method: str = 'gaussian'
autodetect_fallback_policy: str = 'max'
autodetect_strategy: str = 'mz'
prefer_recompute_from_channel: bool = False
outlier_threshold: float = 3.0
use_outlier_rejection: bool = True
max_iterations: int = 3
min_calibrants: int = 3
max_ppm_threshold: float | None = 100.0
fail_on_high_error: bool = False
retry_high_error_with_pruning: bool = False
retry_high_error_with_mz_fallback: bool = False
retry_high_error_max_removals: int = 5
exclude_reference_masses: List[float]
auto_screen_reference_masses: bool = False
screen_max_mean_abs_ppm: float = 50.0
screen_max_median_abs_ppm: float | None = None
screen_min_valid_fraction: float = 0.8
screen_min_count: int = 3
screen_exclude_below_mz: float = 1.5
spline_smoothing: float | None = None
multisegment_breakpoints: List[float]
instrument_params: Dict[str, float]
save_diagnostic_plots: bool = False
verbose: bool = True
auto_tune: bool = False
class mioXpektron.recalibrate.AutoCalibrator(config=None)[source]

Bases: object

Automatic multi-model calibrator.

Fits all requested models, selects the best one per file, and writes calibrated spectra.

Parameters:

config (AutoCalibConfig | None)

last_autodetect_methods: Dict[str, List[str]]
calibrate(files, calib_channels_dict=None)[source]

Calibrate all files with automatic model selection.

Parameters:
Return type:

DataFrame

class mioXpektron.recalibrate.AutoCalibConfig(reference_masses, output_folder='calibrated_spectra', max_workers=None, autodetect_tol_da=None, autodetect_tol_ppm=None, autodetect_method='gaussian', autodetect_fallback_policy='max', autodetect_strategy='mz', prefer_recompute_from_channel=False, outlier_threshold=3.0, use_outlier_rejection=True, max_iterations=3, model=None, models_to_try=None, prefer_physical_models=True, min_calibrants=3, max_ppm_warning=100.0, max_ppm_error=500.0, use_bootstrap_init=True, spline_smoothing=None, multisegment_breakpoints=<factory>, instrument_params=<factory>)[source]

Bases: object

Universal calibration configuration with robust options.

Parameters:
  • reference_masses (list of float) – Known calibrant ion masses (m/z).

  • model (str, optional) – Convenience shortcut — a single model name (or common alias like 'quadratic', 'tof', 'linear'). Resolved into models_to_try during __post_init__. Ignored when models_to_try is explicitly provided.

  • models_to_try (list of str, optional) – Explicit list of model names to fit. Default: all production-ready models (excludes experimental ones such as multisegment and physical).

  • output_folder (str)

  • max_workers (int | None)

  • autodetect_tol_da (float | None)

  • autodetect_tol_ppm (float | None)

  • autodetect_method (str)

  • autodetect_fallback_policy (str)

  • autodetect_strategy (str)

  • prefer_recompute_from_channel (bool)

  • outlier_threshold (float)

  • use_outlier_rejection (bool)

  • max_iterations (int)

  • prefer_physical_models (bool)

  • min_calibrants (int)

  • max_ppm_warning (float)

  • max_ppm_error (float)

  • use_bootstrap_init (bool)

  • spline_smoothing (float | None)

  • multisegment_breakpoints (List[float])

  • instrument_params (Dict[str, float])

reference_masses: List[float]
output_folder: str = 'calibrated_spectra'
max_workers: int | None = None
autodetect_tol_da: float | None = None
autodetect_tol_ppm: float | None = None
autodetect_method: str = 'gaussian'
autodetect_fallback_policy: str = 'max'
autodetect_strategy: str = 'mz'
prefer_recompute_from_channel: bool = False
outlier_threshold: float = 3.0
use_outlier_rejection: bool = True
max_iterations: int = 3
model: str | None = None
models_to_try: List[str] | None = None
prefer_physical_models: bool = True
min_calibrants: int = 3
max_ppm_warning: float = 100.0
max_ppm_error: float = 500.0
use_bootstrap_init: bool = True
spline_smoothing: float | None = None
multisegment_breakpoints: List[float]
instrument_params: Dict[str, float]
class mioXpektron.recalibrate.FlexibleCalibratorDebug(config=None)[source]

Bases: FlexibleCalibrator

Debug variant of FlexibleCalibrator with verbose peak-picking.

Inherits all calibration logic and overrides only _autodetect_channels to route through the diagnostic versions of _enhanced_pick_channels and _parabolic_peak_center.

Parameters:

config (FlexibleCalibConfig | None)

mioXpektron.recalibrate.FlexibleCalibConfigDebug

alias of FlexibleCalibConfig

Modules

auto_calibrator

AutoCalibrator — automatic multi-model calibration for mass spectrometry.

calibrate_spectrum

flexible_calibrator

FlexibleCalibrator — single-model calibration with user-selected method.

flexible_calibrator_debug

Debug version of FlexibleCalibrator with diagnostic logging.

peak_picker

peak_picker.py Identify the most intense point within ±0.5 Da of eight reference m/z values in every calibrated ToF-SIMS spectrum and return the results as a nested Python dictionary.

peak_picker_uncal

peak_picker.py Identify the most intense point within ±0.5 Da of eight reference m/z values in every calibrated ToF-SIMS spectrum and return the results as a nested Python dictionary.

test_diagnostic

Test script to demonstrate the diagnostic logging in flexible_calibrator_debug.py