hepunits

Units and constants in the HEP system of units

https://github.com/scikit-hep/hepunits

Science Score: 77.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 3 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
    3 of 5 committers (60.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.3%) to scientific vocabulary

Keywords

hep scikit-hep units

Keywords from Contributors

histogram mesh energy-system regionalization hydrology exoplanet spacy-extension yolov5s optimizer fitting
Last synced: 6 months ago · JSON representation ·

Repository

Units and constants in the HEP system of units

Basic Info
  • Host: GitHub
  • Owner: scikit-hep
  • License: bsd-3-clause
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 285 KB
Statistics
  • Stars: 28
  • Watchers: 4
  • Forks: 2
  • Open Issues: 2
  • Releases: 23
Topics
hep scikit-hep units
Created about 7 years ago · Last pushed 6 months ago
Metadata Files
Readme License Citation

README.rst

``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:: pycon

    >>> 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:: pycon

    >>> # 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:: pycon

    >>> 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.0 * 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=main
   :target: https://codecov.io/gh/scikit-hep/hepunits?branch=main

Owner

  • Name: Scikit-HEP Project
  • Login: scikit-hep
  • Kind: organization
  • Email: scikit-hep-forum@googlegroups.com

A community project for High Energy Physics data analysis in Python

Citation (CITATION.cff)

cff-version: 1.2.0
title: hepunits
message: >-
  If you use this software, please cite it using the
  metadata from this file.
type: software
abstract: "Hepunits is a Python library for units and constants in the HEP system of units."
authors:
  - family-names: Rodrigues
    given-names: Eduardo
    affiliation: University of Liverpool
    orcid: "https://orcid.org/0000-0003-2846-7625"
doi: 10.5281/zenodo.7244906
repository-code: "https://github.com/scikit-hep/hepunits"
keywords:
  - python
  - HEP units
  - scikit-hep
license: "BSD-3-Clause"

GitHub Events

Total
  • Create event: 44
  • Issues event: 2
  • Release event: 1
  • Watch event: 3
  • Delete event: 44
  • Issue comment event: 41
  • Push event: 47
  • Pull request review event: 39
  • Pull request event: 75
  • Fork event: 1
Last Year
  • Create event: 44
  • Issues event: 2
  • Release event: 1
  • Watch event: 3
  • Delete event: 44
  • Issue comment event: 41
  • Push event: 47
  • Pull request review event: 39
  • Pull request event: 75
  • Fork event: 1

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 268
  • Total Committers: 5
  • Avg Commits per committer: 53.6
  • Development Distribution Score (DDS): 0.384
Past Year
  • Commits: 58
  • Committers: 4
  • Avg Commits per committer: 14.5
  • Development Distribution Score (DDS): 0.172
Top Committers
Name Email Commits
pre-commit-ci[bot] 6****] 165
Eduardo Rodrigues e****s@c****h 43
Henry Schreiner h****r@c****h 41
dependabot[bot] 4****] 18
Jonas Eschle j****e@c****h 1
Committer Domains (Top 20 + Academic)
cern.ch: 3

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 5
  • Total pull requests: 296
  • Average time to close issues: about 1 month
  • Average time to close pull requests: about 17 hours
  • Total issue authors: 4
  • Total pull request authors: 4
  • Average comments per issue: 0.2
  • Average comments per pull request: 0.65
  • Merged pull requests: 279
  • Bot issues: 1
  • Bot pull requests: 246
Past Year
  • Issues: 2
  • Pull requests: 88
  • Average time to close issues: N/A
  • Average time to close pull requests: about 14 hours
  • Issue authors: 2
  • Pull request authors: 4
  • Average comments per issue: 0.0
  • Average comments per pull request: 0.92
  • Merged pull requests: 85
  • Bot issues: 0
  • Bot pull requests: 78
Top Authors
Issue Authors
  • eduardo-rodrigues (2)
  • nsmith- (1)
  • GeorgeAlex22 (1)
  • pre-commit-ci[bot] (1)
Pull Request Authors
  • pre-commit-ci[bot] (221)
  • dependabot[bot] (30)
  • henryiii (29)
  • eduardo-rodrigues (21)
Top Labels
Issue Labels
enhancement (1) good first issue (1) ci (1)
Pull Request Labels
ci (146) dependencies (32) docs (6) enhancement (5) github_actions (4)

Packages

  • Total packages: 3
  • Total downloads:
    • pypi 264,094 last-month
  • Total docker downloads: 324
  • Total dependent packages: 5
    (may contain duplicates)
  • Total dependent repositories: 20
    (may contain duplicates)
  • Total versions: 35
  • Total maintainers: 3
pypi.org: hepunits

Units and constants in the HEP system of units

  • Versions: 22
  • Dependent Packages: 2
  • Dependent Repositories: 16
  • Downloads: 264,094 Last month
  • Docker Downloads: 324
Rankings
Docker downloads count: 2.2%
Dependent packages count: 3.2%
Dependent repos count: 3.6%
Downloads: 4.0%
Average: 7.5%
Stargazers count: 12.7%
Forks count: 19.1%
Maintainers (2)
Last synced: 6 months ago
spack.io: py-hepunits

Units and constants in the HEP system of units.

  • Versions: 4
  • Dependent Packages: 1
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Average: 20.4%
Stargazers count: 24.4%
Dependent packages count: 28.1%
Forks count: 29.3%
Maintainers (1)
Last synced: 6 months ago
conda-forge.org: hepunits
  • Versions: 9
  • Dependent Packages: 2
  • Dependent Repositories: 4
Rankings
Dependent repos count: 16.2%
Dependent packages count: 19.6%
Average: 35.9%
Stargazers count: 48.4%
Forks count: 59.3%
Last synced: 6 months ago

Dependencies

.github/workflows/cd.yml actions
  • actions/checkout v3 composite
  • actions/download-artifact v3 composite
  • actions/upload-artifact v3 composite
  • pypa/gh-action-pypi-publish v1.6.4 composite
.github/workflows/main.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
  • codecov/codecov-action v3 composite
  • pre-commit/action v3.0.0 composite
pyproject.toml pypi