uvex_transients.utils.phot_utils.hz_per_unit#

uvex_transients.utils.phot_utils.hz_per_unit(unit: str | UnitBase, *, is_wavelength: bool) → float[source]#

Return the coefficient converting a bare number in unit to a frequency in Hz.

Resolved once, up front – not on every element of every model evaluation – so that letting a model’s spectral axis be expressed in an arbitrary (self-consistent) unit costs one extra multiply or divide per evaluation, not a Quantity conversion in the hot loop.

Parameters:
  • unit (str or UnitBase) – A wavelength unit if is_wavelength, otherwise a frequency unit.

  • is_wavelength (bool) – Whether unit is a wavelength unit (True) or a frequency unit (False).

Returns:

If is_wavelength is False, \(\nu_\mathrm{Hz} = \mathrm{coefficient} \times x\); if True, \(\nu_\mathrm{Hz} = \mathrm{coefficient} / x\) (frequency is inversely, not linearly, related to wavelength). Either way, this is that coefficient.

Return type:

float

Raises:

ValueError – If unit is not a wavelength/frequency unit matching is_wavelength.

Examples

>>> hz_per_unit(u.THz, is_wavelength=False)
1000000000000.0