ecoli.library.units

ecoli.library.units.add_units(magnitudes, units, strict=True)[source]

Combine a tree of magnitudes with a tree of units.

Intended to be used as the inverse of remove_units().

ecoli.library.units.remove_units(quantity_tree, expected_units_tree=None, path=())[source]

Split a tree of Quantities into units and magnitudes.

Parameters:
  • quantity_tree (dict[str, Any]) – The nested dictionary representing the tree of Quantity objects to split. This tree may also contain non-Quantity leaf nodes, which will be treated as unitless values.

  • expected_units_tree (dict[str, Any]) – A nested dictionary of the same shape as quantity_tree specifying expected units for various leaf nodes. If a leaf is present in quantity_tree but not expected_units_tree, no assertion will be made as to whether that node has units. A Quantity with an associated expected unit will be converted to that unit before being split.

  • path (tuple[str]) – Path to the root of quantity_tree. Used mainly for recursion.

Returns:

Two trees (as nested dictionaries), one with the magnitudes and another with the units. The units are from after any conversions imposed by expected_units_tree.

Raises:

ValueError – If a leaf node in quantity_tree unexpectedly has no units.

Return type:

tuple[dict[str, Any], dict[str, Any]]