metrolopy 0.6.3__py3-none-any.whl → 0.6.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- metrolopy/budget.py +1 -1
- metrolopy/dfunc.py +4 -1
- metrolopy/distributions.py +1 -1
- metrolopy/fit.py +3 -3
- metrolopy/gummy.py +10 -9
- metrolopy/tests/__init__.py +0 -2
- metrolopy/tests/test_complex.py +137 -132
- metrolopy/tests/test_create.py +347 -343
- metrolopy/tests/test_gummy.py +639 -637
- metrolopy/tests/test_misc.py +94 -80
- metrolopy/tests/test_operations.py +337 -330
- metrolopy/tests/test_ubreakdown.py +335 -310
- metrolopy/unitparser.py +2 -2
- metrolopy/version.py +2 -2
- {metrolopy-0.6.3.dist-info → metrolopy-0.6.5.dist-info}/METADATA +102 -95
- {metrolopy-0.6.3.dist-info → metrolopy-0.6.5.dist-info}/RECORD +20 -20
- {metrolopy-0.6.3.dist-info → metrolopy-0.6.5.dist-info}/WHEEL +1 -1
- {metrolopy-0.6.3.dist-info → metrolopy-0.6.5.dist-info/licenses}/LICENSE +0 -0
- {metrolopy-0.6.3.dist-info → metrolopy-0.6.5.dist-info}/top_level.txt +0 -0
- {metrolopy-0.6.3.dist-info → metrolopy-0.6.5.dist-info}/zip-safe +0 -0
metrolopy/budget.py
CHANGED
metrolopy/dfunc.py
CHANGED
|
@@ -121,7 +121,6 @@ ddict = {np.sin: np.cos,
|
|
|
121
121
|
|
|
122
122
|
fdict = {np.angle: lambda x: x.angle(),
|
|
123
123
|
np.around: _f_around,
|
|
124
|
-
np.round_: _f_around,
|
|
125
124
|
np.heaviside: _f_heaviside,
|
|
126
125
|
np.absolute: lambda x: abs(x),
|
|
127
126
|
np.add: _f_add,
|
|
@@ -154,6 +153,10 @@ fdict = {np.angle: lambda x: x.angle(),
|
|
|
154
153
|
np.isneginf: lambda x: np.isneginf(x.x),
|
|
155
154
|
np.isposinf: lambda x: np.isposinf(x.x)
|
|
156
155
|
}
|
|
156
|
+
if np.lib.NumpyVersion(np.__version__) >= '1.25.0':
|
|
157
|
+
fdict[np.round] = _f_around
|
|
158
|
+
else:
|
|
159
|
+
fdict[np.round_] = _f_around
|
|
157
160
|
|
|
158
161
|
|
|
159
162
|
try_fconvert = True
|
metrolopy/distributions.py
CHANGED
|
@@ -920,7 +920,7 @@ class UniformDist(Distribution):
|
|
|
920
920
|
if lower_limit >= upper_limit:
|
|
921
921
|
raise ValueError('lower_limit >= upper_limit')
|
|
922
922
|
self.center = (upper_limit + lower_limit)/2
|
|
923
|
-
self.half_width = upper_limit - lower_limit
|
|
923
|
+
self.half_width = (upper_limit - lower_limit)/2
|
|
924
924
|
if upper_limit is not None:
|
|
925
925
|
k += 1
|
|
926
926
|
self.upper_limit = upper_limit
|
metrolopy/fit.py
CHANGED
|
@@ -415,7 +415,7 @@ class _Fit:
|
|
|
415
415
|
s = self.s
|
|
416
416
|
else:
|
|
417
417
|
s = self.sigma
|
|
418
|
-
return k*(np.sqrt(self.ypred(x).u + s**2))
|
|
418
|
+
return k*(np.sqrt(self.ypred(x).u**2 + s**2))
|
|
419
419
|
|
|
420
420
|
|
|
421
421
|
class Fit(_Fit,PrettyPrinter):
|
|
@@ -2017,7 +2017,7 @@ class DoubleExpFit(Fit):
|
|
|
2017
2017
|
return 'y = p(1)*exp(-x/p(2)) + p(3)*exp(-x/p(4)) + p(5)'
|
|
2018
2018
|
|
|
2019
2019
|
def flatex(self):
|
|
2020
|
-
return '$ y = p_{1}
|
|
2020
|
+
return '$ y = p_{1}\\exp(-x/p_{2}) + p_{3}\\exp(-x/p_{4}) + p_{5} $'
|
|
2021
2021
|
|
|
2022
2022
|
def fhtml(self):
|
|
2023
2023
|
return '<i>y</i> = <i>p</i><sub>1</sub> exp(-<i>x</i>/<i>p</i><sub>2</sub>) + <i>p</i><sub>3</sub> exp(-<i>x</i>/<i>p</i><sub>4</sub>) + <i>p</i><sub>5</sub>'
|
|
@@ -2160,7 +2160,7 @@ class ExpFit(Fit):
|
|
|
2160
2160
|
return 'y = p(1)*exp(x/p(2)) + p(3)'
|
|
2161
2161
|
|
|
2162
2162
|
def flatex(self):
|
|
2163
|
-
return '$ y = p_{1}
|
|
2163
|
+
return '$ y = p_{1}\\exp(x/p_{2}) + p_{3} $'
|
|
2164
2164
|
|
|
2165
2165
|
def fhtml(self):
|
|
2166
2166
|
return '<i>y</i> = <i>p</i><sub>1</sub> exp(<i>x</i>/<i>p</i><sub>2</sub>) + <i>p</i><sub>3</sub>'
|
metrolopy/gummy.py
CHANGED
|
@@ -1695,13 +1695,11 @@ class gummy(Quantity,metaclass=MetaGummy):
|
|
|
1695
1695
|
else:
|
|
1696
1696
|
slashaxis = gummy.slashaxis
|
|
1697
1697
|
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
else:
|
|
1704
|
-
name = g
|
|
1698
|
+
try:
|
|
1699
|
+
name = g.name
|
|
1700
|
+
except:
|
|
1701
|
+
name = None
|
|
1702
|
+
|
|
1705
1703
|
if name == '':
|
|
1706
1704
|
name = None
|
|
1707
1705
|
|
|
@@ -1721,7 +1719,10 @@ class gummy(Quantity,metaclass=MetaGummy):
|
|
|
1721
1719
|
name = str(name).replace(' ','\\,').strip()
|
|
1722
1720
|
xl += norm(name)
|
|
1723
1721
|
else:
|
|
1724
|
-
|
|
1722
|
+
try:
|
|
1723
|
+
xl += name.tolatex()
|
|
1724
|
+
except:
|
|
1725
|
+
xl += str(name).strip()
|
|
1725
1726
|
if symbol is not None:
|
|
1726
1727
|
if xl != '':
|
|
1727
1728
|
if slashaxis:
|
|
@@ -2861,7 +2862,7 @@ class gummy(Quantity,metaclass=MetaGummy):
|
|
|
2861
2862
|
return '{:.4f}'.format(x) + pct
|
|
2862
2863
|
if x < 99.9999:
|
|
2863
2864
|
return '{:.5f}'.format(x) + pct
|
|
2864
|
-
return str(x) +
|
|
2865
|
+
return str(x) + pct
|
|
2865
2866
|
|
|
2866
2867
|
@staticmethod
|
|
2867
2868
|
def _k_to_str(k):
|
metrolopy/tests/__init__.py
CHANGED
metrolopy/tests/test_complex.py
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
# MetroloPy. If not, see <http://www.gnu.org/licenses/>.
|
|
22
22
|
|
|
23
23
|
import numpy as np
|
|
24
|
+
import unittest
|
|
24
25
|
from metrolopy import immy,ummy,jummy,gummy
|
|
25
26
|
from metrolopy.tests.common import display
|
|
26
27
|
|
|
@@ -75,148 +76,152 @@ def make_immy(prnt=False):
|
|
|
75
76
|
|
|
76
77
|
return (ret,real,imag)
|
|
77
78
|
|
|
78
|
-
def assert_ummy_close(u1,u2):
|
|
79
|
-
assert abs(u1.correlation(u2)) > 1 - 1e-4
|
|
80
|
-
u1x = max(u1.x,u1.u,u2.x,u2.u)
|
|
81
|
-
assert abs((u1.x - u2.x)/(u1x)) < 1e-10
|
|
82
|
-
assert abs((u1.u - u2.u)/(u1.u)) < 1e-2
|
|
83
|
-
|
|
84
|
-
if u1.dof == float('inf'):
|
|
85
|
-
assert u2.dof == float('inf')
|
|
86
|
-
else:
|
|
87
|
-
assert abs((u2.dof - u1.dof)/u1.dof) < 1e-2
|
|
88
|
-
|
|
89
|
-
def assert_immy_close(i1,i2):
|
|
90
|
-
assert_ummy_close(i1.real,i2.real)
|
|
91
|
-
assert_ummy_close(i1.imag,i2.imag)
|
|
92
79
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
assert_ummy_close(x.real,xr)
|
|
104
|
-
assert_ummy_close(x.imag,xi)
|
|
105
|
-
assert_ummy_close(x.angle(),np.arctan2(xi,xr))
|
|
106
|
-
assert_ummy_close(abs(x),np.sqrt(xr**2 + xi**2))
|
|
107
|
-
assert_immy_close(x.conjugate(),immy(real=xr,imag=-xi))
|
|
108
|
-
assert_immy_close(-x,immy(real=-xr,imag=-xi))
|
|
109
|
-
assert_immy_close(+x,immy(real=xr,imag=xi))
|
|
110
|
-
|
|
111
|
-
if prnt:
|
|
112
|
-
if rand.randint(2):
|
|
113
|
-
y =1e12*x
|
|
80
|
+
class TestComplex(unittest.TestCase):
|
|
81
|
+
def assert_ummy_close(self,u1,u2):
|
|
82
|
+
self.assertTrue(abs(u1.correlation(u2)) > 1 - 1e-4)
|
|
83
|
+
u1x = max(u1.x,u1.u,u2.x,u2.u)
|
|
84
|
+
self.assertTrue(abs((u1.x - u2.x)/(u1x)) < 1e-10)
|
|
85
|
+
self.assertTrue(abs((u1.u - u2.u)/(u1.u)) < 1e-2)
|
|
86
|
+
|
|
87
|
+
if u1.dof == float('inf'):
|
|
88
|
+
self.assertTrue(u2.dof == float('inf'))
|
|
114
89
|
else:
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
90
|
+
self.assertTrue(abs((u2.dof - u1.dof)/u1.dof) < 1e-2)
|
|
91
|
+
|
|
92
|
+
def assert_immy_close(self,i1,i2):
|
|
93
|
+
self.assert_ummy_close(i1.real,i2.real)
|
|
94
|
+
self.assert_ummy_close(i1.imag,i2.imag)
|
|
95
|
+
|
|
96
|
+
def test_immy_init(self,n=1000,prnt=False):
|
|
97
|
+
for m in range(n):
|
|
98
|
+
x,xr,xi = make_immy(prnt=prnt)
|
|
99
|
+
|
|
125
100
|
if rand.randint(2):
|
|
126
|
-
b = 4*rand.rand() + 1
|
|
127
101
|
if rand.randint(2):
|
|
128
|
-
|
|
102
|
+
x = type(x)(x)
|
|
103
|
+
else:
|
|
104
|
+
x = x.copy(formatting=False)
|
|
105
|
+
|
|
106
|
+
self.assert_ummy_close(x.real,xr)
|
|
107
|
+
self.assert_ummy_close(x.imag,xi)
|
|
108
|
+
self.assert_ummy_close(x.angle(),np.arctan2(xi,xr))
|
|
109
|
+
self.assert_ummy_close(abs(x),np.sqrt(xr**2 + xi**2))
|
|
110
|
+
self.assert_immy_close(x.conjugate(),immy(real=xr,imag=-xi))
|
|
111
|
+
self.assert_immy_close(-x,immy(real=-xr,imag=-xi))
|
|
112
|
+
self.assert_immy_close(+x,immy(real=xr,imag=xi))
|
|
113
|
+
|
|
114
|
+
if prnt:
|
|
129
115
|
if rand.randint(2):
|
|
130
|
-
|
|
131
|
-
|
|
116
|
+
y =1e12*x
|
|
117
|
+
else:
|
|
118
|
+
y = x/1e12
|
|
119
|
+
display(y)
|
|
120
|
+
|
|
121
|
+
def _test_immy_bop(self,f,nf,n=1000,prnt=False,allow_small=True):
|
|
122
|
+
m = 0
|
|
123
|
+
while m < n:
|
|
124
|
+
a,ar,ai = make_immy()
|
|
125
|
+
if True:#rand.randint(2):
|
|
126
|
+
b,br,bi = make_immy()
|
|
132
127
|
else:
|
|
133
|
-
br = 4*rand.rand() + 1
|
|
134
128
|
if rand.randint(2):
|
|
135
|
-
|
|
136
|
-
|
|
129
|
+
b = 4*rand.rand() + 1
|
|
130
|
+
if rand.randint(2):
|
|
131
|
+
b = -b
|
|
132
|
+
if rand.randint(2):
|
|
133
|
+
bu = (0.1*rand.rand()+0.01)*(abs(b))
|
|
134
|
+
b = ummy(b,u=bu)
|
|
135
|
+
else:
|
|
136
|
+
br = 4*rand.rand() + 1
|
|
137
|
+
if rand.randint(2):
|
|
138
|
+
br = -br
|
|
139
|
+
bi = 4*rand.rand() + 1
|
|
140
|
+
if rand.randint(2):
|
|
141
|
+
bi = -bi
|
|
142
|
+
b = complex(br,bi)
|
|
137
143
|
if rand.randint(2):
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
+
bb = b
|
|
145
|
+
b = a
|
|
146
|
+
a = bb
|
|
147
|
+
|
|
148
|
+
if isinstance(a,(immy,ummy)):
|
|
149
|
+
ax = a.x
|
|
150
|
+
else:
|
|
151
|
+
ax = a
|
|
152
|
+
if isinstance(b,(immy,ummy)):
|
|
153
|
+
bx = b.x
|
|
154
|
+
else:
|
|
155
|
+
bx = b
|
|
156
|
+
|
|
144
157
|
|
|
145
|
-
|
|
146
|
-
ax = a.x
|
|
147
|
-
else:
|
|
148
|
-
ax = a
|
|
149
|
-
if isinstance(b,(immy,ummy)):
|
|
150
|
-
bx = b.x
|
|
151
|
-
else:
|
|
152
|
-
bx = b
|
|
153
|
-
|
|
158
|
+
cx = f(ax,bx)
|
|
154
159
|
|
|
155
|
-
|
|
160
|
+
if allow_small or abs(cx) > 0.1:
|
|
161
|
+
m +=1
|
|
162
|
+
|
|
163
|
+
c = f(a,b)
|
|
164
|
+
cn = type(c).napply(nf,a,b)
|
|
165
|
+
|
|
166
|
+
if prnt:
|
|
167
|
+
display(a)
|
|
168
|
+
display(b)
|
|
169
|
+
display(c)
|
|
170
|
+
display(cn)
|
|
171
|
+
print('---')
|
|
156
172
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
for m in range(10):
|
|
178
|
-
i = make_immy()[0]
|
|
179
|
-
assert i + 0 == i
|
|
180
|
-
assert 0 + i == i
|
|
181
|
-
|
|
182
|
-
def test_immy_sub(n=1000,prnt=False):
|
|
183
|
-
_test_immy_bop(lambda a,b: a - b,np.subtract,n,prnt)
|
|
184
|
-
|
|
185
|
-
for m in range(10):
|
|
186
|
-
i = make_immy()[0]
|
|
187
|
-
assert i - 0 == i
|
|
188
|
-
assert 0 - i == -i
|
|
189
|
-
|
|
190
|
-
def test_immy_mul(n=1000,prnt=False):
|
|
191
|
-
_test_immy_bop(lambda a,b: a*b,np.multiply,n,prnt)
|
|
192
|
-
|
|
193
|
-
for m in range(10):
|
|
194
|
-
i = make_immy()[0]
|
|
195
|
-
assert i*0 == 0
|
|
196
|
-
assert i*immy(0) == 0
|
|
197
|
-
assert i*1 == i
|
|
198
|
-
assert i*immy(1) == i
|
|
199
|
-
assert 1*i == i
|
|
200
|
-
assert immy(1)*i == i
|
|
201
|
-
|
|
202
|
-
def test_immy_div(n=1000,prnt=False):
|
|
203
|
-
_test_immy_bop(lambda a,b: a/b,np.divide,n,prnt,allow_small=False)
|
|
204
|
-
|
|
205
|
-
for m in range(10):
|
|
206
|
-
i = make_immy()[0]
|
|
207
|
-
assert i/1 == i
|
|
208
|
-
|
|
209
|
-
def test_immy_pow(n=1000,prnt=False):
|
|
210
|
-
#_test_immy_bop(lambda a,b: a**b,np.power,n,prnt,allow_small=False)
|
|
211
|
-
|
|
212
|
-
for m in range(10):
|
|
213
|
-
i = make_immy()[0]
|
|
214
|
-
assert 0**i == immy(0)
|
|
215
|
-
assert 0**i == ummy(0)
|
|
216
|
-
assert 0**i == 0
|
|
217
|
-
assert i**0 == 1
|
|
173
|
+
self.assertTrue(abs((c.real.x - cx.real)/cx.real) < 1e-10)
|
|
174
|
+
self.assertTrue(abs((c.imag.x - cx.imag)/cx.imag) < 1e-10)
|
|
175
|
+
self.assert_immy_close(c,cn)
|
|
176
|
+
|
|
177
|
+
def test_immy_add(self,n=1000,prnt=False):
|
|
178
|
+
self._test_immy_bop(lambda a,b: a + b,np.add,n,prnt)
|
|
179
|
+
|
|
180
|
+
for m in range(10):
|
|
181
|
+
i = make_immy()[0]
|
|
182
|
+
self.assertTrue(i + 0 == i)
|
|
183
|
+
self.assertTrue(0 + i == i)
|
|
184
|
+
|
|
185
|
+
def test_immy_sub(self,n=1000,prnt=False):
|
|
186
|
+
self._test_immy_bop(lambda a,b: a - b,np.subtract,n,prnt)
|
|
187
|
+
|
|
188
|
+
for m in range(10):
|
|
189
|
+
i = make_immy()[0]
|
|
190
|
+
self.assertTrue(i - 0 == i)
|
|
191
|
+
self.assertTrue(0 - i == -i)
|
|
218
192
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
193
|
+
def test_immy_mul(self,n=1000,prnt=False):
|
|
194
|
+
self._test_immy_bop(lambda a,b: a*b,np.multiply,n,prnt)
|
|
195
|
+
|
|
196
|
+
for m in range(10):
|
|
197
|
+
i = make_immy()[0]
|
|
198
|
+
self.assertTrue(i*0 == 0)
|
|
199
|
+
self.assertTrue(i*immy(0) == 0)
|
|
200
|
+
self.assertTrue(i*1 == i)
|
|
201
|
+
self.assertTrue(i*immy(1) == i)
|
|
202
|
+
self.assertTrue(1*i == i)
|
|
203
|
+
self.assertTrue(immy(1)*i == i)
|
|
204
|
+
|
|
205
|
+
def test_immy_div(self,n=1000,prnt=False):
|
|
206
|
+
self._test_immy_bop(lambda a,b: a/b,np.divide,n,prnt,allow_small=False)
|
|
207
|
+
|
|
208
|
+
for m in range(10):
|
|
209
|
+
i = make_immy()[0]
|
|
210
|
+
self.assertTrue(i/1 == i)
|
|
211
|
+
|
|
212
|
+
def test_immy_pow(self,n=1000,prnt=False):
|
|
213
|
+
#_test_immy_bop(lambda a,b: a**b,np.power,n,prnt,allow_small=False)
|
|
214
|
+
|
|
215
|
+
for m in range(10):
|
|
216
|
+
i = make_immy()[0]
|
|
217
|
+
self.assertTrue(0**i == immy(0))
|
|
218
|
+
self.assertTrue(0**i == ummy(0))
|
|
219
|
+
self.assertTrue(0**i == 0)
|
|
220
|
+
self.assertTrue(i**0 == 1)
|
|
221
|
+
|
|
222
|
+
self.assert_immy_close(i**-1,1/i)
|
|
223
|
+
self.assert_immy_close(i**2,i*i)
|
|
224
|
+
self.assert_immy_close(i**3,i*i*i)
|
|
222
225
|
|
|
226
|
+
if __name__ == '__main__':
|
|
227
|
+
unittest.main()
|