Skip to content

Commit

Permalink
PDG 2020 update to use exact definitions, more sub-units (#21)
Browse files Browse the repository at this point in the history
* Use exact constant definitions, taken from PDG 2020

* Add a series of sub-units

* Trivial test update

* README update
  • Loading branch information
eduardo-rodrigues authored Sep 30, 2020
1 parent d5c1041 commit 895c72c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ It is largely based on the international system of units (`SI`_)

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

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

Expand Down
13 changes: 8 additions & 5 deletions src/hepunits/constants/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,23 @@
# Physical constants
# -----------------------------------------------------------------------------

# Speed of light in vacuum
# Speed of light in vacuum (exact value, taken from PDG 2020)
c_light = 299792458 * m / s
c_light_sq = c_light * c_light

# Electron charge
eminus = -eplus # electron charge
e_sq = eplus * eplus

# Avogadro constant (taken from CODATA)
Avogadro = 6.022140857e23 / mole
# Avogadro constant (exact value, taken from PDG 2020)
Avogadro = 6.02214076e23 / mole

# Planck constant (exact value, taken from PDG 2020)
h_Planck = 6.62607015e-34 * joule * s

# Planck constant (taken from CODATA)
h_Planck = 6.626070040e-34 * joule * s
hbar_Planck = h_Planck / two_pi
hbar = hbar_Planck

hbarc = hbar_Planck * c_light

hbarc_sq = hbarc * hbarc
34 changes: 32 additions & 2 deletions src/hepunits/units/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,14 @@
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
Expand All @@ -155,6 +157,7 @@

s = second
ms = millisecond
us = microsecond
ps = picosecond
fs = femtosecond
# shortcut "as = attosecond" not possible since "as" is a reserved word ;-)
Expand Down Expand Up @@ -250,7 +253,8 @@
# --------------------------------------------------------------------

# Positron charge [Coulomb]
e_SI = 1.6021766208e-19 # taken from CODATA
e_SI = 1.602176634e-19 # exact value, taken from PDG 2020


# Electric charge [Q]
# --------------------------------------------------------------------
Expand All @@ -268,7 +272,7 @@

# Energy [E]
# ----------
joule = electronvolt / e_SI # joule = 6.24150 e+12 * MeV
joule = electronvolt / e_SI # joule = 6.24151e+12 * MeV

J = joule

Expand Down Expand Up @@ -350,17 +354,43 @@
# 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

Expand Down
2 changes: 1 addition & 1 deletion tests/constants/test_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

def test_constants():
assert pi_sq == two_pi * half_pi
assert Avogadro == 6.022140857e23
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
Expand Down

0 comments on commit 895c72c

Please sign in to comment.