Skip to content

Commit

Permalink
Merge branch 'master' into 795_preserve_caches
Browse files Browse the repository at this point in the history
  • Loading branch information
crusaderky committed Dec 3, 2019
2 parents 1d60fbe + cf05eb8 commit ccfe418
Show file tree
Hide file tree
Showing 46 changed files with 2,046 additions and 886 deletions.
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ env:
- UNCERTAINTIES="N" PYTHON="3.5" NUMPY_VERSION=0 PANDAS=0
# Test with the latest numpy version
- UNCERTAINTIES="N" PYTHON="2.7" NUMPY_VERSION=1.14 PANDAS=0
- UNCERTAINTIES="N" PYTHON="3.4" NUMPY_VERSION=1.14 PANDAS=0
#- UNCERTAINTIES="N" PYTHON="3.4" NUMPY_VERSION=1.14 PANDAS=0
- UNCERTAINTIES="N" PYTHON="3.5" NUMPY_VERSION=1.14 PANDAS=0
- UNCERTAINTIES="Y" PYTHON="3.5" NUMPY_VERSION=1.14 PANDAS=0
- UNCERTAINTIES="N" PYTHON="3.6" NUMPY_VERSION=1.14 PANDAS=0
Expand All @@ -35,12 +35,16 @@ before_install:
- hash -r
- conda config --set always_yes yes --set changeps1 no
- conda update -q conda
- if [[ "$PYTHON" != "2.7" ]]; then
conda config --set restore_free_channel yes;
fi
# Useful for debugging any issues with conda
- conda info -a

# The next couple lines fix a crash with multiprocessing on Travis and are not specific to using Miniconda
- sudo rm -rf /dev/shm
- sudo ln -s /run/shm /dev/shm
# But broke travis 2019-08
# - sudo rm -rf /dev/shm
# - sudo ln -s /run/shm /dev/shm

- export ENV_NAME=travis

Expand Down
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Other contributors, listed alphabetically, are:
* Felix Hummel <[email protected]>
* Francisco Couzo <[email protected]>
* Giel van Schijndel <[email protected]>
* Ignacio Fdez. Galván <[email protected]>
* James Rowe <[email protected]>
* Jim Turner <[email protected]>
* Joel B. Mohler <[email protected]>
Expand Down
5 changes: 5 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ Documentation

Full documentation is available at https://pint.readthedocs.org/

GUI Website
-----------

This [website](www.dimensionalanalysis.org) wraps Pint's "dimensional analysis" methods to provide a GUI.


Design principles
-----------------
Expand Down
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ Documentation

Full documentation is available at https://pint.readthedocs.org/

GUI Website
-----------

This [website](www.dimensionalanalysis.org) wraps Pint's "dimensional analysis" methods to provide a GUI.


Design principles
-----------------
Expand Down
20 changes: 15 additions & 5 deletions docs/contexts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ If you work frequently on certain topics, you will probably find the need to
convert between dimensions based on some pre-established (physical)
relationships. For example, in spectroscopy you need to transform from
wavelength to frequency. These are incompatible units and therefore Pint will
raise an error if your do this directly:
raise an error if you do this directly:

.. doctest::

Expand All @@ -17,7 +17,7 @@ raise an error if your do this directly:
>>> q.to('Hz')
Traceback (most recent call last):
...
pint.errors.DimensionalityError: Cannot convert from 'nanometer' ([length]) to 'hertz' (1 / [time])
DimensionalityError: Cannot convert from 'nanometer' ([length]) to 'hertz' (1 / [time])


You probably want to use the relation `frequency = speed_of_light / wavelength`:
Expand Down Expand Up @@ -138,7 +138,8 @@ context and the parameters that you wish to set.
398.496240602


This decorator can be combined with **wraps** or **check** decorators described in `wrapping`_
This decorator can be combined with **wraps** or **check** decorators described in
:doc:`wrapping`.


Defining contexts in a file
Expand Down Expand Up @@ -188,7 +189,16 @@ functions. For example:
>>> ureg = pint.UnitRegistry()
>>> c = pint.Context('ab')
>>> c.add_transformation('[length]', '[time]',
... lambda ureg, x: ureg.speed_of_light / x)
... lambda ureg, x: x / ureg.speed_of_light)
>>> c.add_transformation('[time]', '[length]',
... lambda ureg, x: ureg.speed_of_light * x)
... lambda ureg, x: x * ureg.speed_of_light)
>>> ureg.add_context(c)
>>> ureg("1 s").to("km", "ab")
299792.458 kilometer

It is also possible to create anonymous contexts without invoking add_context:

>>> c = pint.Context()
...
>>> ureg("1 s").to("km", c)
299792.458 kilometer
47 changes: 41 additions & 6 deletions docs/defining.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@ other units. For example this is how the minute and the hour are defined in
minute = 60 * second = min

It is quite straightforward, isn't it? We are saying that `minute` is
`60 seconds` and is also known as `min`. The first word is always the canonical
name. Next comes the definition (based on other units). Finally, a list of
aliases, separated by equal signs.
`60 seconds` and is also known as `min`.

1. The first word is always the canonical name.
2. Next comes the definition (based on other units).
3. Next, optionally, there is the unit symbol.
4. Finally, again optionally, a list of aliases, separated by equal signs.
If one wants to specify aliases but not a symbol, the symbol should be
conventionally set to ``_``; e.g.::

millennium = 1e3 * year = _ = millennia

The order in which units are defined does not matter, Pint will resolve the
dependencies to define them in the right order. What is important is that if
Expand Down Expand Up @@ -68,12 +75,28 @@ unit, including non-metric ones (e.g. kiloinch is valid for Pint). This
simplifies definitions files enormously without introducing major problems.
Pint, like Python, believes that we are all consenting adults.

Derived dimensions are defined as follows::

[density] = [mass] / [volume]

Note that primary dimensions don't need to be declared; they can be
defined for the first time as part of a unit definition.

Finally, one may add aliases to an already existing unit definition::

@alias meter = metro = metr

This is particularly useful when one wants to enrich definitions from defaults_en.txt
with new aliases from a custom file. It can also be used for translations (like in the
example above) as long as one is happy to have the localized units automatically
converted to English when they are parsed.


Programmatically
----------------

You can easily add units to the registry programmatically. Let's add a dog_year
(sometimes written as dy) equivalent to 52 (human) days:
You can easily add units, dimensions, or aliases to the registry programmatically.
Let's add a dog_year (sometimes written as dy) equivalent to 52 (human) days:

.. doctest::

Expand All @@ -93,6 +116,8 @@ You can easily add units to the registry programmatically. Let's add a dog_year

Note that we have used the name `dog_years` even though we have not defined the
plural form as an alias. Pint takes care of that, so you don't have to.
Plural forms that aren't simply built by adding a 's' suffix to the singular form
should be explicitly stated as aliases (see for example ``millennia`` above).

You can also add prefixes programmatically:

Expand All @@ -102,4 +127,14 @@ You can also add prefixes programmatically:

where the number indicates the multiplication factor.

.. warning:: Units and prefixes added programmatically are forgotten when the program ends.
Same for aliases and derived dimensions:

.. doctest::

>>> ureg.define('@alias meter = metro = metr')
>>> ureg.define('[hypervolume] = [length ** 4]')


.. warning::
Units, prefixes, aliases and dimensions added programmatically are forgotten when the
program ends.
123 changes: 123 additions & 0 deletions docs/developers_reference.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
===================
Developer reference
===================

Pint
====

.. automodule:: pint
:members:

.. automodule:: pint.babel_names
:members:

.. automodule:: pint.context
:members:

.. automodule:: pint.converters
:members:

.. automodule:: pint.definitions
:members:

.. automodule:: pint.errors
:members:

.. automodule:: pint.formatting
:members:

.. automodule:: pint.matplotlib
:members:

.. automodule:: pint.measurement
:members:

.. automodule:: pint.pint_eval
:members:

.. automodule:: pint.quantity
:members:

.. automodule:: pint.registry
:members:

.. automodule:: pint.registry_helpers
:members:

.. automodule:: pint.systems
:members:

.. automodule:: pint.unit
:members:

.. automodule:: pint.util
:members:

.. automodule:: pint.compat.chainmap
:members:

.. automodule:: pint.compat.lrucache
:members:

.. automodule:: pint.compat.meta
:members:

.. automodule:: pint.compat.tokenize
:members:

.. automodule:: pint.testsuite.helpers
:members:

.. automodule:: pint.testsuite.parameterized
:members:

.. automodule:: pint.testsuite.test_babel
:members:

.. automodule:: pint.testsuite.test_contexts
:members:

.. automodule:: pint.testsuite.test_converters
:members:

.. automodule:: pint.testsuite.test_definitions
:members:

.. automodule:: pint.testsuite.test_errors
:members:

.. automodule:: pint.testsuite.test_formatter
:members:

.. automodule:: pint.testsuite.test_infer_base_unit
:members:

.. automodule:: pint.testsuite.test_issues
:members:

.. automodule:: pint.testsuite.test_measurement
:members:

.. automodule:: pint.testsuite.test_numpy
:members:

.. automodule:: pint.testsuite.test_pint_eval
:members:

.. automodule:: pint.testsuite.test_pitheorem
:members:

.. automodule:: pint.testsuite.test_quantity
:members:

.. automodule:: pint.testsuite.test_systems
:members:

.. automodule:: pint.testsuite.test_umath
:members:

.. automodule:: pint.testsuite.test_unit
:members:

.. automodule:: pint.testsuite.test_util
:members:
5 changes: 2 additions & 3 deletions docs/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ You mention other similar Python libraries. Can you point me to those?

`SymPy <https://docs.sympy.org/dev/modules/physics/units.html>`_

`Units <https://bitbucket.org/adonohue/units/>`_

`cf units <https://github.com/SciTools/cf_units>`_

`astropy units <https://github.com/astropy/astropy>`_

`yt <https://github.com/yt-project/yt>`_

`measurement <https://github.com/coddingtonbear/python-measurement>`_

If your are aware of another one, please contribute a patch to the docs.
If you're aware of another one, please contribute a patch to the docs.
3 changes: 2 additions & 1 deletion docs/getting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ That's all! You can check that Pint is correctly installed by starting up python
.. note:: If you have an old system installation of Python and you don't want to
mess with it, you can try `Anaconda CE`_. It is a free Python distribution by
Continuum Analytics that includes many scientific packages. To install pint
from the conda-forge channel instead of through pip use:
from the conda-forge channel instead of through pip use::

$ conda install -c conda-forge pint

You can check the installation with the following command:
Expand Down
3 changes: 2 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ More information
.. toctree::
:maxdepth: 1

developers_reference
contributing
faq

Expand All @@ -150,7 +151,7 @@ One last thing
The MCO MIB has determined that the root cause for the loss of the MCO spacecraft was the failure to use metric units in the coding of a ground software file, “Small Forces,” used in trajectory models. Specifically, thruster performance data in English units instead of metric units was used in the software application code titled SM_FORCES (small forces). The output from the SM_FORCES application code as required by a MSOP Project Software Interface Specification (SIS) was to be in metric units of Newtonseconds (N-s). Instead, the data was reported in English units of pound-seconds (lbf-s). The Angular Momentum Desaturation (AMD) file contained the output data from the SM_FORCES software. The SIS, which was not followed, defines both the format and units of the AMD file generated by ground-based computers. Subsequent processing of the data from AMD file by the navigation software algorithm therefore, underestimated the effect on the spacecraft trajectory by a factor of 4.45, which is the required conversion factor from force in pounds to Newtons. An erroneous trajectory was computed using this incorrect data.

`Mars Climate Orbiter Mishap Investigation Phase I Report`
`PDF <ftp:https://ftp.hq.nasa.gov/pub/pao/reports/1999/MCO_report.pdf>`_
`PDF <https:https://llis.nasa.gov/llis_lib/pdf/1009464main1_0641-mr.pdf>`_



Expand Down
6 changes: 3 additions & 3 deletions docs/nonmult.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ If you want to add a quantity with absolute unit to one with offset unit, like h
>>> Q_(10., ureg.degC) + heating_rate * Q_(30, ureg.min)
Traceback (most recent call last):
...
pint.errors.OffsetUnitCalculusError: Ambiguous operation with offset unit (degC, kelvin).
OffsetUnitCalculusError: Ambiguous operation with offset unit (degC, kelvin).

you have to avoid the ambiguity by either converting the offset unit to the
absolute unit before addition
Expand Down Expand Up @@ -123,7 +123,7 @@ to be explicitly created:
>>> home = 25.4 * ureg.degC
Traceback (most recent call last):
...
pint.errors.OffsetUnitCalculusError: Ambiguous operation with offset unit (degC).
OffsetUnitCalculusError: Ambiguous operation with offset unit (degC).
>>> Q_(25.4, ureg.degC)
<Quantity(25.4, 'degC')>

Expand Down Expand Up @@ -157,7 +157,7 @@ You can change the behaviour at any time:
>>> 1/T
Traceback (most recent call last):
...
pint.errors.OffsetUnitCalculusError: Ambiguous operation with offset unit (degC).
OffsetUnitCalculusError: Ambiguous operation with offset unit (degC).

The parser knows about *delta* units and uses them when a temperature unit
is found in a multiplicative context. For example, here:
Expand Down
Loading

0 comments on commit ccfe418

Please sign in to comment.