astrocook.recipes.continuum module#

class astrocook.recipes.continuum.RecipeContinuum(session_v2: Session)[source]#

Bases: object

Recipes for estimating and fitting the quasar continuum.

These methods are accessed via the session.continuum attribute and delegate heavy logic to Spectrum.

__init__(session_v2: Session)[source]#
estimate_auto(smooth_len_lya: float = 5000.0, smooth_len_out: float = 400.0, kappa: float = 2.0, fudge: str = 'auto', smooth_fwhm: float = 800.0, template: bool = False, renorm_model: bool = True, smooth_std: str | None = None) → Session[source]#

Auto-estimate continuum (single-click).

A single-click recipe that runs find_absorbed and then fit_continuum in sequence, based on the V1 ‘clip_flux’ algorithm.

Parameters:
  • smooth_len_lya (float, optional) – Smoothing length (km/s) for initial guess in the Ly-alpha forest. Defaults to 5000.0.

  • smooth_len_out (float, optional) – Smoothing length (km/s) for initial guess outside the forest. Defaults to 400.0.

  • kappa (float, optional) – Sigma threshold for finding absorption. Defaults to 2.0.

  • fudge (str, optional) – A multiplicative factor. Can be a float (e.g., '1.0') or 'auto'. If 'auto', the factor is calculated to center the continuum residuals. Defaults to 'auto', as the GUI (the same result as '1.0', see fit_continuum()).

  • smooth_fwhm (float, optional) – FWHM (km/s) of the final Gaussian smoothing. Defaults to 800.0.

  • smooth_std (str, optional) – Deprecated: the standard deviation (km/s) used before; overrides smooth_fwhm when given. Defaults to None.

  • template (bool, optional) – If True, use a QSO template. Defaults to False.

  • renorm_model (bool, optional) – If True, re-normalize the ‘model’ column to match the new continuum. Defaults to True.

  • ('5000.0' (The parameters can also be given as strings)

:param : :param 'True'): :type 'True'): they are :param as the dialogs and the session log give them: :type as the dialogs and the session log give them: they are :param converted to their types before the recipe runs.:

Returns:

A new Session with updated continuum and absorption mask.

Return type:

Session

Raises:

RecipeError – If a parameter cannot be used, or the continuum cannot be estimated (astrocook.recipes.errors).

find_absorbed(smooth_len_lya: float = 5000.0, smooth_len_out: float = 400.0, kappa: float = 2.0, template: bool = False) → Session[source]#

Find absorbed regions (V1 logic).

Runs the V1 ‘clip_flux’ kappa-sigma algorithm (with Ly-alpha forest split) to create a boolean mask (abs_mask) where True indicates absorption. Delegates to astrocook.core.spectrum.Spectrum.find_absorbed().

Parameters:
  • smooth_len_lya (float, optional) – Smoothing length (km/s) for initial guess in the Ly-alpha forest. Defaults to 5000.0.

  • smooth_len_out (float, optional) – Smoothing length (km/s) for initial guess outside the forest. Defaults to 400.0.

  • kappa (float, optional) – Sigma threshold for clipping. Flux below mean - kappa * sigma is considered absorbed. Defaults to 2.0.

  • template (bool, optional) – If True, use a QSO template (Not Implemented). Defaults to False.

Returns:

A new Session with the abs_mask column added/updated.

Return type:

Session

Raises:

RecipeError – If the recipe cannot run (astrocook.recipes.errors).

fit_continuum(fudge: str = 'auto', smooth_fwhm: float = 800.0, mask_col: str = 'abs_mask', renorm_model: bool = True, template: str = 'False', smooth_std: str | None = None) → Session[source]#

Fit continuum to mask (V1 logic).

Interpolates unabsorbed regions from a mask, optionally applies an auto-fudge factor to center residuals, and smooths the result. Delegates to astrocook.core.spectrum.Spectrum.fit_continuum().

Parameters:
  • fudge (str, optional) – Fudge factor. Can be a float (e.g., '1.0') or 'auto'. Defaults to 'auto'.

  • smooth_fwhm (float, optional) – FWHM (km/s) of the final Gaussian smoothing. Defaults to 800.0.

  • smooth_std (str, optional) – Deprecated: the standard deviation (km/s) used before; overrides smooth_fwhm when given. Defaults to None.

  • mask_col (str, optional) – Name of the mask column to use (True=Absorbed). Defaults to 'abs_mask'.

  • renorm_model (bool, optional) – If True, re-normalize the ‘model’ column. Defaults to True.

  • template (str, optional) – If 'True', use a QSO template. Defaults to 'False'.

Returns:

A new Session with the cont column added/updated.

Return type:

Session

Raises:

RecipeError – If the recipe cannot run (astrocook.recipes.errors).

fit_powerlaw(regions: str = '128.0-129.0, 131.5-132.5, 134.5-136.0', kappa: float = 3.0) → Session[source]#

Fit power-law continuum.

Fits a power-law (linear in log-log space) to user-defined, unabsorbed rest-frame regions. Creates the cont_pl column. Delegates to astrocook.core.spectrum.Spectrum.fit_powerlaw().

Parameters:
  • regions (str, optional) – Comma-separated rest-frame wavelength regions (nm). Example: '128.0-129.0, 131.5-132.5'. Defaults to '128.0-129.0, 131.5-132.5, 134.5-136.0'.

  • kappa (float, optional) – Sigma threshold for clipping outliers within regions. Defaults to 3.0.

Returns:

A new Session with the cont_pl column added/updated.

Return type:

Session

Raises:

RecipeError – If the recipe cannot run (astrocook.recipes.errors).

update_from_knots(knots_x: list, knots_y: list, renorm_model: bool = True) → Session[source]#

Update continuum from manual knots.

Interpolates a Cubic Spline through manually placed knots and updates the continuum. Delegates to astrocook.core.spectrum.Spectrum.update_continuum_from_knots().

Parameters:
  • knots_x (list) – List of x coordinates (wavelength/velocity) for the knots.

  • knots_y (list) – List of y coordinates (flux) for the knots.

  • renorm_model (bool, optional) – If True, re-normalize the ‘model’ column to match the new continuum. Defaults to True.

Returns:

A new Session with the updated continuum.

Return type:

Session