unitty.quantity module¶
Created on Fri May 1 11:52:26 2020
@author: Reuben
The Quantity class combines a magnitude with dimensional information that gives that magnitude meaning. Quantity objects wrap a value with information about the dimensions. The value can be a scalar or array.
Quantities are always expressed in terms of other quantities, with the exception of base dimensions like length, time, mass, etc. unitty imposes no restrictions on what these base dimensions are. They may also include derived base dimensions, such as force or pressure. Quantities defined by derived base dimensions will understand the underlying dimensionality that defines them, but also their preferred expression of force, pressure, etc.
-
class
unitty.quantity.Quantity(value, spec, vector, abbr=None, name=None, parent=None)¶ Bases:
objectThe core object that combines magnitude and dimensional information.
Parameters: - value (int, float, arraylike) – A float representing the magnitude of the quantity in terms of base dimensions (length, time, mass, etc) spec: A list of signed integers. For simple units, there will be only one integer. For compound units (e.g. m/s), there will be more than one. The integers correspond to other Quantities. Positive integers indicate the are multiplied, while negative integers indicate they are divided.
- vector (ndarray) – Each base dimensions is independent, and the exponent for each base dimension is represented as a number. This vectore is an array of such numbers for all base dimensions. This allows quick and robust dimensionality checking.
- abbr (str) – [optional] The abbreviation of the Quantity (usually for Units)
- name (str) – [optional] The name of the Quantity (usually for Units)
- parent (str) – [optional] The name of the Units instance it belongs to. This is important, since otherwise the spec doesn’t make any sense.
Note
Normally, Quantities would only be created automatically or from other Quantities, not directly by the user.
-
by_ref()¶ Express the Quantity in units specified by a reference name
Returns: A value and unit string tuple. Return type: Quantity_Tuple Note
The value and unit string returned will depend on which unit system is active. Named references must specify units for the active system (See
system.Systems.set_refs()).
-
in_base(dimensional=False)¶ Express the Quantity in base units.
Returns: A value and unit string tuple. Return type: Quantity_Tuple Note
The value and unit string returned will not depend on which unit system is active.
-
in_dimensions()¶
-
in_sys()¶ Express the Quantity in units specified by the active system.
Returns: A value and unit string tuple. Return type: Quantity_Tuple Note
The value and unit string returned will depend on which unit system is active. See the
systemmodule.
-
in_units(unit=None)¶ Express the Quantity in particular units
Parameters: unit (Unit) – [Optional] The units to express this Quantity in. If omitted, the Quantity will be expressed in the units in which it was defined. Returns: A value and unit string tuple. Return type: Quantity_Tuple
-
set_ref(ref)¶ Set the reference name for this quantity
Parameters: ref (str) – The reference name
-
set_units(unit)¶ Set the units for this quantity
Parameters: unit (Quantity) – A Quantity or Unit instance.
-
str_in_base(dimensional=False)¶ Format the result from
in_base()into stringReturns: A string showing the value and units of the Quantity. Return type: str
-
str_in_dimensions()¶
-
str_in_sys()¶ Format the result from
in_sys()into stringReturns: A string showing the value and units of the Quantity. Return type: str
-
str_in_units(unit=None)¶ Format the result from
in_units()into stringParameters: unit (Unit) – [Optional] The units to express this Quantity in. If omitted, the Quantity will be expressed in the units in which it was defined. Returns: A string showing the value and units of the Quantity. Return type: str