flux_conversion_general#

jdaviz.core.unit_conversion_utils.flux_conversion_general(values, original_unit, target_unit, equivalencies=None, with_unit=True)[source]#

Converts values from original_unit to target_unit using the provided equivalencies 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 a u.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_unitUnit or str

The unit of the input values.

target_unitUnit 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_valuesQuantity or float

The converted values, with or without units based on with_unit.

Raises:
astropy.units.UnitConversionError

If the conversion between original_unit and target_unit fails despite the provided equivalencies.