astrocook.recipes.edit module#

class astrocook.recipes.edit.RecipeEditV2(session_v2: SessionV2)[source]#

Bases: object

Recipes for general structure editing and arithmetic operations.

These methods are accessed via the session.edit attribute and delegate heavy logic to the Core structures SpectrumV2 and SystemListV2.

__init__(session_v2: SessionV2)[source]#
set_properties(name: str = '_current_', object: str = '_current_', z_em: str = '_current_', resol: str = '_current_', overwrite_resol_col: bool = True) SessionV2 | None[source]#

Set session properties.

Set core session properties like name, object, redshift, and resolution. Delegates to astrocook.core.spectrum.SpectrumV2.with_properties().

Parameters:
  • name (str, optional) – The session Name (display label). Defaults to '_current_' (no change).

  • object (str, optional) – The object Name (header target). Defaults to '_current_' (no change).

  • z_em (str, optional) – Emission Redshift. Defaults to '_current_' (no change).

  • resol (str, optional) – Resolving Power R (e.g., 50000) OR Pixel FWHM (e.g., '3px'). Defaults to '_current_' (no change).

  • overwrite_resol_col (bool, optional) – If True, updates the ‘resol’ column in the spectrum data with the new resolution value. Defaults to True.

Returns:

A new SessionV2 with updated properties, or 0 on failure.

Return type:

SessionV2 or int

x_convert(z_ref: str = '0.0', xunit: str = 'km/s') SessionV2 | None[source]#

Convert X axis.

Convert the x axis units and zero point to wavelength or velocity units. Delegates to astrocook.core.spectrum.SpectrumV2.x_convert().

Parameters:
  • z_ref (str, optional) – Reference redshift for velocity conversion. Defaults to '0.0' (can use '_current_' to use the session’s z_em).

  • xunit (str, optional) – Unit of wavelength or velocity (e.g., 'nm', 'km/s'). Defaults to 'km/s'.

Returns:

A new SessionV2 with the converted X-axis, or 0 on failure.

Return type:

SessionV2 or int

y_convert(yunit: str = 'erg/(nm s cm^2)') SessionV2 | None[source]#

Convert Y axis units.

Converts the flux and error arrays to the specified unit. Delegates to astrocook.core.spectrum.SpectrumV2.y_convert().

Parameters:

yunit (str, optional) – Target unit of flux density. Defaults to 'erg/(nm s cm^2)'.

Returns:

A new SessionV2 with the converted Y-axis, or 0 on failure.

Return type:

SessionV2 or int

apply_expression(target_col: str, expression: str, alias_map: Dict[str, str] = None) SessionV2[source]#

Apply expression to columns.

Apply a NumPy-style expression. Use column names (λ, F, cont…) as variables. Supports multi-session arithmetic via aliases. Delegates to astrocook.core.spectrum.SpectrumV2.apply_expression().

Parameters:
  • target_col (str) – Target column (to be overwritten or created).

  • expression (str) – Expression to evaluate (e.g., 'F / dF', 'F * 2.0').

  • alias_map (dict, optional) – Mapping of aliases to session names (e.g. {'s1': 'Session 1'}).

Returns:

A new SessionV2 with the computed column, or 0 on failure.

Return type:

SessionV2 or int

mask_expression(target_col: str, expression: str, alias_map: Dict[str, str] = None) SessionV2[source]#

Mask column by expression.

Mask a target column by setting values to NaN where the expression is True. Delegates to astrocook.core.spectrum.SpectrumV2.mask_expression().

Parameters:
  • target_col (str) – Target column to mask (e.g., 'F').

  • expression (str) – Boolean expression (e.g., '(λ < 300) | > 400)', 'dF <= 0').

  • alias_map (dict, optional) – Mapping of aliases to session names.

Returns:

A new SessionV2 with the masked column, or 0 on failure.

Return type:

SessionV2 or int

smooth_column(target_col: str = 'dF', sigma_kms: str = '100.0', renorm_model: str = 'False') SessionV2[source]#

Smooth a single column.

Apply a Gaussian filter to a single data column. Delegates to astrocook.core.spectrum.SpectrumV2.smooth_column().

Parameters:
  • target_col (str, optional) – Target column to smooth. Defaults to 'dF'.

  • sigma_kms (str, optional) – Standard deviation for Gaussian kernel (km/s). Defaults to '100.0'.

  • renorm_model (str, optional) – If 'True' and smoothing 'cont', the 'model' column is re-normalized. Defaults to 'False'.

Returns:

A new SessionV2 with the smoothed column, or 0 on failure.

Return type:

SessionV2 or int

import_systems(source_session: str, append: bool = True, refit: bool = False) SessionV2[source]#

Import systems from session.

Copy absorption systems from another open session into this one, filtering those that fall outside the current spectral range. Delegates filtering to astrocook.core.system_list.SystemListV2.filter_by_range().

Parameters:
  • source_session (str) – Name of the session to import from.

  • append (bool, optional) – If True, adds to existing systems. If False, replaces them. Defaults to True.

  • refit (bool, optional) – If True, runs a refit on the imported systems. Defaults to False.

Returns:

A new SessionV2 with imported systems.

Return type:

SessionV2

delete(targets: str) SessionV2[source]#

Delete elements.

Remove columns from the spectrum or clear the line list. Delegates to astrocook.core.spectrum.SpectrumV2.remove_columns().

Parameters:

targets (str) – Comma-separated list of items to delete (e.g. 'cont, lines'). Use 'lines' or 'systems' to clear the component list.

Returns:

A new SessionV2 with the elements removed.

Return type:

SessionV2

split(expression: str, alias_map: Dict[str, str] = None) SessionV2[source]#

Split spectrum by expression.

Extract a portion of the spectrum into a new session using a boolean expression. Only rows where the expression is True are kept. Delegates to astrocook.core.spectrum.SpectrumV2.split().

Parameters:
  • expression (str) – Boolean expression to select data (e.g., '(λ > 400) & < 500)').

  • alias_map (dict, optional) – Mapping for multi-session variables.

Returns:

A new SessionV2 containing the subset of data, or 0 on failure.

Return type:

SessionV2 or int

extract_preset(region: str = 'lya_forest') SessionV2 | List[SessionV2][source]#

Extract region by preset.

Extract a specific standard region (like the Ly-alpha forest) into a new session, based on the current emission redshift (z_em). Delegates to astrocook.core.spectrum.SpectrumV2.get_region_bounds() and split().

Parameters:

region (str, optional) – Preset region identifier. Options: 'lya_forest', 'all_ly_forest', 'red_side'. Can be a comma-separated list. Defaults to 'lya_forest'.

Returns:

One or more new SessionV2 instances, or 0 on failure.

Return type:

SessionV2 or List[SessionV2] or int

trim_common(others_names: str, z_target: str, trans_self: str, trans_others: str, window_kms: str = '500.0') SessionV2[source]#

Trim to common velocity coverage.

Trims the current session to the velocity range shared by a list of other sessions (intersection). Delegates to astrocook.core.spectrum.SpectrumV2.calc_intersection_expression().

Parameters:
  • others_names (str) – Comma-separated names of other sessions.

  • z_target (str) – Target redshift (float parsed from string).

  • trans_self (str) – Transition for current session (e.g. 'Ly_a').

  • trans_others (str) – Comma-separated transitions for other sessions.

  • window_kms (str, optional) – Symmetric window width in km/s. Defaults to '500.0'.

Returns:

A new SessionV2 trimmed to the common coverage, or 0 on failure.

Return type:

SessionV2 or int

stitch(other_sessions: List[SessionV2 | str], sort: bool = True) SessionV2[source]#

Merge multiple sessions.

Concatenates the current session with a list of other sessions. Delegates to astrocook.core.spectrum.SpectrumV2.stitch().

Parameters:
  • other_sessions (list) – A list of SessionV2 objects OR strings (names of sessions loaded in the GUI).

  • sort (bool, optional) – If True, sorts the final spectrum by wavelength. Defaults to True.

Returns:

A new SessionV2 containing the merged data, or 0 on failure.

Return type:

SessionV2 or int

equalize_and_stitch(other_sessions: str, stitch_wavelengths: str, equalize_ranges: str = 'auto', manual_factors: str = 'auto') SessionV2[source]#

Equalize and stitch arms.

Equalize flux levels and stitch multiple sessions at specific cut-off wavelengths. This recipe is designed to seamlessly combine data from multi-arm spectrographs (e.g., X-Shooter’s UVB, VIS, and NIR arms).

The procedure enforces a strict blue-to-red processing order regardless of input order. For $N$ total sessions, exactly $N-1$ parameters must be provided for cuts, ranges, and factors.

Parameters:
  • other_sessions (str) – Comma-separated names of the other sessions to stitch to the current one. (This parameter is hidden in the GUI dialog).

  • stitch_wavelengths (str) – Comma-separated cut-off wavelengths (in nm) where the arms join. Data bluer than a cut is taken from the bluer arm; data redder is taken from the redder arm. Requires $N-1$ values.

  • equalize_ranges (str, optional) – Comma-separated overlap ranges formatted as 'min-max, min-max' (in nm) used to calculate the scaling factor between adjacent arms. If set to 'auto', the recipe attempts a global match. Defaults to 'auto'.

  • manual_factors (str, optional) – Comma-separated fixed multipliers to scale adjacent arms. If provided, these override the equalize_ranges calculation. Defaults to 'auto'.

Returns:

A new SessionV2 containing the equalized and stitched spectrum, or 0 on failure.

Return type:

SessionV2 or int

coadd(session_names: str, xstart: str = 'None', xend: str = 'None', dx: str = '0.01', xunit: str = 'nm', kappa: str = '5.0', equalize_order: str = '0') Dict[str, Any][source]#

Co-add multiple sessions.

Stitches multiple sessions together and rebins them onto a single common grid in one pass (Inverse Variance Weighting). Delegates to astrocook.core.spectrum.SpectrumV2.coadd().

Parameters:
  • session_names (str) – Comma-separated names of sessions to co-add.

  • xstart (str, optional) – Start wavelength. 'None' for auto. Defaults to 'None'.

  • xend (str, optional) – End wavelength. 'None' for auto. Defaults to 'None'.

  • dx (str, optional) – Step size for the final grid. Defaults to '0.01'.

  • xunit (str, optional) – Unit for the step size (e.g., 'nm' or 'km/s'). Defaults to 'nm'.

  • kappa (str, optional) – Sigma clipping threshold. 'None' for off. Defaults to '5.0'.

  • equalize_order (str, optional) – Polynomial order for flux scaling (-1=Off, 0=Scalar, 1=Linear). Defaults to '0'.

Returns:

A new SessionV2 containing the co-added spectrum, or 0 on failure.

Return type:

SessionV2 or int