mpacts.core.units. util

Miscellaneous functions for mpacts.units.

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.util
#or assign it to a shorter name
import mpacts.core.units.util as uti


class mpacts.core.units.util.BlockIterator

Bases: mpacts.core.units.util.SourceIterator

Like SourceIterator but stops when it finds '@end‘ It also raises an error if another ‘@’ directive is found inside.

BlockIterator(name, parent, **kwargs)


class mpacts.core.units.util.SharedRegistryObject

Bases: object

Base class for object keeping a refrence to the registree.

Such object are for now _Quantity and _Unit, in a number of places it is that an object from this class has a ‘_units’ attribute.

SharedRegistryObject(name, parent, **kwargs)


class mpacts.core.units.util.SourceIterator

Bases: object

Iterator to facilitate reading the definition files.

Accepts any sequence (like a list of lines, a file or another SourceIterator)

The iterator yields the line number and line (skipping comments and empty lines) and stripping white spaces.

for lineno, line in SourceIterator(sequence):
# do something here
SourceIterator(name, parent, **kwargs)

Iterate block including header.

mpacts.core.units.util.column_echelon_form(matrix, ntype=<class 'fractions.Fraction'>, transpose_result=False)

Calculates the column echelon form using Gaussian elimination.

  • matrix – a 2D matrix as nested list.
  • ntype – the numerical type to use in the calculation.
  • transpose_result – indicates if the returned matrix should be transposed.

column echelon form, transformed identity matrix, swapped rows

mpacts.core.units.util.find_connected_nodes(graph, start, visited=None)
mpacts.core.units.util.find_shortest_path(graph, start, end, path=None)

Enable python2/3 compatible behaviour for __str__.


Return UnitsContainer of q with all prefixes stripped.

mpacts.core.units.util.matrix_to_string(matrix, row_headers=None, col_headers=None, fmtfun=<function <lambda>>)

Takes a 2D matrix (as nested list) and returns a string.

mpacts.core.units.util.pi_theorem(quantities, registry=None)

Builds dimensionless quantities using the Buckingham π theorem

Parameters:quantities (dict) – mapping between variable name and units
Returns:a list of dimensionless quantities expressed as dicts

Solve a dependency graph.

Parameters:dependencies – dependency dictionary. For each key, the value is an iterable indicating its dependencies.
Returns:list of sets, each containing keys of independents tasks dependent only of the previous tasks in the list.
mpacts.core.units.util.to_units_container(unit_like, registry=None)

Convert a unit compatible type to a UnitsContainer.


Takes a 2D matrix (as nested list) and returns the transposed version.


class mpacts.core.units.util.udict

Bases: dict

Custom dict implementing __missing__.

udict(name, parent, **kwargs)