ararpy 0.0.24__py3-none-any.whl → 0.1.11__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/files/raw_file.py CHANGED
@@ -14,6 +14,7 @@ from typing import List, Union
14
14
  import traceback
15
15
  import os
16
16
  import re
17
+ import pickle
17
18
  import chardet
18
19
  from xlrd import open_workbook
19
20
  from datetime import datetime
@@ -55,16 +56,16 @@ def open_file(file_path: str, input_filter: List[Union[str, int, bool]]):
55
56
  """
56
57
  extension = str(os.path.split(file_path)[-1]).split('.')[-1]
57
58
  try:
58
- handler = {'txt': open_raw_txt, 'excel': open_raw_xls, 'Qtegra Exported XLS': open_argus_exported_xls}[
59
- ['txt', 'excel', 'Qtegra Exported XLS'][int(input_filter[1])]]
59
+ handler = {'txt': open_raw_txt, 'excel': open_raw_xls,
60
+ 'Qtegra Exported XLS': open_qtegra_exported_xls, 'Seq': open_raw_seq}[
61
+ ['txt', 'excel', 'Qtegra Exported XLS', 'Seq'][int(input_filter[1])]]
60
62
  except KeyError:
61
63
  print(traceback.format_exc())
62
64
  raise FileNotFoundError("Wrong File.")
63
- data, _ = handler(file_path, input_filter)
64
- return {'data': data, 'type': extension}
65
+ return handler(file_path, input_filter)
65
66
 
66
67
 
67
- def open_argus_exported_xls(filepath, input_filter=None):
68
+ def open_qtegra_exported_xls(filepath, input_filter=None):
68
69
  if input_filter is None:
69
70
  input_filter = []
70
71
  try:
@@ -85,7 +86,10 @@ def open_argus_exported_xls(filepath, input_filter=None):
85
86
  # if the first item of each row is float (1.0, 2.0, ...) this row is the header of a step.
86
87
  if isinstance(each_row[0], float):
87
88
  each_row[0] = int(each_row[0])
88
- each_row[1] = datetime.strptime(each_row[1], '%m/%d/%Y %H:%M:%S').isoformat(timespec='seconds')
89
+ if "M" in each_row[1].upper():
90
+ each_row[1] = datetime.strptime(each_row[1], '%m/%d/%Y %I:%M:%S %p').isoformat(timespec='seconds')
91
+ else:
92
+ each_row[1] = datetime.strptime(each_row[1], '%m/%d/%Y %H:%M:%S').isoformat(timespec='seconds')
89
93
  step_header.append(each_row)
90
94
  for step_index, each_step_header in enumerate(step_header):
91
95
  row_start_number = value.index(each_step_header)
@@ -106,7 +110,7 @@ def open_argus_exported_xls(filepath, input_filter=None):
106
110
  except Exception as e:
107
111
  raise ValueError('Error in opening the original file: %s' % str(e))
108
112
  else:
109
- return step_list, {}
113
+ return {'data': step_list}
110
114
 
111
115
 
112
116
  def open_raw_txt(file_path, input_filter: List[Union[str, int]]):
@@ -133,10 +137,8 @@ def open_raw_txt(file_path, input_filter: List[Union[str, int]]):
133
137
  for line in contents.decode(encoding=encoding["encoding"]).split('\r\n')]
134
138
 
135
139
  file_name = os.path.basename(file_path).rstrip(os.path.splitext(file_path)[-1])
136
- sample_info = get_sample_info([lines], input_filter)
137
140
  step_list = get_raw_data([lines], input_filter, file_name=file_name)
138
-
139
- return step_list, sample_info
141
+ return {'data': step_list}
140
142
 
141
143
 
142
144
  def open_raw_xls(file_path, input_filter: List[Union[str, int]]):
@@ -162,16 +164,27 @@ def open_raw_xls(file_path, input_filter: List[Union[str, int]]):
162
164
 
163
165
  wb = open_workbook(file_path)
164
166
  used_sheet_index = set([input_filter[i] - 1 if input_filter[i] != 0 else 0 for i in
165
- [4, 34, 37, 40, 43, 46, 49, 52, 55, 58, 61, 64, 67, 70, 73, 76, 79, 82, 85,
166
- 88, 91, 94, 97, 100, 103, 106, 109, 112, 115, 118, 121, 124, 127]])
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]])
167
169
  contents = [[] if i not in used_sheet_index else _get_content_from_sheet(i)
168
170
  for i in range(max(used_sheet_index) + 1)]
169
171
 
170
172
  file_name = os.path.basename(file_path).rstrip(os.path.splitext(file_path)[-1])
171
- sample_info = get_sample_info(contents, input_filter)
172
173
  step_list = get_raw_data(contents, input_filter, file_name=file_name)
173
174
 
174
- return step_list, sample_info
175
+ return {'data': step_list}
176
+
177
+
178
+ def open_raw_seq(file_path, input_filter=None):
179
+ with open(file_path, 'rb') as f:
180
+ sequences = pickle.load(f)
181
+ name_list = []
182
+ for seq in sequences:
183
+ while seq.name in name_list:
184
+ seq.name = f"{seq.name}-{seq.index}"
185
+ name_list.append(seq.name)
186
+
187
+ return {'sequences': sequences}
175
188
 
176
189
 
177
190
  def get_raw_data(file_contents: List[List[Union[int, float, str, bool, list]]], input_filter: list,
@@ -187,136 +200,236 @@ def get_raw_data(file_contents: List[List[Union[int, float, str, bool, list]]],
187
200
  -------
188
201
 
189
202
  """
190
- if input_filter[131]: # input_filter[131]: date in one string
191
- if input_filter[32].strip() != "":
192
- zero_date = datetime.strptime(get_item(file_contents, input_filter[46:49], based=1),
193
- input_filter[32])
194
- else:
195
- zero_date = datetime_parser.parse(get_item(file_contents, input_filter[46:49], based=1))
196
- else:
197
- zero_date = datetime(year=get_item(file_contents, input_filter[46:49], based=1),
198
- month=get_item(file_contents, input_filter[52:55], based=1),
199
- day=get_item(file_contents, input_filter[58:61], based=1))
200
-
201
- if input_filter[132]: # input_filter[132]: time in one string
202
- if input_filter[33].strip() != "":
203
- zero_time = datetime.strptime(get_item(file_contents, input_filter[49:52], based=1),
204
- input_filter[33])
205
- else:
206
- zero_time = datetime_parser.parse(get_item(file_contents, input_filter[49:52], based=1))
207
- else:
208
- zero_time = datetime(year=2020, month=12, day=31,
209
- hour=get_item(file_contents, input_filter[49:52], based=1),
210
- minute=get_item(file_contents, input_filter[55:58], based=1),
211
- second=get_item(file_contents, input_filter[61:64], based=1))
212
-
213
- zero_datetime = datetime(zero_date.year, zero_date.month, zero_date.day, zero_time.hour,
214
- zero_time.minute, zero_time.second).isoformat(timespec='seconds')
215
-
216
- # Get step name
217
- experiment_name = get_item(file_contents, input_filter[34:37], default="", based=1) if input_filter[35] > 0 else ""
218
- step_name = get_item(file_contents, input_filter[37:40], default="", based=1) if input_filter[38] > 0 else ""
219
- if input_filter[130] and input_filter[31] != "":
220
- _res = string_parser(input_filter[31], file_name)
221
- if _res is not None:
222
- experiment_name = _res.named.get("en", experiment_name)
223
- step_index = _res.named.get("sn", step_name)
224
- if step_index.isnumeric():
225
- step_name = f"{experiment_name}-{int(step_index):02d}"
203
+
204
+ def datetime_parse(string, format):
205
+ try:
206
+ return datetime.strptime(string, format)
207
+ except ValueError as v:
208
+ if len(v.args) > 0 and v.args[0].startswith('unconverted data remains: '):
209
+ string = string[:-(len(v.args[0]) - 26)]
210
+ return datetime.strptime(string, format)
226
211
  else:
227
- step_name = f"{experiment_name}-{step_index}"
228
- step_list = [[[step_name, zero_datetime, experiment_name]]]
229
-
230
- break_num = 0
231
- step_num = 0
232
- data_content = file_contents[input_filter[4] - 1 if input_filter[4] != 0 else 0]
233
- for step_index in range(2000):
234
- start_row = input_filter[5] + input_filter[27] * step_num + input_filter[28] * step_num
212
+ raise
213
+
214
+ step_list = []
215
+ idx = step_index = 0
216
+
217
+ header = input_filter[5]
218
+ sample_info_index = input_filter[33:64]
219
+ isotopic_data_index = input_filter[8:28]
220
+
221
+ while True:
222
+ # Zero datetime
235
223
  try:
236
- if data_content[start_row] == "" or data_content[start_row] == [""]:
237
- break
238
- except IndexError:
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]))
230
+ 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]))
241
+ else:
242
+ 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')
249
+ except (TypeError, ValueError, IndexError):
250
+ # print(f"Cannot parse zero datetime")
251
+ zero_datetime = datetime(1949, 10, 1, 10, 0, 0).isoformat(timespec='seconds')
252
+
253
+ # Experiment name
254
+ 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
+ except (TypeError, ValueError, IndexError):
257
+ # print(f"Cannot parse experiment name")
258
+ experiment_name = "ExpNameError"
259
+
260
+ # Step name
261
+ 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] != "":
264
+ _res = string_parser(sample_info_index[0], file_name)
265
+ if _res is not None:
266
+ experiment_name = _res.named.get("en", experiment_name)
267
+ step_index = _res.named.get("sn", step_name)
268
+ if step_index.isnumeric():
269
+ step_name = f"{experiment_name}-{int(step_index):02d}"
270
+ else:
271
+ step_name = f"{experiment_name}-{step_index}"
272
+ if step_name == "":
273
+ raise ValueError(f"Step name not found")
274
+ except (TypeError, ValueError, IndexError):
275
+ # When parsing the step name fails, the end of the file has been reached
239
276
  break
240
- if break_num < input_filter[28]:
241
- break_num += 1
242
- continue
277
+
278
+ # other information
279
+ options = get_sample_info(file_contents, input_filter, default="", base=[1, 1 - idx, 1])
280
+
281
+ current_step = [[step_name, zero_datetime, experiment_name, options]]
282
+
243
283
  break_num = 0
244
- step_num += 1
245
- if int(input_filter[6]) == 0: # == 0, vertical
246
- step_list[0].append([
247
- str(step_num),
248
- # in sequence: Ar36, Ar37, Ar38, Ar39, Ar40
249
- float(data_content[start_row + input_filter[25] - 1][input_filter[26] - 1]),
250
- float(data_content[start_row + input_filter[25] - 1][input_filter[24] - 1]),
251
- float(data_content[start_row + input_filter[21] - 1][input_filter[22] - 1]),
252
- float(data_content[start_row + input_filter[21] - 1][input_filter[20] - 1]),
253
- float(data_content[start_row + input_filter[17] - 1][input_filter[18] - 1]),
254
- float(data_content[start_row + input_filter[17] - 1][input_filter[16] - 1]),
255
- float(data_content[start_row + input_filter[13] - 1][input_filter[14] - 1]),
256
- float(data_content[start_row + input_filter[13] - 1][input_filter[12] - 1]),
257
- float(data_content[start_row + input_filter[9] - 1][input_filter[10] - 1]),
258
- float(data_content[start_row + input_filter[9] - 1][input_filter[8] - 1]),
259
- ])
260
- elif int(input_filter[6]) == 1: # == 1, horizontal
261
- step_list[0].append([
262
- str(step_num),
263
- # Ar36, Ar37, Ar38, Ar39, Ar40
264
- float(data_content[start_row][input_filter[26] - 1]), float(data_content[start_row][input_filter[24] - 1]),
265
- float(data_content[start_row][input_filter[22] - 1]), float(data_content[start_row][input_filter[20] - 1]),
266
- float(data_content[start_row][input_filter[18] - 1]), float(data_content[start_row][input_filter[16] - 1]),
267
- float(data_content[start_row][input_filter[14] - 1]), float(data_content[start_row][input_filter[12] - 1]),
268
- float(data_content[start_row][input_filter[10] - 1]), float(data_content[start_row][input_filter[8] - 1]),
269
- ])
270
- else:
271
- raise ValueError
284
+ cycle_num = 0
285
+ f = float(input_filter[31])
286
+ data_content = file_contents[input_filter[4] - 1 if input_filter[4] != 0 else 0]
287
+ for i in range(2000):
288
+ if break_num < input_filter[29]:
289
+ break_num += 1
290
+ continue
291
+ break_num = 0
292
+ if int(input_filter[6]) == 0: # == 0, vertical
293
+ start_row = input_filter[28] * cycle_num + input_filter[29] * cycle_num + header + idx - 1
294
+ try:
295
+ current_step.append([
296
+ str(cycle_num + 1),
297
+ # in sequence: Ar36, Ar37, Ar38, Ar39, Ar40
298
+ float(data_content[start_row + isotopic_data_index[18]][isotopic_data_index[19] - 1]),
299
+ float(data_content[start_row + isotopic_data_index[16]][isotopic_data_index[17] - 1]) * f,
300
+ float(data_content[start_row + isotopic_data_index[14]][isotopic_data_index[15] - 1]),
301
+ float(data_content[start_row + isotopic_data_index[12]][isotopic_data_index[13] - 1]) * f,
302
+ float(data_content[start_row + isotopic_data_index[10]][isotopic_data_index[11] - 1]),
303
+ float(data_content[start_row + isotopic_data_index[ 8]][isotopic_data_index[ 9] - 1]) * f,
304
+ float(data_content[start_row + isotopic_data_index[ 6]][isotopic_data_index[ 7] - 1]),
305
+ float(data_content[start_row + isotopic_data_index[ 4]][isotopic_data_index[ 5] - 1]) * f,
306
+ float(data_content[start_row + isotopic_data_index[ 2]][isotopic_data_index[ 3] - 1]),
307
+ float(data_content[start_row + isotopic_data_index[ 0]][isotopic_data_index[ 1] - 1]) * f,
308
+ ])
309
+ except (ValueError, IndexError):
310
+ # print(f"Cannot parse isotope data")
311
+ current_step.append([
312
+ str(cycle_num + 1), None, None, None, None, None, None, None, None, None, None,
313
+ ])
314
+ elif int(input_filter[6]) == 1: # == 1, horizontal
315
+ start_row = input_filter[5] + idx
316
+ col_inc = input_filter[28] * cycle_num + input_filter[29] * cycle_num - 1
317
+ try:
318
+ current_step.append([
319
+ str(cycle_num + 1),
320
+ # Ar36, Ar37, Ar38, Ar39, Ar40
321
+ float(data_content[start_row][isotopic_data_index[19] + col_inc]),
322
+ float(data_content[start_row][isotopic_data_index[17] + col_inc]) * f,
323
+ float(data_content[start_row][isotopic_data_index[15] + col_inc]),
324
+ float(data_content[start_row][isotopic_data_index[13] + col_inc]) * f,
325
+ float(data_content[start_row][isotopic_data_index[11] + col_inc]),
326
+ float(data_content[start_row][isotopic_data_index[ 9] + col_inc]) * f,
327
+ float(data_content[start_row][isotopic_data_index[ 7] + col_inc]),
328
+ float(data_content[start_row][isotopic_data_index[ 5] + col_inc]) * f,
329
+ float(data_content[start_row][isotopic_data_index[ 3] + col_inc]),
330
+ float(data_content[start_row][isotopic_data_index[ 1] + col_inc]) * f,
331
+ ])
332
+ except (ValueError, IndexError):
333
+ # print(f"Cannot parse isotope data")
334
+ current_step.append([
335
+ str(cycle_num + 1), None, None, None, None, None, None, None, None, None, None,
336
+ ])
337
+ else:
338
+ raise ValueError(f"{input_filter[6]} not in [0, 1]")
339
+
340
+ cycle_num += 1
341
+ if cycle_num >= input_filter[7]:
342
+ break
343
+
344
+ step_list.append(current_step)
345
+ step_index += 1
346
+ idx = input_filter[32] * step_index
347
+
348
+ if not input_filter[132] or step_index >= 500: # input_filter[132]: multiple sequences
349
+ break
272
350
 
273
351
  return step_list
274
352
 
275
353
 
276
- def get_sample_info(file_contents: list, input_filter: list) -> dict:
354
+ def get_sample_info(file_contents: list, input_filter: list, default="", base=1) -> dict:
277
355
  """
278
356
  Parameters
279
357
  ----------
280
358
  file_contents
281
359
  input_filter
360
+ default
361
+ base
282
362
 
283
363
  Returns
284
364
  -------
285
365
 
286
366
  """
367
+ sample_info_index = input_filter[36:132]
287
368
  sample_info = DEFAULT_SAMPLE_INFO.copy()
288
369
  sample_info.update({
289
- "Experiment Name": get_item(file_contents, input_filter[34:37], default="", based=1),
290
- "Step Name": get_item(file_contents, input_filter[37:40], default="", based=1),
291
- "Sample Type": get_item(file_contents, input_filter[40:43], default="", based=1),
292
- "Step Label": get_item(file_contents, input_filter[43:46], default="", based=1),
293
- "Zero Date Year": get_item(file_contents, input_filter[46:49], default="", based=1),
294
- "Zero Time Hour": get_item(file_contents, input_filter[49:52], default="", based=1),
295
- "Zero Date Month": get_item(file_contents, input_filter[52:55], default="", based=1),
296
- "Zero Time Minute": get_item(file_contents, input_filter[55:58], default="", based=1),
297
- "Zero Date Day": get_item(file_contents, input_filter[58:61], default="", based=1),
298
- "Zero Time Second": get_item(file_contents, input_filter[61:64], default="", based=1),
299
- "Sample Name": get_item(file_contents, input_filter[64:67], default="", based=1),
300
- "Sample location": get_item(file_contents, input_filter[67:70], default="", based=1),
301
- "Sample Material": get_item(file_contents, input_filter[70:73], default="", based=1),
302
- "Experiment Type": get_item(file_contents, input_filter[73:76], default="", based=1),
303
- "Sample Weight": get_item(file_contents, input_filter[76:79], default="", based=1),
304
- "Step unit": get_item(file_contents, input_filter[79:82], default="", based=1),
305
- "Heating time": get_item(file_contents, input_filter[82:85], default="", based=1),
306
- "Instrument name": get_item(file_contents, input_filter[85:88], default="", based=1),
307
- "Researcher": get_item(file_contents, input_filter[88:91], default="", based=1),
308
- "Analyst": get_item(file_contents, input_filter[91:94], default="", based=1),
309
- "Laboratory": get_item(file_contents, input_filter[94:97], default="", based=1),
310
- "J value": get_item(file_contents, input_filter[97:100], default="", based=1),
311
- "J value error": get_item(file_contents, input_filter[100:103], default="", based=1),
312
- "Calc params": get_item(file_contents, input_filter[103:106], default="", based=1),
313
- "Irra name": get_item(file_contents, input_filter[106:109], default="", based=1),
314
- "Irra label": get_item(file_contents, input_filter[109:112], default="", based=1),
315
- "Irra position H": get_item(file_contents, input_filter[112:115], default="", based=1),
316
- "Irra position X": get_item(file_contents, input_filter[115:118], default="", based=1),
317
- "Irra position Y": get_item(file_contents, input_filter[118:121], default="", based=1),
318
- "Standard name": get_item(file_contents, input_filter[121:124], default="", based=1),
319
- "Standard age": get_item(file_contents, input_filter[124:127], default="", based=1),
320
- "Standard age error": get_item(file_contents, input_filter[127:130], default="", based=1)
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),
402
+ # "Experiment Name": get_item(file_contents, sample_info_index[0:3], default=default, base=base),
403
+ # "Step Name": get_item(file_contents, sample_info_index[3:6], default=default, base=base),
404
+ # "Sample Type": get_item(file_contents, sample_info_index[6:9], default=default, base=base),
405
+ # "Step Label": get_item(file_contents, sample_info_index[9:12], default=default, base=base),
406
+ # "Zero Date Year": get_item(file_contents, sample_info_index[12:15], default=default, base=base),
407
+ # "Zero Time Hour": get_item(file_contents, sample_info_index[15:18], default=default, base=base),
408
+ # "Zero Date Month": get_item(file_contents, sample_info_index[18:21], default=default, base=base),
409
+ # "Zero Time Minute": get_item(file_contents, sample_info_index[21:24], default=default, base=base),
410
+ # "Zero Date Day": get_item(file_contents, sample_info_index[24:27], default=default, base=base),
411
+ # "Zero Time Second": get_item(file_contents, sample_info_index[27:30], default=default, base=base),
412
+ # "Sample Name": get_item(file_contents, sample_info_index[30:33], default=default, base=base),
413
+ # "Sample location": get_item(file_contents, sample_info_index[33:36], default=default, base=base),
414
+ # "Sample Material": get_item(file_contents, sample_info_index[36:39], default=default, base=base),
415
+ # "Experiment Type": get_item(file_contents, sample_info_index[39:42], default=default, base=base),
416
+ # "Sample Weight": get_item(file_contents, sample_info_index[42:45], default=default, base=base),
417
+ # "Step unit": get_item(file_contents, sample_info_index[45:48], default=default, base=base),
418
+ # "Heating time": get_item(file_contents, sample_info_index[48:51], default=default, base=base),
419
+ # "Instrument name": get_item(file_contents, sample_info_index[51:54], default=default, base=base),
420
+ # "Researcher": get_item(file_contents, sample_info_index[54:57], default=default, base=base),
421
+ # "Analyst": get_item(file_contents, sample_info_index[57:60], default=default, base=base),
422
+ # "Laboratory": get_item(file_contents, sample_info_index[60:63], default=default, base=base),
423
+ # "J value": get_item(file_contents, sample_info_index[63:66], default=default, base=base),
424
+ # "J value error": get_item(file_contents, sample_info_index[66:69], default=default, base=base),
425
+ # "Calc params": get_item(file_contents, sample_info_index[69:72], default=default, base=base),
426
+ # "Irra name": get_item(file_contents, sample_info_index[72:75], default=default, base=base),
427
+ # "Irra label": get_item(file_contents, sample_info_index[75:78], default=default, base=base),
428
+ # "Irra position H": get_item(file_contents, sample_info_index[78:81], default=default, base=base),
429
+ # "Irra position X": get_item(file_contents, sample_info_index[81:84], default=default, base=base),
430
+ # "Irra position Y": get_item(file_contents, sample_info_index[84:87], default=default, base=base),
431
+ # "Standard name": get_item(file_contents, sample_info_index[87:90], default=default, base=base),
432
+ # "Standard age": get_item(file_contents, sample_info_index[90:93], default=default, base=base),
433
+ # "Standard age error": get_item(file_contents, sample_info_index[93:96], default=default, base=base),
321
434
  })
322
435
  return sample_info
ararpy/smp/__init__.py CHANGED
@@ -1,11 +1,10 @@
1
1
 
2
2
  from . import (
3
- sample as samples, consts, json, basic, corr, raw, initial,
4
- plots, style, table, calculation, export
3
+ sample as samples, info, consts, json, basic, corr, raw, initial,
4
+ plots, style, table, calculation, export, diffusion_funcs
5
5
  )
6
6
 
7
7
  Sample = samples.Sample
8
- Info = samples.Info
9
8
  Table = samples.Table
10
9
  Plot = samples.Plot
11
10
  Set = samples.Plot.Set
ararpy/smp/basic.py CHANGED
@@ -18,7 +18,7 @@ import copy
18
18
  from typing import Optional, Union, List
19
19
  from .. import calc
20
20
  from ..files.basic import (read as read_params)
21
- from .sample import Sample, Info, Table, Plot, ArArData, ArArBasic, Sequence, RawData
21
+ from .sample import Sample, Table, Plot, ArArData, ArArBasic, Sequence, RawData
22
22
 
23
23
  Set = Plot.Set
24
24
  Label = Plot.Label
@@ -42,9 +42,39 @@ def calc_apparent_ages(smp: Sample):
42
42
  -------
43
43
 
44
44
  """
45
- age = calc_age(smp=smp)
46
- smp.ApparentAgeValues[2:6] = age
47
- smp.PublishValues[5:7] = copy.deepcopy(age[0:2])
45
+ if smp.Info.sample.type == "Unknown":
46
+ age = calc_age(smp=smp)
47
+ smp.ApparentAgeValues[2:6] = age
48
+ smp.PublishValues[5:7] = copy.deepcopy(age[0:2])
49
+ if smp.Info.sample.type == "Standard":
50
+ j = calc_j(smp=smp)
51
+ smp.ApparentAgeValues[2:4] = j
52
+ smp.PublishValues[5:7] = copy.deepcopy(j[0:2])
53
+ if smp.Info.sample.type == "Air":
54
+ mdf = calc_mdf(smp=smp)
55
+ smp.ApparentAgeValues[2:4] = mdf
56
+ smp.PublishValues[5:7] = copy.deepcopy(mdf[0:2])
57
+
58
+
59
+ def calc_j(ar40ar39=None, params: dict = None, smp: Sample = None, index: list = None):
60
+ std_age, std_err = smp.TotalParam[59:61]
61
+ r, sr = smp.ApparentAgeValues[0:2] # ar40ar39, error
62
+ f, rsf = smp.TotalParam[34:36] # L, sL
63
+ j, sj = calc.jvalue.j_value(std_age, std_err, r, sr, f, rsf)
64
+ return [j.tolist(), sj.tolist()]
65
+
66
+
67
+ def calc_mdf(ar40ar36=None, params: dict = None, smp: Sample = None, index: list = None):
68
+ std_air, std_err = smp.TotalParam[93:95]
69
+ m36, sm36 = smp.TotalParam[71:73]
70
+ m40, sm40 = smp.TotalParam[79:81]
71
+ air, sair = smp.ApparentAgeValues[0:2] # ar40ar36 air, error
72
+ discrimination_method = smp.TotalParam[100] # L, sL
73
+ mdf = []
74
+ for i in range(len(std_air)):
75
+ k = calc.corr.mdf(air[i], sair[i], m36[i], m40[i], std_air[i], std_err[i]) # linear, exp, pow
76
+ mdf.append({"linear": k[0:2], "exp": k[2:4], "pow": k[4:6]}[discrimination_method[i].lower()])
77
+ return np.transpose(mdf).tolist()
48
78
 
49
79
 
50
80
  def calc_age(ar40ar39=None, params: dict = None, smp: Sample = None, index: list = None):
@@ -156,7 +186,7 @@ def get_content_dict(smp: Sample):
156
186
  ))
157
187
 
158
188
 
159
- def get_dict_from_obj(obj: (Sample, Info, Plot, Table, Set, Label, Axis, Text,
189
+ def get_dict_from_obj(obj: (Sample, Plot, Table, Set, Label, Axis, Text,
160
190
  ArArBasic, ArArData, Sequence, RawData)):
161
191
  """
162
192
 
@@ -170,7 +200,7 @@ def get_dict_from_obj(obj: (Sample, Info, Plot, Table, Set, Label, Axis, Text,
170
200
  """
171
201
  res = {}
172
202
  for key, attr in obj.__dict__.items():
173
- if not isinstance(attr, (Sample, Info, Plot, Table, Set, Label, Axis, Text,
203
+ if not isinstance(attr, (Sample, Plot, Table, Set, Label, Axis, Text,
174
204
  ArArBasic, ArArData, Sequence, RawData)):
175
205
  res.update({key: attr})
176
206
  else:
@@ -213,7 +243,7 @@ def get_component_byid(smp: Sample, comp_id: str):
213
243
 
214
244
  """
215
245
  for key, val in smp.__dict__.items():
216
- if isinstance(val, (Plot, Table, Info, ArArBasic)) and getattr(val, 'id') == comp_id:
246
+ if isinstance(val, (Plot, Table, ArArBasic)) and getattr(val, 'id') == comp_id:
217
247
  return val
218
248
 
219
249
 
@@ -252,7 +282,8 @@ def update_plot_from_dict(plot, attrs: dict):
252
282
  if isinstance(v1, dict):
253
283
  if hasattr(_plot, k1):
254
284
  if isinstance(getattr(_plot, k1), dict):
255
- setattr(_plot, k1, v1)
285
+ setattr(_plot, k1, calc.basic.update_dicts(getattr(_plot, k1), v1))
286
+ # setattr(_plot, k1, v1)
256
287
  else:
257
288
  _do(getattr(_plot, k1), v1)
258
289
  else:
@@ -262,6 +293,39 @@ def update_plot_from_dict(plot, attrs: dict):
262
293
  return plot
263
294
 
264
295
 
296
+ def update_object_from_dict(obj, attrs: dict):
297
+ """
298
+ update object
299
+ Parameters
300
+ ----------
301
+ obj
302
+ attrs
303
+
304
+ Returns
305
+ -------
306
+
307
+ """
308
+ def _do(_obj, _attrs: dict):
309
+
310
+ for k1, v1 in _attrs.items():
311
+ if hasattr(_obj, k1):
312
+ if getattr(_obj, k1) == v1:
313
+ continue
314
+ elif isinstance(v1, dict):
315
+ if isinstance(getattr(_obj, k1), dict):
316
+ setattr(_obj, k1, calc.basic.update_dicts(getattr(_obj, k1), v1))
317
+ # setattr(_plot, k1, v1)
318
+ else:
319
+ _do(getattr(_obj, k1), v1)
320
+ else:
321
+ setattr(_obj, k1, v1)
322
+ else:
323
+ setattr(_obj, k1, v1)
324
+
325
+ _do(_obj=obj, _attrs=attrs)
326
+ return obj
327
+
328
+
265
329
  # =======================
266
330
  # Merge sample instances
267
331
  # =======================
@@ -307,9 +371,12 @@ def get_merged_smp(a: Sample, b: (Sample, dict)):
307
371
 
308
372
  for name, attr in b.items():
309
373
  if hasattr(a, name):
310
- if isinstance(attr, (Plot, Table, Info, Plot.BasicAttr)):
374
+ if isinstance(attr, (Plot, Table, ArArBasic, Plot.BasicAttr)):
311
375
  if not type(getattr(a, name)) == type(attr):
312
- setattr(a, name, type(attr)())
376
+ if isinstance(getattr(a, name), dict):
377
+ setattr(a, name, type(attr)(**getattr(a, name)))
378
+ else:
379
+ setattr(a, name, type(attr)())
313
380
  get_merged_smp(getattr(a, name), attr)
314
381
  if isinstance(attr, dict) and isinstance(getattr(a, name), dict):
315
382
  setattr(a, name, calc.basic.merge_dicts(getattr(a, name), attr))
@@ -376,7 +443,7 @@ def get_diff_smp(backup: (dict, Sample), smp: (dict, Sample)):
376
443
  res.update({name: attr})
377
444
  continue
378
445
  if isinstance(attr, (Plot, Table, Plot.Text, Plot.Axis, Plot.Set,
379
- Plot.Label, Plot.BasicAttr, Info, ArArBasic, ArArData)):
446
+ Plot.Label, Plot.BasicAttr, ArArBasic, ArArData)):
380
447
  _res = get_diff_smp(backup[name].__dict__, attr.__dict__)
381
448
  if _res != {}:
382
449
  res.update({name: _res})
@@ -470,7 +537,7 @@ def set_params(smp: Sample, params: Union[List, str], flag: Optional[str] = None
470
537
  smp.TotalParam[120:123] = remove_none(smp.TotalParam[120:123], params[21:24], n, 123 - 120)
471
538
  smp.TotalParam[100:114] = remove_none(
472
539
  smp.TotalParam[100:114],
473
- [['Linear', 'Exponential', 'Power'][params[24:27].index(True)], *params[27:]], n, 114 - 100)
540
+ [['Linear', 'Exponential', 'Power'][params[24:27].index(True)] if True in params[24:27] else '', *params[27:]], n, 114 - 100)
474
541
  else:
475
542
  raise KeyError(f"{flag = } is not supported. It must be 'calc' for Calc Params, "
476
543
  f"'irra' for Irradiation Params, or 'smp' for Sample Params.")