astrocook.recipes.edit module#
- class astrocook.recipes.edit.RecipeEdit(session_v2: Session)[source]#
Bases:
objectRecipes for general structure editing and arithmetic operations.
These methods are accessed via the
session.editattribute and delegate heavy logic to the Core structuresSpectrumandSystemList.- set_properties(name: str = '_current_', object: str = '_current_', z_em: float | str = '_current_', resol: str = '_current_', overwrite_resol_col: bool = False, yunit: str = '_current_', telluric_corrected: str = '_current_') Session | None[source]#
Set session properties.
Set core session properties like name, object, redshift, and resolution. Delegates to
astrocook.core.spectrum.Spectrum.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 (float or str, optional) – Emission Redshift, above -1 and finite. Defaults to
'_current_'(no change).resol (str, optional) – Resolving Power R (e.g.,
50000) OR Pixel FWHM (e.g.,'3px'), positive and finite. Defaults to'_current_'(no change); an empty string keeps the current resolution too (FT8).overwrite_resol_col (bool, optional) – If
True, aresolcolumn that varies with wavelength is replaced by a flat one at the new resolution; ifFalseit is kept (a flat or missing column is always set). Defaults toFalse(#526: before, a variable column was flattened even withresol='_current_').yunit (str, optional) – The unit of the flux, declared without converting the values (phase 6-quater, PR 8-bis): a flux density per unit wavelength (e.g.
'erg/(Angstrom s cm^2)') or'arb_flux', the arbitrary units of Astrocook. Defaults to'_current_'(no change).y_convert()converts a flux that has a unit.telluric_corrected (str, optional) – Whether the flux is already corrected for the telluric absorption (phase 7-ter, T1):
'yes'sets the flagTELLURIC_CORRECTEDof the metadata, and the normalization is the continuum alone;'no'clears it, and the normalization is the continuum times thetelluriccolumn, when there is one. Defaults to'_current_'(no change).
- Returns:
A new
Sessionwith updated properties.- Return type:
- x_convert(z_ref: float | str = '_current_', xunit: str = 'km/s') Session | None[source]#
Convert X axis.
Convert the x axis units and zero point to wavelength or velocity units. Delegates to
astrocook.core.spectrum.Spectrum.x_convert().- Parameters:
- Returns:
A new
Sessionwith the converted X-axis.- Return type:
- y_convert(yunit: str = 'erg/(nm s cm^2)') Session | None[source]#
Convert Y axis units.
Converts the flux and error arrays to the specified unit. Delegates to
astrocook.core.spectrum.Spectrum.y_convert().
- apply_expression(target_col: str, expression: str, alias_map: Dict[str, str] | None = None) Session[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.Spectrum.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
Sessionwith the computed column.- Return type:
- mask_expression(target_col: str, expression: str, alias_map: Dict[str, str] | None = None) Session[source]#
Mask column by expression.
Mask a target column by setting values to NaN where the expression is True. Delegates to
astrocook.core.spectrum.Spectrum.mask_expression().
- smooth_column(target_col: str = 'dF', sigma_kms: float = 100.0, renorm_model: bool = False) Session[source]#
Smooth a single column.
Apply a Gaussian filter to a single data column. Delegates to
astrocook.core.spectrum.Spectrum.smooth_column().- Parameters:
- Returns:
A new
Sessionwith the smoothed column.- Return type:
- import_systems(source_session: str | Session, append: bool = True, refit: bool = False) Session[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.SystemList.filter_by_range().- Parameters:
source_session (str) – Name of the open session to import from (required; in a script, also the session itself).
append (bool, optional) – If
True, adds to existing systems. IfFalse, replaces them. Defaults toTrue.refit (bool, optional) – If
True, runs a refit on the imported systems. Defaults toFalse.
- Returns:
A new
Sessionwith imported systems.- Return type:
- import_systems_ascii(file_path: str, append: bool = True, refit: bool = False) Session[source]#
Import systems from an ASCII file (issue #480).
Reads a table with a header, in any format astropy can guess (CSV, whitespace-separated, …), e.g. the
_systems.csvwritten byastrocook.recipes.file.RecipeFile.export_ascii(). Required columns:seriesandz; optional:logN(default 13.0),b(default 10.0 km/s),btur(default 0),dz,dlogN,db. Other columns are ignored. Components outside the spectral range are skipped.- Parameters:
- Returns:
A new session with the imported systems (the session as it was if the file holds no valid row).
- Return type:
- Raises:
RecipeFailed – If the file cannot be read or lacks the required columns.
- delete(targets: str) Session[source]#
Delete elements.
Remove columns from the spectrum or clear the line list. Delegates to
astrocook.core.spectrum.Spectrum.remove_columns().- Parameters:
targets (str) – Comma-separated list of items to delete (e.g.
'cont, model'), columns of the spectrum other than its axis, flux and error. Use'systems'(or'lines') to clear the component list.- Returns:
A new
Sessionwith the elements removed.- Return type:
- Raises:
InvalidParameter – If
targetsnames nothing, a column of every spectrum (λ, λmin, λmax, F, dF) or a column that the spectrum does not have (phase 6-quater, PR 9: each gave a WARNING and an unchanged state, recorded as done).
- split(expression: str, alias_map: Dict[str, str] | None = None) Session[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.Spectrum.split().
- extract_preset(region: str = 'lya_forest') Session | List[Session][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.Spectrum.get_region_bounds()andsplit().- 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
Sessioninstances.- Return type:
- Raises:
InvalidParameter – If
regionnames no region, or one that is not a preset (phase 6-quater, PR 9: an unknown one was skipped with a WARNING).
- trim_common(other_sessions: str | List[Session | str], z_target: float | str, trans_self: str, trans_others: str, window_kms: float = 500.0) Session[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.Spectrum.calc_intersection_expression().- Parameters:
other_sessions (str or list) – Comma-separated names of other sessions (in a script, also a list of the sessions themselves).
others_namesuntil phase 6-quater, PR 9, still accepted.z_target (float) – Target redshift, above -1 and finite.
trans_self (str) – Transition for current session (e.g.
'Ly_a'), as named in the atomic data.trans_others (str) – Comma-separated transitions for other sessions, one per session.
window_kms (float, optional) – Symmetric window width in km/s, positive. Defaults to
500.0.
- Returns:
A new
Sessiontrimmed to the common coverage.- Return type:
- Raises:
InvalidParameter – If a transition is not in the atomic data, or the transitions are not one per session (phase 6-quater, PR 9: an unknown transition of this session gave “no range in common”, one of another session was ignored).
- stitch(other_sessions: str | List[Session | str], sort: bool = True) Session[source]#
Merge multiple sessions.
Concatenates the current session with a list of other sessions. Delegates to
astrocook.core.spectrum.Spectrum.stitch().- Parameters:
- Returns:
A new
Sessioncontaining the merged data.- Return type:
- Raises:
RecipeFailed – If a name is not that of an open session (phase 6-quater, PR 9: skipped with a WARNING), or a flux or an axis cannot be converted to the units of this session.
- equalize_and_stitch(other_sessions: str | List[Session | str], stitch_wavelengths: str, equalize_ranges: str = 'auto', manual_factors: str = 'auto') Session[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. The arms are converted to the units of the axis and of the flux of the bluest (an arm in arbitrary units of flux takes those of the bluest once scaled; phase 6-quater, PR 9, F132, F134).
- Parameters:
other_sessions (str or list) – Comma-separated names of the other sessions to stitch to the current one (in a script, also a list of the sessions themselves). (This parameter is hidden in the GUI dialog).
stitch_wavelengths (str) – Comma-separated cut-off wavelengths (in nm), increasing, 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 positive multipliers to scale adjacent arms. If provided, these override the equalize_ranges calculation. Defaults to
'auto'.
- Returns:
A new
Sessioncontaining the equalized and stitched spectrum.- Return type:
- coadd(session_names: str | List[Session | str], xstart: float | None = None, xend: float | None = None, dx: float = 10.0, xunit: str = 'km/s', kappa: float | None = 5.0, equalize_order: int | None = 0) Session[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.Spectrum.coadd().- Parameters:
session_names (str or list) – Comma-separated names of sessions to co-add, this one among them (in a script, also a list of the sessions themselves). The first is the reference: the others are converted to the units of its axis and flux, and scaled to its flux (F133, F134).
xstart (float or None, optional) – Start wavelength (nm). None for auto. Defaults to None.
xend (float or None, optional) – End wavelength (nm), above
xstart. None for auto. Defaults to None.dx (float, optional) – Step size for the final grid, positive. Defaults to
10.0(km/s), as the GUI: choose the native pixel size for high-resolution data (e.g. ~2.5 km/s for UVES, ~0.8 km/s for ESPRESSO).xunit (str, optional) – Unit for the step size: a velocity or a wavelength (e.g.,
'km/s'or'nm'). Defaults to'km/s'.kappa (float or None, optional) – Sigma clipping threshold, positive. None for off. Defaults to
5.0.equalize_order (int or None, optional) – Order of the polynomial (0 to 5) that scales each session to the first: 0 a constant factor, None no scaling (
-1, the value of no scaling until phase 6-quater, PR 9, F123, is read as None). Defaults to0.
- Returns:
A new
Sessioncontaining the co-added spectrum.- Return type:
- Raises:
InvalidParameter – If
session_namesnames no session or not this one,xstartis not belowxend(an empty spectrum) orxunitis neither a velocity nor a wavelength (phase 6-quater, PR 9).RecipeFailed – If a name is not that of an open session (it was skipped without a word), or a flux or an axis cannot be converted.