richvalues 3.0.10__tar.gz → 3.0.12__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.
@@ -0,0 +1,16 @@
1
+ Metadata-Version: 2.1
2
+ Name: richvalues
3
+ Version: 3.0.12
4
+ Summary: Python library for working with uncertainties and upper/lower limits
5
+ Home-page: https://github.com/andresmegias/richvalues/
6
+ Author: Andrés Megías Toledano
7
+ License: BSD-3-Clause
8
+ Description: 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_. 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.
9
+
10
+ The libraries NumPy, Pandas, SciPy and Matplotlib are required. An user guide is available on the GitHub repository: https://github.com/andresmegias/richvalues/.
11
+
12
+ Platform: UNKNOWN
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: License :: OSI Approved :: BSD License
15
+ Classifier: Operating System :: OS Independent
16
+ Description-Content-Type: text/markdown
@@ -0,0 +1,3 @@
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_. 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.
2
+
3
+ The libraries NumPy, Pandas, SciPy and Matplotlib are required. An user guide is available on the GitHub repository: 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 = "3.0.10"
7
+ version = "3.0.12"
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__ = '3.0.9'
40
+ __version__ = '3.0.11'
41
41
  __author__ = 'Andrés Megías Toledano'
42
42
 
43
43
  import copy
@@ -52,7 +52,7 @@ from scipy.stats import linregress
52
52
 
53
53
  defaultparams = {
54
54
  'domain': [-np.inf, np.inf],
55
- 'size of samples': int(8e3),
55
+ 'size of samples': int(12e3),
56
56
  'number of significant figures': 1,
57
57
  'limit for extra significant figure': 2.5,
58
58
  'minimum exponent for scientific notation': 4,
@@ -65,7 +65,7 @@ defaultparams = {
65
65
  'decimal exponent to define infinity': 90.,
66
66
  'multiplication symbol for scientific notation in LaTeX': '\\cdot',
67
67
  'sigmas for overlap': 1.,
68
- 'sigmas for interval': 3.
68
+ 'sigmas for intervals': 3.
69
69
  }
70
70
 
71
71
  variable_count = 1
@@ -455,21 +455,27 @@ class RichValue():
455
455
  def unc_eb(self):
456
456
  """Uncertainties with shape (2,1)"""
457
457
  unceb = [[self.unc[0]], [self.unc[1]]]
458
- return unceb
458
+ return unceb
459
459
  @property
460
460
  def rel_unc(self):
461
461
  """Relative uncertainties"""
462
- m, s = self.main, self.unc
463
- with np.errstate(divide='ignore', invalid='ignore'):
464
- runc = list(np.array(s) / abs(m))
462
+ if self.is_centr:
463
+ m, s = self.main, self.unc
464
+ with np.errstate(divide='ignore', invalid='ignore'):
465
+ runc = list(np.array(s) / abs(m))
466
+ else:
467
+ runc = [np.nan]*2
465
468
  return runc
466
469
  @property
467
470
  def signal_noise(self):
468
471
  """Signal-to-noise ratios (S/N)"""
469
- m, s = self.main, self.unc
470
- with np.errstate(divide='ignore', invalid='ignore'):
471
- s_n = list(np.nan_to_num(abs(m) / np.array(s),
472
- nan=0, posinf=np.inf))
472
+ if self.is_centr:
473
+ m, s = self.main, self.unc
474
+ with np.errstate(divide='ignore', invalid='ignore'):
475
+ s_n = list(np.nan_to_num(abs(m) / np.array(s),
476
+ nan=0, posinf=np.inf))
477
+ else:
478
+ s_n = [np.nan]*2
473
479
  return s_n
474
480
  @property
475
481
  def ampl(self):
@@ -480,22 +486,31 @@ class RichValue():
480
486
  @property
481
487
  def rel_ampl(self):
482
488
  """Relative amplitudes"""
483
- s, a = self.unc, self.ampl
484
- with np.errstate(divide='ignore'):
485
- a_s = list(np.array(a) / np.array(s))
489
+ if self.is_centr:
490
+ s, a = self.unc, self.ampl
491
+ with np.errstate(divide='ignore'):
492
+ a_s = list(np.array(a) / np.array(s))
493
+ else:
494
+ a_s = [np.nan]*2
486
495
  return a_s
487
496
  @property
488
497
  def norm_unc(self):
489
498
  """Normalized uncertainties"""
490
- s, a = self.unc, self.ampl
491
- s_a = list(np.array(s) / np.array(a))
499
+ if self.is_centr:
500
+ s, a = self.unc, self.ampl
501
+ s_a = list(np.array(s) / np.array(a))
502
+ else:
503
+ s_a = [np.nan]*2
492
504
  return s_a
493
505
  @property
494
506
  def prop_score(self):
495
507
  """Minimum of the signals-to-noise and the relative amplitudes."""
496
- s_n = self.signal_noise
497
- a_s = self.rel_ampl
498
- pf = np.min([s_n, a_s])
508
+ if self.is_centr:
509
+ s_n = self.signal_noise
510
+ a_s = self.rel_ampl
511
+ pf = np.min([s_n, a_s])
512
+ else:
513
+ pf = 0.
499
514
  return pf
500
515
  @property
501
516
  def is_nan(self):
@@ -516,7 +531,7 @@ class RichValue():
516
531
  and all(np.isfinite(self.unc)) else False)
517
532
  return isfinite
518
533
 
519
- def interval(self, sigmas=defaultparams['sigmas for interval']):
534
+ def interval(self, sigmas=defaultparams['sigmas for intervals']):
520
535
  """Interval of possible values of the rich value."""
521
536
  if not self.is_interv:
522
537
  ampl1 = sigmas * self.unc[0] if self.unc[0] != 0 else 0
@@ -1375,16 +1390,16 @@ class RichArray(np.ndarray):
1375
1390
  .reshape((*self.shape,2)))
1376
1391
  @property
1377
1392
  def ampls(self):
1378
- return (np.array([x.ampls for x in self.flat])
1393
+ return (np.array([x.ampl for x in self.flat])
1379
1394
  .reshape((*self.shape,2)))
1380
1395
  @property
1381
1396
  def rel_ampls(self):
1382
- return (np.array([x.rel_ampls for x in self.flat])
1397
+ return (np.array([x.rel_ampl for x in self.flat])
1383
1398
  .reshape((*self.shape,2)))
1384
1399
  @property
1385
1400
  def norm_uncs(self):
1386
1401
  return (np.array([x.norm_unc for x in self.flat])
1387
- .reshape((self.shape,2)))
1402
+ .reshape((*self.shape,2)))
1388
1403
  @property
1389
1404
  def prop_scores(self):
1390
1405
  return (np.array([x.prop_score for x in self.flat])
@@ -1393,9 +1408,13 @@ class RichArray(np.ndarray):
1393
1408
  def uncs_eb(self):
1394
1409
  return self.uncs.transpose()
1395
1410
 
1396
- def intervals(self, sigmas=None):
1397
- return (np.array([x.interval() for x in self.flat])
1411
+ def intervals(self, sigmas=defaultparams['sigmas for intervals']):
1412
+ return (np.array([x.interval(sigmas) for x in self.flat])
1398
1413
  .reshape((*self.shape,2)))
1414
+
1415
+ def signs(self, sigmas=np.inf):
1416
+ return (np.array([x.sign(sigmas) for x in self.flat])
1417
+ .reshape(self.shape))
1399
1418
 
1400
1419
  def set_params(self, params):
1401
1420
  """Set the rich value parameters of each entry of the rich array."""
@@ -1488,15 +1507,15 @@ class RichDataFrame(pd.DataFrame):
1488
1507
  def _constructor_sliced(self):
1489
1508
  return RichSeries
1490
1509
 
1491
- def _attribute(self, attribute):
1492
- """Apply the input RichArray attribute with 1 element."""
1510
+ def _property(self, name):
1511
+ """Apply the input RichArray attribute/method with 1 element."""
1493
1512
  code = [
1494
1513
  'array = self.values',
1495
1514
  'shape = array.shape',
1496
1515
  'types = np.array([type(x) for x in array.flat]).reshape(shape)',
1497
1516
  'data = np.zeros(shape, object)',
1498
1517
  'cond = types == RichValue',
1499
- 'data[cond] = rich_array(array[cond]).{}'.format(attribute),
1518
+ 'data[cond] = rich_array(array[cond]).{}'.format(name),
1500
1519
  'cond = ~cond',
1501
1520
  'data[cond] = array[cond]',
1502
1521
  'df = pd.DataFrame(data, self.index, self.columns)']
@@ -1505,15 +1524,15 @@ class RichDataFrame(pd.DataFrame):
1505
1524
  exec(code, {**{'self': self}, **globals()}, output)
1506
1525
  return output['df']
1507
1526
 
1508
- def _attribute2(self, attribute):
1509
- """Apply the input RichArray attribute with 2 elements."""
1527
+ def _property2(self, name):
1528
+ """Apply the input RichArray attribute/method with 2 elements."""
1510
1529
  code = [
1511
1530
  'array = self.values',
1512
1531
  'shape = array.shape',
1513
1532
  'types = np.array([type(x) for x in array.flat]).reshape(shape)',
1514
1533
  'data = np.zeros(shape, object)',
1515
1534
  'cond = types == RichValue',
1516
- 'new_elements = rich_array(array[cond]).{}'.format(attribute),
1535
+ 'new_elements = rich_array(array[cond]).{}'.format(name),
1517
1536
  'new_elements = [[x[0], x[1]] for x in new_elements]',
1518
1537
  'new_subarray = np.frompyfunc(list, 0, 1)'
1519
1538
  + '(np.empty(cond.sum(), dtype=object))',
@@ -1528,40 +1547,45 @@ class RichDataFrame(pd.DataFrame):
1528
1547
  return output['df']
1529
1548
 
1530
1549
  @property
1531
- def mains(self): return self._attribute('mains')
1550
+ def mains(self): return self._property('mains')
1532
1551
  @property
1533
- def uncs(self): return self._attribute2('uncs')
1552
+ def uncs(self): return self._property2('uncs')
1534
1553
  @property
1535
- def are_lolims(self): return self._attribute('are_lolims')
1554
+ def are_lolims(self): return self._property('are_lolims')
1536
1555
  @property
1537
- def are_uplims(self): return self._attribute('are_uplims')
1556
+ def are_uplims(self): return self._property('are_uplims')
1538
1557
  @property
1539
- def are_ranges(self): return self._attribute('are_ranges')
1558
+ def are_ranges(self): return self._property('are_ranges')
1540
1559
  @property
1541
- def domains(self): return self._attribute2('domains')
1560
+ def domains(self): return self._property2('domains')
1542
1561
  @property
1543
- def are_lims(self): return self._attribute('are_lims')
1562
+ def are_lims(self): return self._property('are_lims')
1544
1563
  @property
1545
- def are_intervs(self): return self._attribute('are_intervs')
1564
+ def are_intervs(self): return self._property('are_intervs')
1546
1565
  @property
1547
- def are_centrs(self): return self._attribute('are_centrs')
1566
+ def are_centrs(self): return self._property('are_centrs')
1548
1567
  @property
1549
- def rel_uncs(self): return self._attribute2('rel_uncs')
1568
+ def rel_uncs(self): return self._property2('rel_uncs')
1550
1569
  @property
1551
- def signals_noises(self): return self._attribute2('signal_noises')
1570
+ def signals_noises(self): return self._property2('signal_noises')
1552
1571
  @property
1553
- def ampls(self): return self._attribute2('ampls')
1572
+ def ampls(self): return self._property2('ampls')
1554
1573
  @property
1555
- def rel_ampls(self): return self._attribute2('rel_ampls')
1574
+ def rel_ampls(self): return self._property2('rel_ampls')
1556
1575
  @property
1557
- def norm_uncs(self): return self._attribute2('norm_uncs')
1576
+ def norm_uncs(self): return self._property2('norm_uncs')
1558
1577
  @property
1559
- def prop_scores(self): return self._attribute('prop_scores')
1578
+ def prop_scores(self): return self._property('prop_scores')
1560
1579
 
1561
- def intervals(self):
1562
- return self._attribute2('intervals')
1580
+ def intervals(self, sigmas=defaultparams['sigmas for intervals']):
1581
+ sigmas = str(sigmas).replace('inf', 'np.inf')
1582
+ return self._property2('intervals({})'.format(sigmas))
1583
+
1584
+ def signs(self, sigmas=np.inf):
1585
+ sigmas = str(sigmas).replace('inf', 'np.inf')
1586
+ return self._property('signs({})'.format(sigmas))
1563
1587
 
1564
- def flatten_attribute_output(self, attribute):
1588
+ def flatten_property_output(self, attribute):
1565
1589
  """Separate the list elements from the output of the given attribute."""
1566
1590
  df = eval('self.{}'.format(attribute))
1567
1591
  df1, df2 = df.copy(), df.copy()
@@ -1815,12 +1839,14 @@ class RichSeries(pd.Series):
1815
1839
  self.index) for i in (0,1)]
1816
1840
  @property
1817
1841
  def prop_scores(self):
1818
- return [pd.Series(rich_array(self.values).prop_scores.T[i].T,
1819
- self.index) for i in (0,1)]
1842
+ return pd.Series(rich_array(self.values).prop_scores, self.index)
1820
1843
 
1821
- def intervals(self, sigmas=defaultparams['sigmas for interval']):
1844
+ def intervals(self, sigmas=defaultparams['sigmas for intervals']):
1822
1845
  return [pd.Series(rich_array(self.values).intervals(sigmas).T[i].T,
1823
1846
  self.index) for i in (0,1)]
1847
+
1848
+ def signs(self, sigmas=defaultparams['sigmas for intervals']):
1849
+ return pd.Series(rich_array(self.values).signs(sigmas), self.index)
1824
1850
 
1825
1851
  def set_params(self, params):
1826
1852
  data = self.values.view(RichArray)
@@ -1933,7 +1959,7 @@ def divide_two_rich_values(x, y):
1933
1959
  z.min_exp = min_exp
1934
1960
  return z
1935
1961
 
1936
- def greater(x, y, sigmas=defaultparams['sigmas for interval']):
1962
+ def greater(x, y, sigmas=defaultparams['sigmas for intervals']):
1937
1963
  """Determine if a rich value/array (x) is greater than another one (y)."""
1938
1964
  are_single_values = all([type(var) is str
1939
1965
  or not hasattr(var, '__iter__') for var in (x,y)])
@@ -2010,7 +2036,7 @@ def equiv(x, y, sigmas=defaultparams['sigmas for overlap']):
2010
2036
  return output
2011
2037
 
2012
2038
  def greater_equiv(x, y,
2013
- sigmas_interval=defaultparams['sigmas for interval'],
2039
+ sigmas_interval=defaultparams['sigmas for intervals'],
2014
2040
  sigmas_overlap=defaultparams['sigmas for overlap']):
2015
2041
  """Check if a rich value/array is greater or equivalent than another one."""
2016
2042
  are_single_values = all([type(var) is str
@@ -2035,7 +2061,7 @@ def greater_equiv(x, y,
2035
2061
  return output
2036
2062
 
2037
2063
  def less_equiv(x, y,
2038
- sigmas_interval=defaultparams['sigmas for interval'],
2064
+ sigmas_interval=defaultparams['sigmas for intervals'],
2039
2065
  sigmas_overlap=defaultparams['sigmas for overlap']):
2040
2066
  """Check if a rich value/array is less or equivalent than another one."""
2041
2067
  are_single_values = all([type(var) is str
@@ -0,0 +1,16 @@
1
+ Metadata-Version: 2.1
2
+ Name: richvalues
3
+ Version: 3.0.12
4
+ Summary: Python library for working with uncertainties and upper/lower limits
5
+ Home-page: https://github.com/andresmegias/richvalues/
6
+ Author: Andrés Megías Toledano
7
+ License: BSD-3-Clause
8
+ Description: 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_. 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.
9
+
10
+ The libraries NumPy, Pandas, SciPy and Matplotlib are required. An user guide is available on the GitHub repository: https://github.com/andresmegias/richvalues/.
11
+
12
+ Platform: UNKNOWN
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: License :: OSI Approved :: BSD License
15
+ Classifier: Operating System :: OS Independent
16
+ Description-Content-Type: text/markdown
@@ -5,14 +5,14 @@ with open('README.md', 'r') as file:
5
5
 
6
6
  setuptools.setup(
7
7
  name = 'richvalues',
8
- version = '3.0.10',
8
+ version = '3.0.12',
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',
12
12
  long_description = long_description,
13
13
  long_description_content_type = 'text/markdown',
14
14
  packages = setuptools.find_packages('.'),
15
- url = 'https://github.com/andresmegias/richvalues',
15
+ url = 'https://github.com/andresmegias/richvalues/',
16
16
  install_requires = ['numpy', 'pandas', 'scipy', 'matplotlib'],
17
17
  classifiers = [
18
18
  'Programming Language :: Python :: 3',
@@ -1,18 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: richvalues
3
- Version: 3.0.10
4
- Summary: Python library for working with uncertainties and upper/lower limits
5
- Home-page: https://github.com/andresmegias/richvalues
6
- Author: Andrés Megías Toledano
7
- License: BSD-3-Clause
8
- Description: # RichValues
9
-
10
- Python 3 library for working with numeric values with uncertainties, upper/lower limits and finite intervals, which may be called _rich values_. 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.
11
-
12
- The libraries NumPy, Pandas, SciPy and Matplotlib are required. An user guide is available on the GitHub repository: https://github.com/andresmegias/richvalues.
13
-
14
- Platform: UNKNOWN
15
- Classifier: Programming Language :: Python :: 3
16
- Classifier: License :: OSI Approved :: BSD License
17
- Classifier: Operating System :: OS Independent
18
- Description-Content-Type: text/markdown
@@ -1,5 +0,0 @@
1
- # RichValues
2
-
3
- Python 3 library for working with numeric values with uncertainties, upper/lower limits and finite intervals, which may be called _rich values_. 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.
4
-
5
- The libraries NumPy, Pandas, SciPy and Matplotlib are required. An user guide is available on the GitHub repository: https://github.com/andresmegias/richvalues.
@@ -1,18 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: richvalues
3
- Version: 3.0.10
4
- Summary: Python library for working with uncertainties and upper/lower limits
5
- Home-page: https://github.com/andresmegias/richvalues
6
- Author: Andrés Megías Toledano
7
- License: BSD-3-Clause
8
- Description: # RichValues
9
-
10
- Python 3 library for working with numeric values with uncertainties, upper/lower limits and finite intervals, which may be called _rich values_. 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.
11
-
12
- The libraries NumPy, Pandas, SciPy and Matplotlib are required. An user guide is available on the GitHub repository: https://github.com/andresmegias/richvalues.
13
-
14
- Platform: UNKNOWN
15
- Classifier: Programming Language :: Python :: 3
16
- Classifier: License :: OSI Approved :: BSD License
17
- Classifier: Operating System :: OS Independent
18
- Description-Content-Type: text/markdown
File without changes