pyre.units

Package Contents

class pyre.units.dimensional(value, derivation)

This class comprises the fundamental representation of quantities with units

fundamental = ['kg', 'm', 's', 'A', 'K', 'mol', 'cd']
zero
value = 0
derivation
isCompatible(self, other)

Predicate that checks whether {other} has the same derivation as I do

__add__(self, other)

Addition

__sub__(self, other)

Subtraction

__mul__(self, other)

Multiplication

__truediv__(self, other)

True division

__pow__(self, other)

Exponentiation

__pos__(self)

Unary plus

__neg__(self)

Unary minus

__abs__(self)

Absolute value

__rmul__(self, other)

Right multiplication

__rtruediv__(self, other)

Right division

__float__(self)

Conversion to float

__lt__(self, other)

Ordering: less than

__le__(self, other)

Ordering: less than or equal to

__eq__(self, other)

Ordering: equality

__ne__(self, other)

Ordering: not equal to

__gt__(self, other)

Ordering: greater than

__ge__(self, other)

Ordering: greater than or equal to

__str__(self)

Conversion to str

__format__(self, code)

Formatting support

The parameter {code} is a string of the form
value={format_spec},base={scale},label={label}
where
{format_spec}: a format specification appropriate for representing floats {scale}: a dimensional quantity to be used as a scale for the value {label}: the label with units that should follow the magnitude of the quantity
Example:
>>> from pyre.units.SI import m,s
>>> g = 9.81*m/s
>>> "{accel:value=.2f,base={scale},label=g}".format(accel=100*m/s**2, scale=g)
'10.2 g'
_strDerivation(self)

Build a representation of the fundamental unit labels raised to the exponents specified in my derivation.

The unit parser can parse this textual representation and convert it back into a dimensional quantity.

pyre.units.fundamental
pyre.units.zero
class pyre.units.parser(**kwds)

Singleton that converts string representations of dimensional quantities into instances of Dimensional

parse(self, text, context=None)

Convert the string representation in {text} into a dimensional quantity

_initializeContext(self)

Build the initial list of resolvable unit symbols

pyre.units.quantities()

Build a list of all available modules