{"id":19098243,"url":"https://github.com/scikit-hep/hepunits","last_synced_at":"2025-04-07T18:13:58.963Z","repository":{"id":34072416,"uuid":"168227204","full_name":"scikit-hep/hepunits","owner":"scikit-hep","description":"Units and constants in the HEP system of units","archived":false,"fork":false,"pushed_at":"2025-03-25T07:38:00.000Z","size":275,"stargazers_count":27,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-25T12:52:03.926Z","etag":null,"topics":["hep","scikit-hep","units"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scikit-hep.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-29T20:55:46.000Z","updated_at":"2025-03-25T07:38:03.000Z","dependencies_parsed_at":"2023-10-01T22:12:46.584Z","dependency_job_id":"263d87e5-4eec-4c28-984d-174f7c43ff3b","html_url":"https://github.com/scikit-hep/hepunits","commit_stats":{"total_commits":144,"total_committers":8,"mean_commits":18.0,"dds":0.5277777777777778,"last_synced_commit":"888fe605352152c246c5b257d91d218824a884c3"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scikit-hep%2Fhepunits","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scikit-hep%2Fhepunits/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scikit-hep%2Fhepunits/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scikit-hep%2Fhepunits/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scikit-hep","download_url":"https://codeload.github.com/scikit-hep/hepunits/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247704571,"owners_count":20982298,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hep","scikit-hep","units"],"created_at":"2024-11-09T03:44:45.776Z","updated_at":"2025-04-07T18:13:58.946Z","avatar_url":"https://github.com/scikit-hep.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"``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:: pycon\n\n    \u003e\u003e\u003e from hepunits.constants import c_light\n    \u003e\u003e\u003e from hepunits.units import picosecond, micrometer\n    \u003e\u003e\u003e tau_Bs = 1.5 * picosecond  # a particle lifetime, say the Bs meson's\n    \u003e\u003e\u003e ctau_Bs = c_light * tau_Bs  # ctau of the particle, ~450 microns\n    \u003e\u003e\u003e print(ctau_Bs)  # result in HEP units, so mm\n    0.449688687\n    \u003e\u003e\u003e print(ctau_Bs / micrometer)  # result in micrometers\n    449.688687\n\nTypical usage of the ``hepunits.units`` module:\n\n.. code-block:: pycon\n\n    \u003e\u003e\u003e # add two quantities with length units and get the result in meters\n    \u003e\u003e\u003e from hepunits import units as u\n    \u003e\u003e\u003e (1 * u.meter + 5 * u.cm) / u.meter\n    1.05\n    \u003e\u003e\u003e # the default result is, of course, in HEP units, so mm\n    \u003e\u003e\u003e 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:: pycon\n\n    \u003e\u003e\u003e from hepunits.units import keV, MeV, GeV\n    \u003e\u003e\u003e mass_window = 1 * GeV  # define a 1 GeV mass window\n    \u003e\u003e\u003e def energy_resolution():\n    ...     # returns the energy resolution of 500 keV\n    ...     return 500.0 * keV  # numerical value is 0.5\n    ...\n    \u003e\u003e\u003e 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=main\n   :target: https://codecov.io/gh/scikit-hep/hepunits?branch=main\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscikit-hep%2Fhepunits","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscikit-hep%2Fhepunits","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscikit-hep%2Fhepunits/lists"}