API reference¶
The user-facing API is a single function, frizzle.frizzle(). The helpers
in frizzle.utils are documented below for completeness.
frizzle¶
- frizzle.frizzle(λ_out, λ, flux, ivar=None, mask=None, flags=None, censor_missing_regions=True, n_modes=None)¶
Combine spectra by forward modeling.
- Parameters:
λ_out (array) – The wavelengths to sample the combined spectrum on.
λ (array) – An N-length array of wavelength values (the wavelengths of individual pixels).
flux (array) – An N-length array of input flux values.
ivar (array | None) – [optional] An N-length array of inverse variances.
mask (array | None) – [optional] A boolean mask of which pixels to use when combining spectra (pixels with mask True get ignored). The mask is used to ignore pixel values when combining spectra, but the mask is not used when computing combined pixel flags.
flags (array | None) – [optional] An optional integer array of bitwise flags. If given, this should be shape (N, ).
censor_missing_regions (bool | None) – [optional] If True, then regions where there is no data will be set to NaN in the combined spectrum. If False the values evaluated from the model will be reported (and have correspondingly large uncertainties) but this will produce unphysical features.
n_modes (int | None) – [optional] The number of Fourier modes to use. If None is given then this will default to len(λ_out).
- Returns:
- A four-length tuple of
(y_star, C_star, flags, meta)where: y_staris the combined fluxes,C_staris the covariance of the combined fluxes,flagsare the combined flags, andmetais a dictionary.
Note that the input expects inverse variance ivar, but the output returns C_star, the covariance of the combined fluxes.
- A four-length tuple of
frizzle.utils¶
- frizzle.utils.get_modes(n_modes, λ_out, mask)¶
Choose the number of Fourier modes to use.
If
n_modesis provided it is returned unchanged. Otherwise the value is set to the smaller oflen(λ_out)and the number of unmasked pixels, and rounded down to the nearest odd integer.- Parameters:
n_modes (int | None) – The user-specified number of modes, or
Noneto choose automatically.λ_out (ArrayLike) – The wavelengths to sample the combined spectrum on.
mask (ArrayLike) – A boolean array where
Truemarks masked pixels.
- Returns:
The number of Fourier modes to use.
- Return type:
- frizzle.utils.check_inputs(λ_out, λ, flux, ivar, mask)¶
Validate and normalize the inputs for combining spectra.
Concatenates per-spectrum arrays into single 1D arrays, fills in defaults for
ivarandmask, sortsλ_out, and extends the mask to cover pixels that fall outside the resampling range.- Parameters:
λ_out (ArrayLike) – The wavelengths to sample the combined spectrum on.
λ (ArrayLike) – The input wavelengths, either a single array or a sequence of arrays that will be concatenated.
flux (ArrayLike) – The input fluxes, with the same shape conventions as
λ.ivar (ArrayLike | None) – The input inverse variances, with the same shape conventions as
λ. IfNone, an array of ones is used.mask (ArrayLike | None) – A boolean mask where
Truemarks pixels to ignore, with the same shape conventions asλ. IfNone, no pixels are masked.
- Returns:
A tuple
(λ_out, λ, flux, ivar, mask)of normalized arrays.- Return type:
- frizzle.utils.combine_flags(λ_out, λ, flags)¶
Combine flags from input spectra.
For each set bit, a flag is propagated to an output pixel when the nearest flagged input wavelength is within one output pixel width.
- Parameters:
- Returns:
An array of combined integer flags with shape
λ_out.shape.- Return type:
- frizzle.utils.separate_flags(flags=None)¶
Separate flags into a dictionary of flags for each bit.
frizzle.test_utils¶
Synthetic-data helpers used throughout the documentation and tests.
- frizzle.test_utils.make_one_dataset(dx, snr, N=8, x_min=8.7, x_max=8.7025, R=135000.0, lines_per_x=20000.0, ew_max_x=3e-05, ew_power=5.0, badfrac=0.01, profile_type='gaussian', profile_width=None, random_seed=None, Delta_xs=None)¶
Generate one synthetic multi-epoch dataset.
- Parameters:
dx – Pixel spacing in log-wavelength.
snr – Continuum signal-to-noise ratio per pixel.
N – Number of epochs.
x_max (x_min,) – Log-wavelength range.
R – Spectral resolving power.
lines_per_x – Mean line density per unit log-wavelength.
ew_max_x – Max equivalent width.
ew_power – Power-law index for the EW distribution.
badfrac – Fraction of pixels marked bad.
profile_type – ‘gaussian’, ‘lorentzian’, or ‘voigt’.
profile_width – Profile width(s); defaults to
1/R.random_seed – Seed for reproducibility.
Delta_xs – Per-epoch Doppler shifts (defaults to a sinusoid).
- Returns:
(xs, ys, y_ivars, bs, Delta_xs, line_args)whereline_argsis a tuple(line_xs, line_ews, profile_func)accepted bytrue_spectrum().
- frizzle.test_utils.true_spectrum(xs, doppler, line_xs, line_ews, profile_func)¶
The noise-free template at log-wavelengths
xs, Doppler-shifted bydoppler.