skip to navigation
skip to content

Not Logged In

natu 0.1.0-a2

Natural units in Python

Latest Version: 0.1.1

Natural units in Python

Warning

This project is currently in a pre-release state because it has not been fully tested. It will be officially released once the unit tests are complete.

natu is a free, open-source package to represent physical quantities. There are many Python packages that deal with units and quantities (see the “See also” list below), but natu is unique because it is truly system-independent. The units are derived from physical constants with adjustable values and dimensions. The value of a unit is factored into a quantity so that the quantity is not “in” any particular unit. This offers the following advantages:

  • Flexibility: Different unit systems, including natural units (hence the name “natu”), can be represented by simply adjusting the physical constants.
  • Simplicity: Unit conversion is inherent. This results in quick computations and a small code base (<1500 lines). By default, dimensions and display units are tracked to catch errors and for string formatting, respectively. However, this feature can be turned off to reduce the computational overhead to nearly zero while still allowing input and output in mixed units.
  • Scalability: Numerical scaling is independent of the units used to create quantities. This can be used to prevent exponent overflow [Davies2012].
  • Intuitive: Each unit is a fixed quantity which can be treated as a mathematical entity. A variable quantity is expressed as the product of a number and a unit, as stated in [BIPM2006].
  • Representative: The structure of the package reflects the way modern units are defined: standards organizations such as NIST assign values to universal physical constants so that the values of units can be determined by physical experiments instead of prototypes.

Please view the tutorial to see how natu is used. natu incorporates some of the best features of the existing packages and introduces some novel features:

  • All constants and units are defined in INI files. Units can be added or removed.
  • Units can with offsets (e.g., degree Celsius (degC)) and even nonlinear functions (e.g., decibel (dB)) are supported.
  • Display units can be simplified automatically using coherent relations gathered from the unit definitions.
  • All units can be imported directly (from natu.units import *), selectively imported (from natu.units import m, kg, s), or used from within a package (from natu import units as U; length = 10*U.m).
  • Prefixes are automatically applied to units upon import or access.
  • Units are automatically copied and sorted into convenient groups (see natu.groups).
  • Rationalized and unrationalized unit systems are supported.
  • Modules are provided as drop-in quantity-aware replacements for math and numpy.
  • There are no external dependencies. Only the Python Standard Library is required; numpy is optional.
  • Fractional exponents can be used for units as well as quantities (e.g., in the definition of the statcoulomb).

For the full documentation, please see the main website.

For a list of changes, please see the change log.

Installation

The easiest way to install natu is to use pip:

> pip install natu

On Linux, it may be necessary to have root privileges:

$ sudo pip install natu

Another way is to download and extract a copy of the package from the sidebar on the left. Run the following command from the base folder:

> python setup.py install

Or, on Linux:

$ sudo python setup.py install

License terms and development

natu is published under a BSD-compatible license. Please share any improvements you make, preferably as a pull request to the master branch of the GitHub repository. There are useful development scripts in the hooks folder. If you find a bug, have a suggestion, or just want to leave a comment, please open an issue.

See also

References

[Davies2012]K. Davies and C. Paredis, “Natural Unit Representation in Modelica,” in Modelica Conference (Munich, Germany), Modelica Assoc., Sep. 2012.
[BIPM2006]International Bureau of Weights and Measures (BIPM), “The International System of Units (SI),” 8th ed., 2006.
 
File Type Py Version Uploaded on Size
natu-0.1.0-a2.tar.gz (md5) Source 2014-08-08 157KB
  • Downloads (All Versions):
  • 2 downloads in the last day
  • 147 downloads in the last week
  • 601 downloads in the last month