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

mag

Magnitude of Quantity. Default is 1.

Type

float, optional

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

A

K

amount

Amount dimension or Quantity

cd

current

Current dimension or Quantity

dim

Dimensions of Quantity

intensity

Intensity dimension or Quantity

kg

length

Length dimension or Quantity

m

mass

Mass dimension or Quantity

mol

s

temperature

Temperature dimension or Quantity

time

Time dimension or Quantity

units

Units of Quantity

property A
property K
add(other, return_quantity=True, operation='Addition')

Helper method for addition.

Parameters
  • other (Quantity or other object) – Variable to add

  • return_quantity (bool, optional) – If True, returns a Quantity object.

  • operation (str, optional) – Operation to apply. Default is ‘Addition’.

Returns

out – Result of sum.

Return type

Quantity or other object

property amount

Amount dimension or Quantity

Type

float

property cd
property current

Current dimension or Quantity

Type

float

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. If unit_db is not specified, uses the vunits.db.unit_db.

Returns

quantity – New quantity object.

Return type

Quantity

property intensity

Intensity dimension or Quantity

Type

float

property kg
property length

Length dimension or Quantity

Type

float

property m
property mass

Mass dimension or Quantity

Type

float

property mol
property s
property temperature

Temperature dimension or Quantity

Type

float

property time

Time dimension or Quantity

Type

float

to_dict()

Represents object as dictionary with JSON-accepted datatypes

Returns

obj_dict

Return type

dict

property units

Units of Quantity

Returns

units – Powers of units. Columns are labeled with ‘m’, ‘kg’, ‘s’, ‘A’, ‘K’, ‘mol’, ‘cd’.

Return type

dict