ararpy 0.1.199__py3-none-any.whl → 0.2.1__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/Example - Check arr.py +52 -0
- ararpy/Example - Granite Cooling History.py +411 -0
- ararpy/Example - Plot temperature calibration.py +291 -0
- ararpy/Example - Show MDD results.py +561 -0
- ararpy/Example - Show all Kfs age spectra.py +344 -0
- ararpy/Example - Show random walk results.py +363 -0
- ararpy/Example - Tc calculation.py +437 -0
- ararpy/__init__.py +3 -4
- ararpy/calc/age.py +34 -36
- ararpy/calc/arr.py +0 -20
- ararpy/calc/basic.py +26 -3
- ararpy/calc/corr.py +131 -85
- ararpy/calc/plot.py +1 -2
- ararpy/calc/raw_funcs.py +41 -2
- ararpy/calc/regression.py +224 -132
- ararpy/files/arr_file.py +2 -1
- ararpy/files/basic.py +0 -22
- ararpy/files/calc_file.py +107 -84
- ararpy/files/raw_file.py +242 -229
- ararpy/smp/basic.py +133 -34
- ararpy/smp/calculation.py +6 -6
- ararpy/smp/corr.py +339 -153
- ararpy/smp/diffusion_funcs.py +345 -36
- ararpy/smp/export.py +247 -129
- ararpy/smp/info.py +2 -2
- ararpy/smp/initial.py +93 -45
- ararpy/smp/json.py +2 -2
- ararpy/smp/plots.py +144 -164
- ararpy/smp/raw.py +11 -15
- ararpy/smp/sample.py +222 -181
- ararpy/smp/style.py +26 -7
- ararpy/smp/table.py +42 -33
- ararpy/thermo/atomic_level_random_walk.py +56 -48
- ararpy/thermo/basic.py +2 -2
- {ararpy-0.1.199.dist-info → ararpy-0.2.1.dist-info}/METADATA +1 -1
- ararpy-0.2.1.dist-info/RECORD +73 -0
- {ararpy-0.1.199.dist-info → ararpy-0.2.1.dist-info}/WHEEL +1 -1
- ararpy-0.1.199.dist-info/RECORD +0 -66
- {ararpy-0.1.199.dist-info → ararpy-0.2.1.dist-info}/licenses/LICENSE +0 -0
- {ararpy-0.1.199.dist-info → ararpy-0.2.1.dist-info}/top_level.txt +0 -0
ararpy/files/raw_file.py
CHANGED
|
@@ -22,13 +22,50 @@ from parse import parse as string_parser
|
|
|
22
22
|
import dateutil.parser as datetime_parser
|
|
23
23
|
from ..calc.arr import get_item
|
|
24
24
|
from ..calc.basic import utc_dt
|
|
25
|
+
from ..smp.sample import RawData
|
|
25
26
|
|
|
26
27
|
""" Open raw data file """
|
|
27
28
|
|
|
28
|
-
DEFAULT_SAMPLE_INFO = {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
DEFAULT_SAMPLE_INFO = {
|
|
30
|
+
"ExpName": "en", # "Experiment Name"
|
|
31
|
+
"StepName": "sn", # "Step Name"
|
|
32
|
+
"StepType": "st", # "Step Type"
|
|
33
|
+
"StepLabel": "sl", # "Step Label"
|
|
34
|
+
"ZeroYear": "date", # "Zero Date Year"
|
|
35
|
+
"ZeroHour": "time", # "Zero Time Hour"
|
|
36
|
+
"ZeroMon": "mon", # "Zero Date Month"
|
|
37
|
+
"ZeroMin": "min", # "Zero Time Minute"
|
|
38
|
+
"ZeroDay": "day", # "Zero Date Day"
|
|
39
|
+
"ZeroSec": "sec", # "Zero Time Second"
|
|
40
|
+
"SmpName": "smpn", # "Sample Name"
|
|
41
|
+
"SmpLoc": "smpl", # "Sample location"
|
|
42
|
+
"SmpMatr": "smpm", # "Sample Material"
|
|
43
|
+
"ExpType": "et", # "Experiment Type"
|
|
44
|
+
"SmpWeight": "smpw", # "Sample Weight"
|
|
45
|
+
"Stepunit": "su", # "Step unit"
|
|
46
|
+
"HeatingTime": "ht", # "Heating time"
|
|
47
|
+
"InstrName": "inn", # "Instrument name"
|
|
48
|
+
"Researcher": "re", # "Researcher"
|
|
49
|
+
"Analyst": "an", # "Analyst"
|
|
50
|
+
"Lab": "la", # "Laboratory"
|
|
51
|
+
"Jv": "jv", # "J value"
|
|
52
|
+
"Jsig": "je", # "J value error"
|
|
53
|
+
"MDF": "mdf", # "MDF"
|
|
54
|
+
"MDFSig": "mdfe", # "MDF error"
|
|
55
|
+
"CalcName": "cp", # "Calc params"
|
|
56
|
+
"IrraName": "in", # "Irra name"
|
|
57
|
+
"IrraLabel": "il", # "Irra label"
|
|
58
|
+
"IrraPosH": "ih", # "Irra position H"
|
|
59
|
+
"IrraPosX": "ix", # "Irra position X"
|
|
60
|
+
"IrraPosY": "iy", # "Irra position Y"
|
|
61
|
+
"StdName": "stdn", # "Standard name"
|
|
62
|
+
"StdAge": "stda", # "Standard age"
|
|
63
|
+
"StdAgeSig": "stde", # "Standard age error"
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def open_file(file_path: str, input_filter: List[Union[str, int, bool]], name=None):
|
|
32
69
|
"""
|
|
33
70
|
Parameters
|
|
34
71
|
----------
|
|
@@ -57,64 +94,14 @@ def open_file(file_path: str, input_filter: List[Union[str, int, bool]]):
|
|
|
57
94
|
"""
|
|
58
95
|
extension = str(os.path.split(file_path)[-1]).split('.')[-1]
|
|
59
96
|
try:
|
|
60
|
-
handler = {'txt': open_raw_txt, 'excel': open_raw_xls,
|
|
61
|
-
|
|
62
|
-
['txt', 'excel', 'Qtegra Exported XLS', 'Seq'][int(input_filter[1])]]
|
|
97
|
+
handler = {'txt': open_raw_txt, 'excel': open_raw_xls, 'Seq': open_raw_seq}[
|
|
98
|
+
['txt', 'excel', 'Qtegra Excel (deleted)', 'Seq'][int(input_filter[1])]]
|
|
63
99
|
except KeyError:
|
|
64
|
-
print(traceback.format_exc())
|
|
65
100
|
raise FileNotFoundError("Wrong File.")
|
|
66
|
-
return handler(file_path, input_filter)
|
|
101
|
+
return handler(file_path, input_filter, name)
|
|
67
102
|
|
|
68
103
|
|
|
69
|
-
def
|
|
70
|
-
if input_filter is None:
|
|
71
|
-
input_filter = []
|
|
72
|
-
try:
|
|
73
|
-
wb = open_workbook(filepath)
|
|
74
|
-
sheets = wb.sheet_names()
|
|
75
|
-
sheet = wb.sheet_by_name(sheets[0])
|
|
76
|
-
value, step_header, step_list = [], [], []
|
|
77
|
-
for row in range(sheet.nrows):
|
|
78
|
-
row_set = []
|
|
79
|
-
for col in range(sheet.ncols):
|
|
80
|
-
if sheet.cell(row, col).value == '':
|
|
81
|
-
pass
|
|
82
|
-
else:
|
|
83
|
-
row_set.append(sheet.cell(row, col).value)
|
|
84
|
-
if row_set != [] and len(row_set) > 1:
|
|
85
|
-
value.append(row_set)
|
|
86
|
-
for each_row in value:
|
|
87
|
-
# if the first item of each row is float (1.0, 2.0, ...) this row is the header of a step.
|
|
88
|
-
if isinstance(each_row[0], float):
|
|
89
|
-
each_row[0] = int(each_row[0])
|
|
90
|
-
if "M" in each_row[1].upper():
|
|
91
|
-
each_row[1] = datetime.strptime(each_row[1], '%m/%d/%Y %I:%M:%S %p').isoformat(timespec='seconds')
|
|
92
|
-
else:
|
|
93
|
-
each_row[1] = datetime.strptime(each_row[1], '%m/%d/%Y %H:%M:%S').isoformat(timespec='seconds')
|
|
94
|
-
step_header.append(each_row)
|
|
95
|
-
for step_index, each_step_header in enumerate(step_header):
|
|
96
|
-
row_start_number = value.index(each_step_header)
|
|
97
|
-
try:
|
|
98
|
-
row_stop_number = value.index(step_header[step_index + 1])
|
|
99
|
-
except IndexError:
|
|
100
|
-
row_stop_number = len(value) + 1
|
|
101
|
-
step_values = [
|
|
102
|
-
each_step_header[0:4],
|
|
103
|
-
*list(map(
|
|
104
|
-
# lambda x: [x[0], x[1], x[2], x[1], x[3], x[1], x[4], x[1], x[5], x[1], x[6]],
|
|
105
|
-
# x[1] = time, x[2] = H2:40, x[3] = H1: 39, x[4] = AX: 38, x[5] = L1: 37, x[6] = L2: 36
|
|
106
|
-
lambda x: [x[0], x[1], x[6], x[1], x[5], x[1], x[4], x[1], x[3], x[1], x[2]],
|
|
107
|
-
# in sequence: Ar36, Ar37, Ar38, Ar39, Ar40
|
|
108
|
-
[value[i] for i in range(row_start_number + 2, row_stop_number - 7, 1)]))
|
|
109
|
-
]
|
|
110
|
-
step_list.append(step_values)
|
|
111
|
-
except Exception as e:
|
|
112
|
-
raise ValueError('Error in opening the original file: %s' % str(e))
|
|
113
|
-
else:
|
|
114
|
-
return {'data': step_list}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
def open_raw_txt(file_path, input_filter: List[Union[str, int]]):
|
|
104
|
+
def open_raw_txt(file_path, input_filter: List[Union[str, int]], name=None):
|
|
118
105
|
"""
|
|
119
106
|
Parameters
|
|
120
107
|
----------
|
|
@@ -125,11 +112,14 @@ def open_raw_txt(file_path, input_filter: List[Union[str, int]]):
|
|
|
125
112
|
-------
|
|
126
113
|
|
|
127
114
|
"""
|
|
115
|
+
file_name = os.path.basename(file_path).rstrip(os.path.splitext(file_path)[-1]) if name is None else name
|
|
116
|
+
|
|
128
117
|
if not input_filter:
|
|
129
118
|
raise ValueError("Input filter is empty array.")
|
|
130
119
|
|
|
131
120
|
if os.path.splitext(file_path)[1][1:].lower() != input_filter[0].strip().lower():
|
|
132
|
-
raise ValueError("The file does not
|
|
121
|
+
raise ValueError(f"The file extension does not match the filter: {file_name}, "
|
|
122
|
+
f"{input_filter[0].strip().lower()} required.")
|
|
133
123
|
|
|
134
124
|
with open(file_path, 'rb') as f:
|
|
135
125
|
contents = f.read()
|
|
@@ -137,12 +127,11 @@ def open_raw_txt(file_path, input_filter: List[Union[str, int]]):
|
|
|
137
127
|
lines = [line.strip().split(['\t', ';', " ", ",", input_filter[3]][int(input_filter[2])])
|
|
138
128
|
for line in contents.decode(encoding=encoding["encoding"]).split('\r\n')]
|
|
139
129
|
|
|
140
|
-
file_name = os.path.basename(file_path).rstrip(os.path.splitext(file_path)[-1])
|
|
141
130
|
step_list = get_raw_data([lines], input_filter, file_name=file_name)
|
|
142
131
|
return {'data': step_list}
|
|
143
132
|
|
|
144
133
|
|
|
145
|
-
def open_raw_xls(file_path, input_filter: List[Union[str, int]]):
|
|
134
|
+
def open_raw_xls(file_path, input_filter: List[Union[str, int]], name=None):
|
|
146
135
|
"""
|
|
147
136
|
Parameters
|
|
148
137
|
----------
|
|
@@ -153,11 +142,14 @@ def open_raw_xls(file_path, input_filter: List[Union[str, int]]):
|
|
|
153
142
|
-------
|
|
154
143
|
|
|
155
144
|
"""
|
|
145
|
+
file_name = os.path.basename(file_path).rstrip(os.path.splitext(file_path)[-1]) if name is None else name
|
|
146
|
+
|
|
156
147
|
if not input_filter:
|
|
157
148
|
raise ValueError("Input filter is empty array.")
|
|
158
149
|
|
|
159
150
|
if os.path.splitext(file_path)[1][1:].lower() != input_filter[0].strip().lower():
|
|
160
|
-
raise ValueError("The file does not
|
|
151
|
+
raise ValueError(f"The file extension does not match the filter: {file_name}, "
|
|
152
|
+
f"{input_filter[0].strip().lower()} required.")
|
|
161
153
|
|
|
162
154
|
def _get_content_from_sheet(_index) -> List[List[Union[str, bool, int, float]]]:
|
|
163
155
|
try:
|
|
@@ -169,15 +161,34 @@ def open_raw_xls(file_path, input_filter: List[Union[str, int]]):
|
|
|
169
161
|
|
|
170
162
|
wb = open_workbook(file_path)
|
|
171
163
|
contents = [_get_content_from_sheet(i) for i in range(100)]
|
|
172
|
-
file_name = os.path.basename(file_path).rstrip(os.path.splitext(file_path)[-1])
|
|
173
164
|
step_list = get_raw_data(contents, input_filter, file_name=file_name)
|
|
174
165
|
|
|
175
166
|
return {'data': step_list}
|
|
176
167
|
|
|
177
168
|
|
|
178
|
-
def open_raw_seq(file_path, input_filter=None):
|
|
169
|
+
def open_raw_seq(file_path, input_filter=None, name=None):
|
|
170
|
+
|
|
171
|
+
class RenameUnpickler(pickle.Unpickler):
|
|
172
|
+
def find_class(self, module: str, name: str):
|
|
173
|
+
MODULE = RawData().__module__
|
|
174
|
+
renamed_module = module
|
|
175
|
+
if '.sample' in module and module != MODULE:
|
|
176
|
+
renamed_module = MODULE
|
|
177
|
+
try:
|
|
178
|
+
return super(RenameUnpickler, self).find_class(renamed_module, name)
|
|
179
|
+
except AttributeError:
|
|
180
|
+
return super(RenameUnpickler, self).find_class(renamed_module, 'ArArBasic')
|
|
181
|
+
|
|
182
|
+
def renamed_load(file_obj):
|
|
183
|
+
return RenameUnpickler(file_obj).load()
|
|
184
|
+
|
|
179
185
|
with open(file_path, 'rb') as f:
|
|
180
|
-
sequences =
|
|
186
|
+
sequences = renamed_load(f)
|
|
187
|
+
|
|
188
|
+
# with open(file_path, 'rb') as f:
|
|
189
|
+
# sequences = pickle.load(f)
|
|
190
|
+
# print(sequences[0].__module__)
|
|
191
|
+
|
|
181
192
|
name_list = []
|
|
182
193
|
for seq in sequences:
|
|
183
194
|
while seq.name in name_list:
|
|
@@ -201,155 +212,187 @@ def get_raw_data(file_contents: List[List[Union[int, float, str, bool, list]]],
|
|
|
201
212
|
|
|
202
213
|
"""
|
|
203
214
|
|
|
204
|
-
def datetime_parse(string, f):
|
|
215
|
+
def datetime_parse(string: str, f: str):
|
|
205
216
|
try:
|
|
206
217
|
return datetime.strptime(string, f)
|
|
207
218
|
except ValueError as v:
|
|
219
|
+
# print(traceback.format_exc())
|
|
208
220
|
if f.strip() == "":
|
|
209
221
|
return datetime_parser.parse(string)
|
|
210
222
|
elif len(v.args) > 0 and v.args[0].startswith('unconverted data remains: '):
|
|
211
|
-
|
|
212
|
-
return
|
|
223
|
+
# %f handles microseconds (6 digits), remove the remains
|
|
224
|
+
return datetime_parse(string[:-(len(v.args[0]) - 26)], f)
|
|
225
|
+
# elif f.upper()[-2:] in ['PM', 'AM']:
|
|
226
|
+
# return datetime_parse(string, f[:-2])
|
|
213
227
|
else:
|
|
214
228
|
raise
|
|
215
229
|
|
|
230
|
+
def step_num_parse(s: str):
|
|
231
|
+
try:
|
|
232
|
+
return f"{round(float(s)):02d}"
|
|
233
|
+
except (ValueError, TypeError):
|
|
234
|
+
return s
|
|
235
|
+
|
|
236
|
+
def step_type_parse(s: str):
|
|
237
|
+
if any([s.lower().__contains__(each) for each in ['blk', 'blank']]):
|
|
238
|
+
return "Blank"
|
|
239
|
+
return "Unknown"
|
|
240
|
+
|
|
216
241
|
step_list = []
|
|
217
|
-
|
|
242
|
+
step_idx = 0 # step_index rows
|
|
218
243
|
|
|
219
244
|
header = input_filter[5]
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
245
|
+
isotope_index = input_filter[8:28]
|
|
246
|
+
data_index = input_filter[4:33]
|
|
247
|
+
strings_index = input_filter[33:41] # strings: filename, parsing information, datetime, timezone
|
|
248
|
+
optional_info_index = input_filter[41:-7] # from Exp Name to Std Age Error
|
|
249
|
+
check_box_index = input_filter[-7:]
|
|
224
250
|
|
|
225
|
-
timezone = sample_info_index[3] if sample_info_index[3] != "" else "utc"
|
|
226
251
|
while True: # measurment steps sloop
|
|
227
|
-
|
|
252
|
+
|
|
253
|
+
# ============ all text information ============
|
|
254
|
+
options = get_sample_info(file_contents, optional_info_index, default="", base=[1, 1 - step_idx, 1])
|
|
255
|
+
|
|
256
|
+
# ============ Step name ============
|
|
228
257
|
try:
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
258
|
+
step_name = options.get('StepName')
|
|
259
|
+
experiment_name = options.get('ExpName')
|
|
260
|
+
if check_box_index[1] and strings_index[0].strip() != "":
|
|
261
|
+
res = string_parser(strings_index[0], file_name)
|
|
262
|
+
if res is not None and "en" in res.named.keys():
|
|
263
|
+
experiment_name = res.named.get("en")
|
|
264
|
+
if res is not None and "sn" in res.named.keys():
|
|
265
|
+
step_name = res.named.get("sn")
|
|
266
|
+
if str(step_name) == "":
|
|
267
|
+
raise ValueError(f"Step name not found, break reading steps")
|
|
268
|
+
step_name = f"{experiment_name}-{step_num_parse(step_name)}"
|
|
269
|
+
except (TypeError, ValueError, IndexError):
|
|
270
|
+
# When parsing the step name fails, the end of the file has been reached
|
|
271
|
+
# raise
|
|
272
|
+
print(traceback.format_exc())
|
|
273
|
+
break
|
|
274
|
+
else:
|
|
275
|
+
options.update({'StepName': step_name})
|
|
276
|
+
options.update({'ExpName': experiment_name})
|
|
277
|
+
|
|
278
|
+
# ============ Step information ============
|
|
279
|
+
try:
|
|
280
|
+
if check_box_index[2]:
|
|
281
|
+
string = get_item(file_contents, strings_index[1:4], default="", base=[1, 1 - step_idx, 1])
|
|
282
|
+
res = string_parser(strings_index[4], string)
|
|
283
|
+
if res is not None:
|
|
284
|
+
options.update(dict(zip(DEFAULT_SAMPLE_INFO.keys(), [res.named.get(value, options.get(key)) for key, value in DEFAULT_SAMPLE_INFO.items()])))
|
|
285
|
+
except (TypeError, ValueError, IndexError):
|
|
286
|
+
print(traceback.format_exc())
|
|
287
|
+
break
|
|
288
|
+
else:
|
|
289
|
+
pass
|
|
290
|
+
|
|
291
|
+
# ============ Zero datetime ============
|
|
292
|
+
timezone = strings_index[7] if strings_index[7] != "" else "utc"
|
|
293
|
+
options.update({'TimeZone': timezone})
|
|
294
|
+
try:
|
|
295
|
+
if check_box_index[3]: # date in one string
|
|
296
|
+
zero_date = datetime_parse(options.get('ZeroYear'), strings_index[5])
|
|
232
297
|
else:
|
|
233
|
-
zero_date = datetime(year=
|
|
234
|
-
|
|
235
|
-
day=get_item(file_contents, sample_info_index[28:31], base=[1, 1 - idx, 1]))
|
|
298
|
+
zero_date = datetime(year=options.get('ZeroYear'), month=options.get('ZeroMon'),
|
|
299
|
+
day=options.get('ZeroDay'))
|
|
236
300
|
|
|
237
|
-
if check_box_index[
|
|
238
|
-
zero_time = datetime_parse(
|
|
239
|
-
get_item(file_contents, sample_info_index[19:22], base=[1, 1 - idx, 1]), sample_info_index[2])
|
|
301
|
+
if check_box_index[4]: # time in one string
|
|
302
|
+
zero_time = datetime_parse(options.get('ZeroHour'), strings_index[6])
|
|
240
303
|
else:
|
|
241
|
-
zero_time = datetime(year=2020, month=12, day=31,
|
|
242
|
-
|
|
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]))
|
|
304
|
+
zero_time = datetime(year=2020, month=12, day=31, hour=options.get('ZeroHour'),
|
|
305
|
+
minute=options.get('ZeroMin'), second=options.get('ZeroSec'))
|
|
245
306
|
|
|
246
307
|
zero_datetime = datetime(
|
|
247
308
|
zero_date.year, zero_date.month, zero_date.day, zero_time.hour, zero_time.minute, zero_time.second)
|
|
248
309
|
# adjust to UTC
|
|
249
310
|
zero_datetime = utc_dt(zero_datetime, tz=timezone).isoformat(timespec='seconds')
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
try:
|
|
256
|
-
experiment_name = get_item(file_contents, sample_info_index[4:7], default="", base=[1, 1 - idx, 1])
|
|
257
|
-
except (TypeError, ValueError, IndexError):
|
|
258
|
-
# print(f"Cannot parse experiment name")
|
|
259
|
-
experiment_name = "ExpName"
|
|
311
|
+
options.update({'ZeroDT': zero_datetime})
|
|
312
|
+
except (TypeError, ValueError, IndexError) as e:
|
|
313
|
+
print(traceback.format_exc())
|
|
314
|
+
raise ValueError(f"Failed to parse zero datetime: {e}")
|
|
315
|
+
# zero_datetime = datetime(1970, 1, 1, 0, 0, 0).isoformat(timespec='seconds')
|
|
260
316
|
|
|
261
|
-
# Step
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
if check_box_index[1] and sample_info_index[0].strip() != "":
|
|
265
|
-
_res = string_parser(sample_info_index[0], file_name)
|
|
266
|
-
if _res is not None:
|
|
267
|
-
experiment_name = _res.named.get("en", experiment_name)
|
|
268
|
-
step_index = _res.named.get("sn", step_name)
|
|
269
|
-
if step_index.isnumeric():
|
|
270
|
-
step_name = f"{experiment_name}-{int(step_index):02d}"
|
|
271
|
-
else:
|
|
272
|
-
step_name = f"{experiment_name}-{step_index}"
|
|
273
|
-
if step_name == "":
|
|
274
|
-
raise ValueError(f"Step name not found")
|
|
275
|
-
except (TypeError, ValueError, IndexError):
|
|
276
|
-
# When parsing the step name fails, the end of the file has been reached
|
|
277
|
-
raise
|
|
317
|
+
# ============== Step Type =============
|
|
318
|
+
step_type = step_type_parse(options.get("StepType")) # blank or unknown
|
|
319
|
+
options.update({'StepType': step_type})
|
|
278
320
|
|
|
279
|
-
#
|
|
280
|
-
|
|
321
|
+
# ============== Step Type =============
|
|
322
|
+
exp_type = options.get("ExpType") # crushing, laser, heating, air
|
|
323
|
+
options.update({'ExpType': exp_type})
|
|
281
324
|
|
|
282
|
-
current_step = [[step_name, zero_datetime,
|
|
325
|
+
current_step = [[step_name, zero_datetime, options]]
|
|
283
326
|
|
|
327
|
+
# ============ isotope data ============
|
|
284
328
|
break_num = 0
|
|
285
329
|
cycle_num = 0
|
|
286
|
-
f = float(
|
|
287
|
-
data_content = file_contents[
|
|
330
|
+
f = float(data_index[27]) # Intensity Scale Factor
|
|
331
|
+
data_content = file_contents[data_index[0] - 1 if data_index[0] != 0 else 0]
|
|
332
|
+
base = 1
|
|
288
333
|
for i in range(2000): # measurement cycle sloop
|
|
289
|
-
if break_num <
|
|
334
|
+
if break_num < data_index[25]:
|
|
290
335
|
break_num += 1
|
|
291
336
|
continue
|
|
292
337
|
break_num = 0
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
338
|
+
try:
|
|
339
|
+
if int(data_index[2]) == 0: # == 0, vertical
|
|
340
|
+
start_row = data_index[24] * cycle_num + data_index[25] * cycle_num + header + step_idx
|
|
341
|
+
if check_box_index[0] and start_row - step_idx - header >= data_index[28]:
|
|
342
|
+
break
|
|
296
343
|
current_step.append([
|
|
297
344
|
str(cycle_num + 1),
|
|
298
345
|
# in sequence: Ar36, Ar37, Ar38, Ar39, Ar40
|
|
299
|
-
float(data_content[start_row +
|
|
300
|
-
float(data_content[start_row +
|
|
301
|
-
float(data_content[start_row +
|
|
302
|
-
float(data_content[start_row +
|
|
303
|
-
float(data_content[start_row +
|
|
304
|
-
float(data_content[start_row +
|
|
305
|
-
float(data_content[start_row +
|
|
306
|
-
float(data_content[start_row +
|
|
307
|
-
float(data_content[start_row +
|
|
308
|
-
float(data_content[start_row +
|
|
309
|
-
])
|
|
310
|
-
except (ValueError, IndexError):
|
|
311
|
-
print(f"Cannot parse isotope data")
|
|
312
|
-
print(traceback.format_exc())
|
|
313
|
-
current_step.append([
|
|
314
|
-
str(cycle_num + 1), None, None, None, None, None, None, None, None, None, None,
|
|
346
|
+
float(data_content[start_row + isotope_index[18] - base][isotope_index[19] - base]),
|
|
347
|
+
float(data_content[start_row + isotope_index[16] - base][isotope_index[17] - base]) * f,
|
|
348
|
+
float(data_content[start_row + isotope_index[14] - base][isotope_index[15] - base]),
|
|
349
|
+
float(data_content[start_row + isotope_index[12] - base][isotope_index[13] - base]) * f,
|
|
350
|
+
float(data_content[start_row + isotope_index[10] - base][isotope_index[11] - base]),
|
|
351
|
+
float(data_content[start_row + isotope_index[ 8] - base][isotope_index[ 9] - base]) * f,
|
|
352
|
+
float(data_content[start_row + isotope_index[ 6] - base][isotope_index[ 7] - base]),
|
|
353
|
+
float(data_content[start_row + isotope_index[ 4] - base][isotope_index[ 5] - base]) * f,
|
|
354
|
+
float(data_content[start_row + isotope_index[ 2] - base][isotope_index[ 3] - base]),
|
|
355
|
+
float(data_content[start_row + isotope_index[ 0] - base][isotope_index[ 1] - base]) * f,
|
|
315
356
|
])
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
try:
|
|
357
|
+
elif int(data_index[2]) == 1: # == 1, horizontal
|
|
358
|
+
start_row = data_index[1] + step_idx
|
|
359
|
+
col_inc = data_index[24] * cycle_num + data_index[25] * cycle_num
|
|
320
360
|
current_step.append([
|
|
321
361
|
str(cycle_num + 1),
|
|
322
362
|
# Ar36, Ar37, Ar38, Ar39, Ar40
|
|
323
|
-
float(data_content[start_row][
|
|
324
|
-
float(data_content[start_row][
|
|
325
|
-
float(data_content[start_row][
|
|
326
|
-
float(data_content[start_row][
|
|
327
|
-
float(data_content[start_row][
|
|
328
|
-
float(data_content[start_row][
|
|
329
|
-
float(data_content[start_row][
|
|
330
|
-
float(data_content[start_row][
|
|
331
|
-
float(data_content[start_row][
|
|
332
|
-
float(data_content[start_row][
|
|
363
|
+
float(data_content[start_row][isotope_index[19] + col_inc - base]),
|
|
364
|
+
float(data_content[start_row][isotope_index[17] + col_inc - base]) * f,
|
|
365
|
+
float(data_content[start_row][isotope_index[15] + col_inc - base]),
|
|
366
|
+
float(data_content[start_row][isotope_index[13] + col_inc - base]) * f,
|
|
367
|
+
float(data_content[start_row][isotope_index[11] + col_inc - base]),
|
|
368
|
+
float(data_content[start_row][isotope_index[ 9] + col_inc - base]) * f,
|
|
369
|
+
float(data_content[start_row][isotope_index[ 7] + col_inc - base]),
|
|
370
|
+
float(data_content[start_row][isotope_index[ 5] + col_inc - base]) * f,
|
|
371
|
+
float(data_content[start_row][isotope_index[ 3] + col_inc - base]),
|
|
372
|
+
float(data_content[start_row][isotope_index[ 1] + col_inc - base]) * f,
|
|
333
373
|
])
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
374
|
+
else:
|
|
375
|
+
raise ValueError(f"{data_index[2]} not in [0, 1]")
|
|
376
|
+
except Exception as e:
|
|
377
|
+
print(f"Cannot parse isotope data")
|
|
378
|
+
# print(traceback.format_exc())
|
|
379
|
+
current_step.append([
|
|
380
|
+
str(cycle_num + 1), None, None, None, None, None, None, None, None, None, None,
|
|
381
|
+
])
|
|
342
382
|
|
|
343
383
|
cycle_num += 1
|
|
344
|
-
if cycle_num >=
|
|
384
|
+
if cycle_num >= data_index[3]:
|
|
345
385
|
break
|
|
346
386
|
|
|
347
387
|
step_list.append(current_step)
|
|
348
|
-
|
|
349
|
-
|
|
388
|
+
step_idx = data_index[28] * len(step_list)
|
|
350
389
|
if not check_box_index[0] or len(step_list) >= 500: # check_box_index[0]: multiple sequences
|
|
390
|
+
# print(f"Multiple Sequence = {check_box_index[0]}, Step number = {len(step_list)}")
|
|
351
391
|
break
|
|
352
392
|
|
|
393
|
+
if not step_list:
|
|
394
|
+
raise ValueError("Failed to read the original file. It might be because the names of the experiments or steps were not recognized.")
|
|
395
|
+
|
|
353
396
|
return step_list
|
|
354
397
|
|
|
355
398
|
|
|
@@ -368,69 +411,39 @@ def get_sample_info(file_contents: list, index_list: list, default="", base: Uni
|
|
|
368
411
|
"""
|
|
369
412
|
sample_info = DEFAULT_SAMPLE_INFO.copy()
|
|
370
413
|
sample_info.update({
|
|
371
|
-
"ExpName": get_item(file_contents, index_list[0:3], default=default, base=base),
|
|
372
|
-
"StepName": get_item(file_contents, index_list[3:6], default=default, base=base),
|
|
373
|
-
"
|
|
374
|
-
"StepLabel": get_item(file_contents, index_list[9:12], default=default, base=base),
|
|
375
|
-
"ZeroYear": get_item(file_contents, index_list[12:15], default=default, base=base),
|
|
376
|
-
"ZeroHour": get_item(file_contents, index_list[15:18], default=default, base=base),
|
|
377
|
-
"ZeroMon": get_item(file_contents, index_list[18:21], default=default, base=base),
|
|
378
|
-
"ZeroMin": get_item(file_contents, index_list[21:24], default=default, base=base),
|
|
379
|
-
"ZeroDay": get_item(file_contents, index_list[24:27], default=default, base=base),
|
|
380
|
-
"ZeroSec": get_item(file_contents, index_list[27:30], default=default, base=base),
|
|
381
|
-
"SmpName": get_item(file_contents, index_list[30:33], default=default, base=base),
|
|
382
|
-
"SmpLoc": get_item(file_contents, index_list[33:36], default=default, base=base),
|
|
383
|
-
"SmpMatr": get_item(file_contents, index_list[36:39], default=default, base=base),
|
|
384
|
-
"ExpType": get_item(file_contents, index_list[39:42], default=default, base=base),
|
|
385
|
-
"SmpWeight": get_item(file_contents, index_list[42:45], default=default, base=base),
|
|
386
|
-
"Stepunit": get_item(file_contents, index_list[45:48], default=default, base=base),
|
|
387
|
-
"HeatingTime": get_item(file_contents, index_list[48:51], default=default, base=base),
|
|
388
|
-
"InstrName": get_item(file_contents, index_list[51:54], default=default, base=base),
|
|
389
|
-
"Researcher": get_item(file_contents, index_list[54:57], default=default, base=base),
|
|
390
|
-
"Analyst": get_item(file_contents, index_list[57:60], default=default, base=base),
|
|
391
|
-
"Lab": get_item(file_contents, index_list[60:63], default=default, base=base),
|
|
392
|
-
"Jv": get_item(file_contents, index_list[63:66], default=default, base=base),
|
|
393
|
-
"Jsig": get_item(file_contents, index_list[66:69], default=default, base=base),
|
|
394
|
-
"
|
|
395
|
-
"
|
|
396
|
-
"
|
|
397
|
-
"
|
|
398
|
-
"
|
|
399
|
-
"
|
|
400
|
-
"
|
|
401
|
-
"
|
|
402
|
-
"
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
# "Sample Type": get_item(file_contents, sample_info_index[6:9], default=default, base=base),
|
|
406
|
-
# "Step Label": get_item(file_contents, sample_info_index[9:12], default=default, base=base),
|
|
407
|
-
# "Zero Date Year": get_item(file_contents, sample_info_index[12:15], default=default, base=base),
|
|
408
|
-
# "Zero Time Hour": get_item(file_contents, sample_info_index[15:18], default=default, base=base),
|
|
409
|
-
# "Zero Date Month": get_item(file_contents, sample_info_index[18:21], default=default, base=base),
|
|
410
|
-
# "Zero Time Minute": get_item(file_contents, sample_info_index[21:24], default=default, base=base),
|
|
411
|
-
# "Zero Date Day": get_item(file_contents, sample_info_index[24:27], default=default, base=base),
|
|
412
|
-
# "Zero Time Second": get_item(file_contents, sample_info_index[27:30], default=default, base=base),
|
|
413
|
-
# "Sample Name": get_item(file_contents, sample_info_index[30:33], default=default, base=base),
|
|
414
|
-
# "Sample location": get_item(file_contents, sample_info_index[33:36], default=default, base=base),
|
|
415
|
-
# "Sample Material": get_item(file_contents, sample_info_index[36:39], default=default, base=base),
|
|
416
|
-
# "Experiment Type": get_item(file_contents, sample_info_index[39:42], default=default, base=base),
|
|
417
|
-
# "Sample Weight": get_item(file_contents, sample_info_index[42:45], default=default, base=base),
|
|
418
|
-
# "Step unit": get_item(file_contents, sample_info_index[45:48], default=default, base=base),
|
|
419
|
-
# "Heating time": get_item(file_contents, sample_info_index[48:51], default=default, base=base),
|
|
420
|
-
# "Instrument name": get_item(file_contents, sample_info_index[51:54], default=default, base=base),
|
|
421
|
-
# "Researcher": get_item(file_contents, sample_info_index[54:57], default=default, base=base),
|
|
422
|
-
# "Analyst": get_item(file_contents, sample_info_index[57:60], default=default, base=base),
|
|
423
|
-
# "Laboratory": get_item(file_contents, sample_info_index[60:63], default=default, base=base),
|
|
424
|
-
# "J value": get_item(file_contents, sample_info_index[63:66], default=default, base=base),
|
|
425
|
-
# "J value error": get_item(file_contents, sample_info_index[66:69], default=default, base=base),
|
|
426
|
-
# "Calc params": get_item(file_contents, sample_info_index[69:72], default=default, base=base),
|
|
427
|
-
# "Irra name": get_item(file_contents, sample_info_index[72:75], default=default, base=base),
|
|
428
|
-
# "Irra label": get_item(file_contents, sample_info_index[75:78], default=default, base=base),
|
|
429
|
-
# "Irra position H": get_item(file_contents, sample_info_index[78:81], default=default, base=base),
|
|
430
|
-
# "Irra position X": get_item(file_contents, sample_info_index[81:84], default=default, base=base),
|
|
431
|
-
# "Irra position Y": get_item(file_contents, sample_info_index[84:87], default=default, base=base),
|
|
432
|
-
# "Standard name": get_item(file_contents, sample_info_index[87:90], default=default, base=base),
|
|
433
|
-
# "Standard age": get_item(file_contents, sample_info_index[90:93], default=default, base=base),
|
|
434
|
-
# "Standard age error": get_item(file_contents, sample_info_index[93:96], default=default, base=base),
|
|
414
|
+
"ExpName": get_item(file_contents, index_list[0:3], default=default, base=base).strip(),
|
|
415
|
+
"StepName": get_item(file_contents, index_list[3:6], default=default, base=base).strip(),
|
|
416
|
+
"StepType": get_item(file_contents, index_list[6:9], default=default, base=base).strip(),
|
|
417
|
+
"StepLabel": get_item(file_contents, index_list[9:12], default=default, base=base).strip(),
|
|
418
|
+
"ZeroYear": get_item(file_contents, index_list[12:15], default=default, base=base).strip(),
|
|
419
|
+
"ZeroHour": get_item(file_contents, index_list[15:18], default=default, base=base).strip(),
|
|
420
|
+
"ZeroMon": get_item(file_contents, index_list[18:21], default=default, base=base).strip(),
|
|
421
|
+
"ZeroMin": get_item(file_contents, index_list[21:24], default=default, base=base).strip(),
|
|
422
|
+
"ZeroDay": get_item(file_contents, index_list[24:27], default=default, base=base).strip(),
|
|
423
|
+
"ZeroSec": get_item(file_contents, index_list[27:30], default=default, base=base).strip(),
|
|
424
|
+
"SmpName": get_item(file_contents, index_list[30:33], default=default, base=base).strip(),
|
|
425
|
+
"SmpLoc": get_item(file_contents, index_list[33:36], default=default, base=base).strip(),
|
|
426
|
+
"SmpMatr": get_item(file_contents, index_list[36:39], default=default, base=base).strip(),
|
|
427
|
+
"ExpType": get_item(file_contents, index_list[39:42], default=default, base=base).strip(),
|
|
428
|
+
"SmpWeight": get_item(file_contents, index_list[42:45], default=default, base=base).strip(),
|
|
429
|
+
"Stepunit": get_item(file_contents, index_list[45:48], default=default, base=base).strip(),
|
|
430
|
+
"HeatingTime": get_item(file_contents, index_list[48:51], default=default, base=base).strip(),
|
|
431
|
+
"InstrName": get_item(file_contents, index_list[51:54], default=default, base=base).strip(),
|
|
432
|
+
"Researcher": get_item(file_contents, index_list[54:57], default=default, base=base).strip(),
|
|
433
|
+
"Analyst": get_item(file_contents, index_list[57:60], default=default, base=base).strip(),
|
|
434
|
+
"Lab": get_item(file_contents, index_list[60:63], default=default, base=base).strip(),
|
|
435
|
+
"Jv": get_item(file_contents, index_list[63:66], default=default, base=base).strip(),
|
|
436
|
+
"Jsig": get_item(file_contents, index_list[66:69], default=default, base=base).strip(),
|
|
437
|
+
"MDF": get_item(file_contents, index_list[69:72], default=default, base=base).strip(),
|
|
438
|
+
"MDFSig": get_item(file_contents, index_list[72:75], default=default, base=base).strip(),
|
|
439
|
+
"CalcName": get_item(file_contents, index_list[75:78], default=default, base=base).strip(),
|
|
440
|
+
"IrraName": get_item(file_contents, index_list[78:81], default=default, base=base).strip(),
|
|
441
|
+
"IrraLabel": get_item(file_contents, index_list[81:84], default=default, base=base).strip(),
|
|
442
|
+
"IrraPosH": get_item(file_contents, index_list[84:87], default=default, base=base).strip(),
|
|
443
|
+
"IrraPosX": get_item(file_contents, index_list[87:90], default=default, base=base).strip(),
|
|
444
|
+
"IrraPosY": get_item(file_contents, index_list[90:93], default=default, base=base).strip(),
|
|
445
|
+
"StdName": get_item(file_contents, index_list[93:96], default=default, base=base).strip(),
|
|
446
|
+
"StdAge": get_item(file_contents, index_list[96:99], default=default, base=base).strip(),
|
|
447
|
+
"StdAgeSig": get_item(file_contents, index_list[99:102], default=default, base=base).strip(),
|
|
435
448
|
})
|
|
436
449
|
return sample_info
|