astrocook.recipes.flux module#

astrocook.recipes.flux.CORE_COLUMNS = ('x', 'xmin', 'xmax', 'y', 'dy')#

not a name for a column written by a recipe (phase 6-quater, PR 7: the result went to a column that nothing shows), by the names of the data; those of the GUI (λ, F, dF, …) too since PR 8

Type:

The columns of every spectrum

class astrocook.recipes.flux.RecipeFlux(session_v2: Session)[source]#

Bases: object

Recipes for manipulating spectral flux and grid sampling.

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

__init__(session_v2: Session)[source]#
calculate_running_std(input_col: str = 'F', output_col: str = 'running_std', window_pix: int = 21) → Session[source]#

Calculate running standard deviation.

Calculates a running Root-Mean-Square (RMS) on a specific column to estimate local error or variability. Delegates to astrocook.core.spectrum.Spectrum.calculate_running_std().

Parameters:
  • input_col (str, optional) – The column to use for StdDev calculation, by the names of the GUI ('F', 'dF', 'cont', …; 'y', 'dy' are accepted). Defaults to 'F' ('y' until phase 6-quater, PR 8: the same column).

  • output_col (str, optional) – Name of the column to write (e.g., 'running_std'): a new column, or an auxiliary one to replace; not empty, nor one of the columns of every spectrum (λ, λmin, λmax, F, dF, or their names in the data, x, …, dy). Defaults to 'running_std'.

  • window_pix (int, optional) – Total window size in pixels (should be odd: an even one is increased by 1, and one below 3 is 3). Defaults to 21.

Returns:

A new Session with the calculated column added.

Return type:

Session

Raises:

InvalidParameter – If output_col is empty or the name of a column of every spectrum (phase 6-quater, PR 7: the result went to a hidden column, findings register F122; PR 8: also by the names of the GUI, which made a column that no expression could name).

smooth(sigma_kms: float = 100.0) → Session[source]#

Smooth spectrum.

Applies a Gaussian filter to the spectrum flux (y-axis), error (dy-axis), and auxiliary columns. Delegates to astrocook.core.spectrum.Spectrum.smooth().

Parameters:

sigma_kms (float, optional) – Standard deviation for Gaussian kernel in km/s. Defaults to 100.0.

Returns:

A new Session with smoothed columns.

Return type:

Session

rebin(xstart: float | None = None, xend: float | None = None, dx: float = 10.0, xunit: str = 'km/s', kappa: float | None = 5.0, filling: float = nan, norm: bool | str = False) → Session[source]#

Rebin spectrum.

Applies a new binning to a spectrum with a constant bin size. Delegates to astrocook.core.spectrum.Spectrum.rebin().

Parameters:
  • xstart (float or None, optional) – Start wavelength (nm). None for auto (data minimum). Defaults to None.

  • xend (float or None, optional) – End wavelength (nm), above xstart. None for auto (data maximum). Defaults to None.

  • dx (float, optional) – Step size, in the unit of xunit. Defaults to 10.0.

  • xunit (str, optional) – Unit of the step: a velocity ('km/s', a grid uniform in log wavelength) or a wavelength ('nm'). Defaults to 'km/s'.

  • kappa (float or None, optional) – Sigma clipping threshold for binning. None for off. Defaults to 5.0.

  • filling (float, optional) – Value to fill regions without data. Defaults to NaN.

  • norm (bool or str, optional) – Ignored, kept so that scripts and logs written for V1 still run: the rebinned spectrum is never normalized, and a true value (True, 'True', 'true', 1) only logs a warning. To see the normalized flux, use the normalized view of the plot, or apply_expression with y/cont. Defaults to False.

Returns:

A new Session with the rebinned spectrum.

Return type:

Session

Raises:

InvalidParameter – If xunit is not a unit, or xstart is not below xend (phase 6-quater, PR 7: an empty spectrum, findings register F124).

equalize(reference_session: str = '', order: int = 0) → Session[source]#

Equalize flux to a reference session.

Scales the flux of the current session to match the flux level of a reference session using a polynomial scaling model.

Parameters:
  • reference_session (str) – The name of the open session whose flux is matched (required; '' or 'None', the default of the old logs, fail saying that no session is selected).

  • order (int, optional) – The model of the scaling: 0 a constant factor, n > 0 a polynomial of order n, -1 a spline (the lowest value). Defaults to 0.

Returns:

A new session with the scaled flux, in the unit of its flux (an arbitrary flux scaled to a physical one takes the unit of the reference).

Return type:

Session

Raises:

RecipeFailed – If the reference is not an open session, its axis cannot be compared with this one (a velocity against a wavelength), or a flux is normalized and the other is not (phase 6-quater, PR 9, F138: the values were compared as they were, so an axis in Å against one in nm was not scaled, and a flux per Å against one per nm came out off by their ratio).

resample(target_session: str = '') → Session[source]#

Resample on another grid.

Resamples this spectrum onto the exact wavelength grid of another open session. This is often a prerequisite for multi-session arithmetic. Delegates to astrocook.core.spectrum.Spectrum.resample_on_grid().

Parameters:

target_session (str) – Name of the open session whose grid is used (required; '' or 'None', the default of the old logs, fail saying that no session is selected).

Returns:

A new Session interpolated to the target grid.

Return type:

Session

calibrate_from_magnitudes(magnitudes: str = 'SDSS_r=17.0') → Session[source]#

Flux calibrate (multi-band).

Warps the spectrum SED to match multiple photometric points. Delegates to astrocook.core.spectrum.Spectrum.calibrate().

Parameters:

magnitudes (str, optional) – List of ‘Filter=Mag’ pairs (AB magnitudes) separated by commas (e.g., "SDSS_g=17.5, SDSS_r=17.0"), the filters among those of astrocook.core.photometry.STANDARD_FILTERS. Defaults to "SDSS_r=17.0".

Returns:

A new Session with calibrated flux.

Return type:

Session

Raises:

InvalidParameter – If magnitudes is not a list of pairs, or names a filter that is not known (phase 6-quater, PR 7: a RecipeFailed from the core).