metrolopy 0.6.2__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 +20 -20
- metrolopy/dfunc.py +4 -1
- metrolopy/distributions.py +3 -3
- metrolopy/fit.py +3 -3
- metrolopy/gummy.py +97 -31
- metrolopy/mean.py +12 -20
- metrolopy/nummy.py +32 -11
- metrolopy/tests/__init__.py +2 -3
- metrolopy/tests/test_complex.py +139 -128
- metrolopy/tests/test_create.py +350 -342
- metrolopy/tests/test_gummy.py +670 -0
- metrolopy/tests/test_misc.py +118 -50
- metrolopy/tests/test_operations.py +337 -330
- metrolopy/tests/test_ubreakdown.py +335 -310
- metrolopy/ummy.py +11 -7
- metrolopy/unitparser.py +2 -2
- metrolopy/version.py +2 -2
- {metrolopy-0.6.2.dist-info → metrolopy-0.6.4.dist-info}/METADATA +102 -94
- metrolopy-0.6.4.dist-info/RECORD +44 -0
- {metrolopy-0.6.2.dist-info → metrolopy-0.6.4.dist-info}/WHEEL +1 -1
- metrolopy-0.6.2.dist-info/RECORD +0 -43
- {metrolopy-0.6.2.dist-info → metrolopy-0.6.4.dist-info/licenses}/LICENSE +0 -0
- {metrolopy-0.6.2.dist-info → metrolopy-0.6.4.dist-info}/top_level.txt +0 -0
- {metrolopy-0.6.2.dist-info → metrolopy-0.6.4.dist-info}/zip-safe +0 -0
metrolopy/budget.py
CHANGED
|
@@ -250,7 +250,7 @@ class Budget(PrettyPrinter):
|
|
|
250
250
|
g.style = 'xf'
|
|
251
251
|
if nsig is not None:
|
|
252
252
|
g.nsig = nsig
|
|
253
|
-
return g.tostring(fmt)
|
|
253
|
+
return g.tostring(fmt,show_name=False)
|
|
254
254
|
|
|
255
255
|
units_on_values = None
|
|
256
256
|
show_s = True
|
|
@@ -828,9 +828,9 @@ class Budget(PrettyPrinter):
|
|
|
828
828
|
xst = 'xf'
|
|
829
829
|
|
|
830
830
|
fvalues = [g.x for g in self._dfx['x']]
|
|
831
|
-
values = [g.tostring(style=xst,solidus=self.solidus,mulsep=self.mulsep) for g in self._dfx['x']]
|
|
832
|
-
hvalues = [g.tostring(fmt='html',style=xst,solidus=self.solidus,mulsep=self.mulsep) for g in self._dfx['x']]
|
|
833
|
-
lvalues = [g.tostring(fmt='latex',style=xst,solidus=self.solidus,mulsep=self.mulsep) for g in self._dfx['x']]
|
|
831
|
+
values = [g.tostring(style=xst,solidus=self.solidus,mulsep=self.mulsep,show_name=False) for g in self._dfx['x']]
|
|
832
|
+
hvalues = [g.tostring(fmt='html',style=xst,solidus=self.solidus,mulsep=self.mulsep,show_name=False) for g in self._dfx['x']]
|
|
833
|
+
lvalues = [g.tostring(fmt='latex',style=xst,solidus=self.solidus,mulsep=self.mulsep,show_name=False) for g in self._dfx['x']]
|
|
834
834
|
|
|
835
835
|
if self.show_subtotals:
|
|
836
836
|
for t in self.type.values():
|
|
@@ -843,9 +843,9 @@ class Budget(PrettyPrinter):
|
|
|
843
843
|
fvalues.append(self._y.xsim)
|
|
844
844
|
else:
|
|
845
845
|
fvalues.append(self._y.x)
|
|
846
|
-
values.append(self._y.tostring(style=xst))
|
|
847
|
-
hvalues.append(self._y.tostring(fmt='html',style=xst))
|
|
848
|
-
lvalues.append(self._y.tostring(fmt='latex',style=xst))
|
|
846
|
+
values.append(self._y.tostring(style=xst,show_name=False))
|
|
847
|
+
hvalues.append(self._y.tostring(fmt='html',style=xst,show_name=False))
|
|
848
|
+
lvalues.append(self._y.tostring(fmt='latex',style=xst,show_name=False))
|
|
849
849
|
|
|
850
850
|
if show_exu:
|
|
851
851
|
fvalues.append(None)
|
|
@@ -877,30 +877,30 @@ class Budget(PrettyPrinter):
|
|
|
877
877
|
ust = 'uf'
|
|
878
878
|
|
|
879
879
|
fu = [g.u for g in self._dfx['x']]
|
|
880
|
-
u = [g.tostring(style=ust,solidus=self.solidus,mulsep=self.mulsep) for g in self._dfx['x']]
|
|
881
|
-
hu = [g.tostring(fmt='html',style=ust,solidus=self.solidus,mulsep=self.mulsep) for g in self._dfx['x']]
|
|
882
|
-
lu = [g.tostring(fmt='latex',style=ust,solidus=self.solidus,mulsep=self.mulsep) for g in self._dfx['x']]
|
|
880
|
+
u = [g.tostring(style=ust,solidus=self.solidus,mulsep=self.mulsep,show_name=False) for g in self._dfx['x']]
|
|
881
|
+
hu = [g.tostring(fmt='html',style=ust,solidus=self.solidus,mulsep=self.mulsep,show_name=False) for g in self._dfx['x']]
|
|
882
|
+
lu = [g.tostring(fmt='latex',style=ust,solidus=self.solidus,mulsep=self.mulsep,show_name=False) for g in self._dfx['x']]
|
|
883
883
|
|
|
884
884
|
if self.show_subtotals:
|
|
885
885
|
for t in self.type.values():
|
|
886
886
|
fu.append(t[2].U)
|
|
887
|
-
u.append(t[2].tostring(style=ust_g,solidus=self.solidus,mulsep=self.mulsep))
|
|
888
|
-
hu.append(t[2].tostring(fmt='html',style=ust_g,solidus=self.solidus,mulsep=self.mulsep))
|
|
889
|
-
lu.append(t[2].tostring(fmt='latex',style=ust_g,solidus=self.solidus,mulsep=self.mulsep))
|
|
887
|
+
u.append(t[2].tostring(style=ust_g,solidus=self.solidus,mulsep=self.mulsep,show_name=False))
|
|
888
|
+
hu.append(t[2].tostring(fmt='html',style=ust_g,solidus=self.solidus,mulsep=self.mulsep,show_name=False))
|
|
889
|
+
lu.append(t[2].tostring(fmt='latex',style=ust_g,solidus=self.solidus,mulsep=self.mulsep,show_name=False))
|
|
890
890
|
|
|
891
891
|
fu.append(self._yu.U)
|
|
892
|
-
u.append(self._yu.tostring(style=ust,solidus=self.solidus,mulsep=self.mulsep))
|
|
893
|
-
hu.append(self._yu.tostring(fmt='html',style=ust,solidus=self.solidus,mulsep=self.mulsep))
|
|
894
|
-
lu.append(self._yu.tostring(fmt='latex',style=ust,solidus=self.solidus,mulsep=self.mulsep))
|
|
892
|
+
u.append(self._yu.tostring(style=ust,solidus=self.solidus,mulsep=self.mulsep,show_name=False))
|
|
893
|
+
hu.append(self._yu.tostring(fmt='html',style=ust,solidus=self.solidus,mulsep=self.mulsep,show_name=False))
|
|
894
|
+
lu.append(self._yu.tostring(fmt='latex',style=ust,solidus=self.solidus,mulsep=self.mulsep,show_name=False))
|
|
895
895
|
if show_exu:
|
|
896
896
|
if self.sim:
|
|
897
897
|
g = gummy(self._y.x,self._y.ksim*self._y.usim,unit=self._y.unit)
|
|
898
898
|
else:
|
|
899
899
|
g = self._y
|
|
900
900
|
fu.append(g.U)
|
|
901
|
-
u.append(g.tostring(style=ust_g,solidus=self.solidus,mulsep=self.mulsep))
|
|
902
|
-
hu.append(g.tostring(fmt='html',style=ust_g,solidus=self.solidus,mulsep=self.mulsep))
|
|
903
|
-
lu.append(g.tostring(fmt='latex',style=ust_g,solidus=self.solidus,mulsep=self.mulsep))
|
|
901
|
+
u.append(g.tostring(style=ust_g,solidus=self.solidus,mulsep=self.mulsep,show_name=False))
|
|
902
|
+
hu.append(g.tostring(fmt='html',style=ust_g,solidus=self.solidus,mulsep=self.mulsep,show_name=False))
|
|
903
|
+
lu.append(g.tostring(fmt='latex',style=ust_g,solidus=self.solidus,mulsep=self.mulsep,show_name=False))
|
|
904
904
|
|
|
905
905
|
cnm = cnmh = self.column_names.get(c)
|
|
906
906
|
if cnm is None:
|
|
@@ -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
|
metrolopy/distributions.py
CHANGED
|
@@ -915,12 +915,12 @@ class UniformDist(Distribution):
|
|
|
915
915
|
self.lower_limit = self.center - half_width
|
|
916
916
|
if lower_limit is not None:
|
|
917
917
|
k += 1
|
|
918
|
-
self.lower_limit =
|
|
918
|
+
self.lower_limit = lower_limit
|
|
919
919
|
if upper_limit is not None:
|
|
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
|
|
@@ -1037,7 +1037,7 @@ class TriangularDist(Distribution):
|
|
|
1037
1037
|
return self.mode
|
|
1038
1038
|
|
|
1039
1039
|
def u(self):
|
|
1040
|
-
return np.sqrt((self.
|
|
1040
|
+
return np.sqrt((self.left_width**2+self.right_width**2+self.left_width*self.right_width)/18)
|
|
1041
1041
|
|
|
1042
1042
|
class ExponentialDist(Distribution):
|
|
1043
1043
|
def __init__(self,scale=None,rate=None):
|
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
|
@@ -36,11 +36,11 @@ from .nummy import nummy
|
|
|
36
36
|
from .exceptions import IncompatibleUnitsError,NoUnitConversionFoundError
|
|
37
37
|
from .unit import Unit,one,Quantity
|
|
38
38
|
from .distributions import Distribution,MultivariateDistribution
|
|
39
|
-
from .pmethod import _Pmthd
|
|
39
|
+
from .pmethod import _Pmthd,loc_from_k
|
|
40
40
|
from .printing import MetaPrettyPrinter
|
|
41
41
|
from math import isnan, isinf,log10
|
|
42
42
|
from fractions import Fraction
|
|
43
|
-
from numbers import Integral,Rational
|
|
43
|
+
from numbers import Integral,Rational,Real,Complex
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
try:
|
|
@@ -128,7 +128,7 @@ class MetaGummy(MetaPrettyPrinter):
|
|
|
128
128
|
uncertainty should be the standard deviation of this distribution which
|
|
129
129
|
is s*sqrt{(n-1)/[n*(n-3)]}. Thus
|
|
130
130
|
|
|
131
|
-
u(bayesian) = [dof/(dof - 2)]*u(traditional)
|
|
131
|
+
u(bayesian) = sqrt[dof/(dof - 2)]*u(traditional)
|
|
132
132
|
|
|
133
133
|
where dof = n - 1 and the "extra uncertainty" is incorporated directly
|
|
134
134
|
into the standard uncertainty.
|
|
@@ -504,6 +504,7 @@ class gummy(Quantity,metaclass=MetaGummy):
|
|
|
504
504
|
self._value._fp = self._get_p
|
|
505
505
|
self._unit = x._unit
|
|
506
506
|
self._U = self._value._u
|
|
507
|
+
self._value._name = x._value._name
|
|
507
508
|
self._k = 1
|
|
508
509
|
self._pm = None
|
|
509
510
|
self._set_k = True
|
|
@@ -526,21 +527,6 @@ class gummy(Quantity,metaclass=MetaGummy):
|
|
|
526
527
|
self._set_k = True
|
|
527
528
|
return
|
|
528
529
|
|
|
529
|
-
if isinstance(u,gummy):
|
|
530
|
-
uunit = u.unit
|
|
531
|
-
u = u.x
|
|
532
|
-
elif isinstance(u,Quantity):
|
|
533
|
-
uunit = u.unit
|
|
534
|
-
u = u.value
|
|
535
|
-
|
|
536
|
-
if uunit is not None:
|
|
537
|
-
if u != 0:
|
|
538
|
-
uunit = Unit.unit(uunit)
|
|
539
|
-
if uunit is unit:
|
|
540
|
-
uunit = None
|
|
541
|
-
else:
|
|
542
|
-
uunit = None
|
|
543
|
-
|
|
544
530
|
if p is not None:
|
|
545
531
|
p = float(p)
|
|
546
532
|
self._k = self._p_method.fptok(p,dof,gummy.bayesian)
|
|
@@ -560,9 +546,27 @@ class gummy(Quantity,metaclass=MetaGummy):
|
|
|
560
546
|
if uunit is None:
|
|
561
547
|
self._U = _ku(self._k,self._value.u)
|
|
562
548
|
else:
|
|
549
|
+
uunit = Unit.unit(uunit)
|
|
550
|
+
if uunit is unit:
|
|
551
|
+
uunit = None
|
|
563
552
|
self._U = None
|
|
564
553
|
self._set_U(self._k,uunit)
|
|
565
554
|
return
|
|
555
|
+
|
|
556
|
+
if isinstance(u,gummy):
|
|
557
|
+
uunit = u.unit
|
|
558
|
+
u = u.x
|
|
559
|
+
elif isinstance(u,Quantity):
|
|
560
|
+
uunit = u.unit
|
|
561
|
+
u = u.value
|
|
562
|
+
|
|
563
|
+
if uunit is not None:
|
|
564
|
+
if u != 0:
|
|
565
|
+
uunit = Unit.unit(uunit)
|
|
566
|
+
if uunit is unit:
|
|
567
|
+
uunit = None
|
|
568
|
+
else:
|
|
569
|
+
uunit = None
|
|
566
570
|
|
|
567
571
|
if uunit is not None and u != 0:
|
|
568
572
|
U = Quantity(u,unit=uunit)
|
|
@@ -773,8 +777,9 @@ class gummy(Quantity,metaclass=MetaGummy):
|
|
|
773
777
|
else:
|
|
774
778
|
unit = self._U.unit
|
|
775
779
|
x = float(self.unit.convert(self.xsim,unit))
|
|
776
|
-
|
|
777
|
-
|
|
780
|
+
ci1 = float(self.unit.convert(self.cisim[1],unit))
|
|
781
|
+
ci0 = float(self.unit.convert(self.cisim[0],unit))
|
|
782
|
+
return (ci1 - x, x - ci0)
|
|
778
783
|
|
|
779
784
|
|
|
780
785
|
@property
|
|
@@ -884,19 +889,24 @@ class gummy(Quantity,metaclass=MetaGummy):
|
|
|
884
889
|
return self.value.ksim
|
|
885
890
|
|
|
886
891
|
@property
|
|
887
|
-
def
|
|
892
|
+
def independent(self):
|
|
888
893
|
"""
|
|
889
894
|
`bool`, read-only
|
|
890
895
|
|
|
891
896
|
Returns `False` if the owning gummy was created from a operation involving
|
|
892
|
-
other gummys and `True` otherwise.
|
|
897
|
+
other gummys or has zero uncertainty and `True` otherwise.
|
|
893
898
|
"""
|
|
894
|
-
return self.value.
|
|
899
|
+
return self.value.independent
|
|
895
900
|
|
|
896
901
|
@property
|
|
897
902
|
def name(self):
|
|
898
903
|
"""
|
|
899
|
-
gets or sets an optional name for the gummy, may be `str` or
|
|
904
|
+
gets or sets an optional name for the gummy, may be `str`, `None` or a
|
|
905
|
+
length four `tuple` of `str`. If name is set to a length four tuple
|
|
906
|
+
the elements are, in order, the unicode name, the html name, the latex
|
|
907
|
+
name and the ASCII name. Getting this property returns only the unicode
|
|
908
|
+
name not the full tuple. Use the `get_name` method to get the name
|
|
909
|
+
in html, latex or ASCII format.
|
|
900
910
|
"""
|
|
901
911
|
return self.value.name
|
|
902
912
|
@name.setter
|
|
@@ -904,6 +914,23 @@ class gummy(Quantity,metaclass=MetaGummy):
|
|
|
904
914
|
self.value.name = v
|
|
905
915
|
|
|
906
916
|
def get_name(self,fmt='unicode',norm=None):
|
|
917
|
+
"""
|
|
918
|
+
|
|
919
|
+
Parameters
|
|
920
|
+
----------
|
|
921
|
+
fmt: The format, must be a `str` in {'unicode','html','latex','ascii'}.
|
|
922
|
+
The default is 'unicode'.
|
|
923
|
+
norm: An optional function which returns the name in nomral text. This
|
|
924
|
+
function is applied to the name before it is returned if
|
|
925
|
+
fmt = 'latex', name has been set to single string, and the name
|
|
926
|
+
is more than one character long. The default is
|
|
927
|
+
'\\text{' + name + '}'.
|
|
928
|
+
|
|
929
|
+
Returns
|
|
930
|
+
-------
|
|
931
|
+
`str`, the name in the requested format.
|
|
932
|
+
|
|
933
|
+
"""
|
|
907
934
|
return self.value.get_name(fmt,norm)
|
|
908
935
|
|
|
909
936
|
@property
|
|
@@ -1067,11 +1094,8 @@ class gummy(Quantity,metaclass=MetaGummy):
|
|
|
1067
1094
|
def _get_p(self):
|
|
1068
1095
|
#if self.u == 0:
|
|
1069
1096
|
#return 1
|
|
1070
|
-
if self._pm is
|
|
1071
|
-
|
|
1072
|
-
return 0
|
|
1073
|
-
return self._pm
|
|
1074
|
-
self._pm = self._p_method.fktop(self._k,self.dof,self.bayesian)
|
|
1097
|
+
if self._pm is None:
|
|
1098
|
+
self._pm = self._p_method.fktop(self._k,self.dof,self.bayesian)
|
|
1075
1099
|
if self._pm < 0:
|
|
1076
1100
|
return 0
|
|
1077
1101
|
return self._pm
|
|
@@ -1115,6 +1139,9 @@ class gummy(Quantity,metaclass=MetaGummy):
|
|
|
1115
1139
|
return self._get_p()
|
|
1116
1140
|
@p.setter
|
|
1117
1141
|
def p(self,v):
|
|
1142
|
+
if isinstance(v,str) and v.strip().lower() == 'ssd':
|
|
1143
|
+
self.p = loc_from_k(1)
|
|
1144
|
+
return
|
|
1118
1145
|
if v <= 0 or v >= 1:
|
|
1119
1146
|
raise ValueError('p is not in the interval (0,1)')
|
|
1120
1147
|
self._pm = v
|
|
@@ -1171,7 +1198,7 @@ class gummy(Quantity,metaclass=MetaGummy):
|
|
|
1171
1198
|
def covariance_sim(self,gummy):
|
|
1172
1199
|
"""
|
|
1173
1200
|
Returns the covariance, calculated from Monte-Carlo data, between the
|
|
1174
|
-
owning gummy and the gummy `g
|
|
1201
|
+
owning gummy and the gummy `g`.
|
|
1175
1202
|
|
|
1176
1203
|
See the method `gummy.covariance(g)` for the corresponding result based
|
|
1177
1204
|
on first order error propagation.
|
|
@@ -1458,7 +1485,7 @@ class gummy(Quantity,metaclass=MetaGummy):
|
|
|
1458
1485
|
uncertainty should be the standard deviation of this distribution which
|
|
1459
1486
|
is s*sqrt{(n-1)/[n*(n-3)]}. Thus
|
|
1460
1487
|
|
|
1461
|
-
u(bayesian) = [dof/(dof - 2)]*u(traditional)
|
|
1488
|
+
u(bayesian) = sqrt[dof/(dof - 2)]*u(traditional)
|
|
1462
1489
|
|
|
1463
1490
|
where dof = n - 1 and the "extra uncertainty" is incorporated directly
|
|
1464
1491
|
into the standard uncertainty.
|
|
@@ -3173,78 +3200,117 @@ class gummy(Quantity,metaclass=MetaGummy):
|
|
|
3173
3200
|
if isinstance(v,np.ndarray):
|
|
3174
3201
|
return np.array(self) + v
|
|
3175
3202
|
|
|
3203
|
+
if isinstance(v,Complex) and not isinstance(v,Real):
|
|
3204
|
+
return jummy(self) + v
|
|
3205
|
+
|
|
3176
3206
|
return super().__add__(v)
|
|
3177
3207
|
|
|
3178
3208
|
def __radd__(self,v):
|
|
3179
3209
|
if isinstance(v,np.ndarray):
|
|
3180
3210
|
return v + np.array(self)
|
|
3181
3211
|
|
|
3212
|
+
if isinstance(v,Complex) and not isinstance(v,Real):
|
|
3213
|
+
return v + jummy(self)
|
|
3214
|
+
|
|
3182
3215
|
return super().__radd__(v)
|
|
3183
3216
|
|
|
3184
3217
|
def __sub__(self,v):
|
|
3185
3218
|
if isinstance(v,np.ndarray):
|
|
3186
3219
|
return np.array(self) - v
|
|
3187
3220
|
|
|
3221
|
+
if isinstance(v,Complex) and not isinstance(v,Real):
|
|
3222
|
+
return jummy(self) - v
|
|
3223
|
+
|
|
3188
3224
|
return super().__sub__(v)
|
|
3189
3225
|
|
|
3190
3226
|
def __rsub__(self,v):
|
|
3191
3227
|
if isinstance(v,np.ndarray):
|
|
3192
3228
|
return v - np.array(self)
|
|
3193
3229
|
|
|
3230
|
+
if isinstance(v,Complex) and not isinstance(v,Real):
|
|
3231
|
+
return v - jummy(self)
|
|
3232
|
+
|
|
3194
3233
|
return super().__rsub__(v)
|
|
3195
3234
|
|
|
3196
3235
|
def __mul__(self,v):
|
|
3197
3236
|
if isinstance(v,np.ndarray):
|
|
3198
3237
|
return np.array(self)*v
|
|
3199
3238
|
|
|
3239
|
+
if isinstance(v,Complex) and not isinstance(v,Real):
|
|
3240
|
+
return jummy(self)*v
|
|
3241
|
+
|
|
3200
3242
|
return super().__mul__(v)
|
|
3201
3243
|
|
|
3202
3244
|
def __rmul__(self,v):
|
|
3203
3245
|
if isinstance(v,np.ndarray):
|
|
3204
3246
|
return v*np.array(self)
|
|
3205
3247
|
|
|
3248
|
+
if isinstance(v,Complex) and not isinstance(v,Real):
|
|
3249
|
+
return v*jummy(self)
|
|
3250
|
+
|
|
3206
3251
|
return super().__rmul__(v)
|
|
3207
3252
|
|
|
3208
3253
|
def __truediv__(self,v):
|
|
3209
3254
|
if isinstance(v,np.ndarray):
|
|
3210
3255
|
return np.array(self)/v
|
|
3211
3256
|
|
|
3257
|
+
if isinstance(v,Complex) and not isinstance(v,Real):
|
|
3258
|
+
return jummy(self)/v
|
|
3259
|
+
|
|
3212
3260
|
return super().__truediv__(v)
|
|
3213
3261
|
|
|
3214
3262
|
def __rtruediv__(self,v):
|
|
3215
3263
|
if isinstance(v,np.ndarray):
|
|
3216
3264
|
return v/np.array(self)
|
|
3217
3265
|
|
|
3266
|
+
if isinstance(v,Complex) and not isinstance(v,Real):
|
|
3267
|
+
return v/jummy(self)
|
|
3268
|
+
|
|
3218
3269
|
return super().__rtruediv__(v)
|
|
3219
3270
|
|
|
3220
3271
|
def __pow__(self,v):
|
|
3221
3272
|
if isinstance(v,np.ndarray):
|
|
3222
3273
|
return np.array(self)**v
|
|
3223
3274
|
|
|
3275
|
+
if isinstance(v,Complex) and not isinstance(v,Real):
|
|
3276
|
+
return jummy(self)**v
|
|
3277
|
+
|
|
3224
3278
|
return super().__pow__(v)
|
|
3225
3279
|
|
|
3226
3280
|
def __rpow__(self,v):
|
|
3227
3281
|
if isinstance(v,np.ndarray):
|
|
3228
3282
|
return v**np.array(self)
|
|
3229
3283
|
|
|
3284
|
+
if isinstance(v,Complex) and not isinstance(v,Real):
|
|
3285
|
+
return v**jummy(self)
|
|
3286
|
+
|
|
3230
3287
|
return super().__rpow__(v)
|
|
3231
3288
|
|
|
3232
3289
|
def __floordiv__(self,v):
|
|
3233
3290
|
if isinstance(v,np.ndarray):
|
|
3234
3291
|
return np.array(self) // v
|
|
3235
3292
|
|
|
3293
|
+
if isinstance(v,Complex) and not isinstance(v,Real):
|
|
3294
|
+
return jummy(self) // v
|
|
3295
|
+
|
|
3236
3296
|
return super().__floordiv__(v)
|
|
3237
3297
|
|
|
3238
3298
|
def __rfloordiv__(self,v):
|
|
3239
3299
|
if isinstance(v,np.ndarray):
|
|
3240
3300
|
return v // np.array(self)
|
|
3241
3301
|
|
|
3302
|
+
if isinstance(v,Complex) and not isinstance(v,Real):
|
|
3303
|
+
return v // jummy(self)
|
|
3304
|
+
|
|
3242
3305
|
return super().__rfloordiv__(v)
|
|
3243
3306
|
|
|
3244
3307
|
def __mod__(self,v):
|
|
3245
3308
|
if isinstance(v,np.ndarray):
|
|
3246
3309
|
return np.array(self) % v
|
|
3247
3310
|
|
|
3311
|
+
if isinstance(v,Complex) and not isinstance(v,Real):
|
|
3312
|
+
return jummy(self) % v
|
|
3313
|
+
|
|
3248
3314
|
return super().__mod__(v)
|
|
3249
3315
|
|
|
3250
3316
|
def __rmod__(self,v):
|
metrolopy/mean.py
CHANGED
|
@@ -26,6 +26,7 @@ Some miscellaneous functions that are useful for uncertainty analysis.
|
|
|
26
26
|
|
|
27
27
|
import numpy as np
|
|
28
28
|
from .gummy import gummy
|
|
29
|
+
from .distributions import TDist
|
|
29
30
|
import datetime
|
|
30
31
|
|
|
31
32
|
def autocorrelation(x):
|
|
@@ -181,7 +182,7 @@ def wmean(x,chi_correct=False):
|
|
|
181
182
|
|
|
182
183
|
return ret
|
|
183
184
|
|
|
184
|
-
def mean(x,n_sigma_trim=3,unit=1,ignore_nan=True,use_n_eff=None
|
|
185
|
+
def mean(x,n_sigma_trim=3,unit=1,ignore_nan=True,use_n_eff=None):
|
|
185
186
|
"""
|
|
186
187
|
Returns a gummy representing the mean of a float array.
|
|
187
188
|
|
|
@@ -211,7 +212,7 @@ def mean(x,n_sigma_trim=3,unit=1,ignore_nan=True,use_n_eff=None,bayesian=None):
|
|
|
211
212
|
If bayesian is `False` the standard uncertainty of the returned
|
|
212
213
|
gummy is s/sqrt(n) where s is the standard deviation of x and n is
|
|
213
214
|
the the number of samples (or n_eff). If bayesian is `True` then
|
|
214
|
-
the standard uncertainty is ((n-1)/(n-3))*s/sqrt(n). If bayesian
|
|
215
|
+
the standard uncertainty is sqrt((n-1)/(n-3))*s/sqrt(n). If bayesian
|
|
215
216
|
is `None` then the value of `gummy.bayesian` will be used. The
|
|
216
217
|
default value is `None`.
|
|
217
218
|
"""
|
|
@@ -231,16 +232,11 @@ def mean(x,n_sigma_trim=3,unit=1,ignore_nan=True,use_n_eff=None,bayesian=None):
|
|
|
231
232
|
if dof < 1:
|
|
232
233
|
dof = 1
|
|
233
234
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
u = (dof/(dof - 2))*float(np.std(x,ddof=1))/np.sqrt(n)
|
|
240
|
-
return gummy(m,u,unit=unit)
|
|
241
|
-
else:
|
|
242
|
-
u = float(np.std(x,ddof=1))/np.sqrt(n)
|
|
243
|
-
return gummy(m,u,dof=dof,unit=unit)
|
|
235
|
+
u = float(np.std(x,ddof=1))/np.sqrt(n)
|
|
236
|
+
if gummy.bayesian:
|
|
237
|
+
u *= np.sqrt(dof/(dof-2))
|
|
238
|
+
|
|
239
|
+
return gummy(m,u,dof=dof,unit=unit)
|
|
244
240
|
|
|
245
241
|
def sigma_trim(x, n_sigma = 3):
|
|
246
242
|
"""
|
|
@@ -288,7 +284,7 @@ def delta_diff(x):
|
|
|
288
284
|
z[0::2] = -z[0::2]
|
|
289
285
|
return z
|
|
290
286
|
|
|
291
|
-
def delta_diff_mean(x,n_sigma=None,unit=1
|
|
287
|
+
def delta_diff_mean(x,n_sigma=None,unit=1):
|
|
292
288
|
"""
|
|
293
289
|
Returns a gummy representing the mean value and uncertainty of a delta
|
|
294
290
|
type difference taken on the data. A delta type difference removes a
|
|
@@ -313,7 +309,7 @@ def delta_diff_mean(x,n_sigma=None,unit=1,bayesian=None):
|
|
|
313
309
|
If bayesian is `False` the standard uncertainty of the returned
|
|
314
310
|
gummy is s/sqrt(n) where s is the standard deviation of x and n is
|
|
315
311
|
the the number of samples (or n_eff). If bayesian is `True` then
|
|
316
|
-
the standard uncertainty is ((n-1)/(n-3))*s/sqrt(n). If bayesian
|
|
312
|
+
the standard uncertainty is sqrt((n-1)/(n-3))*s/sqrt(n). If bayesian
|
|
317
313
|
is `None` then the value of `gummy.bayesian` will be used. The
|
|
318
314
|
default value is `None`.
|
|
319
315
|
|
|
@@ -335,12 +331,8 @@ def delta_diff_mean(x,n_sigma=None,unit=1,bayesian=None):
|
|
|
335
331
|
sd = np.std(diff,ddof=1)
|
|
336
332
|
u = (np.sqrt(4*n-11)/(n-2))*sd
|
|
337
333
|
dof = (4*n-11)**2/(41/2+16*(n-4))
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
bayesian = gummy.bayesian
|
|
341
|
-
if bayesian:
|
|
342
|
-
u = u*dof/(dof-2)
|
|
343
|
-
return gummy(mn,u,unit=unit)
|
|
334
|
+
if gummy.bayesian:
|
|
335
|
+
u *= np.sqrt(dof/(dof-2))
|
|
344
336
|
|
|
345
337
|
return gummy(mn,u,dof=dof,unit=unit)
|
|
346
338
|
|