summaryrefslogtreecommitdiff
path: root/pint
diff options
context:
space:
mode:
authorHernan Grecco <hgrecco@gmail.com>2023-04-27 02:41:12 -0300
committerHernan Grecco <hgrecco@gmail.com>2023-04-27 02:41:12 -0300
commit32abc1ccdb9e5b20b5938dff69c6e6b2bf1727fd (patch)
treeab8c8c3623139aff0c9fe75d5d29d534e08f9ca8 /pint
parentf991a4b0346032c254aacfada3c2c4ef1670584d (diff)
downloadpint-32abc1ccdb9e5b20b5938dff69c6e6b2bf1727fd.tar.gz
Fixed pint-convert
Close #1646
Diffstat (limited to 'pint')
-rwxr-xr-xpint/pint_convert.py56
1 files changed, 40 insertions, 16 deletions
diff --git a/pint/pint_convert.py b/pint/pint_convert.py
index b30bb94..d8d60e8 100755
--- a/pint/pint_convert.py
+++ b/pint/pint_convert.py
@@ -69,6 +69,12 @@ ureg.autoconvert_offset_to_baseunit = True
ureg.enable_contexts("Gau", "ESU", "sp", "energy", "boltzmann")
ureg.default_system = args.system
+
+def _set(key: str, value):
+ obj = ureg._units[key].converter
+ object.__setattr__(obj, "scale", value)
+
+
if args.unc:
import uncertainties
@@ -106,28 +112,46 @@ if args.unc:
m_e = uncertainties.ufloat(*m_e)
m_p = uncertainties.ufloat(*m_p)
m_n = uncertainties.ufloat(*m_n)
- ureg._units["R_inf"].converter.scale = R_i
- ureg._units["g_e"].converter.scale = g_e
- ureg._units["m_u"].converter.scale = m_u
- ureg._units["m_e"].converter.scale = m_e
- ureg._units["m_p"].converter.scale = m_p
- ureg._units["m_n"].converter.scale = m_n
+
+ _set("R_inf", R_i)
+ _set("g_e", g_e)
+ _set("m_u", m_u)
+ _set("m_e", m_e)
+ _set("m_p", m_p)
+ _set("m_n", m_n)
# Measured constants with zero correlation
- ureg._units["gravitational_constant"].converter.scale = uncertainties.ufloat(
- ureg._units["gravitational_constant"].converter.scale, 0.00015e-11
+ _set(
+ "gravitational_constant",
+ uncertainties.ufloat(
+ ureg._units["gravitational_constant"].converter.scale, 0.00015e-11
+ ),
)
- ureg._units["d_220"].converter.scale = uncertainties.ufloat(
- ureg._units["d_220"].converter.scale, 0.000000032e-10
+
+ _set(
+ "d_220",
+ uncertainties.ufloat(ureg._units["d_220"].converter.scale, 0.000000032e-10),
)
- ureg._units["K_alpha_Cu_d_220"].converter.scale = uncertainties.ufloat(
- ureg._units["K_alpha_Cu_d_220"].converter.scale, 0.00000022
+
+ _set(
+ "K_alpha_Cu_d_220",
+ uncertainties.ufloat(
+ ureg._units["K_alpha_Cu_d_220"].converter.scale, 0.00000022
+ ),
)
- ureg._units["K_alpha_Mo_d_220"].converter.scale = uncertainties.ufloat(
- ureg._units["K_alpha_Mo_d_220"].converter.scale, 0.00000019
+
+ _set(
+ "K_alpha_Mo_d_220",
+ uncertainties.ufloat(
+ ureg._units["K_alpha_Mo_d_220"].converter.scale, 0.00000019
+ ),
)
- ureg._units["K_alpha_W_d_220"].converter.scale = uncertainties.ufloat(
- ureg._units["K_alpha_W_d_220"].converter.scale, 0.000000098
+
+ _set(
+ "K_alpha_W_d_220",
+ uncertainties.ufloat(
+ ureg._units["K_alpha_W_d_220"].converter.scale, 0.000000098
+ ),
)
ureg._root_units_cache = dict()