Natural units in Python
Project description
Natural units in Python
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], [1].
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 units are defined in INI files. Units can be added or removed.
Units can involve offsets (e.g., degree Celsius (degC)) or even nonlinear functions (e.g., decibel (dB)).
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 or unrationalized unit systems can be represented.
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.
natu runs in Python 2 and 3.
Fractional exponents can be used for units as well as quantities (e.g., in the definition of the statcoulomb).
For the full documentation and more examples, 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 or have a suggestion, please open an issue.
See also
References
K. Davies and C. Paredis, “Natural Unit Representation in Modelica,” in Modelica Conference (Munich, Germany), Modelica Assoc., Sep. 2012.
International Bureau of Weights and Measures (BIPM), “The International System of Units (SI),” 8th ed., 2006.
Footnotes
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file natu-0.1.0-a1.tar.gz
.
File metadata
- Download URL: natu-0.1.0-a1.tar.gz
- Upload date:
- Size: 161.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6fcb936ec43d4bbc7c9f45d58b1ccbccd87a713e7403ed53a76ac811705f2283 |
|
MD5 | c057a2cdf9d54241e94c36f200df37f9 |
|
BLAKE2b-256 | b65dd3d04ceaee7529a757bd9e54b718b8e320a55ffbe960fd5cd7cfcc250390 |