PySharp Units of Measure
Units of Measure in Python
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
uom.unit_of_measure.UnitOfMeasure Class Reference

The UnitOfMeasure class represents a unit of measure. More...

Inheritance diagram for uom.unit_of_measure.UnitOfMeasure:

Public Member Functions

def __init__ (self, unitType=UnitType.UNCLASSIFIED, name=None, symbol=None, description=None)
 
def __hash__ (self)
 
def __eq__ (self, other)
 
def __lt__ (self, other)
 
def __gt__ (self, other)
 
def __ne__ (self, other)
 
def __str__ (self)
 
def setBaseSymbol (self, symbol)
 
def setPowerProduct (self, uom1, exponent1, uom2, exponent2)
 
def setProductUnits (self, multiplier, multiplicand)
 Set the multiplier and multiplicand. More...
 
def setQuotientUnits (self, dividend, divisor)
 Set the dividend and divisor. More...
 
def getMeasurementType (self)
 Get the measurement type. More...
 
def getReducer (self)
 
def getBaseUnitsOfMeasure (self)
 Get the most reduced units of measure. More...
 
def isTerminal (self)
 Check to see if this unit of measure has a conversion to another unit of measure other than itself. More...
 
def setBridgeConversion (self, scalingFactor, abscissaUnit, offset)
 
def setConversion (self, scalingFactor, abscissaUnit, offset=0.0)
 Define a conversion with the specified scaling factor, abscissa unit of measure and scaling factor. More...
 
def getPowerExponent (self)
 Get the exponent of a power unit. More...
 
def getDividend (self)
 Get the dividend unit of measure. More...
 
def getDivisor (self)
 Get the divisor unit of measure. More...
 
def getMultiplier (self)
 Get the multiplier. More...
 
def getMultiplicand (self)
 Get the multiplicand. More...
 
def setPowerUnit (self, base, exponent)
 Set the base unit of measure and exponent. More...
 
def clonePower (self, uom)
 
def classify (self)
 If the unit of measure is unclassified, from its base unit map find a matching unit type. More...
 
def getBaseSymbol (self)
 Get the unit of measure symbol in the fundamental units for that system. More...
 
def traversePath (self)
 
def checkOffset (self, other)
 
def clearCache (self)
 
def clonePowerProduct (self, uom1, uom2)
 
def multiplyOrDivide (self, other, invert)
 
def convertScalarToScalar (self, targetUOM)
 
def getBridgeFactor (self, uom)
 
def divide (self, divisor)
 Divide two units of measure to create a third one. More...
 
def getBaseUOM (self)
 
def convertUnit (self, targetUOM)
 
def getConversionFactor (self, targetUOM)
 Get the factor to convert to the unit of measure. More...
 
def getPowerBase (self)
 Get the base unit of measure for the power. More...
 
def invert (self)
 Invert a unit of measure to create a new one. More...
 
def multiply (self, multiplicand)
 Multiply two units of measure to create a third one. More...
 

Static Public Member Functions

def isValidExponent (exponent)
 Check to see if the exponent is valid. More...
 
def generateIntermediateSymbol ()
 
def generatePowerSymbol (base, exponent)
 
def generateProductSymbol (multiplier, multiplicand)
 
def generateQuotientSymbol (dividend, divisor)
 
def checkTypes (uom1, uom2)
 

Public Attributes

 conversionRegistry
 
 category
 
 unit
 
 unitType
 
 abscissaUnit
 
 scalingFactor
 
 offset
 
 uom1
 
 uom2
 
 exponent1
 
 exponent2
 
 bridgeScalingFactor
 
 bridgeOffset
 
 bridgeAbscissaUnit
 
 baseSymbol
 

Static Public Attributes

int MAX_SYMBOL_LENGTH = 16
 

Detailed Description

The UnitOfMeasure class represents a unit of measure.

A UnitOfMeasure can have a linear conversion (y = ax + b) to another unit of measure in the same internationally recognized measurement system of International Customary, SI, US or British Imperial. Or, the unit of measure can have a conversion to another custom unit of measure. It is owned by the unified MeasurementSystem defined by this project.

A unit of measure is categorized by scalar (simple unit), quotient (divisor and dividend units), product (multiplier and multiplicand units) or power (unit with an integral exponent). More than one representation of a unit of measure is possible. For example, a unit of "per second" could be a quotient of "1/s" (e.g. an inverted second) or a power of s^-1.

A unit of measure also has an enumerated UnitType (for example LENGTH or MASS) and a unique Unit discriminator (for example METRE).
A basic unit (a.k.a fundamental unit in the SI system) can have a bridge conversion to another basic unit in another recognized measurement system. This conversion is defined unidirectionally. For example, an International Customary foot is 0.3048 SI metres. The conversion from metre to foot is just the inverse of this relationship.

A unit of measure has a base symbol, for example 'm' for metre. A base symbol is one that consists only of the symbols for the base units of measure. In the SI system, the base units are well-defined. The derived units such as Newton all have base symbols expressed in the fundamental units of length (metre), mass (kilogram), time (second), temperature (Kelvin), plane angle (radian), electric charge (Coulomb) and luminous intensity (candela). In the US and British systems, base units are not defined. Caliper uses foot for length, pound mass for mass and Rankine for temperature. This base symbol is used in unit of measure conversions to uniquely identify the target unit.

The SI system has defined prefixes (e.g. "centi") for 1/100th of another unit (e.g. metre). Instead of defining all the possible unit of measure combinations, the MeasurementSystem is able to create units by specifying the Prefix and target unit of measure. Similarly, computer science has defined prefixes for bytes (e.g. "mega").

Member Function Documentation

◆ classify()

def uom.unit_of_measure.UnitOfMeasure.classify (   self)

If the unit of measure is unclassified, from its base unit map find a matching unit type.

Returns
UnitOfMeasure

◆ divide()

def uom.unit_of_measure.UnitOfMeasure.divide (   self,
  divisor 
)

Divide two units of measure to create a third one.

Parameters
divisorUnitOfMeasure
Returns
UnitOfMeasure

◆ getBaseSymbol()

def uom.unit_of_measure.UnitOfMeasure.getBaseSymbol (   self)

Get the unit of measure symbol in the fundamental units for that system.

For example a Newton is a kg.m/s2.

Returns
Base symbol

◆ getBaseUnitsOfMeasure()

def uom.unit_of_measure.UnitOfMeasure.getBaseUnitsOfMeasure (   self)

Get the most reduced units of measure.

Returns
Map of UnitOfMeasure and exponent

◆ getConversionFactor()

def uom.unit_of_measure.UnitOfMeasure.getConversionFactor (   self,
  targetUOM 
)

Get the factor to convert to the unit of measure.

Parameters
targetUOMTarget UnitOfMeasure
Returns
conversion factor

◆ getDividend()

def uom.unit_of_measure.UnitOfMeasure.getDividend (   self)

Get the dividend unit of measure.

Returns
UnitOfMeasure

◆ getDivisor()

def uom.unit_of_measure.UnitOfMeasure.getDivisor (   self)

Get the divisor unit of measure.

Returns
UnitOfMeasure

◆ getMeasurementType()

def uom.unit_of_measure.UnitOfMeasure.getMeasurementType (   self)

Get the measurement type.

Returns
MeasurementType

◆ getMultiplicand()

def uom.unit_of_measure.UnitOfMeasure.getMultiplicand (   self)

Get the multiplicand.

Returns
UnitOfMeasure

◆ getMultiplier()

def uom.unit_of_measure.UnitOfMeasure.getMultiplier (   self)

Get the multiplier.

Returns
UnitOfMeasure

◆ getPowerBase()

def uom.unit_of_measure.UnitOfMeasure.getPowerBase (   self)

Get the base unit of measure for the power.

Returns
UnitOfMeasure

◆ getPowerExponent()

def uom.unit_of_measure.UnitOfMeasure.getPowerExponent (   self)

Get the exponent of a power unit.

Returns
Exponent

◆ invert()

def uom.unit_of_measure.UnitOfMeasure.invert (   self)

Invert a unit of measure to create a new one.

Returns
UnitOfMeasure

◆ isTerminal()

def uom.unit_of_measure.UnitOfMeasure.isTerminal (   self)

Check to see if this unit of measure has a conversion to another unit of measure other than itself.

Returns
True if it does not

◆ isValidExponent()

def uom.unit_of_measure.UnitOfMeasure.isValidExponent (   exponent)
static

Check to see if the exponent is valid.

Parameters
exponentPower exponent
Returns
True if it is a valid exponent

◆ multiply()

def uom.unit_of_measure.UnitOfMeasure.multiply (   self,
  multiplicand 
)

Multiply two units of measure to create a third one.

Parameters
multiplicandUnitOfMeasure
Returns
UnitOfMeasure

◆ setConversion()

def uom.unit_of_measure.UnitOfMeasure.setConversion (   self,
  scalingFactor,
  abscissaUnit,
  offset = 0.0 
)

Define a conversion with the specified scaling factor, abscissa unit of measure and scaling factor.

Parameters
scalingFactorFactor
abscissaUnitUnitOfMeasure
offsetOffset

◆ setPowerUnit()

def uom.unit_of_measure.UnitOfMeasure.setPowerUnit (   self,
  base,
  exponent 
)

Set the base unit of measure and exponent.

Parameters
baseBase unit of measure
exponentExponent

◆ setProductUnits()

def uom.unit_of_measure.UnitOfMeasure.setProductUnits (   self,
  multiplier,
  multiplicand 
)

Set the multiplier and multiplicand.

Parameters
multiplierMultiplier
multiplicandMultiplicand

◆ setQuotientUnits()

def uom.unit_of_measure.UnitOfMeasure.setQuotientUnits (   self,
  dividend,
  divisor 
)

Set the dividend and divisor.

Parameters
dividendDividend
divisorDivisor

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