hispecdrp.primitives.line_fitting.fit_lfc_lines_primitive

Functions

_drop_duplicate_lfc_modes(params_table)

Keep the highest-AMPLITUDE row per (ORDER, MODE_NUM) pair.

_gen_lfc_modes(nu0, delta_nu, integers)

Generate LFC modes based on central frequency, frequency spacing, and integer indices.

_get_closest_lfc_mode(nu0, delta_nu, wave)

Get the closest LFC mode to a given wavelength value.

_unusable_lfc_line_fit_reason(fit, *, ...)

Return a skip reason for a collapsed / bound-hitting Gaussian, else None.

gen_lfc_modes(nu0, delta_nu, wave_min, wave_max)

Generate LFC modes based on central frequency, frequency spacing, and wavelength bounds.

Classes

FitLFCLinesPrimitive([dataset, config, ...])

NOTE: Under development

class FitLFCLinesPrimitive(dataset=None, config=None, context=None, log_config=None, parent=None, **kwargs)[source]

Bases: BasePrimitive

NOTE: Under development

Fit each laser frequency comb (LFC) line with a Gaussian profile. This is useful for calculating the wavelength solution and the the line spread function (LSF).

Each LFC line is first identified with scipy.signal.find_peaks then refined with a centroid. Then each line is fit with a Gaussian profile using scipy.optimize.least_squares. The fit parameters are stored in a table in the output data model’s attribute lfc_fitparams_fib#.

Parameters:
  • input – A level 1 or 2 data product.

  • fwhm_bounds (Sequence[float, float]) – The bounds for the FWHM of the fit. Default is (0.2, 8) pixels.

  • mu_bounds (Sequence[float, float]) – The bounds for the mean of the fit (in pixels) relative the centroid. Default is (-1, 1) pixels.

  • max_fit_window (float) – The maximum number of pixels to fit for a mode. Default is 14 pixels.

  • do_orders (Sequence[int] | None) – Which order(s) to fit. If None, fit all available orders.

  • do_fibers (Sequence[int] | None) – Which fiber(s) to fit. If None, fit all available fibers.

  • lfc_nu0 (float) – The central frequency (pump line) of the LFC in GHz.

  • lfc_delta_nu (float) – The frequency spacing of the LFC modes in GHz.

  • line_source (str) – The source of the lines to fit. Options: - ‘peaks’ : Use only the lines found by find_emission_lines. - ‘wavesol’ : Use all lines that fall within the valid wavelength range.

  • min_line_spacing (int) – Minimum spacing between lines in pixels. Default is 10 pixels.

  • background_filter_width (int | None) – Number of pixels to use for background estimation. If None, no background subtraction is performed.

Returns:

output (LFCFitParamsModel) – A data model containing the fit parameters for each LFC line.

_create_preview()[source]

Build an interactive preview comparing each fitted LFC line’s Gaussian model to the underlying spectral data.

Navigation is three-level: a fiber dropdown, an order dropdown (options depend on the selected fiber), and a line slider (options depend on the selected fiber+order).

For speed and file size, this keeps exactly two persistent traces in the figure (the data points and the Gaussian fit curve) and swaps their x/y data on each dropdown/slider interaction, rather than pre-building a trace pair per line and toggling visibility across thousands of traces (which scales quadratically with the number of lines and is what made this slow). Additionally, at most preview_n_lines_per_order lines (evenly sampled) are included per order; set it to None to include every fitted line.