richvalues 4.0.4__tar.gz → 4.0.6__tar.gz
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.
- {richvalues-4.0.4 → richvalues-4.0.6}/PKG-INFO +2 -2
- {richvalues-4.0.4 → richvalues-4.0.6}/README.md +1 -1
- {richvalues-4.0.4 → richvalues-4.0.6}/pyproject.toml +1 -1
- {richvalues-4.0.4 → richvalues-4.0.6}/richvalues/__init__.py +103 -50
- {richvalues-4.0.4 → richvalues-4.0.6}/richvalues.egg-info/PKG-INFO +2 -2
- {richvalues-4.0.4 → richvalues-4.0.6}/setup.py +1 -1
- {richvalues-4.0.4 → richvalues-4.0.6}/LICENSE +0 -0
- {richvalues-4.0.4 → richvalues-4.0.6}/richvalues.egg-info/SOURCES.txt +0 -0
- {richvalues-4.0.4 → richvalues-4.0.6}/richvalues.egg-info/dependency_links.txt +0 -0
- {richvalues-4.0.4 → richvalues-4.0.6}/richvalues.egg-info/requires.txt +0 -0
- {richvalues-4.0.4 → richvalues-4.0.6}/richvalues.egg-info/top_level.txt +0 -0
- {richvalues-4.0.4 → richvalues-4.0.6}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: richvalues
|
3
|
-
Version: 4.0.
|
3
|
+
Version: 4.0.6
|
4
4
|
Summary: Python library for working with uncertainties and upper/lower limits
|
5
5
|
Home-page: https://github.com/andresmegias/richvalues/
|
6
6
|
Author: Andrés Megías Toledano
|
@@ -15,7 +15,7 @@ License-File: LICENSE
|
|
15
15
|
|
16
16
|
RichValues is a Python 3 library for working with numeric values with uncertainties, upper/lower limits and finite intervals, which may be called _rich values_.
|
17
17
|
|
18
|
-
With it, one can import rich values written in plain text documents in an easily readable format, operate with them propagating the uncertainties automatically, and export them in the same formatting style as the import. It also allows to easily plot rich values and to make fits to any function, taking into account the uncertainties and the upper/limits or finite intervals. Moreover, correlations between variables are taken into account when performing calculations with rich values.
|
18
|
+
With it, one can import rich values written in plain text documents in an easily readable format, operate with them propagating the uncertainties automatically, and export them in the same formatting style as the import. It also allows to easily plot rich values and to make fits to any function, taking into account the uncertainties and the upper/lower limits or finite intervals. Moreover, correlations between variables are taken into account when performing calculations with rich values.
|
19
19
|
|
20
20
|
The libraries NumPy, Pandas, SciPy and Matplotlib are required by RichValues. A user guide and a quick tutorial are available on GitHub: https://github.com/andresmegias/richvalues/.
|
21
21
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
RichValues is a Python 3 library for working with numeric values with uncertainties, upper/lower limits and finite intervals, which may be called _rich values_.
|
2
2
|
|
3
|
-
With it, one can import rich values written in plain text documents in an easily readable format, operate with them propagating the uncertainties automatically, and export them in the same formatting style as the import. It also allows to easily plot rich values and to make fits to any function, taking into account the uncertainties and the upper/limits or finite intervals. Moreover, correlations between variables are taken into account when performing calculations with rich values.
|
3
|
+
With it, one can import rich values written in plain text documents in an easily readable format, operate with them propagating the uncertainties automatically, and export them in the same formatting style as the import. It also allows to easily plot rich values and to make fits to any function, taking into account the uncertainties and the upper/lower limits or finite intervals. Moreover, correlations between variables are taken into account when performing calculations with rich values.
|
4
4
|
|
5
5
|
The libraries NumPy, Pandas, SciPy and Matplotlib are required by RichValues. A user guide and a quick tutorial are available on GitHub: https://github.com/andresmegias/richvalues/.
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
4
4
|
|
5
5
|
[project]
|
6
6
|
name = "richvalues"
|
7
|
-
version = "4.0.
|
7
|
+
version = "4.0.6"
|
8
8
|
description = "Python library for working with uncertainties and upper/lower limits"
|
9
9
|
license = {file="LICENSE"}
|
10
10
|
authors = [{name="Andrés Megías Toledano"}]
|
@@ -37,7 +37,7 @@ IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
37
37
|
POSSIBILITY OF SUCH DAMAGE.
|
38
38
|
"""
|
39
39
|
|
40
|
-
__version__ = '4.0.
|
40
|
+
__version__ = '4.0.6'
|
41
41
|
__author__ = 'Andrés Megías Toledano'
|
42
42
|
|
43
43
|
import copy
|
@@ -231,11 +231,15 @@ def round_sf_unc(x, dx, n=None, min_exp=None, extra_sf_lim=None):
|
|
231
231
|
if not use_exp:
|
232
232
|
m = len(dy.split('.')[1]) if '.' in dy else 0
|
233
233
|
y = '{:.{}f}'.format(x, m) if x != 0. else '0'
|
234
|
-
if m
|
234
|
+
if m == 0:
|
235
235
|
num_digits_y = len(y)
|
236
236
|
num_digits_dy = len(dy)
|
237
237
|
m = n + int(num_digits_y - num_digits_dy)
|
238
|
-
|
238
|
+
num_digits_x = len(str(x).split('.')[0])
|
239
|
+
if num_digits_y > num_digits_x:
|
240
|
+
m -= 1
|
241
|
+
base_dy = '{:e}'.format(float(dy)).split('e')[0]
|
242
|
+
if float(base_dy) <= extra_sf_lim:
|
239
243
|
m += 1
|
240
244
|
y = round_sf(x, m, min_exp, extra_sf_lim=1-1e-8)
|
241
245
|
else:
|
@@ -243,7 +247,7 @@ def round_sf_unc(x, dx, n=None, min_exp=None, extra_sf_lim=None):
|
|
243
247
|
base_dy, exp_dy = '{:e}'.format(dx).split('e')
|
244
248
|
exp_y, exp_dy = int(exp_y), int(exp_dy)
|
245
249
|
d = exp_dy - exp_y
|
246
|
-
if x != 0. and d < 0
|
250
|
+
if x != 0. and d < 0:
|
247
251
|
o = 1 if float(base_dy) <= extra_sf_lim else 0
|
248
252
|
m = max(n+d+o, n)
|
249
253
|
min_exp_ = np.inf
|
@@ -254,8 +258,7 @@ def round_sf_unc(x, dx, n=None, min_exp=None, extra_sf_lim=None):
|
|
254
258
|
base_dy = '{:.{}f}'.format(float(base_dy), m)
|
255
259
|
y = '{}e{}'.format(base_y, exp_y)
|
256
260
|
dy = '{}e{}'.format(base_dy, exp_y)
|
257
|
-
|
258
|
-
base_y, exp_y = '{:e}'.format(x).split('e')
|
261
|
+
elif d == 0:
|
259
262
|
if 'e' in dy:
|
260
263
|
base_dy, exp_dy = dy.split('e')
|
261
264
|
else:
|
@@ -264,6 +267,10 @@ def round_sf_unc(x, dx, n=None, min_exp=None, extra_sf_lim=None):
|
|
264
267
|
base_y = ('{:.{}f}'.format(float(base_y)*10**(-d), m) if x != 0
|
265
268
|
else '0')
|
266
269
|
y = '{}e{}'.format(base_y, exp_dy)
|
270
|
+
else:
|
271
|
+
f = 10**(-int(exp_y))
|
272
|
+
base_y, dy = round_sf_unc(x*f, dx*f, n, np.inf, extra_sf_lim)
|
273
|
+
y = '{}e{}'.format(base_y, exp_y)
|
267
274
|
elif dx == 0:
|
268
275
|
y = round_sf(x, n, min_exp, extra_sf_lim)
|
269
276
|
dy = '0e0'
|
@@ -333,8 +340,10 @@ def round_sf_uncs(x, dx, n=None, min_exp=None, extra_sf_lim=None):
|
|
333
340
|
diff = num_dec_1 - num_dec_2
|
334
341
|
off1, off2 = 0, 0
|
335
342
|
if num_dec_1 == 0 == num_dec_2:
|
336
|
-
|
337
|
-
|
343
|
+
base_dy1 = '{:e}'.format(dx1).split('e')[0]
|
344
|
+
base_dy2 = '{:e}'.format(dx2).split('e')[0]
|
345
|
+
b1 = float(base_dy1) if np.isfinite(dx1) else 10.
|
346
|
+
b2 = float(base_dy2) if np.isfinite(dx2) else 10.
|
338
347
|
if dx2 > dx1 and b1 <= extra_sf_lim and b2 > extra_sf_lim:
|
339
348
|
off2 = 1
|
340
349
|
if dx1 > dx2 and b2 <= extra_sf_lim and b1 > extra_sf_lim:
|
@@ -939,13 +948,13 @@ class RichValue():
|
|
939
948
|
elif is_uplim:
|
940
949
|
symbol = '<'
|
941
950
|
y = int(np.ceil(x)) if is_int else x
|
942
|
-
min_exp = 0
|
943
951
|
y = round_sf(y, n, min_exp, extra_sf_lim)
|
944
|
-
|
945
|
-
|
952
|
+
if 'e' in y:
|
953
|
+
y, a = y.split('e')
|
954
|
+
else:
|
955
|
+
a = '0'
|
946
956
|
text = ('${} {} {}'.format(symbol, y, mult_symbol)
|
947
957
|
+ ' 10^{'+a+'}$')
|
948
|
-
text = text.replace('e-0', 'e-').replace('e+','e')
|
949
958
|
a = int(text.split('10^{')[1].split('}')[0])
|
950
959
|
if abs(a) < min_exp:
|
951
960
|
y = RichValue(x, dx, is_lolim, is_uplim,
|
@@ -956,7 +965,8 @@ class RichValue():
|
|
956
965
|
text = y.latex(*kwargs)
|
957
966
|
if (not use_extra_sf_in_exacts and omit_ones_in_sci_notation
|
958
967
|
and dx[0] == dx[1] and dx[0] == 0 or np.isnan(dx[0])):
|
959
|
-
|
968
|
+
if '.' not in text:
|
969
|
+
text = text.replace('1 {} '.format(mult_symbol), '')
|
960
970
|
else:
|
961
971
|
x1 = RichValue(main - unc[0], domain=domain)
|
962
972
|
x2 = RichValue(main + unc[1], domain=domain)
|
@@ -1058,7 +1068,7 @@ class RichValue():
|
|
1058
1068
|
is_other_numeric = type(other) is not RichValue
|
1059
1069
|
expression = ('{}+{}'.format(self.expression, other_expression)
|
1060
1070
|
.replace('+-','-'))
|
1061
|
-
variables =
|
1071
|
+
variables = list(dict.fromkeys(self.variables + other_vars).keys())
|
1062
1072
|
common_vars = set(self.variables) & set(other_vars)
|
1063
1073
|
if len(common_vars) == 0:
|
1064
1074
|
if is_other_numeric:
|
@@ -1107,7 +1117,7 @@ class RichValue():
|
|
1107
1117
|
other_expression = str(other)
|
1108
1118
|
is_other_numeric = type(other) is not RichValue
|
1109
1119
|
expression = '({})*({})'.format(self.expression, other_expression)
|
1110
|
-
variables =
|
1120
|
+
variables = list(dict.fromkeys(self.variables + other_vars).keys())
|
1111
1121
|
common_vars = set(self.variables) & set(other_vars)
|
1112
1122
|
if len(common_vars) == 0:
|
1113
1123
|
if is_other_numeric:
|
@@ -1151,7 +1161,7 @@ class RichValue():
|
|
1151
1161
|
other_expression = str(other)
|
1152
1162
|
is_other_numeric = type(other) is not RichValue
|
1153
1163
|
expression = '({})/({})'.format(self.expression, other_expression)
|
1154
|
-
variables =
|
1164
|
+
variables = list(dict.fromkeys(self.variables + other_vars).keys())
|
1155
1165
|
common_vars = set(self.variables) & set(other_vars)
|
1156
1166
|
if len(common_vars) == 0:
|
1157
1167
|
if is_other_numeric:
|
@@ -1236,7 +1246,7 @@ class RichValue():
|
|
1236
1246
|
other_vars = []
|
1237
1247
|
other_expression = str(other)
|
1238
1248
|
expression = '({})**({})'.format(self.expression, other_expression)
|
1239
|
-
variables =
|
1249
|
+
variables = list(dict.fromkeys(self.variables + other_vars).keys())
|
1240
1250
|
common_vars = set(self.variables) & set(other_vars)
|
1241
1251
|
if len(common_vars) == 0:
|
1242
1252
|
sigmas = defaultparams['sigmas to use approximate '
|
@@ -2657,7 +2667,7 @@ def add_rich_values(x, y):
|
|
2657
2667
|
is_int = x.is_int and y.is_int
|
2658
2668
|
domain = [x.domain[0] + y.domain[0], x.domain[1] + y.domain[1]]
|
2659
2669
|
sigmas = defaultparams['sigmas to use approximate uncertainty propagation']
|
2660
|
-
if x.is_exact or y.is_exact:
|
2670
|
+
if (x.is_exact or y.is_exact) and (x.is_interv or y.is_interv):
|
2661
2671
|
z = list(np.array(x.interval()) + np.array(y.interval()))
|
2662
2672
|
z = RichValue(z, domain=domain, is_int=is_int)
|
2663
2673
|
elif (not (x.is_interv or y.is_interv)
|
@@ -2681,7 +2691,7 @@ def multiply_rich_values(x, y):
|
|
2681
2691
|
is_int = x.is_int and y.is_int
|
2682
2692
|
domain = propagate_domain(x.domain, y.domain, lambda a,b: a*b)
|
2683
2693
|
sigmas = defaultparams['sigmas to use approximate uncertainty propagation']
|
2684
|
-
if x.is_exact or y.is_exact:
|
2694
|
+
if (x.is_exact or y.is_exact) and (x.is_interv or y.is_interv):
|
2685
2695
|
z = list(np.array(x.interval()) * np.array(y.interval()))
|
2686
2696
|
z = RichValue(z, domain=domain, is_int=is_int)
|
2687
2697
|
elif (not (x.is_interv or y.is_interv)
|
@@ -2998,8 +3008,13 @@ def rich_value(text=None, domain=None, is_int=None, pdf=None,
|
|
2998
3008
|
text = text[1:]
|
2999
3009
|
else:
|
3000
3010
|
x = text.split('-')[0]
|
3001
|
-
|
3002
|
-
|
3011
|
+
if '+' not in x:
|
3012
|
+
dx1 = text.split('-')[1].split('+')[0]
|
3013
|
+
dx2 = text.split('+')[1].split(' ')[0]
|
3014
|
+
else:
|
3015
|
+
x = x.split('+')[0]
|
3016
|
+
dx2 = text.split('+')[1].split('-')[0]
|
3017
|
+
dx1 = text.split('-')[1].split(' ')[0]
|
3003
3018
|
else:
|
3004
3019
|
x = text.split(' ')[0]
|
3005
3020
|
dx1, dx2 = '0', '0'
|
@@ -3041,7 +3056,7 @@ def rich_value(text=None, domain=None, is_int=None, pdf=None,
|
|
3041
3056
|
base = float('{:e}'.format(eval(val)).split('e')[0])
|
3042
3057
|
if base <= default_extra_sf_lim:
|
3043
3058
|
if num_sf < default_num_sf + 1:
|
3044
|
-
extra_sf_lim = base - 1e-8
|
3059
|
+
extra_sf_lim = base - 1e-8
|
3045
3060
|
else:
|
3046
3061
|
extra_sf_lim = default_extra_sf_lim
|
3047
3062
|
x = x.replace('e0','')
|
@@ -3059,7 +3074,7 @@ def rich_value(text=None, domain=None, is_int=None, pdf=None,
|
|
3059
3074
|
unc = 0
|
3060
3075
|
is_lolim, is_uplim, is_range = False, False, True
|
3061
3076
|
min_exp = round(np.mean([me1, me2]))
|
3062
|
-
extra_sf_lim =
|
3077
|
+
extra_sf_lim = max(el1, el2)
|
3063
3078
|
return (main, unc, is_lolim, is_uplim, is_range, domain,
|
3064
3079
|
min_exp, extra_sf_lim)
|
3065
3080
|
|
@@ -3192,7 +3207,7 @@ def rich_array(array, domain=None, is_int=None,
|
|
3192
3207
|
rarray = RichArray(mains, uncs, are_lolims, are_uplims, are_ranges,
|
3193
3208
|
domains, are_ints, variables, expressions)
|
3194
3209
|
min_exp = round(np.mean(min_exps))
|
3195
|
-
extra_sf_lim =
|
3210
|
+
extra_sf_lim = max(extra_sf_lims)
|
3196
3211
|
rarray.set_params({'min_exp': min_exp, 'extra_sf_lim': extra_sf_lim})
|
3197
3212
|
return rarray
|
3198
3213
|
|
@@ -3571,7 +3586,7 @@ def loguniform_distribution(low=-1, high=1, size=1,
|
|
3571
3586
|
return distr
|
3572
3587
|
|
3573
3588
|
def distr_with_rich_values(function, args, len_samples=None,
|
3574
|
-
is_vectorizable=False):
|
3589
|
+
is_vectorizable=False, **kwargs):
|
3575
3590
|
"""
|
3576
3591
|
Same as function_with_rich_values, but just returns the final distribution.
|
3577
3592
|
"""
|
@@ -3581,7 +3596,7 @@ def distr_with_rich_values(function, args, len_samples=None,
|
|
3581
3596
|
else arg for arg in args]
|
3582
3597
|
if type(function) is str:
|
3583
3598
|
variables = list(np.concatenate(tuple(arg.variables for arg in args)))
|
3584
|
-
variables = list(
|
3599
|
+
variables = list(dict.fromkeys(variables).keys())
|
3585
3600
|
vars_str = ','.join(variables)
|
3586
3601
|
expressions = [arg.expression for arg in args]
|
3587
3602
|
function = function.replace('{}','({})')
|
@@ -3677,7 +3692,7 @@ def remove_zero_infs(interval, zero_log, inf_log):
|
|
3677
3692
|
return new_interval
|
3678
3693
|
|
3679
3694
|
def evaluate_distr(distr, domain=None, function=None, args=None,
|
3680
|
-
len_samples=None, is_vectorizable=False, consider_intervs=
|
3695
|
+
len_samples=None, is_vectorizable=False, consider_intervs=None,
|
3681
3696
|
is_domain_cyclic=False, lims_fraction=None, num_reps_lims=None,
|
3682
3697
|
save_pdf=None, **kwargs):
|
3683
3698
|
"""
|
@@ -3738,7 +3753,7 @@ def evaluate_distr(distr, domain=None, function=None, args=None,
|
|
3738
3753
|
input_function = copy.copy(function)
|
3739
3754
|
if type(function) is str:
|
3740
3755
|
variables = list(np.concatenate(tuple(arg.variables for arg in args)))
|
3741
|
-
variables = list(
|
3756
|
+
variables = list(dict.fromkeys(variables).keys())
|
3742
3757
|
vars_str = ','.join(variables)
|
3743
3758
|
expressions = [arg.expression for arg in args]
|
3744
3759
|
function = function.replace('{}','({})')
|
@@ -3765,8 +3780,13 @@ def evaluate_distr(distr, domain=None, function=None, args=None,
|
|
3765
3780
|
if args is not None:
|
3766
3781
|
if type(args) not in (tuple, list):
|
3767
3782
|
args = [args]
|
3768
|
-
|
3769
|
-
|
3783
|
+
if type(args[0]) is not RichArray:
|
3784
|
+
args = [rich_value(arg) if type(arg) not in
|
3785
|
+
(RichValue, ComplexRichValue) else arg for arg in args]
|
3786
|
+
if consider_intervs is None:
|
3787
|
+
consider_intervs = True
|
3788
|
+
if args is not None and all([arg.is_centr for arg in args]):
|
3789
|
+
consider_intervs = False
|
3770
3790
|
|
3771
3791
|
distr = np.array(distr)
|
3772
3792
|
|
@@ -4065,11 +4085,13 @@ def function_with_rich_values(function, args, unc_function=None,
|
|
4065
4085
|
args = [args]
|
4066
4086
|
args = [rich_value(arg) if type(arg) not in (RichValue, ComplexRichValue)
|
4067
4087
|
else arg for arg in args]
|
4088
|
+
args_copy = copy.copy(args)
|
4068
4089
|
|
4069
4090
|
input_function = copy.copy(function)
|
4070
4091
|
if type(function) is str:
|
4071
4092
|
variables = (list(np.concatenate(tuple(arg.variables for arg in args)))
|
4072
4093
|
if len(args) > 0 else [])
|
4094
|
+
variables = list(dict.fromkeys(variables).keys())
|
4073
4095
|
vars_str = ','.join(variables)
|
4074
4096
|
expressions = [arg.expression for arg in args]
|
4075
4097
|
function = function.replace('{}','({})')
|
@@ -4107,7 +4129,7 @@ def function_with_rich_values(function, args, unc_function=None,
|
|
4107
4129
|
|
4108
4130
|
if len_samples is None:
|
4109
4131
|
len_samples = int(len(args)**0.5 * defaultparams['size of samples'])
|
4110
|
-
num_sf =
|
4132
|
+
num_sf = int(np.median([arg.num_sf for arg in args]))
|
4111
4133
|
min_exp = round(np.mean([arg.min_exp for arg in args]))
|
4112
4134
|
extra_sf_lim = max([arg.extra_sf_lim for arg in args])
|
4113
4135
|
|
@@ -4124,9 +4146,6 @@ def function_with_rich_values(function, args, unc_function=None,
|
|
4124
4146
|
use_analytic_propagation = False
|
4125
4147
|
|
4126
4148
|
args_main = np.array([arg.main for arg in args])
|
4127
|
-
# print()
|
4128
|
-
# print(args)
|
4129
|
-
# print(args[0].expression)
|
4130
4149
|
with np.errstate(divide='ignore', invalid='ignore'):
|
4131
4150
|
main = function(*args_main)
|
4132
4151
|
output_size = np.array(main).size
|
@@ -4212,16 +4231,14 @@ def function_with_rich_values(function, args, unc_function=None,
|
|
4212
4231
|
|
4213
4232
|
mains = [main] if output_size == 1 else main
|
4214
4233
|
if unc_function is not None:
|
4215
|
-
|
4216
|
-
|
4234
|
+
uncs = []
|
4235
|
+
args_main = np.array([arg.main for arg in args_copy])
|
4236
|
+
for i in (0,1):
|
4237
|
+
args_unc = [arg.unc[i] for arg in args_copy]
|
4238
|
+
uncs += [unc_function(*args_main, *args_unc)]
|
4217
4239
|
uncs = [uncs] if output_size == 1 else uncs
|
4218
|
-
|
4219
|
-
|
4220
|
-
if not hasattr(uncs[k], '__iter__'):
|
4221
|
-
uncs[k] = [uncs[k]]*2
|
4222
|
-
uncs[k][1] = abs(uncs[k][1])
|
4223
|
-
if not hasattr(uncs,'__iter__'):
|
4224
|
-
uncs = [uncs]*output_size
|
4240
|
+
for k in range(output_size):
|
4241
|
+
uncs[k][1] = abs(uncs[k][1])
|
4225
4242
|
else:
|
4226
4243
|
inds_combs = list(itertools.product(*[[0,1,2]]*len(args)))
|
4227
4244
|
comb_main = tuple([1]*len(args))
|
@@ -4249,6 +4266,9 @@ def function_with_rich_values(function, args, unc_function=None,
|
|
4249
4266
|
real_k = RichValue(main_k.real, unc_k.real, domain=domain_k)
|
4250
4267
|
imag_k = RichValue(main_k.imag, unc_k.imag, domain=domain_k)
|
4251
4268
|
rval_k = ComplexRichValue(real_k, imag_k)
|
4269
|
+
rval_k.num_sf = num_sf
|
4270
|
+
rval_k.min_exp = min_exp
|
4271
|
+
rval_k.extra_sf_lim = extra_sf_lim
|
4252
4272
|
output += [rval_k]
|
4253
4273
|
|
4254
4274
|
else:
|
@@ -4324,6 +4344,37 @@ def function_with_rich_arrays(function, args, elementwise=False, **kwargs):
|
|
4324
4344
|
output : rich array / rich value
|
4325
4345
|
Result of the function.
|
4326
4346
|
"""
|
4347
|
+
if 'domain' in kwargs:
|
4348
|
+
domain = kwargs['domain']
|
4349
|
+
del kwargs['domain']
|
4350
|
+
else:
|
4351
|
+
domain = None
|
4352
|
+
distr = distr_with_rich_arrays(function, args, elementwise, **kwargs)
|
4353
|
+
if len(distr.shape) == 1:
|
4354
|
+
output = evaluate_distr(distr, domain, function, args, **kwargs)
|
4355
|
+
else:
|
4356
|
+
output_size = distr.shape[1]
|
4357
|
+
output = []
|
4358
|
+
for k in range(output_size):
|
4359
|
+
function_k = lambda *args: function(args)[k]
|
4360
|
+
rval_k = evaluate_distr(distr[:,k], domain, function_k, args,
|
4361
|
+
**kwargs)
|
4362
|
+
output += [rval_k]
|
4363
|
+
args_main = np.array([arg.main for arg in args])
|
4364
|
+
with np.errstate(divide='ignore', invalid='ignore'):
|
4365
|
+
main = function(*args_main)
|
4366
|
+
output_size = np.array(main).size
|
4367
|
+
output_type = RichArray if type(main) is np.ndarray else type(main)
|
4368
|
+
if output_type is tuple and output_size > 1:
|
4369
|
+
output = tuple(output)
|
4370
|
+
elif output_type is RichArray:
|
4371
|
+
output = np.array(output).view(RichArray)
|
4372
|
+
return output
|
4373
|
+
|
4374
|
+
def distr_with_rich_arrays(function, args, elementwise=False, **kwargs):
|
4375
|
+
"""
|
4376
|
+
Same as function_with_rich_arrays, but just returns the final distribution.
|
4377
|
+
"""
|
4327
4378
|
if type(args) not in (tuple, list):
|
4328
4379
|
args = [args]
|
4329
4380
|
args = [rich_array(arg) if type(arg) != RichArray else arg
|
@@ -4339,6 +4390,8 @@ def function_with_rich_arrays(function, args, elementwise=False, **kwargs):
|
|
4339
4390
|
if 'len_samples' not in kwargs:
|
4340
4391
|
kwargs['len_samples'] = int(len(args)**0.5
|
4341
4392
|
* defaultparams['size of samples'])
|
4393
|
+
if 'consider_intervs' in kwargs:
|
4394
|
+
del kwargs['consider_intervs']
|
4342
4395
|
if elementwise:
|
4343
4396
|
same_shapes = True
|
4344
4397
|
for arg in args[1:]:
|
@@ -4347,15 +4400,14 @@ def function_with_rich_arrays(function, args, elementwise=False, **kwargs):
|
|
4347
4400
|
break
|
4348
4401
|
if not same_shapes:
|
4349
4402
|
raise Exception('Input arrays have different shapes.')
|
4350
|
-
array = np.empty(0,
|
4403
|
+
array = np.empty(0, float)
|
4351
4404
|
args_flat = np.array([arg.flatten() for arg in args])
|
4352
4405
|
for i in range(args[0].size):
|
4353
4406
|
args_i = np.array(args_flat)[:,i].tolist()
|
4354
|
-
rvalue =
|
4407
|
+
rvalue = distr_with_rich_values(function, args_i, **kwargs)
|
4355
4408
|
array = np.append(array, rvalue)
|
4356
4409
|
if shape == ():
|
4357
4410
|
array = np.array(array[0])
|
4358
|
-
array = array.view(RichArray)
|
4359
4411
|
output = array
|
4360
4412
|
else:
|
4361
4413
|
if type(function) is str:
|
@@ -4398,7 +4450,7 @@ def function_with_rich_arrays(function, args, elementwise=False, **kwargs):
|
|
4398
4450
|
alt_args = []
|
4399
4451
|
for arg in args:
|
4400
4452
|
alt_args += list(arg.flat)
|
4401
|
-
output =
|
4453
|
+
output = distr_with_rich_values(alt_function, alt_args, **kwargs)
|
4402
4454
|
return output
|
4403
4455
|
|
4404
4456
|
def fmean(array, function='None', inverse_function='None',
|
@@ -4512,12 +4564,12 @@ def errorbar(x, y, lims_factor=None, **kwargs):
|
|
4512
4564
|
xa, ya = rich_array(x), rich_array(y)
|
4513
4565
|
xc = rich_array([x]) if len(xa.shape) == 0 else xa
|
4514
4566
|
yc = rich_array([y]) if len(ya.shape) == 0 else ya
|
4515
|
-
if lims_factor
|
4516
|
-
lims_factor_x, lims_factor_y = None, None
|
4517
|
-
elif type(lims_factor) in (float, int):
|
4567
|
+
if type(lims_factor) in (float, int):
|
4518
4568
|
lims_factor_x, lims_factor_y = [lims_factor]*2
|
4519
4569
|
elif type(lims_factor) in (list, tuple):
|
4520
4570
|
lims_factor_x, lims_factor_y = lims_factor
|
4571
|
+
else:
|
4572
|
+
lims_factor_x, lims_factor_y = None, None
|
4521
4573
|
if lims_factor_x is None:
|
4522
4574
|
lims_factor_x = lim_factor(xc)
|
4523
4575
|
if lims_factor_y is None:
|
@@ -4967,6 +5019,7 @@ rich_df = rdataframe = rich_dataframe
|
|
4967
5019
|
function = function_with_rich_values
|
4968
5020
|
array_function = function_with_rich_arrays
|
4969
5021
|
distribution = distr_with_rich_values
|
5022
|
+
array_distribution = distr_with_rich_arrays
|
4970
5023
|
evaluate_distribution = evaluate_distr
|
4971
5024
|
center_and_uncertainties = center_and_uncs
|
4972
5025
|
is_not_a_number = is_nan = isnan
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: richvalues
|
3
|
-
Version: 4.0.
|
3
|
+
Version: 4.0.6
|
4
4
|
Summary: Python library for working with uncertainties and upper/lower limits
|
5
5
|
Home-page: https://github.com/andresmegias/richvalues/
|
6
6
|
Author: Andrés Megías Toledano
|
@@ -15,7 +15,7 @@ License-File: LICENSE
|
|
15
15
|
|
16
16
|
RichValues is a Python 3 library for working with numeric values with uncertainties, upper/lower limits and finite intervals, which may be called _rich values_.
|
17
17
|
|
18
|
-
With it, one can import rich values written in plain text documents in an easily readable format, operate with them propagating the uncertainties automatically, and export them in the same formatting style as the import. It also allows to easily plot rich values and to make fits to any function, taking into account the uncertainties and the upper/limits or finite intervals. Moreover, correlations between variables are taken into account when performing calculations with rich values.
|
18
|
+
With it, one can import rich values written in plain text documents in an easily readable format, operate with them propagating the uncertainties automatically, and export them in the same formatting style as the import. It also allows to easily plot rich values and to make fits to any function, taking into account the uncertainties and the upper/lower limits or finite intervals. Moreover, correlations between variables are taken into account when performing calculations with rich values.
|
19
19
|
|
20
20
|
The libraries NumPy, Pandas, SciPy and Matplotlib are required by RichValues. A user guide and a quick tutorial are available on GitHub: https://github.com/andresmegias/richvalues/.
|
21
21
|
|
@@ -5,7 +5,7 @@ with open('README.md', 'r') as file:
|
|
5
5
|
|
6
6
|
setuptools.setup(
|
7
7
|
name = 'richvalues',
|
8
|
-
version = '4.0.
|
8
|
+
version = '4.0.6',
|
9
9
|
license = 'BSD-3-Clause',
|
10
10
|
author = 'Andrés Megías Toledano',
|
11
11
|
description = 'Python library for working with uncertainties and upper/lower limits',
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|