Python 基于百分位法批量确定站点极端降水事件阈值

Python 基于百分位法批量确定站点极端降水事件阈值

介绍

通常在定义极端事件中,我们采取绝对阈值法和相对阈值法。绝对阈值法就是我们规定某一定值,若该站点超过该值则判定发生极端事件。我国降水强度大致分为小雨、中雨、大雨和暴雨。其中,24h内降水量超过50mm统称为暴雨,我们就可以将50mm作为绝对阈值来识别暴雨事件。

而相对阈值法分为参数法与非参数法。非参数法目前最常见的是采用某个百分位值作为参考值,一旦超过该值即视为极端降水事件发生。

这里展示了通过百分位法来计算各个站点极端降水事件阈值的代码,仅供参考。

代码

导入库和数据

import pandas as pd
import math

#导入站点降水数据
#这里需要换成你站点数据的路径,我的是excel文件,可以根据你的文件类型进行替换
data =pd.read_excel('your_path/your_excel.xlsx')	
del data['Unnamed: 0']   #删除导出数据时产生的index 其他数据无需此行

获取站点列表

station = data['Station']
station_list = list(set(station))  #去除重复站点,获取站点列表
station_list = sorted(station_list) #这里对站点列表也进行了排序 可省略

数据预处理

由于百分位法是对降水量升序序列中降水量>0mm的序列片段进行百分位分析

data = data.drop(data[data['Pre'] < 0.1].index) #去除降水量小于0.1mm的数据
#这里创建一个DataFrame来储存后续结果
threshold = pd.DataFrame(columns=['Station', 'Threshold'])

利用循环批量计算

#利用循环批量计算逐个站点百分位法的降水阈值
for i in range(0,len(station_list)):
    data_station = data[(data['Station'] == station_list[i])]    #提取某一站号的降水量数据
    sorted_data_station = data_station.sort_values('Pre')   #按照降水数据从小到大排序
    sorted_data_station = sorted_data_station.reset_index()  #重置排序后的数据索引
    del sorted_data_station['index']   #删除转换出的旧的index列
    #设置百分位数
    percentile = 95	#这里根据需要替换数值
    #计算降水阈值
    threshold_index = math.ceil(percentile / 100 * len(sorted_data_station))    #利用ceil函数向上取最接近的整数
    station_threshold = sorted_data_station.iloc[threshold_index]['Pre']    #获取index所在行的降水量
    # 初始化一个空的 DataFrame
    threshold.loc[i] = {'Station': station_list[i], 'Threshold': station_threshold}
#将结果导出
threshold.to_excel('your_path/降水阈值(第95百分位).xlsx', index=True)

结果实例

这里展示了我导出的excel的一部分
在这里插入图片描述

  • 5
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值