ararpy 0.1.11__py3-none-any.whl → 0.1.13__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.
ararpy/calc/arr.py CHANGED
@@ -499,6 +499,8 @@ def transpose(obj, ignore: bool = True):
499
499
 
500
500
  """
501
501
  try:
502
+ if len(obj) == 0:
503
+ return obj
502
504
  if not is_twoD(obj):
503
505
  raise ValueError("The requested object is not two dimensional.")
504
506
  obj = obj if is_homo(obj) else homo(obj)
@@ -539,7 +541,8 @@ def get_item(obj: list, loc: (list, tuple, int), default: Union[str, int, float,
539
541
  return get_item(obj[loc[0] - base[0]], loc[1:], base=base[1:], default=default)
540
542
  except (IndexError, TypeError, ValueError):
541
543
  return default
542
- raise ValueError(f"Cannot get a item from {obj = }, {loc = }")
544
+ except:
545
+ raise ValueError(f"Cannot get a item from {obj = }, {loc = }")
543
546
 
544
547
 
545
548
  # =======================
ararpy/calc/basic.py CHANGED
@@ -10,9 +10,30 @@
10
10
  #
11
11
  """
12
12
  import copy
13
+ import random
14
+ import string
15
+ from datetime import datetime, timezone, timedelta
16
+ import pytz
13
17
 
14
18
 
15
- def get_datetime(t_year: int, t_month: int, t_day: int, t_hour: int, t_min: int, t_seconds: int = 0, base=None):
19
+ def utc_dt(dt: datetime, tz: str = "utc", is_dst: bool = False) -> datetime:
20
+ """
21
+ Parameters
22
+ ----------
23
+ dt
24
+ tz
25
+ is_dst: only valid when an ambiguous time inputted
26
+
27
+ Returns
28
+ -------
29
+
30
+ """
31
+ tz = pytz.timezone(tz)
32
+ return tz.localize(dt, is_dst).astimezone(pytz.utc)
33
+
34
+
35
+ def get_datetime(t_year: int, t_month: int, t_day: int, t_hour: int, t_min: int, t_seconds: int = 0,
36
+ tz_hour: int = 0, tz_min: int = 0, base=None):
16
37
  """
17
38
  :param t_year: int
18
39
  :param t_month: int
@@ -20,22 +41,19 @@ def get_datetime(t_year: int, t_month: int, t_day: int, t_hour: int, t_min: int,
20
41
  :param t_hour: int
21
42
  :param t_min: int
22
43
  :param t_seconds: int, default == 0
44
+ :param tz_hour: int, default == 0
45
+ :param tz_min: int, default == 0
23
46
  :param base: base time [y, m, d, h, m]
24
- :return: seconds since 1970-1-1 8:00
47
+ :return: seconds since 1970-1-1 0:00
25
48
  """
26
- t_year, t_month, t_day, t_hour, t_min, t_seconds = \
27
- int(t_year), int(t_month), int(t_day), int(t_hour), int(t_min), int(t_seconds)
49
+ t_year, t_month, t_day, t_hour, t_min, t_seconds, tz_hour, tz_min = \
50
+ int(t_year), int(t_month), int(t_day), int(t_hour), int(t_min), int(t_seconds), int(tz_hour), int(tz_min)
28
51
  if base is None:
29
- base = [1970, 1, 1, 8, 0]
30
- base_year, base_mouth, base_day, base_hour, base_min = base
31
- if t_year % 4 == 0 and t_year % 100 != 0 or t_year % 400 == 0:
32
- days = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
33
- else:
34
- days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
35
- delta_seconds = ((((t_year - base_year) * 365 + ((t_year + 1 - base_year) - (t_year + 1 - base_year) % 4) / 4 +
36
- sum(days[base_mouth - 1:t_month - 1]) + t_day - base_day) * 24 + t_hour - base_hour) * 60 +
37
- t_min - base_min) * 60 + t_seconds
38
- return delta_seconds
52
+ base = [1970, 1, 1, 0, 0]
53
+ base = datetime(*base, tzinfo=timezone.utc).timestamp()
54
+ ts = datetime(t_year, t_month, t_day, t_hour, t_min, t_seconds,
55
+ tzinfo=timezone(offset=timedelta(hours=tz_hour, minutes=tz_min))).timestamp()
56
+ return ts - base
39
57
 
40
58
 
41
59
  def merge_dicts(a: dict, b: dict):
@@ -78,3 +96,7 @@ def update_dicts(a: dict, b: dict):
78
96
  else:
79
97
  res[key] = val
80
98
  return res
99
+
100
+
101
+ def get_random_digits(length: int = 7) -> str:
102
+ return ''.join(random.choices(string.digits, k=length))
ararpy/calc/corr.py CHANGED
@@ -11,7 +11,7 @@
11
11
  """
12
12
  import traceback
13
13
 
14
- from . import arr, err
14
+ from . import arr, err, basic
15
15
  import numpy as np
16
16
  from typing import Tuple, List, Optional, Union
17
17
  from types import MethodType
@@ -30,6 +30,18 @@ def blank(a0: list, e0: list, a1: list, e1: list):
30
30
  return arr.sub((a0, e0), (a1, e1))
31
31
 
32
32
 
33
+ def gain(a0: list, e0: list, a1: list, e1: list):
34
+ """
35
+ :param a0: a list of tested isotope value
36
+ :param e0: 1 sigma error of a0, list type
37
+ :param a1: a list of blank isotope value
38
+ :param e1: 1 sigma error of a1, list type
39
+ :return: list of corrected data | error list
40
+ """
41
+ # Do not force negative value to zero in correcting blank...
42
+ return arr.div((a0, e0), (a1, e1))
43
+
44
+
33
45
  def mdf(rm: float, srm: float, m1: float, m2: float, ra: float = 298.56,
34
46
  sra: float = 0):
35
47
  """
@@ -157,8 +169,8 @@ def get_decay_factor(t1: list, t2: list, t3: list, f: float, sf: float,
157
169
  v2 = []
158
170
  e1 = []
159
171
  # t_year, t_month, t_day, t_hour, t_min = t1
160
- t_test_start = get_datetime(*t1) # the time when analysis began
161
- t2 = [get_datetime(*i) for i in t2] # the time when irradiation ended for all cycles, in second
172
+ t_test_start = basic.get_datetime(*t1) # the time when analysis began
173
+ t2 = [basic.get_datetime(*i) for i in t2] # the time when irradiation ended for all cycles, in second
162
174
  k2 = [t_test_start - i for i in t2] # standing time in second between irradiation and analysing
163
175
 
164
176
  try:
@@ -191,33 +203,6 @@ def get_decay_factor(t1: list, t2: list, t3: list, f: float, sf: float,
191
203
  return k0, k1
192
204
 
193
205
 
194
- def get_datetime(t_year: int, t_month: int, t_day: int, t_hour: int, t_min: int,
195
- t_seconds: int = 0, base=None):
196
- """
197
- :param t_year: int
198
- :param t_month: int
199
- :param t_day: int
200
- :param t_hour: int
201
- :param t_min: int
202
- :param t_seconds: int, default == 0
203
- :param base: base time [y, m, d, h, m]
204
- :return: seconds since 1970-1-1 8:00
205
- """
206
- t_year, t_month, t_day, t_hour, t_min, t_seconds = \
207
- int(t_year), int(t_month), int(t_day), int(t_hour), int(t_min), int(t_seconds)
208
- if base is None:
209
- base = [1970, 1, 1, 8, 0]
210
- base_year, base_mouth, base_day, base_hour, base_min = base
211
- if t_year % 4 == 0 and t_year % 100 != 0 or t_year % 400 == 0:
212
- days = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
213
- else:
214
- days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
215
- delta_seconds = ((((t_year - base_year) * 365 + ((t_year + 1 - base_year) - (t_year + 1 - base_year) % 4) / 4 +
216
- sum(days[base_mouth - 1:t_month - 1]) + t_day - base_day) * 24 + t_hour - base_hour) * 60 +
217
- t_min - base_min) * 60 + t_seconds
218
- return delta_seconds
219
-
220
-
221
206
  def get_irradiation_datetime_by_string(datetime_str: str):
222
207
  """
223
208
  Parameters
ararpy/calc/isochron.py CHANGED
@@ -134,7 +134,7 @@ def get_ellipse(x: float, sx: float, y: float, sy: float, r: float, plt_sfactor:
134
134
  return ellipse_points
135
135
 
136
136
 
137
- def get_line_points(xscale, yscale, coeffs=None):
137
+ def get_line_points(xscale, yscale, coeffs):
138
138
  """
139
139
 
140
140
  Parameters
@@ -147,7 +147,9 @@ def get_line_points(xscale, yscale, coeffs=None):
147
147
  -------
148
148
  List of data points
149
149
  """
150
-
150
+ xscale = [float(i) for i in xscale]
151
+ yscale = [float(i) for i in yscale]
152
+ coeffs = [float(i) for i in coeffs]
151
153
  if not isinstance(coeffs, list) or len(coeffs) < 2:
152
154
  raise ValueError(f"Coeffs should be a list with length with 2.")
153
155
  get_y = lambda x: coeffs[0] + coeffs[1] * x
ararpy/calc/raw_funcs.py CHANGED
@@ -57,11 +57,11 @@ def get_raw_data_regression_results(points_data, unselected: list = None):
57
57
  except TypeError or IndexError:
58
58
  line_data, line_results, reg_coeffs = [], ['NotEnoughPoints', np.nan, np.nan, np.nan, ], []
59
59
  except ZeroDivisionError:
60
- line_data, line_results, reg_coeffs = [], [np.inf, np.nan, np.nan, np.nan, ], []
60
+ line_data, line_results, reg_coeffs = [], ['ZeroDivisionError', np.nan, np.nan, np.nan, ], []
61
61
  except ValueError:
62
62
  line_data, line_results, reg_coeffs = [], ['BadFitting', np.nan, np.nan, np.nan, ], []
63
63
  except:
64
- line_data, line_results, reg_coeffs = [], [np.nan, np.nan, np.nan, np.nan, ], []
64
+ line_data, line_results, reg_coeffs = [], ['UncaughtError', np.nan, np.nan, np.nan, ], []
65
65
  # linesData.append(line_data)
66
66
  linesResults.append(line_results)
67
67
  regCoeffs.append(reg_coeffs)
ararpy/calc/regression.py CHANGED
@@ -937,7 +937,9 @@ def exponential(a0: list, a1: list):
937
937
  raise RuntimeError
938
938
  except np.linalg.LinAlgError:
939
939
  raise np.linalg.LinAlgError
940
- except TypeError or IndexError:
940
+ except TypeError:
941
+ raise TypeError
942
+ except IndexError:
941
943
  raise IndexError
942
944
 
943
945
  f = linest(a0, [b ** _x for _x in a1])