richvalues 4.2.3__tar.gz → 4.2.5__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: richvalues
3
- Version: 4.2.3
3
+ Version: 4.2.5
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
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "richvalues"
7
- version = "4.2.3"
7
+ version = "4.2.5"
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"}]
@@ -13,12 +13,12 @@ modification, are permitted provided that the following conditions are
13
13
  met:
14
14
 
15
15
  (1) Redistributions of source code must retain the above copyright
16
- notice, this list of conditions and the following disclaimer.
16
+ notice, this list of conditions and the following disclaimer.
17
17
 
18
18
  (2) Redistributions in binary form must reproduce the above copyright
19
19
  notice, this list of conditions and the following disclaimer in
20
20
  the documentation and/or other materials provided with the
21
- distribution.
21
+ distribution.
22
22
 
23
23
  (3) The name of the author may not be used to endorse or promote
24
24
  products derived from this software without specific prior written
@@ -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.2.2'
40
+ __version__ = '4.2.5'
41
41
  __author__ = 'Andrés Megías Toledano'
42
42
 
43
43
  import copy
@@ -303,18 +303,21 @@ def round_sf_unc(x, dx, n=None, min_exp=None, max_dec=None, extra_sf_lim=None):
303
303
  min_exp = np.inf
304
304
  y, dy = round_sf_unc(x, dx, n, min_exp, max_dec, extra_sf_lim)
305
305
  y = y.replace('e+', 'e').replace('e00', 'e0')
306
- dy = dy.replace('e+','e').replace('e00', 'e0')
307
- d = len(y.split('e')[0].split('.')[-1])
308
- if d > max_dec and ')' not in dy:
306
+ dy = dy.replace('e+','e').replace('e00', 'e0') .replace('(', '').replace(')', '')
307
+ d = len(y.split('e')[0].split('.')[-1]) if '.' in y else 0
308
+ if max_dec == 0 or d > max_dec and ')' not in dy:
309
309
  if 'e' in y:
310
310
  y, exp = y.split('e')
311
311
  dy, _ = dy.split('e')
312
312
  else:
313
313
  exp = None
314
- d = len(y.split('.')[-1])
315
- d_ = len(dy.split('.')[-1])
314
+ d = len(y.split('.')[-1]) if '.' in y else 0
315
+ d_ = len(dy.split('.')[-1]) if '.' in dy else 0
316
316
  dy_ = round_sf(float(dy)*10**(d-d_), n, 0, extra_sf_lim)
317
- dy = '(' + dy_.split('e')[0] + ')'
317
+ dy, exp_ = dy_.split('e')
318
+ if int(exp_) > 0:
319
+ dy = round_sf(float(dy)*10**int(exp_), n, np.inf, extra_sf_lim)
320
+ dy = '(' + dy + ')'
318
321
  if exp is not None:
319
322
  y = '{}e{}'.format(y, exp)
320
323
  return y, dy
@@ -632,11 +635,11 @@ class RichValue():
632
635
  """Constant value."""
633
636
  isconst = self.is_exact and self.domain[0] == self.domain[1]
634
637
  return isconst
635
- @property
638
+ @property
636
639
  def center(self):
637
640
  """Central value."""
638
641
  cent = self.main if self.is_centr else np.nan
639
- return cent
642
+ return cent
640
643
  @property
641
644
  def unc_eb(self):
642
645
  """Uncertainties with shape (2,1)."""
@@ -663,7 +666,7 @@ class RichValue():
663
666
  else:
664
667
  s_n = [np.nan]*2
665
668
  return s_n
666
- @property
669
+ @property
667
670
  def ampl(self):
668
671
  """Amplitudes."""
669
672
  m, b = self.main, self.domain
@@ -784,7 +787,7 @@ class RichValue():
784
787
  m = np.nanmedian(distr)
785
788
  else:
786
789
  m = np.nan
787
- return m
790
+ return m
788
791
 
789
792
  def mean(self, num_points=int(1e4), sigmas=8.):
790
793
  """Mean of the PDF of the rich value."""
@@ -840,7 +843,7 @@ class RichValue():
840
843
  y = self.pdf(x)
841
844
  c = np.trapz(y*x, x) if central or standarized else 0.
842
845
  s = np.sqrt(np.trapz(y*(x-c)**2)) if standarized else 1.
843
- moment = np.trapz((y*(x-c)**n)) / s**n
846
+ moment = np.trapz((y*(x-c)**n)) / s**n
844
847
  else:
845
848
  moment = np.nan
846
849
  return moment
@@ -1094,7 +1097,7 @@ class RichValue():
1094
1097
  else:
1095
1098
  if is_lolim:
1096
1099
  symbol = '>'
1097
- y = int(np.floor(x)) if is_int else x
1100
+ y = int(np.floor(x)) if is_int else x
1098
1101
  elif is_uplim:
1099
1102
  symbol = '<'
1100
1103
  y = int(np.ceil(x)) if is_int else x
@@ -1144,10 +1147,10 @@ class RichValue():
1144
1147
  else:
1145
1148
  if is_lolim:
1146
1149
  symbol = '>'
1147
- y = int(np.floor(x)) if is_int else x
1150
+ y = int(np.floor(x)) if is_int else x
1148
1151
  elif is_uplim:
1149
1152
  symbol = '<'
1150
- y = int(np.ceil(x)) if is_int else x
1153
+ y = int(np.ceil(x)) if is_int else x
1151
1154
  y = round_sf(y, n, min_exp, extra_sf_lim)
1152
1155
  if 'e' in y:
1153
1156
  y, a = y.split('e')
@@ -1431,7 +1434,7 @@ class RichValue():
1431
1434
  if domain[0] > 0 and other_.sign() != -1:
1432
1435
  domain[0] = 0
1433
1436
  if domain[1] < 0 and other_.sign() != 1:
1434
- domain[1] = 0
1437
+ domain[1] = 0
1435
1438
  rvalue = function_with_rich_values('{}%{}', [self, other_],
1436
1439
  domain=domain, is_domain_cyclic=True)
1437
1440
  return rvalue
@@ -1546,7 +1549,7 @@ class RichValue():
1546
1549
  x = [x]
1547
1550
  x = np.array(x)
1548
1551
  y = np.zeros(len(x))
1549
- if self.is_exact:
1552
+ if self.is_exact:
1550
1553
  ind = np.argmin(abs(x - main))
1551
1554
  if hasattr(ind, '__iter__'):
1552
1555
  ind = ind[0]
@@ -1607,7 +1610,7 @@ class RichValue():
1607
1610
  if not self.is_lim:
1608
1611
  distr = general_distribution(main, unc, domain, N)
1609
1612
  else:
1610
- x1, x2 = self.interval()
1613
+ x1, x2 = self.interval()
1611
1614
  distr = loguniform_distribution(x1, x2, N)
1612
1615
  elif not is_finite_interv and all(np.isinf(unc)):
1613
1616
  distr = loguniform_distribution(-np.inf, np.inf, N)
@@ -1857,17 +1860,17 @@ class RichArray(np.ndarray):
1857
1860
  return np.array([x.main for x in self.flat]).reshape(self.shape)
1858
1861
  @property
1859
1862
  def uncs(self):
1860
- return np.array([x.unc for x in self.flat]).reshape([*self.shape,2])
1863
+ return np.array([x.unc for x in self.flat]).reshape([*self.shape,2])
1861
1864
  @property
1862
1865
  def are_lolims(self):
1863
1866
  return np.array([x.is_lolim for x in self.flat]).reshape(self.shape)
1864
1867
  @property
1865
1868
  def are_uplims(self):
1866
- return np.array([x.is_uplim for x in self.flat]).reshape(self.shape)
1869
+ return np.array([x.is_uplim for x in self.flat]).reshape(self.shape)
1867
1870
  @property
1868
1871
  def are_ranges(self):
1869
1872
  return np.array([x.is_range for x in self.flat]).reshape(self.shape)
1870
- @property
1873
+ @property
1871
1874
  def domains(self):
1872
1875
  return np.array([x.domain for x in self.flat]).reshape([*self.shape,2])
1873
1876
  @property
@@ -1908,7 +1911,7 @@ class RichArray(np.ndarray):
1908
1911
  return np.array([x.is_inf for x in self.flat]).reshape(self.shape)
1909
1912
  @property
1910
1913
  def centers(self):
1911
- return np.array([x.center for x in self.flat]).reshape(self.shape)
1914
+ return np.array([x.center for x in self.flat]).reshape(self.shape)
1912
1915
  @property
1913
1916
  def rel_uncs(self):
1914
1917
  return (np.array([x.rel_unc for x in self.flat])
@@ -1982,27 +1985,27 @@ class RichArray(np.ndarray):
1982
1985
 
1983
1986
  def medians(self, num_points=None):
1984
1987
  return np.array([x.median(num_points)
1985
- for x in self.flat]).reshape(self.shape)
1988
+ for x in self.flat]).reshape(self.shape)
1986
1989
 
1987
1990
  def means(self, num_points=int(1e4), sigmas=8.):
1988
1991
  return np.array([x.mean(num_points, sigmas)
1989
- for x in self.flat]).reshape(self.shape)
1992
+ for x in self.flat]).reshape(self.shape)
1990
1993
 
1991
1994
  def modes(self, num_points=int(1e4), sigmas=8.):
1992
1995
  return np.array([x.mode(num_points, sigmas)
1993
- for x in self.flat]).reshape(self.shape)
1996
+ for x in self.flat]).reshape(self.shape)
1994
1997
 
1995
1998
  def variances(self, num_points=int(1e4), sigmas=8.):
1996
1999
  return np.array([x.var(num_points, sigmas)
1997
- for x in self.flat]).reshape(self.shape)
2000
+ for x in self.flat]).reshape(self.shape)
1998
2001
 
1999
2002
  def stds(self, num_points=int(1e4), sigmas=8.):
2000
2003
  return np.array([x.std(num_points, sigmas)
2001
- for x in self.flat]).reshape(self.shape)
2004
+ for x in self.flat]).reshape(self.shape)
2002
2005
 
2003
2006
  def moments(self, n, central=True, standarized=False):
2004
2007
  return np.array([x.moments(n, central, standarized)
2005
- for x in self.flat]).reshape(self.shape)
2008
+ for x in self.flat]).reshape(self.shape)
2006
2009
 
2007
2010
  def set_params(self, params):
2008
2011
  """Set the rich value parameters of each entry of the rich array."""
@@ -2011,7 +2014,7 @@ class RichArray(np.ndarray):
2011
2014
  'minimum exponent for scientific notation': 'min_exp',
2012
2015
  'maximum number of decimals': 'max_dec',
2013
2016
  'limit for extra significant figure': 'extra_sf_lim'}
2014
- attributes = ['domain'] + list(abbreviations.values())
2017
+ attributes = ['domain'] + list(abbreviations.values())
2015
2018
  for entry in abbreviations:
2016
2019
  name = abbreviations[entry]
2017
2020
  if entry in params:
@@ -2163,7 +2166,7 @@ class RichDataFrame(pd.DataFrame):
2163
2166
  exec(code, {**{'self': self}, **globals()}, output)
2164
2167
  return output['df']
2165
2168
 
2166
- @property
2169
+ @property
2167
2170
  def mains(self): return self._property('mains')
2168
2171
  @property
2169
2172
  def uncs(self): return self._property2('uncs')
@@ -2595,7 +2598,7 @@ class ComplexRichValue():
2595
2598
  Parameters
2596
2599
  ----------
2597
2600
  real : rich value
2598
- Real part of the complex rich value.
2601
+ Real part of the complex rich value.
2599
2602
  imag : rich value
2600
2603
  Imaginary part of the complex rich value
2601
2604
  """
@@ -2676,14 +2679,14 @@ class ComplexRichValue():
2676
2679
  self.imag.num_sf = x
2677
2680
 
2678
2681
  @property
2679
- def min_exp(self): return round(np.mean([self.real.min_exp, self.imag.min_exp]))
2682
+ def min_exp(self): return round(np.mean([self.real.min_exp, self.imag.min_exp]))
2680
2683
  @min_exp.setter
2681
2684
  def min_exp(self, x):
2682
2685
  self.real.min_exp = x
2683
2686
  self.imag.min_exp = x
2684
2687
 
2685
2688
  @property
2686
- def max_dec(self): return min(self.real.max_dec, self.imag.max_dec)
2689
+ def max_dec(self): return min(self.real.max_dec, self.imag.max_dec)
2687
2690
  @max_dec.setter
2688
2691
  def max_dec(self, x):
2689
2692
  self.real.max_dec = x
@@ -2723,7 +2726,7 @@ class ComplexRichValue():
2723
2726
  def main(self):
2724
2727
  """Main value."""
2725
2728
  x = self.real.main + 1j*self.imag.main
2726
- return x
2729
+ return x
2727
2730
 
2728
2731
  @property
2729
2732
  def unc(self):
@@ -2943,7 +2946,7 @@ class ComplexRichValue():
2943
2946
  """Apply a function to the rich value"""
2944
2947
  return function_with_rich_values(function, self, **kwargs)
2945
2948
 
2946
- # Instance variable acronyms.
2949
+ # Instance variable acronyms.
2947
2950
 
2948
2951
  @property
2949
2952
  def real_part(self): return self.real
@@ -3287,7 +3290,7 @@ def rich_value(text=None, domain=None, is_int=None, pdf=None,
3287
3290
  domain = read_domain(text)
3288
3291
  if domain is not None:
3289
3292
  text = text.split('[')[0][:-1]
3290
- if not '--' in text:
3293
+ if not '--' in text:
3291
3294
  if text.startswith('+'):
3292
3295
  text = text[1:]
3293
3296
  if 'e' in text:
@@ -3397,11 +3400,11 @@ def rich_value(text=None, domain=None, is_int=None, pdf=None,
3397
3400
  if eval(dx1) == eval(dx2) == 0:
3398
3401
  extra_sf_lim = 1 - 1e-8
3399
3402
  else:
3400
- extra_sf_lim = default_extra_sf_lim
3403
+ extra_sf_lim = default_extra_sf_lim
3401
3404
  base = float('{:e}'.format(eval(val)).split('e')[0])
3402
3405
  if base <= default_extra_sf_lim:
3403
3406
  if num_sf < default_num_sf + 1:
3404
- extra_sf_lim = base - 1e-8
3407
+ extra_sf_lim = base - 1e-8
3405
3408
  else:
3406
3409
  extra_sf_lim = default_extra_sf_lim
3407
3410
  x = x.replace('e0','')
@@ -3409,7 +3412,7 @@ def rich_value(text=None, domain=None, is_int=None, pdf=None,
3409
3412
  unc = [eval(dx1), eval(dx2)]
3410
3413
  is_range = False
3411
3414
  if domain is None and np.isfinite(main) and unc[0] == 0. == unc[1]:
3412
- domain = [main]*2
3415
+ domain = [main]*2
3413
3416
  else:
3414
3417
  text = text.replace(' --','--').replace('-- ','--')
3415
3418
  text1, text2 = text.split('--')
@@ -3456,7 +3459,7 @@ def rich_value(text=None, domain=None, is_int=None, pdf=None,
3456
3459
  imag = rich_value(text_imag, *args)
3457
3460
  else:
3458
3461
  text = text.replace(' + ', '+').replace(' - ', '-')
3459
- val = complex(text)
3462
+ val = complex(text)
3460
3463
  real = val.real
3461
3464
  imag = val.imag
3462
3465
  rvalue = ComplexRichValue(real, imag, domain, is_int)
@@ -4173,7 +4176,7 @@ def loguniform_distribution(low=-1, high=1, size=1,
4173
4176
  log_x2 = _log10(abs(x2))
4174
4177
  if log_x1 < zero_log:
4175
4178
  log_x1 = zero_log
4176
- if log_x2 > inf_log:
4179
+ if log_x2 > inf_log:
4177
4180
  log_x2 = inf_log
4178
4181
  if x1 < 0:
4179
4182
  if x2 <= 0:
@@ -4315,7 +4318,7 @@ def add_zero_infs(interval, zero_log, inf_log):
4315
4318
  elif x2 > 0 and x2 > 10**inf_log:
4316
4319
  x2 = np.inf
4317
4320
  new_interval = [x1, x2]
4318
- return new_interval
4321
+ return new_interval
4319
4322
  def remove_zero_infs(interval, zero_log, inf_log):
4320
4323
  """Replace 0 and infinity for the given values in the input interval."""
4321
4324
  x1, x2 = interval
@@ -5427,7 +5430,7 @@ def curve_fit(x, y, function, guess, num_samples=3000,
5427
5430
  lim1, lim2 = 0.2, 1.2
5428
5431
  if disp_coef <= lim1:
5429
5432
  frac1 = 1.
5430
- elif disp_coef < lim2:
5433
+ elif disp_coef < lim2:
5431
5434
  frac1 = 1. - disp_coef / (lim2 - lim1)
5432
5435
  else:
5433
5436
  frac1 = 0.
@@ -5440,7 +5443,7 @@ def curve_fit(x, y, function, guess, num_samples=3000,
5440
5443
  result = {'parameters': params_fit, 'dispersion': dispersion, 'loss': loss,
5441
5444
  'parameters samples': samples, 'dispersion sample': dispersions,
5442
5445
  'loss sample': losses, 'number of fails': num_fails}
5443
- return result
5446
+ return result
5444
5447
 
5445
5448
  def point_fit(y, function, guess, num_samples=3000,
5446
5449
  loss=lambda a,b: (a-b)**2, lim_loss_factor=4.,
@@ -5517,7 +5520,7 @@ def point_fit(y, function, guess, num_samples=3000,
5517
5520
  lim1, lim2 = 0.2, 1.2
5518
5521
  if disp_coef <= lim1:
5519
5522
  frac1 = 1.
5520
- elif disp_coef < lim2:
5523
+ elif disp_coef < lim2:
5521
5524
  frac1 = 1. - disp_coef / (lim2 - lim1)
5522
5525
  else:
5523
5526
  frac1 = 0.
@@ -5760,4 +5763,4 @@ evaluate_distribution = evaluate_distr
5760
5763
  center_and_uncertainties = center_and_uncs
5761
5764
  is_not_a_number = is_nan = isnan
5762
5765
  is_infinite = is_inf = isinf
5763
- is_finite = is_finite = isfinite
5766
+ is_finite = is_finite = isfinite
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: richvalues
3
- Version: 4.2.3
3
+ Version: 4.2.5
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
@@ -5,7 +5,7 @@ with open('README.md', 'r') as file:
5
5
 
6
6
  setuptools.setup(
7
7
  name = 'richvalues',
8
- version = '4.2.3',
8
+ version = '4.2.5',
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