In this example we will use the scipy.constants.physical_constants
dictionary to determine which are the least-accurately known constants. To do this we need the relative uncertainties in the constants' values; the code below uses a structured array to calculate these and outputs the least well-determined constants.
import numpy as np
from scipy.constants import physical_constants
def make_record(k, v):
"""
Return the record for this constant from the key and value of its entry
in the physical_constants dictionary.
"""
name = k
val, units, abs_unc = v
# Calculate the relative uncertainty in ppm
rel_unc = abs_unc / abs(val) * 1.e6
return name, val, units, abs_unc, rel_unc
dtype = [('name', 'S50'), ('val', 'f8'), ('units', 'S20'),
('abs_unc', 'f8'), ('rel_unc', 'f8')]
constants = np.array([make_record(k, v) for k,v in physical_constants.items()],
dtype=dtype )
constants.sort(order='rel_unc')
# List the 10 constants with the largest relative uncertainties
for rec in constants[-10:]:
print('{:.0f} ppm: {:s} = {:g} {:s}'.format(rec['rel_unc'],
rec['name'].decode(), rec['val'], rec['units'].decode()))
The output is:
90 ppm: tau Compton wavelength over 2 pi = 1.11056e-16 m
90 ppm: tau mass energy equivalent in MeV = 1776.82 MeV
193 ppm: W to Z mass ratio = 0.88153
348 ppm: deuteron rms charge radius = 2.12799e-15 m
428 ppm: proton mag. shielding correction = 2.5689e-05
428 ppm: proton magn. shielding correction = 2.5689e-05
829 ppm: shielding difference of t and p in HT = 2.414e-08
990 ppm: shielding difference of d and p in HD = 2.02e-08
1346 ppm: weak mixing angle = 0.2229
2258 ppm: proton rms charge radius = 8.414e-16 m