synthesizer.instruments.utils¶
Utility helpers for instrument-related workflows.
This module currently provides helpers for constructing wavelength grids and line spread functions from resolving power, for inspecting the available premade instruments, and for reading and writing instrument attributes to and from HDF5.
Functions
- synthesizer.instruments.utils.get_lams_from_resolving_power(lam_min, lam_max, resolving_power)[source]¶
Generate a wavelength array from a resolving-power definition.
This function creates an array of wavelengths between lam_min and lam_max, where the spacing between wavelengths is determined by the resolving power. The resolving power can be specified as a constant or as a function that varies with wavelength.
- Parameters:
lam_min (unyt_quantity) – Minimum wavelength of the output grid.
lam_max (unyt_quantity) – Maximum wavelength of the output grid.
resolving_power (float or callable) – Resolving power (R = λ / Δλ). Can be a constant value or a function that takes a wavelength with units and returns a resolving power. This allows either a fixed-resolution grid or one whose spacing varies with wavelength.
- Returns:
- Array of wavelengths with the same units as the inputs.
The spacing is chosen such that successive wavelength bins follow the supplied resolving-power definition.
- Return type:
unyt_array
- synthesizer.instruments.utils.get_lsfs_from_resolving_power(lam, resolving_power, lsf_resample_factor=1, resolving_power_lam=None, nsigma=5)[source]¶
Generate Gaussian line spread function kernels from a resolving power.
This function creates a Gaussian kernel for each wavelength in lam, with a FWHM of the wavelength divided by the resolving power there. The kernels can be passed to a SpectroscopicInstrument as its lsfs (or to its set_lsfs method), together with the same lsf_resample_factor.
- Parameters:
lam (unyt_array) – The wavelengths of the instrument.
resolving_power (float or callable or array) – Resolving power (R = λ / Δλ). Can be a constant value, a function that takes a wavelength with units and returns a resolving power, or an array of values at resolving_power_lam.
lsf_resample_factor (int) – The LSF supersampling factor. The kernels are sampled on wavelength bins this many times finer than lam.
resolving_power_lam (unyt_array, optional) – The wavelengths of a tabulated resolving power. They must cover the wavelength range of lam.
nsigma (float) – The half width of the kernels, in standard deviations of the broadest Gaussian.
- Returns:
- The kernels with shape (nwave, nkernel), each summing to
unity.
- Return type:
np.ndarray
- Raises:
InconsistentArguments – If a tabulated resolving power does not cover lam.
- synthesizer.instruments.utils.print_premade_instruments()[source]¶
List all available premade instruments.
This will also count the filters (if any) available for each instrument and check whether the cached instrument file has been downloaded or not. The output is formatted as a simple ASCII table for quick inspection at the command line.
Factory classes are included in the table, but they report cache availability as
N/Abecause they do not correspond to a single cached instrument file.- Return type:
None
- synthesizer.instruments.utils.read_instrument_attribute(group, name)[source]¶
Read an instrument attribute written by
write_instrument_attribute.Groups are read as dictionaries keyed by entry name. Datasets are read as Python floats if they are dimensionless scalars,
unyt_quantityif they are scalars with units, andunyt_arrayotherwise.- Parameters:
group (h5py.Group) – The group to read from.
name (str) – The name of the dataset or group to read.
- Returns:
- The loaded value, or
None if
nameis not ingroup.
- Return type:
dict, float, unyt_quantity, unyt_array or None
- synthesizer.instruments.utils.write_instrument_attribute(group, name, value)[source]¶
Write an instrument attribute to
groupundername.Dictionaries are written as a group with one entry per key. Anything else is written as a float dataset with a
unitsattribute, which is"dimensionless"for values without units.Nonewrites nothing.- Parameters:
group (h5py.Group) – The group to write into.
name (str) – The name of the dataset or group to create.
value (dict, unyt_array, unyt_quantity, array-like, float, None) – The value to write.