11.1.12. Unit

This module implements units.

Shortcuts are defined to build unit values easily :

  • for each unit prefix, e.g. pico(), nano(), micro(), milli(), kilo(), mega(), tera(). These shortcuts return unit less values.

  • for each unit and prefix as the concatenation of u_, the unit prefix and the unit suffix, e.g. u_pV(), u_nV(), u_uV() u_mV(), u_V(), u_kV(), u_MV(), u_TV().

Theses unit value constructors accept int, float, object that can be converted to float, UnitValue instance and an iterable on these types.

A shortcut is defined to check an unit value match a particular unit, e.g. as_V(). Theses shortcuts return the value if the unit match else it raises the exception UnitError.

A shortcut is defined to access each unit, e.g. U_V(), U_A(), U_s(), U_Hz(), U_Ω(), U_F(), U_H.(), as well as for prefixes e.g. U_mV().

Some shortcuts have Unicode and ASCII variants:

  • For micro, we have the prefix μ and u.

  • For Ohm, we have u_Ω() and u_Ohm().

Some examples of usage:

foo = kilo(1) # unit less

resistance_unit = U_Ω

resistance1 = u_kΩ(1)
resistance1 = u_kOhm(1) # ASCII variant

resistance1 = 1@u_kΩ   # using Python 3.5 syntax
resistance1 = 1 @u_kΩ  # space doesn't matter
resistance1 = 1 @ u_kΩ #

resistance2 = as_Ω(resistance1) # check unit

resistances = u_kΩ(range(1, 11)) # same as [u_kΩ(x) for x in range(1, 11)]
resistances = range(1, 11)@u_kΩ  # using Python 3.5 syntax

capacitance = u_uF(200)
inductance = u_mH(1)
temperature = u_Degree(25)

voltage = resistance1 * u_mA(1) # compute unit

frequency = u_ms(20).frequency
period = u_Hz(50).period
pulsation = frequency.pulsation
pulsation = period.pulsation

Warning

According to the Python `operator precedence

<https://docs.python.org/3/reference/expressions.html#operator-precedence>`_, division operators have a higher priority than the matrix multiplication operator. In consequence you must had parenthesis to perform something like (10@u_s) / (2@_us).

class PySpice.Unit.FrequencyValue(prefixed_unit, value)[source]

Bases: PySpice.Unit.Unit.UnitValue, PySpice.Unit.Unit.FrequencyMixin

class PySpice.Unit.FrequencyValues(prefixed_unit, shape, dtype=<class 'float'>, buffer=None, offset=0, strides=None, order=None)[source]

Bases: PySpice.Unit.Unit.UnitValues

class PySpice.Unit.PeriodValue(prefixed_unit, value)[source]

Bases: PySpice.Unit.Unit.UnitValue, PySpice.Unit.Unit.PeriodMixin

class PySpice.Unit.PeriodValues(prefixed_unit, shape, dtype=<class 'float'>, buffer=None, offset=0, strides=None, order=None)[source]

Bases: PySpice.Unit.Unit.UnitValues

class PySpice.Unit.UnitValueShorcut(prefixed_unit)[source]

Bases: object

PySpice.Unit.atto(value)
PySpice.Unit.deca(value)
PySpice.Unit.define_shortcut(name, shortcut)[source]
PySpice.Unit.exa(value)
PySpice.Unit.femto(value)
PySpice.Unit.giga(value)
PySpice.Unit.hecto(value)
PySpice.Unit.kilo(value)
PySpice.Unit.mega(value)
PySpice.Unit.micro(value)
PySpice.Unit.milli(value)
PySpice.Unit.nano(value)
PySpice.Unit.peta(value)
PySpice.Unit.pico(value)
PySpice.Unit.tera(value)
PySpice.Unit.yocto(value)
PySpice.Unit.yotta(value)
PySpice.Unit.zepto(value)
PySpice.Unit.zetta(value)