This page was generated from docs/Examples/Cpx_Cpx_Liq_Thermobarometry/MachineLearning_Cpx_Liq_Thermobarometry.ipynb. Interactive online version: Binder badge.

Python Notebook Download

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

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

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

First, load the necessary python things

[3]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import Thermobar as pt
pt.__version__
[3]:
'1.0.36'

Now, load the data

[4]:
out=pt.import_excel('Cpx_Liq_Example.xlsx', sheet_name="Sheet1")
my_input=out['my_input']
Liqs=out['Liqs']
Cpxs=out['Cpxs']
[5]:
import joblib as j
j.__version__
[5]:
'1.2.0'

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

[7]:
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)
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
[8]:
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
Youve selected a P-independent function
Youve selected a T-independent function
Youve selected a T-independent function
[8]:
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.0000 2.014248 2.014248 1434.15 37.734604 37.734604
1 2.385743 1422.872182 0 0 2.0000 2.516823 2.516823 1423.15 58.692923 58.692923
2 2.031163 1388.809636 0 0 2.0000 1.335548 1.335548 1398.15 100.495001 100.495001
3 2.175246 1418.986727 0 0 2.0000 2.290651 2.290651 1423.15 62.539834 62.539834
4 2.194894 1358.247818 0 0 2.0000 2.305614 2.305614 1373.15 80.220643 80.220643
5 6.846097 1483.411818 0 0 5.0000 7.297546 7.297546 1473.15 90.448301 90.448301
6 6.049409 1473.710000 0 0 4.0500 6.731814 6.731814 1466.15 85.025018 85.025018
7 9.449931 1483.408909 0 0 8.0000 8.203280 8.203280 1473.15 88.209247 88.209247
8 4.635460 1462.542727 0 0 3.9745 5.282807 5.282807 1449.15 63.993766 63.993766
9 6.107720 1462.148182 0 0 4.9850 6.226865 6.226865 1448.65 68.141951 68.141951
10 10.808077 1506.979455 0 0 9.7000 8.622634 8.622634 1493.15 95.431122 95.431122
11 5.851677 1461.882727 0 0 4.0430 6.151823 6.151823 1453.15 70.670782 70.670782
12 7.826454 1482.080909 0 0 5.0000 7.960571 7.960571 1473.15 94.254987 94.254987
13 10.300083 1496.978000 0 0 8.0000 8.729611 8.729611 1473.15 92.537615 92.537615
14 10.300083 1496.978000 0 0 8.0000 8.729611 8.729611 1473.15 92.537615 92.537615
15 10.300083 1496.978000 0 0 8.0000 8.729611 8.729611 1473.15 92.537615 92.537615
16 10.775014 1500.690364 0 0 9.6000 9.103614 9.103614 1478.15 97.447848 97.447848
17 9.463969 1500.291818 0 0 8.0000 8.543886 8.543886 1473.15 99.245966 99.245966
18 11.731851 1506.468182 0 0 10.0000 9.319109 9.319109 1493.15 93.497859 93.497859
19 9.431157 1495.166727 0 0 7.2500 8.513357 8.513357 1483.15 95.327742 95.327742

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
[16]:
# 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",
                                             H2O_Liq=0)
P_T_Cpx_only_Jorg.head()
Youve selected a P-independent function
Youve selected a T-independent function
[16]:
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 ... TiO2_Cpx Al2O3_Cpx FeOt_Cpx MnO_Cpx MgO_Cpx CaO_Cpx Na2O_Cpx K2O_Cpx Cr2O3_Cpx Sample_ID_Cpx
0 1.0 1355.15 0 0 1.0 0.0 0.0 1355.15 3.183231e-12 3.183231e-12 ... 0.50 3.70 5.18 0.09 15.8 22.8 0.24 0.0 0.66 0
1 2.0 1285.15 0 0 2.0 0.0 0.0 1285.15 4.092726e-12 4.092726e-12 ... 0.73 4.12 5.83 0.00 15.0 22.7 0.24 0.0 0.28 1
2 2.0 1238.15 0 0 2.0 0.0 0.0 1238.15 4.092726e-12 4.092726e-12 ... 1.75 7.85 6.51 0.14 13.1 22.5 0.25 0.0 0.22 2
3 2.0 1273.15 0 0 2.0 0.0 0.0 1273.15 4.092726e-12 4.092726e-12 ... 0.63 4.41 5.66 0.13 15.6 22.6 0.23 0.0 0.27 3
4 2.0 1238.15 0 0 2.0 0.0 0.0 1238.15 4.092726e-12 4.092726e-12 ... 0.56 4.14 7.33 0.20 14.4 22.4 0.31 0.0 0.09 4

5 rows × 21 columns

Using onnx models

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

[17]:
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
[17]:
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

[18]:
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
[18]:
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.000000 1355.150000 0 0 1.00 0.000000 0.000000 1355.15 3.183231e-12 3.183231e-12
1 2.000000 1285.150000 0 0 2.00 0.000000 0.000000 1285.15 4.092726e-12 4.092726e-12
2 2.000000 1238.150000 0 0 2.00 0.000000 0.000000 1238.15 4.092726e-12 4.092726e-12
3 2.000000 1273.150000 0 0 2.00 0.000000 0.000000 1273.15 4.088325e-12 4.088325e-12
4 2.000000 1238.150000 0 0 2.00 0.000000 0.000000 1238.15 4.092726e-12 4.092726e-12
5 8.419458 1446.550498 0 0 8.00 7.241728 7.241728 1433.15 9.848431e+01 9.848431e+01
6 7.142953 1432.000746 0 0 7.00 6.398140 6.398140 1423.15 8.921307e+01 8.921307e+01
7 10.956871 1450.309204 0 0 10.00 8.394058 8.394058 1433.15 1.100438e+02 1.100438e+02
8 5.233430 1401.965920 0 0 4.01 5.269948 5.269948 1408.15 6.391195e+01 6.391195e+01
9 7.305813 1417.891294 0 0 7.00 6.391484 6.391484 1413.15 7.970738e+01 7.970738e+01
10 12.012990 1466.025622 0 0 10.00 8.862633 8.862633 1448.15 1.268004e+02 1.268004e+02
11 6.400005 1412.503234 0 0 5.00 5.518597 5.518597 1413.15 8.188373e+01 8.188373e+01
12 8.628219 1439.751990 0 0 8.00 7.451500 7.451500 1428.15 9.935043e+01 9.935043e+01
13 11.173898 1470.112687 0 0 10.00 8.591048 8.591048 1449.15 1.162777e+02 1.162777e+02
14 11.173898 1470.112687 0 0 10.00 8.591048 8.591048 1449.15 1.162777e+02 1.162777e+02
15 11.173898 1470.112687 0 0 10.00 8.591048 8.591048 1449.15 1.162777e+02 1.162777e+02
16 11.642547 1469.455970 0 0 10.00 8.798096 8.798096 1448.15 1.235193e+02 1.235193e+02
17 11.593090 1468.349005 0 0 10.00 8.791730 8.791730 1448.15 1.283919e+02 1.283919e+02
18 13.392448 1468.339055 0 0 10.00 8.665804 8.665804 1448.15 1.180593e+02 1.180593e+02
19 9.767323 1465.881343 0 0 9.70 7.868123 7.868123 1448.15 1.155477e+02 1.155477e+02
[ ]:
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
c:\users\penny\onedrive\documents\postdoc_missing\mybarometers\thermobar_outer\src\Thermobar\core.py:1561: FutureWarning: In a future version, the Index constructor will not infer numeric dtypes when passed object-dtype sequences (matching Series behavior)
  cpx_calc.loc[(AlVI_minus_Na<0), 'Jd']=cpx_calc['Al_VI_cat_6ox']
Youve selected a T-independent function
Youve selected a T-independent function
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
5 8.419460 1452.618042 0 0
6 7.142956 1438.607666 0 0
7 10.956876 1446.971313 0 0
8 5.233430 1408.817017 0 0
9 7.305816 1418.339111 0 0
10 12.012997 1482.637695 0 0
11 6.400006 1409.916504 0 0
12 8.628222 1452.076050 0 0
13 11.173905 1468.081055 0 0
14 11.173905 1468.081055 0 0
15 11.173905 1468.081055 0 0
16 11.642552 1479.100586 0 0
17 11.593097 1460.817383 0 0
18 13.392457 1472.319458 0 0
19 9.767327 1466.672852 0 0
[22]:
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
[22]:
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
[23]:
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()
[23]:
0    2.002911
1    2.376496
2    2.000006
3    2.000006
4    2.000006
dtype: float32