to_header_quantity

sofia_redux.scan.utilities.utils.to_header_quantity(value, unit=None, keep=False)[source]

Convert a value to a Quantity suitable for header entry.

Converts various input types to a float or units.Quantity output value. If a dimensionless value is input, it will be multiplied by the unit if present. UNKNOWN header quantities (typically -9999) are preserved, and non-finite values also return the UNKNOWN float value.

Parameters:
valueint or float or str or units.Quantity or None

The value to convert.

unitstr or units.Unit or units.Quantity, optional

The units of the output value. If a units.Quantity value is supplied, the output value will be converted to the quantity unit and scaled by the quantity value. Dimensionless units will have no effect, while dimensionless quantities will still scale the value, but result in no conversion to an output unit.

keepbool, optional

If True, return the original value when invalid instead of the UNKNOWN_FLOAT_VALUE.

Returns:
header_quantityfloat or units.Quantity