wcosmo.utils.convert_quantity_if_necessary#
- wcosmo.utils.convert_quantity_if_necessary(arg, unit=None, xp=<module 'numpy' from '/home/runner/work/wcosmo/wcosmo/.venv/lib/python3.11/site-packages/numpy/__init__.py'>)[source]#
Helper function to convert between
astropyandunxtquantities and non-unitful values.The order of precedence is as follows:
If using
jax.numpyas the backend, the input is anastropyorunxtquantity orunitis specified, convert to aunxtquantity with the provided unit.If using
jax.numpyas the backend, the input is not a quantiy and no unit is provided, return the input.If a unit and an
astropyquantity are provided, convert the input to anastropyquantity with the provided unitIf a unit is provided, convert the input to an
astropyquantity with the provided unit.Else return the input as is.
- Parameters:
- arg: Union[astropy.units.Quantity, unxt.Quantity, array_like]
The array to convert
- unit: Optional[astropy.units.Unit, str]
The unit to convert to
- Returns:
- Union[astropy.units.Quantity, unxt.Quantity, array_like]
The converted array