EngVal

This module handles engineering values i.e. a real numeric value associated with a unit-of-measure.

Operator Overloading

EngVals can be operated on by a real number or an other EngVal.

Addition and subtraction

The operators +, -, +=, -= work on mixed real numbers and EngVals as expected. If two EngVal objects then unit conversion is performed before the operation. If the two EngVals have units in different categories an ExceptionUnit will be raised.

Division

Operators /, /= are implemented.

Division of an EngVal by a real number preserves the EngVal units.

The result of a division of an EngVal by an EngVal will have the following units:

  • It preserves the numerator EngVal units if the denominator units are DIMENSIONLESS.

  • The result will have DIMENSIONLESS EngVal units if the numerator and denominator

    have units that are freely convertible i.e. in the same unit category.

If neither condition can be satisfied then an ExceptionUnit will be raised.

Multiplication

Operators *, *= are implemented for reals and EngVals. If an EngVal the units must be DIMENSIONLESS.

Notes

Limitations

There are some limitations in which units the result has. For example dividing a dimensionless number with say metres does not result in the units 1/m (instead an ExceptionUnit is raised). Similarly multiplying metres by meters does not result in m2 units (again an ExceptionUnit is raised).

Type of result

rval operators are implemented and this can result in type promotion. For example the result of 4.0 * EngVal(16, b’INCH’) is an EngVal(64.0, b’INCH’).

Created on 24 Nov 2010

EngVal Reference

class TotalDepth.LIS.core.EngVal.EngVal(theVal, theUom=Mnem(b'x00x00x00x00'))

Represents an engineering value that consists of a numeric value and a unit of measure (usually a string).

__add__(other)

Overload self+other, returned result has the sum of self and other. other can be an EngVal or a Real number. The units chosen are self’s.

__eq__(other)

True if self == other False otherwise. If other is an EngVal unit conversion is performed which may raise an ExceptionUnit. If other is a real number then self units are ignored.

__ge__(other)

True if self >= other False otherwise. If other is an EngVal unit conversion is performed which may raise an ExceptionUnit. If other is a real number then self units are ignored.

__gt__(other)

True if self > other False otherwise. If other is an EngVal unit conversion is performed which may raise an ExceptionUnit. If other is a real number then self units are ignored.

__iadd__(other)

Addition in place, other must be a real number or an EngVal where it is converted to my units.

__imul__(other)

Overload self *= other. other must be a real number or a dimensionless EngVal.

__isub__(other)

Subtraction in place, other must be a real number or an EngVal where it is converted to my units.

__itruediv__(other)

Overload self /= other. other must be a real number or a dimensionless EngVal.

__le__(other)

True if self <= other False otherwise. If other is an EngVal unit conversion is performed which may raise an ExceptionUnit. If other is a real number then self units are ignored.

__lt__(other)

True if self < other False otherwise. If other is an EngVal unit conversion is performed which may raise an ExceptionUnit. If other is a real number then self units are ignored.

__mul__(other)

Overload self*other. other must be a real number or a dimensionless EngVal.

__ne__(other)

True if self != other False otherwise. If other is an EngVal unit conversion is performed which may raise an ExceptionUnit. If other is a real number then self units are ignored.

__radd__(other)

Right value addition, see __add__().

__rmul__(other)

Right value multiplication, see __mul__().

__rsub__(other)

Right value subtraction, see __sub__().

__rtruediv__(other)

Right value true division, see __truediv__().

__str__()

String representation.

__sub__(other)

Overload self-other, returned result has the sum of self and other. The units chosen are self’s.

__truediv__(other)

Overload self/other. other must be a real number or an EngVal. If the units of other are dimensionless then treat as a real number. If the units are in the same category as me convert them and return a dimensionless EngVal.

__weakref__

list of weak references to the object (if defined)

convert(theUnits)

Convert my value to the supplied units in-place. May raise an ExceptionUnits.

dimensionless()

Returns True if the measure is dimensionless.

getInUnits(theUnits)

Returns my value to the supplied units. May raise an ExceptionUnits.

newEngValInOpticalUnits()

Returns a new EngVal converting me to the ‘optical’ units if possible. For example a value in b’.1IN” will be converted to b’FEET’.

newEngValInUnits(theUnits)

Returns a new EngVal converting me to the supplied units. May raise an ExceptionUnits.

pStr()

Returns a ‘pretty’ ASCII string.

strFormat(theFormat, incPrefix=True)

Returns as as string with the value to the specified format (must be capable of handling floating point values.

class TotalDepth.LIS.core.EngVal.EngValRc(theVal, theUom, theRc=None)

An engineering value with a integer Representation Code.

__str__()

String representation.

encode()

Encode my value to my RepCode returning a bytes object. May raise an ExceptionEngVal.

Table Of Contents

Previous topic

Units

Next topic

Mnem

This Page