scuq.quantities¶
- class scuq.quantities.Quantity(unit, value)[source]¶
Bases:
objectBase class that provides an interface to model quantities. arithmetic.RationalNumber) are automatically transformed to an dimensionless quantity if the operations are performed on them. This also applies if a quantity is the right operand of the numeric types stated above.
- __init__(unit, value)[source]¶
Default constructor.
- Parameters:
unit – The corresponding unit.
value – The value assigned
instances of ucomponents.UncertainInput as values.
- reduce_to(unit)[source]¶
Return this quantity expressed in
unit.If the target unit has the same physical dimension as this quantity’s current unit, the numeric value is converted with the corresponding unit operator and a new
Quantityin the target unit is returned. If the target unit is dimensionally incompatible, this quantity is returned unchanged.This is an explicit unit conversion and is therefore performed consistently regardless of the global strict-mode setting. Strict mode only affects implicit compatibility checks, such as addition, subtraction, comparisons, and
get_value().
- get_value(unit)[source]¶
Get the absolute value of the quantity using the specified unit.
- Parameters:
unit – The unit in which the quantity should be expressed in.
- Returns:
The absolute value of the quantity. comparable.
- get_default_unit()[source]¶
Get the unit that is used commonly for this quantity.
- Returns:
The corresponding unit.
- is_dimensionless()[source]¶
Check if this quantity copatible to dimensionless.
- Returns:
True, if the unit assigned is comparable to units.ONE.
- is_dimensionless_strict()[source]¶
Check if this quantity is dimensionless (strict).
- Returns:
True, if the unit assigned IS units.ONE.
- __add__(other)[source]¶
Get the sum of another instance of Quantity and this instance.
- Parameters:
other – Another instance of Quantity or numeric value.
- Returns:
A new instance of Quantity representing the sum of both quantities. comparable.
- __sub__(other)[source]¶
Get the difference of another instance of Quantity and this instance.
- Parameters:
other – Another instance of Quantity.
- Returns:
A new instance of Quantity representing the difference of both quantities. comparable.
- __mul__(other)[source]¶
Get the product of another instance of Quantity and this instance. Even if the units are defined in the same dimension. For example, if one takes m times ft the result will be ft m not m^2 nor ft^2.
- Parameters:
other – Another instance of Quantity or numeric value.
- Returns:
A new instance of Quantity representing the product of both quantities.
- __pow__(other)[source]¶
Get the power of of this instance.
- Parameters:
other – The power to which this instance is raised (must be
an integer or dimensionless quantity).
- Returns:
A new instance of Quantity representing the power of this instance. is not dimensionless.
- __truediv__(other)[source]¶
Get the fraction of another instance of Quantity and this instance. Even if the units are defined in the same dimension. For example, if one takes m div ft the result will be
- Parameters:
other – Another instance of Quantity or numeric value used as
divisor.
- Returns:
A new instance of Quantity representing the sum of both quantities.
- __radd__(other)[source]¶
Get the sum of this instance of Quantity and another value.
- Parameters:
other – Another value (not an instance of Quantity).
- Returns:
A new instance of Quantity representing the sum. comparable.
- __rsub__(other)[source]¶
Get the difference of another value and this instance of Quantity.
- Parameters:
other – Another value (not an instance of Quantity).
- Returns:
A new instance of Quantity representing the difference of both quantities. comparable.
- __rmul__(other)[source]¶
Get the product of this instance of Quantity and another value.
- Parameters:
other – Another value (not an instance of Quantity).
- Returns:
A new instance of Quantity representing the product of both quantities.
- __rtruediv__(other)[source]¶
Get the fraction of another value and this instance.
- Parameters:
other – Another instance of Quantity or numeric value used as
dividend.
- Returns:
A new instance of Quantity representing the sum of both quantities.
- __rpow__(other)[source]¶
Get the power of another value and this instance. instance also accepts floating point powers.
- Parameters:
other – Another instance of Quantity.
- Returns:
A new instance of Quantity representing the sum of both quantities. comparable to units.ONE.
- __iadd__(other)[source]¶
Add the argument to this instance.
- Parameters:
other – Another instance of Quantity or numeric value.
comparable.
- __isub__(other)[source]¶
Substract the argument from this instance.
- Parameters:
other – Another instance of Quantity or numeric value.
comparable.
- __imul__(other)[source]¶
Multiply this instance with the argument.
- Parameters:
other – Another instance of Quantity or numeric value.
- __idiv__(other)[source]¶
Divide this instance by the argument.
- Parameters:
other – Another instance of Quantity or numeric value..
- __ipow__(other)[source]¶
Raise the this instance to the argument.
- Parameters:
other – Another instance of Quantity or numeric value.
- __neg__()[source]¶
Negate the value of this quantity.
- Returns:
A new instance of Quantity representing the negative of this quantity.
- __abs__()[source]¶
Get the absolute value of this Quantity.
- Returns:
The absolute value of this quantity.
- __invert__()[source]¶
Return the inverted instance of this Quantity. For example, let your quantity be frac{1}{2} frac{m}{s} , then the result of this operation is 2 frac{s}{m} .
- Returns:
The inverted quantity.
- __complex__()[source]¶
Cast this instance to the numeric type complex. stripped from the result.
- Returns:
The value of this instance casted to complex.
- __long__()[source]¶
Cast this instance to the numeric type long. stripped from the result.
- Returns:
The value of this instance casted to long.
- __float__()[source]¶
Cast this instance to the numeric type float. stripped from the result. checking is enabled.
- Returns:
The value of this instance casted to float.
- __int__()[source]¶
Cast this instance to the numeric type int. stripped from the result.
- Returns:
The value of this instance casted to int.
- __str__()[source]¶
Get a string describing this Quantity. The result will be of the form
value unit(i.e. “12.0 m”).- Returns:
A string describing this quantity.
- __repr__()[source]¶
Get a string describing this Quantity. The result will be of the form
Quantity(unit, value)(i.e. “Quantity(si.METER, 12.0)”).- Returns:
A string describing this quantity.
- __lt__(other)[source]¶
Check, if this instance is less than the argument. A comparsion will be done, if the units are comparable.
- Parameters:
other – Another instance of Quantity.
- Returns:
True, if this instance is less than the argument. comparable.
- __le__(other)[source]¶
Check, if this instance is less or equal to the argument. A comparsion will be done, if the units are comparable.
- Parameters:
other – Another instance of Quantity.
- Returns:
True, if this instance is less or equal to the argument. comparable.
- __eq__(other)[source]¶
Check, if this instance is equal to the argument. A comparsion will be done, if the units are comparable.
- Parameters:
other – Another instance of Quantity.
- Returns:
True, if this instance is equal to the argument.
- __ne__(other)[source]¶
Check, if this instance is not equal to the argument. A comparsion will be done, if the units are comparable.
- Parameters:
other – Another instance of Quantity.
- Returns:
True, if this instance is not equal to the argument.
- __gt__(other)[source]¶
Check, if this instance is greater than the argument. A comparsion will be done, if the units are comparable.
- Parameters:
other – Another instance of Quantity.
- Returns:
True, if this instance is greater than the argument. comparable.
- __ge__(other)[source]¶
Check, if this instance is greater or equal to the argument. A comparsion will be done, if the units are comparable.
- Parameters:
other – Another instance of Quantity.
- Returns:
True, if this instance is greater or equal to the argument. comparable.
- __cmp__(other)[source]¶
Compare two instances of quantity.
- Parameters:
other – Another instance of Quantity or numeric value.
- Returns:
-1, if the this instance is less than the argument, 0, if this instance is equal to the argument, +1, if this instance is greater than the argument. comparable.
- __getstate__()[source]¶
Serialization using pickle.
- Returns:
A string that represents the serialized form of this instance.
- __setstate__(state)[source]¶
Deserialization using pickle.
- Parameters:
state – The state of the object.
- static value_of(other)[source]¶
Factory for generating quantities.
- Parameters:
other – A quantity, or another value.
- Returns:
A Quantity. If the argument is a quantity this method returns it. If the argument is a numeric value, this method generates a dimensionless quantity having the argument as value. instances of ucomponents.UncertainInput as values.
- arccos()[source]¶
This method provides the broadcast interface for numpy.arccos.
- Returns:
The inverse Cosine of this quantity. If the unit assigned is not dimensionless.
- arccosh()[source]¶
This method provides the broadcast interface for numpy.arccosh.
- Returns:
The inverse hyperbolic Cosine of this quantity. If the unit assigned is not dimensionless.
- arcsin()[source]¶
This method provides the broadcast interface for numpy.arcsin.
- Returns:
The inverse Sine of this quantity. If the unit assigned is not dimensionless.
- arcsinh()[source]¶
This method provides the broadcast interface for numpy.arcsinh.
- Returns:
The inverse hyperbolic Sine of this quantity. If the unit assigned is not dimensionless.
- arctan()[source]¶
This method provides the broadcast interface for numpy.arctan.
- Returns:
The inverse Tangent of this quantity. If the unit assigned is not dimensionless.
- arctanh()[source]¶
This method provides the broadcast interface for numpy.arctanh.
- Returns:
The inverse hyperbolic Tangent of this quantity. If the unit assigned is not dimensionless.
- cos()[source]¶
This method provides the broadcast interface for numpy.cos.
- Returns:
The Cosine of this quantity. If the unit assigned is not dimensionless.
- cosh()[source]¶
This method provides the broadcast interface for numpy.cosh.
- Returns:
The hyperbolic Cosine of this quantity. If the unit assigned is not dimensionless.
- tan()[source]¶
This method provides the broadcast interface for numpy.tan.
- Returns:
The Tangent of this quantity. If the unit assigned is not dimensionless.
- tanh()[source]¶
This method provides the broadcast interface for numpy.tanh.
- Returns:
The hyperbolic Tangent of this quantity. If the unit assigned is not dimensionless.
- log10()[source]¶
This method provides the broadcast interface for numpy.log10.
- Returns:
The decadic Logarithm of this quantity. If the unit assigned is not dimensionless.
- log2()[source]¶
This method provides the broadcast interface for numpy.log2.
- Returns:
The binary logarithm of this quantity. If the unit assigned is not dimensionless.
- sin()[source]¶
This method provides the broadcast interface for numpy.sin.
- Returns:
The Sine of this quantity. If the unit assigned is not dimensionless.
- sinh()[source]¶
This method provides the broadcast interface for numpy.sinh.
- Returns:
The hyperbolic Sine of this quantity. If the unit assigned is not dimensionless.
- sqrt()[source]¶
This method provides the broadcast interface for numpy.sqrt.
- Returns:
The Square Root of this quantity.
- square()[source]¶
This method provides the broadcast interface for numpy.sqrt.
- Returns:
The Square Root of this quantity.
- fabs()[source]¶
This method provides the broadcast interface for numpy.fabs.
- Returns:
The absolute value of this quantity.
- absolute()[source]¶
This method provides the broadcast interface for numpy.absolute.
- Returns:
The absolute value of this quantity.
- __floor__()[source]¶
This method provides the broadcast interface for numpy.floor.
- Returns:
The largest integer less than or equal to this quantity.
- __ceil__()[source]¶
This method provides the broadcast interface for numpy.ceil.
- Returns:
The largest integer greater than or equal to this quantity.
- exp()[source]¶
This method provides the broadcast interface for numpy.exp.
- Returns:
The Exponential of this quantity. If the unit assigned is not dimensionless.
- log()[source]¶
This method provides the broadcast interface for numpy.log.
- Returns:
The Natural Logarithm of this quantity. If the unit assigned is not dimensionless.
- arctan2(other)[source]¶
This method provides the broadcast interface for numpy.arctan2.
- Parameters:
other – Another instance of Quantity.
- Returns:
The inverse two-argument tangent of the arguments. If the unit assigned is not dimensionless.
- hypot(other)[source]¶
This method provides the broadcast interface for hypothenusis.
- Parameters:
other – Another instance of Quantity.
- Returns:
The hypothenusis of the arguments.
- conjugate()[source]¶
This method provides the broadcast interface for numpy.conjugate.
- Returns:
This quantity.
- static set_strict(bValue=True)[source]¶
Turn on/off the strict evaluation of quantities. This will affect any quantities calculation beyond this point.
- Parameters:
bValue – True or False