Package openmdao.units

This package is based on the PhysicalQuantity package that is part of ScientificPython. It performs unit conversions.

units.py

This module provides a data type that represents a physical quantity together with its unit. It is possible to add and subtract these quantities if the units are compatible and a quantity can be converted to another compatible unit. Multiplication, subtraction, and raising to integer powers are allowed without restriction, and the result will have the correct unit. A quantity can be raised to a non-integer power only if the result can be represented by integer powers of the base units.

The module provides a basic set of predefined physical quanitites in its built-in library; however, it also supports generation of personal libararies which can be saved and reused.

This module is based on the PhysicalQuantities module in Scientific Python, by Konrad Hinsen. Modifications by Justin Gray.

class openmdao.units.units.NumberDict[source]

Bases: dict

Dictionary storing numerical values.

Constructor: NumberDict()

An instance of this class acts like an array of numbers with generalized (non-integer) indices. A value of zero is assumed for undefined entries. NumberDict instances support addition and subtraction with other NumberDict instances, and multiplication and division by scalars.

class openmdao.units.units.PhysicalQuantity(*args)[source]

Bases: object

Physical quantity with units

PhysicalQuantity instances allow addition, subtraction, multiplication, and division with each other as well as multiplication, division, and exponentiation with numbers. Addition and subtraction check that the units of the two operands are compatible and return the result in the units of the first operand.

convert_to_unit(unit)[source]

Change the unit and adjust the value so that the combination is equivalent to the original one. The new unit must be compatible with the previous unit of the object.

@param unit: a unit @type unit: C{str} @raise TypeError: if the unit string is not a known unit or a unit incompatible with the current one.

convert_value(target_unit)[source]

Converts the values of the PQ to the target_unit.

cos()[source]

Parsing Cosine.

get_unit_name()[source]

Return unit (string) of physical quantity.

get_value()[source]

Return value (float) of physical quantity (no unit).

in_base_units()[source]

@returns: the same quantity converted to base units, i.e., SI units in most cases @rtype: L{PhysicalQuantity}

in_units_of(unit)[source]

Express the quantity in different units. If one unit is specified, a new PhysicalQuantity object is returned that expresses the quantity in that unit. If several units are specified, the return value is a tuple of PhysicalObject instances with with one element per unit such that the sum of all quantities in the tuple equals the original quantity and all the values except for the last one are integers. This is used to convert to irregular unit systems like hour/minute/second.

@param units: one or several units @type units: C{str} or sequence of C{str} @returns: one or more physical quantities @rtype: L{PhysicalQuantity} or C{tuple} of L{PhysicalQuantity} @raises TypeError: if any of the specified units are not compatible with the original unit.

is_compatible(unit)[source]

@param unit: a unit @type unit: C{str} @returns: C{True} if the specified unit is compatible with the one of the quantity. @rtype: C{bool}.

sin()[source]

Parsing Sine.

sqrt()[source]

Parsing Square Root

tan()[source]

Parsing tangent.

class openmdao.units.units.PhysicalUnit(names, factor, powers, offset=0)[source]

Bases: object

Physical unit.

A physical unit is defined by a name (possibly composite), a scaling factor, and the exponentials of each of the SI base units that enter into it. Units can be multiplied, divided, and raised to integer powers.

conversion_factor_to(other)[source]

@param other: another unit @type other: L{PhysicalUnit} @returns: the conversion factor from this unit to another unit @rtype: C{float} @raises TypeError: if the units are not compatible.

conversion_tuple_to(other)[source]

@param other: another unit @type other: L{PhysicalUnit} @returns: the conversion factor and offset from this unit to another unit @rtype: (C{float}, C{float}) @raises TypeError: if the units are not compatible.

is_angle()[source]

Checks if this PQ is an Angle.

is_compatible(other)[source]

@param other: another unit @type other: L{PhysicalUnit} @returns: C{True} if the units are compatible, i.e., if the powers of the base units are the same @rtype: C{bool}.

is_dimensionless()[source]

Dimensionless PQ.

name()[source]

Looks like it’s parsing fractions.

set_name(name)[source]

Sets the name.

openmdao.units.units.add_offset_unit(name, baseunit, factor, offset, comment='')[source]

Adding Offset Unit.

openmdao.units.units.add_unit(name, unit, comment='')[source]

Adding Unit.

openmdao.units.units.convert_units(value, units, convunits)[source]

Return the given value (given in units) converted to convunits.

openmdao.units.units.import_library(libfilepointer)[source]

Imports a units library, replacing any existing definitions.

openmdao.units.units.update_library(filename)[source]

Update units in current library from filename which must contain a units section.

filename: string or file
Source of units configuration data.
OpenMDAO Home

Table Of Contents

Previous topic

Package openmdao.test

Next topic

Package openmdao.util

This Page