mpacts.core.units. quantity

copyright:2016 by Pint Authors, see AUTHORS for more details.
license:BSD, see LICENSE for more details.

In order to be able to use this module import it like this:

import mpacts.core.units.quantity
#or assign it to a shorter name
import mpacts.core.units.quantity as qua

_Exception

class mpacts.core.units.quantity._Exception(internal)

Bases: exceptions.Exception

_Exception(name, parent, **kwargs)

_Quantity

class mpacts.core.units.quantity._Quantity

Bases: mpacts.core.units.util.SharedRegistryObject

Implements a class to describe a physical quantity: the product of a numerical value and a unit of measurement.

Parameters:
  • value (str, Quantity or any numeric type.) – value of the physical quantity to be created.
  • units (UnitsContainer, str or Quantity.) – units of the physical quantity to be created.
_Quantity(name, parent, **kwargs)
T
clip(first=None, second=None, out=None, **kwargs)
compare(other, op)
compatible_units(*contexts)
debug_used
default_format = u''

Default formatting string.

dimensionality

Quantity’s dimensionality (e.g. {length: 1, time: -1})

dimensionless

Return true if the quantity is dimensionless.

fill(value)
flat
format_babel(spec=u'', **kwspec)
classmethod from_tuple(tup)
imag
ito(other=None, *contexts, **ctx_kwargs)

Inplace rescale to different units.

Parameters:other (Quantity, str or dict) – destination units.
ito_base_units()

Return Quantity rescaled to base units

ito_root_units()

Return Quantity rescaled to base units

m

Quantity’s magnitude. Short form for magnitude

m_SI

Quantity’s magnitude in basic SI units. Short form for magnitude_SI

m_as(units)

Quantity’s magnitude expressed in particular units.

Parameters:units (Quantity, str or dict) – destination units
magnitude

Quantity’s magnitude. Long form for m

magnitude_SI

Quantity’s magnitude in basic SI unit. Long form for m_SI

magnitude_tuple

Quantity’s magnitude as a tuple if more than 1D. Long form for m

plus_minus(error, relative=False)
put(indices, values, mode=u'raise')
real
searchsorted(v, side=u'left')
shape
to(other=None, *contexts, **ctx_kwargs)

Return Quantity rescaled to different units.

Parameters:other (Quantity, str or dict) – destination units.
to_base_units()

Return Quantity rescaled to base units

to_compact(unit=None)

Return Quantity rescaled to compact, human-readable units.

To get output in terms of a different unit, use the unit parameter.

>>> import mpacts.core.units
>>> ureg = mpacts.core.units.UnitRegistry()
>>> (200e-9*ureg.s).to_compact()
<Quantity(200.0, 'nanosecond')>
>>> (1e-2*ureg('kg m/s^2')).to_compact('N')
<Quantity(10.0, 'millinewton')>
to_root_units()

Return Quantity rescaled to base units

to_tuple()
tolist()
u

Quantity’s units. Short form for units

Return type:UnitContainer
unitless

Return true if the quantity does not have units.

units

Quantity’s units. Long form for u

Return type:UnitContainer
mpacts.core.units.quantity._eq(first, second, check_all)

Comparison of scalars and arrays

mpacts.core.units.quantity.build_quantity_class(registry, force_ndarray=False)