to_lal_unit#

gwpy.utils.lal.to_lal_unit(
astropy_unit: Unit | str,
) tuple[Unit, float | complex][source]#

Convert the input unit into a lal.Unit and a scaling factor.

Parameters:
astropy_unitUnit, str

The input unit.

Returns:
lal_unitlal.Unit

The LAL representation of the base unit.

scalefloat, complex

The linear scaling factor that should be applied to any associated data, see _Notes_ below.

Raises:
ValueError

If LAL doesn’t understand the base units for the input.

Notes

Astropy supports ‘scaled’ units of the form <N> <u> ere <N> is a float and <u> the base astropy.units.Unit, e.g. '123 m', e.g:

>>> from astropy.units import Quantity
>>> x = Quantity(4, '123m')
>>> print(x)
4.0 123 m
>>> print(x.decompose())
492.0 m

LAL doesn’t support scaled units in this way, so this function simply returns the scaling factor of the unit so that it may be applied manually to any associated data.

Examples

>>> print(to_lal_unit('m**2 / kg ** 4'))
(m^2 kg^-4, 1.0)
>>> print(to_lal_unit('123 m'))
(m, 123.0)