前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Python气象数据处理与绘图:泰勒图

Python气象数据处理与绘图:泰勒图

作者头像
郭好奇同学
发布2021-08-26 17:25:32
3K0
发布2021-08-26 17:25:32
举报
文章被收录于专栏:好奇心Log

1、前言

泰勒图可以全面直观地比较模拟的极端温度与观测的极端温度的一致性,它是由模拟场与观测场的空间相关系数、相对标准差及其中心化的均方根误差组成的极坐标图,中心化的均方根误差越接近0,空间相关系数和相对标准差越接近1,模式模拟能力越好。 需提前安装:xlsxwriter和SkillMetrics模块。

2、数据处理

导入模块

代码语言:javascript
复制
import matplotlib.pyplot as plt
from matplotlib import rcParams
import numpy as np
import pickle
import skill_metrics as sm
from sys import version_info

读取数据

代码语言:javascript
复制
def load_obj(name):
    # Load object from file in pickle format
    if version_info[0] == 2:
        suffix = 'pkl'
    else:
        suffix = 'pkl3'
    with open(name + '.' + suffix, 'rb') as f:
        return pickle.load(f) # Python2 succeeds

class Container(object):     
    def __init__(self, pred1, pred2, pred3, ref):
        self.pred1 = pred1
        self.pred2 = pred2
        self.pred3 = pred3
        self.ref = ref

3、绘制泰勒图

泰勒图1:

代码语言:javascript
复制
if __name__ == '__main__':
    # Set the figure properties (optional)
    rcParams["figure.figsize"] = [8.0, 6.4]
    rcParams['lines.linewidth'] = 1 # line width for plots
    rcParams.update({'font.size': 12}) # font size of axes text

    # Close any previously open graphics windows
    # ToDo: fails to work within Eclipse
    plt.close('all')

    # Read data from pickle file
    data = load_obj('/home/kesci/input/Talyor5298/taylor_data')

    # Calculate statistics for Taylor diagram
    # The first array element (e.g. taylor_stats1[0]) corresponds to the 
    # reference series while the second and subsequent elements
    # (e.g. taylor_stats1[1:]) are those for the predicted series.
    taylor_stats1 = sm.taylor_statistics(data.pred1,data.ref,'data')
    taylor_stats2 = sm.taylor_statistics(data.pred2,data.ref,'data')
    taylor_stats3 = sm.taylor_statistics(data.pred3,data.ref,'data')

    # Store statistics in arrays
    sdev = np.array([taylor_stats1['sdev'][0], taylor_stats1['sdev'][1], 
                     taylor_stats2['sdev'][1], taylor_stats3['sdev'][1]])
    crmsd = np.array([taylor_stats1['crmsd'][0], taylor_stats1['crmsd'][1], 
                      taylor_stats2['crmsd'][1], taylor_stats3['crmsd'][1]])
    ccoef = np.array([taylor_stats1['ccoef'][0], taylor_stats1['ccoef'][1], 
                      taylor_stats2['ccoef'][1], taylor_stats3['ccoef'][1]])

    '''
    Produce the Taylor diagram

    Note that the first index corresponds to the reference series for 
    the diagram. For example sdev[0] is the standard deviation of the 
    reference series and sdev[1:4] are the standard deviations of the 
    other 3 series. The value of sdev[0] is used to define the origin 
    of the RMSD contours. The other values are used to plot the points 
    (total of 3) that appear in the diagram.

    For an exhaustive list of options to customize your diagram, 
    please call the function at a Python command line:
    >> taylor_diagram
    '''
    sm.taylor_diagram(sdev,crmsd,ccoef)
    # Show plot
    plt.show()

泰勒图2:

代码语言:javascript
复制
if __name__ == '__main__':
    # Close any previously open graphics windows
    # ToDo: fails to work within Eclipse
    plt.close('all')
    # Read data from pickle file
    data = load_obj('/home/kesci/input/Talyor5298/Farmington_River_data')
    # Change number of data points to illustrate effect
    # of changing number of columns
    ncol = 2
    if ncol == 1:
        sdev = data.sdev[0:11]
        crmsd = data.crmsd[0:11]
        ccoef = data.ccoef[0:11]
        gageID = data.gageID[0:11]
    elif ncol == 2:
        sdev = data.sdev
        crmsd = data.crmsd
        ccoef = data.ccoef
        gageID = data.gageID
    else:
        sdev = data.sdev
        crmsd = data.crmsd
        ccoef = data.ccoef
        gageID = data.gageID
        sdev = np.append(sdev,data.sdev[1:11])
        crmsd = np.append(crmsd,data.crmsd[1:11])
        ccoef = np.append(ccoef,data.ccoef[1:11])
        gageID = gageID + data.gageID[1:11]

    # Specify labels for points in a cell array using gage ID.
    label = gageID

    # Must set figure size here to prevent legend from being cut off
    plt.figure(num=1, figsize=(8, 6))


    '''
    Produce the Taylor diagram

    Label the points and change the axis options for SDEV, CRMSD, and CCOEF.
    Increase the upper limit for the SDEV axis and rotate the CRMSD contour 
    labels (counter-clockwise from x-axis). Exchange color and line style
    choices for SDEV, CRMSD, and CCOEFF variables to show effect. Increase
    the line width of all lines. Suppress axes titles and add a legend.

    For an exhaustive list of options to customize your diagram, 
    please call the function at a Python command line:
    >> taylor_diagram
    '''
    sm.taylor_diagram(sdev,crmsd,ccoef, markerLabel = label, markerLabelColor = 'r', 
                      markerLegend = 'on', markerColor = 'r',
                      styleOBS = '-', colOBS = 'r', markerobs = 'o',
                      markerSize = 6, tickRMS = [0.0, 1.0, 2.0, 3.0],
                      tickRMSangle = 115, showlabelsRMS = 'on',
                      titleRMS = 'on', titleOBS = 'Ref', checkstats = 'on')
    # Show plot
    plt.show()

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2021-08-06,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 好奇心Log 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1、前言
  • 2、数据处理
  • 3、绘制泰勒图
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档