flux_conversion_general#
- jdaviz.core.unit_conversion_utils.flux_conversion_general(values, original_unit, target_unit, equivalencies=None, with_unit=True)[source]#
Converts
values
fromoriginal_unit
totarget_unit
using the providedequivalencies
while handling special cases where direct unit conversion is not possible. This function is designed to account for scenarios like conversions involving flux to surface brightness that also require au.spectral_density
equivalency, conversions between per-square pixel surface brightnesses that don’t convert directly, and other flux to surface brightness conversions.This function should be used for unit conversions when possible instead of directly using Astropy’s
unit.to()
, as it handles additional logic for special cases.- Parameters:
- valuesarray-like or float
The numerical values to be converted.
- original_unit
Unit
or str The unit of the input values.
- target_unit
Unit
or str The desired unit to convert to.
- equivalencieslist of equivalencies, optional
Unit equivalencies to apply during the conversion.
- with_unitbool, optional
If True, the returned value retains its unit. If False, only the numerical values are returned.
- Returns:
- converted_values
Quantity
or float The converted values, with or without units based on
with_unit
.
- converted_values
- Raises:
- astropy.units.UnitConversionError
If the conversion between
original_unit
andtarget_unit
fails despite the provided equivalencies.