Skip to main content

Fast quantities

Project description

misu
====

`misu` is short for "misura",
which means **measurement** (in Italian).

Demo
----

Demo to go here.

Introduction
------------

`misu` is a package of handling physical quantities
with dimensions. This means performing calculations
with all the units being tracked correctly. It is
possible to add *kilograms per hour* to
*ounces per minute*, obtain the correct answer, and
have that answer be reported in, say, *pounds per
week*.

`misu` grew out of a personal need. I have used this code
personally in a (chemical) engineering context for
well over a year now (at time of writing, Feb 2015).
Every feature has been added in response to a personal need.

#### Features

- Written as a Cython extension module (for speed).
Speed benefits carry over when using
`misu` from your own Cython module (a `.pxd` is
provided for linking).
- Decorators for functions to enforce dimensions
```python
@dimensions(x=Length, y=Mass)
def f(x, y):
return x/y

f(2*m, 3*kg) # Works
f(200*feet, 3*tons) # Works

f(2*joules, 3*kelvin) # raises UnitsError
f(2*m, 3) # raises UnitsError
```
- An operator for easily stripping the units
component to obtain a plain numerical value
```python
mass = 100 * kg
mass_lb = mass >> lb

duty = 50 * MW
duty_BTU_hr = duty >> BTU / hr
```
- An enormous amount of redundancy in the naming
of various units. This means that `m`, `metre`,
`metres`, `METRE`, `METRES` will all work.
The reason for this is that
from my own experience, when working interactively
(e.g. in the IPython Notebook) it can be very
distracting to incorrectly guess the name for a
particular unit, and have to look it up. `ft`,
`foot` and `feet` all work, `m3` means `m**3` and
so on.
- You can specify a *reporting unit* for a dimension,
meaning that you could have all lengths be reported
in "feet" by default for example.
- You can specify a *reporting format* for a particular
unit.

#### There are other projects, why `misu`?

There are several units systems for Python, but the primary motivating use-case is that `misu` is
written as a Cython module and is by far the fastest*
for managing units available in Python.

\**Except for `NumericalUnits`, which is a special case*

\*\**I haven't actually checked that this statement is true for all of them yet.*

General usage
-------------

For speed-critical code, the application of unit operations can still be too slow.
In these situations it is typical to first cast quantities into numerical values
(doubles, say), perform the speed-critical calculations (perhaps call into a
C-library), and then re-cast the result back into a quantity and return that from
a function.
```python
@dimensions(x = Length, y = Mass):
def f(x, y):
x = x >> metre
y = y >> ounces
<code that assumes meters and ounces, returns value in BTU>
return answer * BTU

```
This way you can still easily wrap performance-critical calculations with
robust unit-handling.

#### Inspiration

The inspiration for `misu` was [Frink](http://futureboy.us/frinkdocs/)
by Alan Eliasen. It is *wonderful*, but I need to work
with units in the IPython Notebook, and with all my
other Python code.

There are a bunch of other similar projects. I have not used any
of them enough yet to provide a fair comparison:

- [astropy.units]("http://astropy.readthedocs.org/en/latest/units/")
- [Buckingham]("http://code.google.com/p/buckingham/")
- [DimPy]("http://www.inference.phy.cam.ac.uk/db410/")
- [Magnitude]("http://juanreyero.com/open/magnitude/")
- [NumericalUnits]("https://pypi.python.org/pypi/numericalunits")
- [Pint]("http://pint.readthedocs.org/")
- [Python-quantities]("https://pypi.python.org/pypi/quantities")
- [Scalar]("http://russp.us/scalar-guide.htm")
- [Scientific.Physics.PhysicalQuantities]("http://dirac.cnrs-orleans.fr/ScientificPython/ScientificPythonManual/Scientific.Physics.PhysicalQuantities-module.html")
- [SciMath]("http://scimath.readthedocs.org/en/latest/units/intro.html")
- [sympy.physics.units]("http://docs.sympy.org/dev/modules/physics/units.html")
- [udunitspy]("https://github.com/blazetopher/udunitspy")
- [Units]("https://bitbucket.org/adonohue/units/")
- [Unum]("https://bitbucket.org/kiv/unum/")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

misu-1.0.2.tar.gz (163.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

misu-1.0.2-cp34-none-win_amd64.whl (100.3 kB view details)

Uploaded CPython 3.4Windows x86-64

misu-1.0.2-cp34-cp34m-macosx_10_5_x86_64.whl (136.9 kB view details)

Uploaded CPython 3.4mmacOS 10.5+ x86-64

misu-1.0.2-cp27-none-win_amd64.whl (103.1 kB view details)

Uploaded CPython 2.7Windows x86-64

misu-1.0.2-cp27-none-macosx_10_5_x86_64.whl (137.8 kB view details)

Uploaded CPython 2.7macOS 10.5+ x86-64

File details

Details for the file misu-1.0.2.tar.gz.

File metadata

  • Download URL: misu-1.0.2.tar.gz
  • Upload date:
  • Size: 163.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for misu-1.0.2.tar.gz
Algorithm Hash digest
SHA256 2c93c297ad255957591b28f02275eee108753fdc538ad1319e4c9056d510c95f
MD5 363e4b3701e025f362f6369b61953b24
BLAKE2b-256 e092ca54a94fcdf9b808178e34e00c44ff77d6f4b2a11d3dde83d3ad9916863e

See more details on using hashes here.

File details

Details for the file misu-1.0.2-cp34-none-win_amd64.whl.

File metadata

File hashes

Hashes for misu-1.0.2-cp34-none-win_amd64.whl
Algorithm Hash digest
SHA256 79229d7496ecd7f3a906ddf7da6a1bd97cae14cd1ae9f4ad04e067025360bd1d
MD5 cb74f896e9168ff2dbf22269b1ccb925
BLAKE2b-256 0a2f4779283ee5050995453c85be806b8cd5b7e65339971445a7a4620fc00687

See more details on using hashes here.

File details

Details for the file misu-1.0.2-cp34-cp34m-macosx_10_5_x86_64.whl.

File metadata

File hashes

Hashes for misu-1.0.2-cp34-cp34m-macosx_10_5_x86_64.whl
Algorithm Hash digest
SHA256 9082eafc5638dc709325b71630d8065c999f4d21243cba79e36124592a89c4f5
MD5 04b292471e04b0b13685b8d0806f5351
BLAKE2b-256 5b25a716488cc8ba50b6e8f4c58fcedf710d0261125cbdb2abe403be8e5bee17

See more details on using hashes here.

File details

Details for the file misu-1.0.2-cp27-none-win_amd64.whl.

File metadata

File hashes

Hashes for misu-1.0.2-cp27-none-win_amd64.whl
Algorithm Hash digest
SHA256 da43db6279c8fa10183471d7fff408628acde177cce7e706eee01d90b30342e2
MD5 537649c340b1ea74208def1bd26e6d1f
BLAKE2b-256 76b41aea1a80504e9761a3973d263e2b11ff6fac3ab0e3c6921172f629190281

See more details on using hashes here.

File details

Details for the file misu-1.0.2-cp27-none-macosx_10_5_x86_64.whl.

File metadata

File hashes

Hashes for misu-1.0.2-cp27-none-macosx_10_5_x86_64.whl
Algorithm Hash digest
SHA256 d1b82c632f56f575257db0a245c45ac97017d265362d5bd02b91f45f47853c7f
MD5 e4c2a2acc546f1ca989c33f7493b85b7
BLAKE2b-256 0a9c132bea4712f4073f18b900bd82a35821055c9fe6025224ef481883fdc0c2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page