python晴雨TS评分

import random
import numpy as np
from scipy.interpolate import griddata


# sta_value = griddata(points, values, (staInfo['经度'], staInfo['纬度']), method='nearest') #模式数据最邻近插值到站点位置

def ts_score_function(sample_data, threshold=-1):
    sample_data = np.delete(sample_data, sample_data[:, 1] < threshold, 0)
    na = 0
    nb = 0
    nc = 0
    nd = 0
    for i in range(len(sample_data)):
        if sample_data[i, 0] > 0 and sample_data[i, 1] > 0:  # 降水预报正确次数
            na = na + 1
        elif sample_data[i, 0] == 0 and sample_data[i, 1] > 0:  # 降水空报次数
            nb = nb + 1
        elif sample_data[i, 0] > 0 and sample_data[i, 1] == 0:  # 降水漏报次数
            nc = nc + 1
        elif sample_data[i, 0] == 0 and sample_data[i, 1] == 0:  # 无降水预报正确次数
            nd = nd + 1
    ts_score = (na + nd) / (na + nb + nc + nd)
    return ts_score


if __name__ == '__main__':
    random_int_list1 = random.sample(range(0, 500), 100)  # 第一列模式数据
    random_int_list2 = random.sample(range(0, 500), 100)  # 第二列观测数据
    sample_data = np.vstack([np.array(random_int_list1), np.array(random_int_list2)]).T  # 随机生成测试数据

    reslut = ts_score_function(sample_data, 100)  # 调用函数示例

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值