hepunits


Namehepunits JSON
Version 2.3.3 PyPI version JSON
download
home_page
SummaryUnits and constants in the HEP system of units
upload_time2024-01-08 12:14:27
maintainer
docs_urlNone
author
requires_python>=3.7
license
keywords constants hep hep system of units units
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ``hepunits``: units and constants in the HEP system of units
============================================================

|Scikit-HEP| |PyPI version| |Conda-forge version| |Zenodo DOI|

|GitHub Actions Status: CI| |Code Coverage|


``hepunits`` collects the most commonly used units and constants in the
HEP System of Units, as derived from the basic units originally defined by the `CLHEP`_ project,
which are *not* the same as the SI system of units:

    ===================   ================== ====
    Quantity              Name               Unit
    ===================   ================== ====
    Length                millimeter         mm
    Time                  nanosecond         ns
    Energy                Mega electron Volt MeV
    Positron charge       eplus
    Temperature           kelvin             K
    Amount of substance   mole               mol
    Luminous intensity    candela            cd
    Plane angle           radian             rad
    Solid angle           steradian          sr
    ===================   ================== ====


It is largely based on the international system of units (`SI`_)

    ===================   ========   ====
    Quantity              Name       Unit
    ===================   ========   ====
    Length                meter      m
    Time                  second     s
    Mass                  kilogram   kg
    Electric current      ampere     A
    Temperature           kelvin     K
    Amount of substance   mole       mol
    Luminous intensity    candela    cd
    ===================   ========   ====

but augments it with handy definitions, changing the basic length and time units.

This HEP system of units is in use in many software libraries such as GEANT4 and Gaudi.

Note that many units are now *exact*, such as the speed of light in vacuum.
The package is in agreement with the values in the 2020 Particle Data Group review.

.. _CLHEP: http://proj-clhep.web.cern.ch/proj-clhep/
.. _SI: http://www.physics.nist.gov/cuu/Units/index.html


Installation
------------

Install ``hepunits`` like any other Python package, typically:

.. code-block:: bash

    python -m pip install hepunits

The package is also available on `conda-forge`_, and installable with

.. code-block:: bash

    conda install -c conda-forge hepunits

.. _conda-forge: https://github.com/conda-forge/hepunits-feedstock


Getting started
---------------

The package contains 2 modules, ``constants`` and ``units``,
whose names are self-explanatory.
It may be more readable to import quantities explicitly from each of the modules
though everything is available from the top-level as ``from hepunits import ...``.

The module ``hepunits.constants`` contains 2 sorts of constants:
physical constants and commonly used constants.

The typical usage is the following:

.. code-block:: python

    >>> from hepunits.constants import c_light
    >>> from hepunits.units     import picosecond, micrometer
    >>> tau_Bs = 1.5 * picosecond    # a particle lifetime, say the Bs meson's
    >>> ctau_Bs = c_light * tau_Bs   # ctau of the particle, ~450 microns
    >>> print ctau_Bs                # result in HEP units, so mm
    0.449688687
    >>> print ctau_Bs / micrometer   # result in micrometers
    449.688687

Typical usage of the ``hepunits.units`` module:

.. code-block:: python

    >>> # add two quantities with length units and get the result in meters
    >>> from hepunits import units as u
    >>> (1 * u.meter + 5 * u.cm) / u.meter
    1.05
    >>> # the default result is, of course, in HEP units, so mm
    >>> 1 * u.meter + 5 * u.cm
    1050.0

Fancier usage
~~~~~~~~~~~~~

When working with data the user should not need to know what units are used in their
internal representation (it makes sense, though, and *is important*, to be consistent throughout the "data storages"!).

These simple rules are enough - exemplified in the code below:

- Dimensioned quantities in the "data stores" abide to the HEP system of units.

- All definitions of dimensioned quantities are dimensioned by multiplying by the units,
  as in ``mass_window = 500 * keV``.

- All output of dimensioned quantities is converted to the required units
  by dividing by the units, as in ``energy_resolution() / GeV``.

For the sake of argument, let's consider below a function returning a dimensioned quantity.
the function below stores a dimensioned quantity defined in keV
(the actual value is represented in MeV, which is the standard unit) and the caller simply needs
to ensure an explicit conversion to the desired unit dividing by it (GeV in the example):

.. code-block:: python

    >>> from hepunits.units import keV, MeV, GeV
    >>> mass_window = 1 * GeV    # define a 1 GeV mass window
    >>> def energy_resolution():
    ...    # returns the energy resolution of 500 keV
    ...    return 500. * keV  # numerical value is 0.5
    ...
    >>> energy_resolution() / GeV # get the energy resolution in GeV
    0.0005



.. |Scikit-HEP| image:: https://scikit-hep.org/assets/images/Scikit--HEP-Project-blue.svg
   :target: https://scikit-hep.org

.. |PyPI version| image:: https://img.shields.io/pypi/v/hepunits.svg
   :target: https://pypi.org/project/hepunits/

.. |Conda-forge version| image:: https://img.shields.io/conda/vn/conda-forge/hepunits.svg
   :target: https://github.com/conda-forge/hepunits-feedstock

.. |Zenodo DOI| image:: https://zenodo.org/badge/DOI/10.5281/zenodo.7244906.svg
   :target: https://doi.org/10.5281/zenodo.7244906

.. |GitHub Actions Status: CI| image:: https://github.com/scikit-hep/hepunits/workflows/CI/badge.svg
   :target: https://github.com/scikit-hep/hepunits/actions

.. |Code Coverage| image:: https://codecov.io/gh/scikit-hep/hepunits/graph/badge.svg?branch=master
   :target: https://codecov.io/gh/scikit-hep/hepunits?branch=master

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "hepunits",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "Scikit-HEP <scikit-hep-admins@googlegroups.com>",
    "keywords": "Constants,HEP,HEP system of units,Units",
    "author": "",
    "author_email": "Eduardo Rodrigues <eduardo.rodrigues@cern.ch>",
    "download_url": "https://files.pythonhosted.org/packages/45/d8/f034a959103e65f9e37e0a83ed2a1283917aaaf14b1ae1c118508edab620/hepunits-2.3.3.tar.gz",
    "platform": null,
    "description": "``hepunits``: units and constants in the HEP system of units\n============================================================\n\n|Scikit-HEP| |PyPI version| |Conda-forge version| |Zenodo DOI|\n\n|GitHub Actions Status: CI| |Code Coverage|\n\n\n``hepunits`` collects the most commonly used units and constants in the\nHEP System of Units, as derived from the basic units originally defined by the `CLHEP`_ project,\nwhich are *not* the same as the SI system of units:\n\n    ===================   ================== ====\n    Quantity              Name               Unit\n    ===================   ================== ====\n    Length                millimeter         mm\n    Time                  nanosecond         ns\n    Energy                Mega electron Volt MeV\n    Positron charge       eplus\n    Temperature           kelvin             K\n    Amount of substance   mole               mol\n    Luminous intensity    candela            cd\n    Plane angle           radian             rad\n    Solid angle           steradian          sr\n    ===================   ================== ====\n\n\nIt is largely based on the international system of units (`SI`_)\n\n    ===================   ========   ====\n    Quantity              Name       Unit\n    ===================   ========   ====\n    Length                meter      m\n    Time                  second     s\n    Mass                  kilogram   kg\n    Electric current      ampere     A\n    Temperature           kelvin     K\n    Amount of substance   mole       mol\n    Luminous intensity    candela    cd\n    ===================   ========   ====\n\nbut augments it with handy definitions, changing the basic length and time units.\n\nThis HEP system of units is in use in many software libraries such as GEANT4 and Gaudi.\n\nNote that many units are now *exact*, such as the speed of light in vacuum.\nThe package is in agreement with the values in the 2020 Particle Data Group review.\n\n.. _CLHEP: http://proj-clhep.web.cern.ch/proj-clhep/\n.. _SI: http://www.physics.nist.gov/cuu/Units/index.html\n\n\nInstallation\n------------\n\nInstall ``hepunits`` like any other Python package, typically:\n\n.. code-block:: bash\n\n    python -m pip install hepunits\n\nThe package is also available on `conda-forge`_, and installable with\n\n.. code-block:: bash\n\n    conda install -c conda-forge hepunits\n\n.. _conda-forge: https://github.com/conda-forge/hepunits-feedstock\n\n\nGetting started\n---------------\n\nThe package contains 2 modules, ``constants`` and ``units``,\nwhose names are self-explanatory.\nIt may be more readable to import quantities explicitly from each of the modules\nthough everything is available from the top-level as ``from hepunits import ...``.\n\nThe module ``hepunits.constants`` contains 2 sorts of constants:\nphysical constants and commonly used constants.\n\nThe typical usage is the following:\n\n.. code-block:: python\n\n    >>> from hepunits.constants import c_light\n    >>> from hepunits.units     import picosecond, micrometer\n    >>> tau_Bs = 1.5 * picosecond    # a particle lifetime, say the Bs meson's\n    >>> ctau_Bs = c_light * tau_Bs   # ctau of the particle, ~450 microns\n    >>> print ctau_Bs                # result in HEP units, so mm\n    0.449688687\n    >>> print ctau_Bs / micrometer   # result in micrometers\n    449.688687\n\nTypical usage of the ``hepunits.units`` module:\n\n.. code-block:: python\n\n    >>> # add two quantities with length units and get the result in meters\n    >>> from hepunits import units as u\n    >>> (1 * u.meter + 5 * u.cm) / u.meter\n    1.05\n    >>> # the default result is, of course, in HEP units, so mm\n    >>> 1 * u.meter + 5 * u.cm\n    1050.0\n\nFancier usage\n~~~~~~~~~~~~~\n\nWhen working with data the user should not need to know what units are used in their\ninternal representation (it makes sense, though, and *is important*, to be consistent throughout the \"data storages\"!).\n\nThese simple rules are enough - exemplified in the code below:\n\n- Dimensioned quantities in the \"data stores\" abide to the HEP system of units.\n\n- All definitions of dimensioned quantities are dimensioned by multiplying by the units,\n  as in ``mass_window = 500 * keV``.\n\n- All output of dimensioned quantities is converted to the required units\n  by dividing by the units, as in ``energy_resolution() / GeV``.\n\nFor the sake of argument, let's consider below a function returning a dimensioned quantity.\nthe function below stores a dimensioned quantity defined in keV\n(the actual value is represented in MeV, which is the standard unit) and the caller simply needs\nto ensure an explicit conversion to the desired unit dividing by it (GeV in the example):\n\n.. code-block:: python\n\n    >>> from hepunits.units import keV, MeV, GeV\n    >>> mass_window = 1 * GeV    # define a 1 GeV mass window\n    >>> def energy_resolution():\n    ...    # returns the energy resolution of 500 keV\n    ...    return 500. * keV  # numerical value is 0.5\n    ...\n    >>> energy_resolution() / GeV # get the energy resolution in GeV\n    0.0005\n\n\n\n.. |Scikit-HEP| image:: https://scikit-hep.org/assets/images/Scikit--HEP-Project-blue.svg\n   :target: https://scikit-hep.org\n\n.. |PyPI version| image:: https://img.shields.io/pypi/v/hepunits.svg\n   :target: https://pypi.org/project/hepunits/\n\n.. |Conda-forge version| image:: https://img.shields.io/conda/vn/conda-forge/hepunits.svg\n   :target: https://github.com/conda-forge/hepunits-feedstock\n\n.. |Zenodo DOI| image:: https://zenodo.org/badge/DOI/10.5281/zenodo.7244906.svg\n   :target: https://doi.org/10.5281/zenodo.7244906\n\n.. |GitHub Actions Status: CI| image:: https://github.com/scikit-hep/hepunits/workflows/CI/badge.svg\n   :target: https://github.com/scikit-hep/hepunits/actions\n\n.. |Code Coverage| image:: https://codecov.io/gh/scikit-hep/hepunits/graph/badge.svg?branch=master\n   :target: https://codecov.io/gh/scikit-hep/hepunits?branch=master\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Units and constants in the HEP system of units",
    "version": "2.3.3",
    "project_urls": {
        "Homepage": "https://github.com/scikit-hep/hepunits"
    },
    "split_keywords": [
        "constants",
        "hep",
        "hep system of units",
        "units"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6cf2f1c70615308c08e07506d16f3976c57475c3555747482e2de81146eda2c7",
                "md5": "464321bc9a428733d40f724866170168",
                "sha256": "2edd3446bab7a853865e402eb14958ea6da6d728a7d9064cc3d8f3bb3a9a1281"
            },
            "downloads": -1,
            "filename": "hepunits-2.3.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "464321bc9a428733d40f724866170168",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 14398,
            "upload_time": "2024-01-08T12:14:25",
            "upload_time_iso_8601": "2024-01-08T12:14:25.303460Z",
            "url": "https://files.pythonhosted.org/packages/6c/f2/f1c70615308c08e07506d16f3976c57475c3555747482e2de81146eda2c7/hepunits-2.3.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "45d8f034a959103e65f9e37e0a83ed2a1283917aaaf14b1ae1c118508edab620",
                "md5": "3864b2f4cbae3eee35294c0f5bd62bcd",
                "sha256": "67d7cc77cd54d72b69c26a68e5efad7842b6f68fa8bc627bb90e41177abe6945"
            },
            "downloads": -1,
            "filename": "hepunits-2.3.3.tar.gz",
            "has_sig": false,
            "md5_digest": "3864b2f4cbae3eee35294c0f5bd62bcd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 13491,
            "upload_time": "2024-01-08T12:14:27",
            "upload_time_iso_8601": "2024-01-08T12:14:27.633766Z",
            "url": "https://files.pythonhosted.org/packages/45/d8/f034a959103e65f9e37e0a83ed2a1283917aaaf14b1ae1c118508edab620/hepunits-2.3.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-08 12:14:27",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "scikit-hep",
    "github_project": "hepunits",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "hepunits"
}
        
Elapsed time: 0.16008s