vivarium.library.units module

Units

Here is where we create the units object from which we pull units throughout Vivarium. We also define utility functions for working with units. Here we also import the _Quantity type as Quantity, which you can use to check if some variable has units. For example:

>>> a = 5 * units.fg
>>> b = 10
>>> isinstance(a, Quantity)
True
>>> isinstance(b, Quantity)
False
>>> a.magnitude
5
>>> isinstance(a.magnitude, Quantity)
False
vivarium.library.units.remove_units(collection)[source]

Strip the units from a collection or scalar

If no units are present, the provided object is returned unaltered. Note that we assume that the provided collection consists solely of lists, dictionaries, Quantity objects with units to strip, and scalars. Behavior is undefined for other structures.

Removal is “deep,” meaning that we remove units in nested structures as well. For instance, given a dictionary:

>>> d = {'a': [1, 3, {4: 3 * units.fg}, 2 * units.fg]}
>>> remove_units(d)
{'a': [1, 3, {4: 3}, 2]}
Parameters

collection (object) – The collection or scalar to strip units from.

Returns

The collection or scalar without any units.

vivarium.library.units.units = <pint.registry.UnitRegistry object>

Units registry that stores the units used throughout Vivarium