kinextract.load_spectrum_for_fit
- kinextract.load_spectrum_for_fit(cfg: FitConfig, gal_file: str | None = None, gal_errors=None)[source]
Load a galaxy spectrum file and return arrays trimmed to the fit window.
Supports two input formats and, for
.normfiles, both continuum modes:Legacy pre-normalized
.normfiles (~kinextract.io.read_norm_spectrum): ifcfg.fit_continuumis False (pre-normalized mode), the already continuum-dividednormflux/normflux_errcolumns are used directly. Ifcfg.fit_continuumis True (continuum-cofit mode), the original (non-divided)orig_flux/orig_flux_errcolumns are used instead sokinextract.joint’s continuum can be co-fit downstream; this requires the.normfile to include those columns (columns 4+). Optionally applies fortran_rebin_after_redshift to match the legacy Fortranimfituniform-grid convention, and (in pre-normalized mode) an additional Fortran-style flux-range mask.Raw
.specfiles (~kinextract.io.read_galaxy_index_flux_err): always effectively continuum-cofit-compatible (the flux column is not pre-divided). Supports both integer-index columns (requiringcfg.wavemin_full/cfg.step) and literal wavelength columns in the first field, with the wavelength converted to rest-frame by dividing by1 + cfg.zgal.
In all cases, gal_errors, if given, overrides the file’s per-pixel flux errors (either a scalar broadcast to every pixel, or a full per-pixel array), and
cfg.use_spectrum_errors=False(only consulted when gal_errors is not given) replaces per-pixel errors with their uniform median.- Parameters:
cfg (FitConfig) – Fit configuration; supplies
fit_continuum,zgal,wavefitmin/wavefitmax,norm_wave_frame,norm_error_mode,use_spectrum_errors,fortran_rebin_norm,step,wavemin_full,spec_col3_is_variance,norm_apply_fortran_flux_mask, and related range-mask settings.gal_file (str, optional) – Path to the spectrum file. Required; a
.normextension (case-insensitive) selects the pre-normalized-file path, anything else is treated as a raw.specfile.gal_errors (float or ndarray, optional) – Optional override for the flux uncertainty: a scalar to use a uniform error for every pixel, or an array to use per-pixel errors directly, bypassing whatever error column the file provides.
- Returns:
x_reg (ndarray) – Rest-frame wavelength array (Å) trimmed to
[cfg.wavefitmin, cfg.wavefitmax].g_reg (ndarray) – Flux array corresponding to x_reg (continuum-divided in pre-normalized mode, raw/undivided in continuum-cofit mode).
ge_reg (ndarray) – Flux uncertainty array corresponding to x_reg; pixels flagged bad by range or flux masks are set to
BIG.step_used (float) – Wavelength step (Å) used or estimated for this spectrum.
prenorm (bool) – True if the pre-normalized (continuum-already-divided) path was used; False if this is continuum-cofit mode or a raw
.specfile.extra (dict) – Auxiliary arrays useful to downstream code (e.g. the full unwindowed wavelength array for LOSVD-grid reference, and, for
.normfiles, copies of the various flux/error/continuum columns both full-length and windowed to the fit region).