SUAVE  2.5.2
An Aerospace Vehicle Environment for Designing Future Aircraft
SUAVE.Plugins.pint.unit.UnitRegistry Class Reference
Inheritance diagram for SUAVE.Plugins.pint.unit.UnitRegistry:

Public Member Functions

def __init__ (self, filename='', force_ndarray=False, default_to_delta=True)
def __getattr__ (self, item)
def __getitem__ (self, item)
def __dir__ (self)
def default_format (self)
def default_format (self, value)
def add_context (self, context)
def remove_context (self, name_or_alias)
def enable_contexts (self, *names_or_contexts, **kwargs)
def disable_contexts (self, n=None)
def context (self, *names, **kwargs)
def define (self, definition)
def load_definitions (self, file, is_resource=False)
def validate (self)
def get_name (self, name_or_alias)
def get_symbol (self, name_or_alias)
def get_dimensionality (self, input_units)
def get_base_units (self, input_units)
def convert (self, value, src, dst)
def pi_theorem (self, quantities)
def parse_unit_name (self, unit_name)
def parse_units (self, input_string, to_delta=None)
def parse_expression (self, input_string, **values)
def wraps (self, ret, args, strict=True)

Public Attributes


Detailed Description

The unit registry stores the definitions and relationships between

:param filename: path of the units definition file to load.
                 Empty to load the default definition file.
                 None to leave the UnitRegistry empty.
:param force_ndarray: convert any input, scalar or not to a numpy.ndarray.
:param default_to_delta: In the context of a multiplication of units, interpret
                         non-multiplicative units as their *delta* counterparts.

Member Function Documentation

◆ add_context()

def SUAVE.Plugins.pint.unit.UnitRegistry.add_context (   self,
Add a context object to the registry.

The context will be accessible by its name and aliases.

Notice that this method will NOT enable the context. Use `enable_contexts`.

◆ context()

def SUAVE.Plugins.pint.unit.UnitRegistry.context (   self,
**  kwargs 
Used as a context manager, this function enables to activate a context
which is removed after usage.

:param names: name of the context.
:param kwargs: keyword arguments for the contexts.

Context are called by their name::

    >>> with ureg.context('one'):
    ...     pass

If the context has an argument, you can specify it's value as a keyword

    >>> with ureg.context('one', n=1):
    ...     pass

Multiple contexts can be entered in single call:

    >>> with ureg.context('one', 'two', n=1):
    ...     pass

or nested allowing you to give different values to the same keyword argument::

    >>> with ureg.context('one', n=1):
    ...     with ureg.context('two', n=2):
    ...         pass

A nested context inherits the defaults from the containing context::

    >>> with ureg.context('one', n=1):
    ...     with ureg.context('two'): # Here n takes the value of the upper context
    ...         pass

◆ convert()

def SUAVE.Plugins.pint.unit.UnitRegistry.convert (   self,
Convert value from some source to destination units.

:param value: value
:param src: source units.
:type src: UnitsContainer or str
:param dst: destination units.
:type dst: UnitsContainer or str

:return: converted value

◆ default_format()

def SUAVE.Plugins.pint.unit.UnitRegistry.default_format (   self)
Default formatting string for quantities.

◆ define()

def SUAVE.Plugins.pint.unit.UnitRegistry.define (   self,
Add unit to the registry.

◆ disable_contexts()

def SUAVE.Plugins.pint.unit.UnitRegistry.disable_contexts (   self,
  n = None 
Disable the last n enabled contexts.

◆ enable_contexts()

def SUAVE.Plugins.pint.unit.UnitRegistry.enable_contexts (   self,
**  kwargs 
Enable contexts provided by name or by object.

:param names_or_contexts: sequence of the contexts or contexts names/alias
:param kwargs: keyword arguments for the context

◆ get_base_units()

def SUAVE.Plugins.pint.unit.UnitRegistry.get_base_units (   self,
Convert unit or dict of units to the base units.

If the unit is non multiplicative, None is returned as
the multiplicative factor.

:param input_units:
:return: multiplicative factor, base units

◆ get_dimensionality()

def SUAVE.Plugins.pint.unit.UnitRegistry.get_dimensionality (   self,
Convert unit or dict of units or dimensions to a dict of base dimensions

:param input_units:
:return: dimensionality

◆ get_name()

def SUAVE.Plugins.pint.unit.UnitRegistry.get_name (   self,
Return the canonical name of a unit.

◆ get_symbol()

def SUAVE.Plugins.pint.unit.UnitRegistry.get_symbol (   self,
Return the preferred alias for a unit

◆ load_definitions()

def SUAVE.Plugins.pint.unit.UnitRegistry.load_definitions (   self,
  is_resource = False 
Add units and prefixes defined in a definition text file.

◆ parse_expression()

def SUAVE.Plugins.pint.unit.UnitRegistry.parse_expression (   self,
**  values 
Parse a mathematical expression including units and return a quantity object.

Numerical constants can be specified as keyword arguments and will take precedence
over the names defined in the registry.

◆ parse_unit_name()

def SUAVE.Plugins.pint.unit.UnitRegistry.parse_unit_name (   self,
Parse a unit to identify prefix, unit name and suffix
by walking the list of prefix and suffix.

◆ parse_units()

def SUAVE.Plugins.pint.unit.UnitRegistry.parse_units (   self,
  to_delta = None 
Parse a units expression and returns a UnitContainer with
the canonical names.

The expression can only contain products, ratios and powers of units.

:param to_delta: if the expression has multiple units, the parser will
         interpret non multiplicative units as their `delta_` counterparts.

    :class:`pint.UndefinedUnitError` if a unit is not in the registry
    :class:`ValueError` if the expression is invalid.

◆ pi_theorem()

def SUAVE.Plugins.pint.unit.UnitRegistry.pi_theorem (   self,
Builds dimensionless quantities using the Buckingham π theorem

:param quantities: mapping between variable name and units
:type quantities: dict
:return: a list of dimensionless quantities expressed as dicts

◆ remove_context()

def SUAVE.Plugins.pint.unit.UnitRegistry.remove_context (   self,
Remove a context from the registry and return it.

Notice that this methods will not disable the context. Use `disable_contexts`.

◆ validate()

def SUAVE.Plugins.pint.unit.UnitRegistry.validate (   self)
Walk the registry and calculate for each unit definition
the corresponding base units and dimensionality.

◆ wraps()

def SUAVE.Plugins.pint.unit.UnitRegistry.wraps (   self,
  strict = True 
Wraps a function to become pint-aware.

Use it when a function requires a numerical value but in some specific
units. The wrapper function will take a pint quantity, convert to the units
specified in `args` and then call the wrapped function with the resulting

The value returned by the wrapped function will be converted to the units
specified in `ret`.

Use None to skip argument conversion.
Set strict to False, to accept also numerical values.

:param ret: output units.
:param args: iterable of input units.
:param strict: boolean to indicate that only quantities are accepted.
:return: the wrapped function.
    :class:`ValueError` if strict and one of the arguments is not a Quantity.

The documentation for this class was generated from the following file: