metrolopy 0.6.3__py3-none-any.whl → 0.6.4__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 CHANGED
@@ -1207,7 +1207,7 @@ class Budget(PrettyPrinter):
1207
1207
  if i == self.nx - 1 or i == self.nx+nt-1 or i == ndf-2:
1208
1208
  txt += r'\hline'
1209
1209
  txt += '\n'
1210
- txt += '\end{array}'
1210
+ txt += r'\end{array}'
1211
1211
  return txt
1212
1212
 
1213
1213
  def _tohtml(self):
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
@@ -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}\exp(-x/p_{2}) + p_{3}\exp(-x/p_{4}) + p_{5} $'
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}\exp(x/p_{2}) + p_{3} $'
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>'
@@ -1,7 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- from ..version import __version__
4
-
5
3
  from .test_create import *
6
4
  from .test_operations import *
7
5
  from .test_ubreakdown import *
@@ -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
- def test_immy_init(n=1000,prnt=False):
94
- for m in range(n):
95
- x,xr,xi = make_immy(prnt=prnt)
96
-
97
- if rand.randint(2):
98
- if rand.randint(2):
99
- x = type(x)(x)
100
- else:
101
- x = x.copy(formatting=False)
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
- y = x/1e12
116
- display(y)
117
-
118
- def _test_immy_bop(f,nf,n=1000,prnt=False,allow_small=True):
119
- m = 0
120
- while m < n:
121
- a,ar,ai = make_immy()
122
- if True:#rand.randint(2):
123
- b,br,bi = make_immy()
124
- else:
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
- b = -b
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
- bu = (0.1*rand.rand()+0.01)*(abs(b))
131
- b = ummy(b,u=bu)
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
- br = -br
136
- bi = 4*rand.rand() + 1
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
- bi = -bi
139
- b = complex(br,bi)
140
- if rand.randint(2):
141
- bb = b
142
- b = a
143
- a = bb
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
- if isinstance(a,(immy,ummy)):
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
- cx = f(ax,bx)
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
- if allow_small or abs(cx) > 0.1:
158
- m +=1
159
-
160
- c = f(a,b)
161
- cn = type(c).napply(nf,a,b)
162
-
163
- if prnt:
164
- display(a)
165
- display(b)
166
- display(c)
167
- display(cn)
168
- print('---')
169
-
170
- assert abs((c.real.x - cx.real)/cx.real) < 1e-10
171
- assert abs((c.imag.x - cx.imag)/cx.imag) < 1e-10
172
- assert_immy_close(c,cn)
173
-
174
- def test_immy_add(n=1000,prnt=False):
175
- _test_immy_bop(lambda a,b: a + b,np.add,n,prnt)
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
- assert_immy_close(i**-1,1/i)
220
- assert_immy_close(i**2,i*i)
221
- assert_immy_close(i**3,i*i*i)
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()