Skip to content

Commit 7b6c991

Browse files
committed
Complete the tutorial materials.
1 parent 8a1477c commit 7b6c991

8 files changed

+424
-192
lines changed

01_retrieve_micaps_data.ipynb

+82-80
Large diffs are not rendered by default.

02_probability_matched.ipynb

+238-39
Large diffs are not rendered by default.

03_frequency-matching.ipynb

+39-25
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
},
3939
{
4040
"cell_type": "code",
41-
"execution_count": 2,
41+
"execution_count": 11,
4242
"id": "3656786a-88f2-4a88-9ec8-80bbf3789f05",
4343
"metadata": {},
4444
"outputs": [],
@@ -53,7 +53,9 @@
5353
"import pandas as pd\n",
5454
"import cartopy.crs as ccrs\n",
5555
"import matplotlib as mpl\n",
56-
"import matplotlib.pyplot as plt"
56+
"import matplotlib.pyplot as plt\n",
57+
"\n",
58+
"from nmc_met_base.qpf_cal import cum_freq, cfd_match"
5759
]
5860
},
5961
{
@@ -99,7 +101,7 @@
99101
},
100102
{
101103
"cell_type": "code",
102-
"execution_count": 65,
104+
"execution_count": 3,
103105
"id": "d9672e48-12b7-4c30-bb3b-3ce310caad2b",
104106
"metadata": {},
105107
"outputs": [
@@ -143,7 +145,7 @@
143145
},
144146
{
145147
"cell_type": "code",
146-
"execution_count": 67,
148+
"execution_count": 4,
147149
"id": "8ee51932-5859-4ea2-bf39-cdd35884cf84",
148150
"metadata": {},
149151
"outputs": [
@@ -274,7 +276,7 @@
274276
},
275277
{
276278
"cell_type": "code",
277-
"execution_count": 81,
279+
"execution_count": 5,
278280
"id": "4a0cc4d3-afe6-47fa-834a-0c0abcf2a6de",
279281
"metadata": {},
280282
"outputs": [],
@@ -293,7 +295,7 @@
293295
},
294296
{
295297
"cell_type": "code",
296-
"execution_count": 82,
298+
"execution_count": 8,
297299
"id": "c069a88e-76f9-4bf0-9a8a-c99c22c804b1",
298300
"metadata": {},
299301
"outputs": [],
@@ -306,7 +308,7 @@
306308
},
307309
{
308310
"cell_type": "code",
309-
"execution_count": 94,
311+
"execution_count": 9,
310312
"id": "719def2a-364f-44e7-9f71-8ceb594c74c5",
311313
"metadata": {},
312314
"outputs": [
@@ -398,7 +400,7 @@
398400
},
399401
{
400402
"cell_type": "code",
401-
"execution_count": null,
403+
"execution_count": 12,
402404
"id": "621f24b6-e3bb-48b2-99af-ae0daa31d6bf",
403405
"metadata": {},
404406
"outputs": [],
@@ -425,7 +427,7 @@
425427
},
426428
{
427429
"cell_type": "code",
428-
"execution_count": 92,
430+
"execution_count": 14,
429431
"id": "6f9acf80-ecc2-478f-abed-d84929a2794c",
430432
"metadata": {},
431433
"outputs": [
@@ -439,7 +441,7 @@
439441
],
440442
"source": [
441443
"with np.printoptions(precision=3, suppress=True):\n",
442-
" print(cfd_match([0, 0.1, 2, 6, 15, 52, 100, 130, 203.], obs_cdf, fct_cdf, bins))"
444+
" print(cfd_match([0, 0.1, 2, 6, 15, 52, 100, 130, 203.], obs_cfd, fct_cfd, bins))"
443445
]
444446
},
445447
{
@@ -452,7 +454,7 @@
452454
},
453455
{
454456
"cell_type": "code",
455-
"execution_count": 95,
457+
"execution_count": 16,
456458
"id": "da02eb03-322a-490e-89b0-4b261d20af13",
457459
"metadata": {},
458460
"outputs": [
@@ -482,7 +484,7 @@
482484
"data['FCST'] = data['FCST'].astype(float)\n",
483485
"\n",
484486
"# adjust the forecast values\n",
485-
"fct_cal = cfd_match(data['FCST'], obs_cdf, fct_cdf, bins)\n",
487+
"fct_cal = cfd_match(data['FCST'], obs_cfd, fct_cfd, bins)\n",
486488
"\n",
487489
"# calculate the calibrated forecast and observation CFD\n",
488490
"obs_cfd, bins = cum_freq(data['OBS'])\n",
@@ -507,9 +509,21 @@
507509
"\n",
508510
"分位值映射是另一种较为常用的降水量级订正方法,不仅用于天气模式(Bremnes,2007),也多用于气候模式(Maraun,2013)。分位值映射具有与频率匹配方法相同的两个步骤,主要不同点在于其采用降水样本的分位值分布曲线。Maraun(2013)指出当观测数据的分辨率远高于预报数据时,分位值映射还起到将低分辨预报转换为高分辨率的功能,但该降尺度作用会使得校正后降水序列的时空结构歪曲(如区域平均的极端值被过高估计,降水变化趋势受到影响等);为避免这些问题,需要加入随机偏差订正。Cannon等(2015)进一步引入分位差值映射来确保订正后降水时间序列的变化趋势不变,并将单变量的分位值映射拓展到多变量(降水和温度)协同订正。Hamill等(2017)以分位值映射方法为基础,发展多中心集合模式的降水概率预报后处理技术,得到的结果表现出更高的预报技巧和可靠性,同时保留了解析度和空间分布细节。\n",
509511
"\n",
510-
"<img src=\"./images/quantile_mapping.png\" alt=\"image\" style=\"height: 600px;\">"
512+
"<img src=\"./images/quantile_mapping.png\" alt=\"image\" style=\"height: 600px;\"> \n",
513+
"<div id=\"images\">\n",
514+
"<img src=\"./images/qmap_raw.png\" alt=\"image\" style=\"height: 300px;\"> \n",
515+
"<img src=\"./images/qmap_cal.png\" alt=\"image\" style=\"height: 300px;\"> \n",
516+
"</div> "
511517
]
512518
},
519+
{
520+
"cell_type": "code",
521+
"execution_count": null,
522+
"id": "4063d9bf-56eb-430a-a4e2-777d4c7a52ef",
523+
"metadata": {},
524+
"outputs": [],
525+
"source": []
526+
},
513527
{
514528
"cell_type": "markdown",
515529
"id": "620027cf-844c-4b4e-8631-9101806dc887",
@@ -537,7 +551,7 @@
537551
},
538552
{
539553
"cell_type": "code",
540-
"execution_count": 3,
554+
"execution_count": 17,
541555
"id": "88ded8bf-2c07-422a-b61f-63563c1f1117",
542556
"metadata": {},
543557
"outputs": [],
@@ -551,7 +565,7 @@
551565
},
552566
{
553567
"cell_type": "code",
554-
"execution_count": 4,
568+
"execution_count": 18,
555569
"id": "aaa5d04b-856b-461b-9566-fd335209dcba",
556570
"metadata": {},
557571
"outputs": [],
@@ -569,7 +583,7 @@
569583
},
570584
{
571585
"cell_type": "code",
572-
"execution_count": 5,
586+
"execution_count": 19,
573587
"id": "9a6f827b-f898-4af7-8aa8-1ae05ecd8948",
574588
"metadata": {},
575589
"outputs": [
@@ -688,7 +702,7 @@
688702
"[10957 rows x 3 columns]"
689703
]
690704
},
691-
"execution_count": 5,
705+
"execution_count": 19,
692706
"metadata": {},
693707
"output_type": "execute_result"
694708
}
@@ -699,7 +713,7 @@
699713
},
700714
{
701715
"cell_type": "code",
702-
"execution_count": 6,
716+
"execution_count": 20,
703717
"id": "9e60345a-8f08-439b-9ae3-6357037f0319",
704718
"metadata": {},
705719
"outputs": [
@@ -818,7 +832,7 @@
818832
"[10799 rows x 3 columns]"
819833
]
820834
},
821-
"execution_count": 6,
835+
"execution_count": 20,
822836
"metadata": {},
823837
"output_type": "execute_result"
824838
}
@@ -829,7 +843,7 @@
829843
},
830844
{
831845
"cell_type": "code",
832-
"execution_count": 7,
846+
"execution_count": 21,
833847
"id": "7aafc2ff-9f12-4b4d-afd2-9526659b72c4",
834848
"metadata": {},
835849
"outputs": [],
@@ -841,7 +855,7 @@
841855
},
842856
{
843857
"cell_type": "code",
844-
"execution_count": 8,
858+
"execution_count": 22,
845859
"id": "dfb6f28f-0e03-45f7-84c6-2c0c27ce2824",
846860
"metadata": {},
847861
"outputs": [
@@ -894,7 +908,7 @@
894908
},
895909
{
896910
"cell_type": "code",
897-
"execution_count": 9,
911+
"execution_count": 23,
898912
"id": "28523ba9-78f1-44a4-b92c-4afcea8f213b",
899913
"metadata": {},
900914
"outputs": [
@@ -913,7 +927,7 @@
913927
},
914928
{
915929
"cell_type": "code",
916-
"execution_count": 10,
930+
"execution_count": 24,
917931
"id": "3e815eb7-8f8e-47eb-bf28-84a872aa1a39",
918932
"metadata": {},
919933
"outputs": [],
@@ -927,7 +941,7 @@
927941
},
928942
{
929943
"cell_type": "code",
930-
"execution_count": 11,
944+
"execution_count": 25,
931945
"id": "bdb5b674-088b-4d2e-abad-dfa35bcde67c",
932946
"metadata": {},
933947
"outputs": [
@@ -957,7 +971,7 @@
957971
},
958972
{
959973
"cell_type": "code",
960-
"execution_count": 12,
974+
"execution_count": 26,
961975
"id": "39fc88cc-acaa-4db4-ae43-18853a8b6528",
962976
"metadata": {},
963977
"outputs": [

04_optimal_percentiles.ipynb

+25-17
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
},
2222
{
2323
"cell_type": "code",
24-
"execution_count": 2,
24+
"execution_count": 1,
2525
"id": "85c6f6ca-ef01-428f-b4c4-bf77542a31d5",
2626
"metadata": {},
2727
"outputs": [],
@@ -34,17 +34,17 @@
3434
},
3535
{
3636
"cell_type": "code",
37-
"execution_count": 3,
37+
"execution_count": 7,
3838
"id": "a61a1ab1-a65d-4bb1-b909-2d30d6506bb7",
3939
"metadata": {},
4040
"outputs": [
4141
{
4242
"data": {
4343
"text/plain": [
44-
"<xarray.core.options.set_options at 0x7f1b6633b890>"
44+
"<xarray.core.options.set_options at 0x7fdf586417d0>"
4545
]
4646
},
47-
"execution_count": 3,
47+
"execution_count": 7,
4848
"metadata": {},
4949
"output_type": "execute_result"
5050
}
@@ -64,6 +64,7 @@
6464
"# load nmc_met_io for retrieving micaps server data\n",
6565
"from nmc_met_io.retrieve_micaps_server import get_model_grid, get_model_grids\n",
6666
"from nmc_met_graphics.plot.china_map import add_china_map_2cartopy\n",
67+
"from nmc_met_base.ensemble import optimal_quantiles_cal\n",
6768
"\n",
6869
"xr.set_options(display_style=\"text\")"
6970
]
@@ -133,7 +134,7 @@
133134
},
134135
{
135136
"cell_type": "code",
136-
"execution_count": 6,
137+
"execution_count": 3,
137138
"id": "b4c9fbda-641d-40e1-bd00-4aff98651c52",
138139
"metadata": {},
139140
"outputs": [],
@@ -157,7 +158,7 @@
157158
},
158159
{
159160
"cell_type": "code",
160-
"execution_count": 7,
161+
"execution_count": 4,
161162
"id": "a52c78ec-683a-4712-8464-a199c76dc928",
162163
"metadata": {},
163164
"outputs": [
@@ -196,7 +197,7 @@
196197
" Origin: MICAPS Cassandra Server"
197198
]
198199
},
199-
"execution_count": 7,
200+
"execution_count": 4,
200201
"metadata": {},
201202
"output_type": "execute_result"
202203
}
@@ -207,7 +208,7 @@
207208
},
208209
{
209210
"cell_type": "code",
210-
"execution_count": 8,
211+
"execution_count": 5,
211212
"id": "9b3ebbc7-233e-4f33-9622-ccc642444466",
212213
"metadata": {},
213214
"outputs": [],
@@ -230,7 +231,7 @@
230231
},
231232
{
232233
"cell_type": "code",
233-
"execution_count": 10,
234+
"execution_count": 6,
234235
"id": "fb2c2e8a-458b-40df-837a-37892064fe5f",
235236
"metadata": {},
236237
"outputs": [
@@ -284,11 +285,6 @@
284285
"metadata": {},
285286
"source": [
286287
"```Python\n",
287-
"\n",
288-
"# 定影降水阈值及其最优百分位值\n",
289-
"thresholds = [0.0, 10, 25, 50, 100]\n",
290-
"optimal_quant = [0.0, 0.5, 0.75, 0.90, 0.95]\n",
291-
"\n",
292288
"# 定义最优百分位计算函数\n",
293289
"def optimal_quantiles_cal(values, thresholds, optimal_quant):\n",
294290
" \"\"\"\n",
@@ -314,15 +310,27 @@
314310
" # loop each threshold ..., complete the code\n",
315311
" \n",
316312
" return values_cal\n",
313+
"```"
314+
]
315+
},
316+
{
317+
"cell_type": "code",
318+
"execution_count": 8,
319+
"id": "c7262875-0071-4394-90cd-cd43bfc434e5",
320+
"metadata": {},
321+
"outputs": [],
322+
"source": [
323+
"# 定影降水阈值及其最优百分位值\n",
324+
"thresholds = [0.0, 10, 25, 50, 100]\n",
325+
"optimal_quant = [0.0, 0.5, 0.75, 0.90, 0.95]\n",
317326
"\n",
318327
"# 计算最优百分位值\n",
319-
"values_cal = optimal_quantiles_cal(values, thresholds, optimal_quant)\n",
320-
"```"
328+
"values_cal = optimal_quantiles_cal(values, thresholds, optimal_quant)"
321329
]
322330
},
323331
{
324332
"cell_type": "code",
325-
"execution_count": 42,
333+
"execution_count": 9,
326334
"id": "876b15ea-4c59-41b3-a32c-7097790ce580",
327335
"metadata": {},
328336
"outputs": [

05_model_blending.ipynb

+23-15
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)