eradiate.units#

Attributes#

eradiate.units.unit_context_config#

Unit context used when interpreting config dictionaries. Aliased in eradiate.

eradiate.units.unit_context_kernel#

Unit context used when building kernel dictionaries. Aliased in eradiate.

eradiate.units.unit_registry(*args, **kwargs)#

Unit registry common to all Eradiate components. All units used in Eradiate must be created using this registry. 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 for Spectrum 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 in quantity_map based on uctx.

Parameters:
  • d (dict) – Dictionary to apply unit conversion, checking and defaults.

  • quantity_map (dict[str, str]) – Dictionary mapping fields to quantity identifiers (see PhysicalQuantity for valid quantity IDs).

  • uctx (pinttr.UnitContext) – Unit context containing quantity and default units definitions.

  • force (bool, default: False) – If True, 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

PhysicalQuantity

eradiate.units.symbol(units)[source]#

Normalize a string or Pint units to a symbol string.

Parameters:

units (pint.Unit or str) – Value to convert to a symbol string.

Returns:

str – Symbol string (e.g. 'm' for 'metre', 'W / m ** 2' for 'W/m^2', etc.).

eradiate.units.to_quantity(da)[source]#

Converts a DataArray to a Quantity. The array’s attrs metadata mapping must contain a units 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.