ararpy 0.1.12__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
@@ -541,7 +541,8 @@ def get_item(obj: list, loc: (list, tuple, int), default: Union[str, int, float,
541
541
  return get_item(obj[loc[0] - base[0]], loc[1:], base=base[1:], default=default)
542
542
  except (IndexError, TypeError, ValueError):
543
543
  return default
544
- raise ValueError(f"Cannot get a item from {obj = }, {loc = }")
544
+ except:
545
+ raise ValueError(f"Cannot get a item from {obj = }, {loc = }")
545
546
 
546
547
 
547
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
@@ -169,8 +169,8 @@ def get_decay_factor(t1: list, t2: list, t3: list, f: float, sf: float,
169
169
  v2 = []
170
170
  e1 = []
171
171
  # t_year, t_month, t_day, t_hour, t_min = t1
172
- t_test_start = get_datetime(*t1) # the time when analysis began
173
- 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
174
174
  k2 = [t_test_start - i for i in t2] # standing time in second between irradiation and analysing
175
175
 
176
176
  try:
@@ -203,33 +203,6 @@ def get_decay_factor(t1: list, t2: list, t3: list, f: float, sf: float,
203
203
  return k0, k1
204
204
 
205
205
 
206
- def get_datetime(t_year: int, t_month: int, t_day: int, t_hour: int, t_min: int,
207
- t_seconds: int = 0, base=None):
208
- """
209
- :param t_year: int
210
- :param t_month: int
211
- :param t_day: int
212
- :param t_hour: int
213
- :param t_min: int
214
- :param t_seconds: int, default == 0
215
- :param base: base time [y, m, d, h, m]
216
- :return: seconds since 1970-1-1 8:00
217
- """
218
- t_year, t_month, t_day, t_hour, t_min, t_seconds = \
219
- int(t_year), int(t_month), int(t_day), int(t_hour), int(t_min), int(t_seconds)
220
- if base is None:
221
- base = [1970, 1, 1, 8, 0]
222
- base_year, base_mouth, base_day, base_hour, base_min = base
223
- if t_year % 4 == 0 and t_year % 100 != 0 or t_year % 400 == 0:
224
- days = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
225
- else:
226
- days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
227
- delta_seconds = ((((t_year - base_year) * 365 + ((t_year + 1 - base_year) - (t_year + 1 - base_year) % 4) / 4 +
228
- sum(days[base_mouth - 1:t_month - 1]) + t_day - base_day) * 24 + t_hour - base_hour) * 60 +
229
- t_min - base_min) * 60 + t_seconds
230
- return delta_seconds
231
-
232
-
233
206
  def get_irradiation_datetime_by_string(datetime_str: str):
234
207
  """
235
208
  Parameters
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])
ararpy/files/calc_file.py CHANGED
@@ -342,7 +342,7 @@ def general_adjustment(
342
342
  irradiation_name: str
343
343
  ):
344
344
  """
345
- General handle for all age files, including set irradiaition time, initial ratios, error display
345
+ General handle for all age files, including set irradiation time, initial ratios, error display
346
346
  :param total_param:
347
347
  :param logs02:
348
348
  :param experimental_time:
ararpy/files/raw_file.py CHANGED
@@ -21,6 +21,7 @@ from datetime import datetime
21
21
  from parse import parse as string_parser
22
22
  import dateutil.parser as datetime_parser
23
23
  from ..calc.arr import get_item
24
+ from ..calc.basic import utc_dt
24
25
 
25
26
  """ Open raw data file """
26
27
 
@@ -159,16 +160,15 @@ def open_raw_xls(file_path, input_filter: List[Union[str, int]]):
159
160
  raise ValueError("The file does not comply with the extension in the given filter.")
160
161
 
161
162
  def _get_content_from_sheet(_index) -> List[List[Union[str, bool, int, float]]]:
162
- _sheet = wb.sheet_by_index(_index)
163
- return [[_sheet.cell(_row, _col).value for _col in range(_sheet.ncols)] for _row in range(_sheet.nrows)]
163
+ try:
164
+ _sheet = wb.sheet_by_index(_index)
165
+ except IndexError:
166
+ return []
167
+ else:
168
+ return [[_sheet.cell(_row, _col).value for _col in range(_sheet.ncols)] for _row in range(_sheet.nrows)]
164
169
 
165
170
  wb = open_workbook(file_path)
166
- used_sheet_index = set([input_filter[i] - 1 if input_filter[i] != 0 else 0 for i in
167
- [4, 36, 39, 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 72, 75, 78, 81, 84, 87,
168
- 90, 93, 96, 99, 102, 105, 108, 111, 114, 117, 120, 123, 126, 129]])
169
- contents = [[] if i not in used_sheet_index else _get_content_from_sheet(i)
170
- for i in range(max(used_sheet_index) + 1)]
171
-
171
+ contents = [_get_content_from_sheet(i) for i in range(100)]
172
172
  file_name = os.path.basename(file_path).rstrip(os.path.splitext(file_path)[-1])
173
173
  step_list = get_raw_data(contents, input_filter, file_name=file_name)
174
174
 
@@ -201,13 +201,15 @@ def get_raw_data(file_contents: List[List[Union[int, float, str, bool, list]]],
201
201
 
202
202
  """
203
203
 
204
- def datetime_parse(string, format):
204
+ def datetime_parse(string, f):
205
205
  try:
206
- return datetime.strptime(string, format)
206
+ return datetime.strptime(string, f)
207
207
  except ValueError as v:
208
- if len(v.args) > 0 and v.args[0].startswith('unconverted data remains: '):
208
+ if f.strip() == "":
209
+ return datetime_parser.parse(string)
210
+ elif len(v.args) > 0 and v.args[0].startswith('unconverted data remains: '):
209
211
  string = string[:-(len(v.args[0]) - 26)]
210
- return datetime.strptime(string, format)
212
+ return datetime.strptime(string, f)
211
213
  else:
212
214
  raise
213
215
 
@@ -215,52 +217,51 @@ def get_raw_data(file_contents: List[List[Union[int, float, str, bool, list]]],
215
217
  idx = step_index = 0
216
218
 
217
219
  header = input_filter[5]
218
- sample_info_index = input_filter[33:64]
219
220
  isotopic_data_index = input_filter[8:28]
221
+ sample_info_index = input_filter[33:65]
222
+ optional_info_index = input_filter[37:-6]
223
+ check_box_index = input_filter[-6:]
220
224
 
221
- while True:
225
+ timezone = sample_info_index[3] if sample_info_index[3] != "" else "utc"
226
+ while True: # measurment steps sloop
222
227
  # Zero datetime
223
228
  try:
224
- if input_filter[134]: # input_filter[134]: date in one string
225
- if sample_info_index[1].strip() != "":
226
- zero_date = datetime_parse(
227
- get_item(file_contents, sample_info_index[15:18], base=[1, 1 - idx, 1]), sample_info_index[1])
228
- else:
229
- zero_date = datetime_parser.parse(get_item(file_contents, sample_info_index[15:18], base=[1, 1 - idx, 1]))
229
+ if check_box_index[2]: # input_filter[134]: date in one string
230
+ zero_date = datetime_parse(
231
+ get_item(file_contents, sample_info_index[16:19], base=[1, 1 - idx, 1]), sample_info_index[1])
230
232
  else:
231
- zero_date = datetime(year=get_item(file_contents, sample_info_index[15:18], base=1),
232
- month=get_item(file_contents, sample_info_index[21:24], base=[1, 1 - idx, 1]),
233
- day=get_item(file_contents, sample_info_index[27:30], base=[1, 1 - idx, 1]))
234
-
235
- if input_filter[135]: # input_filter[135]: time in one string
236
- if sample_info_index[2].strip() != "":
237
- zero_time = datetime_parse(
238
- get_item(file_contents, sample_info_index[18:21], base=[1, 1 - idx, 1]), sample_info_index[2])
239
- else:
240
- zero_time = datetime_parser.parse(get_item(file_contents, sample_info_index[18:21], base=[1, 1 - idx, 1]))
233
+ zero_date = datetime(year=get_item(file_contents, sample_info_index[16:19], base=1),
234
+ month=get_item(file_contents, sample_info_index[22:25], base=[1, 1 - idx, 1]),
235
+ day=get_item(file_contents, sample_info_index[28:31], base=[1, 1 - idx, 1]))
236
+
237
+ if check_box_index[3]: # input_filter[135]: time in one string
238
+ zero_time = datetime_parse(
239
+ get_item(file_contents, sample_info_index[19:22], base=[1, 1 - idx, 1]), sample_info_index[2])
241
240
  else:
242
241
  zero_time = datetime(year=2020, month=12, day=31,
243
- hour=get_item(file_contents, sample_info_index[18:21], base=[1, 1 - idx, 1]),
244
- minute=get_item(file_contents, sample_info_index[24:27], base=[1, 1 - idx, 1]),
245
- second=get_item(file_contents, sample_info_index[30:33], base=[1, 1 - idx, 1]))
246
-
247
- zero_datetime = datetime(zero_date.year, zero_date.month, zero_date.day, zero_time.hour,
248
- zero_time.minute, zero_time.second).isoformat(timespec='seconds')
242
+ hour=get_item(file_contents, sample_info_index[19:22], base=[1, 1 - idx, 1]),
243
+ minute=get_item(file_contents, sample_info_index[25:28], base=[1, 1 - idx, 1]),
244
+ second=get_item(file_contents, sample_info_index[31:34], base=[1, 1 - idx, 1]))
245
+
246
+ zero_datetime = datetime(
247
+ zero_date.year, zero_date.month, zero_date.day, zero_time.hour, zero_time.minute, zero_time.second)
248
+ # adjust to UTC
249
+ zero_datetime = utc_dt(zero_datetime, tz=timezone).isoformat(timespec='seconds')
249
250
  except (TypeError, ValueError, IndexError):
250
251
  # print(f"Cannot parse zero datetime")
251
- zero_datetime = datetime(1949, 10, 1, 10, 0, 0).isoformat(timespec='seconds')
252
+ zero_datetime = datetime(1970, 1, 1, 0, 0, 0).isoformat(timespec='seconds')
252
253
 
253
254
  # Experiment name
254
255
  try:
255
- experiment_name = get_item(file_contents, sample_info_index[3:6], default="", base=[1, 1 - idx, 1]) if input_filter[4] > 0 else ""
256
+ experiment_name = get_item(file_contents, sample_info_index[4:7], default="", base=[1, 1 - idx, 1])
256
257
  except (TypeError, ValueError, IndexError):
257
258
  # print(f"Cannot parse experiment name")
258
- experiment_name = "ExpNameError"
259
+ experiment_name = "ExpName"
259
260
 
260
261
  # Step name
261
262
  try:
262
- step_name = get_item(file_contents, sample_info_index[6:9], default="", base=[1, 1 - idx, 1]) if input_filter[7] > 0 else ""
263
- if input_filter[133] and sample_info_index[0] != "":
263
+ step_name = get_item(file_contents, sample_info_index[7:10], default="", base=[1, 1 - idx, 1]) if input_filter[7] > 0 else ""
264
+ if check_box_index[1] and sample_info_index[0].strip() != "":
264
265
  _res = string_parser(sample_info_index[0], file_name)
265
266
  if _res is not None:
266
267
  experiment_name = _res.named.get("en", experiment_name)
@@ -276,15 +277,15 @@ def get_raw_data(file_contents: List[List[Union[int, float, str, bool, list]]],
276
277
  break
277
278
 
278
279
  # other information
279
- options = get_sample_info(file_contents, input_filter, default="", base=[1, 1 - idx, 1])
280
+ options = get_sample_info(file_contents, optional_info_index, default="", base=[1, 1 - idx, 1])
280
281
 
281
282
  current_step = [[step_name, zero_datetime, experiment_name, options]]
282
283
 
283
284
  break_num = 0
284
285
  cycle_num = 0
285
- f = float(input_filter[31])
286
+ f = float(input_filter[31]) # Intensity Scale Factor
286
287
  data_content = file_contents[input_filter[4] - 1 if input_filter[4] != 0 else 0]
287
- for i in range(2000):
288
+ for i in range(2000): # measurement cycle sloop
288
289
  if break_num < input_filter[29]:
289
290
  break_num += 1
290
291
  continue
@@ -307,7 +308,8 @@ def get_raw_data(file_contents: List[List[Union[int, float, str, bool, list]]],
307
308
  float(data_content[start_row + isotopic_data_index[ 0]][isotopic_data_index[ 1] - 1]) * f,
308
309
  ])
309
310
  except (ValueError, IndexError):
310
- # print(f"Cannot parse isotope data")
311
+ print(f"Cannot parse isotope data")
312
+ print(traceback.format_exc())
311
313
  current_step.append([
312
314
  str(cycle_num + 1), None, None, None, None, None, None, None, None, None, None,
313
315
  ])
@@ -330,7 +332,8 @@ def get_raw_data(file_contents: List[List[Union[int, float, str, bool, list]]],
330
332
  float(data_content[start_row][isotopic_data_index[ 1] + col_inc]) * f,
331
333
  ])
332
334
  except (ValueError, IndexError):
333
- # print(f"Cannot parse isotope data")
335
+ print(f"Cannot parse isotope data")
336
+ print(traceback.format_exc())
334
337
  current_step.append([
335
338
  str(cycle_num + 1), None, None, None, None, None, None, None, None, None, None,
336
339
  ])
@@ -345,18 +348,18 @@ def get_raw_data(file_contents: List[List[Union[int, float, str, bool, list]]],
345
348
  step_index += 1
346
349
  idx = input_filter[32] * step_index
347
350
 
348
- if not input_filter[132] or step_index >= 500: # input_filter[132]: multiple sequences
351
+ if not check_box_index[0] or step_index >= 500: # check_box_index[0]: multiple sequences
349
352
  break
350
353
 
351
354
  return step_list
352
355
 
353
356
 
354
- def get_sample_info(file_contents: list, input_filter: list, default="", base=1) -> dict:
357
+ def get_sample_info(file_contents: list, index_list: list, default="", base: Union[int, tuple, list] = 1) -> dict:
355
358
  """
356
359
  Parameters
357
360
  ----------
358
361
  file_contents
359
- input_filter
362
+ index_list
360
363
  default
361
364
  base
362
365
 
@@ -364,41 +367,40 @@ def get_sample_info(file_contents: list, input_filter: list, default="", base=1)
364
367
  -------
365
368
 
366
369
  """
367
- sample_info_index = input_filter[36:132]
368
370
  sample_info = DEFAULT_SAMPLE_INFO.copy()
369
371
  sample_info.update({
370
- "ExpName": get_item(file_contents, sample_info_index[0:3], default=default, base=base),
371
- "StepName": get_item(file_contents, sample_info_index[3:6], default=default, base=base),
372
- "SmpType": get_item(file_contents, sample_info_index[6:9], default=default, base=base),
373
- "StepLabel": get_item(file_contents, sample_info_index[9:12], default=default, base=base),
374
- "ZeroYear": get_item(file_contents, sample_info_index[12:15], default=default, base=base), # year
375
- "ZeroHour": get_item(file_contents, sample_info_index[15:18], default=default, base=base), # hour
376
- "ZeroMon": get_item(file_contents, sample_info_index[18:21], default=default, base=base), # month
377
- "ZeroMin": get_item(file_contents, sample_info_index[21:24], default=default, base=base), # minute
378
- "ZeroDay": get_item(file_contents, sample_info_index[24:27], default=default, base=base), # day
379
- "ZeroSec": get_item(file_contents, sample_info_index[27:30], default=default, base=base), # second
380
- "SmpName": get_item(file_contents, sample_info_index[30:33], default=default, base=base),
381
- "SmpLoc": get_item(file_contents, sample_info_index[33:36], default=default, base=base),
382
- "SmpMatr": get_item(file_contents, sample_info_index[36:39], default=default, base=base),
383
- "ExpType": get_item(file_contents, sample_info_index[39:42], default=default, base=base),
384
- "SmpWeight": get_item(file_contents, sample_info_index[42:45], default=default, base=base),
385
- "Stepunit": get_item(file_contents, sample_info_index[45:48], default=default, base=base),
386
- "HeatingTime": get_item(file_contents, sample_info_index[48:51], default=default, base=base),
387
- "InstrName": get_item(file_contents, sample_info_index[51:54], default=default, base=base),
388
- "Researcher": get_item(file_contents, sample_info_index[54:57], default=default, base=base),
389
- "Analyst": get_item(file_contents, sample_info_index[57:60], default=default, base=base),
390
- "Lab": get_item(file_contents, sample_info_index[60:63], default=default, base=base),
391
- "Jv": get_item(file_contents, sample_info_index[63:66], default=default, base=base),
392
- "Jsig": get_item(file_contents, sample_info_index[66:69], default=default, base=base),
393
- "CalcName": get_item(file_contents, sample_info_index[69:72], default=default, base=base),
394
- "IrraName": get_item(file_contents, sample_info_index[72:75], default=default, base=base),
395
- "IrraLabel": get_item(file_contents, sample_info_index[75:78], default=default, base=base),
396
- "IrraPosH": get_item(file_contents, sample_info_index[78:81], default=default, base=base),
397
- "IrraPosX": get_item(file_contents, sample_info_index[81:84], default=default, base=base),
398
- "IrraPosY": get_item(file_contents, sample_info_index[84:87], default=default, base=base),
399
- "StdName": get_item(file_contents, sample_info_index[87:90], default=default, base=base),
400
- "StdAge": get_item(file_contents, sample_info_index[90:93], default=default, base=base),
401
- "StdAgeSig": get_item(file_contents, sample_info_index[93:96], default=default, base=base),
372
+ "ExpName": get_item(file_contents, index_list[0:3], default=default, base=base),
373
+ "StepName": get_item(file_contents, index_list[3:6], default=default, base=base),
374
+ "SmpType": get_item(file_contents, index_list[6:9], default=default, base=base),
375
+ "StepLabel": get_item(file_contents, index_list[9:12], default=default, base=base),
376
+ "ZeroYear": get_item(file_contents, index_list[12:15], default=default, base=base), # year
377
+ "ZeroHour": get_item(file_contents, index_list[15:18], default=default, base=base), # hour
378
+ "ZeroMon": get_item(file_contents, index_list[18:21], default=default, base=base), # month
379
+ "ZeroMin": get_item(file_contents, index_list[21:24], default=default, base=base), # minute
380
+ "ZeroDay": get_item(file_contents, index_list[24:27], default=default, base=base), # day
381
+ "ZeroSec": get_item(file_contents, index_list[27:30], default=default, base=base), # second
382
+ "SmpName": get_item(file_contents, index_list[30:33], default=default, base=base),
383
+ "SmpLoc": get_item(file_contents, index_list[33:36], default=default, base=base),
384
+ "SmpMatr": get_item(file_contents, index_list[36:39], default=default, base=base),
385
+ "ExpType": get_item(file_contents, index_list[39:42], default=default, base=base),
386
+ "SmpWeight": get_item(file_contents, index_list[42:45], default=default, base=base),
387
+ "Stepunit": get_item(file_contents, index_list[45:48], default=default, base=base),
388
+ "HeatingTime": get_item(file_contents, index_list[48:51], default=default, base=base),
389
+ "InstrName": get_item(file_contents, index_list[51:54], default=default, base=base),
390
+ "Researcher": get_item(file_contents, index_list[54:57], default=default, base=base),
391
+ "Analyst": get_item(file_contents, index_list[57:60], default=default, base=base),
392
+ "Lab": get_item(file_contents, index_list[60:63], default=default, base=base),
393
+ "Jv": get_item(file_contents, index_list[63:66], default=default, base=base),
394
+ "Jsig": get_item(file_contents, index_list[66:69], default=default, base=base),
395
+ "CalcName": get_item(file_contents, index_list[69:72], default=default, base=base),
396
+ "IrraName": get_item(file_contents, index_list[72:75], default=default, base=base),
397
+ "IrraLabel": get_item(file_contents, index_list[75:78], default=default, base=base),
398
+ "IrraPosH": get_item(file_contents, index_list[78:81], default=default, base=base),
399
+ "IrraPosX": get_item(file_contents, index_list[81:84], default=default, base=base),
400
+ "IrraPosY": get_item(file_contents, index_list[84:87], default=default, base=base),
401
+ "StdName": get_item(file_contents, index_list[87:90], default=default, base=base),
402
+ "StdAge": get_item(file_contents, index_list[90:93], default=default, base=base),
403
+ "StdAgeSig": get_item(file_contents, index_list[93:96], default=default, base=base),
402
404
  # "Experiment Name": get_item(file_contents, sample_info_index[0:3], default=default, base=base),
403
405
  # "Step Name": get_item(file_contents, sample_info_index[3:6], default=default, base=base),
404
406
  # "Sample Type": get_item(file_contents, sample_info_index[6:9], default=default, base=base),
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: UTF-8 -*-
3
+ """
4
+ # ==========================================
5
+ # Copyright 2024 Yang
6
+ # webarar - EXPORT_TO_PDF_DATA_PROPERTIES
7
+ # ==========================================
8
+ #
9
+ #
10
+ #
11
+ """
12
+
13
+ def plot_data(data: dict):
14
+ """
15
+
16
+ Parameters
17
+ ----------
18
+ data: dict
19
+ - file_name: string
20
+ file name, like "24WHA0001"
21
+ - data: list of dicts
22
+ properties:
23
+ - name: string
24
+ diagram name, like "Age spectra"
25
+
26
+ - xAxis: list
27
+ properties:
28
+ - extend: list
29
+ limits of values of axis, like [0, 100]
30
+ - interval: list
31
+ sticks location, like [0, 20, 40, 60, 80, 100]
32
+ - title: string
33
+ - nameLocation: string
34
+ axis title location, 'middle'
35
+
36
+ - yAxis: same as xAxis
37
+
38
+ - series: list
39
+ properties:
40
+ - type: string
41
+ series type, 'line', 'scatter', 'text', and any string contains these characters
42
+ - id: string
43
+ - name: string
44
+ - color: string or list
45
+ color for outlines, color name | RGB triplet | Hex color code
46
+ - fillColor: string or list
47
+ color for filling markers, format is similar to that of color
48
+ - data: 2-dimensional array
49
+ [[x1, y1], [x2, y2], ...]
50
+
51
+ optional:
52
+ - lineCaps: string
53
+ for lines only, 'square', 'none', 'butt'
54
+ - text: string
55
+ for texts only
56
+ - size: int
57
+ for scatters only
58
+
59
+
60
+ Returns
61
+ -------
62
+
63
+ """
64
+ pass
65
+
66
+
67
+ data = {
68
+ "data": [
69
+ {
70
+ 'name': 'spectra',
71
+ 'xAxis': [{'extent': [0, 100], 'interval': [0, 20, 40, 60, 80, 100],
72
+ 'title': 'Cumulative <sup>39</sup>Ar Released (%)', 'title_location': 'middle', }],
73
+ 'yAxis': [{'extent': [0, 25], 'interval': [0, 5, 10, 15, 20, 25],
74
+ 'title': 'Apparent Age (Ma)', 'title_location': 'middle', }],
75
+ 'series': [
76
+ {
77
+ 'type': 'text', 'id': f'text_0', 'name': f'text_0', 'color': '#222222',
78
+ 'text': f'xxx<r>xxxxxx', 'size': 10,
79
+ 'data': [[5, 23]],
80
+ },
81
+ {
82
+ 'type': 'series.line', 'id': f'line_0', 'name': f'line_0',
83
+ 'color': '#333333',
84
+ 'data': [[]], 'line_caps': 'square',
85
+ },
86
+ {
87
+ 'type': 'series.line', 'id': f'line_2', 'name': f'line_2',
88
+ 'color': '#555555',
89
+ 'data': [[]], 'line_caps': 'square',
90
+ }
91
+ ]
92
+ }
93
+ ],
94
+ "file_name": "WHA"
95
+ }
ararpy/smp/basic.py CHANGED
@@ -11,6 +11,7 @@
11
11
  """
12
12
  # === Internal imports ===
13
13
  import os
14
+ import re
14
15
  import traceback
15
16
  import pandas as pd
16
17
  import numpy as np
@@ -521,15 +522,15 @@ def set_params(smp: Sample, params: Union[List, str], flag: Optional[str] = None
521
522
  smp.TotalParam[30] = [params[-5]] * n
522
523
  try:
523
524
  stand_time_second = [
524
- calc.basic.get_datetime(*smp.TotalParam[31][i].split('-')) - calc.basic.get_datetime(
525
- *smp.TotalParam[30][i].split('-')) for i in range(n)]
526
- except Exception as e:
527
- # print(f'Error in calculate standing duration: {traceback.format_exc()}')
528
- pass
525
+ calc.basic.get_datetime(*re.findall(r"\d+", smp.TotalParam[31][i])) - calc.basic.get_datetime(
526
+ *re.findall(r"\d+", smp.TotalParam[30][i])) for i in range(n)]
527
+ except TypeError:
528
+ print(f'Error in calculate standing duration: {traceback.format_exc()}')
529
529
  else:
530
530
  smp.TotalParam[32] = [i / (3600 * 24 * 365.242) for i in stand_time_second] # stand year
531
531
 
532
532
  elif flag == 'smp':
533
+ print(params)
533
534
  smp.TotalParam[67:71] = remove_none(smp.TotalParam[67:71], params[0:4], n, 71 - 67)
534
535
  smp.TotalParam[58:67] = remove_none(smp.TotalParam[58:67], params[4:13], n, 67 - 58)
535
536
  smp.TotalParam[97:100] = remove_none(smp.TotalParam[97:100], params[13:16], n, 100 - 97)
ararpy/smp/calculation.py CHANGED
@@ -64,10 +64,10 @@ def recalculate(
64
64
  if re_initial: # 1
65
65
  initial.re_set_smp(sample)
66
66
  # --- calculating ---
67
- if re_corr_blank: # 2
68
- corr.corr_blank(sample)
69
67
  if re_corr_gain: # 2 2024-10-04 add
70
68
  corr.corr_gain(sample)
69
+ if re_corr_blank: # 2
70
+ corr.corr_blank(sample)
71
71
  if re_corr_massdiscr: # 3
72
72
  corr.corr_massdiscr(sample)
73
73
  if re_corr_decay: # 4