kinextract.run_iterative_clean_map
- kinextract.run_iterative_clean_map(st: FitState, a0: ndarray, bounds: list, map_maxiter: int, map_ftol: float, map_maxfun: int, print_every: int, sigma_clip: float = 3.0, clean_maxiter: int = 5, clean_minpix: int = 10, protect_mask: ndarray | None = None, protect_absorption_only: bool = True, bloom_pixels: int = 0, map_gtol: float = 1e-10, map_maxls: int = 50, use_scaled_optimizer: bool = True, use_jax_objective: bool = False, jax_enable_x64: bool = True)[source]
Iteratively sigma-clip outlier pixels while refitting the MAP model.
Alternates fitting the LOSVD/template model (
_fit_map_once()) with identifying and masking outlier pixels (viakinextract.masking._update_clean_mask()) whose residuals exceed sigma_clip, until the set of good pixels stops changing (convergence), a maximum number of iterations is reached, or too few good pixels would remain. This “cleaning” process removes cosmic rays, sky-line residuals, bad columns, and other artifacts that would otherwise bias the LOSVD recovery, while protect_mask prevents known genuine spectral features (e.g. the Ca II triplet) from ever being clipped even if they are poorly fit.- Parameters:
st (FitState) – Fit state;
st.gerris temporarily modified pixel-by-pixel during cleaning (masked pixels get their error set to the large sentinel valueBIG) and is left consistent with the final good-pixel set on return.a0 (ndarray) – Initial guess for the flat parameter vector, used to start the first clean iteration.
bounds (list of tuple) – Per-parameter
(lower, upper)bounds passed through to_fit_map_once().map_maxiter – Passed through to each call of
_fit_map_once(); see that function for descriptions.map_ftol – Passed through to each call of
_fit_map_once(); see that function for descriptions.map_maxfun – Passed through to each call of
_fit_map_once(); see that function for descriptions.print_every – Passed through to each call of
_fit_map_once(); see that function for descriptions.sigma_clip (float, optional) – Number of standard deviations beyond which a pixel’s residual is considered an outlier and masked on the next iteration.
clean_maxiter (int, optional) – Maximum number of clean/refit iterations.
clean_minpix (int, optional) – Minimum number of good pixels required; cleaning stops (with a warning logged) rather than masking below this floor.
protect_mask (ndarray of bool, optional) – Boolean mask, length
npix, marking pixels that must never be clipped regardless of residual (e.g. a window around the Ca II triplet). If None, no pixels are protected.protect_absorption_only (bool, optional) – If True, the protection in protect_mask only prevents clipping of pixels where the data lies below the model (absorption-like residuals), still allowing clipping of emission-like outliers within the protected window.
bloom_pixels (int, optional) – If > 0, grow (dilate) each newly-rejected pixel run by this many pixels on each side before finalising the mask for the next iteration, so that the wings of a bad feature are also excluded, not just its most deviant pixels. Growth is not applied within protect_mask.
map_gtol – Passed through to each call of
_fit_map_once(); see that function for descriptions.map_maxls – Passed through to each call of
_fit_map_once(); see that function for descriptions.use_scaled_optimizer – Passed through to each call of
_fit_map_once(); see that function for descriptions.use_jax_objective – Passed through to each call of
_fit_map_once(); see that function for descriptions.jax_enable_x64 – Passed through to each call of
_fit_map_once(); see that function for descriptions.
- Returns:
best_res (scipy.optimize.OptimizeResult) – The optimisation result from the final clean iteration.
good_mask (ndarray of bool) – Final good-pixel mask, length
npix, after all clipping.