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/__init__.py +3 -5
- ararpy/calc/age.py +2 -2
- ararpy/calc/arr.py +25 -21
- ararpy/calc/basic.py +23 -0
- ararpy/calc/corr.py +32 -17
- ararpy/calc/err.py +9 -2
- ararpy/calc/jvalue.py +3 -2
- ararpy/calc/raw_funcs.py +1 -1
- ararpy/calc/regression.py +64 -4
- ararpy/examples/22WHA0433.age +0 -0
- ararpy/examples/22WHA0433.arr +0 -0
- ararpy/files/basic.py +2 -2
- ararpy/files/calc_file.py +1 -2
- ararpy/files/raw_file.py +238 -125
- ararpy/smp/__init__.py +2 -3
- ararpy/smp/basic.py +79 -12
- ararpy/smp/corr.py +97 -60
- ararpy/smp/diffusion_funcs.py +4745 -0
- ararpy/smp/export.py +287 -343
- ararpy/smp/info.py +23 -0
- ararpy/smp/initial.py +43 -20
- ararpy/smp/json.py +2 -2
- ararpy/smp/plots.py +151 -20
- ararpy/smp/raw.py +20 -14
- ararpy/smp/sample.py +44 -29
- ararpy/smp/style.py +5 -4
- ararpy/smp/table.py +66 -15
- ararpy/test.py +5 -3
- {ararpy-0.0.24.dist-info → ararpy-0.1.11.dist-info}/METADATA +1 -1
- ararpy-0.1.11.dist-info/RECORD +60 -0
- {ararpy-0.0.24.dist-info → ararpy-0.1.11.dist-info}/WHEEL +1 -1
- ararpy-0.0.24.dist-info/RECORD +0 -58
- {ararpy-0.0.24.dist-info → ararpy-0.1.11.dist-info}/LICENSE +0 -0
- {ararpy-0.0.24.dist-info → ararpy-0.1.11.dist-info}/top_level.txt +0 -0
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,
|
|
59
|
-
|
|
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
|
-
|
|
64
|
-
return {'data': data, 'type': extension}
|
|
65
|
+
return handler(file_path, input_filter)
|
|
65
66
|
|
|
66
67
|
|
|
67
|
-
def
|
|
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
|
-
|
|
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,
|
|
166
|
-
|
|
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
|
|
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
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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
|
|
237
|
-
|
|
238
|
-
|
|
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
|
-
|
|
241
|
-
|
|
242
|
-
|
|
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
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
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
|
-
"
|
|
290
|
-
"
|
|
291
|
-
"
|
|
292
|
-
"
|
|
293
|
-
"
|
|
294
|
-
"
|
|
295
|
-
"
|
|
296
|
-
"
|
|
297
|
-
"
|
|
298
|
-
"
|
|
299
|
-
"
|
|
300
|
-
"
|
|
301
|
-
"
|
|
302
|
-
"
|
|
303
|
-
"
|
|
304
|
-
"
|
|
305
|
-
"
|
|
306
|
-
"
|
|
307
|
-
"Researcher": get_item(file_contents,
|
|
308
|
-
"Analyst": get_item(file_contents,
|
|
309
|
-
"
|
|
310
|
-
"
|
|
311
|
-
"
|
|
312
|
-
"
|
|
313
|
-
"
|
|
314
|
-
"
|
|
315
|
-
"
|
|
316
|
-
"
|
|
317
|
-
"
|
|
318
|
-
"
|
|
319
|
-
"
|
|
320
|
-
"
|
|
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,
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
374
|
+
if isinstance(attr, (Plot, Table, ArArBasic, Plot.BasicAttr)):
|
|
311
375
|
if not type(getattr(a, name)) == type(attr):
|
|
312
|
-
|
|
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,
|
|
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.")
|