mioXpektron.recalibrate.flexible_calibrator

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

Unlike AutoCalibrator which fits all models and picks the best, FlexibleCalibrator fits exactly one user-chosen model with optional iterative outlier rejection and quality-control thresholds.

All model fitting, inversion, and peak-detection functions live in the shared _models backend.

Author: Data Analysis Team @KaziLab.se Version: 0.0.1

Functions

select_stable_reference_masses(...[, ...])

Select a stable reference-mass subset based on cross-spectrum residuals.

summarize_reference_mass_stability(summary_df, *)

Summarize per-mass residual stability across the current calibration summary.

Classes

FlexibleCalibConfig(reference_masses[, ...])

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

FlexibleCalibrator([config])

Single-model calibrator with user-selected method.

class mioXpektron.recalibrate.flexible_calibrator.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
mioXpektron.recalibrate.flexible_calibrator.summarize_reference_mass_stability(summary_df, *, exclude_below_mz=1.5)[source]

Summarize per-mass residual stability across the current calibration summary.

Parameters:
Return type:

DataFrame

mioXpektron.recalibrate.flexible_calibrator.select_stable_reference_masses(reference_masses, stability_df, *, exclude_below_mz=1.5, max_mean_abs_ppm=50.0, max_median_abs_ppm=None, min_valid_fraction=0.8, min_count=3)[source]

Select a stable reference-mass subset based on cross-spectrum residuals.

Parameters:
Return type:

Tuple[ndarray[tuple[Any, …], dtype[float64]], DataFrame]

class mioXpektron.recalibrate.flexible_calibrator.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