API reference

This page covers the public surface exposed at the top level (import kinextract / from kinextract import ...), grouped by the submodule that defines each name. Internal helpers (leading-underscore names) are not listed here but remain documented and importable from their defining submodule for advanced use.

Configuration

kinextract.FitConfig

All tunable parameters controlling a single LOSVD spectral fit.

kinextract.load_config_from_toml

Build a FitConfig from a TOML configuration file.

Top-level fitting API

kinextract.run_spectral_fit

Run the full non-parametric LOSVD spectral fit end-to-end.

kinextract.fit_state_map_with_optional_clean

Run the MAP fit, optionally with sigma-clipping.

kinextract.build_parameter_xscale

Build a per-parameter scale vector to precondition the L-BFGS-B fit.

kinextract.run_iterative_clean_map

Iteratively sigma-clip outlier pixels while refitting the MAP model.

kinextract.compute_losvd_roughness

Peak-normalised maximum absolute second difference of a LOSVD array.

kinextract.compute_losvd_n_peaks

Count topographically-prominent peaks in a LOSVD.

State

kinextract.FitState

Mutable container holding the full numerical state of one spectral fit.

kinextract.precompute_losvd_interp

Precompute linear-interpolation indices/weights from xl onto vgrid0.

kinextract.precompute_ip_map

Precompute the (npix, nlosvd) pixel-shift index map for convolution.

kinextract.getnlosvd_fast_from_b

Resample a trial LOSVD histogram onto the fine internal velocity grid.

Spectrum loading

kinextract.load_spectrum_for_fit

Load a galaxy spectrum file and return arrays trimmed to the fit window.

kinextract.make_fit_state

Load a spectrum and assemble the fully-populated FitState for one fit.

kinextract.build_initial_guess_nonparam

Build the initial non-parametric-LOSVD parameter vector and its bounds.

kinextract.choose_norm_wavelength_frame

Determine whether a .norm file's wavelength column is rest- or observed-frame, and return it converted to the frame the fit expects.

kinextract.fortran_rebin_after_redshift

Resample a de-redshifted spectrum onto a uniform wavelength grid.

Continuum

kinextract.asymmetric_least_squares_continuum

Fit a smooth asymmetric-least-squares baseline to a spectrum (Eilers 2003).

kinextract.grow_boolean_mask

Dilate a boolean mask by a fixed number of pixels on each side.

kinextract.grow_boolean_mask_A

Dilate a boolean mask by approximately a fixed wavelength on each side.

kinextract.robust_sigma

Robust standard-deviation estimate via the normalized MAD.

asymmetric_least_squares_continuum/robust_sigma are standalone, one-time pre-normalization utilities – not part of the main fitting pipeline.

Joint continuum-in-the-model fit

The continuum-cofitting method (FitConfig.fit_continuum = True). See kinextract.joint for the full rationale.

kinextract.run_joint_fit

Run the joint fit and package results in the same shape as kinextract.fitting.run_spectral_fit()'s "outputs" dict.

kinextract.fit_joint

Run the joint LOSVD + template + continuum-P-spline MAP fit.

kinextract.fit_joint_auto_xlam

Automatically select the joint model's LOSVD regularization strength.

kinextract.fit_joint_auto_xlam_sigl0

Self-consistent fixed-point refinement of the wing-taper's sigl0.

kinextract.build_pspline_design

Build a B-spline design matrix for the continuum.

kinextract.evaluate_model_gp_joint

Evaluate the joint forward model for a trial parameter vector.

LOSVD analysis

kinextract.fit_losvd_gauss_hermite

Fit the classic 4-moment Gauss-Hermite model to a non-parametric LOSVD.

kinextract.fit_losvd_gauss_hermite_higher

Fit a higher-order Gauss-Hermite model (h3..h_max_order) to a LOSVD.

kinextract.gauss_hermite_losvd_model

Four-moment Gauss-Hermite LOSVD model, legacy Fortran normalization.

kinextract.gauss_hermite_losvd_model_ho

Higher-order Gauss-Hermite LOSVD model, van der Marel & Franx (1993) convention.

kinextract.fh3_fortran_like

Third-order Gauss-Hermite basis polynomial, legacy Fortran normalization.

kinextract.fh4_fortran_like

Fourth-order Gauss-Hermite basis polynomial, legacy Fortran normalization.

kinextract.getfwhm_fortran_like

Estimate the full-width-at-fraction-of-max and flux moments of a curve.

Numerics

kinextract.evaluate_model_gp

Evaluate the forward model spectrum for a trial parameter vector.

kinextract.objective_map

Scalar objective function minimised by the MAP LOSVD/template fit.

kinextract.objective_components

Break down the MAP objective into its individual terms.

kinextract.compute_weighted_template_spectrum

Compute the weighted mixture of stellar templates for given weights.

Templates

kinextract.interp_template_tp_with_outside

Linearly interpolate a single template spectrum onto the galaxy grid.

kinextract.build_template_matrix_fortran

Build the full (npix, ntemplates) stellar template matrix.

kinextract.resolution_mismatch_sigma_A

Compute the Gaussian kernel needed to remove a data/template LSF mismatch.

kinextract.convolve_gaussian_pixels

Convolve flux with a Gaussian kernel of a fixed width in pixels.

Masking

kinextract.build_emission_line_mask

Build a boolean mask of emission-line pixels to exclude from the fit.

kinextract.build_clean_protect_mask

Build the boolean "protect" mask exempting known real features from clipping.

Plotting

kinextract.plot_fit

Plot the observed spectrum against the best-fit model and residuals.

kinextract.plot_losvd

Plot the recovered non-parametric LOSVD with its Gauss-Hermite overlay.

kinextract.plot_continuum

Diagnostic plot for a continuum-cofit fit (kinextract.joint).

Error estimation

kinextract.LOSVDErrorEstimator

Unified interface for estimating uncertainties on a recovered LOSVD.

kinextract.estimate_losvd_errors

Convenience wrapper: run all requested error estimation methods and return the combined summary.

Recovery-bias validation

kinextract.assess_recovery_bias

Measure empirical LOSVD recovery bias on a grid of known truths.

kinextract.correct_recovered_losvd

Apply an empirical bias correction from an assess_recovery_bias() table.

kinextract.build_matched_mock

Synthetic spectrum matched to st's instrument/template/continuum/noise.

kinextract.true_losvd_on_grid

Ground-truth LOSVD histogram on xl, normalized so sum(b) == 1.

I/O

kinextract.read_galaxy_index_flux_err

Read a raw 3-column galaxy spectrum file.

kinextract.read_norm_spectrum

Read a pre-normalized .norm spectrum file.

kinextract.read_template_xy

Load a single stellar/SSP template spectrum file.

kinextract.read_template_list

Read a template-list file and resolve each entry to a full path.

kinextract.read_galaxy_params

Read a legacy galaxy.params file.

kinextract.write_fitlov_outputs

Write the final LOSVD fit results to legacy-format ASCII files.

kinextract.write_losvd_errors_file

Write LOSVD vector with error bars to a file for modeling pipeline.

kinextract.write_gh_errors_file

Write Gauss-Hermite moment errors to a file.

Optional Bayesian (NUTS) path

Not part of the top-level namespace (requires pip install kinextract[bayesian]); import directly from kinextract.bayesian.

kinextract.bayesian.fit_state_bayesian

Run the full Bayesian LOSVD/template/continuum fit, called from kinextract.fitting.run_spectral_fit().

kinextract.bayesian.build_numpyro_model

Build the NumPyro model function for one LOSVD/template/continuum- offset posterior, at fixed regularization strength st.xlam.