一抡柿、鈦鐵氧化物溫度計
鈦鐵氧化物溫度計(Fe-Ti oxide geothermobarometer )通過計算平衡共生礦物的共有成份分配函數(shù),可以測定礦物大致的結(jié)晶溫度嘲驾。
二、計算軟件
目前比較成熟的計算軟件是由Ghiorso MS , Evans BW (2008)編寫的軟件,提供了Mac Os和Windows平臺的應(yīng)用以及網(wǎng)頁在線版畅卓。
1.Mac Os 版 該版本所兼容的系統(tǒng)(OS 10.5 (Leopard) and OS10.6 (Snow Leopard) 版本早已過時。
2.Windows版 該版本為Excel編寫的宏蟋恬,僅支持Office 2003翁潘,現(xiàn)在誰還用這古老的版本!<哒拜马!
3.網(wǎng)頁在線版 該網(wǎng)頁僅支持手動輸入數(shù)據(jù),且無法完成批量計算沐绒。
那么怎么去實現(xiàn)批量計算呢俩莽?
三、思路解析
首先對excel宏源碼進(jìn)行了分析洒沦,試圖從源代碼里面找到計算公式豹绪,可是大佬寫的VBA代碼里面根本沒有計算公式,而是將excel數(shù)據(jù)以數(shù)組的形式傳遞給了在線服務(wù)器。放棄B鹘颉2跻隆!
既然無法獲取算法公式巷蚪,那么只能打網(wǎng)頁在線版的主意了病毡。
F6A2BE3E-B3AB-49FC-820B-C0B10B778EBD.png
網(wǎng)頁版的界面上可以直接手動輸入數(shù)據(jù)進(jìn)行計算,并返回單次計算結(jié)果屁柏,可是對于批量計算無能為力啦膜。
于是想到的就是用爬蟲批量傳遞數(shù)據(jù)給服務(wù)器,然后爬取返回的結(jié)果寫入excel淌喻。通過分析該網(wǎng)頁網(wǎng)址傳遞參數(shù)到服務(wù)器計算的過程僧家,發(fā)現(xiàn)該網(wǎng)站參數(shù)傳遞非常簡單,僅僅是參數(shù)拼接裸删。參數(shù)傳遞鏈接如下:
http://melts.ofm-research.org/CORBA_CTserver/OxideGeothrm/OxideGeothrmResult.php?SiO2sp=0.0&SiO2rh=0.0&TiO2sp=4.35&TiO2rh=28.73&Al2O3sp=1.94&Al2O3rh=0.35&Fe2O3sp=0.0&Fe2O3rh=0.0&V2O3sp=0.0&V2O3rh=0.0&Cr2O3sp=0.18&Cr2O3rh=0.0&FeOsp=86.34&FeOrh=65.98&MnOsp=0.44&MnOrh=0.23&MgOsp=1.2&MgOrh=1.02&CaOsp=0.0&CaOrh=0.0&ZnOsp=0.0&ZnOrh=0.0&NiOsp=0.0&NiOrh=0.0&Submit1=Calculate+T+and+fO2
所以只需將數(shù)據(jù)按照以上網(wǎng)址的樣式進(jìn)行簡單的組合八拱,即可利用爬蟲實現(xiàn)批量計算。
四涯塔、數(shù)據(jù)準(zhǔn)備
按如下形式整理數(shù)據(jù)為excel肌稻。
7DD9C4923C051145142B42EE9FD02EAF.png
1.表頭分別為兩種礦物的各元素標(biāo)識。诺凡。
2.第一列為每一個測點的編號。
五药薯、實現(xiàn)過程
# -*- 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
###定義一個函數(shù)绑洛,并返回計算結(jié)果
def getresult(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("連接失敗童本!正在重試U嫱汀!")
###主函數(shù)入口
if __name__ == "__main__":
file = easygui.fileopenbox(filetypes=["*.xls", "*.xlsx"], default="*.xlsx")
data = pd.read_excel(file, sheet_name=0)
tfetilist = []
log10f02list = []
tfemglist = []
ati02list = []
for i in range(data.shape[0]):
tfeti, log10f02, tfemg, ati02=getresult(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.xlsx",sheet_name="res",index=False)