meteva

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


Example

<p>[TOC]</p> <p>Meteva is a modular verification Python package, which integrates calculation algorithms of various commonly used verification indexes (such as me, RMSE, TS, etc.).Advanced users can organize data and call these algorithms to complete verification calculation and draw results, but it may be difficult for entry-level users (especially those who are not proficient in Python) to organize data and draw results. In this case, Users can learn from this article as an introduction to meteva.</p> <pre><code class="language-python">import meteva.base as meb # this module is for IO、data transformation and so on import meteva.method as mem # this module contains verification algorithm import meteva.product as mpd # this module contains veification tools import numpy as np import datetime import copy import pandas as pd</code></pre> <p>The veification process with meteva can separated into two parts:</p> <ul> <li>part1: Data Collection</li> <li>part2: Verification and Analysis </li> </ul> <h1>Data Collection</h1> <pre><code class="language-python">################### below is the part of data collection code example #set conserned time period time_begin= datetime.datetime(2019,7,1,8,0) time_end = datetime.datetime(2019,8,1,8,0) #read station list station = meb.read_stadata_from_micaps3(r"H:\Example_data\ob\temp_2m\BT19070102.000") #set default value station.iloc[:,-1] = meb.IV ##Collect observation dir_ob = r"H:\Example_data\ob\temp_2m\BTYYMMDDHH.000" # OBS data path patten sta_list = [] time0 = time_begin time_end_ob = time_end + datetime.timedelta(hours = 72) while time0 &lt; time_end_ob: path = meb.get_path(dir_ob,time0) # generate OBS data path from pattern and time #read OBS data form Micaps3 format file sta = meb.read_stadata_from_micaps3(path,station = station,time = time0,dtime = 0,level = 0,data_name = "OBS",show = True) sta_list.append(sta) # add data to list time0 += datetime.timedelta(hours = 3) # move to next time ob_sta_all = meb.concat(sta_list) #contcat OBS data list into a DataFrame #Collect ECMWF prediction dir_ec = r"H:\Example_data\ecmwf\temp_2m\YYMMDD\BTYYMMDDHH.TTT" #ECMWF data path patten sta_list =[] time0 = time_begin while time0 &lt; time_end: for dh in range(0,73,3): path = meb.get_path(dir_ec,time0,dh) # generate ECMWF data path from pattern,time and valid time #read ECMWF data form Micaps4 format file grd = meb.read_griddata_from_micaps4(path,show = False) if grd is not None: sta = meb.interp_gs_linear(grd,station) #interpolate grid data to station meb.set_stadata_coords(sta,time = time0,dtime = dh,level = 0) #add time,valid time and level informations to data meb.set_stadata_names(sta,["ECMWF"]) sta_list.append(sta) time0 += datetime.timedelta(hours = 12) ec_sta_all = meb.concat(sta_list) #concat ECMWF data list int a DataFrame #Collect GRAPES prediction dir_grapes = r"H:\Example_data\grapes\temp_2m\YYMMDD\BTYYMMDDHH.TTT" sta_list =[] time0 = time_begin while time0 &lt; time_end: for dh in range(0,73,3): path = meb.get_path(dir_grapes,time0,dh) # generate GRAPES data path from pattern,time and valid time #read GRAPES data form Micaps4 format file grd = meb.read_griddata_from_micaps4(path,show = False) if grd is not None: sta = meb.interp_gs_linear(grd,station) #interpolate grid data to station meb.set_stadata_coords(sta,time = time0,dtime = dh,level = 0) #add time,valid time and level informations to data meb.set_stadata_names(sta,["GRAPES"]) sta_list.append(sta) time0 += datetime.timedelta(hours = 12) grapes_sta_all = meb.concat(sta_list) #Concat GRAPES data list into a DataFrame #Combine obs and fst data into a DataFrame, based on the level,time, valid time and Id of station. sta_all = meb.combine_on_obTime_id(ob_sta_all,[ec_sta_all,grapes_sta_all],need_match_ob=True) sta_all.to_hdf(r"H:\Example_data\sta_all.h5","df") # output data-collection into file ###################below is the part of data collection code example</code></pre> <pre><code>success read from H:\Example_data\ob\temp_2m\BT19070108.000 success read from H:\Example_data\ob\temp_2m\BT19070111.000 success read from H:\Example_data\ob\temp_2m\BT19070114.000 success read from H:\Example_data\ob\temp_2m\BT19070117.000 ... ... success read from H:\Example_data\ob\temp_2m\BT19080405.000</code></pre> <h1>Verification and Analysis</h1> <pre><code class="language-python"># load data-collection from file sta_all = pd.read_hdf(r"H:\Example_data\sta_all.h5") print(sta_all)</code></pre> <pre><code> level time dtime id lon lat OBS ECMWF \ 0 0 2019-07-01 08:00:00 0 54398 116.6 40.1 25.8 24.724 1 0 2019-07-01 08:00:00 0 54410 116.1 40.6 18.9 20.284 2 0 2019-07-01 08:00:00 0 54416 116.9 40.4 25.1 22.864 3 0 2019-07-01 08:00:00 0 54419 116.6 40.4 27.5 21.796 4 0 2019-07-01 08:00:00 0 54499 116.2 40.2 27.5 23.076 ... ... ... ... ... ... ... ... ... 9187 0 2019-07-31 20:00:00 72 54410 116.1 40.6 18.8 21.556 9188 0 2019-07-31 20:00:00 72 54416 116.9 40.4 26.7 24.960 9189 0 2019-07-31 20:00:00 72 54419 116.6 40.4 27.0 22.920 9190 0 2019-07-31 20:00:00 72 54499 116.2 40.2 29.3 23.056 9191 0 2019-07-31 20:00:00 72 54412 116.6 40.7 25.4 21.640 GRAPES 0 23.844 1 21.740 2 22.704 3 23.136 4 23.736 ... ... 9187 19.968 9188 23.404 9189 23.056 9190 22.568 9191 21.232 [9192 rows x 9 columns]</code></pre> <h2>Example1</h2> <p>the below line of code is used for caculation the mean absolute error group by valid time and plotting the result,<br /> where:</p> <ul> <li>mem.mae is the function name of mean absolute error in meteva</li> <li>g=&quot;dtime&quot; means group by valid time</li> <li>plot = &quot;bar&quot; means plot with format of bar </li> </ul> <pre><code class="language-python">result = mpd.score(sta_all,mem.mae,g= "dtime",plot = "bar") </code></pre> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/b995f01fcc78ac497767a6add5bd96a1" alt="" /></p> <h2>Example2</h2> <p>the below line of code is used for caculation the root mean square error grouped by time and plotting the result,<br /> where:</p> <ul> <li>mem.rmse is the function name of root mean square error in meteva</li> <li>g=&quot;time&quot; means group by time</li> <li>plot = &quot;line&quot; means plot with format of line </li> </ul> <pre><code class="language-python">result = mpd.score(sta_all,mem.rmse,g= "time",plot = "line") </code></pre> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/7445afd0349dd23014e61234a118b10a" alt="" /></p> <h2>Example3</h2> <p>the below line of code is used for caculation the threat score grouped by hour of time and plotting the result,<br /> where:</p> <ul> <li>mem.ts is the function name of threat score in meteva</li> <li>grade_list = [30,35,37,40], is set to verify for kinds of threshold at the same time </li> <li>g=&quot;hour&quot; means group by hour of time</li> <li>plot = &quot;bar&quot; means plot with format of bar </li> </ul> <pre><code class="language-python">result = mpd.score(sta_all,mem.ts,grade_list = [30,35,37,40],g = "hour",plot = "bar") </code></pre> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/e943e904aab381678eb58972b4c882a5" alt="" /></p> <h2>Example4</h2> <p>the below line of code is used for caculation mean errof group by time and valid time and plotting the result,<br /> where:</p> <ul> <li>mem.me is the function name of mean error in meteva</li> <li>x_y=&quot;time_dtime&quot; is used for setting the x-axis and y-axis</li> </ul> <pre><code class="language-python">result = mpd.score_tdt(sta_all,mem.me,x_y = "time_dtime") </code></pre> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/9374750a7de98a1b582c5bccea8630a3" alt="" /></p> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/f2f8a7a6e31672a3af0117eadf3f18c8" alt="" /></p> <h2>Example5</h2> <p>the below line of code is used for statistics and showing the mean error distribution<br /> where:</p> <ul> <li>mem.me is the function name of mean error in meteva</li> <li>subplot = &quot;member&quot; is set to contian results of different model in one figure </li> <li>ncol is the column number of subplots</li> <li>width is the width of fig.</li> </ul> <pre><code class="language-python">result = mpd.score_id(sta_all,mem.me,subplot = "member",ncol = 2,width = 10) </code></pre> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/6844bfd3c873a6bf8f736b999163d950" alt="" /></p> <h2>Example6</h2> <p>the below line of code is used for plotting regress relation between obs. and fst.<br /> where:</p> <ul> <li>mem.scatter_regress is the function name regress map in meteva</li> </ul> <pre><code class="language-python">result = mpd.plot(sta_all,mem.scatter_regress) </code></pre> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=3f1b0920ff4b953cbbf6445b567ea62b" alt="" /></p> <h2>Example7</h2> <p>the below line of code is used for plotting frequency_histogram of obs. and fst.<br /> where:</p> <ul> <li>mem.frequency_histogram is the function name in meteva</li> <li>grade_list is the grade setting</li> </ul> <pre><code class="language-python">result = mpd.plot(sta_all,mem.frequency_histogram,grade_list = np.arange(10,40,5).tolist()) </code></pre> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/89ea336ed143fea98dae0cac7f42493f" alt="" /></p> <p>Above codes are some expample of using meteva, only little part funtions and parameters is show above, please find more details in other pages. </p>

页面列表

ITEM_HTML