Package esys :: Package escript :: Module unitsSI :: Class Unit
[hide private]
[frames] | no frames]

Class Unit

object --+
         |
        Unit
Known Subclasses:

a general class to define a physical unit and convert from this unit to an appropriate SI unit.

Unit object have a dual purpose: Firstly physical units can be combined through *,/ and ** to form new physical units or to add prefixes such as Milli to m to form mm=Milli*m. Moreover, a given floating point number x (or any other arithmetic object) can be converted from the physical unit to the SI system, eg. 10*mm to create the value for 10mm which is the float number 0.01 in the SI system. In addition, a value in the SI unit can be converted back to the given unit, eg. to express 0.01m in physical units of mm use 0.01/mm which will return 10.

Instance Methods [hide private]
 
__call__(self, x)
Converts a value x in the physical unit self to SI
Unit or NotImplemented
__div__(self, other)
Performs self*other operation for two Unit objects
 
__init__(self, name, longname, a, b)
initializes the physical unit
Unit or NotImplemented
__mul__(self, other)
Performs self*other operation for two Unit objects
Unit
__pow__(self, other)
Performs self**other operation
Unit or an arithmetic object
__rdiv__(self, other)
Performs other/self operation
Unit of or an arithmetic object
__rmul__(self, other)
Performs other*self operation
 
__str__(self)
str(x)
str
getLongName(self)
Returns the long name of the physical unit
str
getName(self)
Returns the name of the physical unit
 
setLongName(self, name)
Sets the long name of the physical unit
 
setName(self, name)
Sets the name of the physical unit

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__call__(self, x)
(Call operator)

 

Converts a value x in the physical unit self to SI

Parameters:
  • x (an arithmetic object) - value to convert

__div__(self, other)

 

Performs self*other operation for two Unit objects

Parameters:
  • other (Unit) - an other physical unit
Returns: Unit or NotImplemented

__init__(self, name, longname, a, b)
(Constructor)

 

initializes the physical unit

Parameters:
  • name (str) - short name of the physical unit or prefix
  • longname (str) - long name of the physical unit or prefix
  • a (float) - absolute value in transformation
  • b (float) - slop in translation
Overrides: object.__init__

__mul__(self, other)

 

Performs self*other operation for two Unit objects

Parameters:
  • other (Unit) - an other physical unit
Returns: Unit or NotImplemented

__pow__(self, other)

 

Performs self**other operation

Parameters:
  • other (int or float) - an exponent
Returns: Unit

__rdiv__(self, other)

 

Performs other/self operation

Parameters:
  • other (Unit or an arithmetic object) - an other Unit or an arithmetic object
Returns: Unit or an arithmetic object

__rmul__(self, other)

 

Performs other*self operation

Parameters:
  • other (Unit or) - an other Unit or an arithmetic object. if other is a arithmetic object such as float other is assumed to be given in the physical unit self and is converted into the corresponding SI unit.
Returns: Unit of or an arithmetic object

__str__(self)
(Informal representation operator)

 

str(x)

Overrides: object.__str__
(inherited documentation)

getLongName(self)

 

Returns the long name of the physical unit

Returns: str
name of the physical unit

getName(self)

 

Returns the name of the physical unit

Returns: str
name of the physical unit

setLongName(self, name)

 

Sets the long name of the physical unit

Parameters:
  • name (str) - new long name of the physical unit

setName(self, name)

 

Sets the name of the physical unit

Parameters:
  • name (str) - new name of the physical unit