mpacts.core.units. systems

Functions and classes related to system definitions and conversions.

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

Lister

class mpacts.core.units.systems.Lister(d)

Bases: object

Lister(name, parent, **kwargs)

_Group

class mpacts.core.units.systems._Group(name)

Bases: mpacts.core.units.util.SharedRegistryObject

A group is a set of units.

Units can be added directly or by including other groups.

Members are computed dynamically, that is if a unit is added to a group X all groups that include X are affected.

The group belongs to one Registry.

It can be specified in the definition file as:

@group <name> [using <group 1>, ..., <group N>]
<definition 1> ... <definition N>

@end

Parameters:
  • name (str) – Name of the group. If not given, a root Group will be created.
  • groups (dict[str | Group]) – dictionary like object groups and system. The newly created group will be added after creation.
_Group(name, parent, **kwargs)
add_groups(*group_names)

Add groups to group.

add_units(*unit_names)

Add units to group.

classmethod from_lines(lines, define_func)

Return a Group object parsing an iterable of lines.

Parameters:
  • lines (list[str]) – iterable
  • define_func (str -> None) – Function to define a unit in the registry.
invalidate_members()

Invalidate computed members in this Group and all parent nodes.

is_used_group(group_name)
iter_used_groups()
members

Names of the units that are members of the group.

Calculated to include to all units in all included _used_groups.

Return type:frozenset[str]
name = None

type: str

non_inherited_unit_names
remove_groups(*group_names)

Remove groups from group.

remove_units(*unit_names)

Remove units from group.

_System

class mpacts.core.units.systems._System(name)

Bases: mpacts.core.units.util.SharedRegistryObject

A system is a Group plus a set of base units.

Members are computed dynamically, that is if a unit is added to a group X all groups that include X are affected.

The System belongs to one Registry.

It can be specified in the definition file as:

@system <name> [using <group 1>, ..., <group N>]
<rule 1> ... <rule N>

@end

The syntax for the rule is:

new_unit_name : old_unit_name
where:
  • old_unit_name: a root unit part which is going to be removed from the system.
  • new_unit_name: a non root unit which is going to replace the old_unit.

If the new_unit_name and the old_unit_name, the later and the colon can be ommited.

Parameters:name (str) – Name of the group
_System(name, parent, **kwargs)
add_groups(*group_names)

Add groups to group.

base_units = None

Maps root unit names to a dict indicating the new unit and its exponent. :type: dict[str, dict[str, number]]]

derived_units = None

Derived unit names. :type: set(str)

format_babel(locale)

translate the name of the system

classmethod from_lines(lines, get_root_func)
invalidate_members()

Invalidate computed members in this Group and all parent nodes.

members
name = None

Name of the system :type: str

remove_groups(*group_names)

Remove groups from group.

mpacts.core.units.systems.build_group_class(registry)
mpacts.core.units.systems.build_system_class(registry)