meteva

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


点对面检验

<p>[TOC]</p> <pre><code class="language-python">%matplotlib inline %load_ext autoreload %autoreload 2 import meteva.base as meb import meteva.method as mem import numpy as np import pandas as pd import datetime</code></pre> <p>点对面检验是邻域检验方法中的一种。它在检验指标的选择和使用上和二分类检验并没有什么差别,前者的不同体现为判断观测或预报样本是否为正样本的方法的差异。在普通的二分类检验中,以短时强降水为例,一个站点是否记为发生了短时强降水,指向判断该点小时降水量是否大于20mm即可,但在点对面检验时,需要扫描站点附近半径r范围内的所有站点,当其中有一个点出现了大于20mm。 为此邻域检验的方法可以拆解成两个步骤: </p> <ul> <li>步骤1: 将根据观测或者预报场中要素值的空间分布,计算出每个站点上事件是发生了(记为1),还是没发生(记为0)。</li> <li>步骤2: 将步骤1的结果,采用二分类预报检验的检验指标进行检验。</li> </ul> <p>考虑到上面步骤2的所需的功能已经在有无预报检验中充分叙述,因此以下着重讲步骤1所需的功能</p> <h1>点对点要素转01</h1> <p>&lt;font face=&quot;黑体&quot; color=blue size = 5&gt;<strong>p2p_vto01(sta_all,threshold = 1e-30,compair = &quot;&gt;=&quot;)</strong>&lt;/font&gt; </p> <ul> <li>原始值:每个站点的值仅由该站点的观测值或诊断值</li> <li>事件实况:一个站点判断为事件发生,则记为1,否则记为0 在本函数中,sta_all里存储了原始的数据值,对于sta_all的每个站点,compair参数默认时,如果其大于等于阈值threshold,则该站点邻域实况记为1,否则记为0。</li> </ul> <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>&lt;font face=&quot;黑体&quot; color=blue size = 5&gt;sta_ob_all&lt;/font&gt;</strong></td> <td style="text-align: left;"><a href="https://www.showdoc.com.cn/meteva?page_id=3975600580125986">站点数据</a>,sta_ob_all 里也可以包含多个层次、时刻和时效的站点数据,当出现这种情况时,程序会自动将sta_all切割成单个层次、时刻和时效的站点数据后,转换成01后重新拼接在一起</td> </tr> <tr> <td style="text-align: left;"><strong>threshold</strong></td> <td style="text-align: left;">当该参数为浮点数时,意味着所有站点数据采用相同的阈值。如果希望阈值随着时空变化,则threshold应该是站点数据形式,阈值的取值可以随着level,time,dtime,id四个维度而变化,当阈值不随某些维度变化时,在theshold在这些列的坐标值需设置为np.nan,或mem.IV</td> </tr> <tr> <td style="text-align: left;"><strong>compair</strong></td> <td style="text-align: left;">比较方法,可选项包括&quot;&gt;=&quot;,&quot;&gt;&quot;,&quot;&lt;=&quot;,&quot;&lt;&quot;, 是要素原始值和阈值对比的方法,默认方法为&quot;&gt;=&quot;,即原始值大于等于阈值记为1,否则记为0,当compair 为&quot;&lt;=&quot;时,原始值小于等于阈值的站点记为1, 这在基于能见度标记大雾事件时可以用到</td> </tr> <tr> <td style="text-align: left;">&lt;font face=&quot;黑体&quot; color=blue size=5&gt;return&lt;/font&gt;</td> <td style="text-align: left;">站点数据,其行数和sta_all一致,而数据列只为0或者1</td> </tr> </tbody> </table> <p><strong>调用示例:</strong> </p> <pre><code class="language-python">station0 = meb.read_station(meb.station_国家站) rain01 = meb.read_stadata_from_micaps3(r&amp;quot;H:\test_data\input\meb\rain01.m3.txt&amp;quot;,station = station0) clev,cmap = meb.tool.color_tools.clev_cmap_rain_1h() meb.tool.plot_tools.scatter_sta(rain01,clevs=clev,cmap=cmap)</code></pre> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/5cdc3ad2ea18a227bee9b64fe24aee4d?showdoc=.jpg" alt="" /></p> <pre><code class="language-python">heavy_rain = mem.space.p2p_vto01(rain01,threshold=20) meb.tool.plot_tools.scatter_sta(heavy_rain)</code></pre> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/c277e43c04ce81d9c5aaf6044f8aed24?showdoc=.jpg" alt="" /></p> <pre><code class="language-python">threshold_ob = station0.copy() threshold_ob[&amp;quot;level&amp;quot;] = np.nan threshold_ob[&amp;quot;time&amp;quot;] = np.nan threshold_ob[&amp;quot;dtime&amp;quot;] = np.nan threshold_ob.loc[threshold_ob[&amp;quot;lon&amp;quot;] &amp;gt; 110,&amp;quot;data0&amp;quot;] = 40 threshold_ob.loc[threshold_ob[&amp;quot;lon&amp;quot;] &amp;lt;= 110,&amp;quot;data0&amp;quot;] = 0.1 print(threshold_ob) # 通过一个站点数据形式,对不同站点设置有差异的阈值</code></pre> <pre><code> level time dtime id lon lat data0 0 NaN NaN NaN 50136 122.52 52.97 40.0 1 NaN NaN NaN 50137 122.37 53.47 40.0 2 NaN NaN NaN 50246 124.72 52.35 40.0 3 NaN NaN NaN 50247 123.57 52.03 40.0 4 NaN NaN NaN 50349 124.40 51.67 40.0 ... ... ... ... ... ... ... ... 2406 NaN NaN NaN 59945 109.70 18.65 0.1 2407 NaN NaN NaN 59948 109.58 18.22 0.1 2408 NaN NaN NaN 59951 110.33 18.80 40.0 2409 NaN NaN NaN 59954 110.03 18.55 40.0 2410 NaN NaN NaN 59981 112.33 16.83 40.0 [2411 rows x 7 columns]</code></pre> <pre><code class="language-python">heavy_rain =mem.p2p_vto01(rain01,threshold=threshold_ob) meb.tool.plot_tools.scatter_sta(heavy_rain)</code></pre> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/1b500e82a9152892a381638c6d469de7?showdoc=.jpg" alt="" /></p> <h1>点对面要素转01</h1> <p>&lt;font face=&quot;黑体&quot; color=blue size = 5&gt;<strong>p2a_vto01(sta_ob_all,r = 40,threshold = 1e-30)</strong>&lt;/font&gt; </p> <ul> <li>原始值:每个站点的值仅由该站点的观测值或诊断值</li> <li>事件实况:一个站点判断为事件发生,则记为1,否则记为0。在点对面算法中一个站点值,是从该站点附近半径r范围内所有站点的集合中统计出来的,在强对流天气的邻域检验方法中,判断一个点上强对流实况为发生,意味着,该站点附近40km内所有站点中1小时降水量最大值大于20mm。</li> </ul> <p>在本函数中,sta_all里存储了原始值,会采用<strong>点对点要素转01</strong>的功能将站点值先转为01,在查询其附近半径r范围内的所有站点数据是否存在取值为1的站点,如果存在则该站点邻域实况记为1,否则记为0。</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>&lt;font face=&quot;黑体&quot; color=blue size = 5&gt;sta_ob_all&lt;/font&gt;</strong></td> <td style="text-align: left;"><a href="https://www.showdoc.com.cn/meteva?page_id=3975600580125986">站点数据</a>,sta_ob_all 里也可以包含多个层次、时刻和时效的站点数据,当出现这种情况时,程序会自动将sta_all切割成单个层次、时刻和时效的站点数据后,转换成01后重新拼接在一起</td> </tr> <tr> <td style="text-align: left;"><strong>r</strong></td> <td style="text-align: left;">邻域判断时的扫描半径</td> </tr> <tr> <td style="text-align: left;"><strong>threshold</strong></td> <td style="text-align: left;">当该参数为浮点数时,意味着所有站点数据采用相同的阈值。如果希望阈值随着时空变化,则threshold应该是站点数据形式,阈值的取值可以随着level,time,dtime,id四个维度而变化,当阈值不随某些维度变化时,在theshold在这些列的坐标值需设置为np.nan,或mem.IV</td> </tr> <tr> <td style="text-align: left;"><strong>compair</strong></td> <td style="text-align: left;">比较方法,可选项包括&quot;&gt;=&quot;,&quot;&gt;&quot;,&quot;&lt;=&quot;,&quot;&lt;&quot;, 是要素原始值和阈值对比的方法,默认方法为&quot;&gt;=&quot;,即原始值大于等于阈值记为1,否则记为0,当compair 为&quot;&lt;=&quot;时,原始值小于等于阈值的站点记为1, 这在基于能见度标记大雾事件时可以用到</td> </tr> <tr> <td style="text-align: left;">&lt;font face=&quot;黑体&quot; color=blue size=5&gt;return&lt;/font&gt;</td> <td style="text-align: left;">站点数据,其行数和sta_all一致,而数据列只为0或者1</td> </tr> </tbody> </table> <p><strong>调用示例:</strong> </p> <pre><code class="language-python">heavy_rain = mem.space.p2a_vto01(rain01,threshold=20) meb.tool.plot_tools.scatter_sta(heavy_rain)</code></pre> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/d8097d1caaa83e2dcf3e39cd6a61a768?showdoc=.jpg" alt="" /></p> <pre><code class="language-python">heavy_rain = mem.space.p2a_vto01(rain01,threshold=threshold_ob) meb.tool.plot_tools.scatter_sta(heavy_rain) #threshold_ob 在以110度以东的阈值高于前面给定的固定阈值,因此在该区域,判定为短时强降水发生的点较上例更少 #threshold_ob 在以110度以东的阈值低于前面给定的固定阈值,因此在该区域,判定为短时强降水发生的点较上例更多</code></pre> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/09add0f080210f79d86db4a3f2d5df4e?showdoc=.jpg" alt="" /></p> <pre><code class="language-python">rain01_next_hour = rain01.copy() rain01_next_hour[&amp;quot;time&amp;quot;] += datetime.timedelta(hours = 1) sta_ob_all = pd.concat([rain01,rain01_next_hour],axis = 0) print(sta_ob_all)</code></pre> <pre><code> level time dtime id lon lat data0 0 0 2020-07-01 08:00:00 0 50136 122.52 52.97 0.000000 1 0 2020-07-01 08:00:00 0 50137 122.37 53.47 0.000000 2 0 2020-07-01 08:00:00 0 50246 124.72 52.35 0.000000 3 0 2020-07-01 08:00:00 0 50247 123.57 52.03 0.000000 4 0 2020-07-01 08:00:00 0 50349 124.40 51.67 0.000000 ... ... ... ... ... ... ... ... 2406 0 2020-07-01 09:00:00 0 59945 109.70 18.65 18.900000 2407 0 2020-07-01 09:00:00 0 59948 109.58 18.22 0.700000 2408 0 2020-07-01 09:00:00 0 59951 110.33 18.80 12.700000 2409 0 2020-07-01 09:00:00 0 59954 110.03 18.55 22.799999 2410 0 2020-07-01 09:00:00 0 59981 112.33 16.83 8.300000 [4822 rows x 7 columns]</code></pre> <pre><code class="language-python">heavy_rain = mem.p2a_vto01(sta_ob_all,threshold=20) print(heavy_rain) # sta_ob_all 中包含了多个时刻的观测,生成的邻域实况和sta_ob_all 列表形式一致。</code></pre> <pre><code> level time dtime id lon lat amax 0 0 2020-07-01 08:00:00 0 50136 122.52 52.97 0 1 0 2020-07-01 08:00:00 0 50137 122.37 53.47 0 2 0 2020-07-01 08:00:00 0 50246 124.72 52.35 0 3 0 2020-07-01 08:00:00 0 50247 123.57 52.03 0 4 0 2020-07-01 08:00:00 0 50349 124.40 51.67 0 ... ... ... ... ... ... ... ... 2406 0 2020-07-01 09:00:00 0 59945 109.70 18.65 1 2407 0 2020-07-01 09:00:00 0 59948 109.58 18.22 0 2408 0 2020-07-01 09:00:00 0 59951 110.33 18.80 0 2409 0 2020-07-01 09:00:00 0 59954 110.03 18.55 1 2410 0 2020-07-01 09:00:00 0 59981 112.33 16.83 0 [4822 rows x 7 columns]</code></pre> <pre><code class="language-python"></code></pre>

页面列表

ITEM_HTML