eradiate.units
#
Attributes#
- eradiate.units.unit_context_config#
Unit context used when interpreting config dictionaries. Aliased in
eradiate
.
Enumerations#
- class eradiate.units.PhysicalQuantity(value)[source]#
An enumeration defining physical quantities known to Eradiate.
- classmethod spectrum()[source]#
Return a tuple containing a subset of
PhysicalQuantity
members suitable forSpectrum
initialization. This function caches its results for improved efficiency.
Functions#
- eradiate.units.interpret_quantities(d, quantity_map, uctx, force=False)[source]#
Advanced unit interpretation and wrapping for dictionaries. This function first calls
pinttr.interpret_units()
to interpret units attached to a given field. Then, it converts quantities and possibly applies default units to fields specified inquantity_map
based onuctx
.- Parameters:
d (
dict
) – Dictionary to apply unit conversion, checking and defaults.quantity_map (
dict[str
,str]
) – Dictionary mapping fields to quantity identifiers (seePhysicalQuantity
for valid quantity IDs).uctx (
pinttr.UnitContext
) – Unit context containing quantity and default units definitions.force (
bool
, default:False
) – IfTrue
, fields specified as quantities will be converted to target units; otherwise, only units compatibility will be checked.
- Returns:
dict
– Dictionary with units interpreted and checked, and default units applied to relevant fields.- Raises:
pinttr.UnitsError – If a field and its mapped quantity have incompatible units.
See also
- eradiate.units.to_quantity(da)[source]#
Converts a
DataArray
to aQuantity
. The array’sattrs
metadata mapping must contain aunits
field.- Parameters:
da (
DataArray
) –DataArray
instance which will be converted.- Returns:
quantity
– The corresponding Pint quantity.- Raises:
ValueError – If the array’s metadata do not contain a
units
field.
Notes
This function can also be used on coordinate variables.