mcsas.utils.units module

Defines methods for using and manipulating units of variables. Some default magnitude-name dictionaries are provided, but the user can supply their own dictionary if required. Default unit to translate to must be set. Required keyword arguments:

  • magnitudedict: a dictionary of magnitude - name pairs. Names must be
    unicode strings.
  • simagnitudename: the si magnitude name.

Example usage:

>>> rUnit = Length("nm")
>>> rUnit.siMagnitudeName
u'm'
>>> rUnit.displayMagnitudeName
u'nm'
>>> rUnit.magnitudeConversion
1e-09

or:

>>> rUnit.toSi(32)
3.2e-08

Selecting a default:

>>> qUnit = ScatteringVector(u"cm⁻¹")
>>> qUnit.magnitudeConversion
100.0
class Angle(magnitudeName=None)[source]

Bases: utils.units.Unit

Set up a unit of measurement. The provided magnitude name is used by default in the UI. Using SI units if unspecified.

class Area(magnitudeName=None)[source]

Bases: utils.units.Unit

Set up a unit of measurement. The provided magnitude name is used by default in the UI. Using SI units if unspecified.

class DynamicViscosity(magnitudeName=None)[source]

Bases: utils.units.Unit

Set up a unit of measurement. The provided magnitude name is used by default in the UI. Using SI units if unspecified.

class Fraction(magnitudeName=None)[source]

Bases: utils.units.Unit

Set up a unit of measurement. The provided magnitude name is used by default in the UI. Using SI units if unspecified.

class Length(magnitudeName=None)[source]

Bases: utils.units.Unit

Set up a unit of measurement. The provided magnitude name is used by default in the UI. Using SI units if unspecified.

class NoUnit(magnitudeName=None)[source]

Bases: utils.units.Unit

Set up a unit of measurement. The provided magnitude name is used by default in the UI. Using SI units if unspecified.

class SLD(magnitudeName=None)[source]

Bases: utils.units.Unit

Set up a unit of measurement. The provided magnitude name is used by default in the UI. Using SI units if unspecified.

class ScatteringIntensity(magnitudeName=None)[source]

Bases: utils.units.Unit

Set up a unit of measurement. The provided magnitude name is used by default in the UI. Using SI units if unspecified.

class ScatteringVector(magnitudeName=None)[source]

Bases: utils.units.Unit

Set up a unit of measurement. The provided magnitude name is used by default in the UI. Using SI units if unspecified.

class Temperature(magnitudeName=None)[source]

Bases: utils.units.Unit

test case for special conversions. Done by redefining toSI and toDisplay. Implemented units are given in _magnitudeMap.

Set up a unit of measurement. The provided magnitude name is used by default in the UI. Using SI units if unspecified.

magnitudeConversion

Scaling factor to move from display magnitude to si units. Required display argument:

displaymagnitudename : The name of the magnitude to convert from

Optional display argument:

simagnitudename : The name of the magnitude to convert to.
Defaults to self.siMagnitudeName
Returns:
float : A scaling factor for display unit to scale to si unit.
toDisplay(value)[source]

Warning

method ‘utils.units.Temperature.toDisplay’ undocumented

toSi(value)[source]

Warning

method ‘utils.units.Temperature.toSi’ undocumented

class Time(magnitudeName=None)[source]

Bases: utils.units.Unit

Set up a unit of measurement. The provided magnitude name is used by default in the UI. Using SI units if unspecified.

class Unit(magnitudeName=None)[source]

Bases: object

Set up a unit of measurement. The provided magnitude name is used by default in the UI. Using SI units if unspecified.

availableMagnitudeNames
displayMagnitude
displayMagnitudeName
hdfLoad(hdf)[source]

should go something like this, here, hold my beer.

hdfWrite(hdf)[source]

Warning

method ‘utils.units.Unit.hdfWrite’ undocumented

static invName(unitString)[source]

Adds an ⁻¹ sign or removes it if already present

classmethod magnitude(name)[source]

Returns a (numerical) magnitude matching a magnitude name

magnitudeConversion

Scaling factor to move from display magnitude to si units. Required display argument:

displaymagnitudename : The name of the magnitude to convert from

Optional display argument:

simagnitudename : The name of the magnitude to convert to.
Defaults to self.siMagnitudeName
Returns:
float : A scaling factor for display unit to scale to si unit.
magnitudeMapping = {}
classmethod name()[source]

Warning

method ‘utils.units.Unit.name’ undocumented

siMagnitude = ''
siMagnitudeName = ''
toDisplay(value)[source]

Warning

method ‘utils.units.Unit.toDisplay’ undocumented

toSi(value)[source]

Warning

method ‘utils.units.Unit.toSi’ undocumented

class Volume(magnitudeName=None)[source]

Bases: utils.units.Unit

Set up a unit of measurement. The provided magnitude name is used by default in the UI. Using SI units if unspecified.