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)  # 调用函数示例

你可能感兴趣的:(python,开发语言)