brainunit.UNITLESS#
- brainunit.UNITLESS = Unit("1")#
A physical unit.
Basically, a unit is just a number with given dimensions, e.g. mvolt = 0.001 with the dimensions of voltage. The units module defines a large number of standard units, and you can also define your own (see below).
Mathematically, a unit represents:
\[\text{{factor}} \times \text{{base}}^{\text{{scale}}} \times \text{{dimension}}\]where the
factoris the conversion factor of the unit (e.g.1 calorie = 4.18400 Joule, so the factor is 4.18400), thebaseis the base of the exponent (e.g. 10 for the kilo prefix), thescaleis the exponent of the base (e.g. 3 for the kilo prefix), and thedimensionis the physical dimensions of the unit (e.g.joulefor energy).The unit class also keeps track of various things that were used to define it so as to generate a nice string representation of it. See below.
- Parameters:
dim (Dimension, optional) – The physical dimensions of the unit. Defaults to
DIMENSIONLESS.scale (array_like, optional) – The scale exponent, e.g. 3 for a “k” (kilo) prefix. Defaults to 0.
base (array_like, optional) – The base of the exponent, e.g. 10 for SI prefixes. Defaults to 10.
factor (array_like, optional) – The conversion factor of the unit. Defaults to 1.
name (str, optional) – The full name of the unit, e.g.
'volt'.dispname (str, optional) – The display name, e.g.
'V'.is_fullname (bool, optional) – Whether
nameis the canonical full name. Defaults toTrue.display_parts (list of tuple, optional) – Canonical display components for compound units.
Notes
When creating scaled units, you can use the following prefixes:
Factor
Name
Prefix
10^24
yotta
Y
10^21
zetta
Z
10^18
exa
E
10^15
peta
P
10^12
tera
T
10^9
giga
G
10^6
mega
M
10^3
kilo
k
10^2
hecto
h
10^1
deka
da
1
10^-1
deci
d
10^-2
centi
c
10^-3
milli
m
10^-6
micro
u (mu in SI)
10^-9
nano
n
10^-12
pico
p
10^-15
femto
f
10^-18
atto
a
10^-21
zepto
z
10^-24
yocto
y
Defining your own
It can be useful to define your own units for printing purposes. So for example, to define the newton metre, you write:
>>> import saiunit as u >>> Nm = u.newton * u.metre
You can then do:
>>> (1 * Nm).in_unit(Nm) '1. N m'
New “compound units”, i.e. units that are composed of other units will be automatically registered and from then on used for display. For example, imagine you define total conductance for a membrane, and the total area of that membrane:
>>> import saiunit as u >>> conductance = 10. * u.nS >>> area = 20000 * u.um ** 2
If you now ask for the conductance density, you will get an “ugly” display in basic SI dimensions, as saiunit does not know of a corresponding unit:
>>> conductance / area 0.5 * metre ** -4 * kilogram ** -1 * second ** 3 * amp ** 2
By using an appropriate unit once, it will be registered and from then on used for display when appropriate:
>>> u.usiemens / u.cm ** 2 usiemens / (cmetre ** 2) >>> conductance / area # same as before, but now knows about uS/cm^2 50. * usiemens / (cmetre ** 2)
Note that user-defined units cannot override the standard units (
volt,second, etc.) that are predefined. For example, the unitNmhas the dimensions “length^2 * mass / time^2”, and therefore the same dimensions as the standard unitjoule. The latter will be used for display purposes:>>> 3 * u.joule 3. * joule >>> 3 * Nm 3. * joule
Examples
Create a simple unit:
>>> import saiunit as u >>> u.volt Unit("V") >>> u.mvolt Unit("mV")
Combine units:
>>> import saiunit as u >>> u.volt / u.amp Unit("V / A")