Skip to content

Commit

Permalink
Updated physical constants to CODATA 2018 values. Switched to MIT lic…
Browse files Browse the repository at this point in the history
…ense.
  • Loading branch information
Ken Kundert authored and Ken Kundert committed Jun 25, 2021
1 parent 21ac2c0 commit 5808d4e
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 723 deletions.
695 changes: 21 additions & 674 deletions LICENSE

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions doc/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Latest development release
| Version: 2.14.1
| Released: 2021-06-20
- updated predefined physical constants to CODATA 2018 values.
- switched to more permissive MIT license.
- add feet to the available length/distance unit conversions.


Expand Down
32 changes: 20 additions & 12 deletions quantiphy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# QuantiPhy -- Physical Quantities
# QuantiPhy Physical Quantities
# encoding: utf8

# Description {{{1
Expand All @@ -21,20 +21,26 @@
Documentation can be found at https://quantiphy.readthedocs.io.
"""

# License {{{1
# MIT License {{{1
# Copyright (C) 2016-2021 Kenneth S. Kundert
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# Imports {{{1
import re
Expand Down Expand Up @@ -3119,6 +3125,8 @@ def all_from_si_fmt(cls, text, **kwargs):

# Predefined Constants {{{1
# Plank's constant {{{2
# Where appropriate, these are the 2018 CODATA values from
# physics.nist.gov/constants.
add_constant(
Quantity(
'6.62607015e-34',
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
author_email = 'quantiphy@nurdletech.com',
url = 'https://quantiphy.readthedocs.io',
download_url = 'https://github.com/kenkundert/quantiphy/tarball/master',
license = 'GPLv3+',
license = 'MIT',
zip_safe = False,
py_modules = 'quantiphy'.split(),
install_requires = [],
Expand All @@ -30,7 +30,7 @@
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 3.6',
Expand Down
2 changes: 1 addition & 1 deletion tests/test_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
0C; 273.15 K; 273.15 K; 273.15 K; 273.15; 273.1500000000 K
eps0; 8.8542 pF/m; 0 F/m; 0.0000 F/m; 0.; 0.000000000009 F/m
mu0; 1.2566 uH/m; 0 H/m; 0.0000 H/m; 0.; 0.000001256637 H/m
Z0; 376.73 Ohms; 376.73 Ohms; 376.73 Ohms; 376.73; 376.7303134610 Ohms
Z0; 376.73 Ohms; 376.73 Ohms; 376.73 Ohms; 376.73; 376.7303136680 Ohms
1Zippy; 1 Zippy; 1 Zippy; 1.0000 Zippy; 1.; 1.000000000000 Zippy
""".strip()

Expand Down
84 changes: 50 additions & 34 deletions tests/test_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ def test_constants():
Quantity.reset_prefs()
Quantity.set_prefs(spacer=None, show_label=None, label_fmt=None, label_fmt_full=None)
Quantity.set_prefs(show_desc=True)
assert '{:.12q}'.format(Quantity('h')) == '662.607004e-36 J-s'
assert '{:.12q}'.format(Quantity('hbar')) == '105.45718e-36 J-s'
assert '{:.12q}'.format(Quantity('ħ')) == '105.45718e-36 J-s'
assert '{:.12q}'.format(Quantity('k')) == '13.8064852e-24 J/K'
assert '{:.12q}'.format(Quantity('q')) == '160.21766208e-21 C'
assert '{:.12q}'.format(Quantity('h')) == '662.607015e-36 J-s'
assert '{:.12q}'.format(Quantity('hbar')) == '105.4571817e-36 J-s'
assert '{:.12q}'.format(Quantity('ħ')) == '105.4571817e-36 J-s'
assert '{:.12q}'.format(Quantity('k')) == '13.80649e-24 J/K'
assert '{:.12q}'.format(Quantity('q')) == '160.2176634e-21 C'
assert '{:.12q}'.format(Quantity('c')) == '299.792458 Mm/s'
assert '{:.12q}'.format(Quantity('0C')) == '273.15 K'
assert '{:.12q}'.format(Quantity('eps0')) == '8.854187817 pF/m'
assert '{:.12q}'.format(Quantity('mu0')) == '1.256637061436 uH/m'
assert '{:.12q}'.format(Quantity('µ₀')) == '1.256637061436 uH/m' # uses micro
assert '{:.12q}'.format(Quantity('μ₀')) == '1.256637061436 uH/m' # uses mu
assert '{:.12q}'.format(Quantity('Z0')) == '376.730313461 Ohms'
assert '{:.12q}'.format(Quantity('ε₀')) == '8.8541878128 pF/m'
assert '{:.12q}'.format(Quantity('eps0')) == '8.8541878128 pF/m'
assert '{:.12q}'.format(Quantity('mu0')) == '1.25663706212 uH/m'
assert '{:.12q}'.format(Quantity('µ₀')) == '1.25663706212 uH/m' # uses micro
assert '{:.12q}'.format(Quantity('μ₀')) == '1.25663706212 uH/m' # uses mu
assert '{:.12q}'.format(Quantity('Z0')) == '376.730313668 Ohms'

assert str(Quantity('h')) == '662.61e-36 J-s'
assert str(Quantity('hbar')) == '105.46e-36 J-s'
Expand Down Expand Up @@ -51,12 +52,26 @@ def test_constants():
assert '{:S}'.format(Quantity('μ₀')) == 'µ₀ = 1.2566 uH/m -- permeability of free space' # uses mu
assert '{:S}'.format(Quantity('Z0')) == 'Z₀ = 376.73 Ohms -- characteristic impedance of free space'

assert Quantity('h').render(prec='full') == '662.607015e-36 J-s'
assert Quantity('hbar').render(prec='full') == '105.4571817e-36 J-s'
assert Quantity('ħ').render(prec='full') == '105.4571817e-36 J-s'
assert Quantity('k').render(prec='full') == '13.80649e-24 J/K'
assert Quantity('q').render(prec='full') == '160.2176634e-21 C'
assert Quantity('c').render(prec='full') == '299.792458 Mm/s'
assert Quantity('0C').render(prec='full') == '273.15 K'
assert Quantity('ε₀').render(prec='full') == '8.8541878128 pF/m'
assert Quantity('eps0').render(prec='full') == '8.8541878128 pF/m'
assert Quantity('mu0').render(prec='full') == '1.25663706212 uH/m'
assert Quantity('µ₀').render(prec='full') == '1.25663706212 uH/m' # uses micro
assert Quantity('μ₀').render(prec='full') == '1.25663706212 uH/m' # uses mu
assert Quantity('Z0').render(prec='full') == '376.730313668 Ohms'

set_unit_system('cgs')
assert '{:.12q}'.format(Quantity('h')) == '6.62607004e-27 erg-s'
assert '{:.12q}'.format(Quantity('hbar')) == '1.0545718e-27 erg-s'
assert '{:.12q}'.format(Quantity('ħ')) == '1.0545718e-27 erg-s'
assert '{:.12q}'.format(Quantity('k')) == '138.064852 aerg/K'
assert '{:.12q}'.format(Quantity('q')) == '480.320425 pFr'
assert '{:.12q}'.format(Quantity('h')) == '6.62607015e-27 erg-s'
assert '{:.12q}'.format(Quantity('hbar')) == '1.054571817e-27 erg-s'
assert '{:.12q}'.format(Quantity('ħ')) == '1.054571817e-27 erg-s'
assert '{:.12q}'.format(Quantity('k')) == '138.0649 aerg/K'
assert '{:.12q}'.format(Quantity('q')) == '480.320471257 pFr'
assert '{:.12q}'.format(Quantity('c')) == '299.792458 Mm/s'
assert '{:.12q}'.format(Quantity('0C')) == '273.15 K'

Expand Down Expand Up @@ -101,18 +116,19 @@ def test_constants():
assert '{:S}'.format(Quantity('0C')) == '0°C = 273.15 K -- zero degrees Celsius'

set_unit_system('mks')
assert '{:.12q}'.format(Quantity('h')) == '662.607004e-36 J-s'
assert '{:.12q}'.format(Quantity('hbar')) == '105.45718e-36 J-s'
assert '{:.12q}'.format(Quantity('ħ')) == '105.45718e-36 J-s'
assert '{:.12q}'.format(Quantity('k')) == '13.8064852e-24 J/K'
assert '{:.12q}'.format(Quantity('q')) == '160.21766208e-21 C'
assert '{:.12q}'.format(Quantity('c')) == '299.792458 Mm/s'
assert '{:.12q}'.format(Quantity('0C')) == '273.15 K'
assert '{:.12q}'.format(Quantity('eps0')) == '8.854187817 pF/m'
assert '{:.12q}'.format(Quantity('mu0')) == '1.256637061436 uH/m'
assert '{:.12q}'.format(Quantity('µ₀')) == '1.256637061436 uH/m' # uses micro
assert '{:.12q}'.format(Quantity('μ₀')) == '1.256637061436 uH/m' # uses mu
assert '{:.12q}'.format(Quantity('Z0')) == '376.730313461 Ohms'
assert Quantity('h').render(prec='full') == '662.607015e-36 J-s'
assert Quantity('hbar').render(prec='full') == '105.4571817e-36 J-s'
assert Quantity('ħ').render(prec='full') == '105.4571817e-36 J-s'
assert Quantity('k').render(prec='full') == '13.80649e-24 J/K'
assert Quantity('q').render(prec='full') == '160.2176634e-21 C'
assert Quantity('c').render(prec='full') == '299.792458 Mm/s'
assert Quantity('0C').render(prec='full') == '273.15 K'
assert Quantity('ε₀').render(prec='full') == '8.8541878128 pF/m'
assert Quantity('eps0').render(prec='full') == '8.8541878128 pF/m'
assert Quantity('mu0').render(prec='full') == '1.25663706212 uH/m'
assert Quantity('µ₀').render(prec='full') == '1.25663706212 uH/m' # uses micro
assert Quantity('μ₀').render(prec='full') == '1.25663706212 uH/m' # uses mu
assert Quantity('Z0').render(prec='full') == '376.730313668 Ohms'

assert str(Quantity('h')) == '662.61e-36 J-s'
assert str(Quantity('hbar')) == '105.46e-36 J-s'
Expand Down Expand Up @@ -145,17 +161,17 @@ def test_constants():

add_constant(Quantity('1420.405751786 MHz'), 'hline')
assert str(Quantity('hline')) == '1.4204 GHz'
add_constant(Quantity(4.80320427e-10, 'Fr'), 'q', 'esu gaussian')
add_constant(Quantity(1.602176487e-20, 'abC'), alias='q', unit_systems='emu')
assert str(Quantity('q')) == '160.22e-21 C'
add_constant(Quantity(4.80320471257e-10, 'Fr'), 'q', 'esu gaussian')
add_constant(Quantity(1.602176634e-20, 'abC'), alias='q', unit_systems='emu')
assert Quantity('q').render(prec='full') == '160.2176634e-21 C'
set_unit_system('cgs')
assert str(Quantity('q')) == '480.32 pFr'
assert Quantity('q').render(prec='full') == '480.320471257 pFr'
set_unit_system('esu')
assert str(Quantity('q')) == '480.32 pFr'
assert Quantity('q').render(prec='full') == '480.320471257 pFr'
set_unit_system('gaussian')
assert str(Quantity('q')) == '480.32 pFr'
assert Quantity('q').render(prec='full') == '480.320471257 pFr'
set_unit_system('emu')
assert str(Quantity('q')) == '16.022e-21 abC'
assert Quantity('q').render(prec='full') == '16.02176634e-21 abC'
set_unit_system('mks')

with pytest.raises(NameError) as exception:
Expand Down

0 comments on commit 5808d4e

Please sign in to comment.