flux_conversion_general#
- jdaviz.core.unit_conversion_utils.flux_conversion_general(values, original_unit, target_unit, equivalencies=None, with_unit=True)[source]#
Converts
valuesfromoriginal_unittotarget_unitusing the providedequivalencieswhile 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_densityequivalency, 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
Unitor str The unit of the input values.
- target_unit
Unitor 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
Quantityor float The converted values, with or without units based on
with_unit.
- converted_values
- Raises:
- astropy.units.UnitConversionError
If the conversion between
original_unitandtarget_unitfails despite the provided equivalencies.