PySharp Units of Measure
Units of Measure in Python
Loading...
Searching...
No Matches
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

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

Static Public Member Functions

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

Public Attributes

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

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()

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()

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

Divide two units of measure to create a third one.

Parameters
divisorUnitOfMeasure
Returns
UnitOfMeasure

◆ getBaseSymbol()

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()

uom.unit_of_measure.UnitOfMeasure.getBaseUnitsOfMeasure ( self)

Get the most reduced units of measure.

Returns
Map of UnitOfMeasure and exponent

◆ getConversionFactor()

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()

uom.unit_of_measure.UnitOfMeasure.getDividend ( self)

Get the dividend unit of measure.

Returns
UnitOfMeasure

◆ getDivisor()

uom.unit_of_measure.UnitOfMeasure.getDivisor ( self)

Get the divisor unit of measure.

Returns
UnitOfMeasure

◆ getMeasurementType()

uom.unit_of_measure.UnitOfMeasure.getMeasurementType ( self)

Get the measurement type.

Returns
MeasurementType

◆ getMultiplicand()

uom.unit_of_measure.UnitOfMeasure.getMultiplicand ( self)

Get the multiplicand.

Returns
UnitOfMeasure

◆ getMultiplier()

uom.unit_of_measure.UnitOfMeasure.getMultiplier ( self)

Get the multiplier.

Returns
UnitOfMeasure

◆ getPowerBase()

uom.unit_of_measure.UnitOfMeasure.getPowerBase ( self)

Get the base unit of measure for the power.

Returns
UnitOfMeasure

◆ getPowerExponent()

uom.unit_of_measure.UnitOfMeasure.getPowerExponent ( self)

Get the exponent of a power unit.

Returns
Exponent

◆ invert()

uom.unit_of_measure.UnitOfMeasure.invert ( self)

Invert a unit of measure to create a new one.

Returns
UnitOfMeasure

◆ isTerminal()

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()

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()

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

Multiply two units of measure to create a third one.

Parameters
multiplicandUnitOfMeasure
Returns
UnitOfMeasure

◆ setConversion()

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()

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

Set the base unit of measure and exponent.

Parameters
baseBase unit of measure
exponentExponent

◆ setProductUnits()

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

Set the multiplier and multiplicand.

Parameters
multiplierMultiplier
multiplicandMultiplicand

◆ setQuotientUnits()

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: