pax_global_header00006660000000000000000000000064150116000660014505gustar00rootroot0000000000000052 comment=190a2f4a23e87a50a9119a064061409877699c37 hepunits-2.3.6/000077500000000000000000000000001501160006600133545ustar00rootroot00000000000000hepunits-2.3.6/.github/000077500000000000000000000000001501160006600147145ustar00rootroot00000000000000hepunits-2.3.6/.github/dependabot.yml000066400000000000000000000003411501160006600175420ustar00rootroot00000000000000version: 2 updates: # Maintain dependencies for GitHub Actions - package-ecosystem: "github-actions" directory: "/" schedule: interval: "monthly" groups: actions: patterns: - "*" hepunits-2.3.6/.github/workflows/000077500000000000000000000000001501160006600167515ustar00rootroot00000000000000hepunits-2.3.6/.github/workflows/cd.yml000066400000000000000000000014571501160006600200710ustar00rootroot00000000000000name: CD on: workflow_dispatch: push: branches: - main release: types: - published jobs: dist: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Build wheel and SDist run: pipx run build - uses: actions/upload-artifact@v4 with: path: dist/* - name: Check metadata run: pipx run twine check dist/* publish: needs: [dist] runs-on: ubuntu-latest if: github.event_name == 'release' && github.event.action == 'published' environment: pypi permissions: id-token: write steps: - uses: actions/download-artifact@v4 with: name: artifact path: dist - uses: pypa/gh-action-pypi-publish@release/v1 hepunits-2.3.6/.github/workflows/main.yml000066400000000000000000000024151501160006600204220ustar00rootroot00000000000000name: CI on: pull_request: push: branches: [main] concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: pre-commit: name: Format runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: python-version: "3.x" - name: Check manifest uses: pre-commit/action@v3.0.1 checks: runs-on: ubuntu-latest strategy: fail-fast: false matrix: python-version: - "3.8" - "3.9" - "3.10" - "3.11" - "3.12" - "3.13" name: Check Python ${{ matrix.python-version }} steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} allow-prereleases: true - uses: astral-sh/setup-uv@v6 - name: Install package run: uv pip install --system -e .[test] - name: Test package run: python -m pytest --doctest-modules --cov=src/hepunits --cov-report=xml - name: Test coverage with Codecov uses: codecov/codecov-action@v5 env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} hepunits-2.3.6/.gitignore000066400000000000000000000013041501160006600153420ustar00rootroot00000000000000*.py[cod] # C extensions *.so # Packages *.egg *.egg-info dist build eggs .eggs parts bin var sdist wheelhouse develop-eggs .installed.cfg lib lib64 venv*/ pyvenv*/ # Installer logs pip-log.txt # Unit test / coverage reports .coverage .tox .coverage.* nosetests.xml coverage.xml htmlcov # Translations *.mo # Mr Developer .mr.developer.cfg .project .pydevproject .idea *.iml *.komodoproject .editorconfig # Complexity output/*.html output/*/index.html # Sphinx docs/_build .DS_Store *~ .*.sw[po] .build .ve .env .cache .pytest .bootstrap .appveyor.token *.bak .ipynb_checkpoints .pytest_cache /docs/html *.gv* /.mypy_cache/* /pip-wheel-metadata/* /src/hepunits/version.py /src/hepunits/_version.py hepunits-2.3.6/.pre-commit-config.yaml000066400000000000000000000027111501160006600176360ustar00rootroot00000000000000ci: autoupdate_commit_msg: "chore(deps): update pre-commit hooks" autofix_commit_msg: "style: pre-commit fixes" repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v5.0.0 hooks: - id: debug-statements - id: end-of-file-fixer - id: mixed-line-ending - id: requirements-txt-fixer - id: trailing-whitespace - id: check-added-large-files - id: check-case-conflict - id: check-merge-conflict - id: check-symlinks - id: check-yaml - repo: https://github.com/astral-sh/ruff-pre-commit rev: "v0.11.9" hooks: - id: ruff args: ["--fix", "--show-fixes"] - id: ruff-format - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.15.0 hooks: - id: mypy files: src args: [] - repo: https://github.com/codespell-project/codespell rev: v2.4.1 hooks: - id: codespell args: ["-L", "HEP"] - repo: https://github.com/rbubley/mirrors-prettier rev: "v3.5.3" hooks: - id: prettier types_or: [yaml, markdown, html, css, scss, javascript, json] - repo: https://github.com/adamchainz/blacken-docs rev: 1.19.1 hooks: - id: blacken-docs args: ["-E"] additional_dependencies: [black~=24.0] - repo: https://github.com/pre-commit/pygrep-hooks rev: v1.10.0 hooks: - id: rst-backticks - id: rst-directive-colons - id: rst-inline-touching-normal hepunits-2.3.6/CITATION.cff000066400000000000000000000010451501160006600152460ustar00rootroot00000000000000cff-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" hepunits-2.3.6/LICENSE000066400000000000000000000027631501160006600143710ustar00rootroot00000000000000BSD 3-Clause License Copyright (c) 2018-2025, Eduardo Rodrigues. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. hepunits-2.3.6/README.rst000066400000000000000000000132651501160006600150520ustar00rootroot00000000000000``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 hepunits-2.3.6/codecov.yml000066400000000000000000000000441501160006600155170ustar00rootroot00000000000000codecov: require_ci_to_pass: true hepunits-2.3.6/noxfile.py000066400000000000000000000007351501160006600153770ustar00rootroot00000000000000import nox nox.needs_version = ">=2024.4.15" nox.options.default_venv_backend = "uv|virtualenv" @nox.session def lint(session: nox.Session) -> None: """ Run the linter. """ session.install("pre-commit") session.run("pre-commit", "run", "--all-files", *session.posargs) @nox.session def tests(session: nox.Session) -> None: """ Run the unit and regular tests. """ session.install("-e.[test]") session.run("pytest", *session.posargs) hepunits-2.3.6/pyproject.toml000066400000000000000000000061201501160006600162670ustar00rootroot00000000000000[build-system] requires = ["hatchling", "hatch-vcs"] build-backend = "hatchling.build" [project] name = "hepunits" description = "Units and constants in the HEP system of units" readme = "README.rst" requires-python = ">=3.8" authors = [ { name = "Eduardo Rodrigues", email = "eduardo.rodrigues@cern.ch" }, ] maintainers = [ { name = "Scikit-HEP", email = "scikit-hep-admins@googlegroups.com" }, ] keywords = [ "Constants", "HEP", "HEP system of units", "Units", ] classifiers = [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Intended Audience :: Science/Research", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3 :: Only", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", "Topic :: Scientific/Engineering", ] dynamic = ["version"] [project.optional-dependencies] all = [ "pytest-cov>=2.8.0", "pytest>=6", ] dev = [ "pytest-cov>=2.8.0", "pytest>=6", ] test = [ "pytest-cov>=2.8.0", "pytest>=6", ] [project.urls] Homepage = "https://github.com/scikit-hep/hepunits" [tool.hatch] version.source = "vcs" build.hooks.vcs.version-file = "src/hepunits/_version.py" [tool.pytest.ini_options] minversion = "6.0" junit_family = "xunit2" testpaths = ["tests"] filterwarnings = [ "error", ] addopts = [ "-ra", "--showlocals", "--strict-markers", "--strict-config", ] xfail_strict = true log_cli_level = "DEBUG" [tool.check-manifest] ignore = [ "src/hepunits/_version.py", ".pre-commit-config.yaml", "noxfile.py", ] [tool.mypy] warn_unused_configs = true python_version = "3.8" files = ["src"] strict = true warn_unreachable = true enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] [tool.ruff.lint] extend-select = [ "B", # flake8-bugbear "I", # isort "ARG", # flake8-unused-arguments "C4", # flake8-comprehensions "EM", # flake8-errmsg "ICN", # flake8-import-conventions "ISC", # flake8-implicit-str-concat "PGH", # pygrep-hooks "PIE", # flake8-pie "PL", # pylint "PT", # flake8-pytest-style "PTH", # flake8-use-pathlib "RET", # flake8-return "RUF", # Ruff-specific "SIM", # flake8-simplify "T20", # flake8-print "UP", # pyupgrade "YTT", # flake8-2020 ] ignore = [ "ISC001", # Conflicts with formatter ] [tool.ruff.lint.per-file-ignores] "tests/*" = [ "F403", "F405", "PLR2004", # Magic value in comparisons "PT013", # Okay to import approx from pytest "T20", ] [tool.repo-review] ignore = [ "RTD", # ReadTheDocs "PY004", # Has docs folder ] hepunits-2.3.6/src/000077500000000000000000000000001501160006600141435ustar00rootroot00000000000000hepunits-2.3.6/src/hepunits/000077500000000000000000000000001501160006600160025ustar00rootroot00000000000000hepunits-2.3.6/src/hepunits/__init__.py000066400000000000000000000147361501160006600201260ustar00rootroot00000000000000# Licensed under a 3-clause BSD style license, see LICENSE. # Convenient access to the version number from typing import List from . import constants, units from ._version import version as __version__ from .constants.constants import ( Avogadro, c_light, c_light_sq, e_sq, eminus, h_Planck, half_pi, hbar, hbar_Planck, hbarc, hbarc_sq, k_Boltzmann, pi, pi_sq, two_pi, ) from .units.prefixes import ( atto, centi, deca, deci, exa, exbi, femto, gibi, giga, googol, hecto, kibi, kilo, mebi, mega, micro, milli, nano, pebi, peta, pico, tebi, tera, yobi, yocto, yotta, zebi, zepto, zetta, ) from .units.units import ( GW, MW, A, Bq, Ci, EeV, GBq, GeV, GHz, Gy, H, Hz, J, K, MBq, MeV, MGy, MHz, N, Pa, PeV, Sv, TeV, THz, W, Wb, ZeV, ab, ampere, angstrom, atmosphere, attobarn, attosecond, bar, barn, becquerel, candela, cd, centimeter, centimeter2, centimeter3, cm, cm2, cm3, coulomb, curie, d, day, deg, degree, dyne, e_SI, electronvolt, eplus, erg, eV, exaelectronvolt, farad, fb, femtobarn, femtometer, femtosecond, fermi, fm, fm2, fm3, fs, g, gauss, gigabecquerel, gigaelectronvolt, gigahertz, gram, gray, h, henry, hertz, hour, invab, invfb, invmb, invnb, invpb, invub, joule, kBq, kelvin, keV, kg, kGy, kHz, kilobecquerel, kiloelectronvolt, kilogauss, kilogram, kilogray, kilohertz, kilometer, kilometer2, kilometer3, kilovolt, km, km2, km3, kW, lumen, lux, m, m2, m3, mb, mCi, megabecquerel, megaelectronvolt, megagray, megahertz, megavolt, meter, meter2, meter3, mg, mGy, microampere, microbarn, microcurie, microfarad, microgray, micrometer, micron, microsecond, microweber, milliampere, millibarn, millicurie, millifarad, milligram, milligray, millimeter, millimeter2, millimeter3, milliradian, millisecond, milliweber, minute, mm, mm2, mm3, mol, mole, mrad, ms, mWb, nanoampere, nanobarn, nanocurie, nanofarad, nanometer, nanosecond, nanoweber, nb, nCi, newton, ns, nWb, ohm, pascal, pb, petaelectronvolt, picobarn, picofarad, picosecond, ps, rad, radian, s, second, sievert, sr, steradian, teraelectronvolt, terahertz, tesla, ub, uCi, uGy, us, uWb, volt, watt, weber, y, year, yoctosecond, ys, zeptosecond, zettaelectronvolt, zs, ) # Units and constants directly available __all__ = ( "GW", "MW", "A", "Avogadro", "Bq", "Ci", "EeV", "GBq", "GHz", "GeV", "Gy", "H", "Hz", "J", "K", "MBq", "MGy", "MHz", "MeV", "N", "Pa", "PeV", "Sv", "THz", "TeV", "W", "Wb", "ZeV", "__version__", "ab", "ampere", "angstrom", "atmosphere", "atto", "attobarn", "attosecond", "bar", "barn", "becquerel", "c_light", "c_light_sq", "candela", "cd", "centi", "centimeter", "centimeter2", "centimeter3", "cm", "cm2", "cm3", "constants", "coulomb", "curie", "d", "day", "deca", "deci", "deg", "degree", "dyne", "eV", "e_SI", "e_sq", "electronvolt", "eminus", "eplus", "eplus", "erg", "exa", "exaelectronvolt", "exbi", "farad", "fb", "femto", "femtobarn", "femtometer", "femtosecond", "fermi", "fm", "fm2", "fm3", "fs", "g", "gauss", "gibi", "giga", "gigabecquerel", "gigaelectronvolt", "gigahertz", "googol", "gram", "gray", "h", "h_Planck", "half_pi", "hbar", "hbar_Planck", "hbarc", "hbarc_sq", "hecto", "henry", "hertz", "hour", "invab", "invfb", "invmb", "invnb", "invpb", "invub", "joule", "joule", "kBq", "kGy", "kHz", "kW", "k_Boltzmann", "keV", "kelvin", "kelvin", "kg", "kibi", "kilo", "kilobecquerel", "kiloelectronvolt", "kilogauss", "kilogram", "kilogray", "kilohertz", "kilometer", "kilometer2", "kilometer3", "kilovolt", "km", "km2", "km3", "lumen", "lux", "m", "m", "m2", "m3", "mCi", "mGy", "mWb", "mb", "mebi", "mega", "megabecquerel", "megaelectronvolt", "megagray", "megahertz", "megavolt", "meter", "meter2", "meter3", "mg", "micro", "microampere", "microbarn", "microcurie", "microfarad", "microgray", "micrometer", "micron", "microsecond", "microweber", "milli", "milliampere", "millibarn", "millicurie", "millifarad", "milligram", "milligray", "millimeter", "millimeter2", "millimeter3", "milliradian", "millisecond", "milliweber", "minute", "mm", "mm2", "mm3", "mol", "mole", "mole", "mrad", "ms", "nCi", "nWb", "nano", "nanoampere", "nanobarn", "nanocurie", "nanofarad", "nanometer", "nanosecond", "nanoweber", "nb", "newton", "ns", "ohm", "pascal", "pb", "pebi", "peta", "petaelectronvolt", "pi", "pi_sq", "pico", "picobarn", "picofarad", "picosecond", "ps", "rad", "radian", "s", "s", "second", "sievert", "sr", "steradian", "tebi", "tera", "teraelectronvolt", "terahertz", "tesla", "two_pi", "uCi", "uGy", "uWb", "ub", "units", "us", "volt", "watt", "weber", "y", "year", "yobi", "yocto", "yoctosecond", "yotta", "ys", "zebi", "zepto", "zeptosecond", "zetta", "zettaelectronvolt", "zs", ) def __dir__() -> List[str]: return list(__all__) hepunits-2.3.6/src/hepunits/_version.pyi000066400000000000000000000001221501160006600203440ustar00rootroot00000000000000version: str version_tuple: tuple[int, int, int] | tuple[int, int, int, str, str] hepunits-2.3.6/src/hepunits/constants/000077500000000000000000000000001501160006600200165ustar00rootroot00000000000000hepunits-2.3.6/src/hepunits/constants/__init__.py000066400000000000000000000013761501160006600221360ustar00rootroot00000000000000# Licensed under a 3-clause BSD style license, see LICENSE. from typing import List from . import constants from .constants import ( Avogadro, c_light, c_light_sq, e_sq, eminus, eplus, h_Planck, half_pi, hbar, hbar_Planck, hbarc, hbarc_sq, joule, k_Boltzmann, kelvin, m, mole, pi, pi_sq, s, two_pi, ) __all__ = ( "Avogadro", "c_light", "c_light_sq", "constants", "e_sq", "eminus", "eplus", "h_Planck", "half_pi", "hbar", "hbar_Planck", "hbarc", "hbarc_sq", "joule", "k_Boltzmann", "kelvin", "m", "mole", "pi", "pi_sq", "s", "two_pi", ) def __dir__() -> List[str]: return list(__all__) hepunits-2.3.6/src/hepunits/constants/constants.py000066400000000000000000000046351501160006600224140ustar00rootroot00000000000000# Licensed under a 3-clause BSD style license, see LICENSE. """ Physical and other handy constants ================================== This module `hepunits.constants` contains 2 sorts of constants: * Physical constants. * Common and/or handy constants. All constants are computed in the HEP System of Units as defined in the `hepunits.units` module. Typical use case:: >>> 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 """ # ----------------------------------------------------------------------------- # Import statements # ----------------------------------------------------------------------------- from math import pi from typing import List from ..units.units import eplus, joule, kelvin, m, mole, s __all__ = ( "Avogadro", "c_light", "c_light_sq", "e_sq", "eminus", "eplus", "h_Planck", "half_pi", "hbar", "hbar_Planck", "hbarc", "hbarc_sq", "joule", "k_Boltzmann", "kelvin", "m", "mole", "pi", "pi_sq", "s", "two_pi", ) # ----------------------------------------------------------------------------- # Mathematical constants # ----------------------------------------------------------------------------- two_pi = 2 * pi half_pi = pi / 2 pi_sq = pi * pi # ----------------------------------------------------------------------------- # Physical constants # ----------------------------------------------------------------------------- # Speed of light in vacuum (exact value, taken from PDG 2022) c_light = 299792458 * m / s c_light_sq = c_light * c_light # Electron charge eminus = -eplus # electron charge e_sq = eplus * eplus # Avogadro constant (exact value, taken from PDG 2022) Avogadro = 6.02214076e23 / mole # Planck constant (exact value, taken from PDG 2022) h_Planck = 6.62607015e-34 * joule * s hbar_Planck = h_Planck / two_pi hbar = hbar_Planck hbarc = hbar_Planck * c_light hbarc_sq = hbarc * hbarc # Boltzmann constant (exact value, taken from PDG 2022) k_Boltzmann = 1.380649e-23 * joule / kelvin def __dir__() -> List[str]: return list(__all__) hepunits-2.3.6/src/hepunits/py.typed000066400000000000000000000000001501160006600174670ustar00rootroot00000000000000hepunits-2.3.6/src/hepunits/units/000077500000000000000000000000001501160006600171445ustar00rootroot00000000000000hepunits-2.3.6/src/hepunits/units/__init__.py000066400000000000000000000134621501160006600212630ustar00rootroot00000000000000# Licensed under a 3-clause BSD style license, see LICENSE. from typing import List from . import prefixes, units from .prefixes import ( atto, centi, deca, deci, exa, exbi, femto, gibi, giga, googol, hecto, kibi, kilo, mebi, mega, micro, milli, nano, pebi, peta, pico, tebi, tera, yobi, yocto, yotta, zebi, zepto, zetta, ) from .units import ( GW, MW, A, Bq, Ci, EeV, GBq, GeV, GHz, Gy, H, Hz, J, K, MBq, MeV, MGy, MHz, N, Pa, PeV, Sv, TeV, THz, W, Wb, ZeV, ab, ampere, angstrom, atmosphere, attobarn, attosecond, bar, barn, becquerel, candela, cd, centimeter, centimeter2, centimeter3, cm, cm2, cm3, coulomb, curie, d, day, deg, degree, dyne, e_SI, electronvolt, eplus, erg, eV, exaelectronvolt, farad, fb, femtobarn, femtometer, femtosecond, fermi, fm, fm2, fm3, fs, g, gauss, gigabecquerel, gigaelectronvolt, gigahertz, gram, gray, h, henry, hertz, hour, invab, invfb, invmb, invnb, invpb, invub, joule, kBq, kelvin, keV, kg, kGy, kHz, kilobecquerel, kiloelectronvolt, kilogauss, kilogram, kilogray, kilohertz, kilometer, kilometer2, kilometer3, kilovolt, km, km2, km3, kW, lumen, lux, m, m2, m3, mb, mCi, megabecquerel, megaelectronvolt, megagray, megahertz, megavolt, meter, meter2, meter3, mg, mGy, microampere, microbarn, microcurie, microfarad, microgray, micrometer, micron, microsecond, microweber, milliampere, millibarn, millicurie, millifarad, milligram, milligray, millimeter, millimeter2, millimeter3, milliradian, millisecond, milliweber, minute, mm, mm2, mm3, mol, mole, mrad, ms, mWb, nanoampere, nanobarn, nanocurie, nanofarad, nanometer, nanosecond, nanoweber, nb, nCi, newton, ns, nWb, ohm, pascal, pb, petaelectronvolt, picobarn, picofarad, picosecond, ps, rad, radian, s, second, sievert, sr, steradian, teraelectronvolt, terahertz, tesla, ub, uCi, uGy, us, uWb, volt, watt, weber, y, year, yoctosecond, ys, zeptosecond, zettaelectronvolt, zs, ) __all__ = ( "GW", "MW", "A", "Bq", "Ci", "EeV", "GBq", "GHz", "GeV", "Gy", "H", "Hz", "J", "K", "MBq", "MGy", "MHz", "MeV", "N", "Pa", "PeV", "Sv", "THz", "TeV", "W", "Wb", "ZeV", "ab", "ampere", "angstrom", "atmosphere", "atto", "attobarn", "attosecond", "bar", "barn", "becquerel", "candela", "cd", "centi", "centimeter", "centimeter2", "centimeter3", "cm", "cm2", "cm3", "coulomb", "curie", "d", "day", "deca", "deci", "deg", "degree", "dyne", "eV", "e_SI", "electronvolt", "eplus", "erg", "exa", "exaelectronvolt", "exbi", "farad", "fb", "femto", "femtobarn", "femtometer", "femtosecond", "fermi", "fm", "fm2", "fm3", "fs", "g", "gauss", "gibi", "giga", "gigabecquerel", "gigaelectronvolt", "gigahertz", "googol", "gram", "gray", "h", "hecto", "henry", "hertz", "hour", "invab", "invfb", "invmb", "invnb", "invpb", "invub", "joule", "kBq", "kGy", "kHz", "kW", "keV", "kelvin", "kg", "kibi", "kilo", "kilobecquerel", "kiloelectronvolt", "kilogauss", "kilogram", "kilogray", "kilohertz", "kilometer", "kilometer2", "kilometer3", "kilovolt", "km", "km2", "km3", "lumen", "lux", "m", "m2", "m3", "mCi", "mGy", "mWb", "mb", "mebi", "mega", "megabecquerel", "megaelectronvolt", "megagray", "megahertz", "megavolt", "meter", "meter2", "meter3", "mg", "micro", "microampere", "microbarn", "microcurie", "microfarad", "microgray", "micrometer", "micron", "microsecond", "microweber", "milli", "milliampere", "millibarn", "millicurie", "millifarad", "milligram", "milligray", "millimeter", "millimeter2", "millimeter3", "milliradian", "millisecond", "milliweber", "minute", "mm", "mm2", "mm3", "mol", "mole", "mrad", "ms", "nCi", "nWb", "nano", "nanoampere", "nanobarn", "nanocurie", "nanofarad", "nanometer", "nanosecond", "nanoweber", "nb", "newton", "ns", "ohm", "pascal", "pb", "pebi", "peta", "petaelectronvolt", "pico", "picobarn", "picofarad", "picosecond", "prefixes", "ps", "rad", "radian", "s", "second", "sievert", "sr", "steradian", "tebi", "tera", "teraelectronvolt", "terahertz", "tesla", "uCi", "uGy", "uWb", "ub", "units", "us", "volt", "watt", "weber", "y", "year", "yobi", "yocto", "yoctosecond", "yotta", "ys", "zebi", "zepto", "zeptosecond", "zetta", "zettaelectronvolt", "zs", ) def __dir__() -> List[str]: return list(__all__) hepunits-2.3.6/src/hepunits/units/prefixes.py000066400000000000000000000034321501160006600213450ustar00rootroot00000000000000# Licensed under a 3-clause BSD style license, see LICENSE. """ Common unit prefixes ==================== There are 2 types of prefixes: * SI prefixes [SI_prefixes]_. * Binary prefixes [Binary_prefixes]_. **References** .. [SI_prefixes] https://en.wikipedia.org/wiki/International_System_of_Units#Prefixes. .. [Binary_prefixes] https://en.wikipedia.org/wiki/Unit_prefix#Binary_prefixes. """ __all__ = ( "atto", "centi", "deca", "deci", "exa", "exbi", "femto", "gibi", "giga", "googol", "hecto", "kibi", "kilo", "mebi", "mega", "micro", "milli", "nano", "pebi", "peta", "pico", "tebi", "tera", "yobi", "yocto", "yotta", "zebi", "zepto", "zetta", ) # ----------------------------------------------------------------------------- # SI prefixes # ----------------------------------------------------------------------------- from typing import List yotta = 1.0e24 zetta = 1.0e21 exa = 1.0e18 peta = 1.0e15 tera = 1.0e12 giga = 1.0e9 mega = 1.0e6 kilo = 1.0e3 hecto = 1.0e2 deca = 1.0e1 deci = 1.0e-1 centi = 1.0e-2 milli = 1.0e-3 micro = 1.0e-6 nano = 1.0e-9 pico = 1.0e-12 femto = 1.0e-15 atto = 1.0e-18 zepto = 1.0e-21 yocto = 1.0e-24 # ----------------------------------------------------------------------------- # Binary prefixes # ----------------------------------------------------------------------------- kibi = 2.0**10 mebi = 2.0**20 gibi = 2.0**30 tebi = 2.0**40 pebi = 2.0**50 exbi = 2.0**60 zebi = 2.0**70 yobi = 2.0**80 # ----------------------------------------------------------------------------- # Miscellaneous prefixes # ----------------------------------------------------------------------------- googol = 1.0e100 def __dir__() -> List[str]: return list(__all__) hepunits-2.3.6/src/hepunits/units/units.py000066400000000000000000000302611501160006600206620ustar00rootroot00000000000000# Licensed under a 3-clause BSD style license, see LICENSE. """ Units in the HEP system of units ================================ This module `hepunits.units` contains 2 submodules for: * Basic physical units and derived units (`hepunits.units.units`). * Commonly-used unit prefixes (`hepunits.units.prefixes`). All units are provided in the HEP System of Units as defined below. In HEP the System of Units consists of the basic units originally defined by the [CLHEP]_ project: =================== ================== ==== 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. Typical use cases:: >>> # 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 >>> from hepunits.units import MeV, GeV >>> massWindow = 100 * MeV # define a 100 MeV mass window >>> def energy_resolution(): ... # returns the energy resolution of 100 MeV ... return 100 * MeV ... >>> energy_resolution() / GeV # get the energy resolution in GeV 0.1 **References** .. [CLHEP] http://proj-clhep.web.cern.ch/proj-clhep/. .. [SI] http://www.physics.nist.gov/cuu/Units/index.html. """ from math import pi as _pi from typing import List from . import prefixes as _pre # -------------------------------------------------------------------- # Units of length # --------------- millimeter = 1.0 millimeter2 = millimeter * millimeter millimeter3 = millimeter * millimeter * millimeter mm = millimeter mm2 = millimeter2 mm3 = millimeter3 meter = _pre.kilo * millimeter meter2 = meter * meter meter3 = meter * meter * meter m = meter m2 = meter2 m3 = meter3 centimeter = _pre.centi * meter centimeter2 = centimeter * centimeter centimeter3 = centimeter * centimeter * centimeter cm = centimeter cm2 = centimeter2 cm3 = centimeter3 kilometer = _pre.kilo * meter kilometer2 = kilometer * kilometer kilometer3 = kilometer * kilometer * kilometer km = kilometer km2 = kilometer2 km3 = kilometer3 micrometer = _pre.micro * meter micron = micrometer nanometer = _pre.nano * meter angstrom = 1e-10 * meter femtometer = _pre.femto * meter fermi = femtometer fm = femtometer fm2 = femtometer * femtometer fm3 = femtometer * femtometer * femtometer barn = 1.0e-28 * meter2 millibarn = _pre.milli * barn microbarn = _pre.micro * barn nanobarn = _pre.nano * barn picobarn = _pre.pico * barn femtobarn = _pre.femto * barn attobarn = _pre.atto * barn mb = millibarn ub = microbarn nb = nanobarn pb = picobarn fb = femtobarn ab = attobarn invmb = 1.0 / millibarn invub = 1.0 / microbarn invnb = 1.0 / nanobarn invpb = 1.0 / picobarn invfb = 1.0 / femtobarn invab = 1.0 / attobarn # -------------------------------------------------------------------- # Units of time # -------------------------------------------------------------------- nanosecond = 1.0 ns = nanosecond second = _pre.giga * nanosecond millisecond = _pre.milli * second microsecond = _pre.micro * second picosecond = _pre.pico * second femtosecond = _pre.femto * second attosecond = _pre.atto * second zeptosecond = _pre.zepto * second yoctosecond = _pre.yocto * second s = second ms = millisecond us = microsecond ps = picosecond fs = femtosecond # shortcut "as = attosecond" not possible since "as" is a reserved word ;-) zs = zeptosecond ys = yoctosecond minute = 60 * second hour = 60 * minute day = 24 * hour year = 365.25 * day h = hour d = day y = year hertz = 1.0 / second kilohertz = _pre.kilo * hertz megahertz = _pre.mega * hertz gigahertz = _pre.giga * hertz terahertz = _pre.tera * hertz Hz = hertz kHz = kilohertz MHz = megahertz GHz = gigahertz THz = terahertz # -------------------------------------------------------------------- # Units of energy # -------------------------------------------------------------------- megaelectronvolt = 1.0 electronvolt = _pre.micro * megaelectronvolt zettaelectronvolt = _pre.zetta * electronvolt exaelectronvolt = _pre.exa * electronvolt petaelectronvolt = _pre.peta * electronvolt teraelectronvolt = _pre.tera * electronvolt gigaelectronvolt = _pre.giga * electronvolt kiloelectronvolt = _pre.kilo * electronvolt ZeV = zettaelectronvolt EeV = exaelectronvolt PeV = petaelectronvolt TeV = teraelectronvolt GeV = gigaelectronvolt MeV = megaelectronvolt keV = kiloelectronvolt eV = electronvolt # -------------------------------------------------------------------- # Units of electric charge # -------------------------------------------------------------------- eplus = 1.0 # positron charge # -------------------------------------------------------------------- # Units of temperature # -------------------------------------------------------------------- kelvin = 1.0 K = kelvin # -------------------------------------------------------------------- # Units of amount of substance # -------------------------------------------------------------------- mole = 1.0 mol = mole # -------------------------------------------------------------------- # Units of luminous intensity # -------------------------------------------------------------------- candela = 1.0 cd = candela # -------------------------------------------------------------------- # Units of angles # -------------------------------------------------------------------- radian = 1.0 # plane angle steradian = 1.0 # solid angle rad = radian sr = steradian milliradian = _pre.milli * radian mrad = milliradian degree = (_pi / 180.0) * radian deg = degree # -------------------------------------------------------------------- # Derived units # -------------------------------------------------------------------- # Positron charge [Coulomb] e_SI = 1.602176634e-19 # exact value, taken from PDG 2022 # Electric charge [Q] # -------------------------------------------------------------------- coulomb = eplus / e_SI # Electric current [Q][T^-1] # ------------------------- ampere = coulomb / second milliampere = _pre.milli * ampere microampere = _pre.micro * ampere nanoampere = _pre.nano * ampere A = ampere # Energy [E] # ---------- joule = electronvolt / e_SI # joule = 6.24151e+12 * MeV J = joule erg = 1.0e-7 * joule # Power [M][L^2][T^-3] watt = joule / second W = watt kW = _pre.kilo * watt MW = _pre.mega * watt GW = _pre.giga * watt # Force [E][L^-1] newton = joule / meter N = newton dyne = 1.0e-5 * newton # Pressure pascal = newton / meter2 Pa = pascal bar = 1.0e5 * pascal atmosphere = 101325 * pascal # Mass [E][T^2][L^-2] kilogram = joule * second * second / (meter * meter) gram = _pre.milli * kilogram milligram = _pre.milli * gram kg = kilogram g = gram mg = milligram # Electric potential megavolt = megaelectronvolt / eplus volt = _pre.micro * megavolt kilovolt = _pre.kilo * volt # Electric capacitance farad = coulomb / volt millifarad = _pre.milli * farad microfarad = _pre.micro * farad nanofarad = _pre.nano * farad picofarad = _pre.pico * farad # Electric resistance ohm = volt / ampere # Magnetic Field tesla = volt * second / meter2 gauss = 1.0e-4 * tesla kilogauss = _pre.kilo * gauss # Magnetic Flux weber = volt * second # weber = 1000*megavolt*ns milliweber = _pre.milli * weber microweber = _pre.micro * weber nanoweber = _pre.nano * weber Wb = weber mWb = milliweber uWb = microweber nWb = nanoweber # Inductance henry = weber / ampere H = henry # -------------------------------------------------------------------- # Units derived from luminous intensity # -------------------------------------------------------------------- # Luminous flux [I] lumen = candela * steradian # Illuminance, i.e. amount of luminous flux per unit area [I][L^-2] lux = lumen / meter2 # -------------------------------------------------------------------- # Units for radiation # -------------------------------------------------------------------- # Activity [T^-1] becquerel = 1.0 / second kilobecquerel = _pre.kilo * becquerel megabecquerel = _pre.mega * becquerel gigabecquerel = _pre.giga * becquerel Bq = becquerel kBq = kilobecquerel MBq = megabecquerel GBq = gigabecquerel curie = 3.7e10 * becquerel millicurie = _pre.milli * curie microcurie = _pre.micro * curie nanocurie = _pre.nano * curie Ci = curie mCi = millicurie uCi = microcurie nCi = nanocurie # Absorbed dose [L^2][T^-2] gray = joule / kilogram megagray = _pre.mega * gray kilogray = _pre.kilo * gray milligray = _pre.milli * gray microgray = _pre.micro * gray Gy = gray MGy = megagray kGy = kilogray mGy = milligray uGy = microgray # Dose equivalent sievert = joule / kilogram Sv = sievert __all__ = ( "GW", "MW", "A", "Bq", "Ci", "EeV", "GBq", "GHz", "GeV", "Gy", "H", "Hz", "J", "K", "MBq", "MGy", "MHz", "MeV", "N", "Pa", "PeV", "Sv", "THz", "TeV", "W", "Wb", "ZeV", "ab", "ampere", "angstrom", "atmosphere", "attobarn", "attosecond", "bar", "barn", "becquerel", "candela", "cd", "centimeter", "centimeter2", "centimeter3", "cm", "cm2", "cm3", "coulomb", "curie", "d", "day", "deg", "degree", "dyne", "eV", "e_SI", "electronvolt", "eplus", "erg", "exaelectronvolt", "farad", "fb", "femtobarn", "femtometer", "femtosecond", "fermi", "fm", "fm2", "fm3", "fs", "g", "gauss", "gigabecquerel", "gigaelectronvolt", "gigahertz", "gram", "gray", "h", "henry", "hertz", "hour", "invab", "invfb", "invmb", "invnb", "invpb", "invub", "joule", "kBq", "kGy", "kHz", "kW", "keV", "kelvin", "kg", "kilobecquerel", "kiloelectronvolt", "kilogauss", "kilogram", "kilogray", "kilohertz", "kilometer", "kilometer2", "kilometer3", "kilovolt", "km", "km2", "km3", "lumen", "lux", "m", "m2", "m3", "mCi", "mGy", "mWb", "mb", "megabecquerel", "megaelectronvolt", "megagray", "megahertz", "megavolt", "meter", "meter2", "meter3", "mg", "microampere", "microbarn", "microcurie", "microfarad", "microgray", "micrometer", "micron", "microsecond", "microweber", "milliampere", "millibarn", "millicurie", "millifarad", "milligram", "milligray", "millimeter", "millimeter2", "millimeter3", "milliradian", "millisecond", "milliweber", "minute", "mm", "mm2", "mm3", "mol", "mole", "mrad", "ms", "nCi", "nWb", "nanoampere", "nanobarn", "nanocurie", "nanofarad", "nanometer", "nanosecond", "nanoweber", "nb", "newton", "ns", "ohm", "pascal", "pb", "petaelectronvolt", "picobarn", "picofarad", "picosecond", "ps", "rad", "radian", "s", "second", "sievert", "sr", "steradian", "teraelectronvolt", "terahertz", "tesla", "uCi", "uGy", "uWb", "ub", "us", "volt", "watt", "weber", "y", "year", "yoctosecond", "ys", "zeptosecond", "zettaelectronvolt", "zs", ) def __dir__() -> List[str]: return list(__all__) hepunits-2.3.6/tests/000077500000000000000000000000001501160006600145165ustar00rootroot00000000000000hepunits-2.3.6/tests/constants/000077500000000000000000000000001501160006600165325ustar00rootroot00000000000000hepunits-2.3.6/tests/constants/test_constants.py000066400000000000000000000011771501160006600221650ustar00rootroot00000000000000#!/usr/bin/env python # Licensed under a 3-clause BSD style license, see LICENSE. """ Tests for the hepunits.constants.constants module. """ from pytest import approx from hepunits import * from hepunits import THz, eV, nanometer, s def test_constants(): assert pi_sq == two_pi * half_pi assert Avogadro == 6.02214076e23 assert c_light / (m / s) == 299792458 assert hbarc_sq / c_light_sq == approx((h_Planck / two_pi) ** 2) assert hbar / (eV * s) == hbar / 1.0e3 # wavelength of 555-ish nanometres (green light) has a frequency of 540 THz assert c_light / (555.17121851852 * nanometer) == approx(540 * THz) hepunits-2.3.6/tests/test_missing_all.py000066400000000000000000000021671501160006600204360ustar00rootroot00000000000000import pytest import hepunits def filter_module(item: str) -> bool: if item == "__version__": return True if item.startswith("_"): return False return item not in {"List"} @pytest.mark.parametrize( "module", [ hepunits, hepunits.units, hepunits.constants, hepunits.constants.constants, hepunits.units.prefixes, hepunits.units.units, ], ) def test_missing_all(module): assert set(dir(module)) == set(module.__all__) full_module = {it for it in module.__dict__ if filter_module(it)} assert full_module == set(module.__all__) def test_exported(): expr = set(hepunits.units.__all__) - (set(hepunits.__all__) | {"prefixes"}) assert not expr expr = set(hepunits.constants.__all__) - set(hepunits.__all__) assert not expr expr = set(hepunits.constants.constants.__all__) - set(hepunits.constants.__all__) assert not expr expr = set(hepunits.units.prefixes.__all__) - set(hepunits.units.__all__) assert not expr expr = set(hepunits.units.units.__all__) - set(hepunits.units.__all__) assert not expr hepunits-2.3.6/tests/units/000077500000000000000000000000001501160006600156605ustar00rootroot00000000000000hepunits-2.3.6/tests/units/test_prefixes.py000066400000000000000000000007261501160006600211230ustar00rootroot00000000000000#!/usr/bin/env python # Licensed under a 3-clause BSD style license, see LICENSE. """ Tests for the hepunits.units.prefixes module. """ from math import log from pytest import approx from hepunits import kibi, mega, micro, tebi, yocto, yotta def test_prefixes_e6(): assert 4 * mega == 1.0 / 0.25 / micro def test_prefixes_e24(): assert yotta * yocto == approx(1.0) def test_prefixes_binary(): assert log(kibi, 2) == 10 assert log(tebi, 2) == 40 hepunits-2.3.6/tests/units/test_units.py000066400000000000000000000045031501160006600204350ustar00rootroot00000000000000#!/usr/bin/env python # Licensed under a 3-clause BSD style license, see LICENSE. """ Tests for the hepunits.units.units module. """ from pytest import approx from hepunits import * from hepunits import two_pi def test_length(): assert 3 * mm == approx(m * 0.003) assert 3 * mm == approx(cm * 0.3) assert 3 * mm == approx(km * 0.000003) assert 3 * mm == approx(micrometer * 3000) assert 3 * mm == approx(nanometer * 3000000) assert 3 * mm == approx(angstrom * 30000000) assert 3 * mm == approx(fermi * 3e12) def test_area(): assert (3 * mm) ** 2 == approx(9 * mm2) assert (3 * cm) ** 2 == approx(9 * cm2) assert (3 * km) ** 2 == approx(9 * km2) assert 2e-28 * meter2 == approx(2 * barn) def test_crosssection(): assert 3e-31 * barn == approx(9 * millibarn) assert 3e-34 * barn == approx(9 * microbarn) assert 3e-37 * barn == approx(9 * nanobarn) assert 3e-40 * barn == approx(9 * picobarn) assert 1 * barn == approx(100 * fm2) def test_luminosity(): assert invpb / invfb == approx(1.0e-3) def test_volume(): assert (3 * mm) ** 3 == approx(27 * mm3) assert (3 * cm) ** 3 == approx(27 * cm3) assert (3 * m) ** 3 == approx(27 * m3) def test_time(): assert 3 * ns == approx(3e-9 * s) assert 3 * ns == approx(3e-6 * ms) assert 3 * ns == approx(3e-3 * microsecond) assert 3 * ns == approx(3000 * picosecond) assert 3 * ns == approx(3000000 * femtosecond) assert day == 24 * 60 * minute def test_frequency(): assert second**-1 == approx(Hz) assert 1000 * hertz == approx(kHz) assert 1000000 * hertz == approx(MHz) assert 1000000000 * hertz == approx(GHz) def test_energy(): assert 1e3 * eV == approx(keV) assert 1e6 * eV == approx(MeV) assert 1e9 * eV == approx(GeV) assert 1e12 * eV == approx(TeV) assert 1e15 * eV == approx(PeV) assert 1e18 * eV == approx(EeV) def test_angle(): assert 360.0 * degree == two_pi * radian def test_magnetic_field(): assert 10 * gauss == approx(1 * milli * tesla) def test_electricity(): assert 1 * mega * joule / second == approx(1 * MW) def test_radiation_units(): assert gray == sievert # equal in terms of value assert 1 * curie == 37 * giga * becquerel def test_magnetic_flux(): assert weber == tesla * meter2 assert weber == ohm * coulomb