-
Notifications
You must be signed in to change notification settings - Fork 0
/
PyCalcolAr.py
1853 lines (1516 loc) · 61.5 KB
/
PyCalcolAr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
# coding: utf-8
# # PyCalcolAr
# ### Inizializzazione
# Importare le librerie utili per la creazione del codice
import pandas as pd
import numpy as np
import math
import matplotlib.pyplot as plt
from copy import deepcopy
import os
# se ricevi un errore "ModuleNotFoundError", devi istallare il pacchetto https://github.com/Phlya/adjustText:
# se usi Anaconda, apri "Anaconda prompt" dal menu Start e esegui conda install -c conda-forge adjusttext
from adjustText import adjust_text
# ### importing the file sample_name_config.xlsx
# #### (unico parametro da modificare nel codice)
# indicate the path of the sample_name_config.xlsx file
while True:
config_path = input('Enter the path of the config file for the sample or "exit": ')
if config_path == "exit":
break
elif os.path.exists(config_path) is False:
print("The path does not exist")
continue
else:
# In[53]:
# read the sheet "analysis_parameter" from the sample_name_config.xlsx file
df_config_sample_parameters = pd.read_excel(
io=config_path, sheet_name="analysis_parameter"
)
# set the input values from the sample_name_config.xlsx file
# nome del campione
sample_name = df_config_sample_parameters.iat[0, 1]
# definire il percorso del file calibrazione
file_path_36 = df_config_sample_parameters.iat[1, 1]
# definire il percorso dei file dati
file_path_4 = df_config_sample_parameters.iat[2, 1]
file_path_22 = df_config_sample_parameters.iat[3, 1]
file_path_faradaysolo = df_config_sample_parameters.iat[4, 1]
# filtrare il dataframe per numero run
run_start = df_config_sample_parameters.iat[5, 1]
run_end = df_config_sample_parameters.iat[6, 1]
# days passed between the irradiation and the measurement of the sample
delay = df_config_sample_parameters.iat[7, 1]
# sample_weight, (cambia per ogni campione)
sample_weight = df_config_sample_parameters.iat[8, 1]
# J_factor e J_factor_errors, (cambia per ogni campione)
J_factor = df_config_sample_parameters.iat[9, 1]
J_factor_errors = df_config_sample_parameters.iat[10, 1]
# sensitivity, (valore misurato un paio di volte l'anno)
sensitivity = df_config_sample_parameters.iat[11, 1]
# In[11]:
# valori misurati 4/5 di volte l'anno
# update_data = df_config_sample_parameters.iat[12, 1]
background_spectrometer_dict = {
"Background 40Ar": [
df_config_sample_parameters.iat[13, 1],
df_config_sample_parameters.iat[13, 2],
],
"Background 39Ar": [
df_config_sample_parameters.iat[14, 1],
df_config_sample_parameters.iat[14, 2],
],
"Background 38Ar": [
df_config_sample_parameters.iat[15, 1],
df_config_sample_parameters.iat[15, 2],
],
"Background 37Ar": [
df_config_sample_parameters.iat[16, 1],
df_config_sample_parameters.iat[16, 2],
],
"Background 36Ar": [
df_config_sample_parameters.iat[17, 1],
df_config_sample_parameters.iat[17, 2],
],
}
# ### Tabella: IRRADIATIONS CONSTANTS
# #### (NON SONO DA MODIFICARE, valori costanti)
# In[12]:
# read the sheet "irradiation_constants" from the sample_name_config.xlsx file
df_config_irradiation_constants = pd.read_excel(
io=config_path, sheet_name="irradiation_constants"
)
# In[13]:
irradiations_constants_dict = {
"Atmospheric Ratio": [
df_config_irradiation_constants.iat[0, 1],
df_config_irradiation_constants.iat[0, 2],
],
"(36Ar/37Ar) Ca": [
df_config_irradiation_constants.iat[1, 1],
df_config_irradiation_constants.iat[1, 2],
],
"(38Ar/37Ar) Ca": [
df_config_irradiation_constants.iat[2, 1],
df_config_irradiation_constants.iat[2, 2],
],
"(39Ar/37Ar) Ca": [
df_config_irradiation_constants.iat[3, 1],
df_config_irradiation_constants.iat[3, 2],
],
"Lambda Ar37 [1/d]": [
df_config_irradiation_constants.iat[4, 1],
df_config_irradiation_constants.iat[4, 2],
],
"Lambda Ar40 [1/Ma]": [
df_config_irradiation_constants.iat[5, 1],
df_config_irradiation_constants.iat[5, 2],
],
"Interference 40K": [
df_config_irradiation_constants.iat[6, 1],
df_config_irradiation_constants.iat[6, 2],
],
"Coefficient 39Ar for J": [
df_config_irradiation_constants.iat[7, 1],
df_config_irradiation_constants.iat[7, 2],
],
"Coefficient Ca/K": [
df_config_irradiation_constants.iat[8, 1],
df_config_irradiation_constants.iat[8, 2],
],
"Coefficient Cl/K": [
df_config_irradiation_constants.iat[9, 1],
df_config_irradiation_constants.iat[9, 2],
],
}
# ### Importazione files dello spettrometro
# ### > file Triplo36 (file di calibrazione dell'aria)
# In[14]:
# to change the file name of triplo36_..._.txt, see above
# definire la lista con gli indici delle colonne
columns_names = [
"40F",
"err 40F",
"38IC0",
"err 38IC0",
"36IC1",
"err 36IC1",
"36IC0",
"err 36IC0",
"36F",
"err 36F",
"gain IC0/IC1",
"err gain IC0/IC1",
"gain F/IC1",
"err gain F/IC1",
"gain F/IC0",
"err gain F/IC0",
"40F/36IC1",
"err 40F/36IC1 ",
"40F/36F",
"err 40F/36F",
"40F/36IC0",
"err 40F/36IC0",
"38IC0/36IC0",
"err 38IC0/36IC0",
"Run",
"Path",
]
# definire le colonne che contengono dati numerici (ad eccezione delle colonne 'Run' e 'Path')
columns_numeric = [
"40F",
"err 40F",
"38IC0",
"err 38IC0",
"36IC1",
"err 36IC1",
"36IC0",
"err 36IC0",
"36F",
"err 36F",
"gain IC0/IC1",
"err gain IC0/IC1",
"gain F/IC1",
"err gain F/IC1",
"gain F/IC0",
"err gain F/IC0",
"40F/36IC1",
"err 40F/36IC1 ",
"40F/36F",
"err 40F/36F",
"40F/36IC0",
"err 40F/36IC0",
"38IC0/36IC0",
"err 38IC0/36IC0",
]
# importare il file utilizzando caratteri separatori (sep = '\t|,') '\t' = tab, ',' = virgola
airpipette_data = pd.read_csv(
file_path_36, header=None, names=columns_names, sep="\t|,", engine="python"
)
# eliminare i caratteri "{}" dalle colonne relative all'errore
airpipette_data = airpipette_data.replace(["{", "}"], ["", ""], regex=True)
# convertire tutte le colonne del dataframe a numeric (float64)
for i in columns_numeric:
airpipette_data[i] = pd.to_numeric(airpipette_data[i])
# definire un dataframe con le "colonne utili" (foglio airpipette_data)
airpipette_data = airpipette_data[
[
"40F",
"err 40F",
"38IC0",
"err 38IC0",
"36IC1",
"err 36IC1",
"36IC0",
"err 36IC0",
"36F",
"err 36F",
"40F/36F",
"err 40F/36F",
"Run",
"Path",
]
]
# stampare il dataframe 'airpipette_data'
# print("Air pipette initial imported data:")
# dividere la colonna 'Run' in due colonne: nome del run e data/ora
run_split = airpipette_data["Run"].str.split(" run on ")
# formattare la colonna con il nome del run (del campione) in una serie pandas e associarle un nome
run_name = run_split.str[0]
run_name = run_name.replace(["'"], [""], regex=True)
run_name.name = "Run_Name"
# formattare la colonna con il numero del run
run_number = airpipette_data["Path"].str.split(".").str[0]
run_number = run_number.str.split("_").str[-1]
run_number.name = "Run_Number"
run_number = pd.to_numeric(run_number)
# formattare la colonna con la data e l'ora in una serie pandas e associarle un nome, convertire il dato in datetime64
dataora = run_split.str[1]
dataora.name = "Date_Time"
dataora = pd.to_datetime(dataora)
# concatenare le nuove colonne all'inizio del dataframe airpipette_data
airpipette_data = pd.concat(
[run_name, run_number, dataora, airpipette_data], axis=1
)
# eliminare la colonna 'Run' (non più utilizzata)
airpipette_data.drop("Run", axis=1, inplace=True)
# conversione valore da count a V per tutti IC0,IC1 e relativi errori... (n / 62415000)
airpipette_data.loc[:, "38IC0"] = (
airpipette_data.loc[:, "38IC0"].values / 62415000
)
airpipette_data.loc[:, "err 38IC0"] = (
airpipette_data.loc[:, "err 38IC0"].values / 62415000
)
airpipette_data.loc[:, "36IC1"] = (
airpipette_data.loc[:, "36IC1"].values / 62415000
)
airpipette_data.loc[:, "err 36IC1"] = (
airpipette_data.loc[:, "err 36IC1"].values / 62415000
)
airpipette_data.loc[:, "36IC0"] = (
airpipette_data.loc[:, "36IC0"].values / 62415000
)
airpipette_data.loc[:, "err 36IC0"] = (
airpipette_data.loc[:, "err 36IC0"].values / 62415000
)
airpipette_data.loc[:, "36F"] = airpipette_data.loc[:, "36F"].values / 62415000
airpipette_data.loc[:, "err 36F"] = (
airpipette_data.loc[:, "err 36F"].values / 62415000
)
# ### > file Run4 e Run22 (file di misura)
# In[15]:
# to change the file name of run4.txt, run22.txt, faradaysolo.txt see above
# definire la lista con gli indici delle colonne
column_names_run4 = [
"40Ar F",
"err40Ar F",
"38Ar IC0",
"err38Ar IC0",
"36Ar IC1",
"err36Ar IC1",
"38Ar F",
"err38Ar F",
"36Ar IC0",
"err36Ar IC0",
"39Ar F",
"err39Ar F",
"37Ar IC0",
"err37Ar IC0",
"35Cl IC1",
"err35Cl IC1",
"39Ar IC0",
"err39Ar IC0",
"37Ar IC1",
"err37Ar IC1",
"gainF/IC0",
"err gainF/IC0",
"gainIC0/IC1",
"err gainIC0/IC1",
"40F/36IC1",
"err40F/36IC1",
"40F/36IC0",
"err40F/36IC0",
"Run",
"Path",
]
column_names_run22 = [
"40Ar F",
"err40Ar F",
"38Ar IC0",
"err38Ar IC0",
"36Ar IC1",
"err36Ar IC1",
"38Ar F",
"err38Ar F",
"36Ar IC0",
"err36Ar IC0",
"39Ar F",
"err39Ar F",
"37Ar IC0",
"err37Ar IC0",
"35Cl IC1",
"err35Cl IC1",
"gainIC0/IC1",
"err gainIC0/IC1",
"40F/36IC1",
"err40F/36IC1",
"40F/36IC0",
"err40F/36IC0",
"Run",
"Path",
]
column_names_faradaysolo = [
"40Ar F",
"err40Ar F",
"38Ar F",
"err38Ar F",
"36Ar F",
"err36Ar F",
"39Ar F",
"err39Ar F",
"37Ar F",
"err37Ar F",
"Run",
"Path",
]
# definire le colonne che contengono dati numerici
colnames_numeric_4 = [
"40Ar F",
"err40Ar F",
"38Ar IC0",
"err38Ar IC0",
"36Ar IC1",
"err36Ar IC1",
"38Ar F",
"err38Ar F",
"36Ar IC0",
"err36Ar IC0",
"39Ar F",
"err39Ar F",
"37Ar IC0",
"err37Ar IC0",
"35Cl IC1",
"err35Cl IC1",
"39Ar IC0",
"err39Ar IC0",
"37Ar IC1",
"err37Ar IC1",
"gainF/IC0",
"err gainF/IC0",
"gainIC0/IC1",
"err gainIC0/IC1",
"40F/36IC1",
"err40F/36IC1",
"40F/36IC0",
"err40F/36IC0",
]
colnames_numeric_22 = [
"40Ar F",
"err40Ar F",
"38Ar IC0",
"err38Ar IC0",
"36Ar IC1",
"err36Ar IC1",
"38Ar F",
"err38Ar F",
"36Ar IC0",
"err36Ar IC0",
"39Ar F",
"err39Ar F",
"37Ar IC0",
"err37Ar IC0",
"35Cl IC1",
"err35Cl IC1",
"gainIC0/IC1",
"err gainIC0/IC1",
"40F/36IC1",
"err40F/36IC1",
"40F/36IC0",
"err40F/36IC0",
]
colnames_numeric_faradaysolo = column_names_faradaysolo[:-2]
# importare i file run
df_data_4 = pd.read_csv(
file_path_4,
header=None,
index_col=False,
names=column_names_run4,
sep="\t|,",
engine="python",
)
df_data_22 = pd.read_csv(
file_path_22,
header=None,
index_col=False,
names=column_names_run22,
sep="\t|,",
engine="python",
)
df_data_faradaysolo = pd.read_csv(
file_path_faradaysolo,
header=None,
index_col=False,
names=column_names_faradaysolo,
sep="\t|,",
engine="python",
)
# eliminare i caratteri "{}" dalle colonne
df_data_4 = df_data_4.replace(["{", "}"], ["", ""], regex=True)
df_data_22 = df_data_22.replace(["{", "}"], ["", ""], regex=True)
df_data_faradaysolo = df_data_faradaysolo.replace(
["{", "}"], ["", ""], regex=True
)
# convertire tutte le colonne del dataframe df_data_4 a numeric (float64)
for i in colnames_numeric_4:
df_data_4[i] = pd.to_numeric(df_data_4[i])
# convertire tutte le colonne del dataframe df_data_22 a numeric (float64)
for i in colnames_numeric_22:
df_data_22[i] = pd.to_numeric(df_data_22[i])
# convertire tutte le colonne del dataframe df_data_faradaysolo a numeric (float64)
for i in colnames_numeric_faradaysolo:
df_data_faradaysolo[i] = pd.to_numeric(df_data_faradaysolo[i])
df_data = pd.concat([df_data_4, df_data_22, df_data_faradaysolo], axis=0)
# dividere la colonna 'Run' in due colonne: nome del run e data/ora
run_split = df_data["Run"].str.split(" run on ")
# formattare la colonna con il nome del run (del campione) in una serie pandas e associarle un nome
run_name = run_split.str[0]
run_name = run_name.replace(["'"], [""], regex=True)
run_name.name = "Run_Name"
# formattare la colonna con il numero del run
run_number = df_data["Path"].str.split(".").str[0]
run_number = run_number.str.split("_").str[-1]
run_number.name = "Run_Number"
run_number = pd.to_numeric(run_number)
# formattare la colonna con la data e l'ora in una serie pandas e associarle un nome, convertire il dato in datetime64
dataora = run_split.str[1]
dataora.name = "Date_Time"
dataora = pd.to_datetime(dataora)
# concatenare le nuove colonne all'inizio del dataframe df_data
df_data = pd.concat([run_name, run_number, dataora, df_data], axis=1)
# eliminare la colonna 'Run' (non più utilizzata)
df_data.drop("Run", axis=1, inplace=True)
# ### Filtrare i dati per numero run per selezionare un solo campione
# #### Verificare correttezza della selezione nel dataframe visualizzato !
# In[16]:
df_data = df_data.loc[df_data["Run_Number"].between(run_start, run_end)]
df_data.reset_index(drop=True, inplace=True)
df_data.sort_values(
"Date_Time",
axis=0,
ascending=True,
inplace=True,
kind="quicksort",
na_position="last",
)
df_data.reset_index(drop=True, inplace=True)
print("\n > df_data:")
print(df_data)
# In[17]:
# opzione selezione automatica della calibrazione più recente disponibile tra quelle più vecchie della misura
sample_min = min(df_data["Date_Time"].to_list())
older_calibration_df = airpipette_data[
airpipette_data["Date_Time"] < sample_min
]
data_w = max(older_calibration_df["Date_Time"].to_list())
airpipette_data_filtered = airpipette_data[
airpipette_data["Date_Time"] == data_w
]
calibration_data = deepcopy(airpipette_data_filtered)
print("\n\n > calibration_data:")
print(calibration_data)
# In[18]:
# CALCOLO GAIN F/ICO ISOTOPO 39Ar
df_data.loc[:, "F/IC0_39Ar"] = (
df_data["39Ar F"].values / df_data["39Ar IC0"].values
)
# df_data
# ## Crea cartella specifica per ogni campione
# In[19]:
# genera una variabile che registra la data di analisi del campione
date_analysis = df_data.iat[0, 2]
# crea le cartelle dove vengono salvati i file di output
directory_sample = (
"Results/" + date_analysis.strftime("%Y-%m-%d") + " " + sample_name
)
directory_sample_plot = directory_sample + "/" + sample_name + "_plots"
os.makedirs(directory_sample, exist_ok=True)
os.makedirs(directory_sample_plot, exist_ok=True)
# ### Operazioni derivate dal file di calibrazione triplo36 (fogli Excel airpipette_data e sample_data)
# #### Per calcolare 1sig_rel (errore relativo) = err_abs / _Ar (err_abs corrisponde all'errore che misura lo spettrometro)
# #### 1sig_abs = errore assoluto, 1sig_rel = errore relativo
# In[20]:
# calcolare sig_rel 36_IC0
value_err36IC0 = float(calibration_data["err 36IC0"].values)
value_36IC0 = float(calibration_data["36IC0"].values)
sig_rel_36IC0 = float(value_err36IC0 / value_36IC0)
# print ('1sig_rel_36IC0: ', sig_rel_36IC0)
# calcolare sig_rel 36_IC1
value_err36IC1 = float(calibration_data["err 36IC1"].values)
value_36IC1 = float(calibration_data["36IC1"].values)
sig_rel_36IC1 = float(value_err36IC1 / value_36IC1)
# print ('1sig_rel_36IC1: ', sig_rel_36IC1)
# calcolare sig_rel 36_F
value_err36F = float(calibration_data["err 36F"].values)
value_36F = float(calibration_data["36F"].values)
sig_rel_36F = float(value_err36F / value_36F)
# print ('1sig_rel_36F: ', sig_rel_36F)
# calcolare sig_rel 40F/36F
value_err40F_36F = float(calibration_data["err 40F/36F"].values)
value_40F_36F = float(calibration_data["40F/36F"].values)
sig_rel_40F_36F = float(value_err40F_36F / value_40F_36F)
# print ('1sig_rel_40F/36F: ', sig_rel_40F_36F)
# calcolare GAIN_F/IC0
value_36F = float(calibration_data["36F"].values)
value_36IC0 = float(calibration_data["36IC0"].values)
gain_F_IC0 = float(value_36F / value_36IC0)
# print ('gain F/IC0: ', gain_F_IC0)
# calcolare sig_abs GAIN_F/IC0
sig_abs_F_ICO = gain_F_IC0 * (pow(sig_rel_36IC0, 2) + pow(sig_rel_36F, 2)) ** (
1 / 2
)
# print ('sig_abs_F/ICO: ', sig_abs_F_ICO)
# calcolare GAIN_F/IC1
value_36F = float(calibration_data["36F"].values)
value_36IC1 = float(calibration_data["36IC1"].values)
gain_F_IC1 = float(value_36F / value_36IC1)
# print ('gain F/IC1: ', gain_F_IC1)
# calcolare sig_abs GAIN_F/IC1
sig_abs_F_IC1 = gain_F_IC1 * (pow(sig_rel_36IC1, 2) + pow(sig_rel_36F, 2)) ** (
1 / 2
)
# print ('sig_abs_F/IC1: ', sig_abs_F_IC1)
# calcolare 36IC0 correzione gain
corr_gain_36IC0 = value_36IC0 * gain_F_IC0
# print ('corr_gain_36IC0: ', corr_gain_36IC0)
# calcolare 40/36 correzione
value_40F = float(calibration_data["40F"].values)
corr_40_36 = (value_40F) / corr_gain_36IC0
# print ('corr_40_36: ', corr_40_36)
# calcolare sig_abs 40/36 correzione
sig_abs_40_36 = corr_40_36 * (
pow(sig_rel_36F, 2)
+ pow(
calibration_data["err 40F"].values / calibration_data["40F"].values, 2
)
) ** (1 / 2)
# print ('sig_abs_40/36: ', sig_abs_40_36)
# calcolare source frax
source_frax = float(corr_40_36 / 298.56)
# print ('source_frax: ', source_frax)
# calcolare sig_abs source frax
sig_abs_source_frax = source_frax * (sig_abs_40_36 / corr_40_36)
# print ('sig_abs_source_frax: ', sig_abs_source_frax)
# #### Definire tutti i parametri delle tabelle (A) e (B) del file Excel CalcolAr
# ### Tabella: BACKGROUND SPECTROMETER
# In[21]:
# to change the background value measurements, see above
background_spectrometer_df = pd.DataFrame.from_dict(
background_spectrometer_dict, orient="index"
)
background_spectrometer_df.columns = ["value", "relative error"]
# ### Tabella: IRRADIATIONS CONSTANTS
# #### (NON SONO DA MODIFICARE, valori costanti)
# In[22]:
# to change the irradiation constants, see above
irradiations_constants_df = pd.DataFrame.from_dict(
irradiations_constants_dict, orient="index"
)
irradiations_constants_df.columns = ["value", "relative error"]
# ### Tabella: IRRADIATIONS
# In[23]:
# to change sample weight, J factors, and sensitivity, see above
# i seguenti calcoli vengono svolti dal codice
# i gain_F_IC1 sono già stati calcolati precedentemente
measured_40Ar_36Ar_pipettes_sensor36 = "IC1"
measured_40Ar_36Ar_pipettes = (
calibration_data["40F"].values / calibration_data["36IC1"].values
)
gain_rel_uncertainty_errors = sig_rel_40F_36F
gain_rel_uncertainty = gain_rel_uncertainty_errors / gain_F_IC1
# TODO this is just calculating calibration_data[36F] exactly (dividing and multiplying the same numbers)
gain_corrected_40Ar_36Ar_pipettes = measured_40Ar_36Ar_pipettes / gain_F_IC1
gain_corrected_40Ar_36Ar_pipettes_errors = (
gain_corrected_40Ar_36Ar_pipettes
/ irradiations_constants_df.loc["Atmospheric Ratio", "value"]
)
pipette_rel_uncertainty = sig_abs_source_frax
total_fractionation_uncertainty = sig_abs_source_frax
irradiations_dict = {
"Sample weight [g]": [sample_weight, 0],
"J factor": [J_factor, J_factor_errors],
"Sensitivity (mL/mV)": [sensitivity, 0],
"Gain F/IC1": [gain_F_IC1, 0],
"Gain rel uncertainty": [gain_rel_uncertainty, gain_rel_uncertainty_errors],
"Gain corrected 40Ar/36Ar pipettes": [
gain_corrected_40Ar_36Ar_pipettes[0],
gain_corrected_40Ar_36Ar_pipettes_errors[0],
],
"Pipette rel uncertainty": [pipette_rel_uncertainty[0], 0],
"Total fractionation uncertainty": [total_fractionation_uncertainty[0], 0],
}
irradiations_df = pd.DataFrame.from_dict(irradiations_dict, orient="index")
irradiations_df.columns = ["value", "relative error"]
# ### Operazioni foglio Excel CalcolAr = file PyCalcolAr
# #### Le operazione verranno aggiunte in un unico dataframe di risultati simili a quelle del file Excel CalcolAr
# In[24]:
# creare il dataframe input_data
input_data_df = pd.DataFrame()
# colonna Time costante
input_data_df.loc[:, "Time"] = pd.Series(
1 for k in range(0, len(df_data.index))
)
# 6° cella del codice (DA MODIFICARE MANUALMENTE DALL'UTENTE)
input_data_df.loc[:, "Delay"] = pd.Series(
delay for k in range(0, len(df_data.index))
)
# print(input_data_df)
# ### Input = online Regression
# In[25]:
input_data_df.loc[:, "40Ar"] = df_data.loc[:, "40Ar F"].values * 1000
input_data_df.loc[:, "err40Ar"] = df_data.loc[:, "err40Ar F"].values * 1000
count_row = df_data.shape[0]
for i in range(count_row):
if pd.isna(df_data.loc[i, "39Ar IC0"]):
input_data_df.loc[i, "39Ar"] = df_data.loc[i, "39Ar F"] * 1000
input_data_df.loc[i, "err39Ar"] = df_data.loc[i, "err39Ar F"] * 1000
elif (df_data.loc[i, "39Ar F"]) >= 0.003:
input_data_df.loc[i, "39Ar"] = df_data.loc[i, "39Ar F"] * 1000
input_data_df.loc[i, "err39Ar"] = df_data.loc[i, "err39Ar F"] * 1000
else:
input_data_df.loc[i, "39Ar"] = (
df_data.loc[i, "39Ar IC0"] * gain_F_IC0 * 1000
)
input_data_df.loc[i, "err39Ar"] = (
df_data.loc[i, "err39Ar IC0"] * gain_F_IC0 * 1000
)
for i in range(count_row):
if pd.isna(df_data.loc[i, "38Ar IC0"]):
input_data_df.loc[i, "38Ar"] = df_data.loc[i, "38Ar F"] * 1000
input_data_df.loc[i, "err38Ar"] = df_data.loc[i, "err38Ar F"] * 1000
else:
input_data_df.loc[i, "38Ar"] = (
df_data.loc[i, "38Ar IC0"] * gain_F_IC0 * 1000
)
input_data_df.loc[i, "err38Ar"] = (
df_data.loc[i, "err38Ar IC0"] * gain_F_IC0 * 1000
)
for i in range(count_row):
if pd.isna(df_data.loc[i, "37Ar IC0"]):
input_data_df.loc[i, "37Ar"] = df_data.loc[i, "37Ar F"] * 1000
input_data_df.loc[i, "err37Ar"] = df_data.loc[i, "err37Ar F"] * 1000
else:
input_data_df.loc[i, "37Ar"] = (
df_data.loc[i, "37Ar IC0"] * gain_F_IC0 * 1000
)
input_data_df.loc[i, "err37Ar"] = (
df_data.loc[i, "err37Ar IC0"] * gain_F_IC0 * 1000
)
# elif (df_data.loc[i, '37Ar IC1'])<= 0.001:
# input_data_df.loc[i, '37Ar'] = df_data.loc[i, '37Ar IC0'] * gain_F_IC0 * 1000
# input_data_df.loc[i, 'err37Ar'] = df_data.loc[i, 'err37Ar IC0'] * gain_F_IC0 * 1000
# else:
# input_data_df.loc[i, '37Ar'] = df_data.loc[i, '37Ar IC1'] * df_data.loc[i, 'gainIC0/IC1'] * 1000
# input_data_df.loc[i, 'err37Ar'] = df_data.loc[i, 'err37Ar IC1']* df_data.loc[i, 'gainIC0/IC1'] * 1000
# print("wanrning verificare il gain: ", df_data.loc[i, 'gainIC0/IC1'])
# print('i = ', i, ' - 37Ar IC0= ', input_data_df.loc[i, '37Ar IC0'], ' - 37Ar IC1= ', input_data_df.loc[i, '37Ar IC1'], ' - 37Ar = ', input_data_df.loc[i, '37Ar'])
for i in range(count_row):
if pd.isna(df_data.loc[i, "36Ar IC1"]):
input_data_df.loc[i, "36Ar"] = df_data.loc[i, "36Ar F"] * 1000
input_data_df.loc[i, "err36Ar"] = df_data.loc[i, "err36Ar F"] * 1000
else:
input_data_df.loc[i, "36Ar"] = (
df_data.loc[i, "36Ar IC1"] * gain_F_IC1 * 1000
)
input_data_df.loc[i, "err36Ar"] = (
df_data.loc[i, "err36Ar IC1"] * gain_F_IC1 * 1000
)
# ### Measured values corrected for mass spectrometer background
# In[26]:
results_data = input_data_df
results_data.loc[:, "40Ar BC"] = (
results_data.loc[:, "40Ar"].values
- (
results_data.loc[:, "39Ar"].values
* irradiations_constants_df.loc["Interference 40K", "value"]
)
- background_spectrometer_df.loc["Background 40Ar", "value"]
)
results_data.loc[:, "1sigma_abs40"] = (
pow(results_data.loc[:, "err40Ar"].values, 2)
+ pow(
background_spectrometer_df.loc["Background 40Ar", "value"]
* background_spectrometer_df.loc["Background 40Ar", "relative error"],
2,
)
) ** (1 / 2)
results_data.loc[:, "1sigma_rel40"] = (
results_data.loc[:, "1sigma_abs40"].values
/ results_data.loc[:, "40Ar BC"].values
)
results_data.loc[:, "39Ar BC"] = (
results_data.loc[:, "39Ar"].values
- background_spectrometer_df.loc["Background 39Ar", "value"]
)
results_data.loc[:, "1sigma_abs39"] = (
pow(results_data.loc[:, "err39Ar"].values, 2)
+ pow(
background_spectrometer_df.loc["Background 39Ar", "value"]
* background_spectrometer_df.loc["Background 39Ar", "relative error"],
2,
)
) ** (1 / 2)
results_data.loc[:, "1sigma_rel39"] = (
results_data.loc[:, "1sigma_abs39"].values
/ results_data.loc[:, "39Ar BC"].values
)
results_data.loc[:, "38Ar BC"] = (
results_data.loc[:, "38Ar"].values
- background_spectrometer_df.loc["Background 38Ar", "value"]
)
results_data.loc[:, "1sigma_abs38"] = (
pow(results_data.loc[:, "err38Ar"].values, 2)
+ pow(
background_spectrometer_df.loc["Background 38Ar", "value"]
* background_spectrometer_df.loc["Background 38Ar", "relative error"],
2,
)
) ** (1 / 2)
results_data.loc[:, "1sigma_rel38"] = (
results_data.loc[:, "1sigma_abs38"].values
/ results_data.loc[:, "38Ar BC"].values
)
results_data.loc[:, "37Ar BC"] = (
results_data.loc[:, "37Ar"].values
- background_spectrometer_df.loc["Background 37Ar", "value"]
)
results_data.loc[:, "1sigma_abs37"] = (
pow(results_data.loc[:, "err37Ar"].values, 2)
+ pow(
background_spectrometer_df.loc["Background 37Ar", "value"]
* background_spectrometer_df.loc["Background 37Ar", "relative error"],
2,
)
) ** (1 / 2)
results_data.loc[:, "1sigma_rel37"] = (
results_data.loc[:, "1sigma_abs37"].values
/ results_data.loc[:, "37Ar BC"].values
)
results_data.loc[:, "36Ar BC"] = (
results_data.loc[:, "36Ar"].values
- background_spectrometer_df.loc["Background 36Ar", "value"]
)
results_data.loc[:, "1sigma_abs36"] = (
pow(results_data.loc[:, "err36Ar"].values, 2)
+ pow(
background_spectrometer_df.loc["Background 36Ar", "value"]
* background_spectrometer_df.loc["Background 36Ar", "relative error"],
2,
)
) ** (1 / 2)
results_data.loc[:, "1sigma_rel36"] = (
results_data.loc[:, "1sigma_abs36"].values
/ results_data.loc[:, "36Ar BC"].values
)
# 37Ar decay
results_data.loc[:, "Decay Factor"] = (
irradiations_constants_df.loc["Lambda Ar37 [1/d]", "value"]
* results_data.loc[0, "Time"]
* math.exp(
irradiations_constants_df.loc["Lambda Ar37 [1/d]", "value"]
* results_data.loc[0, "Delay"]
)
) / (
1
- math.exp(
(-1) * irradiations_constants_df.loc["Lambda Ar37 [1/d]", "value"] * 1
)
)
# Multiplier for Fract Corr: si moltiplichi l'isotopo leggero per il fattore
results_data.loc[:, "Mult 4amu"] = irradiations_df.loc[
"Gain corrected 40Ar/36Ar pipettes", "relative error"
]
results_data.loc[:, "Mult 2amu"] = (
results_data.loc[:, "Mult 4amu"].values + 1
) / 2
results_data.loc[:, "Mult 1amu"] = (
results_data.loc[:, "Mult 4amu"].values + 3
) / 4
# Bg + Fract + Decay Corrected
results_data.loc[:, "Ar36tot"] = (
results_data.loc[:, "36Ar BC"].values
* results_data.loc[:, "Mult 4amu"].values
)
results_data.loc[:, "1sigRel36tot"] = (
pow(results_data.loc[:, "1sigma_rel36"].values, 2)
+ pow(irradiations_df.loc["Total fractionation uncertainty", "value"], 2)
) ** (1 / 2)
results_data.loc[:, "Ar38tot"] = (
results_data.loc[:, "38Ar BC"].values
* results_data.loc[:, "Mult 2amu"].values
)
results_data.loc[:, "1sigRel38tot"] = (
pow(results_data.loc[:, "1sigma_rel38"].values, 2)
+ 0.25
* pow(irradiations_df.loc["Total fractionation uncertainty", "value"], 2)
) ** (1 / 2)
results_data.loc[:, "Ar39tot"] = (
results_data.loc[:, "39Ar BC"].values
* results_data.loc[:, "Mult 1amu"].values
)
results_data.loc[:, "1sigRel39tot"] = (
pow(results_data.loc[:, "1sigma_rel39"].values, 2)
+ 0.0625
* pow(irradiations_df.loc["Total fractionation uncertainty", "value"], 2)
) ** (1 / 2)
results_data.loc[:, "Ar37day0"] = (
results_data.loc[:, "Decay Factor"].values
* results_data.loc[:, "37Ar BC"].values
* (
results_data.loc[:, "Mult 4amu"].values
* results_data.loc[:, "Mult 2amu"]
)
)
results_data.loc[:, "1sigRel37corr"] = (
pow(results_data.loc[:, "1sigma_rel37"].values, 2)
+ pow(irradiations_df.loc["Total fractionation uncertainty", "value"], 2)
* 9
/ 16
) ** (1 / 2)
# Interference Corrected
results_data.loc[:, "Ar39Ca"] = results_data.loc[:, "Ar37day0"].values * (
irradiations_constants_df.loc["(39Ar/37Ar) Ca", "value"]