UnitRegistry class

(Shortest import: from brian2.units.fundamentalunits import UnitRegistry)

class brian2.units.fundamentalunits.UnitRegistry[source]

Bases: object

Stores known units for printing in best units.

All a user needs to do is to use the register_new_unit() function.

Default registries:

The units module defines three registries, the standard units, user units, and additional units. Finding best units is done by first checking standard, then user, then additional. New user units are added by using the register_new_unit() function.

Standard units includes all the basic non-compound unit names built in to the module, including volt, amp, etc. Additional units defines some compound units like newton metre (Nm) etc.

Methods

add(u) Add a unit to the registry
__getitem__(x) Returns the best unit for quantity x

Details

add(u)[source]

Add a unit to the registry

__getitem__(x)[source]

Returns the best unit for quantity x

The algorithm is to consider the value:

m=abs(x/u)

for all matching units u. We select the unit where this ratio is the closest to 10 (if it is an array with several values, we select the unit where the deviations from that are the smallest. More precisely, the unit that minimizes the sum of (log10(m)-1)**2 over all entries).