synthesizer.instruments.utils¶
Utility helpers for instrument-related workflows.
This module currently provides helpers for constructing wavelength grids 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.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.