vunits.quantity.Quantity¶
-
class
vunits.quantity.
Quantity
(mag=1.0, m=0.0, kg=0.0, s=0.0, A=0.0, K=0.0, mol=0.0, cd=0.0)¶ Bases:
object
Represents a quantity with units
-
m
¶ Power of meter (length). Default is 0.
- Type
float, optional
-
kg
¶ Power of kilogram (mass). Default is 0.
- Type
float, optional
-
s
¶ Power of seconds (time). Default is 0.
- Type
float, optional
-
A
¶ Power of amperes (electric current). Default is 0.
- Type
float, optional
-
K
¶ Power of Kelvin (temperature). Default is 0.
- Type
float, optional
-
mol
¶ Power of moles (amount of substance). Default is 0.
- Type
float, optional
-
cd
¶ Power of candela (luminous intensity). Default is 0.
- Type
float, optional
-
__init__
(mag=1.0, m=0.0, kg=0.0, s=0.0, A=0.0, K=0.0, mol=0.0, cd=0.0)¶ Initialize self. See help(type(self)) for accurate signature.
Methods
__init__
([mag, m, kg, s, A, K, mol, cd])Initialize self.
add
(other[, return_quantity, operation])Helper method for addition.
from_dict
(json_obj)Recreate an object from the JSON representation.
from_units
([mag, units, unit_db])Method to create a
Quantity
by parsing units.to_dict
()Represents object as dictionary with JSON-accepted datatypes
Attributes
Amount dimension or
Quantity
Current dimension or
Quantity
Dimensions of
Quantity
Intensity dimension or
Quantity
Length dimension or
Quantity
Mass dimension or
Quantity
Temperature dimension or
Quantity
Time dimension or
Quantity
Units of
Quantity
-
property
A
-
property
K
-
add
(other, return_quantity=True, operation='Addition')¶ Helper method for addition.
-
property
cd
-
property
dim
¶ Dimensions of
Quantity
- Returns
dim – Powers of units. Columns are labeled with ‘length’, ‘mass’, ‘time’, ‘current’, ‘temperature’, ‘amount’, ‘intensity’.
- Return type
dict
-
classmethod
from_dict
(json_obj)¶ Recreate an object from the JSON representation.
- Parameters
json_obj (dict) – JSON representation
- Returns
Obj
- Return type
Appropriate object
-
classmethod
from_units
(mag=1.0, units='', unit_db=None)¶ Method to create a
Quantity
by parsing units.- Parameters
mag (float, optional) – Magnitude of
Quantity
units (str, optional) – Units to parse. Different units must be sparated by a ‘ ‘ or ‘/’. Supports powers as numbers after units. e.g. ‘cm/s2’, ‘cm s-2’, or ‘cm s^-2’. Default is ‘’
unit_db (dict, optional) – Unit database to use parse units. Keys should be strings of expected units and values are
Quantity
objects. Ifunit_db
is not specified, uses thevunits.db.unit_db
.
- Returns
quantity – New quantity object.
- Return type
-
property
kg
-
property
m
-
property
mol
-
property
s
-
to_dict
()¶ Represents object as dictionary with JSON-accepted datatypes
- Returns
obj_dict
- Return type
dict
-