hexrd.valunits module

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.

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.02535746439056
class hexrd.valunits.valWUnit(name, unitType, value, unit)[source]

Bases: object

Value with units

getVal(toUnit)[source]

Returns object value in requested units.

Parameters

toUnitstr

The identifier for desired unit type. Current choices are .

Raises

RuntimeError

Where the requested units are invalid

Returns

scalar

The value of the object in the requested units.

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

hexrd.valunits.valWithDflt(val, dflt, toUnit=None)[source]

Return value or default value