-
Notifications
You must be signed in to change notification settings - Fork 4
/
magmatrace_current.py
2336 lines (1964 loc) · 78.8 KB
/
magmatrace_current.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 python3
# -*- coding: utf-8 -*-
"""
Created on Tue Nov 17 23:02:42 2020
@author: jordanlubbers / chucklewis
"""
"""magmatrace is a python module for doing high temperature geochemistry calculations
"""
# import the dependencies we'll need in these functions:
import numpy as np
import pandas as pd
import warnings
import re
#%% Mixing model related functions
def mixing(c1, c2, f):
"""
mixing creates a mixing model between two endmembers
Inputs:
c1 = concentration of endmember 1
c2 = concentration of endmember 2
f = fraction of endmember 1 in the model
Returns:
cm = concnetration of the mixture
"""
cm = c1 * f + c2 * (1 - f)
return cm
# isotopic mixing model.
# fix this to add in a conditional to choose either one or two ratios
def isomix(rationum, c1, r1, c2, r2, *data):
"""
isomix uses equations 18.24-18.26 from Faure 1998 to calculate isotopic mixing
compositions for a given isotopic pair
Inputs:
rationum: use the input 'oneratio' or 'tworatios' to define how many isotopic
systems you are interested in
c1 = concentration of element for endmember 1
c2 = concentration of element for endmember 2
r1 = isotopic ratio for endmember 1
r2 = isotopic ratio for endmember 2
*data = repeat the first 4 inputs for the second isotopic system of interest
Returns:
cm = concentrations of mixture for various values of 'f' where
f is the fraction of endmember 1 in the mixture
rm = isotopic ratios of mixture for various values of 'f'
"""
# array of fractions of component 1
f = np.linspace(0, 1, 11)
# concentration of the mixture
# eq. 18.19
if rationum == "oneratio":
cm = c1 * f + c2 * (1 - f)
# eq. 18.25
a = (c1 * c2 * (r2 - r1)) / (c1 - c2)
# eq. 18.26
b = (c1 * r1 - c2 * r2) / (c1 - c2)
# eq. 18.24
rm = a / cm + b
return cm, rm
elif rationum == "tworatios":
cm = c1 * f + c2 * (1 - f)
# eq. 18.25
a = (c1 * c2 * (r2 - r1)) / (c1 - c2)
# eq. 18.26
b = (c1 * r1 - c2 * r2) / (c1 - c2)
# eq. 18.24
rm = a / cm + b
cm2 = data[0] * f + data[2] * (1 - f)
# eq 18.25
c = (data[0] * data[2] * (data[3] - data[1])) / (data[0] - data[2])
# eq 18.26
d = (data[0] * data[1] - data[2] * data[3]) / (data[0] - data[2])
rm2 = c / cm2 + d
return cm, rm, cm2, rm2
else:
print(
"Check your input. Ensure to specify rattionum and the correct amount of concentrations or ratios"
)
def ratio_mixing(df, n_components, resolution=0.1):
"""
Mixing of ratios as described by Albarede 1995
Introduction to Geochemical Modeling equation 1.3.1
Inputs:
df | pandas DataFrame
DataFrame of inputs. should be formatted as follows:
For 2 component mixing:
Index|Element1_c|Element1_r|Element2_c|Element2_r
-------------------------------------------------
A | | | |
-------------------------------------------------
B | | | |
For 3 component mixing:
Index|Element1_c|Element1_r|Element2_c|Element2_r
-------------------------------------------------
A | | | |
-------------------------------------------------
B | | | |
-------------------------------------------------
C | | | |
Where the name of each component is the index of the dataframe and the
concentration and ratio columns for each elemental species contain "_c" and "_r"
somewhere in the column header, respectively.
n_components | int
Number of end-member components (either 2 or 3)
resolution | float
The resolution you want to run your mixing model at. This is a number between 0.01
and 0.5. This is how far apart to space points in the eventual mixing mesh
(e.g. .1 will return a mixing mesh spaced by 1O% increments for each component)
Default is 0.1
Returns:
results | pandas DataFrame
The results of the mixing model that is n x 7 in shape:
f_A|f_B|f_C|Element1_c_mix|Element2_c_mix|Element1_r_mix|Element2_r_mix
-----------------------------------------------------------------------
Where f columns are fraction of each component in the mixture and other columns
Are for the concentrations and ratios of the mixture for each respective combination
of f values
"""
if n_components == 2:
if resolution < 0.01:
print(
"Please pick a lower resolution (e.g., bigger number).\nYou don't need it and it your computer may explode"
)
if resolution > 0.5:
print("Please pick a higher resolution (e.g., number < 0.5). \n")
else:
# generate an array for fraction of each component
f = np.arange(0, 1 + resolution, resolution)
# all possible combinations for three f arrays
a = np.array(np.meshgrid(f, f)).T.reshape(-1, 2)
# where the combinations sum to 1
f_vals = a[a.sum(axis=1) == 1]
# get names of components
components = df.index.tolist()
# get names of columns where concentrations and ratios are held
# IMPORTANT TO HAVE DATAFRAME IN THIS FORMAT
elements = [col for col in df.columns if "_c" in col]
ratios = [col for col in df.columns if "_r" in col]
# Concentration of mixture
if len(elements) == 1:
el1_mix_concentrations = (
df.loc[components[0], elements[0]] * f_vals[:, 0]
+ df.loc[components[1], elements[0]] * f_vals[:, 1]
)
# ratio values of the mixture using Albarede 1995 eq. 1.3.1
el1_mix_ratios = df.loc[components[0], ratios[0]] * (
(f_vals[:, 0] * df.loc[components[0], elements[0]])
/ el1_mix_concentrations
) + df.loc[components[1], ratios[0]] * (
(f_vals[:, 1] * df.loc[components[1], elements[0]])
/ el1_mix_concentrations
)
results = pd.DataFrame(
{
"f_{}".format(components[0]): f_vals[:, 0],
"f_{}".format(components[1]): f_vals[:, 1],
"{}_mix".format(elements[0]): el1_mix_concentrations,
"{}_mix".format(ratios[0]): el1_mix_ratios,
}
)
else:
el1_mix_concentrations = (
df.loc[components[0], elements[0]] * f_vals[:, 0]
+ df.loc[components[1], elements[0]] * f_vals[:, 1]
)
el2_mix_concentrations = (
df.loc[components[0], elements[1]] * f_vals[:, 0]
+ df.loc[components[1], elements[1]] * f_vals[:, 1]
)
# ratio values of the mixture using Albarede 1995 eq. 1.3.1
el1_mix_ratios = df.loc[components[0], ratios[0]] * (
(f_vals[:, 0] * df.loc[components[0], elements[0]])
/ el1_mix_concentrations
) + df.loc[components[1], ratios[0]] * (
(f_vals[:, 1] * df.loc[components[1], elements[0]])
/ el1_mix_concentrations
)
el2_mix_ratios = df.loc[components[0], ratios[1]] * (
(f_vals[:, 0] * df.loc[components[0], elements[1]])
/ el2_mix_concentrations
) + df.loc[components[1], ratios[1]] * (
(f_vals[:, 1] * df.loc[components[1], elements[1]])
/ el2_mix_concentrations
)
results = pd.DataFrame(
{
"f_{}".format(components[0]): f_vals[:, 0],
"f_{}".format(components[1]): f_vals[:, 1],
"{}_mix".format(elements[0]): el1_mix_concentrations,
"{}_mix".format(elements[1]): el2_mix_concentrations,
"{}_mix".format(ratios[0]): el1_mix_ratios,
"{}_mix".format(ratios[1]): el2_mix_ratios,
}
)
if n_components == 3:
if resolution < 0.01:
print(
"Please pick a lower resolution (e.g., bigger number).\nYou don't need it and it your computer may explode"
)
if resolution > 0.5:
print("Please pick a higher resolution (e.g., number < 0.5). \n")
else:
# generate an array for fraction of each component
f = np.arange(0, 1 + resolution, resolution)
# all possible combinations for three f arrays
a = np.array(np.meshgrid(f, f, f)).T.reshape(-1, 3)
# where the combinations sum to 1
f_vals = a[a.sum(axis=1) == 1]
# get names of components
components = df.index.tolist()
# get names of columns where concentrations and ratios are held
# IMPORTANT TO HAVE DATAFRAME IN THIS FORMAT
elements = [col for col in df.columns if "_c" in col]
ratios = [col for col in df.columns if "_r" in col]
if len(elements) == 1:
# Concentration of mixture using basic 3 component mixing
# of concentrations
el1_mix_concentrations = (
df.loc[components[0], elements[0]] * f_vals[:, 0]
+ df.loc[components[1], elements[0]] * f_vals[:, 1]
+ df.loc[components[2], elements[0]] * f_vals[:, 2]
)
# ratio values of the mixture using Albarede 1995 eq. 1.3.1
el1_mix_ratios = (
df.loc[components[0], ratios[0]]
* (
(f_vals[:, 0] * df.loc[components[0], elements[0]])
/ el1_mix_concentrations
)
+ df.loc[components[1], ratios[0]]
* (
(f_vals[:, 1] * df.loc[components[1], elements[0]])
/ el1_mix_concentrations
)
+ df.loc[components[2], ratios[0]]
* (
(f_vals[:, 2] * df.loc[components[2], elements[0]])
/ el1_mix_concentrations
)
)
results = pd.DataFrame(
{
"f_{}".format(components[0]): f_vals[:, 0],
"f_{}".format(components[1]): f_vals[:, 1],
"f_{}".format(components[2]): f_vals[:, 2],
"{}_mix".format(elements[0]): el1_mix_concentrations,
"{}_mix".format(ratios[0]): el1_mix_ratios,
}
)
else:
# Concentration of mixture using basic 3 component mixing
# of concentrations
el1_mix_concentrations = (
df.loc[components[0], elements[0]] * f_vals[:, 0]
+ df.loc[components[1], elements[0]] * f_vals[:, 1]
+ df.loc[components[2], elements[0]] * f_vals[:, 2]
)
el2_mix_concentrations = (
df.loc[components[0], elements[1]] * f_vals[:, 0]
+ df.loc[components[1], elements[1]] * f_vals[:, 1]
+ df.loc[components[2], elements[1]] * f_vals[:, 2]
)
# ratio values of the mixture using Albarede 1995 eq. 1.3.1
el1_mix_ratios = (
df.loc[components[0], ratios[0]]
* (
(f_vals[:, 0] * df.loc[components[0], elements[0]])
/ el1_mix_concentrations
)
+ df.loc[components[1], ratios[0]]
* (
(f_vals[:, 1] * df.loc[components[1], elements[0]])
/ el1_mix_concentrations
)
+ df.loc[components[2], ratios[0]]
* (
(f_vals[:, 2] * df.loc[components[2], elements[0]])
/ el1_mix_concentrations
)
)
el2_mix_ratios = (
df.loc[components[0], ratios[1]]
* (
(f_vals[:, 0] * df.loc[components[0], elements[1]])
/ el2_mix_concentrations
)
+ df.loc[components[1], ratios[1]]
* (
(f_vals[:, 1] * df.loc[components[1], elements[1]])
/ el2_mix_concentrations
)
+ df.loc[components[2], ratios[1]]
* (
(f_vals[:, 2] * df.loc[components[2], elements[1]])
/ el2_mix_concentrations
)
)
results = pd.DataFrame(
{
"f_{}".format(components[0]): f_vals[:, 0],
"f_{}".format(components[1]): f_vals[:, 1],
"f_{}".format(components[2]): f_vals[:, 2],
"{}_mix".format(elements[0]): el1_mix_concentrations,
"{}_mix".format(elements[1]): el2_mix_concentrations,
"{}_mix".format(ratios[0]): el1_mix_ratios,
"{}_mix".format(ratios[1]): el2_mix_ratios,
}
)
return results
def isoassim(modeltype, rationum, r, D, cp, ca, ep, ea, *data):
"""
isoassim uses equation 15B from DePaolo (1981) in order to look at
the evolution of one or two isotopic ratios and their associated trace element
concentrations during combined assimilation and fractionation
Inputs:
modeltype == DePaolo15b; this is the only one currently and is by far the most useful
rationum = the number of isotopic systems you are interested in. List 'oneratio' or 'tworatios'
r = the r value, defined as the rate of fractionation to the rate of assimilation by mass
D = the bulk D value for the first isotopic system
cp = concentration of trace element in parental magma
ca = concentration of trace element in assimilant
ep = isotopic ratio of parental magma
ea = isotopic ratio of assimilant
*data = if you are interested in two ratios as opposed to one then you must input new values
for D through ea for the second isotopic system
"""
# array of fractions of component 1
f = np.linspace(0, 1, 11)
if modeltype == "DePaolo15b" and rationum == "oneratio":
# mix the trace elements
cm = cp * f + ca * (1 - f)
# get the effective distribution coefficient
z = (r + D - 1) / (r - 1)
# calculate the isotopic ratio of the daughter that has undergone assimilation
em = ((r / (r - 1)) * (ca / z) * (1 - f ** (-z)) * ea + cp * f ** (-z) * ep) / (
(r / (r - 1)) * (ca / z) * (1 - f ** (-z)) + (cp * f ** (-z))
)
return cm, em
elif modeltype == "DePaolo15b" and rationum == "tworatios":
# get mixes of both trace elements associated with the isotopic systems of interest
cm = cp * f + ca * (1 - f)
cm2 = data[1] * f + data[2] * (1 - f)
# get the effective distribution coefficents for both isotopic systems
z1 = (r + D - 1) / (r - 1)
z2 = (r + data[0] - 1) / (r - 1)
# calculate the isotopic ratios of the daughter for both systems
em = ((r / (r - 1)) * (ca / z) * (1 - f ** (-z)) * ea + cp * f ** (-z) * ep) / (
(r / (r - 1)) * (ca / z) * (1 - f ** (-z)) + (cp * f ** (-z))
)
em2 = (
(r / (r - 1)) * (data[2] / z2) * (1 - f ** (-z2)) * data[4]
+ data[1] * f ** (-z2) * data[3]
) / ((r / (r - 1)) * (data[2] / z1) * (1 - f ** (-z1)) + (data[1] * f ** (-z1)))
return cm, cm2, em, em2
else:
print(
"You must specify the modeltype as DePaolo15b, number of ratios as one or two, r, D, and/or D2, then your ratios"
)
# Equations by Aitcheson & Forrest (1994) used to estimate the degree of assimilation independent of
# Depaolo's (1981) variable r
# equations based on isotopic compositions
def crustfraciso(eq, systems, D, c0m, e0m, em, ea, *data):
"""
This model will give either equation 5 or 7 of the Aitcheson & Forrest (1994) equations that are used for estimating
the fraction of assimilated crust without the requirement of guessing at the r value required for the DePaolo (1981)
equations. The user should be familiar about what needs to be input - in short, this is estimated basement compositions
as the assimilant, measured compositions for the 'daughter', and a thoroughly educated guess at intital magma
composition. An example of this applicability can be seen in Kay et al. (2010).
Inputs:
eq: 'five' for equation five and 'seven' for equation 'seven'.
Equation five is independent of erupted magma composition and degree of melting F
Equation seven is independent of the trace element composition in the assimilant
systems: Up to four isotopic systems can be considered. These are designated by the input 'one', 'two', 'threee', or
'four'. There is a caveat to putting in more than one isotopic system explained by teh input parameter *data
seen below
D: The bulk partition coefficient of the element associated with the isotopic system of interest in the host magma
c0m: Estimated trace element composition of the element associated with the isotopic system of interest in the
original parent magma.
e0m: Estimated isotopic ratio for the system of interest in the original parent magma.
em: Measured isotpic ratio of hte daughter magma that has undergone assimilation.
ea: Estimated isotopic ratio of the assimilant.
*data: If you wish to do more than one isotpic system, you must input values for D thorugh ea in exactly the same
order as defined in the function above
Outputs:
crustfrac 1, 2, 3, or 4 depending on how many isotpic systems you are interested in. This is equivalent to the
value 'rho' in Aitcheson & Forrest (1994)
"""
import numpy as np
r = np.linspace(0, 1, 11)
if eq == "five" and systems == "one":
wave = (e0m - em) / (em - ea)
ca = data[0]
gamma = ca / c0m
crustfrac = (r / (r - 1)) * (
(1 + ((wave * (r + D - 1)) / (r * gamma))) ** ((r - 1) / (r + D - 1)) - 1
)
return crustfrac
elif eq == "five" and systems == "two":
wave1 = (e0m - em) / (em - ea)
ca1 = data[0]
gamma1 = ca / c0m
crustfrac1 = (r / (r - 1)) * (
(1 + ((wave1 * (r + D - 1)) / (r * gamma1))) ** ((r - 1) / (r + D - 1)) - 1
)
wave2 = (data[3] - data[4]) / (data[4] - data[5])
ca2 = data[6]
gamma2 = ca2 / data[2]
crustfrac2 = (r / (r - 1)) * (
(1 + ((wave2 * (r + data[1] - 1)) / (r * gamma2)))
** ((r - 1) / (r + data[1] - 1))
- 1
)
return crustfrac1, crustfrac2
elif eq == "five" and systems == "three":
wave1 = (e0m - em) / (em - ea)
ca1 = data[0]
gamma1 = ca / c0m
crustfrac1 = (r / (r - 1)) * (
(1 + ((wave1 * (r + D - 1)) / (r * gamma1))) ** ((r - 1) / (r + D - 1)) - 1
)
wave2 = (data[3] - data[4]) / (data[4] - data[5])
ca2 = data[6]
gamma2 = ca2 / data[2]
crustfrac2 = (r / (r - 1)) * (
(1 + ((wave2 * (r + data[1] - 1)) / (r * gamma2)))
** ((r - 1) / (r + data[1] - 1))
- 1
)
wave3 = (data[9] - data[10]) / (data[10] - data[11])
ca3 = data[12]
gamma3 = ca3 / data[8]
crustfrac3 = (r / (r - 1)) * (
(1 + ((wave3 * (r + data[7] - 1)) / (r * gamma3)))
** ((r - 1) / (r + data[7] - 1))
- 1
)
return crustfrac1, crustfrac2, crustfrac3
elif eq == "five" and systems == "four":
wave1 = (e0m - em) / (em - ea)
ca1 = data[0]
gamma1 = ca / c0m
crustfrac1 = (r / (r - 1)) * (
(1 + ((wave1 * (r + D - 1)) / (r * gamma1))) ** ((r - 1) / (r + D - 1)) - 1
)
wave2 = (data[3] - data[4]) / (data[4] - data[5])
ca2 = data[6]
gamma2 = ca2 / data[2]
crustfrac2 = (r / (r - 1)) * (
(1 + ((wave2 * (r + data[1] - 1)) / (r * gamma2)))
** ((r - 1) / (r + data[1] - 1))
- 1
)
wave3 = (data[9] - data[10]) / (data[10] - data[11])
ca3 = data[12]
gamma3 = ca3 / data[8]
crustfrac3 = (r / (r - 1)) * (
(1 + ((wave3 * (r + data[7] - 1)) / (r * gamma3)))
** ((r - 1) / (r + data[7] - 1))
- 1
)
wave4 = (data[15] - data[16]) / (data[16] - data[17])
ca4 = data[18]
gamma4 = ca4 / data[14]
crustfrac4 = (r / (r - 1)) * (
(1 + ((wave4 * (r + data[13] - 1)) / (r * gamma4)))
** ((r - 1) / (r + data[13] - 1))
- 1
)
return crustfrac1, crustfrac2, crustfrac3, crustfrac4
elif eq == "seven" and systems == "one":
cm = data[0]
crustfrac = (r / (r - 1)) * (
((c0m / cm) * ((ea - e0m) / (ea - em))) ** ((r - 1) / (r + D - 1)) - 1
)
return crustfrac
elif eq == "seven" and systems == "two":
cm1 = data[0]
crustfrac1 = (r / (r - 1)) * (
((c0m / cm1) * ((ea - e0m) / (ea - em))) ** ((r - 1) / (r + D - 1)) - 1
)
cm2 = data[6]
crustfrac2 = (r / (r - 1)) * (
((data[2] / cm1) * ((data[5] - data[3]) / (data[5] - data[4])))
** ((r - 1) / (r + data[1] - 1))
- 1
)
return crustfrac1, crustfrac2
elif eq == "seven" and systems == "three":
cm1 = data[0]
crustfrac1 = (r / (r - 1)) * (
((c0m / cm1) * ((ea - e0m) / (ea - em))) ** ((r - 1) / (r + D - 1)) - 1
)
cm2 = data[6]
crustfrac2 = (r / (r - 1)) * (
((data[2] / cm2) * ((data[5] - data[3]) / (data[5] - data[4])))
** ((r - 1) / (r + data[1] - 1))
- 1
)
cm3 = data[12]
crustfrac3 = (r / (r - 1)) * (
((data[8] / cm3) * ((data[11] - data[9]) / (data[11] - data[10])))
** ((r - 1) / (r + data[7] - 1))
- 1
)
cm4 = data[18]
crustfrac4 = (r / (r - 1)) * (
((data[14] / cm4) * ((data[17] - data[15]) / (data[17] - data[16])))
** ((r - 1) / (r + data[13] - 1))
- 1
)
return crustfrac1, crustfrac2, crustfrac3, crustfrac4
else:
print("Check your input")
# equations independent of the isotopic composition
def crustfracele(systems, D, c0m, cm, ca, *data):
"""
This model will give either equation 6of the Aitcheson & Forrest (1994) equations that are used for estimating
the fraction of assimilated crust without the requirement of guessing at the r value required for the DePaolo (1981)
equations. The user should be familiar about what needs to be input - in short, this is estimated basement compositions
as the assimilant, measured compositions for the 'daughter', and a thoroughly educated guess at intital magma
composition. An example of this applicability can be seen in Kay et al. (2010). This particular equation uses trace
elements only and is independent of isotopic ratios. This equation is best used in combination with the function
crustfraciso.
Inputs:
systems: Up to four systems can be considered. These are designated by the input 'one', 'two', 'threee', or
'four'. There is a caveat to putting in more than one isotopic system explained by teh input parameter *data
seen below
D: The bulk partition coefficient of the element associated with the isotopic system of interest in the host magma
c0m: Estimated trace element composition of the element associated with the isotopic system of interest in the
original parent magma.
cm: Measured trace element composition of the 'daughter' magma that has undergone assimilation
ca: Estimated trace element composition of the assimilant
*data: If you wish to do more than one isotpic system, you must input values for D thorugh ea in exactly the same
order as defined in the function above
Outputs:
crustfrac 1, 2, 3, or 4 depending on how many systems you are interested in. This is equivalent to the
value 'rho' in Aitcheson & Forrest (1994)
"""
import numpy as np
r = np.linspace(0, 1, 11)
if systems == "one":
crustfrac = (r / (r - 1)) * (
((c0m * (r + D - 1) - r * ca) / (cm * (r + D - 1) - r * ca))
** ((r - 1) / (r + D - 1))
- 1
)
return (crustfrac,)
elif systems == "two":
crustfrac1 = (r / (r - 1)) * (
((c0m * (r + D - 1) - r * ca) / (cm * (r + D - 1) - r * ca))
** ((r - 1) / (r + D - 1))
- 1
)
crustfrac2 = (r / (r - 1)) * (
(
(data[1] * (r + data[0] - 1) - r * data[3])
/ (data[2] * (r + data[0] - 1) - r * data[3])
)
** ((r - 1) / (r + data[0] - 1))
- 1
)
return crustfrac1, crustfrac2
elif systems == "three":
crustfrac1 = (r / (r - 1)) * (
((c0m * (r + D - 1) - r * ca) / (cm * (r + D - 1) - r * ca))
** ((r - 1) / (r + D - 1))
- 1
)
crustfrac2 = (r / (r - 1)) * (
(
(data[1] * (r + data[0] - 1) - r * data[3])
/ (data[2] * (r + data[0] - 1) - r * data[3])
)
** ((r - 1) / (r + data[0] - 1))
- 1
)
crustfrac3 = (r / (r - 1)) * (
(
(data[5] * (r + data[4] - 1) - r * data[7])
/ (data[6] * (r + data[4] - 1) - r * data[7])
)
** ((r - 1) / (r + data[4] - 1))
- 1
)
return crustfrac1, crustfrac2, crustfrac3
elif systems == "four":
crustfrac1 = (r / (r - 1)) * (
((c0m * (r + D - 1) - r * ca) / (cm * (r + D - 1) - r * ca))
** ((r - 1) / (r + D - 1))
- 1
)
crustfrac2 = (r / (r - 1)) * (
(
(data[1] * (r + data[0] - 1) - r * data[3])
/ (data[2] * (r + data[0] - 1) - r * data[3])
)
** ((r - 1) / (r + data[0] - 1))
- 1
)
crustfrac3 = (r / (r - 1)) * (
(
(data[5] * (r + data[4] - 1) - r * data[7])
/ (data[6] * (r + data[4] - 1) - r * data[7])
)
** ((r - 1) / (r + data[4] - 1))
- 1
)
crustfrac4 = (r / (r - 1)) * (
(
(data[9] * (r + data[8] - 1) - r * data[11])
/ (data[10] * (r + data[8] - 1) - r * data[11])
)
** ((r - 1) / (r + data[8] - 1))
- 1
)
return crustfrac1, crustfrac2, crustfrac3, crustfrac3
else:
print("Check your input")
#%% Thermometry related functions
def plag_kd_calc(element, An, temp, method):
"""
calculates the partition coefficient for a given element in plagioclase based on its anorthite
content according to the Arrhenius relationship as originally defined by Blundy and Wood (1991)
This function gives the user an option of three experimental papers to choose from when calculating
partition coefficient:
Bindeman et al., 1998 = ['Li','Be','B','F','Na','Mg','Al','Si','P','Cl','K','Ca','Sc',
'Ti','Cr','Fe','Co','Rb','Sr','Zr','Ba','Y','La','Ce','Pr','Nd','Sm','Eu','Pb']
Nielsen et al., 2017 = ['Mg','Ti','Sr','Y','Zr','Ba','La','Ce','Pr','Nd','Pb']
Tepley et al., 2010 = ['Sr','Rb','Ba','Pb','La','Nd','Sm','Zr','Th','Ti']
Inputs:
-------
element : string
The element you are trying to calculate the partition coefficient for. See Bindeman 1998 for supported
elements
An : array-like
Anorthite content (between 0 and 1) of the plagioclase. This can be a scalar value or Numpy array
temp: scalar
Temperature in Kelvin to calculate the partition coefficient at
method : string
choice of 'Bindeman', 'Nielsen', 'Tepley'. This uses then uses the Arrhenius parameters from
Bindeman et al., 1998, Nielsen et al., 2017, or Tepley et al., 2010, respectively.
Returns:
--------
kd_mean : array-like
the mean partition coefficient for the inputs listed
kd_std : array-like
standard deviation of the partition coefficient calculated via
Monte Carlo simulation of 1000 normally distributed random A and B
parameters based on their mean and uncertainties
"""
if method == "Bindeman":
# Table 4 from Bindeman et al 1998
elements = [
"Li",
"Be",
"B",
"F",
"Na",
"Mg",
"Al",
"Si",
"P",
"Cl",
"K",
"Ca",
"Sc",
"Ti",
"Cr",
"Fe",
"Co",
"Rb",
"Sr",
"Zr",
"Ba",
"Y",
"La",
"Ce",
"Pr",
"Nd",
"Sm",
"Eu",
"Pb",
]
a = (
np.array(
[
-6.9,
28.2,
-0.61,
-37.8,
-9.4,
-26.1,
-0.3,
-2,
-30.7,
-24.5,
-25.5,
-15.2,
-94.2,
-28.9,
-44,
-35.2,
-59.9,
-40,
-30.4,
-90.4,
-55,
-48.1,
-10.8,
-17.5,
-22.5,
-19.9,
-25.7,
-15.1,
-60.5,
]
)
* 1e3
)
a_unc = (
np.array(
[
1.9,
6.1,
0.5,
11.5,
1,
1.1,
0.8,
0.2,
4.6,
9.5,
1.2,
0.6,
28.3,
1.5,
6.3,
1.9,
10.8,
6.7,
1.1,
5.5,
2.4,
3.7,
2.6,
2.3,
4.1,
3.6,
6.3,
16.1,
11.8,
]
)
* 1e3
)
b = (
np.array(
[
-12.1,
-29.5,
9.9,
23.6,
2.1,
-25.7,
5.7,
-0.04,
-12.1,
11,
-10.2,
17.9,
37.4,
-15.4,
-9.3,
4.5,
12.2,
-15.1,
28.5,
-15.3,
19.1,
-3.4,
-12.4,
-12.4,
-9.3,
-9.4,
-7.7,
-14.2,
25.3,
]
)
* 1e3
)
b_unc = (
np.array(
[
1,
4.1,
3.8,
7.1,
0.5,
0.7,
0.4,
0.08,
2.9,
5.3,
0.7,
0.3,
18.4,
1,
4.1,
1.1,
7,
3.8,
0.7,
3.6,
1.3,
1.9,
1.8,
1.4,
2.7,
2.0,
3.9,
11.3,
7.8,
]
)
* 1e3
)
plag_kd_params = pd.DataFrame(
[a, a_unc, b, b_unc], columns=elements, index=["a", "a_unc", "b", "b_unc"]
)
R = 8.314
elif method == "Nielsen":
elements = ["Mg", "Ti", "Sr", "Y", "Zr", "Ba", "La", "Ce", "Pr", "Nd", "Pb"]
a = (
np.array([-10, -32.5, -25, -65.7, -25, -35.1, -32, -33.6, -29, -31, -50])
* 1e3
)
a_unc = np.array([3.3, 1.5, 1.1, 3.7, 5.5, 4.5, 2.9, 2.3, 4.1, 3.6, 11.8]) * 1e3
b = np.array([-35, -15.1, 25.5, 2.2, -50, 10, -5, -6.8, 8.7, -8.9, 22.3]) * 1e3
b_unc = np.array([2.1, 1, 0.7, 1.9, 3.6, 2.4, 2.3, 1.4, 2.7, 2.0, 7.8]) * 1e3
plag_kd_params = pd.DataFrame(
[a, a_unc, b, b_unc], columns=elements, index=["a", "a_unc", "b", "b_unc"]
)