Module: valunits

Module for associating units with scalar quantities

This module has been modified from its original form by removing the call to the “units” executable and restricting the units to only those used by the heXRD package.

2 Classes

class hexrd.valunits.UNames[source]

Bases: object

Units used in this module

class hexrd.valunits.valWUnit(name, unitType, value, unit)[source]

Value with units

__init__(name, unitType, value, unit)[source]

Initialization

INPUTS name

(str) name of the item
unitType
(str) class of units, e.g. ‘length’, ‘angle’
value
(float) numerical value
unit
(str) name of unit
getVal(toUnit)[source]

Return value in requested units

INPUTS

toUnit
(str) requested unit for output
isAngle()[source]

Return true if quantity is an angle

isEnergy()[source]

Return true if quantity is an energy

isLength()[source]

Return true if quantity is a length

2 Functions

hexrd.valunits.toFloat(val, unitName)[source]

Return the raw value of the object

INPUTS

val
(float|valWUnit) object with value
unitName
(str) name of unit

This function returns the raw value of the object, ignoring the unit, if it is numeric or converts it to the requested units and returns the magnitude if it is a valWUnit instance.

For example:

>>> print toFloat(1.1, 'radians')
1.1
>>> v = valWUnit('vee', 'angle', 1.1, 'radians')
>>> print toFloat(v, 'degrees')
63.0253574644
hexrd.valunits.valWithDflt(val, dflt, toUnit=None)[source]

Return value or default value