irfpy.util.unitq

Unit handling using external “quantities” module.

Code author: Yoshifumi Futaana

Note

This module uses ‘’quantities’’ package. I appreciate the author, Darren Dale, for providing the software.

https://github.com/python-quantities/python-quantities

irfpy.util.unitq handles the unit (dimension) based on the quantities package. See http://pythonhosted.org/quantities/ for detailed documentation on the quantities package.

irfpy.util.unitq adds some functionalies:

  • Shorter names (aliases) of the dimension.

  • r() (alias of rescale())

  • n() (get the value - remove units)

  • s() (get the simplified form based on the current system – default MKSA system)

  • u() (get the unit in the string format)

  • Simple conversion of the string formatted unit to the unit object. (Functions unit(), or nit())

  • Some new units commonly used in plasma physics. (For example, cu_flux.)

  • Dynamic definition of the new unit with SI prefix. (For example, ‘pT’ is automatically defined as pico-tesla if you use it in nit() function.)

  • You can set default unit system. (set_default_units(), or wrapped function use() or specific functions use_mksa() and use_plasma().)

  • Helper function for implementing formula, simple extention for unitful formula is possible. See make_unitful_function(). (Mainly for developer. It is used in irfpy.util.physics intensively.

  • Converting the “list of Quantities” to the single “Quantities” instance. (asarray())

Usage

It is recommended to start with

>>> import irfpy.util.unitq as u

to use the unitq module.

Then, you can make a quantity of “8.57 m” simply as

>>> print(8.57 * u.m)
8.57 m

Numerical calculation is simply done.

>>> l = 8.57 * u.m   # 8.57 meter
>>> t = 2.48 * u.s   # 2.48 seconds
>>> v = l / t    # Get the speed
>>> print('{:.3f}'.format(v))
3.456 m/s

Or you can make a unit object using unit() function (or nit(), with the module name u, it can be called u.nit).

>>> print(u.nit('300 MPa'))    # 300 Mega pascal
300.0 MPa

The attribute s (or simplified for long) convert the unit.

>>> print(u.nit('3.6 km/h').s)
1.0 m/s

You can remove the unit to get the normal numpy ndarray with the attribute of n.

>>> val = [8.57, 2.55] * u.m
>>> val_arr = val.n     #  .n will return the numpy array
>>> print(val_arr, isinstance(val_arr, np.ndarray))   
[8.57  2.55] True

The new array is a new instance, so changes are not propageted.

>>> val_arr[0] = 1.55
>>> print(val)   # The change in the new array will not affect the original   
[8.57  2.55] m

The solid angle is supported. But when you simplify to MKSA, it will go to dimensionless.

>>> print(3.5 * u.sr)
3.5 sr
>>> print((1.5 * u.sr)**2)
2.25 sr**2
>>> print(((0.3 * u.sr)**2).s)   # .s is to simplify. sr is unitless.
0.09 dimensionless

Electron volt is used both energy and temperature. This could be ambiguous. The default eV is for energy. A new unit of eV_asT (or eVT in short) is defined. The function r() rescales the unit.

>>> ev = 1 * eV_asT    # A new unit eV_asT has been defined.
>>> print(ev.r('K'))   # .r is to rescale the unit
11604.5052897 K

In summary, the following functions / attributes can be used.

  • n (numpy) returns the numpy.array expression of the quantity (5.0 or [2.0, 3.5]).

  • u (unit) returns the string expression of the units (kg or cm/s).

  • s (simplified) is an alias to simplified().

  • r (rescale) is an alias to rescale().

  • ns (numpy simplified) returns the numpy.array after being simplified.

  • nr (numpy rescaled) returns the numpy.array after being rescaled.

  • us (unit simplified) returns the string expression of the unit after being simplified.

  • ur (unit rescaled) returns the string expression of the unit after begin rescaled.

In the following, a series of sample is seen.

Constant with units are defined under the namespace of “k”. For example the Planck constant can be obtained as.

>>> h = u.k.Planck_constant   # Planck constant
>>> print(h)
1 h (Planck_constant)
>>> print(h.n)   # Get the value in the unit of Planck_constant
1.0
>>> print(h.u)   # The unit is ``h`` (Planck_constant).
h

Let’s see this value in the MKSA system with simplified attribute.

>>> print(h.simplified)
6.62606896e-34 kg*m**2/s
>>> print(h.ns)   # This expression simplifies the quantity, then return as a value.
6.62606896e-34
>>> print(h.us)    # This returns the unit of simplified quantity.
kg*m**2/s

Rescaling to another unit is also done using the function r, nr and ur.

>>> print('{:.3e}'.format(h.r('g*cm^2/s')))   # Rescale to the g cm^2 / s
6.626e-27 g*cm**2/s
>>> print('%.3e' % h.nr('g*cm^2/s'))  # Return the rescaled value (float) only.
6.626e-27
>>> print(h.ur('g*cm^2/s'))  # Return the rescaled unit
g*cm**2/s

Dynamic definition of the unit

Dynamic definition means that based on the defined unit, SI prefix is added and dynamically defined. For example, Giga year is not defined by default.

>>> print(u.Gyr)    
Traceback (most recent call last):
...
AttributeError: module 'irfpy.util.unitq' has no attribute 'Gyr'

However, once you use unit() function, “Gyr” is defined. >>> three_giga_year = u.nit(‘3 Gyr’) >>> print(three_giga_year) 3000000000.0 yr >>> print(u.Gyr) # Gyr was defined automatically 1 Gyr

Convert list of unit array to the single unit array

Sometimes, one need to iterate some calculation then you may get a list of unit array. As a simple example,

>>> l = [1, 2, 3] * u.m
>>> t = 1 * u.s
>>> print(l / t)
[1. 2. 3.] m/s

For this simple example of calculating the velocity, the above division is sufficient. But if a calculation becomes more complicated, iteration may not be avoided.

Such a case, one can rewrite the velocity calculation as

>>> v = [l_ / t for l_ in l]    # This is not equal to "l / t".
>>> print(v)
[array(1.) * m/s, array(2.) * m/s, array(3.) * m/s]

The result is not very easy to handle as unit array.

>>> print(v.rescale('cm/s'))   # Rescale does not work.   doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
AttributeError: 'list' object has no attribute 'rescale'

The function asarray() can be used to convert a list of unit arrays to a single unit array.

>>> v2 = asarray(v)
>>> print(v2)
[1. 2. 3.] m/s
>>> print(v2.rescale('cm/s'))
[100. 200. 300.] cm/s
irfpy.util.unitq.asarray(a, unit=None)[source]

From the input array-like to make as unit array.

Parameters:
  • a (Array like.) – Array like input. All elements should be values with units, equivalent for all.

  • unit – The unit to be used. It should not be a text representation. Use to wrap u.nit('m') instead of ‘m’.

Returns:

An array fully with a single unit.

A simple one

>>> from irfpy.util import unitq as u
>>> a_in = [3, 4, 5] * u.m
>>> a_out = u.asarray(a_in, unit=u.cm)    # This should work as if the rescale function
>>> print(a_out)
[300. 400. 500.] cm
>>> a_out = u.asarray([3, 4, 5], unit=u.km)   # This also should work as if the ``[3, 4, 5] * u.km``
>>> print(a_out)
[3. 4. 5.] km
>>> a_in = [3 * u.cm, 4 * u.m, 5 * u.km]   # A list. Input unit shall be connected to each component.
>>> a_out = asarray(a_in)     # In this case, the input array shall be converted to the first element unit, and converted to the unit array
>>> print(a_out)
[3.e+00 4.e+02 5.e+05] cm
>>> a_in = [[3 * u.cm, 4 * u.m, 5 * u.mm], [15, 20, 30] * u.mm]   # (3, 2) shape
>>> a_out = asarray(a_in, unit=u.nit('mm'))
>>> print(a_out)
[[  30. 4000.    5.]
 [  15.   20.   30.]] mm
class irfpy.util.unitq.k2[source]

Bases: object

MKSA scalar constant.

Deprecated since version 4.2.5: Use irfpy.util.constant module.

>>> print('%.3e' % k2.amu)
1.661e-27
amu = array(1.66053878e-27)

AMU

e = array(1.60217649e-19)

Elementary charge

m_p = array(1.67262164e-27)

Proton mass

irfpy.util.unitq.CUnit

Alias to CompoundUnit

irfpy.util.unitq.cu_pflux = 1 (1 /cm**2 /s)

Unit of particle flux

irfpy.util.unitq.cu_flux = 1 (1 /cm**2 /s)

Unit of particle flux

irfpy.util.unitq.cu_eflux = 1 (eV/cm**2 /s)

Unit of energy flux

irfpy.util.unitq.cu_diffflux = 1 (1/cm**2 /sr /eV / s)

Unit of differential particle flux

irfpy.util.unitq.cu_ediffflux = 1 (eV/cm**2 /sr /eV/s)

Unit of differential energy flux

irfpy.util.unitq.cu_gfactor = 1 (cm**2 * sr * eV/eV)

Unit of g-factor

irfpy.util.unitq.eVT = UnitQuantity('electron_volt_temperature', 11604.5052897 * K, 'eVT')

Electron volt used as temperature

irfpy.util.unitq.eV_asE = UnitQuantity('electron_volt', 1.60217653e-19 * J, 'eV')

Electron volt used as energy (quantities defined object)

irfpy.util.unitq.ster = UnitQuantity('steradian', 1.0 * rad**2, 'sr')

Steredian, an alias

irfpy.util.unitq.qe = UnitQuantity('elementary_charge', 1.602176487e-19 * C, 'e')

Unit charge, an alias

irfpy.util.unitq.rydberg_energy = UnitQuantity('rydberg_energy', 0.5 * E_h, 'E_Ry')

Rydberg energy. It is about 13.6 eV, and half of the Hartree.

irfpy.util.unitq.si_prefix = {'D': 10.0, 'E': 1e+18, 'G': 1000000000.0, 'M': 1000000.0, 'P': 1000000000000000.0, 'T': 1000000000000.0, 'Y': 1e+24, 'Z': 1e+21, 'a': 1e-18, 'atto': 1e-18, 'c': 0.01, 'centi': 0.01, 'd': 0.1, 'da': 10.0, 'deca': 10.0, 'deci': 0.1, 'exa': 1e+18, 'f': 1e-15, 'femto': 1e-15, 'giga': 1000000000.0, 'h': 100.0, 'hecto': 100.0, 'k': 1000.0, 'kilo': 1000.0, 'm': 0.001, 'mega': 1000000.0, 'micro': 1e-06, 'milli': 0.001, 'n': 1e-09, 'nano': 1e-09, 'p': 1e-12, 'peta': 1000000000000000.0, 'pico': 1e-12, 'tera': 1000000000000.0, 'u': 1e-06, 'y': 1e-24, 'yocto': 1e-24, 'yotta': 1e+24, 'z': 1e-21, 'zepto': 1e-21, 'zetta': 1e+21}

SI prefix

irfpy.util.unitq.known_unit = {'A': UnitCurrent('ampere', 'A'), 'B': UnitInformation('byte', 8.0 * bit, 'B'), 'BTU': UnitQuantity('British_thermal_unit', 1055.05585262 * J, 'BTU'), 'Bd': UnitQuantity('baud', 1.0 * bit/s, 'Bd'), 'Bq': UnitQuantity('becquerel', 1.0 * 1/s, 'Bq'), 'British_horsepower': UnitQuantity('horsepower', 33000.0 * ft*lbf/min, 'hp'), 'Btu': UnitQuantity('British_thermal_unit', 1055.05585262 * J, 'BTU'), 'C': UnitQuantity('coulomb', 1.0 * s*A, 'C'), 'C12_faraday': UnitQuantity('faraday', 96485.3399 * C), 'Canadian_liquid_gallon': UnitQuantity('UK_liquid_gallon', 4.54609 * L), 'Celsius': UnitTemperature('Celsius', 1.0 * K, 'degC'), 'Ci': UnitQuantity('curie', 37000000000.0 * Bq, 'Ci'), 'D': UnitQuantity('darcy', 9.869233e-13 * m**2, 'D'), 'Da': UnitMass('atomic_mass_unit', 1.660538782e-27 * kg, 'u'), 'EB': UnitInformation('exabyte', 1000.0 * PB, 'EB'), 'EC_therm': UnitQuantity('EC_therm', 100000.0 * BTU, 'thm'), 'EK': UnitTemperature('exakelvin', 1e+18 * K, 'EK'), 'E_h': UnitQuantity('hartree', 4.35974394e-18 * J, 'E_h'), 'EiB': UnitInformation('exbibyte', 1024.0 * PiB, 'EiB'), 'Eio': UnitInformation('exbibyte', 1024.0 * PiB, 'EiB'), 'Eo': UnitInformation('exabyte', 1000.0 * PB, 'EB'), 'F': UnitQuantity('farad', 1.0 * C/V, 'F'), 'Fahrenheit': UnitTemperature('Fahrenheit', 1.0 * degR, 'degF'), 'Fr': UnitQuantity('statcoulomb', 1.0 * cm**0.5*erg**0.5, 'esu'), 'GB': UnitInformation('gigabyte', 1000.0 * MB, 'GB'), 'GHz': UnitQuantity('gigahertz', 1000.0 * MHz, 'GHz'), 'GK': UnitTemperature('gigakelvin', 1000000000.0 * K, 'GK'), 'GL': UnitQuantity('gigaliter', 1000.0 * ML, 'GL'), 'GPa': UnitQuantity('gigapascal', 1000.0 * MPa, 'GPa'), 'GWh': UnitQuantity('gigawatt_hour', 1000.0 * MWh, 'GWh'), 'Gbar': UnitQuantity('gigabar', 1000.0 * Mbar, 'Gbar'), 'GeV': UnitQuantity('GeV', 1000.0 * MeV), 'Gi': UnitQuantity('gilbert', 0.7957747154594768 * ampere_turn, 'Gi'), 'GiB': UnitInformation('gibibyte', 1024.0 * MiB, 'GiB'), 'Gio': UnitInformation('gibibyte', 1024.0 * MiB, 'GiB'), 'Go': UnitInformation('gigabyte', 1000.0 * MB, 'GB'), 'Gregorian_year': UnitTime('Gregorian_year', 365.2425 * d), 'Gy': UnitQuantity('gray', 1.0 * J/kg, 'Gy'), 'H': UnitQuantity('henry', 1.0 * Wb/A, 'H'), 'H2O': UnitQuantity('H2O', 1000.0 * kg*g_0/m**3), 'Hg': UnitQuantity('conventional_mercury', 13.5951 * g*g_0/cm**3), 'Hz': UnitQuantity('hertz', 1.0 * 1/s, 'Hz'), 'Imperial_bushel': UnitQuantity('Imperial_bushel', 36.36872 * L), 'J': UnitQuantity('joule', 1.0 * m*N, 'J'), 'Julian_year': UnitTime('Julian_year', 365.25 * d), 'K': UnitTemperature('Kelvin', 'K'), 'Kelvin': UnitTemperature('Kelvin', 'K'), 'KiB': UnitInformation('kibibyte', 1024.0 * B, 'KiB'), 'Kio': UnitInformation('kibibyte', 1024.0 * B, 'KiB'), 'L': UnitQuantity('liter', 0.001 * m**3, 'L'), 'M': UnitQuantity('molar', 1.0 * mol/L, 'M'), 'MB': UnitInformation('megabyte', 1000.0 * kB, 'MB'), 'MHz': UnitQuantity('megahertz', 1000.0 * kHz, 'MHz'), 'MK': UnitTemperature('megakelvin', 1000000.0 * K, 'MK'), 'ML': UnitQuantity('megaliter', 1000.0 * kL, 'ML'), 'MOhm': UnitQuantity('megaohm', 1000.0 * kiloohm), 'MPa': UnitQuantity('megapascal', 1000.0 * kPa, 'MPa'), 'MW': UnitQuantity('megawatt', 1000.0 * kW, 'MW'), 'MWh': UnitQuantity('megawatt_hour', 1000.0 * kWh, 'MWh'), 'Mbar': UnitQuantity('megabar', 1000.0 * kbar, 'Mbar'), 'MeV': UnitQuantity('MeV', 1000.0 * keV), 'MiB': UnitInformation('mebibyte', 1024.0 * KiB, 'MiB'), 'Mio': UnitInformation('mebibyte', 1024.0 * KiB, 'MiB'), 'Mo': UnitInformation('megabyte', 1000.0 * kB, 'MB'), 'Ms': UnitTime('megasecond', 1000.0 * ks, 'Ms'), 'N': UnitQuantity('newton', 1.0 * kg*m/s**2, 'N'), 'Oe': UnitQuantity('oersted', 79.57747154594767 * A/m, 'Oe'), 'Ohm': UnitQuantity('ohm', 1.0 * V/A), 'P': UnitQuantity('poise', 0.1 * s*Pa, 'P'), 'PB': UnitInformation('petabyte', 1000.0 * TB, 'PB'), 'PK': UnitTemperature('petakelvin', 1000000000000000.0 * K, 'PK'), 'Pa': UnitQuantity('pascal', 1.0 * N/m**2, 'Pa'), 'PiB': UnitInformation('pebibyte', 1024.0 * TiB, 'PiB'), 'Pio': UnitInformation('pebibyte', 1024.0 * TiB, 'PiB'), 'Po': UnitInformation('petabyte', 1000.0 * TB, 'PB'), 'R': UnitQuantity('roentgen', 0.000258 * C/kg, 'R'), 'RSI': UnitQuantity('RSI', 1.0 * m**2*K/W), 'R_value': UnitQuantity('R_value', 1.0 * ft**2*h*degF/BTU), 'Rankine': UnitTemperature('Rankine', 0.5555555555555556 * K, 'degR'), 'S': UnitQuantity('siemens', 1.0 * A/V, 'S'), 'St': UnitQuantity('stokes', 0.0001 * m**2/s, 'St'), 'Sv': UnitQuantity('gray', 1.0 * J/kg, 'Gy'), 'T': UnitQuantity('tesla', 1.0 * Wb/m**2, 'T'), 'TB': UnitInformation('terabyte', 1000.0 * GB, 'TB'), 'TK': UnitTemperature('terakelvin', 1000000000000.0 * K, 'TK'), 'Tbl': UnitQuantity('tablespoon', 0.5 * fl_oz, 'tbsp'), 'Tblsp': UnitQuantity('tablespoon', 0.5 * fl_oz, 'tbsp'), 'Tbsp': UnitQuantity('tablespoon', 0.5 * fl_oz, 'tbsp'), 'TiB': UnitInformation('tebibyte', 1024.0 * GiB, 'TiB'), 'Tio': UnitInformation('tebibyte', 1024.0 * GiB, 'TiB'), 'To': UnitInformation('terabyte', 1000.0 * GB, 'TB'), 'UK_fluid_ounce': UnitQuantity('UK_fluid_ounce', 0.2 * UK_liquid_gill), 'UK_horsepower': UnitQuantity('horsepower', 33000.0 * ft*lbf/min, 'hp'), 'UK_liquid_cup': UnitQuantity('UK_liquid_cup', 0.5 * UK_liquid_pint), 'UK_liquid_gallon': UnitQuantity('UK_liquid_gallon', 4.54609 * L), 'UK_liquid_gill': UnitQuantity('UK_liquid_gill', 0.5 * UK_liquid_cup), 'UK_liquid_ounce': UnitQuantity('UK_fluid_ounce', 0.2 * UK_liquid_gill), 'UK_liquid_pint': UnitQuantity('UK_liquid_pint', 0.5 * UK_liquid_quart), 'UK_liquid_quart': UnitQuantity('UK_liquid_quart', 0.25 * UK_liquid_gallon), 'US_bushel': UnitQuantity('US_bushel', 2150.42 * in**3, 'bu'), 'US_dry_gallon': UnitQuantity('US_dry_gallon', 0.125 * bu), 'US_dry_pint': UnitQuantity('US_dry_pint', 0.5 * US_dry_quart), 'US_dry_quart': UnitQuantity('US_dry_quart', 0.25 * US_dry_gallon), 'US_fluid_ounce': UnitQuantity('US_fluid_ounce', 0.25 * gill, 'fl_oz'), 'US_liquid_cup': UnitQuantity('cup', 0.5 * pt), 'US_liquid_gallon': UnitQuantity('US_liquid_gallon', 231.0 * in**3), 'US_liquid_gill': UnitQuantity('US_liquid_gill', 0.5 * cup, 'gill'), 'US_liquid_ounce': UnitQuantity('US_fluid_ounce', 0.25 * gill, 'fl_oz'), 'US_liquid_pint': UnitQuantity('US_liquid_pint', 0.5 * quart, 'pt'), 'US_liquid_quart': UnitQuantity('US_liquid_quart', 0.25 * US_liquid_gallon, 'quart'), 'US_statute_mile': UnitLength('US_survey_mile', 5280.0 * US_survey_foot), 'US_survey_acre': UnitQuantity('US_survey_acre', 160.0 * rod**2), 'US_survey_foot': UnitLength('US_survey_foot', 0.3048006096012192 * m), 'US_survey_mile': UnitLength('US_survey_mile', 5280.0 * US_survey_foot), 'US_survey_yard': UnitLength('US_survey_yard', 3.0 * US_survey_foot), 'US_therm': UnitQuantity('US_therm', 105480400.0 * J), 'V': UnitQuantity('volt', 1.0 * J/C, 'V'), 'W': UnitQuantity('watt', 1.0 * J/s, 'W'), 'Wb': UnitQuantity('weber', 1.0 * s*V, 'Wb'), 'Wh': UnitQuantity('watt_hour', 1.0 * h*J/s, 'Wh'), 'YB': UnitInformation('yottabyte', 1000.0 * ZB, 'YB'), 'YK': UnitTemperature('yottakelvin', 1e+24 * K, 'YK'), 'YiB': UnitInformation('yobibyte', 1024.0 * ZiB, 'YiB'), 'Yio': UnitInformation('yobibyte', 1024.0 * ZiB, 'YiB'), 'Yo': UnitInformation('yottabyte', 1000.0 * ZB, 'YB'), 'ZB': UnitInformation('zettabyte', 1000.0 * EB, 'ZB'), 'ZK': UnitTemperature('zettakelvin', 1e+21 * K, 'ZK'), 'Z_0': UnitQuantity('characteristic_impedance_of_vacuum', 1.0 * c*mu_0, 'Z_0'), 'ZiB': UnitInformation('zebibyte', 1024.0 * EiB, 'ZiB'), 'Zio': UnitInformation('zebibyte', 1024.0 * EiB, 'ZiB'), 'Zo': UnitInformation('zettabyte', 1000.0 * EB, 'ZB'), 'a': UnitTime('year', 31556925.9747 * s, 'yr'), 'aA': UnitCurrent('abampere', 10.0 * A, 'aA'), 'aK': UnitTemperature('attokelvin', 1e-18 * K, 'aK'), 'abampere': UnitCurrent('abampere', 10.0 * A, 'aA'), 'abfarad': UnitQuantity('abfarad', 1000000000.0 * F), 'abhenry': UnitQuantity('abhenry', 1e-09 * H), 'abmho': UnitQuantity('abmho', 1000000000.0 * S), 'abohm': UnitQuantity('abohm', 1e-09 * ohm), 'abvolt': UnitQuantity('abvolt', 1e-08 * V), 'acre': UnitQuantity('acre', 4046.8564224 * m**2), 'acre_foot': UnitQuantity('acre_foot', 1.0 * ft*acre), 'amp': UnitCurrent('ampere', 'A'), 'ampere': UnitCurrent('ampere', 'A'), 'ampere_turn': UnitQuantity('ampere_turn', 1.0 * A), 'amperes': UnitCurrent('ampere', 'A'), 'amps': UnitCurrent('ampere', 'A'), 'amu': UnitMass('atomic_mass_unit', 1.660538782e-27 * kg, 'u'), 'angstrom': UnitLength('angstrom', 0.1 * nm), 'angular_degree': UnitQuantity('arcdegree', 0.017453292519943295 * rad, 'deg'), 'angular_minute': UnitQuantity('arcminute', 0.016666666666666666 * deg, 'arcmin'), 'angular_second': UnitQuantity('arcsecond', 0.016666666666666666 * arcmin, 'arcsec'), 'apdram': UnitMass('drachm', 60.0 * gr), 'apothecary_ounce': UnitMass('troy_ounce', 480.0 * gr, 'toz'), 'apothecary_pound': UnitMass('troy_pound', 12.0 * toz, 'tlb'), 'apounce': UnitMass('troy_ounce', 480.0 * gr, 'toz'), 'appound': UnitMass('troy_pound', 12.0 * toz, 'tlb'), 'arc_minute': UnitQuantity('arcminute', 0.016666666666666666 * deg, 'arcmin'), 'arc_second': UnitQuantity('arcsecond', 0.016666666666666666 * arcmin, 'arcsec'), 'arcdeg': UnitQuantity('arcdegree', 0.017453292519943295 * rad, 'deg'), 'arcdegree': UnitQuantity('arcdegree', 0.017453292519943295 * rad, 'deg'), 'arcmin': UnitQuantity('arcminute', 0.016666666666666666 * deg, 'arcmin'), 'arcminute': UnitQuantity('arcminute', 0.016666666666666666 * deg, 'arcmin'), 'arcsec': UnitQuantity('arcsecond', 0.016666666666666666 * arcmin, 'arcsec'), 'arcsecond': UnitQuantity('arcsecond', 0.016666666666666666 * arcmin, 'arcsec'), 'are': UnitQuantity('are', 100.0 * m**2), 'ares': UnitQuantity('are', 100.0 * m**2), 'arpentlin': UnitLength('arpentlin', 191.835 * ft), 'astronomical_unit': UnitLength('astronomical_unit', 149597870691.0 * m, 'au'), 'at': UnitQuantity('technical_atmosphere', 1.0 * kg*g_0/cm**2, 'at'), 'atm': UnitQuantity('standard_atmosphere', 101325.0 * Pa, 'atm'), 'atmosphere': UnitQuantity('standard_atmosphere', 101325.0 * Pa, 'atm'), 'atomic_mass_unit': UnitMass('atomic_mass_unit', 1.660538782e-27 * kg, 'u'), 'attosecond': UnitTime('attosecond', 0.001 * fs, 'as'), 'au': UnitLength('astronomical_unit', 149597870691.0 * m, 'au'), 'avoirdupois_ounce': UnitMass('ounce', 28.349523125 * g, 'oz'), 'avoirdupois_pound': UnitMass('pound', 0.45359237 * kg, 'lb'), 'b': UnitQuantity('barn', 1e-28 * m**2, 'b'), 'bag': UnitMass('bag', 94.0 * lb), 'bar': UnitQuantity('bar', 100000.0 * Pa), 'barad': UnitQuantity('barye', 0.1 * N/m**2, 'Ba'), 'barie': UnitQuantity('barye', 0.1 * N/m**2, 'Ba'), 'barleycorn': UnitLength('barleycorn', 0.3333333333333333 * in), 'barn': UnitQuantity('barn', 1e-28 * m**2, 'b'), 'barrel': UnitQuantity('barrel', 42.0 * US_liquid_gallon, 'bbl'), 'barrie': UnitQuantity('barye', 0.1 * N/m**2, 'Ba'), 'baryd': UnitQuantity('barye', 0.1 * N/m**2, 'Ba'), 'barye': UnitQuantity('barye', 0.1 * N/m**2, 'Ba'), 'baud': UnitQuantity('baud', 1.0 * bit/s, 'Bd'), 'bbl': UnitQuantity('barrel', 42.0 * US_liquid_gallon, 'bbl'), 'becquerel': UnitQuantity('becquerel', 1.0 * 1/s, 'Bq'), 'bev': UnitQuantity('GeV', 1000.0 * MeV), 'biot': UnitCurrent('abampere', 10.0 * A, 'aA'), 'bit': UnitInformation('bit'), 'board_foot': UnitQuantity('board_foot', 1.0 * in*ft**2, 'FBM'), 'boiler_horsepower': UnitQuantity('boiler_horsepower', 33475.0 * BTU/h), 'bps': UnitQuantity('baud', 1.0 * bit/s, 'Bd'), 'british_thermal_unit': UnitQuantity('British_thermal_unit', 1055.05585262 * J, 'BTU'), 'btu': UnitQuantity('British_thermal_unit', 1055.05585262 * J, 'BTU'), 'bu': UnitQuantity('US_bushel', 2150.42 * in**3, 'bu'), 'bushel': UnitQuantity('US_bushel', 2150.42 * in**3, 'bu'), 'byte': UnitInformation('byte', 8.0 * bit, 'B'), 'c': UnitQuantity('speed_of_light', 299792458.0 * m/s, 'c'), 'cK': UnitTemperature('centikelvin', 0.01 * K, 'cK'), 'cP': UnitQuantity('centipoise', 0.01 * P, 'cP'), 'cal': UnitQuantity('thermochemical_calorie', 4.184 * J, 'cal'), 'calorie': UnitQuantity('thermochemical_calorie', 4.184 * J, 'cal'), 'candela': UnitLuminousIntensity('candela', 'cd'), 'candle': UnitLuminousIntensity('candela', 'cd'), 'carat': UnitMass('carat', 200.0 * mg), 'cc': UnitQuantity('cubic_centimeter', 1.0 * cm**3, 'cc'), 'cd': UnitLuminousIntensity('candela', 'cd'), 'celsius': UnitTemperature('Celsius', 1.0 * K, 'degC'), 'centimeter': UnitLength('centimeter', 0.01 * m, 'cm'), 'centimeter_Hg': UnitQuantity('cmHg', 1.0 * cm*conventional_mercury), 'centimetre': UnitLength('centimeter', 0.01 * m, 'cm'), 'centipoise': UnitQuantity('centipoise', 0.01 * P, 'cP'), 'chain': UnitLength('chain', 66.0 * US_survey_foot), 'characteristic_impedance_of_vacuum': UnitQuantity('characteristic_impedance_of_vacuum', 1.0 * c*mu_0, 'Z_0'), 'chemical_faraday': UnitQuantity('chemical_faraday', 96495.7 * C), 'circle': UnitQuantity('turn', 6.283185307179586 * rad), 'circles': UnitQuantity('turn', 6.283185307179586 * rad), 'circular_mil': UnitQuantity('circular_mil', 5.067075e-10 * m**2, 'cmil'), 'clo': UnitQuantity('clo', 0.155 * RSI), 'clos': UnitQuantity('clo', 0.155 * RSI), 'cm': UnitLength('centimeter', 0.01 * m, 'cm'), 'cmH2O': UnitQuantity('cmH2O', 1.0 * cm*H2O), 'cmHg': UnitQuantity('cmHg', 1.0 * cm*conventional_mercury), 'cm_Hg': UnitQuantity('cmHg', 1.0 * cm*conventional_mercury), 'cmil': UnitQuantity('circular_mil', 5.067075e-10 * m**2, 'cmil'), 'common_year': UnitTime('common_year', 365.0 * d), 'conventional_mercury': UnitQuantity('conventional_mercury', 13.5951 * g*g_0/cm**3), 'conventional_water': UnitQuantity('H2O', 1000.0 * kg*g_0/m**3), 'coulomb': UnitQuantity('coulomb', 1.0 * s*A, 'C'), 'count': UnitQuantity('count', 1.0 * dimensionless, 'ct'), 'counts': UnitQuantity('count', 1.0 * dimensionless, 'ct'), 'cps': UnitQuantity('counts_per_second', 1.0 * ct/s), 'cu_diffflux': 1 (1/cm**2 /sr /eV / s), 'cu_ediffflux': 1 (eV/cm**2 /sr /eV/s), 'cu_eflux': 1 (eV/cm**2 /s), 'cu_flux': 1 (1 /cm**2 /s), 'cu_gfactor': 1 (cm**2 * sr * eV/eV), 'cu_pflux': 1 (1 /cm**2 /s), 'cubic_centimeter': UnitQuantity('cubic_centimeter', 1.0 * cm**3, 'cc'), 'cup': UnitQuantity('cup', 0.5 * pt), 'curie': UnitQuantity('curie', 37000000000.0 * Bq, 'Ci'), 'cycle': UnitQuantity('turn', 6.283185307179586 * rad), 'd': UnitTime('day', 24.0 * h, 'd'), 'dK': UnitTemperature('decikelvin', 0.1 * K, 'dK'), 'daK': UnitTemperature('dekakelvin', 10.0 * K, 'daK'), 'dalton': UnitMass('atomic_mass_unit', 1.660538782e-27 * kg, 'u'), 'darcy': UnitQuantity('darcy', 9.869233e-13 * m**2, 'D'), 'day': UnitTime('day', 24.0 * h, 'd'), 'decimeter': UnitLength('decimeter', 0.1 * m, 'dm'), 'decimetre': UnitLength('decimeter', 0.1 * m, 'dm'), 'deg': UnitQuantity('arcdegree', 0.017453292519943295 * rad, 'deg'), 'degC': UnitTemperature('Celsius', 1.0 * K, 'degC'), 'degF': UnitTemperature('Fahrenheit', 1.0 * degR, 'degF'), 'degK': UnitTemperature('Kelvin', 'K'), 'degR': UnitTemperature('Rankine', 0.5555555555555556 * K, 'degR'), 'degree': UnitQuantity('arcdegree', 0.017453292519943295 * rad, 'deg'), 'degrees': UnitQuantity('arcdegree', 0.017453292519943295 * rad, 'deg'), 'degrees_E': UnitQuantity('degrees_east', 1.0 * deg, 'degE'), 'degrees_N': UnitQuantity('degrees_north', 1.0 * deg, 'degN'), 'degrees_T': UnitQuantity('degrees_true', 1.0 * deg, 'degT'), 'degrees_W': UnitQuantity('degrees_west', 1.0 * deg, 'degW'), 'degrees_east': UnitQuantity('degrees_east', 1.0 * deg, 'degE'), 'degrees_north': UnitQuantity('degrees_north', 1.0 * deg, 'degN'), 'degrees_true': UnitQuantity('degrees_true', 1.0 * deg, 'degT'), 'degrees_west': UnitQuantity('degrees_west', 1.0 * deg, 'degW'), 'denier': UnitQuantity('denier', 0.00011111111111111112 * g/m), 'dimensionless': Dimensionless('dimensionless', 1.0 * dimensionless), 'dm': UnitLength('decimeter', 0.1 * m, 'dm'), 'dr': UnitMass('dram', 0.0625 * oz, 'dr'), 'drachm': UnitMass('drachm', 60.0 * gr), 'dram': UnitMass('dram', 0.0625 * oz, 'dr'), 'dry_pint': UnitQuantity('US_dry_pint', 0.5 * US_dry_quart), 'dry_quart': UnitQuantity('US_dry_quart', 0.25 * US_dry_gallon), 'dtex': UnitQuantity('dtex', 0.0001 * g/m), 'dwt': UnitMass('pennyweight', 24.0 * gr, 'dwt'), 'dynamic': UnitQuantity('standard_gravity', 9.80665 * m/s**2, 'g_0'), 'dyne': UnitQuantity('dyne', 1.0 * g*cm/s**2, 'dyn'), 'e': UnitQuantity('elementary_charge', 1.602176487e-19 * C, 'e'), 'eV': UnitQuantity('electron_volt', 1.60217653e-19 * J, 'eV'), 'eVT': UnitQuantity('electron_volt_temperature', 11604.5052897 * K, 'eVT'), 'eV_asE': UnitQuantity('electron_volt', 1.60217653e-19 * J, 'eV'), 'eV_asT': UnitQuantity('electron_volt_temperature', 11604.5052897 * K, 'eVT'), 'electric_constant': UnitQuantity('electric_constant', 1.0 * 1/(c**2*mu_0), 'epsilon_0'), 'electric_horsepower': UnitQuantity('electric_horsepower', 746.0 * W), 'electron_volt': UnitQuantity('electron_volt', 1.60217653e-19 * J, 'eV'), 'elementary_charge': UnitQuantity('elementary_charge', 1.602176487e-19 * C, 'e'), 'eon': UnitTime('eon', 1000000000.0 * yr), 'epsilon_0': UnitQuantity('electric_constant', 1.0 * 1/(c**2*mu_0), 'epsilon_0'), 'erg': UnitQuantity('erg', 1.0 * cm*dyn), 'esu': UnitQuantity('statcoulomb', 1.0 * cm**0.5*erg**0.5, 'esu'), 'esu_per_second': UnitCurrent('statampere', 1.0 * esu/s, '(esu/s)'), 'exabyte': UnitInformation('exabyte', 1000.0 * PB, 'EB'), 'exbibyte': UnitInformation('exbibyte', 1024.0 * PiB, 'EiB'), 'fF': UnitQuantity('femtofarad', 0.001 * pF, 'fF'), 'fK': UnitTemperature('femtokelvin', 1e-15 * K, 'fK'), 'fahrenheit': UnitTemperature('Fahrenheit', 1.0 * degR, 'degF'), 'farad': UnitQuantity('farad', 1.0 * C/V, 'F'), 'faraday': UnitQuantity('faraday', 96485.3399 * C), 'fathom': UnitLength('fathom', 6.0 * US_survey_foot), 'femtometer': UnitLength('femtometer', 0.001 * pm, 'fm'), 'femtometre': UnitLength('femtometer', 0.001 * pm, 'fm'), 'femtosecond': UnitTime('femtosecond', 0.001 * ps, 'fs'), 'fermi': UnitLength('femtometer', 0.001 * pm, 'fm'), 'firkin': UnitQuantity('firkin', 0.25 * bbl), 'fldr': UnitQuantity('fluid_dram', 0.125 * fl_oz, 'fldr'), 'floz': UnitQuantity('US_fluid_ounce', 0.25 * gill, 'fl_oz'), 'fluid_dram': UnitQuantity('fluid_dram', 0.125 * fl_oz, 'fldr'), 'fluid_ounce': UnitQuantity('US_fluid_ounce', 0.25 * gill, 'fl_oz'), 'fluidram': UnitQuantity('fluid_dram', 0.125 * fl_oz, 'fldr'), 'fm': UnitLength('femtometer', 0.001 * pm, 'fm'), 'foot': UnitLength('foot', 12.0 * in, 'ft'), 'footH2O': UnitQuantity('footH2O', 1.0 * ft*H2O), 'foot_H2O': UnitQuantity('foot_H2O', 1.0 * ft*H2O), 'force_gram': UnitQuantity('gram_force', 1.0 * g*g_0, 'gf'), 'force_kilogram': UnitQuantity('kilogram_force', 1.0 * kg*g_0, 'kgf'), 'force_ounce': UnitQuantity('ounce_force', 1.0 * oz*g_0, 'ozf'), 'force_pound': UnitQuantity('pound_force', 1.0 * lb*g_0, 'lbf'), 'force_ton': UnitQuantity('ton_force', 2000.0 * lbf), 'fortnight': UnitTime('fortnight', 2.0 * week), 'franklin': UnitQuantity('statcoulomb', 1.0 * cm**0.5*erg**0.5, 'esu'), 'free_fall': UnitQuantity('standard_gravity', 9.80665 * m/s**2, 'g_0'), 'fs': UnitTime('femtosecond', 0.001 * ps, 'fs'), 'ft': UnitLength('foot', 12.0 * in, 'ft'), 'ftH2O': UnitQuantity('foot_H2O', 1.0 * ft*H2O), 'furlong': UnitLength('furlong', 660.0 * US_survey_foot), 'g': UnitMass('gram', 0.001 * kg, 'g'), 'g_0': UnitQuantity('standard_gravity', 9.80665 * m/s**2, 'g_0'), 'g_n': UnitQuantity('standard_gravity', 9.80665 * m/s**2, 'g_0'), 'gallon': UnitQuantity('US_liquid_gallon', 231.0 * in**3), 'gamma': UnitQuantity('gamma', 1e-09 * T), 'gauss': UnitQuantity('gauss', 0.0001 * T, 'G'), 'gee': UnitQuantity('standard_gravity', 9.80665 * m/s**2, 'g_0'), 'geopotential': UnitQuantity('standard_gravity', 9.80665 * m/s**2, 'g_0'), 'gf': UnitQuantity('gram_force', 1.0 * g*g_0, 'gf'), 'gibibyte': UnitInformation('gibibyte', 1024.0 * MiB, 'GiB'), 'gigabar': UnitQuantity('gigabar', 1000.0 * Mbar, 'Gbar'), 'gigabyte': UnitInformation('gigabyte', 1000.0 * MB, 'GB'), 'gigahertz': UnitQuantity('gigahertz', 1000.0 * MHz, 'GHz'), 'gigaliter': UnitQuantity('gigaliter', 1000.0 * ML, 'GL'), 'gigalitre': UnitQuantity('gigaliter', 1000.0 * ML, 'GL'), 'gigapascal': UnitQuantity('gigapascal', 1000.0 * MPa, 'GPa'), 'gigawatt_hour': UnitQuantity('gigawatt_hour', 1000.0 * MWh, 'GWh'), 'gigawatthour': UnitQuantity('gigawatt_hour', 1000.0 * MWh, 'GWh'), 'gilbert': UnitQuantity('gilbert', 0.7957747154594768 * ampere_turn, 'Gi'), 'gill': UnitQuantity('US_liquid_gill', 0.5 * cup, 'gill'), 'gp': UnitQuantity('standard_gravity', 9.80665 * m/s**2, 'g_0'), 'gr': UnitMass('grain', 64.79891 * mg, 'gr'), 'grad': UnitQuantity('grad', 0.9 * deg), 'grade': UnitQuantity('grad', 0.9 * deg), 'grain': UnitMass('grain', 64.79891 * mg, 'gr'), 'gram': UnitMass('gram', 0.001 * kg, 'g'), 'gram_force': UnitQuantity('gram_force', 1.0 * g*g_0, 'gf'), 'gravity': UnitQuantity('standard_gravity', 9.80665 * m/s**2, 'g_0'), 'gray': UnitQuantity('gray', 1.0 * J/kg, 'Gy'), 'gross_register_ton': UnitQuantity('gross_register_ton', 100.0 * ft**3, 'GRT'), 'h': UnitTime('hour', 60.0 * min, 'h'), 'h2o': UnitQuantity('H2O', 1000.0 * kg*g_0/m**3), 'hK': UnitTemperature('hectokelvin', 100.0 * K, 'hK'), 'hPa': UnitQuantity('hectopascal', 100.0 * Pa, 'hPa'), 'ha': UnitQuantity('hectare', 10000.0 * m**2, 'ha'), 'hartree': UnitQuantity('hartree', 4.35974394e-18 * J, 'E_h'), 'hartree_energy': UnitQuantity('hartree', 4.35974394e-18 * J, 'E_h'), 'hectare': UnitQuantity('hectare', 10000.0 * m**2, 'ha'), 'hectopascal': UnitQuantity('hectopascal', 100.0 * Pa, 'hPa'), 'henry': UnitQuantity('henry', 1.0 * Wb/A, 'H'), 'hertz': UnitQuantity('hertz', 1.0 * 1/s, 'Hz'), 'horsepower': UnitQuantity('horsepower', 33000.0 * ft*lbf/min, 'hp'), 'hour': UnitTime('hour', 60.0 * min, 'h'), 'hp': UnitQuantity('horsepower', 33000.0 * ft*lbf/min, 'hp'), 'hr': UnitTime('hour', 60.0 * min, 'h'), 'impedence_of_free_space': UnitQuantity('characteristic_impedance_of_vacuum', 1.0 * c*mu_0, 'Z_0'), 'inHg': UnitQuantity('inHg', 1.0 * in*conventional_mercury), 'in_Hg': UnitQuantity('inHg', 1.0 * in*conventional_mercury), 'inch': UnitLength('inch', 2.54 * cm, 'in'), 'inch_H2O_39F': UnitQuantity('inch_H2O_39F', 1.0 * in*water_4C), 'inch_H2O_60F': UnitQuantity('inch_H2O_60F', 1.0 * in*water_60F), 'inch_Hg': UnitQuantity('inHg', 1.0 * in*conventional_mercury), 'inch_Hg_32F': UnitQuantity('inHg', 1.0 * in*conventional_mercury), 'inch_Hg_60F': UnitQuantity('inch_Hg_60F', 1.0 * in*mercury_60F), 'international_acre': UnitQuantity('acre', 4046.8564224 * m**2), 'international_foot': UnitLength('foot', 12.0 * in, 'ft'), 'international_inch': UnitLength('inch', 2.54 * cm, 'in'), 'international_knot': UnitQuantity('nautical_miles_per_hour', 1.0 * nmi/h, 'kt'), 'international_mile': UnitLength('mile', 5280.0 * ft, 'mi'), 'international_steam_table_calorie': UnitQuantity('international_steam_table_calorie', 4.1868 * J, 'cal_IT'), 'international_yard': UnitLength('yard', 3.0 * ft, 'yd'), 'joule': UnitQuantity('joule', 1.0 * m*N, 'J'), 'kB': UnitInformation('kilobyte', 1000.0 * B, 'kB'), 'kHz': UnitQuantity('kilohertz', 1000.0 * Hz, 'kHz'), 'kK': UnitTemperature('kilokelvin', 1000.0 * K, 'kK'), 'kL': UnitQuantity('kiloliter', 1000.0 * L, 'kL'), 'kOhm': UnitQuantity('kiloohm', 1000.0 * ohm), 'kPa': UnitQuantity('kilopascal', 1000.0 * Pa, 'kPa'), 'kV': UnitQuantity('kilovolt', 1000.0 * V, 'kV'), 'kW': UnitQuantity('kilowatt', 1000.0 * W, 'kW'), 'kWh': UnitQuantity('kilowatt_hour', 1000.0 * Wh, 'kWh'), 'kayser': UnitQuantity('kayser', 1.0 * 1/cm), 'kbar': UnitQuantity('kilobar', 1000.0 * bar, 'kbar'), 'keV': UnitQuantity('keV', 1000.0 * eV), 'kelvin': UnitTemperature('Kelvin', 'K'), 'kg': UnitMass('kilogram', 'kg'), 'kgf': UnitQuantity('kilogram_force', 1.0 * kg*g_0, 'kgf'), 'kibibyte': UnitInformation('kibibyte', 1024.0 * B, 'KiB'), 'kilobar': UnitQuantity('kilobar', 1000.0 * bar, 'kbar'), 'kilobyte': UnitInformation('kilobyte', 1000.0 * B, 'kB'), 'kilogram': UnitMass('kilogram', 'kg'), 'kilogram_force': UnitQuantity('kilogram_force', 1.0 * kg*g_0, 'kgf'), 'kilohertz': UnitQuantity('kilohertz', 1000.0 * Hz, 'kHz'), 'kiloliter': UnitQuantity('kiloliter', 1000.0 * L, 'kL'), 'kilolitre': UnitQuantity('kiloliter', 1000.0 * L, 'kL'), 'kilometer': UnitLength('kilometer', 1000.0 * m, 'km'), 'kilometre': UnitLength('kilometer', 1000.0 * m, 'km'), 'kilopascal': UnitQuantity('kilopascal', 1000.0 * Pa, 'kPa'), 'kilosecond': UnitTime('kilosecond', 1000.0 * s, 'ks'), 'kilovolt': UnitQuantity('kilovolt', 1000.0 * V, 'kV'), 'kilowatt': UnitQuantity('kilowatt', 1000.0 * W, 'kW'), 'kilowatt_hour': UnitQuantity('kilowatt_hour', 1000.0 * Wh, 'kWh'), 'kilowatthour': UnitQuantity('kilowatt_hour', 1000.0 * Wh, 'kWh'), 'kip': UnitQuantity('kip', 1000.0 * lbf), 'kip_per_square_inch': UnitQuantity('kip_per_square_inch', 1.0 * kip/in**2, 'ksi'), 'km': UnitLength('kilometer', 1000.0 * m, 'km'), 'knot': UnitQuantity('nautical_miles_per_hour', 1.0 * nmi/h, 'kt'), 'knot_international': UnitQuantity('nautical_miles_per_hour', 1.0 * nmi/h, 'kt'), 'ko': UnitInformation('kilobyte', 1000.0 * B, 'kB'), 'ks': UnitTime('kilosecond', 1000.0 * s, 'ks'), 'ksi': UnitQuantity('kip_per_square_inch', 1.0 * kip/in**2, 'ksi'), 'kt': UnitQuantity('nautical_miles_per_hour', 1.0 * nmi/h, 'kt'), 'l': UnitQuantity('liter', 0.001 * m**3, 'L'), 'lb': UnitMass('pound', 0.45359237 * kg, 'lb'), 'lbf': UnitQuantity('pound_force', 1.0 * lb*g_0, 'lbf'), 'leap_year': UnitTime('leap_year', 366.0 * d), 'light_year': UnitLength('light_year', 9460730472580.8 * km, 'ly'), 'liquid_gallon': UnitQuantity('US_liquid_gallon', 231.0 * in**3), 'liquid_pint': UnitQuantity('US_liquid_pint', 0.5 * quart, 'pt'), 'liquid_quart': UnitQuantity('US_liquid_quart', 0.25 * US_liquid_gallon, 'quart'), 'liter': UnitQuantity('liter', 0.001 * m**3, 'L'), 'litre': UnitQuantity('liter', 0.001 * m**3, 'L'), 'long_hundredweight': UnitMass('long_hundredweight', 112.0 * lb), 'long_ton': UnitMass('long_ton', 2240.0 * lb), 'lsb': UnitQuantity('least_significant_bit', 1.0 * dimensionless, 'lsb'), 'lunar_month': UnitTime('synodic_month', 29.530589 * d), 'ly': UnitLength('light_year', 9460730472580.8 * km, 'ly'), 'm': UnitLength('meter', 'm'), 'mA': UnitCurrent('milliampere', 0.001 * A, 'mA'), 'mC': UnitQuantity('millicoulomb', 0.001 * C, 'mC'), 'mD': UnitQuantity('millidarcy', 0.001 * D, 'mD'), 'mF': UnitQuantity('millifarad', 0.001 * F, 'mF'), 'mK': UnitTemperature('millikelvin', 0.001 * K, 'mK'), 'mL': UnitQuantity('milliliter', 0.001 * L, 'mL'), 'mM': UnitQuantity('millimolar', 0.001 * M, 'mM'), 'mS': UnitQuantity('millisiemens', 0.001 * S, 'mS'), 'mV': UnitQuantity('millivolt', 0.001 * V, 'mV'), 'mW': UnitQuantity('milliwatt', 0.001 * W, 'mW'), 'magnetic_constant': UnitQuantity('magnetic_constant', 1.2566370614359173e-06 * N/A**2, 'mu_0'), 'maxwell': UnitQuantity('maxwell', 1e-08 * Wb, 'Mx'), 'mbar': UnitQuantity('millibar', 0.001 * bar, 'mbar'), 'meV': UnitQuantity('meV', 0.001 * eV), 'mebibyte': UnitInformation('mebibyte', 1024.0 * KiB, 'MiB'), 'megabar': UnitQuantity('megabar', 1000.0 * kbar, 'Mbar'), 'megabyte': UnitInformation('megabyte', 1000.0 * kB, 'MB'), 'megahertz': UnitQuantity('megahertz', 1000.0 * kHz, 'MHz'), 'megaliter': UnitQuantity('megaliter', 1000.0 * kL, 'ML'), 'megalitre': UnitQuantity('megaliter', 1000.0 * kL, 'ML'), 'megapascal': UnitQuantity('megapascal', 1000.0 * kPa, 'MPa'), 'megasecond': UnitTime('megasecond', 1000.0 * ks, 'Ms'), 'megawatt': UnitQuantity('megawatt', 1000.0 * kW, 'MW'), 'megawatt_hour': UnitQuantity('megawatt_hour', 1000.0 * kWh, 'MWh'), 'megawatthour': UnitQuantity('megawatt_hour', 1000.0 * kWh, 'MWh'), 'mercury': UnitQuantity('conventional_mercury', 13.5951 * g*g_0/cm**3), 'mercury_60F': UnitQuantity('mercury_60F', 13556.8 * kg*g_0/m**3), 'meter': UnitLength('meter', 'm'), 'metre': UnitLength('meter', 'm'), 'metric_horsepower': UnitQuantity('metric_horsepower', 0.73549875 * kW), 'metric_ton': UnitMass('tonne', 1000.0 * kg, 't'), 'mg': UnitMass('milligram', 0.001 * g, 'mg'), 'mi': UnitLength('mile', 5280.0 * ft, 'mi'), 'microampere': UnitCurrent('microampere', 0.001 * mA, 'uA'), 'microcoulomb': UnitQuantity('microcoulomb', 1e-06 * C, 'uC'), 'micrometer': UnitLength('micrometer', 0.001 * mm, 'um'), 'micrometre': UnitLength('micrometer', 0.001 * mm, 'um'), 'micromolar': UnitQuantity('micromolar', 0.001 * mM, 'uM'), 'micron': UnitLength('micrometer', 0.001 * mm, 'um'), 'microradian': UnitQuantity('microradian', 0.001 * mrad, 'urad'), 'microsecond': UnitTime('microsecond', 0.001 * ms, 'us'), 'microsiemens': UnitQuantity('microsiemens', 0.001 * mS, 'uS'), 'microvolt': UnitQuantity('microvolt', 1e-06 * V, 'uV'), 'mil': UnitLength('mil', 0.001 * in), 'mile': UnitLength('mile', 5280.0 * ft, 'mi'), 'millenium': UnitTime('millenium', 1000.0 * yr), 'milliamp': UnitCurrent('milliampere', 0.001 * A, 'mA'), 'milliampere': UnitCurrent('milliampere', 0.001 * A, 'mA'), 'millibar': UnitQuantity('millibar', 0.001 * bar, 'mbar'), 'millicoulomb': UnitQuantity('millicoulomb', 0.001 * C, 'mC'), 'millidarcy': UnitQuantity('millidarcy', 0.001 * D, 'mD'), 'milligram': UnitMass('milligram', 0.001 * g, 'mg'), 'milliliter': UnitQuantity('cubic_centimeter', 1.0 * cm**3, 'cc'), 'millilitre': UnitQuantity('milliliter', 0.001 * L, 'mL'), 'millimeter': UnitLength('millimeter', 0.001 * m, 'mm'), 'millimeter_Hg': UnitQuantity('millimeter_Hg', 1.0 * mm*conventional_mercury, 'mmHg'), 'millimeter_Hg_0C': UnitQuantity('millimeter_Hg', 1.0 * mm*conventional_mercury, 'mmHg'), 'millimetre': UnitLength('millimeter', 0.001 * m, 'mm'), 'millimolar': UnitQuantity('millimolar', 0.001 * M, 'mM'), 'milliradian': UnitQuantity('milliradian', 0.001 * rad, 'mrad'), 'millisecond': UnitTime('millisecond', 0.001 * s, 'ms'), 'millisiemens': UnitQuantity('millisiemens', 0.001 * S, 'mS'), 'millivolt': UnitQuantity('millivolt', 0.001 * V, 'mV'), 'milliwatt': UnitQuantity('milliwatt', 0.001 * W, 'mW'), 'min': UnitTime('minute', 60.0 * s, 'min'), 'minute': UnitTime('minute', 60.0 * s, 'min'), 'mm': UnitLength('millimeter', 0.001 * m, 'mm'), 'mmHg': UnitQuantity('millimeter_Hg', 1.0 * mm*conventional_mercury, 'mmHg'), 'mm_Hg': UnitQuantity('millimeter_Hg', 1.0 * mm*conventional_mercury, 'mmHg'), 'mmol': UnitSubstance('millimole', 0.001 * mol, 'mmol'), 'mol': UnitSubstance('mole', 'mol'), 'molar': UnitQuantity('molar', 1.0 * mol/L, 'M'), 'mole': UnitSubstance('mole', 'mol'), 'month': UnitTime('month', 0.08333333333333333 * yr), 'mrad': UnitQuantity('milliradian', 0.001 * rad, 'mrad'), 'ms': UnitTime('millisecond', 0.001 * s, 'ms'), 'mu_0': UnitQuantity('magnetic_constant', 1.2566370614359173e-06 * N/A**2, 'mu_0'), 'nA': UnitCurrent('nanoampere', 0.001 * uA, 'nA'), 'nF': UnitQuantity('nanofarad', 0.001 * uF, 'nF'), 'nK': UnitTemperature('nanokelvin', 1e-09 * K, 'nK'), 'nPa': UnitQuantity('nPa', 1e-09 * Pa, 'nPa'), 'nS': UnitQuantity('nanosiemens', 0.001 * uS, 'nS'), 'nT': UnitQuantity('nT', 1e-09 * T, 'nT'), 'nanoamp': UnitCurrent('nanoampere', 0.001 * uA, 'nA'), 'nanoampere': UnitCurrent('nanoampere', 0.001 * uA, 'nA'), 'nanometer': UnitLength('nanometer', 0.001 * um, 'nm'), 'nanometre': UnitLength('nanometer', 0.001 * um, 'nm'), 'nanosecond': UnitTime('nanosecond', 0.001 * us, 'ns'), 'nanosiemens': UnitQuantity('nanosiemens', 0.001 * uS, 'nS'), 'nautical_mile': UnitLength('nautical_mile', 1852.0 * m, 'nmi'), 'newton': UnitQuantity('newton', 1.0 * kg*m/s**2, 'N'), 'nm': UnitLength('nanometer', 0.001 * um, 'nm'), 'nmi': UnitLength('nautical_mile', 1852.0 * m, 'nmi'), 'ns': UnitTime('nanosecond', 0.001 * us, 'ns'), 'o': UnitInformation('byte', 8.0 * bit, 'B'), 'octet': UnitInformation('byte', 8.0 * bit, 'B'), 'oersted': UnitQuantity('oersted', 79.57747154594767 * A/m, 'Oe'), 'ohm': UnitQuantity('ohm', 1.0 * V/A), 'ounce': UnitMass('ounce', 28.349523125 * g, 'oz'), 'ounce_force': UnitQuantity('ounce_force', 1.0 * oz*g_0, 'ozf'), 'oz': UnitMass('ounce', 28.349523125 * g, 'oz'), 'ozf': UnitQuantity('ounce_force', 1.0 * oz*g_0, 'ozf'), 'pA': UnitCurrent('picoampere', 0.001 * nA, 'pA'), 'pF': UnitQuantity('picofarad', 0.001 * nF, 'pF'), 'pK': UnitTemperature('picokelvin', 1e-12 * K, 'pK'), 'pS': UnitQuantity('picosiemens', 0.001 * nS, 'pS'), 'parsec': UnitLength('parsec', 3.08568025e+16 * m, 'pc'), 'pascal': UnitQuantity('pascal', 1.0 * N/m**2, 'Pa'), 'pc': UnitLength('parsec', 3.08568025e+16 * m, 'pc'), 'pc_per_cc': 1 (pc/cm**3), 'pebibyte': UnitInformation('pebibyte', 1024.0 * TiB, 'PiB'), 'peck': UnitQuantity('peck', 0.25 * bu, 'pk'), 'pennyweight': UnitMass('pennyweight', 24.0 * gr, 'dwt'), 'percent': UnitQuantity('percent', 0.01 * dimensionless, '%'), 'perch': UnitLength('rod', 16.5 * US_survey_foot), 'petabyte': UnitInformation('petabyte', 1000.0 * TB, 'PB'), 'physical_faraday': UnitQuantity('physical_faraday', 96521.9 * C), 'pica': UnitLength('pica', 12.0 * point), 'picoamp': UnitCurrent('picoampere', 0.001 * nA, 'pA'), 'picoampere': UnitCurrent('picoampere', 0.001 * nA, 'pA'), 'picometer': UnitLength('picometer', 0.001 * nm, 'pm'), 'picometre': UnitLength('picometer', 0.001 * nm, 'pm'), 'picosecond': UnitTime('picosecond', 0.001 * ns, 'ps'), 'picosiemens': UnitQuantity('picosiemens', 0.001 * nS, 'pS'), 'pint': UnitQuantity('US_liquid_pint', 0.5 * quart, 'pt'), 'pk': UnitQuantity('peck', 0.25 * bu, 'pk'), 'pm': UnitLength('picometer', 0.001 * nm, 'pm'), 'point': UnitLength('printers_point', 0.3527777777777778 * mm, 'point'), 'poise': UnitQuantity('poise', 0.1 * s*Pa, 'P'), 'pole': UnitLength('rod', 16.5 * US_survey_foot), 'pond': UnitQuantity('pond', 1.0 * kg*g_0, 'p'), 'pound': UnitMass('pound', 0.45359237 * kg, 'lb'), 'pound_force': UnitQuantity('pound_force', 1.0 * lb*g_0, 'lbf'), 'pound_force_per_square_inch': UnitQuantity('pound_force_per_square_inch', 1.0 * lb*g_0/in**2, 'psi'), 'poundal': UnitQuantity('poundal', 1.0 * lb*ft/s**2, 'pdl'), 'printers_point': UnitLength('printers_point', 0.3527777777777778 * mm, 'point'), 'ps': UnitTime('picosecond', 0.001 * ns, 'ps'), 'psi': UnitQuantity('pound_force_per_square_inch', 1.0 * lb*g_0/in**2, 'psi'), 'pt': UnitQuantity('US_liquid_pint', 0.5 * quart, 'pt'), 'q': UnitQuantity('elementary_charge', 1.602176487e-19 * C, 'e'), 'qe': UnitQuantity('elementary_charge', 1.602176487e-19 * C, 'e'), 'quart': UnitQuantity('US_liquid_quart', 0.25 * US_liquid_gallon, 'quart'), 'rad': UnitQuantity('radian', 1.0 * dimensionless, 'rad'), 'radian': UnitQuantity('radian', 1.0 * dimensionless, 'rad'), 'radians': UnitQuantity('radian', 1.0 * dimensionless, 'rad'), 'rads': UnitQuantity('rads', 0.01 * Gy), 'rankine': UnitTemperature('Rankine', 0.5555555555555556 * K, 'degR'), 'rd': UnitQuantity('rutherford', 1000000.0 * Bq, 'Rd'), 'refrigeration_ton': UnitQuantity('refrigeration_ton', 12000.0 * BTU/h), 'register_ton': UnitQuantity('gross_register_ton', 100.0 * ft**3, 'GRT'), 'rem': UnitQuantity('rem', 0.01 * Gy), 'revolution': UnitQuantity('turn', 6.283185307179586 * rad), 'revolutions_per_minute': UnitQuantity('revolutions_per_minute', 1.0 * turn/min, 'rpm'), 'rhe': UnitQuantity('rhe', 10.0 * 1/(s*Pa)), 'rod': UnitLength('rod', 16.5 * US_survey_foot), 'roentgen': UnitQuantity('roentgen', 0.000258 * C/kg, 'R'), 'rpm': UnitQuantity('revolutions_per_minute', 1.0 * turn/min, 'rpm'), 'rps': UnitQuantity('hertz', 1.0 * 1/s, 'Hz'), 'rutherford': UnitQuantity('rutherford', 1000000.0 * Bq, 'Rd'), 'rydberg_energy': UnitQuantity('rydberg_energy', 0.5 * E_h, 'E_Ry'), 's': UnitTime('second', 's'), 'scruple': UnitMass('scruple', 20.0 * gr), 'sec': UnitTime('second', 's'), 'second': UnitTime('second', 's'), 'shake': UnitTime('shake', 1e-08 * s), 'short_hundredweight': UnitMass('short_hundredweight', 100.0 * lb), 'short_ton': UnitMass('short_ton', 2000.0 * lb), 'sidereal_day': UnitTime('sidereal_day', 0.997269566329084 * d), 'sidereal_hour': UnitTime('sidereal_hour', 0.041666666666666664 * sidereal_day), 'sidereal_minute': UnitTime('sidereal_minute', 0.016666666666666666 * sidereal_hour), 'sidereal_month': UnitTime('sidereal_month', 27.321661 * d), 'sidereal_second': UnitTime('sidereal_second', 0.016666666666666666 * sidereal_minute), 'sidereal_year': UnitTime('sidereal_year', 366.25636042 * sidereal_day), 'siemens': UnitQuantity('siemens', 1.0 * A/V, 'S'), 'sievert': UnitQuantity('gray', 1.0 * J/kg, 'Gy'), 'slug': UnitMass('slug', 14.5939 * kg), 'slugs': UnitMass('slug', 14.5939 * kg), 'speed_of_light': UnitQuantity('speed_of_light', 299792458.0 * m/s, 'c'), 'sr': UnitQuantity('steradian', 1.0 * rad**2, 'sr'), 'st': UnitMass('stone', 14.0 * lb, 'st'), 'stF': UnitQuantity('statfarad', 1.11265e-12 * F, 'stF'), 'stH': UnitQuantity('stathenry', 898755400000.0 * H, 'stH'), 'stS': UnitQuantity('statmho', 1.11265e-12 * S, 'stS'), 'stV': UnitQuantity('statvolt', 299.7925 * V, 'stV'), 'standard_atmosphere': UnitQuantity('standard_atmosphere', 101325.0 * Pa, 'atm'), 'standard_free_fall': UnitQuantity('standard_gravity', 9.80665 * m/s**2, 'g_0'), 'standard_gravity': UnitQuantity('standard_gravity', 9.80665 * m/s**2, 'g_0'), 'statC': UnitQuantity('statcoulomb', 1.0 * cm**0.5*erg**0.5, 'esu'), 'statF': UnitQuantity('statfarad', 1.11265e-12 * F, 'stF'), 'statH': UnitQuantity('stathenry', 898755400000.0 * H, 'stH'), 'statS': UnitQuantity('statmho', 1.11265e-12 * S, 'stS'), 'statV': UnitQuantity('statvolt', 299.7925 * V, 'stV'), 'statampere': UnitCurrent('statampere', 1.0 * esu/s, '(esu/s)'), 'statcoulomb': UnitQuantity('statcoulomb', 1.0 * cm**0.5*erg**0.5, 'esu'), 'statfarad': UnitQuantity('statfarad', 1.11265e-12 * F, 'stF'), 'stathenry': UnitQuantity('stathenry', 898755400000.0 * H, 'stH'), 'statmho': UnitQuantity('statmho', 1.11265e-12 * S, 'stS'), 'statohm': UnitQuantity('statohm', 898755400000.0 * ohm), 'statvolt': UnitQuantity('statvolt', 299.7925 * V, 'stV'), 'ster': UnitQuantity('steradian', 1.0 * rad**2, 'sr'), 'steradian': UnitQuantity('steradian', 1.0 * rad**2, 'sr'), 'stere': UnitQuantity('stere', 1.0 * m**3), 'stokes': UnitQuantity('stokes', 0.0001 * m**2/s, 'St'), 'stone': UnitMass('stone', 14.0 * lb, 'st'), 'synodic_month': UnitTime('synodic_month', 29.530589 * d), 't': UnitMass('tonne', 1000.0 * kg, 't'), 'tablespoon': UnitQuantity('tablespoon', 0.5 * fl_oz, 'tbsp'), 'tblsp': UnitQuantity('tablespoon', 0.5 * fl_oz, 'tbsp'), 'tbs': UnitQuantity('tablespoon', 0.5 * fl_oz, 'tbsp'), 'tbsp': UnitQuantity('tablespoon', 0.5 * fl_oz, 'tbsp'), 'teaspoon': UnitQuantity('teaspoon', 0.3333333333333333 * tbsp, 'tsp'), 'tebibyte': UnitInformation('tebibyte', 1024.0 * GiB, 'TiB'), 'technical_atmosphere': UnitQuantity('technical_atmosphere', 1.0 * kg*g_0/cm**2, 'at'), 'terabyte': UnitInformation('terabyte', 1000.0 * GB, 'TB'), 'tesla': UnitQuantity('tesla', 1.0 * Wb/m**2, 'T'), 'tex': UnitQuantity('tex', 0.001 * g/m), 'therm': UnitQuantity('EC_therm', 100000.0 * BTU, 'thm'), 'thermochemical_calorie': UnitQuantity('thermochemical_calorie', 4.184 * J, 'cal'), 'thm': UnitQuantity('EC_therm', 100000.0 * BTU, 'thm'), 'thou': UnitLength('mil', 0.001 * in), 'ton': UnitMass('short_ton', 2000.0 * lb), 'ton_TNT': UnitQuantity('ton_TNT', 4184000000.0 * J, 'tTNT'), 'ton_force': UnitQuantity('ton_force', 2000.0 * lbf), 'ton_of_refrigeration': UnitQuantity('refrigeration_ton', 12000.0 * BTU/h), 'tonne': UnitMass('tonne', 1000.0 * kg, 't'), 'torr': UnitQuantity('torr', 0.0013157894736842105 * atm), 'toz': UnitMass('troy_ounce', 480.0 * gr, 'toz'), 'tropical_month': UnitTime('tropical_month', 27.321582 * d), 'tropical_year': UnitTime('year', 31556925.9747 * s, 'yr'), 'troy_ounce': UnitMass('troy_ounce', 480.0 * gr, 'toz'), 'troy_pound': UnitMass('troy_pound', 12.0 * toz, 'tlb'), 'tsp': UnitQuantity('teaspoon', 0.3333333333333333 * tbsp, 'tsp'), 'turn': UnitQuantity('turn', 6.283185307179586 * rad), 'turns': UnitQuantity('turn', 6.283185307179586 * rad), 'u': UnitMass('atomic_mass_unit', 1.660538782e-27 * kg, 'u'), 'uA': UnitCurrent('microampere', 0.001 * mA, 'uA'), 'uC': UnitQuantity('microcoulomb', 1e-06 * C, 'uC'), 'uF': UnitQuantity('microfarad', 0.001 * mF, 'uF'), 'uK': UnitTemperature('microkelvin', 1e-06 * K, 'uK'), 'uM': UnitQuantity('micromolar', 0.001 * mM, 'uM'), 'uS': UnitQuantity('microsiemens', 0.001 * mS, 'uS'), 'uV': UnitQuantity('microvolt', 1e-06 * V, 'uV'), 'um': UnitLength('micrometer', 0.001 * mm, 'um'), 'umol': UnitSubstance('micromole', 0.001 * mmol, 'umol'), 'unit_pole': UnitQuantity('unit_pole', 1.256637e-07 * Wb), 'urad': UnitQuantity('microradian', 0.001 * mrad, 'urad'), 'us': UnitTime('microsecond', 0.001 * ms, 'us'), 'vacuum_permeability': UnitQuantity('magnetic_constant', 1.2566370614359173e-06 * N/A**2, 'mu_0'), 'vacuum_permittivity': UnitQuantity('electric_constant', 1.0 * 1/(c**2*mu_0), 'epsilon_0'), 'volt': UnitQuantity('volt', 1.0 * J/C, 'V'), 'volt_ampere': UnitQuantity('watt', 1.0 * J/s, 'W'), 'water': UnitQuantity('H2O', 1000.0 * kg*g_0/m**3), 'water_39F': UnitQuantity('water_4C', 999.972 * kg*g_0/m**3), 'water_4C': UnitQuantity('water_4C', 999.972 * kg*g_0/m**3), 'water_60F': UnitQuantity('water_60F', 999.001 * kg*g_0/m**3), 'water_horsepower': UnitQuantity('water_horsepower', 746.043 * W), 'watt': UnitQuantity('watt', 1.0 * J/s, 'W'), 'watt_hour': UnitQuantity('watt_hour', 1.0 * h*J/s, 'Wh'), 'watthour': UnitQuantity('watt_hour', 1.0 * h*J/s, 'Wh'), 'wavenumber': UnitQuantity('kayser', 1.0 * 1/cm), 'weber': UnitQuantity('weber', 1.0 * s*V, 'Wb'), 'week': UnitTime('week', 7.0 * d), 'work_month': UnitQuantity('work_month', 0.08333333333333333 * work_year), 'work_year': UnitQuantity('work_year', 2056.0 * h), 'yK': UnitTemperature('yoctokelvin', 1e-24 * K, 'yK'), 'yard': UnitLength('yard', 3.0 * ft, 'yd'), 'yd': UnitLength('yard', 3.0 * ft, 'yd'), 'year': UnitTime('year', 31556925.9747 * s, 'yr'), 'yobibyte': UnitInformation('yobibyte', 1024.0 * ZiB, 'YiB'), 'yottabyte': UnitInformation('yottabyte', 1000.0 * ZB, 'YB'), 'yr': UnitTime('year', 31556925.9747 * s, 'yr'), 'zK': UnitTemperature('zeptokelvin', 1e-21 * K, 'zK'), 'zebibyte': UnitInformation('zebibyte', 1024.0 * EiB, 'ZiB'), 'zettabyte': UnitInformation('zettabyte', 1000.0 * EB, 'ZB')}

A dictionary of unit.

It maps the name of the unit and the UnitQuantity object.

irfpy.util.unitq.nit(string_units, verbose=False)[source]

Return the unit object corresponding to the given expression

>>> import irfpy.util.unitq as u
>>> print(3 * u.nit('kg'))
3.0 kg

As you see the above example, the name comes for above convenstion :).

Each unit should be one word: 'kg' or 's'. For the multiple of units, separate by space or aster or dot.: e.g. 'J s' or 'J*s' or 'J.s'. 'Js' not allowed. Devision is '/'. '1/s', m/s. For the power, you may use ** or ^. No space before and after the operator. e.g. 'm2', 'm^2' or 'm**2

Anyway, it is highly recommended to make * or space between units and numbers to multiply. Also, ‘^’ is recommended to be added, but not spaces around. ('m2' and 'm 2' provide different result. 'm^2' and 'm*2')

Parenthesis () not supported.

>>> print(u.nit('m'))
1 m (meter)
>>> print(u.nit(' 3 m'))
3.0 m
>>> print(u.nit('m/s'))
1.0 m/s
>>> print(u.nit('J s'))
1.0 s*J
>>> print(u.nit('J2 s'))
1.0 s*J**2
>>> print(u.nit('J2 s-2'))
1.0 J**2/s**2
>>> print(u.nit('J3 s-1 .8'))
0.8 J**3/s
>>> print(u.nit('3 / 2'))   # Even usual number calculation.
1.5
>>> #  print u.nit('3**2')    ## But this is not possible
>>> print(u.nit('s0.5'))   # Fractional unit ok.
1.0 s**0.5
>>> #print u.nit('3.s')   # Will be error
>>> #print u.nit('.3s')   # Will be error
>>> print(u.nit('s.K 3.'))
3.0 s*K
>>> #print u.nit('s.K3.') # Will be error
>>> print(u.nit('m2'))
1.0 m**2
>>> print(u.nit('m 2'))
2.0 m
>>> print(u.nit('m^2'))
1.0 m**2
>>> print(u.nit('m*2'))
2.0 m

It will guess the SI prefix.

>>> print(u.nit('pC'))   # Pico coulon
1e-12 C
>>> pprint(u.nit('TeV').rescale('eV'), fmt='%.2e')   # Tera eV
1.00e+12 eV

Differential flux, for example

>>> print(u.nit('3e8 /cm2 /sr /s /eV'))
300000000.0 1/(cm**2*s*sr*eV)
>>> pprint(u.nit('3e8 /cm2 /sr /s /eV').simplified, fmt='%.3e')
1.872e+31 s/(kg*m**4)
>>> print(nit('3 /cm2 nm sr/s J/A cd'))  # I don't know this unit...
3.0 nm*cd*sr*J/(cm**2*s*A)
>>> pprint(nit('3 /cm2 nm sr/s J/A cd').simplified, fmt='%.2e')  # I don't know this unit...
3.00e-05 kg*m*cd/(s**3*A)
irfpy.util.unitq.unit(string_units, verbose=False)

An alias

irfpy.util.unitq.make_unitful_function(func, unitlist, runit, offset=0)[source]

Make unitful function.

Parameters:
  • func – Physical function (formula)

  • unitful – List of the unit in the order of the argument of func.

  • runit – Unit of the returned value of func.

  • offset – If set, the unitlist is started to be applied to the argument after offset. This is used for when this function is applied for an object method, whose 0-th argument is the object.

When you implement a physical function (or formula), it is usually a good idea to have internal expression of float or numpy.array.

This is usually very fast, and easy to extend.

On the other hand, you may also want to make “unitful” version, particularly for step-by-step calculation in the interactive shell.

This function produces a function of “unitful” version from the float or numpy.array version of function.

Example follows.

>>> import irfpy.util.unitq as u
>>> def PE(m_si, h_si):
...     return 9.8 * m_si * h_si

The above function calculate the gravity potential. It is implincitly assumes float (or numpy array) argument in the MKSA system.

>>> print(PE(1.5, 20.0))
294.0

Something with 1.5 kg mass is placed at 20.0 m, the gravity potential is 294.0 J (at the Earth).

If you want to calculate with unit, PE cannot handle it properly.

>>> print(PE(1.5 * u.kg, 20.0 * u.m))
294.0 kg*m

The value is ok, but the unit is not in Joule, so that I cannot convert it.

>>> pprint(PE(1500 * u.g, 2000 * u.cm), fmt='%.4e')
2.9400e+07 g*cm

The example gives more complicated situation. Again, the unit is not consistent.

To solve this problem, I suggest to make the unitful function. The unitful version of the function can be made via

>>> PE_u = make_unitful_function(PE, [u.kg, u.m], u.J)

The first argument is the unitless function, the second argument is a list of unit assumed in the PE function in the order, and the third argument is the unit returned in the KE function.

>>> print(PE_u(1500 * u.g, 2000 * u.cm).rescale(J))
294.0 J

The :make_unitful_function: returns a wrapped function (PE_u) of the original function (PE). When called the wrapped function, the argument is first converted to float/np.array by stripping the given units used in the original function (mass is ‘kg’ and height is ‘m’ here). Then, the original function is executed with float/np.array. Finally, the given unit (the result is ‘J’) is added to the output float/np.array, to be returned by the new function.

Use of ``offset``

If you have formula as an method of some class. Let’s try to find out the Moon gravity calculator class.

>>> class MoonGravity:
...     def __init__(self):
...         self.g = 1.625   # m/s2, gravitation of Moon
...     def PE(self, mass, distance):
...         return self.g * mass * distance
>>> mg = MoonGravity()
>>> print(mg.PE(1.5, 20))
48.75

A new class, namely the unitful class may be generated as follows.

>>> class MoonGravity_u(MoonGravity):
...     def __init__(self):
...         MoonGravity.__init__(self)
...     PE = make_unitful_function(MoonGravity.PE, [kg, m], J, offset=1)
>>> mg_u = MoonGravity_u()
>>> print(mg_u.PE(1500 * g, 2000 * cm))
48.75 J

Here to define (override) new PE, offset=1 is given. This is because MoonGravity.PE method will take the object as the 0-th argument, which should not be unit-converted.

irfpy.util.unitq.make_unitful_function2(func, argunitarr, retunitarr)[source]

Improved factory of make_unitful_function(), allowing tuple of return.

Parameters:
  • func – Physical function (formula)

  • argunitarr – List of unit in the order of the argument of func. Units or None.

  • retunitarr – List of unit of the returned value of func. Units or None.

When you implement a physical function (or formula), it is usually a good idea to have internal expression of float or numpy.array.

This is usually very fast, and easy to extend.

On the other hand, you may also want to make “unitful” version, particularly for step-by-step calculation in the interactive shell.

This function produces a function of “unitful” version from the float or numpy.array version of function.

Example follows.

Suppose you make a function to calculate the kinetic energy and the momentum. The argument is the mass and the velocity. Also, you may want to give an argument for which unit conversion is not needed, and to return a status flag, which is also not a physical unit.

The function should look like kene, mom, stat = enemom(mass, vel, name). The list of the units of the argument is [u.kg, u.m / u.s, None] and that for return values is [u.J, u.kg * u.m / u.s, None].

>>> def enemom(mass, vel, name):
...     ke = mass * vel * vel / 2.
...     mom = mass * vel
...     stat = len(name)    # Immitate the status.
...     return ke, mom, stat
>>> print(enemom(10., 30., 'sample'))
(4500.0, 300.0, 6)

If you want to make a unitful version,

>>> enemom_u = make_unitful_function2(enemom, [kg, m / s, None], [J, kg * m / s, None])
>>> print(enemom(10. * kg, 30. * m / s, 'unitful sample'))     
(array(4500.) * kg*m**2/s**2, array(300.) * kg*m/s, 14)

Todo

Known issue. If the retunitarr is scalar, the argument is transfered to make_unitful_function(). However, the None argument is not supported for make_unitful_function().

irfpy.util.unitq.use_plasma()[source]

Use space plasma familier system as default.

Length in cm, mass in AMU, temperature in eV, and time in s.

>>> import irfpy.util.unitq as u
>>> print((1 * u.km ** 3).simplified)
1000000000.0 m**3
>>> u.use_plasma()
>>> pprint((1 * u.km ** 3).simplified, fmt='%.1e')
1.0e+15 cm**3
>>> pprint((30000 * u.K).simplified)
2.585 eVT
>>> u.use_mksa()
>>> print((30000 * u.K).simplified)
30000.0 K
irfpy.util.unitq.use_mksa()[source]
irfpy.util.unitq.use(system=None, currency=None, current=None, information=None, length=None, luminous_intensity=None, mass=None, substance=None, temperature=None, time=None)

Alias to set_default_units provided by qunatities

irfpy.util.unitq.pprint(value, fmt='%.3f', *args, **kwds)[source]

Print the value in easily-readable way.

Parameters:
  • value – A quantity

  • fmt – Format. Only effective if the value has shape (), namely float.

  • kwds – Keywords given to irfpy.util.with_context.printoptions() Only effective if value is array. precision and suppress are frequently used.

>>> pprint(np.sqrt(np.arange(3000)) * kg, precision=3, suppress=True)    
[  0.      1.      1.414 ...  54.745  54.754  54.763] kg
>>> pprint(1.537732343e-10 * g, fmt='%.5e')
1.53773e-10 g
irfpy.util.unitq.pp(value, fmt='%.3f', *args, **kwds)

Alias for pprint()