brainunit.add_standard_unit

brainunit.add_standard_unit#

brainunit.add_standard_unit(u, *, auto_simplify=False)[source]#

Register a unit as a standard unit.

Registered units are recognised by parse_unit() (by name and display name) and are the targets of Unit.simplify(). If multiple units are registered for the same key, the preferred alias is selected automatically. Keys with two or more distinct display names are flagged as ambiguous.

Parameters:
  • u (Unit) – The unit to register. Its base, scale, and factor must all be plain Python int or float values (not JAX tracers) for registration to take effect.

  • auto_simplify (bool) – If True, unit arithmetic whose result has exactly this unit’s dimension and magnitude is displayed as this unit (e.g. kg * m / s^2 displays as N). Only meaningful for a named (non-composite) unit. Defaults to False.

Examples

>>> import saiunit as u
>>> my_unit = u.Unit(
...     dim=u.joule.dim,
...     name='my_energy',
...     dispname='myE',
...     is_fullname=True,
... )
>>> u.add_standard_unit(my_unit)