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:
objectRecipes for manipulating spectral flux and grid sampling.
These methods are accessed via the
session.fluxattribute and delegate logic toSpectrum.- 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
Sessionwith the calculated column added.- Return type:
- Raises:
InvalidParameter – If
output_colis 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().
- 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 to10.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, orapply_expressionwithy/cont. Defaults toFalse.
- Returns:
A new
Sessionwith the rebinned spectrum.- Return type:
- Raises:
InvalidParameter – If
xunitis not a unit, orxstartis not belowxend(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:
0a constant factor,n > 0a polynomial of ordern,-1a spline (the lowest value). Defaults to0.
- 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:
- 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().
- 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 ofastrocook.core.photometry.STANDARD_FILTERS. Defaults to"SDSS_r=17.0".- Returns:
A new
Sessionwith calibrated flux.- Return type:
- Raises:
InvalidParameter – If
magnitudesis not a list of pairs, or names a filter that is not known (phase 6-quater, PR 7: a RecipeFailed from the core).