Machine-Learning-based Clinopyroxene-only and Clinopyroxene-Liquid Thermobarometry.

You need to install Thermobar once on your machine, if you haven’t done this yet, uncomment the line below (remove the #)

[1]:
#!pip install Thermobar
[2]:
import sklearn
print(sklearn.__version__)
1.6.1

For Machine learning, you also need to pip install the .pkl files that have saved the pretrained model. This is to keep Thermobar smaller so we can still release on Pip

[5]:
#!pip install "https://github.com/PennyWieser/Thermobar_onnx/archive/refs/tags/v.0.05.zip"

First, load the necessary python things

[6]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import Thermobar as pt
pt.__version__
[6]:
'1.0.59'
[7]:
import Thermobar_onnx as pto
pto.__version__
[7]:
'0.0.5'

Now, load the data

[8]:
out=pt.import_excel('Cpx_Liq_Example.xlsx', sheet_name="Sheet1")
my_input=out['my_input']
Liqs=out['Liqs']
Cpxs=out['Cpxs']

Using saved models

  • This uses pickles, the model will change with different versions of python

  • But, it does give you the voting approach of Jorgenson, with the median and standard deviation of the trees

[10]:
# Jorgenson Cpx-Liq
P_T_EqTests_pkl=pt.calculate_cpx_liq_press_temp(cpx_comps=Cpxs, liq_comps=Liqs,
                                                equationP="P_Jorgenson2022_Cpx_Liq",
                                                equationT="T_Jorgenson2022_Cpx_Liq",
                                                H2O_Liq=3, eq_tests=False)
P_T_EqTests_pkl.tail()
Im normalizing using the Jorgenson method, e.g. 100 total, 2dp
Im normalizing using the Jorgenson method, e.g. 100 total, 2dp
Youve selected a P-independent function
Youve selected a T-independent function
Youve selected a T-independent function
[10]:
P_kbar_calc T_K_calc Delta_P_kbar_Iter Delta_T_K_Iter Median_Trees_P Std_Trees_P IQR_Trees_P Median_Trees_T Std_Trees_T IQR_Trees_T
15 11.173898 1470.137562 0 0 10.0 8.591048 8.591048 1449.15 116.307711 116.307711
16 11.642547 1468.659950 0 0 10.0 8.798096 8.798096 1448.15 123.213623 123.213623
17 11.593090 1468.000746 0 0 10.0 8.791730 8.791730 1448.15 128.441355 128.441355
18 13.392448 1467.990796 0 0 10.0 8.665804 8.665804 1448.15 118.113086 118.113086
19 9.767323 1466.751990 0 0 9.7 7.868123 7.868123 1448.15 115.451141 115.451141
[11]:
# Petrelli Cpx-Liq
P_T_EqTests_pkl=pt.calculate_cpx_liq_press_temp(cpx_comps=Cpxs, liq_comps=Liqs,
                                                equationP="P_Petrelli2020_Cpx_Liq",
                                            equationT="T_Petrelli2020_Cpx_Liq",
                                                 T=1300,
                                             H2O_Liq=0, eq_tests=False)
P_T_EqTests_pkl.head()
Youve selected a P-independent function
Youve selected a T-independent function
Youve selected a T-independent function
[11]:
P_kbar_calc T_K_calc Delta_P_kbar_Iter Delta_T_K_Iter Median_Trees_P Std_Trees_P IQR_Trees_P Median_Trees_T Std_Trees_T IQR_Trees_T
0 2.012874 1436.353636 0 0 2.0 2.014248 2.014248 1434.15 37.734604 37.734604
1 2.385743 1422.872182 0 0 2.0 2.516823 2.516823 1423.15 58.692923 58.692923
2 2.031163 1388.809636 0 0 2.0 1.335548 1.335548 1398.15 100.495001 100.495001
3 2.175246 1418.986727 0 0 2.0 2.290651 2.290651 1423.15 62.539834 62.539834
4 2.194894 1358.247818 0 0 2.0 2.305614 2.305614 1373.15 80.220643 80.220643

Lets do Cpx-only

  • Note, Petrelli doesnt have a T equation

[12]:
P_T_Cpx_only_Pet=pt.calculate_cpx_only_press(cpx_comps=Cpxs,
                                                equationP="P_Petrelli2020_Cpx_only",
                                             H2O_Liq=0)
P_T_Cpx_only_Pet.head()
[12]:
P_kbar_calc Median_Trees Std_Trees IQR_Trees
0 2.002907 2.0 0.890108 0.00
1 2.376498 2.0 1.501786 0.04
2 2.000000 2.0 0.000000 0.00
3 2.000000 2.0 0.000000 0.00
4 2.000000 2.0 0.000000 0.00
[14]:
# Jorg has T and P
P_T_Cpx_only_Jorg=pt.calculate_cpx_only_press_temp(cpx_comps=Cpxs, equationT='T_Jorgenson2022_Cpx_only',
                                                equationP="P_Jorgenson2022_Cpx_only",
                                            )
P_T_Cpx_only_Jorg.tail()
Youve selected a P-independent function
Youve selected a T-independent function
[14]:
P_kbar_calc T_K_calc Delta_P_kbar_Iter Delta_T_K_Iter Median_Trees_P Std_Trees_P IQR_Trees_P Median_Trees_T Std_Trees_T IQR_Trees_T ... Jd Jd_from 0=Na, 1=Al CaTs CaTi DiHd_1996 EnFs DiHd_2003 Di_Cpx FeIII_Wang21 FeII_Wang21
15 11.863184 1424.145025 0 0 10.00 8.512409 8.512409 1423.15 118.952204 118.952204 ... 0.000724 1 0.0 0.080643 0.789095 0.137203 0.789095 0.653001 0.167476 0.010370
16 10.578930 1414.428607 0 0 10.00 8.522943 8.522943 1436.15 144.171754 144.171754 ... 0.016166 1 0.0 0.087705 0.765280 0.121381 0.765280 0.621245 0.130527 0.049936
17 11.221821 1413.950995 0 0 10.00 8.477640 8.477640 1436.15 132.009235 132.009235 ... 0.000000 1 0.0 0.087680 0.785434 0.125194 0.785434 0.644977 0.159251 0.004758
18 12.743761 1437.548010 0 0 10.00 8.749051 8.749051 1448.15 124.387178 124.387178 ... 0.013722 1 0.0 0.081720 0.779896 0.117953 0.779896 0.642299 0.131180 0.041246
19 10.359308 1408.771891 0 0 9.85 7.999391 7.999391 1423.15 141.701341 141.701341 ... 0.019037 1 0.0 0.087068 0.777534 0.128604 0.777534 0.632774 0.145446 0.026854

5 rows × 55 columns

[15]:
# Jorg has T and P
P_T_Cpx_only_Jorg_onnx=pt.calculate_cpx_only_press_temp(cpx_comps=Cpxs, equationT='T_Jorgenson2022_Cpx_only_onnx',
                                                equationP="P_Jorgenson2022_Cpx_only_onnx",
                                             H2O_Liq=0)
P_T_Cpx_only_Jorg_onnx.head()
Youve selected a P-independent function
Youve selected a T-independent function
[15]:
P_kbar_calc T_K_calc Delta_P_kbar_Iter Delta_T_K_Iter SiO2_Cpx TiO2_Cpx Al2O3_Cpx FeOt_Cpx MnO_Cpx MgO_Cpx ... Jd Jd_from 0=Na, 1=Al CaTs CaTi DiHd_1996 EnFs DiHd_2003 Di_Cpx FeIII_Wang21 FeII_Wang21
0 1.000001 1355.152954 0 0 51.5 0.50 3.70 5.18 0.09 15.8 ... 0.017055 0 0.030375 0.041013 0.814436 0.103827 0.814436 0.686042 0.035332 0.123446
1 2.000002 1285.151611 0 0 50.3 0.73 4.12 5.83 0.00 15.0 ... 0.017330 0 0.036817 0.044938 0.819939 0.097220 0.819939 0.673165 0.040732 0.140847
2 2.000002 1238.150146 0 0 47.3 1.75 7.85 6.51 0.14 13.1 ... 0.018085 0 0.091885 0.071667 0.732671 0.099545 0.732671 0.570239 0.038619 0.164508
3 2.000002 1273.152954 0 0 51.1 0.63 4.41 5.66 0.13 15.6 ... 0.016335 0 0.045827 0.041197 0.796049 0.114596 0.796049 0.658834 0.039859 0.133524
4 2.000002 1238.150146 0 0 51.0 0.56 4.14 7.33 0.20 14.4 ... 0.022215 0 0.043110 0.035953 0.806694 0.106652 0.806694 0.623678 0.038138 0.188429

5 rows × 49 columns

Using onnx models

-Using Onnx means you will always get the same answer. But, you dont get the voting results.

[16]:
P_T_EqTests_onnx=pt.calculate_cpx_liq_press_temp(cpx_comps=Cpxs, liq_comps=Liqs,
                                                equationP="P_Petrelli2020_Cpx_Liq_onnx",
                                            equationT="T_Petrelli2020_Cpx_Liq_onnx",
                                                 T=1300,
                                             H2O_Liq=0, eq_tests=True)
P_T_EqTests_onnx.head()
Youve selected a P-independent function
Youve selected a T-independent function
Youve selected a T-independent function
Using Fe3FeT from input file to calculate Kd Fe-Mg
[16]:
P_kbar_calc T_K_calc Eq Tests Neave2017? Delta_P_kbar_Iter Delta_T_K_Iter Delta_Kd_Put2008 Delta_Kd_Mas2013 Delta_EnFs_Mollo13 Delta_EnFs_Put1999 Delta_CaTs_Put1999 ... Delta_EnFs_I_M_Mollo13 CaTs_Pred_Put1999 Delta_CaTs_I_M_Put1999 CrCaTs_Pred_Put1999 Delta_CrCaTs_I_M_Put1999 CaTi_Pred_Put1999 Delta_CaTi_I_M_Put1999 Jd_Pred_Put1999 Delta_Jd_Put1999 Delta_Jd_I_M_Put1999
0 2.012875 1436.355103 False 0 0 0.047419 0.090012 0.001449 0.024126 0.016574 ... 0.001449 0.013801 -0.016574 0.0 0.009562 0.042741 0.001728 0.016176 0.000880 0.000880
1 2.385741 1422.873779 False 0 0 0.045964 0.082381 0.006055 0.027422 0.023015 ... 0.006055 0.013802 -0.023015 0.0 0.004122 0.055375 0.010437 0.017422 0.000092 0.000092
2 2.031165 1388.808716 False 0 0 0.048797 0.163165 0.066580 0.001942 0.074375 ... 0.066580 0.017510 -0.074375 0.0 0.003245 0.028704 0.042963 0.018321 0.000236 0.000236
3 2.175245 1418.988159 False 0 0 0.042373 0.094228 0.002781 0.034579 0.030821 ... 0.002781 0.015006 -0.030821 0.0 0.003909 0.049805 0.008608 0.019322 0.002988 0.002988
4 2.194893 1358.247559 False 0 0 0.030098 0.090116 0.007655 0.053517 0.031539 ... -0.007655 0.011571 -0.031539 0.0 0.001315 0.049482 0.013529 0.027939 0.005724 0.005724

5 rows × 132 columns

[17]:
P_T_EqTests_pkl_Jorg=pt.calculate_cpx_liq_press_temp(cpx_comps=Cpxs, liq_comps=Liqs,
                                                equationP="P_Jorgenson2022_Cpx_Liq",
                                            equationT="T_Jorgenson2022_Cpx_Liq",
                                                 T=1300,
                                             H2O_Liq=0, eq_tests=False)
P_T_EqTests_pkl_Jorg.head()
Im normalizing using the Jorgenson method, e.g. 100 total, 2dp
Im normalizing using the Jorgenson method, e.g. 100 total, 2dp
Youve selected a P-independent function
Youve selected a T-independent function
Youve selected a T-independent function
[17]:
P_kbar_calc T_K_calc Delta_P_kbar_Iter Delta_T_K_Iter Median_Trees_P Std_Trees_P IQR_Trees_P Median_Trees_T Std_Trees_T IQR_Trees_T
0 1.0 1355.15 0 0 1.0 0.0 0.0 1355.15 3.183231e-12 3.183231e-12
1 2.0 1285.15 0 0 2.0 0.0 0.0 1285.15 4.092726e-12 4.092726e-12
2 2.0 1238.15 0 0 2.0 0.0 0.0 1238.15 4.092726e-12 4.092726e-12
3 2.0 1273.15 0 0 2.0 0.0 0.0 1273.15 4.088325e-12 4.088325e-12
4 2.0 1238.15 0 0 2.0 0.0 0.0 1238.15 4.092726e-12 4.092726e-12
[18]:
P_T_EqTests_onnx_Jorg=pt.calculate_cpx_liq_press_temp(cpx_comps=Cpxs, liq_comps=Liqs,
                                                equationP="P_Jorgenson2022_Cpx_Liq_onnx",
                                            equationT="T_Jorgenson2022_Cpx_Liq_onnx",
                                                 T=1300,
                                             H2O_Liq=0, eq_tests=False)
P_T_EqTests_onnx_Jorg.head()
Im normalizing using the Jorgenson method, e.g. 100 total, 2dp
Im normalizing using the Jorgenson method, e.g. 100 total, 2dp
Youve selected a P-independent function
Youve selected a T-independent function
Youve selected a T-independent function
[18]:
P_kbar_calc T_K_calc Delta_P_kbar_Iter Delta_T_K_Iter
0 1.000001 1355.152954 0 0
1 2.000002 1285.151611 0 0
2 2.000002 1238.816772 0 0
3 2.000002 1273.152954 0 0
4 2.000002 1238.821777 0 0
[19]:
P_T_EqTests_pkl_Jorg_Cpx_only=pt.calculate_cpx_only_press_temp(cpx_comps=Cpxs,
                                                equationP="P_Jorgenson2022_Cpx_only_onnx",
                                            equationT="T_Jorgenson2022_Cpx_only_onnx",
                                             H2O_Liq=0, eq_tests=False)
P_T_EqTests_pkl_Jorg_Cpx_only.head()
Youve selected a P-independent function
Youve selected a T-independent function
[19]:
P_kbar_calc T_K_calc Delta_P_kbar_Iter Delta_T_K_Iter
0 1.000001 1355.152954 0 0
1 2.000002 1285.151611 0 0
2 2.000002 1238.150146 0 0
3 2.000002 1273.152954 0 0
4 2.000002 1238.150146 0 0
[20]:
P_T_EqTests_pkl_Pet_Cpx_only=pt.calculate_cpx_only_press(cpx_comps=Cpxs,
                                                equationP="P_Petrelli2020_Cpx_only_onnx",

                                             H2O_Liq=0, eq_tests=False)
P_T_EqTests_pkl_Pet_Cpx_only.head()
[20]:
0    2.002911
1    2.376496
2    2.000006
3    2.000006
4    2.000006
dtype: float32
[21]:
pt.calculate_cpx_liq_press_all_eqs(cpx_comps=Cpxs, liq_comps=Liqs)
We have reset the index on Cpx and Liq comps for the Petrelli expressions
Youve selected a P-independent function
Youve selected a T-independent function
Youve selected a T-independent function
Im normalizing using the Jorgenson method, e.g. 100 total, 2dp
Im normalizing using the Jorgenson method, e.g. 100 total, 2dp
Youve selected a P-independent function
Youve selected a T-independent function
Youve selected a T-independent function
[21]:
P_kbar: (P_Neave17, T_Put2008_eq33) T_K: (P_Neave17, T_Put2008_eq33) P_kbar: (P_Neave17, T_Put2008_eq34_cpx_sat) T_K: (P_Neave17, T_Put2008_eq34_cpx_sat) P_kbar: (P_Put2008_eq30, T_Put2008_eq33) T_K: (P_Put2008_eq30, T_Put2008_eq33) P_kbar: (P_Put2008_eq31, T_Put2008_eq33) T_K: (P_Put2008_eq31, T_Put2008_eq33) P_kbar: (P_Put2008_eq32c, T_Put2008_eq33) T_K: (P_Put2008_eq32c, T_Put2008_eq33) ... P_kbar: (P_Put2008_eq32c, T_Put2008_eq34) T_K: (P_Put2008_eq32c, T_Put2008_eq34)) P_kbar: (P2003 P&T) T_K: (P2003 P&T) T_K: (P_Put1996_eqP1, T_Put1996_eqT2) P_kbar: (P_Put1996_eqP1, T_Put1996_eqT2) P_kbar: (Petrelli, 2020) T_K: (Petrelli, 2020) P_kbar: (Jorgenson, 2022) T_K: (Jorgenson, 2022)
0 0.960631 1344.698427 1.161345 1372.216226 2.530914 1352.408784 2.386186 1351.694450 2.209868 1350.825212 ... 4.653251 1402.264846 0.947885 1429.684711 1431.212441 2.587626 2.329420 1365.986364 1.000000 1355.150000
1 1.583720 1289.239285 1.816406 1323.941135 1.786845 1290.151507 2.624094 1293.925217 1.870946 1290.529579 ... 4.453012 1344.888862 0.453851 1388.379217 1410.593746 1.759554 2.445954 1282.522727 2.000000 1285.150000
2 0.895589 1254.759806 1.055286 1283.601656 1.171520 1255.933868 5.162310 1273.163405 6.281137 1278.078913 ... 9.615150 1348.268665 -0.946284 1362.151670 1402.050070 0.278452 2.000000 1238.150000 2.000000 1238.150000
3 0.952699 1287.319189 1.130722 1317.160073 2.143416 1292.669093 2.225915 1293.041408 2.332966 1293.524848 ... 4.859417 1346.713288 -0.021555 1387.134284 1408.805156 1.263705 2.000000 1273.150000 2.000000 1273.150000
4 3.581562 1246.894077 3.771286 1283.856794 2.763538 1243.469600 2.113770 1240.762861 1.456253 1238.035814 ... 3.559098 1282.306231 -1.003005 1307.655434 1373.636951 1.791782 2.000000 1238.150000 2.000000 1238.150000
5 0.243892 1326.967235 0.415966 1354.908503 0.535148 1328.353392 1.644674 1333.660525 6.217609 1355.989061 ... 10.065676 1437.001010 1.732806 1410.542720 1419.458701 1.415638 6.255929 1407.600909 8.419458 1445.207214
6 0.417517 1347.239217 0.538496 1365.421568 0.493360 1347.611001 2.028287 1355.179555 6.149924 1375.929961 ... 9.198085 1440.101788 0.761159 1421.376427 1420.276203 1.118512 5.358937 1404.295455 7.142953 1431.413682
7 4.547863 1368.088406 4.727133 1386.987455 6.377576 1377.397773 4.958305 1370.165723 6.508429 1378.068397 ... 8.419280 1418.296827 4.506077 1446.355413 1463.224037 7.156675 8.983034 1417.270727 10.956871 1450.617662
8 3.947483 1381.069803 4.056585 1392.883146 5.742168 1390.374437 4.903319 1386.009826 6.701994 1395.402347 ... 8.332797 1429.735042 4.646604 1453.662996 1466.571252 6.358436 4.371746 1383.199091 5.233430 1402.214677
9 0.038430 1333.204600 0.188424 1356.817194 1.396263 1339.752950 1.424833 1339.891421 4.924780 1357.074404 ... 8.135490 1424.668294 1.038394 1415.874785 1419.313558 1.386394 5.537360 1393.935455 7.305813 1417.428607
10 0.200203 1340.625226 0.381647 1368.153233 0.644651 1342.785453 1.858428 1348.720595 6.063573 1369.695049 ... 9.926488 1451.019566 1.516516 1429.767061 1429.264132 1.592055 10.391380 1434.397636 12.012990 1466.722139
11 -2.394313 1309.677677 -2.290033 1333.211926 -1.883972 1312.045437 -1.101693 1315.691536 4.269923 1341.285891 ... 8.047005 1420.803407 -1.885421 1401.586141 1389.749087 -2.342392 5.255480 1383.217273 6.400005 1412.164925
12 0.825219 1342.518158 0.949742 1360.563992 1.211110 1344.398677 2.293732 1349.702714 6.681858 1371.636829 ... 9.698357 1435.142078 1.548641 1416.908216 1420.092279 1.701637 7.227006 1413.153636 8.628219 1439.662438
13 -14.474441 1218.145745 -14.593818 1241.824436 -14.685454 1217.300913 -11.804596 1228.937166 1.380828 1285.164334 ... 8.651346 1438.227877 -12.204949 1317.010081 1269.570664 -17.355526 9.867831 1436.505273 11.173898 1470.137562
14 -14.474441 1218.145745 -14.593818 1241.824436 -14.685454 1217.300913 -11.804596 1228.937166 1.380828 1285.164334 ... 8.651346 1438.227877 -12.204949 1317.010081 1269.570664 -17.355526 9.867831 1436.505273 11.173898 1470.137562
15 -14.474441 1218.145745 -14.593818 1241.824436 -14.685454 1217.300913 -11.804596 1228.937166 1.380828 1285.164334 ... 8.651346 1438.227877 -12.204949 1317.010081 1269.570664 -17.355526 9.867831 1436.505273 11.173898 1470.137562
16 1.708652 1350.360162 1.843592 1369.131043 2.168816 1352.629530 2.451815 1354.028975 6.988374 1376.864417 ... 9.886670 1437.881176 2.242127 1423.170837 1429.687956 2.817740 10.495660 1429.024909 11.642547 1468.659950
17 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... 9.058003 1433.633736 NaN NaN NaN NaN 9.028249 1431.986364 11.593090 1468.000746
18 0.668786 1339.383313 0.785661 1356.879960 1.315338 1342.522331 1.944311 1345.590153 6.353412 1367.495623 ... 9.271050 1428.919575 1.790039 1420.699970 1424.349487 1.771298 11.176709 1425.900909 13.392448 1467.990796
19 2.199064 1363.641781 2.349690 1382.201715 3.494361 1370.176239 4.147692 1373.495956 7.768219 1392.188178 ... 10.756884 1455.107432 3.916329 1440.372414 1451.211814 4.405081 8.741760 1428.795818 9.767323 1466.751990

20 rows × 26 columns

[ ]:

[ ]: