mahautils.multics.MahaMulticsUnit#
- class mahautils.multics.MahaMulticsUnit(base_unit_exps: List[float] | Tuple[float, ...] | ndarray, scale: float, offset: float, identifier: str | None = None, name: str | None = None)#
Bases:
UnitLinearClass for representing units with linear transformations to/from the base units, customized to the Maha Multics software
Defines a unit in which the transformations to/from the base units of the system of units (that is, the functions given by
from_base_functionandto_base_function) are linear. A large portion of the units encountered in everyday use can be considered linear units, so this class was created to simplify defining such units.Notes
To convert an array of arbitrary dimensions
inputsfrom the given object’s unit to the base units, the following equation is applied:outputs = (scale * inputs) + offset
Methods
__init__(base_unit_exps, scale, offset[, ...])Creates an instance of the
MahaMulticsUnitclassInherited Attributes
Defines the mathematical conventions for multiplying or dividing a
Unitobject by a constantA list of exponents relating the given object's units to the base units of
unit_systemA function that transforms a value in the base units of the system of units
unit_systemto the given object's unitsA user-defined string that represents the unit (examples: kg, m, rad)
A user-defined string that describes the unit (examples: kilogram, meter, radian)
The constant value added when converting from the given object's unit to the base units
The multiplicative factor applied when converting from the given object's unit to the base units
A function that transforms a value from the given object's units to the base units of
unit_systemThe system of units to which the unit belongs
Inherited Methods
convert(value, convert_type, unit)Converts a quantity from one unit to another
from_base(value[, exponent])Converts a value or array from base units of the unit system to the given unit
is_convertible(unit)Checks whether a unit can be converted to another unit
to_base(value[, exponent])Converts a value or array from the given unit to the base units of the unit system
- __init__(base_unit_exps: List[float] | Tuple[float, ...] | ndarray, scale: float, offset: float, identifier: str | None = None, name: str | None = None) None#
Creates an instance of the
MahaMulticsUnitclassDefines an object representing a base or derived unit in which the functions converting a value to/from the base units of the system of units
unit_systemare linear functions and the system of units is specific to the Maha Multics software.- Parameters:
base_unit_exps (list or tuple or np.ndarray) – A 1D list of exponents relating the given object’s unit to the base units of
unit systemscale (float) – The multiplicative factor applied when converting from the given object’s unit to the base units
offset (float) – The constant value added when converting from the given object’s unit to the base units
identifier (str, optional) – A short identifier describing the unit (example:
'kg') (default isNone)name (str, optional) – A name describing the unit (example:
'kilogram') (default isNone)
- CONSTANT_MATH_CONVENTION = 1#
Defines the mathematical conventions for multiplying or dividing a
Unitobject by a constantConfigures whether
Unitobjects can be generated by multiplying or dividing anotherUnitobject by a constant, and if so what mathematical conventions are adopted. For more detail, refer to theConstantUnitMathConventionsdocumentation.The default is
ConstantUnitMathConventions.DISABLE, which prohibits multiplying or dividingUnitobjects by constants.Warning
This is a class attribute, so changing its value for one class (such as
UnitLinear) will change it for ALL classes that are an instance of or inherit fromUnit.Notes
To select a math convention for multiplying
Unitobjects by constants, include code similar to:>>> from pyxx.units import Unit, ConstantUnitMathConventions >>> Unit.CONSTANT_MATH_CONVENTION = ConstantUnitMathConventions.DISABLE
In general, it is best to set this option at the beginning of your code, as it can get confusing if you set it later in your code and as a result different parts of your code follow different conventions.
- property base_unit_exps: ndarray#
A list of exponents relating the given object’s units to the base units of
unit_system
- convert(value: ndarray | list | tuple | float, convert_type: str, unit: Unit) ndarray#
Converts a quantity from one unit to another
This method performs a unit conversion, converting one or more values from this object’s units to another unit. This conversion can be performed in “either direction” – either from this object’s units to another unit, or from another unit to this object’s units.
- Parameters:
value (np.ndarray or list or tuple or float) – Quantities to convert to a different unit
convert_type (str) – Must be either
'to'or'from'. Describes whether to convertvaluefrom this object’s units to the units specified byunit, or vice versaunit (Unit) – The unit to convert
valueto or from
- Returns:
NumPy array of the same shape as
valuecontaining the quantities after performing the specified unit conversion- Return type:
np.ndarray
- from_base(value: ndarray | list | tuple | float, exponent: float = 1.0) ndarray#
Converts a value or array from base units of the unit system to the given unit
- Parameters:
value (np.ndarray or list or tuple or float) – Value(s) to convert to base units
exponent (float, optional) – Exponent to which the unit is raised (default is 1.0)
- Returns:
NumPy array with the same shape as
valuecontaining the value(s) invalueexpressed in base units- Return type:
np.ndarray
Notes
Use the
exponentargument to handle units which are raised to a power. For instance, to convert square kilometers to base units (square meters), setexponentto 2.
- property from_base_function#
A function that transforms a value in the base units of the system of units
unit_systemto the given object’s units
- property identifier: str | None#
A user-defined string that represents the unit (examples: kg, m, rad)
- is_convertible(unit: Unit) bool#
Checks whether a unit can be converted to another unit
Checks two units can be converted between each other (i.e., whether they belong to the same system of units and have the same
base_unit_expsrelating them to the base units).- Parameters:
unit (Unit) – Another
Unitinstance- Returns:
Returns
Trueif this unit instance andunitbelong to the same system of units and have the samebase_unit_expsattribute, andFalseotherwise- Return type:
bool
- property name: str | None#
A user-defined string that describes the unit (examples: kilogram, meter, radian)
- property offset: float#
The constant value added when converting from the given object’s unit to the base units
- property scale: float#
The multiplicative factor applied when converting from the given object’s unit to the base units
- to_base(value: ndarray | list | tuple | float, exponent: float = 1.0) ndarray#
Converts a value or array from the given unit to the base units of the unit system
- Parameters:
value (np.ndarray or list or tuple or float) – Value(s) to convert from base units to the given unit
exponent (float, optional) – Exponent to which the unit is raised (default is 1.0)
- Returns:
NumPy array with the same shape as
valuecontaining the value(s) invalueconverted from base units to the given unit- Return type:
np.ndarray
Notes
Use the
exponentargument to handle units which are raised to a power. For instance, to convert to cubic kilometers from cubic meters (the base unit), setexponentto 3.
- property to_base_function#
A function that transforms a value from the given object’s units to the base units of
unit_system
- property unit_system: UnitSystem#
The system of units to which the unit belongs