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/smp/info.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Copyright (C) 2024 Yang. - All Rights Reserved
|
|
2
|
+
|
|
3
|
+
# !/usr/bin/env python
|
|
4
|
+
# -*- coding: UTF-8 -*-
|
|
5
|
+
"""
|
|
6
|
+
# ==========================================
|
|
7
|
+
# Copyright 2024 Yang
|
|
8
|
+
# ararpy - info
|
|
9
|
+
# ==========================================
|
|
10
|
+
#
|
|
11
|
+
#
|
|
12
|
+
#
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def name(smp, n: str = None):
|
|
17
|
+
if n is None:
|
|
18
|
+
return smp.Info.sample.name
|
|
19
|
+
elif isinstance(n, str):
|
|
20
|
+
smp.Info.sample.name = n
|
|
21
|
+
return n
|
|
22
|
+
else:
|
|
23
|
+
raise ValueError(f"{n} is not a string")
|
ararpy/smp/initial.py
CHANGED
|
@@ -31,7 +31,7 @@ plateau_res_keys = [
|
|
|
31
31
|
'F', 'sF', 'Num', 'MSWD', 'Chisq', 'Pvalue', 'age', 's1', 's2', 's3', 'Ar39',
|
|
32
32
|
'rs', # 'rs' means relative error of the total sum
|
|
33
33
|
]
|
|
34
|
-
PLATEAU_RES = dict(zip(plateau_res_keys, [np.nan
|
|
34
|
+
PLATEAU_RES = dict(zip(plateau_res_keys, [np.nan for i in plateau_res_keys]))
|
|
35
35
|
iso_res_keys = [
|
|
36
36
|
'k', 'sk', 'm1', 'sm1',
|
|
37
37
|
'MSWD', 'abs_conv', 'iter', 'mag', 'R2', 'Chisq', 'Pvalue',
|
|
@@ -40,7 +40,14 @@ iso_res_keys = [
|
|
|
40
40
|
'conv', 'initial', 'sinitial', 'F', 'sF',
|
|
41
41
|
]
|
|
42
42
|
ISO_RES = dict(zip(
|
|
43
|
-
iso_res_keys, [np.nan
|
|
43
|
+
iso_res_keys, [np.nan for i in iso_res_keys])
|
|
44
|
+
)
|
|
45
|
+
spectra_res_keys = [
|
|
46
|
+
'F', 'sF', 'Num', 'MSWD', 'Chisq', 'Pvalue', 'age', 's1', 's2', 's3', 'Ar39',
|
|
47
|
+
'rs', # 'rs' means relative error of the total sum
|
|
48
|
+
]
|
|
49
|
+
SPECTRA_RES = dict(zip(
|
|
50
|
+
spectra_res_keys, [np.nan for i in spectra_res_keys])
|
|
44
51
|
)
|
|
45
52
|
|
|
46
53
|
|
|
@@ -100,21 +107,25 @@ def create_sample_from_dict(content: dict, smp_info: dict):
|
|
|
100
107
|
smp.SelectedSequence1 = [index for index, item in enumerate(smp.IsochronMark) if item == 1]
|
|
101
108
|
smp.SelectedSequence2 = [index for index, item in enumerate(smp.IsochronMark) if item == 2]
|
|
102
109
|
smp.UnselectedSequence = [index for index, item in enumerate(smp.IsochronMark) if item not in [1, 2]]
|
|
110
|
+
#
|
|
111
|
+
smp.Info.results.selection[0]['data'] = smp.SelectedSequence1
|
|
112
|
+
smp.Info.results.selection[1]['data'] = smp.SelectedSequence2
|
|
113
|
+
smp.Info.results.selection[2]['data'] = smp.UnselectedSequence
|
|
103
114
|
|
|
104
115
|
return smp
|
|
105
116
|
|
|
106
117
|
|
|
107
118
|
def initial(smp: Sample):
|
|
108
119
|
# 已更新 2023/7/4
|
|
109
|
-
smp.TotalParam = arr.create_arr((
|
|
110
|
-
smp.BlankIntercept = arr.create_arr((
|
|
111
|
-
smp.SampleIntercept = arr.create_arr((
|
|
112
|
-
smp.PublishValues = arr.create_arr((
|
|
120
|
+
smp.TotalParam = arr.create_arr((len(samples.TOTAL_PARAMS_HEADERS) - 2, 0))
|
|
121
|
+
smp.BlankIntercept = arr.create_arr((len(samples.BLANK_INTERCEPT_HEADERS) - 2, 0))
|
|
122
|
+
smp.SampleIntercept = arr.create_arr((len(samples.SAMPLE_INTERCEPT_HEADERS) - 2, 0))
|
|
123
|
+
smp.PublishValues = arr.create_arr((len(samples.PUBLISH_TABLE_HEADERS) - 2, 0))
|
|
113
124
|
smp.DecayCorrected = arr.create_arr((10, 0))
|
|
114
|
-
smp.CorrectedValues = arr.create_arr((
|
|
115
|
-
smp.DegasValues = arr.create_arr((
|
|
116
|
-
smp.ApparentAgeValues = arr.create_arr((
|
|
117
|
-
smp.IsochronValues = arr.create_arr((
|
|
125
|
+
smp.CorrectedValues = arr.create_arr((len(samples.CORRECTED_HEADERS) - 2, 0))
|
|
126
|
+
smp.DegasValues = arr.create_arr((len(samples.DEGAS_HEADERS) - 2, 0))
|
|
127
|
+
smp.ApparentAgeValues = arr.create_arr((len(samples.SPECTRUM_TABLE_HEADERS) - 2, 0))
|
|
128
|
+
smp.IsochronValues = arr.create_arr((len(samples.ISOCHRON_TABLE_HEADERS) - 3, 0))
|
|
118
129
|
|
|
119
130
|
# Doi
|
|
120
131
|
if not hasattr(smp, 'Doi') or getattr(smp, 'Doi') in (None, ""):
|
|
@@ -122,9 +133,9 @@ def initial(smp: Sample):
|
|
|
122
133
|
|
|
123
134
|
# Info
|
|
124
135
|
setattr(smp, 'Info', ArArBasic(
|
|
125
|
-
id='0', name='info', attr_name='Info',
|
|
136
|
+
id='0', name='info', attr_name='Info', arr_version=samples.VERSION,
|
|
126
137
|
sample=ArArBasic(
|
|
127
|
-
name='SAMPLE NAME', material='MATERIAL', location='LOCATION'
|
|
138
|
+
name='SAMPLE NAME', material='MATERIAL', location='LOCATION', type='Unknown'
|
|
128
139
|
),
|
|
129
140
|
researcher=ArArBasic(
|
|
130
141
|
name='RESEARCHER', addr='ADDRESS', email='EMAIL'
|
|
@@ -152,7 +163,15 @@ def initial(smp: Sample):
|
|
|
152
163
|
},
|
|
153
164
|
age_plateau={
|
|
154
165
|
0: copy.deepcopy(PLATEAU_RES), 1: copy.deepcopy(PLATEAU_RES), 2: copy.deepcopy(PLATEAU_RES)},
|
|
155
|
-
age_spectra={
|
|
166
|
+
age_spectra={
|
|
167
|
+
'TGA': copy.deepcopy(SPECTRA_RES),
|
|
168
|
+
0: copy.deepcopy(SPECTRA_RES), 1: copy.deepcopy(SPECTRA_RES), 2: copy.deepcopy(SPECTRA_RES),
|
|
169
|
+
},
|
|
170
|
+
selection={
|
|
171
|
+
0: {'data': [], 'name': 'set1'},
|
|
172
|
+
1: {'data': [], 'name': 'set2'},
|
|
173
|
+
2: {'data': [], 'name': 'set3'}
|
|
174
|
+
}
|
|
156
175
|
),
|
|
157
176
|
reference=ArArBasic(
|
|
158
177
|
name='REFERENCE', journal='JOURNAL', doi='DOI'
|
|
@@ -242,7 +261,7 @@ def check_version(smp: Sample):
|
|
|
242
261
|
|
|
243
262
|
Parameters
|
|
244
263
|
----------
|
|
245
|
-
|
|
264
|
+
smp
|
|
246
265
|
|
|
247
266
|
Returns
|
|
248
267
|
-------
|
|
@@ -287,8 +306,10 @@ def from_arr_files(file_path, sample_name: str = ""):
|
|
|
287
306
|
renamed_module = module
|
|
288
307
|
if '.sample' in module and module != SAMPLE_MODULE:
|
|
289
308
|
renamed_module = SAMPLE_MODULE
|
|
290
|
-
|
|
291
|
-
|
|
309
|
+
try:
|
|
310
|
+
return super(RenameUnpickler, self).find_class(renamed_module, name)
|
|
311
|
+
except AttributeError:
|
|
312
|
+
return super(RenameUnpickler, self).find_class(renamed_module, 'ArArBasic')
|
|
292
313
|
|
|
293
314
|
def renamed_load(file_obj):
|
|
294
315
|
return RenameUnpickler(file_obj).load()
|
|
@@ -391,10 +412,8 @@ def from_raw_data(raw: RawData, mapping: Optional[List[dict]] = None) -> Sample:
|
|
|
391
412
|
else:
|
|
392
413
|
blank: Sequence = raw.get_sequence(row['blank'], flag='name')
|
|
393
414
|
for i in range(5):
|
|
394
|
-
row_unknown_intercept = arr.multi_append(
|
|
395
|
-
|
|
396
|
-
row_blank_intercept = arr.multi_append(
|
|
397
|
-
row_blank_intercept, *blank.results[i][unknown.fitting_method[i]][:2])
|
|
415
|
+
row_unknown_intercept = arr.multi_append(row_unknown_intercept, *unknown.results[i][int(unknown.fitting_method[i])][:2])
|
|
416
|
+
row_blank_intercept = arr.multi_append(row_blank_intercept, *blank.results[i][int(blank.fitting_method[i])][:2])
|
|
398
417
|
|
|
399
418
|
unknown_intercept.append(row_unknown_intercept)
|
|
400
419
|
blank_intercept.append(row_blank_intercept)
|
|
@@ -407,6 +426,10 @@ def from_raw_data(raw: RawData, mapping: Optional[List[dict]] = None) -> Sample:
|
|
|
407
426
|
sample.UnselectedSequence = list(range(len(sample.SequenceName)))
|
|
408
427
|
sample.SelectedSequence1 = []
|
|
409
428
|
sample.SelectedSequence2 = []
|
|
429
|
+
#
|
|
430
|
+
sample.Info.results.selection[0]['data'] = sample.SelectedSequence1
|
|
431
|
+
sample.Info.results.selection[1]['data'] = sample.SelectedSequence2
|
|
432
|
+
sample.Info.results.selection[2]['data'] = sample.UnselectedSequence
|
|
410
433
|
|
|
411
434
|
table.update_table_data(sample) # Update table after submission row data and calculation
|
|
412
435
|
|
ararpy/smp/json.py
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
import json
|
|
14
14
|
import numpy as np
|
|
15
15
|
import pandas as pd
|
|
16
|
-
from .sample import Sample,
|
|
16
|
+
from .sample import Sample, Table, Plot, RawData, Sequence, ArArBasic
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
def dumps(a):
|
|
@@ -41,7 +41,7 @@ class MyEncoder(json.JSONEncoder):
|
|
|
41
41
|
if isinstance(obj, (np.int8, np.int16, np.int32, np.int64)):
|
|
42
42
|
return int(obj)
|
|
43
43
|
# sample or raw instance
|
|
44
|
-
if isinstance(obj, (Sample,
|
|
44
|
+
if isinstance(obj, (Sample, Plot, Table, Plot.Text, Plot.Axis, Plot.Label,
|
|
45
45
|
Plot.Set, Plot.BasicAttr, RawData, Sequence, ArArBasic)):
|
|
46
46
|
if isinstance(obj, Sequence):
|
|
47
47
|
return dict(obj.__dict__, **{
|
ararpy/smp/plots.py
CHANGED
|
@@ -17,7 +17,7 @@ from scipy.signal import find_peaks
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
from .. import calc
|
|
20
|
-
from .sample import Sample,
|
|
20
|
+
from .sample import Sample, Table, Plot
|
|
21
21
|
from . import basic, initial
|
|
22
22
|
|
|
23
23
|
Set = Plot.Set
|
|
@@ -124,8 +124,12 @@ def initial_plot_data(sample: Sample):
|
|
|
124
124
|
total_age = basic.calc_age(total_f[:2], smp=sample)
|
|
125
125
|
except (Exception, BaseException):
|
|
126
126
|
print(traceback.format_exc())
|
|
127
|
+
total_f = [np.nan] * 2
|
|
127
128
|
total_age = [np.nan] * 4
|
|
128
|
-
sample.Info.results.age_spectra
|
|
129
|
+
sample.Info.results.age_spectra['TGA'].update(
|
|
130
|
+
{'Ar39': 100, 'F': total_f[0], 'sF': total_f[1], 'age': total_age[0],
|
|
131
|
+
's1': total_age[1], 's2': total_age[2], 's3': total_age[3], 'Num': len(sample.DegasValues[24])}
|
|
132
|
+
)
|
|
129
133
|
try:
|
|
130
134
|
sample.AgeSpectraPlot.data = calc.spectra.get_data(
|
|
131
135
|
*sample.ApparentAgeValues[2:4], sample.ApparentAgeValues[7])
|
|
@@ -184,26 +188,26 @@ def recalc_isochrons(sample: Sample, **kwargs):
|
|
|
184
188
|
continue
|
|
185
189
|
figure = basic.get_component_byid(sample, key)
|
|
186
190
|
figure.set3.data, figure.set1.data, figure.set2.data = \
|
|
187
|
-
sample.UnselectedSequence, sample.SelectedSequence1, sample.SelectedSequence2
|
|
191
|
+
sample.UnselectedSequence.copy(), sample.SelectedSequence1.copy(), sample.SelectedSequence2.copy()
|
|
188
192
|
for index, sequence in enumerate([figure.set1.data, figure.set2.data, figure.set3.data]):
|
|
189
193
|
set_data = calc.arr.partial(
|
|
190
194
|
sample.IsochronValues, rows=sequence, cols=list(range(*val['data_index'])))
|
|
191
195
|
if key != 'figure_7':
|
|
192
196
|
iso_res = get_isochron_results(
|
|
193
|
-
set_data, figure_type=val["figure_type"],
|
|
197
|
+
set_data, figure_type=val["figure_type"], smp=sample, sequence=sequence)
|
|
194
198
|
sample.Info.results.isochron[figure.id].update({index: iso_res})
|
|
195
199
|
else:
|
|
196
200
|
iso_res = get_3D_results(data=set_data, sequence=sequence, sample=sample)
|
|
197
201
|
sample.Info.results.isochron[figure.id].update({index: iso_res})
|
|
198
202
|
|
|
199
203
|
|
|
200
|
-
def get_isochron_results(data: list,
|
|
204
|
+
def get_isochron_results(data: list, smp: Sample, sequence, figure_type: int = 0):
|
|
201
205
|
"""
|
|
202
206
|
Get isochron figure results based on figure type.
|
|
203
207
|
Parameters
|
|
204
208
|
----------
|
|
205
209
|
data : isochron figure data, 5 columns list
|
|
206
|
-
|
|
210
|
+
smp : sample instance
|
|
207
211
|
sequence : data section index
|
|
208
212
|
figure_type : int, 0 for normal isochron, 1 for inverse isochron, 2 for K-Cl-Ar plot 3
|
|
209
213
|
|
|
@@ -227,27 +231,32 @@ def get_isochron_results(data: list, sample, sequence, figure_type: int = 0):
|
|
|
227
231
|
|
|
228
232
|
if len(sequence) < 3:
|
|
229
233
|
return iso_res
|
|
230
|
-
|
|
234
|
+
regression_method = {
|
|
235
|
+
"york-2": calc.regression.york2, "olst": calc.regression.olst
|
|
236
|
+
}.get(smp.TotalParam[97][min(sequence)].lower(), calc.regression.york2)
|
|
231
237
|
try:
|
|
232
|
-
|
|
238
|
+
regression_res = regression_method(*data[:5])
|
|
233
239
|
except (Exception, BaseException):
|
|
234
240
|
print(f"Warning: {traceback.format_exc()}")
|
|
235
241
|
return iso_res
|
|
236
242
|
else:
|
|
237
|
-
iso_res.update(dict(zip(reg_res_index,
|
|
243
|
+
iso_res.update(dict(zip(reg_res_index, regression_res)))
|
|
238
244
|
if figure_type == 1:
|
|
239
|
-
iso_res.update(zip(['initial', 'sinitial'],
|
|
240
|
-
iso_res.update(zip(['F', 'sF'],
|
|
245
|
+
iso_res.update(zip(['initial', 'sinitial'], regression_res[0:2]))
|
|
246
|
+
iso_res.update(zip(['F', 'sF'], regression_res[2:4]))
|
|
241
247
|
elif figure_type == 2:
|
|
242
|
-
iso_res.update(zip(['initial', 'sinitial'], calc.arr.rec(
|
|
243
|
-
k =
|
|
248
|
+
iso_res.update(zip(['initial', 'sinitial'], calc.arr.rec(regression_res[0:2])))
|
|
249
|
+
k = regression_method(*data[2:4], *data[0:2], data[4])
|
|
244
250
|
iso_res.update(zip(['F', 'sF'], calc.arr.rec(k[0:2])))
|
|
245
251
|
elif figure_type == 3:
|
|
246
|
-
iso_res.update(zip(['initial', 'sinitial'],
|
|
247
|
-
iso_res.update(zip(['F', 'sF'],
|
|
252
|
+
iso_res.update(zip(['initial', 'sinitial'], regression_res[2:4]))
|
|
253
|
+
iso_res.update(zip(['F', 'sF'], regression_res[0:2]))
|
|
248
254
|
# age, analytical err, internal err, full external err
|
|
249
|
-
|
|
250
|
-
|
|
255
|
+
try:
|
|
256
|
+
age = basic.calc_age([iso_res['F'], iso_res['sF']], smp=smp)
|
|
257
|
+
iso_res.update(dict(zip(age_res_index, age)))
|
|
258
|
+
except ValueError:
|
|
259
|
+
pass
|
|
251
260
|
return iso_res
|
|
252
261
|
|
|
253
262
|
|
|
@@ -329,6 +338,7 @@ def reset_isochron_line_data(smp: Sample):
|
|
|
329
338
|
coeffs = [smp.Info.results.isochron[k][index]['k'], smp.Info.results.isochron[k][index]['m1']]
|
|
330
339
|
line_point = calc.isochron.get_line_points(xscale, yscale, coeffs)
|
|
331
340
|
setattr(getattr(v, ['line1', 'line2'][index]), 'data', line_point)
|
|
341
|
+
setattr(getattr(v, ['text1', 'text2'][index]), 'text', "") # 注意和js的配合,js那边根据text是否为空判断是否重新生成文字
|
|
332
342
|
except Exception:
|
|
333
343
|
# print(traceback.format_exc())
|
|
334
344
|
continue
|
|
@@ -362,12 +372,25 @@ def set_selection(smp: Sample, index: int, mark: int):
|
|
|
362
372
|
smp.IsochronMark = [
|
|
363
373
|
1 if i in smp.SelectedSequence1 else 2 if i in smp.SelectedSequence2 else '' for i in
|
|
364
374
|
range(len(smp.IsochronValues[2]))]
|
|
375
|
+
#
|
|
376
|
+
smp.Info.results.selection[0]['data'] = smp.SelectedSequence1
|
|
377
|
+
smp.Info.results.selection[1]['data'] = smp.SelectedSequence2
|
|
378
|
+
smp.Info.results.selection[2]['data'] = smp.UnselectedSequence
|
|
365
379
|
|
|
366
380
|
|
|
367
381
|
# =======================
|
|
368
382
|
# Age spectra results
|
|
369
383
|
# =======================
|
|
370
384
|
def recalc_plateaus(sample: Sample, **kwargs):
|
|
385
|
+
if sample.Info.sample.type == "Unknown":
|
|
386
|
+
return recalc_age_plateaus(sample, **kwargs)
|
|
387
|
+
if sample.Info.sample.type == "Standard":
|
|
388
|
+
return recalc_j_plateaus(sample, **kwargs)
|
|
389
|
+
if sample.Info.sample.type == "Air":
|
|
390
|
+
return recalc_j_plateaus(sample, **kwargs)
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
def recalc_age_plateaus(sample: Sample, **kwargs):
|
|
371
394
|
"""
|
|
372
395
|
Calculate age plateaus results
|
|
373
396
|
Parameters
|
|
@@ -409,18 +432,38 @@ def recalc_plateaus(sample: Sample, **kwargs):
|
|
|
409
432
|
set1_res, set1_age, set1_data = \
|
|
410
433
|
get_plateau_results(sample, sample.SelectedSequence1, calc_ar40ar39(*ratio_set1, smp=sample))
|
|
411
434
|
except ValueError:
|
|
412
|
-
|
|
435
|
+
pass
|
|
436
|
+
# raise ValueError(f"Set 1 Plateau results calculation error.")
|
|
413
437
|
else:
|
|
414
438
|
sample.Info.results.age_plateau.update({0: set1_res})
|
|
415
439
|
sample.AgeSpectraPlot.set1.data = calc.arr.transpose(set1_data)
|
|
440
|
+
sample.AgeSpectraPlot.text1.text = "" # 注意和js的配合,js那边根据text是否为空判断是否重新生成文字
|
|
416
441
|
try:
|
|
417
442
|
set2_res, set2_age, set2_data = \
|
|
418
443
|
get_plateau_results(sample, sample.SelectedSequence2, calc_ar40ar39(*ratio_set2, smp=sample))
|
|
419
444
|
except ValueError:
|
|
420
|
-
|
|
445
|
+
pass
|
|
446
|
+
# raise ValueError(f"Set 2 Plateau results calculation error.")
|
|
421
447
|
else:
|
|
422
448
|
sample.Info.results.age_plateau.update({1: set2_res})
|
|
423
449
|
sample.AgeSpectraPlot.set2.data = calc.arr.transpose(set2_data)
|
|
450
|
+
sample.AgeSpectraPlot.text2.text = "" # 注意和js的配合,js那边根据text是否为空判断是否重新生成文字
|
|
451
|
+
|
|
452
|
+
# Get weighted mean ages of two sets
|
|
453
|
+
try:
|
|
454
|
+
set1_res = get_wma_results(sample, sample.SelectedSequence1)
|
|
455
|
+
except ValueError:
|
|
456
|
+
pass
|
|
457
|
+
# raise ValueError(f"Set 1 WMA calculation error.")
|
|
458
|
+
else:
|
|
459
|
+
sample.Info.results.age_spectra.update({0: set1_res})
|
|
460
|
+
try:
|
|
461
|
+
set2_res = get_wma_results(sample, sample.SelectedSequence2)
|
|
462
|
+
except ValueError:
|
|
463
|
+
pass
|
|
464
|
+
# raise ValueError(f"Set 2 WMA calculation error.")
|
|
465
|
+
else:
|
|
466
|
+
sample.Info.results.age_spectra.update({1: set2_res})
|
|
424
467
|
|
|
425
468
|
# # """3D corrected plateaus"""
|
|
426
469
|
# # 3D ratio, 36Ar(a+cl)/40Ar(a+r), 38Ar(a+cl)/40Ar(a+r), 39Ar(k)/40Ar(a+r),
|
|
@@ -553,7 +596,7 @@ def get_plateau_results(sample: Sample, sequence: list, ar40rar39k: list = None,
|
|
|
553
596
|
'F', 'sF', 'Num', 'MSWD', 'Chisq', 'Pvalue', 'age', 's1', 's2', 's3', 'Ar39',
|
|
554
597
|
'rs', # 'rs' means relative error of the total sum
|
|
555
598
|
]
|
|
556
|
-
plateau_res = dict(zip(plateau_res_keys, [np.nan
|
|
599
|
+
plateau_res = dict(zip(plateau_res_keys, [np.nan for i in plateau_res_keys]))
|
|
557
600
|
|
|
558
601
|
def _get_partial(points, *args):
|
|
559
602
|
return [arg[min(points): max(points) + 1] for arg in args]
|
|
@@ -579,6 +622,94 @@ def get_plateau_results(sample: Sample, sequence: list, ar40rar39k: list = None,
|
|
|
579
622
|
return plateau_res, age, plot_data
|
|
580
623
|
|
|
581
624
|
|
|
625
|
+
def get_wma_results(sample: Sample, sequence: list):
|
|
626
|
+
"""
|
|
627
|
+
Get initial ratio re-corrected plateau results
|
|
628
|
+
Parameters
|
|
629
|
+
----------
|
|
630
|
+
sample : sample instance
|
|
631
|
+
sequence : data slice index
|
|
632
|
+
|
|
633
|
+
Returns
|
|
634
|
+
-------
|
|
635
|
+
three itmes tuple, result dict, age, and plot data, results keys = [
|
|
636
|
+
'F', 'sF', 'Num', 'MSWD', 'Chisq', 'Pvalue',
|
|
637
|
+
'age', 's1', 's2', 's3', 'Ar39', 'rs'
|
|
638
|
+
]
|
|
639
|
+
"""
|
|
640
|
+
spectra_res = initial.SPECTRA_RES.copy()
|
|
641
|
+
# spectra_res = initial.SPECTRA_RES
|
|
642
|
+
|
|
643
|
+
def _get_partial(points, *args):
|
|
644
|
+
return [arg[min(points): max(points) + 1] for arg in args]
|
|
645
|
+
|
|
646
|
+
if len(sequence) > 0:
|
|
647
|
+
sum_ar39k = sum(_get_partial(sequence, sample.ApparentAgeValues[7])[0])
|
|
648
|
+
fs = _get_partial(sequence, sample.ApparentAgeValues[0])[0]
|
|
649
|
+
sfs = _get_partial(sequence, sample.ApparentAgeValues[1])[0]
|
|
650
|
+
|
|
651
|
+
wmf, swmf, num, mswd, chisq, p = calc.arr.wtd_mean(fs, sfs)
|
|
652
|
+
age, s1, s2, s3 = basic.calc_age([wmf, swmf], smp=sample)
|
|
653
|
+
|
|
654
|
+
spectra_res.update({
|
|
655
|
+
'age': age, 's1': s1, 's2': s2, 's3': s3, 'Num': num, 'MSWD': mswd, 'Chisq': chisq, 'Pvalue': p,
|
|
656
|
+
'F': wmf, 'sF': swmf, 'Ar39': sum_ar39k
|
|
657
|
+
})
|
|
658
|
+
return spectra_res
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
def recalc_j_plateaus(sample: Sample, **kwargs):
|
|
662
|
+
|
|
663
|
+
print(f"Recalc J plateau")
|
|
664
|
+
|
|
665
|
+
j = sample.ApparentAgeValues[2:4]
|
|
666
|
+
|
|
667
|
+
try:
|
|
668
|
+
set1_res, _, set1_data = \
|
|
669
|
+
get_j_plateau_results(sample, sample.SelectedSequence1, j)
|
|
670
|
+
except ValueError:
|
|
671
|
+
pass
|
|
672
|
+
else:
|
|
673
|
+
sample.Info.results.age_plateau.update({0: set1_res})
|
|
674
|
+
sample.AgeSpectraPlot.set1.data = calc.arr.transpose(set1_data)
|
|
675
|
+
sample.AgeSpectraPlot.text1.text = "" # 注意和js的配合,js那边根据text是否为空判断是否重新生成文字
|
|
676
|
+
|
|
677
|
+
try:
|
|
678
|
+
set2_res, _, set2_data = \
|
|
679
|
+
get_j_plateau_results(sample, sample.SelectedSequence2, j)
|
|
680
|
+
except ValueError:
|
|
681
|
+
pass
|
|
682
|
+
else:
|
|
683
|
+
sample.Info.results.age_plateau.update({1: set2_res})
|
|
684
|
+
sample.AgeSpectraPlot.set2.data = calc.arr.transpose(set2_data)
|
|
685
|
+
sample.AgeSpectraPlot.text2.text = "" # 注意和js的配合,js那边根据text是否为空判断是否重新生成文字
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+
def get_j_plateau_results(sample: Sample, sequence: list, j: list, ar39k_percentage: list = None):
|
|
689
|
+
|
|
690
|
+
def _get_partial(points, *args):
|
|
691
|
+
# return [arg[min(points): max(points) + 1] for arg in args]
|
|
692
|
+
return [[arg[i] for i in points] for arg in args]
|
|
693
|
+
|
|
694
|
+
if ar39k_percentage is None:
|
|
695
|
+
ar39k_percentage = sample.ApparentAgeValues[7]
|
|
696
|
+
sum_ar39k = sum(_get_partial(sequence, ar39k_percentage)[0])
|
|
697
|
+
|
|
698
|
+
j_values = _get_partial(sequence, *j)
|
|
699
|
+
wmj = calc.arr.wtd_mean(*j_values)
|
|
700
|
+
plot_data = [[sum(ar39k_percentage[:min(sequence)]), sum(ar39k_percentage[:max(sequence) + 1])],
|
|
701
|
+
[wmj[0], wmj[0]]]
|
|
702
|
+
|
|
703
|
+
plateau_res_keys = [
|
|
704
|
+
'F', 'sF', 'Num', 'MSWD', 'Chisq', 'Pvalue', 'age', 's1', 's2', 's3', 'Ar39',
|
|
705
|
+
'rs', # 'rs' means relative error of the total sum
|
|
706
|
+
]
|
|
707
|
+
plateau_res = dict(zip(plateau_res_keys, [np.nan for i in plateau_res_keys]))
|
|
708
|
+
plateau_res.update(dict(zip(plateau_res_keys, [*wmj, np.nan, np.nan, np.nan, np.nan, sum_ar39k, np.nan])))
|
|
709
|
+
|
|
710
|
+
return plateau_res, 0, plot_data
|
|
711
|
+
|
|
712
|
+
|
|
582
713
|
# =======================
|
|
583
714
|
# Age Distribution Plot
|
|
584
715
|
# =======================
|
ararpy/smp/raw.py
CHANGED
|
@@ -41,18 +41,17 @@ def to_raw(file_path: Union[str, List[str]], input_filter_path: Union[str, List[
|
|
|
41
41
|
-------
|
|
42
42
|
|
|
43
43
|
"""
|
|
44
|
-
if isinstance(input_filter_path, list) and len(input_filter_path) == 1:
|
|
45
|
-
input_filter_path: str = input_filter_path[0]
|
|
46
|
-
if isinstance(file_path, list) and len(file_path) == 1:
|
|
47
|
-
file_path: str = file_path[0]
|
|
48
44
|
if isinstance(file_path, list) and isinstance(input_filter_path, list):
|
|
49
45
|
raw = concatenate([to_raw(file, input_filter_path[index]) for index, file in enumerate(file_path)])
|
|
50
46
|
elif isinstance(file_path, str) and isinstance(input_filter_path, str):
|
|
51
47
|
input_filter = read_params(input_filter_path)
|
|
52
|
-
res = raw_file.open_file(file_path, input_filter)
|
|
53
48
|
file_name = str(os.path.split(file_path)[-1]).split('.')[0]
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
res = raw_file.open_file(file_path, input_filter)
|
|
50
|
+
data = res.get('data', None)
|
|
51
|
+
sequences = res.get('sequences', None)
|
|
52
|
+
sequence_num = len(data) if data is not None else len(sequences)
|
|
53
|
+
raw = RawData(name=file_name, data=data, isotopic_num=10, sequence_num=sequence_num,
|
|
54
|
+
source=[file_path], sequence=sequences, unit=str(input_filter[30]))
|
|
56
55
|
else:
|
|
57
56
|
raise ValueError("File path and input filter should be both string or list with a same length.")
|
|
58
57
|
return raw
|
|
@@ -68,23 +67,30 @@ def concatenate(raws: List[RawData]):
|
|
|
68
67
|
-------
|
|
69
68
|
|
|
70
69
|
"""
|
|
71
|
-
|
|
70
|
+
step_names = []
|
|
72
71
|
|
|
73
72
|
def resort_sequence(seq: Sequence, index):
|
|
74
73
|
count = 0
|
|
75
|
-
while seq.name in
|
|
74
|
+
while seq.name in step_names:
|
|
76
75
|
# rename
|
|
76
|
+
if count == 0:
|
|
77
|
+
seq.name = f"{seq.name}-{index + 1}"
|
|
78
|
+
else:
|
|
79
|
+
seq.name = f"{seq.name} ({count})"
|
|
77
80
|
count = count + 1
|
|
78
|
-
|
|
79
|
-
name.append(seq.name)
|
|
81
|
+
step_names.append(seq.name)
|
|
80
82
|
seq.index = index
|
|
83
|
+
seq.is_removed = hasattr(seq, "is_removed") and seq.is_removed is True
|
|
81
84
|
return seq
|
|
82
85
|
|
|
83
86
|
source = [_source for _raw in raws for _source in _raw.source]
|
|
87
|
+
unit = set([_raw.unit for _raw in raws])
|
|
88
|
+
unit = list(unit)[0] if len(unit) == 1 else 'Unknown Unit'
|
|
84
89
|
sequence = [resort_sequence(seq, index) for index, seq in enumerate([i for _raw in raws for i in _raw.sequence])]
|
|
85
90
|
sequence_num = len(sequence)
|
|
86
|
-
|
|
87
|
-
|
|
91
|
+
exp_names = list(set([_raw.name for _raw in raws]))
|
|
92
|
+
return RawData(name='&'.join(exp_names), source=source, isotopic_num=10,
|
|
93
|
+
sequence_num=sequence_num, sequence=sequence, unit=unit)
|
|
88
94
|
|
|
89
95
|
|
|
90
96
|
def get_sequence(raw: RawData, index: Optional[Union[list, int, str, bool]] = None,
|
|
@@ -126,7 +132,6 @@ def do_regression(raw: RawData, sequence_index: Optional[List] = None, isotopic_
|
|
|
126
132
|
raw
|
|
127
133
|
sequence_index
|
|
128
134
|
isotopic_index
|
|
129
|
-
flag
|
|
130
135
|
|
|
131
136
|
Returns
|
|
132
137
|
-------
|
|
@@ -147,6 +152,7 @@ def do_regression(raw: RawData, sequence_index: Optional[List] = None, isotopic_
|
|
|
147
152
|
for index, isotope in enumerate(selected):
|
|
148
153
|
if hasattr(isotopic_index, '__getitem__') and index not in isotopic_index:
|
|
149
154
|
continue
|
|
155
|
+
# print(f"regression for {sequence.name = }, isotope {index = }")
|
|
150
156
|
res = raw_funcs.get_raw_data_regression_results(isotope)
|
|
151
157
|
try:
|
|
152
158
|
sequence.results[index] = res[1]
|