ararpy 0.1.18__py3-none-any.whl → 0.1.20__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 +4 -2
- ararpy/calc/age.py +2 -1
- ararpy/calc/arr.py +16 -6
- ararpy/calc/corr.py +9 -7
- ararpy/calc/jvalue.py +1 -1
- ararpy/calc/plot.py +5 -2
- ararpy/files/calc_file.py +2 -5
- ararpy/files/raw_file.py +3 -4
- ararpy/files/xls.py +1 -2
- ararpy/smp/basic.py +119 -70
- ararpy/smp/corr.py +69 -51
- ararpy/smp/export.py +223 -250
- ararpy/smp/initial.py +49 -18
- ararpy/smp/plots.py +129 -92
- ararpy/smp/sample.py +56 -17
- ararpy/smp/style.py +23 -16
- {ararpy-0.1.18.dist-info → ararpy-0.1.20.dist-info}/METADATA +1 -1
- {ararpy-0.1.18.dist-info → ararpy-0.1.20.dist-info}/RECORD +21 -21
- {ararpy-0.1.18.dist-info → ararpy-0.1.20.dist-info}/WHEEL +1 -1
- {ararpy-0.1.18.dist-info → ararpy-0.1.20.dist-info}/licenses/LICENSE +0 -0
- {ararpy-0.1.18.dist-info → ararpy-0.1.20.dist-info}/top_level.txt +0 -0
ararpy/smp/initial.py
CHANGED
|
@@ -16,7 +16,7 @@ import pandas as pd
|
|
|
16
16
|
import numpy as np
|
|
17
17
|
import copy
|
|
18
18
|
from typing import List, Union, Optional
|
|
19
|
-
from ..calc import arr
|
|
19
|
+
from ..calc import arr, err
|
|
20
20
|
from ..files import calc_file
|
|
21
21
|
from . import (sample as samples, basic, table, raw as smp_raw)
|
|
22
22
|
|
|
@@ -141,7 +141,8 @@ def initial(smp: Sample):
|
|
|
141
141
|
setattr(smp, 'Info', ArArBasic(
|
|
142
142
|
id='0', name='info', attr_name='Info', arr_version=samples.VERSION,
|
|
143
143
|
sample=ArArBasic(
|
|
144
|
-
name='SAMPLE NAME', material='MATERIAL', location='LOCATION', type='Unknown'
|
|
144
|
+
name='SAMPLE NAME', material='MATERIAL', location='LOCATION', type='Unknown', method='',
|
|
145
|
+
sequence_unit='', weight=''
|
|
145
146
|
),
|
|
146
147
|
researcher=ArArBasic(
|
|
147
148
|
name='RESEARCHER', addr='ADDRESS', email='EMAIL'
|
|
@@ -182,7 +183,10 @@ def initial(smp: Sample):
|
|
|
182
183
|
reference=ArArBasic(
|
|
183
184
|
name='REFERENCE', journal='JOURNAL', doi='DOI'
|
|
184
185
|
),
|
|
185
|
-
preference=copy.deepcopy(PREFERENCE_RES)
|
|
186
|
+
preference=copy.deepcopy(PREFERENCE_RES),
|
|
187
|
+
experiment=ArArBasic(
|
|
188
|
+
name='', mass_spec='', collectors='', step_num=0
|
|
189
|
+
),
|
|
186
190
|
))
|
|
187
191
|
|
|
188
192
|
decimal_places = PREFERENCE_RES['decimalPlaces']
|
|
@@ -233,7 +237,7 @@ def initial(smp: Sample):
|
|
|
233
237
|
return smp
|
|
234
238
|
|
|
235
239
|
|
|
236
|
-
def initial_plot_styles(
|
|
240
|
+
def initial_plot_styles(smp: Sample, except_attrs=None):
|
|
237
241
|
"""
|
|
238
242
|
Initialize plot components styles based on Default Styles. Except attrs is a list containing attrs
|
|
239
243
|
that are not expected to be initialized.
|
|
@@ -257,17 +261,26 @@ def initial_plot_styles(sample: Sample, except_attrs=None):
|
|
|
257
261
|
for k, v in value.items():
|
|
258
262
|
set_attr(getattr(obj, name), k, v)
|
|
259
263
|
|
|
260
|
-
default_styles =
|
|
264
|
+
default_styles = get_default_plot_style(smp)
|
|
261
265
|
for figure_index, figure_attr in default_styles.items():
|
|
262
|
-
plot = getattr(
|
|
266
|
+
plot = getattr(smp, figure_attr['attr_name'], Plot())
|
|
263
267
|
for key, attr in figure_attr.items():
|
|
264
268
|
set_attr(plot, key, attr)
|
|
265
269
|
|
|
266
270
|
|
|
267
|
-
def
|
|
271
|
+
def get_default_plot_style(smp: Sample):
|
|
272
|
+
sample_type = smp.Info.sample.type
|
|
273
|
+
try:
|
|
274
|
+
age_unit = str(smp.Info.preference['ageUnit']).capitalize()
|
|
275
|
+
except:
|
|
276
|
+
age_unit = "Undefined"
|
|
277
|
+
return copy.deepcopy(samples.DEFAULT_PLOT_STYLES(sample_type, age_unit))
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
def re_set_smp(smp: Sample):
|
|
268
281
|
std = initial(Sample())
|
|
269
|
-
basic.get_merged_smp(
|
|
270
|
-
return
|
|
282
|
+
basic.get_merged_smp(smp, std)
|
|
283
|
+
return check_version(smp)
|
|
271
284
|
|
|
272
285
|
|
|
273
286
|
def check_version(smp: Sample):
|
|
@@ -282,7 +295,28 @@ def check_version(smp: Sample):
|
|
|
282
295
|
|
|
283
296
|
"""
|
|
284
297
|
if smp.version != samples.VERSION:
|
|
285
|
-
|
|
298
|
+
std = initial(Sample())
|
|
299
|
+
basic.get_merged_smp(smp, std)
|
|
300
|
+
|
|
301
|
+
# 20250328: # Experiment info
|
|
302
|
+
smp.Info.experiment.name = smp.name()
|
|
303
|
+
smp.Info.experiment.step_num = smp.sequence().size
|
|
304
|
+
|
|
305
|
+
# 20250404
|
|
306
|
+
doNormalize = True
|
|
307
|
+
v, sv = [], []
|
|
308
|
+
if smp.Info.sample.type.lower() == "unknown":
|
|
309
|
+
v, sv = smp.TotalParam[67:69]
|
|
310
|
+
sv = np.multiply(v, sv) / 100
|
|
311
|
+
elif smp.Info.sample.type.lower() == "air":
|
|
312
|
+
v, sv = smp.TotalParam[93:95]
|
|
313
|
+
sv = np.multiply(v, sv) / 100
|
|
314
|
+
elif smp.Info.sample.type.lower() == "standard":
|
|
315
|
+
v, sv = smp.TotalParam[59:61]
|
|
316
|
+
smp.NormalizeFactor = [
|
|
317
|
+
[1 if v[0] == each or not doNormalize else v[0] / each for each in v],
|
|
318
|
+
[0 if v[0] == v[i] or not doNormalize else err.div((v[0], sv[0]), (v[i], sv[i])) for i in range(len(v))]
|
|
319
|
+
]
|
|
286
320
|
return smp
|
|
287
321
|
|
|
288
322
|
|
|
@@ -328,11 +362,8 @@ def from_arr_files(file_path, sample_name: str = ""):
|
|
|
328
362
|
def renamed_load(file_obj):
|
|
329
363
|
return RenameUnpickler(file_obj).load()
|
|
330
364
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
sample = renamed_load(f)
|
|
334
|
-
except (Exception, BaseException):
|
|
335
|
-
raise ValueError(f"Fail to open arr file: {file_path}")
|
|
365
|
+
with open(file_path, 'rb') as f:
|
|
366
|
+
sample = renamed_load(f)
|
|
336
367
|
# Check arr version
|
|
337
368
|
# recalculation will not be applied automatically
|
|
338
369
|
return check_version(sample)
|
|
@@ -352,7 +383,7 @@ def from_calc_files(file_path: str, **kwargs):
|
|
|
352
383
|
"""
|
|
353
384
|
file = calc_file.ArArCalcFile(file_path=file_path, **kwargs).open()
|
|
354
385
|
sample = create_sample_from_df(file.get_content(), file.get_smp_info())
|
|
355
|
-
return sample
|
|
386
|
+
return check_version(sample)
|
|
356
387
|
|
|
357
388
|
|
|
358
389
|
# create
|
|
@@ -371,7 +402,7 @@ def from_full_files(file_path: str, sample_name: str = None):
|
|
|
371
402
|
sample_name = str(os.path.split(file_path)[-1]).split('.')[0]
|
|
372
403
|
content, sample_info = calc_file.open_full_xls(file_path, sample_name)
|
|
373
404
|
sample = create_sample_from_dict(content=content, smp_info=sample_info)
|
|
374
|
-
return sample
|
|
405
|
+
return check_version(sample)
|
|
375
406
|
|
|
376
407
|
|
|
377
408
|
# create
|
|
@@ -449,4 +480,4 @@ def from_raw_data(raw: RawData, mapping: Optional[List[dict]] = None) -> Sample:
|
|
|
449
480
|
|
|
450
481
|
# sample.TotalParam[31] = [raw.get_sequence(row['unknown'], flag='name').datetime for row in mapping]
|
|
451
482
|
|
|
452
|
-
return sample
|
|
483
|
+
return check_version(sample)
|
ararpy/smp/plots.py
CHANGED
|
@@ -89,27 +89,27 @@ def set_plot_data(sample: Sample, isInit: bool = True, isIsochron: bool = True,
|
|
|
89
89
|
# =======================
|
|
90
90
|
# Initialize plot data
|
|
91
91
|
# =======================
|
|
92
|
-
def initial_plot_data(
|
|
92
|
+
def initial_plot_data(smp: Sample):
|
|
93
93
|
"""
|
|
94
94
|
Assign initial data for plots
|
|
95
95
|
Parameters
|
|
96
96
|
----------
|
|
97
|
-
|
|
97
|
+
smp : Sample instance
|
|
98
98
|
|
|
99
99
|
Returns
|
|
100
100
|
-------
|
|
101
101
|
None
|
|
102
102
|
"""
|
|
103
103
|
for key, val in ISOCHRON_INDEX_DICT.items():
|
|
104
|
-
figure = basic.get_component_byid(
|
|
104
|
+
figure = basic.get_component_byid(smp, key)
|
|
105
105
|
try:
|
|
106
106
|
# data = [x, sx, y, sy, (z, sz,) r1, (r2, r3,), index from 1]
|
|
107
|
-
figure.data =
|
|
108
|
-
[[i + 1 for i in range(len(
|
|
107
|
+
figure.data = smp.IsochronValues[val['data_index'][0]:val['data_index'][1]] + \
|
|
108
|
+
[[i + 1 for i in range(len(smp.SequenceName))]]
|
|
109
109
|
except (Exception, BaseException):
|
|
110
110
|
print(traceback.format_exc())
|
|
111
111
|
figure.data = [[]] * (val['data_index'][1] - val['data_index'][0]) + \
|
|
112
|
-
[[i + 1 for i in range(len(
|
|
112
|
+
[[i + 1 for i in range(len(smp.SequenceName))]]
|
|
113
113
|
finally:
|
|
114
114
|
# Ellipse
|
|
115
115
|
if key != 'figure_7':
|
|
@@ -122,51 +122,62 @@ def initial_plot_data(sample: Sample):
|
|
|
122
122
|
# Set age spectra lines
|
|
123
123
|
# Try to calculate total gas age
|
|
124
124
|
try:
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
if str(smp.Info.sample.type).lower() == "unknown":
|
|
126
|
+
a0, e0 = sum(smp.DegasValues[24]), pow(sum([i ** 2 for i in smp.DegasValues[25]]), 0.5)
|
|
127
|
+
a1, e1 = sum(smp.DegasValues[20]), pow(sum([i ** 2 for i in smp.DegasValues[21]]), 0.5)
|
|
128
|
+
handle = basic.calc_age
|
|
129
|
+
elif str(smp.Info.sample.type).lower() == "standard":
|
|
130
|
+
a0, e0 = sum(smp.DegasValues[24]), pow(sum([i ** 2 for i in smp.DegasValues[25]]), 0.5)
|
|
131
|
+
a1, e1 = sum(smp.DegasValues[20]), pow(sum([i ** 2 for i in smp.DegasValues[21]]), 0.5)
|
|
132
|
+
handle = basic.calc_j
|
|
133
|
+
elif str(smp.Info.sample.type).lower() == "air":
|
|
134
|
+
a0, e0 = sum(smp.DegasValues[26]), pow(sum([i ** 2 for i in smp.DegasValues[27]]), 0.5)
|
|
135
|
+
a1, e1 = sum(smp.DegasValues[ 0]), pow(sum([i ** 2 for i in smp.DegasValues[ 1]]), 0.5)
|
|
136
|
+
handle = basic.calc_mdf
|
|
137
|
+
else:
|
|
138
|
+
raise TypeError(f"Sample type is not supported: {smp.Info.sample.type}")
|
|
127
139
|
total_f = [a0 / a1, calc.err.div((a0, e0), (a1, e1))]
|
|
128
|
-
total_age =
|
|
140
|
+
total_age = handle(total_f[:2], smp=smp)
|
|
129
141
|
except (Exception, BaseException):
|
|
130
142
|
print(traceback.format_exc())
|
|
131
143
|
total_f = [np.nan] * 2
|
|
132
144
|
total_age = [np.nan] * 4
|
|
133
|
-
|
|
145
|
+
smp.Info.results.age_spectra['TGA'].update(
|
|
134
146
|
{'Ar39': 100, 'F': total_f[0], 'sF': total_f[1], 'age': total_age[0],
|
|
135
|
-
's1': total_age[1], 's2': total_age[2], 's3': total_age[3], 'Num': len(
|
|
147
|
+
's1': total_age[1], 's2': total_age[2], 's3': total_age[3], 'Num': len(smp.DegasValues[24])}
|
|
136
148
|
)
|
|
137
149
|
try:
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
sample.AgeSpectraPlot.data = calc.arr.transpose(sample.AgeSpectraPlot.data)
|
|
150
|
+
smp.AgeSpectraPlot.data = calc.spectra.get_data(*smp.ApparentAgeValues[2:4], smp.ApparentAgeValues[7])
|
|
151
|
+
smp.AgeSpectraPlot.data = calc.arr.transpose(smp.AgeSpectraPlot.data)
|
|
141
152
|
except (Exception, BaseException):
|
|
142
153
|
print(traceback.format_exc())
|
|
143
|
-
|
|
154
|
+
smp.AgeSpectraPlot.data = []
|
|
144
155
|
|
|
145
156
|
# Degassing plot
|
|
146
157
|
try:
|
|
147
|
-
if not hasattr(
|
|
148
|
-
setattr(
|
|
158
|
+
if not hasattr(smp, 'DegasPatternPlot'):
|
|
159
|
+
setattr(smp, 'DegasPatternPlot', Plot(id='figure_8', name='Degas Pattern Plot'))
|
|
149
160
|
isotope_percentage = lambda l: [e / sum(l) * 100 if sum(l) != 0 else 0 for e in l]
|
|
150
|
-
|
|
151
|
-
isotope_percentage(
|
|
152
|
-
isotope_percentage(
|
|
153
|
-
isotope_percentage(
|
|
154
|
-
isotope_percentage(
|
|
155
|
-
isotope_percentage(
|
|
156
|
-
isotope_percentage(
|
|
157
|
-
isotope_percentage(
|
|
158
|
-
isotope_percentage(
|
|
159
|
-
isotope_percentage(
|
|
160
|
-
isotope_percentage(
|
|
161
|
+
smp.DegasPatternPlot.data = [
|
|
162
|
+
isotope_percentage(smp.DegasValues[0]), # Ar36a
|
|
163
|
+
isotope_percentage(smp.DegasValues[8]), # Ar37Ca
|
|
164
|
+
isotope_percentage(smp.DegasValues[10]), # Ar38Cl
|
|
165
|
+
isotope_percentage(smp.DegasValues[20]), # Ar39K
|
|
166
|
+
isotope_percentage(smp.DegasValues[24]), # Ar40r
|
|
167
|
+
isotope_percentage(smp.CorrectedValues[0]), # Ar36
|
|
168
|
+
isotope_percentage(smp.CorrectedValues[2]), # Ar37
|
|
169
|
+
isotope_percentage(smp.CorrectedValues[4]), # Ar38
|
|
170
|
+
isotope_percentage(smp.CorrectedValues[6]), # Ar39
|
|
171
|
+
isotope_percentage(smp.CorrectedValues[8]), # Ar40
|
|
161
172
|
]
|
|
162
|
-
|
|
173
|
+
smp.DegasPatternPlot.info = [True] * 10
|
|
163
174
|
except Exception as e:
|
|
164
175
|
print(traceback.format_exc())
|
|
165
176
|
pass
|
|
166
177
|
|
|
167
178
|
# Set age distribution plot data
|
|
168
179
|
try:
|
|
169
|
-
recalc_agedistribution(
|
|
180
|
+
recalc_agedistribution(smp)
|
|
170
181
|
except Exception as e:
|
|
171
182
|
print(traceback.format_exc())
|
|
172
183
|
|
|
@@ -315,11 +326,9 @@ def get_3D_results(data: list, sequence: list, sample: Sample):
|
|
|
315
326
|
age = basic.calc_age([f, sf], smp=sample)
|
|
316
327
|
except:
|
|
317
328
|
# print(f"Warning: {traceback.format_exc()}")
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
ar40ar36, sar40ar36, P
|
|
321
|
-
f, sf = 0, 0
|
|
322
|
-
iso_res.update(dict(zip(iso_res, [*k, *age, np.nan, ar40ar36, sar40ar36, P, f, sf])))
|
|
329
|
+
pass
|
|
330
|
+
else:
|
|
331
|
+
iso_res.update(dict(zip(iso_res, [*k, *age, np.nan, ar40ar36, sar40ar36, P, f, sf])))
|
|
323
332
|
return iso_res
|
|
324
333
|
|
|
325
334
|
|
|
@@ -392,7 +401,7 @@ def recalc_plateaus(sample: Sample, **kwargs):
|
|
|
392
401
|
if sample.Info.sample.type == "Standard":
|
|
393
402
|
return recalc_j_plateaus(sample, **kwargs)
|
|
394
403
|
if sample.Info.sample.type == "Air":
|
|
395
|
-
return
|
|
404
|
+
return recalc_mdf_plateaus(sample, **kwargs)
|
|
396
405
|
|
|
397
406
|
|
|
398
407
|
def recalc_age_plateaus(sample: Sample, **kwargs):
|
|
@@ -407,6 +416,9 @@ def recalc_age_plateaus(sample: Sample, **kwargs):
|
|
|
407
416
|
-------
|
|
408
417
|
None
|
|
409
418
|
"""
|
|
419
|
+
ar39k, sar39k = calc.arr.mul(sample.DegasValues[20:22], sample.NormalizeFactor)
|
|
420
|
+
ar40r, sar40r = sample.DegasValues[24:26]
|
|
421
|
+
ar40rar39k = calc.arr.div([ar40r, sar40r], [ar39k, sar39k])
|
|
410
422
|
params_initial_ratio = calc.arr.partial(sample.TotalParam, cols=list(range(115, 120)))
|
|
411
423
|
ratio_set1 = [[], []]
|
|
412
424
|
ratio_set2 = [[], []]
|
|
@@ -432,10 +444,12 @@ def recalc_age_plateaus(sample: Sample, **kwargs):
|
|
|
432
444
|
ratio_set2[0].append(298.56)
|
|
433
445
|
ratio_set2[1].append(0.31)
|
|
434
446
|
|
|
435
|
-
#
|
|
447
|
+
# Weighted mean ages of two sets with the given initial ratios
|
|
436
448
|
try:
|
|
437
|
-
set1_res, set1_age, set1_data =
|
|
438
|
-
|
|
449
|
+
set1_res, set1_age, set1_data = get_plateau_results(
|
|
450
|
+
sample, sample.SelectedSequence1, calc_ar40ar39(*ratio_set1, smp=sample),
|
|
451
|
+
ar39k_percentage=np.array(ar39k) / np.sum(ar39k),
|
|
452
|
+
**kwargs)
|
|
439
453
|
except ValueError:
|
|
440
454
|
# print(traceback.format_exc())
|
|
441
455
|
pass
|
|
@@ -445,8 +459,10 @@ def recalc_age_plateaus(sample: Sample, **kwargs):
|
|
|
445
459
|
sample.AgeSpectraPlot.set1.data = calc.arr.transpose(set1_data)
|
|
446
460
|
sample.AgeSpectraPlot.text1.text = "" # 注意和js的配合,js那边根据text是否为空判断是否重新生成文字
|
|
447
461
|
try:
|
|
448
|
-
set2_res, set2_age, set2_data =
|
|
449
|
-
|
|
462
|
+
set2_res, set2_age, set2_data = get_plateau_results(
|
|
463
|
+
sample, sample.SelectedSequence2, calc_ar40ar39(*ratio_set2, smp=sample),
|
|
464
|
+
ar39k_percentage=np.array(ar39k) / np.sum(ar39k),
|
|
465
|
+
**kwargs)
|
|
450
466
|
except ValueError:
|
|
451
467
|
# print(traceback.format_exc())
|
|
452
468
|
pass
|
|
@@ -456,16 +472,18 @@ def recalc_age_plateaus(sample: Sample, **kwargs):
|
|
|
456
472
|
sample.AgeSpectraPlot.set2.data = calc.arr.transpose(set2_data)
|
|
457
473
|
sample.AgeSpectraPlot.text2.text = "" # 注意和js的配合,js那边根据text是否为空判断是否重新生成文字
|
|
458
474
|
|
|
459
|
-
#
|
|
475
|
+
# Weighted mean ages of two sets with 298.56 (defoult air ratio)
|
|
460
476
|
try:
|
|
461
|
-
set1_res = get_wma_results(
|
|
477
|
+
set1_res = get_wma_results(
|
|
478
|
+
sample, sample.SelectedSequence1, ar40rar39k=ar40rar39k, ar39k_percentage=np.array(ar39k) / np.sum(ar39k))
|
|
462
479
|
except ValueError:
|
|
463
480
|
pass
|
|
464
481
|
# raise ValueError(f"Set 1 WMA calculation error.")
|
|
465
482
|
else:
|
|
466
483
|
sample.Info.results.age_spectra.update({0: set1_res})
|
|
467
484
|
try:
|
|
468
|
-
set2_res = get_wma_results(
|
|
485
|
+
set2_res = get_wma_results(
|
|
486
|
+
sample, sample.SelectedSequence2, ar40rar39k=ar40rar39k, ar39k_percentage=np.array(ar39k) / np.sum(ar39k))
|
|
469
487
|
except ValueError:
|
|
470
488
|
pass
|
|
471
489
|
# raise ValueError(f"Set 2 WMA calculation error.")
|
|
@@ -545,6 +563,41 @@ def recalc_age_plateaus(sample: Sample, **kwargs):
|
|
|
545
563
|
# # """end"""
|
|
546
564
|
|
|
547
565
|
|
|
566
|
+
def recalc_mdf_plateaus(sample: Sample, **kwargs):
|
|
567
|
+
"""
|
|
568
|
+
Calculate age plateaus results
|
|
569
|
+
Parameters
|
|
570
|
+
----------
|
|
571
|
+
sample : sample instance
|
|
572
|
+
kwargs : optional args, keys in [r1, sr1, r2, sr2]
|
|
573
|
+
|
|
574
|
+
Returns
|
|
575
|
+
-------
|
|
576
|
+
None
|
|
577
|
+
"""
|
|
578
|
+
ar36a, sar36a = calc.arr.mul(sample.DegasValues[0:2], sample.NormalizeFactor)
|
|
579
|
+
ar40aar36a = sample.ApparentAgeValues[0:2]
|
|
580
|
+
mdf = sample.ApparentAgeValues[2:4]
|
|
581
|
+
|
|
582
|
+
try:
|
|
583
|
+
set1_res, _, set1_data = get_plateau_results(sample, sample.SelectedSequence1, ar40rar39k=ar40aar36a)
|
|
584
|
+
except ValueError:
|
|
585
|
+
pass
|
|
586
|
+
else:
|
|
587
|
+
sample.Info.results.age_plateau.update({0: set1_res})
|
|
588
|
+
sample.AgeSpectraPlot.set1.data = calc.arr.transpose(set1_data)
|
|
589
|
+
sample.AgeSpectraPlot.text1.text = ""
|
|
590
|
+
|
|
591
|
+
try:
|
|
592
|
+
set2_res, _, set2_data = get_plateau_results(sample, sample.SelectedSequence2, ar40rar39k=ar40aar36a)
|
|
593
|
+
except ValueError:
|
|
594
|
+
pass
|
|
595
|
+
else:
|
|
596
|
+
sample.Info.results.age_plateau.update({1: set2_res})
|
|
597
|
+
sample.AgeSpectraPlot.set2.data = calc.arr.transpose(set2_data)
|
|
598
|
+
sample.AgeSpectraPlot.text2.text = ""
|
|
599
|
+
|
|
600
|
+
|
|
548
601
|
def calc_ar40ar39(r, sr, smp):
|
|
549
602
|
"""
|
|
550
603
|
Calculate Ar40r / Ar39K based on passed initial ratio.
|
|
@@ -560,7 +613,7 @@ def calc_ar40ar39(r, sr, smp):
|
|
|
560
613
|
"""
|
|
561
614
|
try:
|
|
562
615
|
ar36a = np.array(smp.DegasValues[0:2])
|
|
563
|
-
ar39k = smp.DegasValues[20:22]
|
|
616
|
+
ar39k = calc.arr.mul(smp.DegasValues[20:22], smp.NormalizeFactor)
|
|
564
617
|
ar40 = smp.CorrectedValues[8:10]
|
|
565
618
|
ar40k = smp.DegasValues[30:32]
|
|
566
619
|
size = ar36a.shape[-1]
|
|
@@ -570,8 +623,6 @@ def calc_ar40ar39(r, sr, smp):
|
|
|
570
623
|
ratio = np.array([r, sr])
|
|
571
624
|
else:
|
|
572
625
|
raise ValueError(f"Initial ratio is unsupported.")
|
|
573
|
-
# print(f"{ratio = }")
|
|
574
|
-
# print(f"{ar36a = }")
|
|
575
626
|
ar40a = calc.arr.mul(ar36a, ratio)
|
|
576
627
|
ar40r = calc.arr.sub(ar40, ar40k, ar40a)
|
|
577
628
|
ar40rar39k: list = calc.arr.div(ar40r, ar39k)
|
|
@@ -581,20 +632,20 @@ def calc_ar40ar39(r, sr, smp):
|
|
|
581
632
|
return ar40rar39k
|
|
582
633
|
|
|
583
634
|
|
|
584
|
-
def get_plateau_results(
|
|
635
|
+
def get_plateau_results(smp: Sample, sequence: list, ar40rar39k: list = None,
|
|
585
636
|
ar39k_percentage: list = None, **kwargs):
|
|
586
637
|
"""
|
|
587
638
|
Get initial ratio re-corrected plateau results
|
|
588
639
|
Parameters
|
|
589
640
|
----------
|
|
590
|
-
|
|
641
|
+
smp : sample instance
|
|
591
642
|
sequence : data slice index
|
|
592
643
|
ar40rar39k :
|
|
593
644
|
ar39k_percentage : Ar39K released
|
|
594
645
|
|
|
595
646
|
Returns
|
|
596
647
|
-------
|
|
597
|
-
three
|
|
648
|
+
three items tuple, result dict, age, and plot data, results keys = [
|
|
598
649
|
'F', 'sF', 'Num', 'MSWD', 'Chisq', 'Pvalue',
|
|
599
650
|
'age', 's1', 's2', 's3', 'Ar39', 'rs'
|
|
600
651
|
]
|
|
@@ -611,31 +662,40 @@ def get_plateau_results(sample: Sample, sequence: list, ar40rar39k: list = None,
|
|
|
611
662
|
if len(sequence) == 0:
|
|
612
663
|
return plateau_res, [], []
|
|
613
664
|
if ar40rar39k is None:
|
|
614
|
-
ar40rar39k =
|
|
665
|
+
ar40rar39k = smp.ApparentAgeValues[0:2]
|
|
615
666
|
if ar39k_percentage is None:
|
|
616
|
-
ar39k_percentage =
|
|
667
|
+
ar39k_percentage = smp.ApparentAgeValues[7]
|
|
668
|
+
|
|
669
|
+
if str(smp.Info.sample.type).lower() == "unknown":
|
|
670
|
+
handle = basic.calc_age
|
|
671
|
+
elif str(smp.Info.sample.type).lower() == "standard":
|
|
672
|
+
handle = basic.calc_j
|
|
673
|
+
elif str(smp.Info.sample.type).lower() == "air":
|
|
674
|
+
handle = basic.calc_mdf
|
|
675
|
+
else:
|
|
676
|
+
raise TypeError(f"Sample type is not supported: {smp.Info.sample.type}")
|
|
617
677
|
|
|
618
|
-
age =
|
|
678
|
+
age = handle(ar40ar39=ar40rar39k, smp=smp)[0:2]
|
|
619
679
|
plot_data = calc.spectra.get_data(*age, ar39k_percentage, indices=sequence, **kwargs)
|
|
620
680
|
f_values = _get_partial(sequence, *ar40rar39k)
|
|
621
681
|
age = _get_partial(sequence, *age)
|
|
622
682
|
sum_ar39k = sum(_get_partial(sequence, ar39k_percentage)[0])
|
|
623
683
|
wmf = calc.arr.wtd_mean(*f_values)
|
|
624
|
-
wmage =
|
|
684
|
+
wmage = handle(wmf[0:2], smp=smp)
|
|
625
685
|
|
|
626
|
-
plateau_res.update(dict(zip(
|
|
627
|
-
plateau_res_keys, [*wmf, *wmage, sum_ar39k, np.nan]
|
|
628
|
-
)))
|
|
686
|
+
plateau_res.update(dict(zip(plateau_res_keys, [*wmf, *wmage, sum_ar39k, np.nan])))
|
|
629
687
|
return plateau_res, age, plot_data
|
|
630
688
|
|
|
631
689
|
|
|
632
|
-
def get_wma_results(sample: Sample, sequence: list):
|
|
690
|
+
def get_wma_results(sample: Sample, sequence: list, ar40rar39k: list = None, ar39k_percentage: list = None):
|
|
633
691
|
"""
|
|
634
692
|
Get initial ratio re-corrected plateau results
|
|
635
693
|
Parameters
|
|
636
694
|
----------
|
|
637
695
|
sample : sample instance
|
|
638
696
|
sequence : data slice index
|
|
697
|
+
ar40rar39k :
|
|
698
|
+
ar39k_percentage :
|
|
639
699
|
|
|
640
700
|
Returns
|
|
641
701
|
-------
|
|
@@ -644,6 +704,11 @@ def get_wma_results(sample: Sample, sequence: list):
|
|
|
644
704
|
'age', 's1', 's2', 's3', 'Ar39', 'rs'
|
|
645
705
|
]
|
|
646
706
|
"""
|
|
707
|
+
if ar40rar39k is None:
|
|
708
|
+
ar40rar39k = sample.ApparentAgeValues[0:2]
|
|
709
|
+
if ar39k_percentage is None:
|
|
710
|
+
ar39k_percentage = sample.ApparentAgeValues[7]
|
|
711
|
+
|
|
647
712
|
spectra_res = initial.SPECTRA_RES.copy()
|
|
648
713
|
# spectra_res = initial.SPECTRA_RES
|
|
649
714
|
|
|
@@ -651,9 +716,9 @@ def get_wma_results(sample: Sample, sequence: list):
|
|
|
651
716
|
return [arg[min(points): max(points) + 1] for arg in args]
|
|
652
717
|
|
|
653
718
|
if len(sequence) > 0:
|
|
654
|
-
sum_ar39k = sum(_get_partial(sequence,
|
|
655
|
-
fs = _get_partial(sequence,
|
|
656
|
-
sfs = _get_partial(sequence,
|
|
719
|
+
sum_ar39k = sum(_get_partial(sequence, ar39k_percentage)[0])
|
|
720
|
+
fs = _get_partial(sequence, ar40rar39k[0])[0]
|
|
721
|
+
sfs = _get_partial(sequence, ar40rar39k[1])[0]
|
|
657
722
|
|
|
658
723
|
wmf, swmf, num, mswd, chisq, p = calc.arr.wtd_mean(fs, sfs)
|
|
659
724
|
age, s1, s2, s3 = basic.calc_age([wmf, swmf], smp=sample)
|
|
@@ -667,13 +732,11 @@ def get_wma_results(sample: Sample, sequence: list):
|
|
|
667
732
|
|
|
668
733
|
def recalc_j_plateaus(sample: Sample, **kwargs):
|
|
669
734
|
|
|
670
|
-
|
|
671
|
-
|
|
735
|
+
ar40rar39k = sample.ApparentAgeValues[0:2]
|
|
672
736
|
j = sample.ApparentAgeValues[2:4]
|
|
673
737
|
|
|
674
738
|
try:
|
|
675
|
-
set1_res, _, set1_data =
|
|
676
|
-
get_j_plateau_results(sample, sample.SelectedSequence1, j)
|
|
739
|
+
set1_res, _, set1_data = get_plateau_results(sample, sample.SelectedSequence1, ar40rar39k=ar40rar39k)
|
|
677
740
|
except ValueError:
|
|
678
741
|
pass
|
|
679
742
|
else:
|
|
@@ -682,8 +745,7 @@ def recalc_j_plateaus(sample: Sample, **kwargs):
|
|
|
682
745
|
sample.AgeSpectraPlot.text1.text = "" # 注意和js的配合,js那边根据text是否为空判断是否重新生成文字
|
|
683
746
|
|
|
684
747
|
try:
|
|
685
|
-
set2_res, _, set2_data =
|
|
686
|
-
get_j_plateau_results(sample, sample.SelectedSequence2, j)
|
|
748
|
+
set2_res, _, set2_data = get_plateau_results(sample, sample.SelectedSequence2, ar40rar39k=ar40rar39k)
|
|
687
749
|
except ValueError:
|
|
688
750
|
pass
|
|
689
751
|
else:
|
|
@@ -692,31 +754,6 @@ def recalc_j_plateaus(sample: Sample, **kwargs):
|
|
|
692
754
|
sample.AgeSpectraPlot.text2.text = "" # 注意和js的配合,js那边根据text是否为空判断是否重新生成文字
|
|
693
755
|
|
|
694
756
|
|
|
695
|
-
def get_j_plateau_results(sample: Sample, sequence: list, j: list, ar39k_percentage: list = None):
|
|
696
|
-
|
|
697
|
-
def _get_partial(points, *args):
|
|
698
|
-
# return [arg[min(points): max(points) + 1] for arg in args]
|
|
699
|
-
return [[arg[i] for i in points] for arg in args]
|
|
700
|
-
|
|
701
|
-
if ar39k_percentage is None:
|
|
702
|
-
ar39k_percentage = sample.ApparentAgeValues[7]
|
|
703
|
-
sum_ar39k = sum(_get_partial(sequence, ar39k_percentage)[0])
|
|
704
|
-
|
|
705
|
-
j_values = _get_partial(sequence, *j)
|
|
706
|
-
wmj = calc.arr.wtd_mean(*j_values)
|
|
707
|
-
plot_data = [[sum(ar39k_percentage[:min(sequence)]), sum(ar39k_percentage[:max(sequence) + 1])],
|
|
708
|
-
[wmj[0], wmj[0]]]
|
|
709
|
-
|
|
710
|
-
plateau_res_keys = [
|
|
711
|
-
'F', 'sF', 'Num', 'MSWD', 'Chisq', 'Pvalue', 'age', 's1', 's2', 's3', 'Ar39',
|
|
712
|
-
'rs', # 'rs' means relative error of the total sum
|
|
713
|
-
]
|
|
714
|
-
plateau_res = dict(zip(plateau_res_keys, [np.nan for i in plateau_res_keys]))
|
|
715
|
-
plateau_res.update(dict(zip(plateau_res_keys, [*wmj, np.nan, np.nan, np.nan, np.nan, sum_ar39k, np.nan])))
|
|
716
|
-
|
|
717
|
-
return plateau_res, 0, plot_data
|
|
718
|
-
|
|
719
|
-
|
|
720
757
|
# =======================
|
|
721
758
|
# Age Distribution Plot
|
|
722
759
|
# =======================
|