Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgsavage committed Feb 2, 2024
1 parent 2dee199 commit c2ca8f8
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 32 deletions.
14 changes: 8 additions & 6 deletions docs/advanced/defining.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,19 @@ way is to create a new file (e.g. `mydef.txt`) with your definitions::

and then in Python, you can load it as:

>>> from pint import UnitRegistry
>>> import pint
>>> # First we create the registry.
>>> ureg = UnitRegistry()
>>> ureg = pint.UnitRegistry()
>>> # Set pint to use the new registry
>>> pint.set_application_registry(ureg)
>>> # Then we append the new definitions
>>> ureg.load_definitions('/your/path/to/my_def.txt') # doctest: +SKIP

If you make a translation of the default units or define a completely new set,
you don't want to append the translated definitions so you just give the
filename to the constructor::

>>> from pint import UnitRegistry
>>> ureg = UnitRegistry('/your/path/to/default_es.txt') # doctest: +SKIP
>>> ureg = pint.UnitRegistry('/your/path/to/default_es.txt') # doctest: +SKIP

In the definition file, prefixes are identified by a trailing dash::

Expand Down Expand Up @@ -100,10 +101,11 @@ Let's add a dog_year (sometimes written as dy) equivalent to 52 (human) days:

.. doctest::

>>> from pint import UnitRegistry
>>> import pint
>>> # We first instantiate the registry.
>>> # If we do not provide any parameter, the default unit definitions are used.
>>> ureg = UnitRegistry()
>>> ureg = pint.UnitRegistry()
>>> pint.set_application_registry(ureg)
>>> Q_ = ureg.Quantity

# Here we add the unit
Expand Down
5 changes: 3 additions & 2 deletions docs/advanced/measurement.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ quantity using the ``plus_minus()`` method.
:skipif: not_installed['uncertainties']

>>> import numpy as np
>>> from pint import UnitRegistry
>>> ureg = UnitRegistry()
>>> import pint
>>> ureg = pint.UnitRegistry()
>>> ureg = pint.get_application_registry()
>>> book_length = (20. * ureg.centimeter).plus_minus(2.)
>>> print(book_length)
(20.0 +/- 2.0) centimeter
Expand Down
4 changes: 2 additions & 2 deletions docs/advanced/performance.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ It's significantly faster to perform mathematical operations on magnitudes (even
.. ipython::
:verbatim:

In [1]: from pint import UnitRegistry
In [1]: import pint

In [2]: ureg = UnitRegistry()
In [2]: ureg = pint.get_application_registry()

In [3]: q1 = ureg('1m')

Expand Down
8 changes: 4 additions & 4 deletions docs/advanced/pitheorem.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ parameters.

.. testsetup:: *

from pint import UnitRegistry
ureg = UnitRegistry()
import pint
ureg = pint.UnitRegistry()
Q_ = ureg.Quantity

To start with a very simple case, consider that you want to find a dimensionless
Expand Down Expand Up @@ -41,8 +41,8 @@ you can use derived dimensions such as speed:

.. doctest::

>>> from pint import UnitRegistry
>>> ureg = UnitRegistry()
>>> import pint
>>> ureg = pint.UnitRegistry()
>>> ureg.pi_theorem({'V': '[speed]', 'T': '[time]', 'L': '[length]'})
[{'V': 1.0, 'T': 1.0, 'L': -1.0}]

Expand Down
4 changes: 2 additions & 2 deletions docs/advanced/wrapping.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ You could wrap this function to use Quantities instead:

.. doctest::

>>> from pint import UnitRegistry
>>> ureg = UnitRegistry()
>>> import pint
>>> ureg = pint.get_application_registry()
>>> Q_ = ureg.Quantity
>>> def mypp_caveman(length):
... return pendulum_period(length.to(ureg.meter).magnitude) * ureg.second
Expand Down
15 changes: 7 additions & 8 deletions docs/getting/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@ and perform unit conversions in Python.
Initializing a Registry
-----------------------

Before using Pint, initialize a :class:`UnitRegistry() <pint.registry.UnitRegistry>`
object. The ``UnitRegistry`` stores the unit definitions, their relationships,
and handles conversions between units.
Pint's ``UnitRegistry`` stores the unit definitions, their relationships,
and handles conversions between units. A ``UnitRegistry`` populated with the
`default list of units`_ and prefixes is initialized when you import Pint:

.. doctest::

>>> from pint import UnitRegistry
>>> ureg = UnitRegistry()
>>> import pint
>>> ureg = pint.get_application_registry()

If no parameters are given to the constructor, the ``UnitRegistry`` is populated
with the `default list of units`_ and prefixes.

Defining a Quantity
-------------------
Expand Down Expand Up @@ -434,7 +432,8 @@ You can also specify the format locale at the registry level either at creation:

.. doctest::

>>> ureg = UnitRegistry(fmt_locale='fr_FR')
>>> ureg = pint.UnitRegistry(fmt_locale='fr_FR')
>>> pint.set_application_registry(ureg)

or later:

Expand Down
4 changes: 2 additions & 2 deletions docs/user/angular_frequency.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ By default, pint treats angle quantities as `dimensionless`, so allows conversio

.. code-block:: python
>> from pint import UnitRegistry
>>> ureg = UnitRegistry()
>>> import pint
>>> ureg = pint.get_application_registry()
>>> angular_frequency = ureg('60rpm')
>>> angular_frequency.to('Hz')
<Quantity(6.28318531, 'hertz')>
Expand Down
4 changes: 2 additions & 2 deletions docs/user/defining-quantities.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ quantity by multiplying a ``Unit()`` and a scalar:

.. doctest::

>>> from pint import UnitRegistry
>>> ureg = UnitRegistry()
>>> import pint
>>> ureg = pint.UnitRegistry()
>>> ureg.meter
<Unit('meter')>
>>> 30.0 * ureg.meter
Expand Down
10 changes: 6 additions & 4 deletions docs/user/nonmult.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ For example, to convert from celsius to fahrenheit:

.. doctest::

>>> from pint import UnitRegistry
>>> ureg = UnitRegistry()
>>> import pint
>>> ureg = pint.get_application_registry()
>>> ureg.default_format = '.3f'
>>> Q_ = ureg.Quantity
>>> home = Q_(25.4, ureg.degC)
Expand Down Expand Up @@ -113,7 +113,8 @@ to be explicitly created:

.. doctest::

>>> ureg = UnitRegistry()
>>> ureg = pint.UnitRegistry()
>>> pint.set_application_registry(ureg)
>>> home = 25.4 * ureg.degC
Traceback (most recent call last):
...
Expand All @@ -130,7 +131,8 @@ to true. In this mode, pint behaves differently:

.. doctest::

>>> ureg = UnitRegistry(autoconvert_offset_to_baseunit = True)
>>> ureg = pint.UnitRegistry(autoconvert_offset_to_baseunit = True)
>>> pint.set_application_registry(ureg)
>>> T = 25.4 * ureg.degC
>>> T
<Quantity(25.4, 'degree_Celsius')>
Expand Down

0 comments on commit c2ca8f8

Please sign in to comment.