synthesizer.instruments.spectroscopic_instrument

Specialised spectroscopic instrument.

This instrument is designed to hold the attributes required for one- dimensional spectroscopy. It stores a wavelength grid together with optional depth, signal-to-noise, and noise-map definitions.

The instrument holds the noise level (depth and snrs) and shape as a function of wavelength.

Classes

class synthesizer.instruments.spectroscopic_instrument.SpectroscopicInstrument(label, lam, resolving_power=None, lsfs=None, resolving_power_lam=None, lsf_resample_factor=1, depth=None, snrs=None, depth_lam=None, depth_window=None, noise_shape_lam=None, noise_shape_std=None, template_on_detector=True, noise_maps=None)[source]

Spectroscopic instrument class.

A class containing the attributes and methods required for integrated spectroscopy. It holds the wavelength array defining the spectral coverage of the instrument together with the optional noise information required to generate noisy spectra. It does not include any spatially resolved state.

lam

The wavelength array defining the spectral coverage of the instrument.

Type:

unyt_array

resolving_power

Resolving power (R = lambda / delta_lambda) of the instrument. May be a constant or a function of wavelength or an array as a function of wavelength (resolving_power_lam must be supplied). Constants and arrays are persisted by to_hdf5(); a callable resolving power cannot be serialised to HDF5 and is silently dropped on save (it is not restored on load either, since there is nothing to restore it from).

Type:

float or callable or array, optional

lsfs

Normalised line spread function kernels with shape (nwave, nkernel). Each row corresponds to a wavelength in lam, and is the profile of a narrow line there, centred on the middle bin. Kernels must have an odd number of bins and sum to unity. They are in wavelength bins, so the spacing of lam should change slowly across a kernel; a wavelength array with a gap or a jump in spacing should be split into separate instruments. Gaussian kernels can be made from a resolving power with get_lsfs_from_resolving_power. To give an existing instrument its LSFs, or to change them, use set_lsfs: the LSFs are prepared when they are set, so later changes to the lsfs, lam or lsf_resample_factor attributes are not picked up.

Type:

array, optional

resolving_power_lam

Wavelength array corresponding to tabulated resolving_power values. Required when resolving_power is provided as an array.

Type:

unyt_array, optional

lsf_resample_factor

The LSF supersampling factor. The kernels are sampled, and applied, on wavelength bins this many times finer than the wavelength array.

Type:

int, optional

depth

The depth of the instrument, the spectral flux density (fnu) or luminosity density (lnu) reached at S/N = snrs, at depth_lam (or over depth_window). Its units set which of the fluxes or luminosities get noise.

Type:

unyt_quantity, optional

snrs

The signal-to-noise ratio at the depth.

Type:

float, optional

depth_lam

The wavelength at which the noise equals depth / snrs.

Type:

unyt_quantity, optional

depth_window

A wavelength window (lam_min, lam_max) over whose median the noise equals depth / snrs. With a noise template, exactly one of this or depth_lam is required; flat noise needs neither.

Type:

unyt_array, optional

noise_shape_lam

Wavelengths of the noise template noise_shape_std(noise_shape_lam), strictly increasing.

Type:

unyt_array, optional

noise_shape_std

The noise template, the 1-sigma noise at noise_shape_lam (NaN in detector gaps). Only its shape is used; depth / snrs sets the noise level.

Type:

unyt_array, optional

template_on_detector

Whether noise_shape_lam are the detector pixel centres. If so, noise is drawn at the detector pixels and interpolated, giving correlated wavelength elements; if not, each wavelength element gets independent noise.

Type:

bool

noise_maps

A fixed noise realisation added to spectra as it is, with one value per wavelength in lam. An alternative to the inline calculation; its units set which of the fluxes or luminosities get noise.

Type:

unyt_array, optional

apply_lam_array(sed, nthreads=1)[source]

Apply the instrument wavelength array to an SED.

Deprecated alias for apply_lam_array_fnu, which treats the instrument wavelengths as observer frame wavelengths.

Parameters:
  • sed (Sed) – Spectral energy distribution to observe.

  • nthreads (int) – Number of threads to use in the low-level resampling call.

Returns:

New SED resampled onto the instrument wavelength grid.

Return type:

Sed

apply_lam_array_fnu(sed, nthreads=1)[source]

Apply the instrument wavelength array in the observer frame.

The instrument wavelengths are interpreted as observer frame wavelengths, so the fluxes are resampled directly onto them and the observer frame wavelengths of the result are exactly the instrument’s. The luminosities are resampled onto the matching rest frame wavelengths, instrument.lam / (1 + redshift).

Parameters:
  • sed (Sed) – Spectral energy distribution to observe. Its fluxes must already have been computed (e.g. with Sed.get_fnu).

  • nthreads (int) – Number of threads to use in the low-level resampling call. Currently unused.

Returns:

New SED resampled onto the instrument wavelength grid in the

observer frame.

Return type:

Sed

apply_lam_array_lnu(sed, nthreads=1)[source]

Apply the instrument wavelength array in the rest frame.

The instrument wavelengths are interpreted as rest frame wavelengths, so the luminosities are resampled directly onto them. Any fluxes are resampled onto the matching observer frame wavelengths, instrument.lam * (1 + redshift).

Parameters:
  • sed (Sed) – Spectral energy distribution to resample.

  • nthreads (int) – Number of threads to use in the low-level resampling call. Currently unused.

Returns:

New SED resampled onto the instrument wavelength grid in the

rest frame.

Return type:

Sed

apply_lsf(sed, frame)[source]

Apply the instrument’s line spread function (LSF) to an SED.

Each element of the instrument wavelength array collects the light around it with its own kernel, so the new SED is on the instrument wavelength grid (as from apply_lam_array_lnu or apply_lam_array_fnu).

The SED can be on any wavelengths, including the instrument’s own (e.g. spectroscopy made without the LSF). Where its wavelengths are finer than the instrument’s, the LSF acts on the light before it is resampled, which places narrow lines more accurately. If it extends beyond the instrument wavelengths, the ends also collect the light from just outside.

Parameters:
  • sed (Sed) – Spectral energy distribution to apply the LSF to.

  • frame (str) – The frame the instrument wavelengths are in, either “rest” or “observer” (“observed” is also accepted). For the observer frame the fluxes must already have been computed (e.g. with Sed.get_fnu).

Returns:

New SED on the instrument wavelength grid with the LSF

applied.

Return type:

Sed

Raises:
apply_noise(sed, rng_seed=None, simspin_snr=None)[source]

Apply spectroscopic noise to an SED.

The noise follows the SimSpin calculation if simspin_snr is given, otherwise from the provided noise maps (a fixed realisation added as it is), or calculated from the depth and SNR. The noise is added to the observer frame fluxes if the depth (or noise maps) is a flux density, or to the rest frame luminosities if it is a luminosity density; SimSpin noise is added to the fluxes if the SED has them. The other spectrum is carried over without noise.

Parameters:
  • sed (Sed) – The SED to add noise to, e.g. from apply_lam_array_fnu or apply_lam_array_lnu. For noise on the fluxes they must already have been computed (e.g. with Sed.get_fnu).

  • rng_seed (int, optional) – Seed for the noise realisation. None gives a fresh realisation.

  • simspin_snr (float, optional) – The S/N of the median spectrum for SimSpin noise.

Returns:

New SED with noise added, with noise_arr (the noise added,

unyt_array) and weight_map (the inverse variance of each element; 0 where it is undefined) attached.

Return type:

Sed

Raises:
property can_do_lsf_spectroscopy

Return whether this instrument supports LSF spectroscopy.

property can_do_noisy_spectroscopy

Return whether this instrument supports noisy spectroscopy.

property can_do_spectroscopy

Return whether this instrument supports spectroscopy.

property instrument_type

Return the serialised type tag for this instrument.

classmethod load(filepath, **kwargs)[source]

Load a spectroscopic instrument from an HDF5 file.

Parameters:
  • filepath (str or PathLike) – Path to the HDF5 file.

  • **kwargs – Attribute overrides applied after deserialisation.

Returns:

The loaded instrument.

Return type:

SpectroscopicInstrument

set_lsfs(lsfs, lsf_resample_factor=None)[source]

Set the LSF kernels of the instrument.

This also sets the wavelength bins the LSFs are applied on, so use this to give an existing instrument its LSFs or to change them.

Parameters:
  • lsfs (array) – Normalised line spread function kernels with shape (nwave, nkernel). If a 1D array is supplied, every wavelength is assumed to have the same kernel. None removes the LSFs.

  • lsf_resample_factor (int, optional) – The LSF supersampling factor the kernels are sampled at. If not given, the instrument keeps the factor it has.

to_hdf5(group)[source]

Write the spectroscopic instrument to an HDF5 group.

Parameters:

group (h5py.Group) – Group into which the instrument should be serialised.