Spectroscopy¶
Spectroscopy-domain containers and operations.
Spectrum
¶
A 1-D spectrum: a wavelength Grid plus per-bin flux, optional 1-sigma error, and optional mask.
The mask convention is True = invalid (a True entry marks the bin
as masked / excluded), matching astropy's masked-array convention. All
per-bin arrays share the wavelength Grid's
dtype (float32 or float64); flux determines the channel and
every other input must match it.
Use rebin to resample onto a new wavelength axis, to_f_nu /
to_f_lambda to convert between flux density conventions, and
synthetic_photometry to integrate through a transmission curve.
dtype
property
¶
The numpy dtype of the Spectrum's arrays.
Returns:
| Type | Description |
|---|---|
dtype
|
Either |
error
property
¶
The 1-sigma uncertainty array, if present.
Returns:
| Type | Description |
|---|---|
ndarray or None
|
A new copy of the per-bin 1-sigma uncertainty, or |
flux
property
¶
The flux density array.
Returns:
| Type | Description |
|---|---|
ndarray
|
A new copy of the per-bin flux density. dtype matches the Spectrum's dtype. |
mask
property
¶
The per-bin mask, if present.
Returns:
| Type | Description |
|---|---|
ndarray of bool or None
|
A new copy of the per-bin mask flags ( |
n_bins
property
¶
Number of bins in the spectrum.
Returns:
| Type | Description |
|---|---|
int
|
The length of the |
wavelength
property
¶
The wavelength axis.
Returns:
| Type | Description |
|---|---|
Grid
|
A clone of the wavelength Grid. dtype matches the Spectrum's dtype. |
convolve_lsf(*, spec, resolving_power=None, sigma=None, speed_of_light=None)
method descriptor
¶
Broaden the spectrum with a Gaussian line-spread function.
The spectrum is treated as a noise-free template: only flux is
convolved and the result carries no error / mask. The
wavelength Grid is returned unchanged and flux is conserved,
including at the spectrum edges. Works for any wavelength axis: a
uniform log grid uses a single fixed kernel, anything else uses an
exact per-pixel variable-width Gaussian.
Both specs describe a Gaussian whose sigma / lambda ratio is
constant (sigma_lambda = sigma_lnlambda * lambda).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
(constant_r, constant_velocity)
|
|
"constant_r"
|
resolving_power
|
float
|
The resolving power |
None
|
sigma
|
float
|
The velocity dispersion for |
None
|
speed_of_light
|
float
|
Speed of light for |
None
|
Returns:
| Type | Description |
|---|---|
Spectrum
|
A new broadened Spectrum on the same wavelength axis. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the spectrum carries |
rebin(target, *, spacing=None, kind=None)
method descriptor
¶
Resample the spectrum onto a target wavelength axis.
Flux is propagated via overlap-weighted averaging (density-conserving:
the integral of flux * bin_width is preserved over the region of
overlap). Error, if present, is propagated by squaring to variance,
applying the same overlap operator assuming independent source bins,
and taking the square root; the result is the marginal 1-sigma per
target bin. Mask, if present, is propagated as logical OR (True =
invalid): a target bin is invalid iff any source bin with non-zero
overlap into it is invalid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
Grid or ndarray
|
Target wavelength axis. If an ndarray is passed, |
required |
spacing
|
(linear, log)
|
Spacing convention for building a Grid from |
"linear"
|
kind
|
(centers, edges)
|
Bin convention for building a Grid from |
"centers"
|
Returns:
| Type | Description |
|---|---|
Spectrum
|
A new Spectrum on the target wavelength axis. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Notes
When the target is finer than the source (upsampling), neighboring
target bins drawing from the same source bin are strongly correlated.
The per-bin sigma values returned here are still individually correct
as marginals, but downstream operations that assume independent bins
(for example summing under quadrature, or synthetic_photometry on
the upsampled spectrum) will underestimate the true uncertainty. See
Spectrum.synthetic_photometry and photometry.synthetic for
the same caveat.
synthetic_photometry(*, transmission_grid, transmission_values, convention='photon_counting')
method descriptor
¶
Compute synthetic photometry through a transmission curve.
Convenience wrapper around photometry.synthetic that reuses the
Spectrum's wavelength, flux, and (optional) error. Returns the
band-averaged flux density, the propagated 1-sigma uncertainty (only
when the Spectrum has an error array), and the geometric coverage of
the filter by the spectrum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transmission_grid
|
Grid or ndarray
|
Filter wavelength axis. If an ndarray is passed, its length must
equal |
required |
transmission_values
|
ndarray
|
Filter transmission per bin. dtype must match the Spectrum's dtype. |
required |
convention
|
(photon_counting, energy_weighted)
|
Photon-counting (default) is appropriate for photon-counting detectors such as CCDs and HgCdTe arrays (including JWST NIRCam). Energy-weighted is appropriate for bolometric / energy-integrating detectors. |
"photon_counting"
|
Returns:
| Type | Description |
|---|---|
tuple of (float, float or None, float)
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If dtypes mismatch across inputs, array lengths are inconsistent,
|
Notes
The error is propagated assuming spectrum bins are statistically
independent. The transmission curve's bin density does not affect
this assumption — it only enters the deterministic weights. The
assumption is violated if the spectrum was previously upsampled (for
example via Spectrum.rebin onto a finer grid), in which case the
returned band_error underestimates the true uncertainty. See
Spectrum.rebin for the same caveat.
to_f_lambda(speed_of_light)
method descriptor
¶
Convert flux density from f_nu to f_lambda.
Applies f_lambda = f_nu * c / lambda^2 per bin, using each bin's
center wavelength. The wavelength Grid and mask are preserved; the
error array, if present, scales by the same factor element-wise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
speed_of_light
|
float
|
Speed of light expressed in the wavelength axis's length unit per
second. For example, with the wavelength in angstroms pass
|
required |
Returns:
| Type | Description |
|---|---|
Spectrum
|
A new Spectrum with the converted flux density. |
Notes
This method does not check whether the input is in fact f_nu; it unconditionally applies the conversion factor. The caller is responsible for tracking which density the Spectrum currently represents.
to_f_nu(speed_of_light)
method descriptor
¶
Convert flux density from f_lambda to f_nu.
Applies f_nu = f_lambda * lambda^2 / c per bin, using each bin's
center wavelength. The wavelength Grid and mask are preserved; the
error array, if present, scales by the same factor element-wise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
speed_of_light
|
float
|
Speed of light expressed in the wavelength axis's length unit per
second. For example, with the wavelength in angstroms pass
|
required |
Returns:
| Type | Description |
|---|---|
Spectrum
|
A new Spectrum with the converted flux density. |
Notes
This method does not check whether the input is in fact f_lambda; it unconditionally applies the conversion factor. The caller is responsible for tracking which density the Spectrum currently represents.
Synthetic Photometry¶
Synthetic photometry through transmission curves. Lives at
noobase.spectroscopy.synthetic_photometry.
synthetic(*, spectrum_grid, spectrum_flux, spectrum_error=None, transmission_grid, transmission_values, convention='photon_counting')
builtin
¶
Compute synthetic photometry of a spectrum through a transmission curve.
Returns the band-averaged flux density, the propagated 1-sigma
uncertainty (only when spectrum_error is given), and the geometric
coverage of the filter by the spectrum.
All arguments are keyword-only. The dtype channel (float32 or
float64) is determined by spectrum_flux; every other array
argument must match.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spectrum_grid
|
Grid or ndarray
|
Spectrum wavelength axis. If an ndarray is passed, its length must
equal |
required |
spectrum_flux
|
ndarray
|
Flux density per bin. Determines the dtype channel for the whole call; all other arrays must match. |
required |
spectrum_error
|
ndarray
|
1-sigma uncertainty per bin. Same length and dtype as
|
None
|
transmission_grid
|
Grid or ndarray
|
Filter wavelength axis. Same dtype and length-match rules as
|
required |
transmission_values
|
ndarray
|
Filter transmission per bin. Same dtype as |
required |
convention
|
(photon_counting, energy_weighted)
|
Photon-counting (default) is appropriate for photon-counting detectors such as CCDs and HgCdTe arrays (including JWST NIRCam). Energy-weighted is appropriate for bolometric / energy-integrating detectors. |
"photon_counting"
|
Returns:
| Type | Description |
|---|---|
tuple of (float, float or None, float)
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If dtypes mismatch across inputs, array lengths are inconsistent,
|
Notes
The error is propagated assuming spectrum bins are statistically
independent. The transmission curve's bin density does not affect this
assumption — it only enters the deterministic weights. The assumption
is violated if the spectrum was previously upsampled (for example via
Spectrum.rebin onto a finer grid), in which case the returned
band_error underestimates the true uncertainty. See
Spectrum.rebin for the same caveat.
SyntheticOperator
¶
Pre-built synthetic photometry operator with cached weights.
Amortizes the cost of grid intersection and transmission weighting for
repeated evaluation against many spectra that share the same wavelength
axis and transmission curve. apply then becomes a small inner
product. Useful for SED-fitting inner loops.
The operator caches both the deterministic weights and the geometric
coverage (available via the coverage property), so per-spectrum
calls do not recompute either.
coverage
property
¶
Geometric coverage of the filter by the operator's spectrum grid.
Returns:
| Type | Description |
|---|---|
float
|
Fraction of the filter's transmission integral probed by the
spectrum grid, in |
dtype
property
¶
The numpy dtype of the operator's cached weights.
Returns:
| Type | Description |
|---|---|
dtype
|
Either |
apply(spectrum_flux, *, spectrum_error=None)
method descriptor
¶
Apply the operator to a spectrum flux array.
Returns the band-averaged flux density and, optionally, the
propagated 1-sigma uncertainty. The geometric coverage is fixed at
construction time and accessible via the coverage property; it
is not returned here.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spectrum_flux
|
ndarray
|
Flux density per bin. Length must equal the operator's spectrum bin count and dtype must match the operator's dtype. |
required |
spectrum_error
|
ndarray
|
1-sigma uncertainty per bin. Same length and dtype as
|
None
|
Returns:
| Type | Description |
|---|---|
tuple of (float, float or None)
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If dtypes mismatch with the operator, or if array lengths do not match the operator's spectrum bin count. |
Notes
As with photometry.synthetic, the error is propagated assuming
spectrum bins are statistically independent; the assumption is
violated for spectra that were previously upsampled via
Spectrum.rebin. See Spectrum.rebin for the same caveat.