=====
Units
=====

The :mod:`units` component allows units to be attached to numerical values, for
expressing experimental measurements.

This module depends on :mod:`helmholtz.core`.

The easiest way to get started is to run on the command line in your project
directory::

    $ python manage.py populate_units
    
We can now get a list of all the units in the database::

    >>> from helmholtz.units.models import Unit
    >>> Unit.objects.all()
    [<Unit: g>, <Unit: m>, <Unit: kg>, <Unit: s>, <Unit: A>, <Unit: K>,
     <Unit: mol>, <Unit: cd>, <Unit: m&sup2;>, <Unit: m&sup3;>, <Unit: 1/m>,
     <Unit: sr>, <Unit: kg/m>, <Unit: kg/m&sup2;>, <Unit: kg/m&sup3;>,
     <Unit: m&sup3;/kg>, <Unit: m/s>, <Unit: rad/s>, <Unit: m/s&sup2;>,
     <Unit: rad/s&sup2;>, '...(remaining elements truncated)...']
    
Unit objects allow various operations::

    >>> mV = Unit.objects.filter(symbol="mV")
    >>> mV.get_root()
    <Unit: V>
    >>> mV.name
    u'millivolt'
    >>> mV.unit_of()
    <Meaning: electric potential>
    >>> mV.convert_to_base_unit(-65)
    -0.065000000000000002

Reference
---------

.. automodule:: helmholtz.units.models

.. autoclass:: Unit

.. autoclass:: BaseUnit

.. autoclass:: DerivedUnit

.. automodule:: helmholtz.units.fields

.. autoclass:: PhysicalQuantityField

.. autoclass:: PhysicalQuantityFormField

.. autoclass:: PhysicalQuantityArrayField

.. autoclass:: ArrayOfPhysicalQuantityField