meteva

提供气象产品检验相关python程序


表格型检验产品

<p>[TOC]</p> <pre><code class="language-python">%matplotlib inline %load_ext autoreload %autoreload 2 import meteva.method as mem import numpy as np</code></pre> <pre><code>The autoreload extension is already loaded. To reload it, use: %reload_ext autoreload</code></pre> <h1>列联表</h1> <p><strong><font face="黑体" color=blue size = 5>contingency_table_yesorno(ob, fo,grade_list=[1e-30],compare = &quot;&gt;=&quot;, member_list=None, save_path=None)</font></strong><br /> 以矩阵形式返回列联表。<br /> 一分为二的预测说:“是的,将会发生一个事件”,或者“否,该事件不会发生”。雨雾预报是是/否预报的常见示例。对于某些应用,可以指定阈值以分隔“是”和“否”,例如,风速大于50节。</p> <p>为了验证这种类型的预测,我们从列联表开始,该表显示“是”和“否”的预测和出现的频率(样本数)。预测(是或否)和观测值(是或否)的四种组合称为联合分布:</p> <pre><code> 命中-事件预测发生,并且确实发生了 漏报-事件预测未发生,但确实发生了 空报-发生事件预测,但未发生 正确的否定-事件预测不会发生,也不会发生</code></pre> <p>列联表的左下方给出了观测和预测的发生与未发生的总数,称为边际分布。<br /> <img src="https://www.showdoc.cc/server/api/common/visitfile/sign/5dafc73c2712497a55887d6081f4c985?showdoc=.jpg" alt="" /></p> <table> <thead> <tr> <th style="text-align: left;">参数</th> <th style="text-align: left;">说明</th> </tr> </thead> <tbody> <tr> <td style="text-align: left;"><strong><font face="黑体" color=blue size = 5>ob</font></strong></td> <td style="text-align: left;">实况数据, 任意维numpy数组</td> </tr> <tr> <td style="text-align: left;"><strong><font face="黑体" color=blue size = 5>fo</font></strong></td> <td style="text-align: left;">fo比Ob.shape多一维或者保持一致,fo.shape低维与ob.shape保持一致</td> </tr> <tr> <td style="text-align: left;"><strong>grade_list</strong></td> <td style="text-align: left;">阈值列表</td> </tr> <tr> <td style="text-align: left;"><strong>compare</strong></td> <td style="text-align: left;">比较方法,可选项包括&quot;&gt;=&quot;,&quot;&gt;&quot;,&quot;&lt;=&quot;,&quot;&lt;&quot;, 是要素原始值和阈值对比的方法,默认方法为&quot;&gt;=&quot;,即原始值大于等于阈值记为1,否则记为0,当compare为&quot;&lt;=&quot;时,原始值小于等于阈值的站点记为1, 这在基于能见度标记大雾事件、低温事件或降温事件等场景中可以用到</td> </tr> <tr> <td style="text-align: left;"><strong>member_list</strong></td> <td style="text-align: left;">个预报成员的名称列表</td> </tr> <tr> <td style="text-align: left;"><strong>save_path</strong></td> <td style="text-align: left;">如果该参数不为None,则混淆矩阵将会以excel文件形式保存到指定文件</td> </tr> <tr> <td style="text-align: left;"><font face="黑体" color=blue size=5>return</font></td> <td style="text-align: left;">如果Fo和Ob的shape一致(即只有一种预报),返回内容为包含混淆矩阵的3维数组, 返回结果的shape为 (等级数,3,3);如果Fo比Ob高出一维,则返回3维数组,shape为(预报成员数, 等级数,3,3)</td> </tr> </tbody> </table> <p><strong>调用示例:</strong> </p> <pre><code class="language-python">ob = (np.random.rand(20) * 10).astype(np.int8) #随机生成数据用于测试 fo = (np.random.rand(2,20) * 10).astype(np.int8) grade_list = [3,5] #设置检验等级列表 member_list = ["ECMWF","GRAPES"] #设置预报成员名称</code></pre> <pre><code class="language-python">ob #观测数据内容</code></pre> <pre><code>array([4, 7, 9, 1, 9, 4, 7, 8, 1, 5, 7, 1, 5, 0, 2, 9, 5, 2, 2, 7], dtype=int8)</code></pre> <pre><code class="language-python">fo #预报数据内容</code></pre> <pre><code>array([[9, 4, 9, 8, 3, 0, 8, 5, 8, 0, 3, 3, 8, 6, 3, 8, 1, 3, 1, 5], [1, 6, 5, 1, 0, 0, 2, 3, 1, 0, 1, 7, 8, 0, 6, 3, 0, 0, 9, 2]], dtype=int8)</code></pre> <pre><code class="language-python">#仅输入一个成员的预报,即输入的预报数据和观测数据shape一致 result = mem.contingency_table_yesorno(ob,fo[0,:], save_path = r"H:\test_data\output\method\yes_or_no\table\ct1.xlsx")</code></pre> <pre><code>列联表已以excel表格形式保存至H:\test_data\output\method\yes_or_no\table\ct1.xlsx</code></pre> <pre><code class="language-python">result.shape #单个预报成员,单个等级情况下返回的结果的shape</code></pre> <pre><code>(1, 3, 3)</code></pre> <p>运行结果excel表格的截图将是如下样式: <img src="https://www.showdoc.cc/server/api/common/visitfile/sign/778cb2616efc0fffaffa4c34ba063e31?showdoc=.jpg" alt="" /></p> <pre><code class="language-python">#输入的预报数据比观测数据高一维,同时检验多个预报 result = mem.contingency_table_yesorno(ob,fo,member_list = member_list, save_path = r"H:\test_data\output\method\yes_or_no\table\ct2.xlsx")</code></pre> <pre><code>列联表已以excel表格形式保存至H:\test_data\output\method\yes_or_no\table\ct2.xlsx</code></pre> <pre><code class="language-python">result.shape #多个预报,单个等级时返回结果的shape</code></pre> <pre><code>(2, 1, 3, 3)</code></pre> <p>运行结果excel表格的截图将是如下样式,不同预报将位于不同的sheet中 <img src="https://www.showdoc.cc/server/api/common/visitfile/sign/645f4bde575e0d0c2e5d507093327792?showdoc=.jpg" alt="" /></p> <pre><code class="language-python">#多个预报,多个等级的检验 result = mem.contingency_table_yesorno(ob,fo,grade_list=grade_list,member_list = member_list, save_path = r"H:\test_data\output\method\yes_or_no\table\ct3.xlsx")</code></pre> <pre><code>列联表已以excel表格形式保存至H:\test_data\output\method\yes_or_no\table\ct3.xlsx</code></pre> <pre><code class="language-python">result.shape #多个预报多个等级时返回结果的shape</code></pre> <pre><code>(2, 2, 3, 3)</code></pre> <p>运行结果excel表格的截图将是如下样式,不同预报和等级组合成多个sheet <img src="https://www.showdoc.cc/server/api/common/visitfile/sign/9b012216126e19d367bc0ca7008608df?showdoc=.jpg" alt="" /></p>

页面列表

ITEM_HTML