计算潜在蒸散量PET的方法
目标是想计算相对湿润度指数MI
得先计算PET:
PET的方法可以采用Thornthwaite方法和FAO Penman-Monteith方法,但是彭曼公式涉及到辐射,需要辐射数据比较麻烦,所以采用Thornthwaite方法
原始数据:
处理后的数据:
代码如下:
#!usr/bin/env python # -*- coding:utf-8 -*- """ @author: Su @file: calculateMI.py @time: 2023/08/17 @desc: """ import pandas as pd import numpy as np df = pd.read_excel('processdata/lianxi/鄂尔多斯.xlsx') df[df['temp']<0] = np.nan ab = df.dropna(axis=0,how='all') # 计算Hi temp = ab.temp.values T = np.power(temp/5,1.514) Hi = pd.DataFrame(T) # 创建一个新DataFrame放入分类好后的站点数据 df2 = pd.DataFrame(ab) df2.insert(loc=7, column='Hi',value=Hi.values) # 给站点分类 nameList1 = set(df2.name.values) # 想将结果写入excel,需创建空的dataframe df_all = pd.DataFrame(data=None) for i in nameList1: # 进行站点遍历 dfName = df2[df2['name'] == i] df3 = pd.DataFrame(dfName) # 分年求和 nameList2 = set(df3.year.values) for j in nameList2: # 按年遍历 dfYear = df3[df3['year'] == j] df4 = pd.DataFrame(dfYear) # 计算Hi的和 H_sum = dfYear['Hi'].sum() df4.insert(loc=8, column='H_sum', value=H_sum) # 计算A值 A = (6.75e-07)*np.power(H_sum,3) - (7.71e-05)*np.power(H_sum,2) + (1.792e-02)*H_sum + 0.49 df4.insert(loc=9, column='A', value=A) # 提取temp、H_sum、A用于计算PET temp = df4.temp.values H_sum = df4.H_sum.values A = df4.A.values # 计算PET PET = 16 * np.power((10*temp)/H_sum,A) df4.insert(loc=10, column='PET',value=PET) df5 = pd.DataFrame(df4) # concat 合并有相同字段名的dataframe df_all = pd.concat([df_all, df5],ignore_index=True) # 避免字段名重复写入,一般会做去重处理 data_list = df_all.drop_duplicates(keep='first') # 写出数据 df_all.to_excel('processdata/lianxi/鄂尔多斯PET.xlsx', index=False)