一雾狈、單組數(shù)據(jù)計算
melts.ofm-research.org 這個網(wǎng)站提供了在線計算廓潜,按照提示及要求輸入數(shù)據(jù)即可∩崎唬可實現(xiàn)單組數(shù)據(jù)的計算辩蛋。缺點也很明顯,就是手動輸入總讓人感覺不舒服移盆。
二悼院、多組數(shù)據(jù)批量計算
2.1 數(shù)據(jù)準(zhǔn)備
按如下格式整理所需數(shù)據(jù)為EXCEL文件:
詳細(xì)數(shù)據(jù)示例:https://pan.baidu.com/s/1EOX6kSA3NBfpKL6Qwbhz1w
提取碼:1111
表格說明:
1.表頭為各組分標(biāo)識,分別以a/b/c開頭咒循,a為橄欖石組分据途,b為尖晶石組分钮呀,c為斜方輝石組分。蚂四。
2.第一列為數(shù)據(jù)點編號。
2.2 實現(xiàn)過程(該代碼包含F(xiàn)e-Ti oxide geothermobarometer (鈦鐵氧化物溫度計) 批量計算溫度和氧逸度)
# -*- coding: utf-8 -*-
"""
Copyright (C) 2021, Inc. All Rights Reserved
@Time :2021/9/23 23:18
@Wechart :Pandas120
@Email :137243562@qq.com
@File :feti_geothermal.py
@Version :1.1
"""
import requests as rq
from lxml import etree
import pandas as pd
import easygui,time
###定義一個函數(shù)哪痰,并返回Fe-Ti oxide geothermobarometer計算結(jié)果
def getresultfeti(data):
SiO2sp = data["aSiO2"]
SiO2rh = data["bSiO2"]
TiO2sp = data["aTiO2"]
TiO2rh = data["bTiO2"]
Al2O3sp = data["aAl2O3"]
Al2O3rh = data["bAl2O3"]
Fe2O3sp = data["aFe2O3"]
Fe2O3rh = data["bFe2O3"]
V2O3sp = data["aV2O3"]
V2O3rh = data["bV2O3"]
Cr2O3sp = data["aCr2O3"]
Cr2O3rh = data["bCr2O3"]
FeOsp = data["aFeO"]
FeOrh = data["bFeO"]
MnOsp = data["aMnO"]
MnOrh = data["bMnO"]
MgOsp = data["aMgO"]
MgOrh = data["bMgO"]
CaOsp = data["aCaO"]
CaOrh = data["bCaO"]
ZnOsp = data["aZnO"]
ZnOrh = data["bZnO"]
NiOsp = data["aNiO"]
NiOrh = data["bNiO"]
url = f"http://melts.ofm-research.org/CORBA_CTserver/OxideGeothrm/OxideGeothrmResult.php?SiO2sp={SiO2sp}&SiO2rh={SiO2rh}&TiO2sp={TiO2sp}&TiO2rh={TiO2rh}&Al2O3sp={Al2O3sp}&Al2O3rh={Al2O3rh}&Fe2O3sp={Fe2O3sp}&Fe2O3rh={Fe2O3rh}&V2O3sp={V2O3sp}&V2O3rh={V2O3rh}&Cr2O3sp={Cr2O3sp}&Cr2O3rh={Cr2O3rh}&FeOsp={FeOsp}&FeOrh={FeOrh}&MnOsp={MnOsp}&MnOrh={MnOrh}&MgOsp={MgOsp}&MgOrh={MgOrh}&CaOsp={CaOsp}&CaOrh={CaOrh}&ZnOsp={ZnOsp}&ZnOrh={ZnOrh}&NiOsp={NiOsp}&NiOrh={NiOrh}&Submit1=Calculate+T+and+fO2"
while True:
res = rq.get(url)
if res.status_code == 200:
html = etree.HTML(res.text)
tfeti = float(html.xpath("/html/body/div/div/div/table[2]/tr[1]/td[2]/div/text()")[0])
log10f02 = float(html.xpath("/html/body/div/div/div/table[2]/tr[2]/td[2]/div/text()")[0])
tfemg = float(html.xpath("/html/body/div/div/div/table[2]/tr[3]/td[2]/div/text()")[0])
ati02 = float(html.xpath("/html/body/div/div/div/table[2]/tr[4]/td[2]/div/text()")[0])
return tfeti, log10f02, tfemg, ati02
else:
print("連接失斔煸!正在重試I谓堋跷睦!")
###定義一個函數(shù),并返回 olivine, spinel and orthopyroxene 橄欖石肋演、尖晶石抑诸、斜方輝石 計算結(jié)果
def getresultolv_spn_opx(data):
sio21 = data["aSiO2"]
tio21 = data["aTiO2"]
al2o31 = data["aAl2O3"]
fe2o31 = data["aFe2O3"]
cr2o31 = data["aCr2O3"]
feo1 = data["aFeO"]
mno1 = data["aMnO"]
mgo1 = data["aMgO"]
nio1 = data["aNiO"]
coo1 = data["aCoO"]
cao1 = data["aCaO"]
na2o1 = data["aNa2O"]
sio22 = data["bSiO2"]
tio22 = data["bTiO2"]
al2o32 = data["bAl2O3"]
fe2o32 = data["bFe2O3"]
cr2o32 = data["bCr2O3"]
feo2 = data["bFeO"]
mno2 = data["bMnO"]
mgo2 = data["bMgO"]
nio2 = data["bNiO"]
coo2 = data["bCoO"]
cao2 = data["bCaO"]
na2o2 = data["bNa2O"]
sio23 = data["cSiO2"]
tio23 = data["cTiO2"]
al2o33 = data["cAl2O3"]
fe2o33 = data["cFe2O3"]
cr2o33 = data["cCr2O3"]
feo3 = data["cFeO"]
mno3 = data["cMnO"]
mgo3 = data["cMgO"]
nio3 = data["cNiO"]
coo3 = data["cCoO"]
cao3 = data["cCaO"]
na2o3 = data["cNa2O"]
url = f"http://melts.ofm-research.org/CORBA_CTserver/Olv_Spn_Opx/Olv_Spn_Opx_stub.php?t=0.0&p=0.0001" \
f"&sio21={sio21}&tio21={tio21}4&al2o31={al2o31}8&fe2o31={fe2o31}&cr2o31={cr2o31}&feo1={feo1}&mno1={mno1}&mgo1={mgo1}&nio1={nio1}&coo1={coo1}&cao1={cao1}&na2o1={na2o1}" \
f"&sio22={sio22}&tio22={tio22}&al2o32={al2o32}&fe2o32={fe2o32}&cr2o32={cr2o32}&feo2={feo2}&mno2={mno2}&mgo2={mgo2}&nio2={nio2}&coo2={coo2}&cao2={cao2}&na2o2={na2o2}" \
f"&sio23={sio23}&tio23={tio23}&al2o33={al2o33}&fe2o33={fe2o33}&cr2o33={cr2o33}&feo3={feo3}&mno3={mno3}&mgo3={mgo3}&nio3={nio3}&coo3={coo3}&cao3={cao3}&na2o3={na2o3}&keepOpxFe2O3=no"
while True:
res = rq.get(url)
if res.status_code == 200:
return res.text.replace(" ","").split(",")
else:
print("連接失敗爹殊!正在重試M上纭!")
###主函數(shù)入口
if __name__ == "__main__":
file = easygui.fileopenbox(filetypes=["*.xls", "*.xlsx"], default="*.xlsx")
data = pd.read_excel(file, sheet_name=0)
while True:
print("Choose a option to calculate:")
print("1.calculate the Fe-Ti Oxide.")
print("2.calculate the Olv_Spn_Opx.")
chose = input("Please input the 1 or 2:")
if chose == "1":
tfetilist = []
log10f02list = []
tfemglist = []
ati02list = []
for i in range(data.shape[0]):
tfeti, log10f02, tfemg, ati02=getresultfeti(data.loc[i, :])
tfetilist.append(tfeti)
log10f02list.append(log10f02)
tfemglist.append(tfemg)
ati02list.append(ati02)
data["tfeti"] = tfetilist
data["log10f02"] = log10f02list
data["tfemg"] = tfemglist
data["ati02"] = ati02list
data.to_excel("result_Fe_Ti_Oxide.xlsx",sheet_name="res",index=False)
print("Finished!! The result has been saved to result_Fe_Ti_Oxide.xlsx !")
time.sleep(3)
break
elif chose=="2":
tlist = []
log10f02list = []
for i in range(data.shape[0]):
t, log10f02=getresultolv_spn_opx(data.loc[i, :])
tlist.append(float(t))
log10f02list.append(float(log10f02))
data["t"] = tlist
data["log10f02"] = log10f02list
data.to_excel("result_olv_spn_opx.xlsx",sheet_name="res",index=False)
print("Finished!! The result has been saved to result_olv_spn_opx.xlsx !")
time.sleep(3)
break
else:
print("Input error,please reinput!!")