阅读建议
使用基于Python的PyCINRAD来处理、显示天气雷达基数据,只做简单推介,根据自己需要来选用。版本迭代,建议使用最新版本的PyCINRAD,以及与之相匹配的Python开发环境,避免一些不必要的库不兼容的问题。
前言介绍安装数据、脚本绘图GUI可视化界面总结问题报错参考
只是简单的安装测试了一下SA/SB/SC格式雷达基数据,不知道什么原因,CD格式的数据读取还存在问题。内容基本参照气象家园上的相关帖子。具体的更多细节可以参照气象家园的帖子,后续我会给出链接。本人不是中尺度研究方向,也是抱着学习的态度来安装测试,也推荐大家业务和科研方面使用PyCINRAD。感谢PyCINRAD的开发者@eeeee@高空急流,花费大量的时间和精力来贡献这款开源库。
注:图片较大显示为压缩后的,点击可下载1下载2原图。
建议git clone https://github.com/CyanideCN/PyCINRAD.git
,cd PyCINRAD/
, python setup.py install
方式来安装,PyCINRAD支持Python3.6+的版本,但是在安装的时候,有时候存在比较慢的情况,可以根据进度来中断,单独来使用pip install packages
或conda install packages
的方式来安装依赖库,譬如,pyresample和shapefile。
再者,也给出我的PyCINRAD环境,Python环境的导出和导入,一键式安装见我之前写的帖子【一键安装气象常用的Python库(大气科学Python库)】,在此不赘述。除了PyCINRAD的GitHub上提供的安装方法之外,也可以采用我的PyCINRAD.yml文件来解决依赖关系。
1name: PyCINRAD
2channels:
3 - conda-forge
4 - conda-forge/label/cf201901
5 - defaults
6dependencies:
7 - arm_pyart=1.9.2=py36_0
8 - asn1crypto=0.24.0=py36_1003
9 - bzip2=1.0.6=1
10 - ca-certificates=2019.3.9=hecc5488_0
11 - cartopy=0.17.0=py36h929c6f0_1004
12 - certifi=2019.3.9=py36_0
13 - cffi=1.12.3=py36hccf1714_0
14 - cftime=1.0.3.4=py36h7eb728f_0
15 - chardet=3.0.4=py36_1003
16 - configobj=5.0.6=py_0
17 - cryptography=2.6.1=py36h212c5bf_0
18 - cryptography-vectors=2.3.1=py36_1000
19 - curl=7.62.0=ha441bb4_0
20 - cython=0.29.7=py36h6de7cb9_0
21 - freetype=2.10.0=h24853df_0
22 - geos=3.7.1=h0a44026_1000
23 - hdf4=4.2.13=h951d187_2
24 - hdf5=1.10.4=nompi_h5598ddc_1105
25 - icu=58.2=h0a44026_1000
26 - idna=2.8=py36_1000
27 - jpeg=9c=h1de35cc_1001
28 - kiwisolver=1.1.0=py36h770b8ee_0
29 - krb5=1.14.6=0
30 - libblas=3.8.0=8_openblas
31 - libcblas=3.8.0=8_openblas
32 - libcurl=7.62.0=h051b688_0
33 - libcxx=4.0.1=hcfea43d_1
34 - libcxxabi=4.0.1=hcfea43d_1
35 - libedit=3.1.20181209=hb402a30_0
36 - libffi=3.2.1=h475c297_4
37 - libgfortran=3.0.1=0
38 - libiconv=1.15=h01d97ff_1005
39 - liblapack=3.8.0=8_openblas
40 - libnetcdf=4.6.2=h2c3f975_1
41 - libpng=1.6.37=h2573ce8_0
42 - libssh2=1.8.2=hcdc9a53_2
43 - libtiff=4.0.10=h79f4b77_1001
44 - libxml2=2.9.9=hd80cff7_0
45 - libxslt=1.1.32=h33a18ac_1002
46 - lxml=4.3.3=py36h08abf6f_0
47 - matplotlib-base=3.0.2=py36hb2d221d_1
48 - ncurses=6.1=h0a44026_1
49 - netcdf4=1.4.2=py36h13743db_0
50 - olefile=0.46=py_0
51 - openblas=0.3.6=hd44dcd8_1
52 - openssl=1.1.1b=h01d97ff_2
53 - owslib=0.17.1=py_0
54 - pillow=5.3.0=py36hbddbef0_1000
55 - pip=19.1.1=py36_0
56 - proj4=5.2.0=h1de35cc_1001
57 - pycparser=2.19=py36_1
58 - pyepsg=0.4.0=py_0
59 - pykdtree=1.3.1=py36h917ab60_1002
60 - pyopenssl=19.0.0=py36_0
61 - pyparsing=2.4.0=py_0
62 - pyproj=1.9.6=py36h9c430a6_1000
63 - pyresample=1.12.2=py36h051e8ed_0
64 - pysocks=1.7.0=py36_0
65 - python=3.6.8=haf84260_0
66 - python-dateutil=2.8.0=py_0
67 - pytz=2019.1=py_0
68 - pyyaml=5.1=py36h1de35cc_0
69 - readline=7.0=h1de35cc_5
70 - requests=2.21.0=py36_1000
71 - scipy=1.2.1=py36hbd7caa9_1
72 - setuptools=41.0.1=py36_0
73 - shapely=1.6.4=py36h4b8df73_1004
74 - six=1.12.0=py36_1000
75 - sqlite=3.28.0=ha441bb4_0
76 - tk=8.6.8=ha441bb4_0
77 - tornado=6.0.2=py36h01d97ff_0
78 - trmm_rsl=1.49=3
79 - urllib3=1.24.2=py36_0
80 - wheel=0.33.2=py36_0
81 - xz=5.2.4=h1de35cc_4
82 - yaml=0.1.7=h1de35cc_1001
83 - zlib=1.2.11=h1de35cc_3
84 - pip:
85 - cinrad==1.3.3
86 - cycler==0.10.0
87 - decorator==4.4.0
88 - dill==0.2.9
89 - inspyred==1.0.1
90 - ipython-genutils==0.2.0
91 - matplotlib==3.1.0rc2
92 - metpy==0.10.0
93 - numpy==1.14.5
94 - packaging==19.0
95 - pandas==0.24.2
96 - pint==0.9
97 - pooch==0.2.1
98 - pykriging==0.2.0
99 - pyqt5==5.12.2
100 - pyqt5-sip==4.19.17
101 - pyshp==2.1.0
102 - traitlets==4.3.2
103 - xarray==0.12.1
104 - xlrd==1.2.0
105prefix: /Users/zhpfu/anaconda3/envs/PyCINRAD
链接:https://pan.baidu.com/s/1riGd4WBZbXCgggkqct_Eyw 密码:k15x
Z_RADR_I_Z9250_20160701001000_O_DOR_SA_CAP.bin Z9250_20160701001005_0.6_230_REF_31.2N117.0E_32.4N120.0E.png Z9250_20160701001005_0.6_230_REF.png
脚本:源于气象家园,版权属于@小其其格、@eeeee
1# -*- coding: utf-8 -*-
2"""
3Created on Sun Jan 13 21:51:35 2019
4
5@author: Fulang WU
6"""
7
8"""定义一个函数,用于读取目标文件夹下的多个雷达基数据"""
9#读取指定文件夹中的指定文件类型的文件名
10import os
11
12def get_filename(path,fileType):
13 file_name =[]
14 final_name = []
15 for files in os.listdir(path): #root为目录路径 #dirs为路径下的子目录 #files为路径下的所有非子目录
16 if fileType in files:
17 file_name.append(files.replace(fileType,''))#生成不带‘.bin’后缀的文件名组成的列表
18 final_name = [path +item +fileType for item in file_name]#生成‘.bin’后缀的文件名组成的绝对路径列表
19 return final_name #输出列表
20"""-----------------------------------------------------------------------------------------------------------"""
21
22
23"""读取目标文件夹下的多个雷达基数据"""
24Dir = "/Users/zhpfu/Dropbox/Code_Fortress/00_My_Python_Library/Radar_data_process/Method_2/data/" #目标文件夹
25fileType = '.bin' #雷达基数据后缀名
26sa_radar_file = get_filename(Dir,fileType)
27print(sa_radar_file)
28"""----------------------------------------------------------------------"""
29
30
31"""---------------------------绘制雷达图像-------------------------------"""
32import cinrad
33from cinrad.io import CinradReader, StandardData
34from cinrad.visualize import PPI
35import matplotlib.ticker as mticker
36from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
37
38
39ele = 0 #第1个仰角
40radius = 230 #绘制图像的范围大小
41
42for nFiles in range(len(sa_radar_file)):
43
44 f = CinradReader(sa_radar_file[nFiles]) #老版本数据
45 r = f.get_data(ele,radius,'REF') #0代表第1个仰角
46 fig = cinrad.visualize.PPI(r) #绘制PPI图像
47
48 fig.plot_range_rings(radius, color='white', linewidth=1.0) #绘制圆圈
49 for i in range(0,radius-30,50):
50 fig.plot_range_rings(i, color='white', linewidth=1.0) #绘制圆圈
51
52 """
53 设置经纬度
54 """
55 liner = fig.geoax.gridlines(draw_labels=True,linewidth=2, color='gray', alpha=0.5, linestyle='--')
56 liner.xlabels_top = False
57 liner.ylabels_right = False
58 liner.xformatter = LONGITUDE_FORMATTER
59 liner.yformatter = LATITUDE_FORMATTER
60 liner.xlabel_style = {'size': 18, 'color': 'white'}
61 #liner.xlabel_style = {'color': 'red', 'weight': 'bold'}
62 liner.ylabel_style = {'size': 18, 'color': 'white'}
63
64 #保存图像
65 fig(Dir)
66 # /Users/zhpfu/anaconda3/envs/PyCINRAD/lib/python3.6/site-packages/cinrad-1.3.3-py3.6.egg/cinrad/visualize
1# -*- coding: utf-8 -*-
2"""
3Created on Sun Jan 13 21:51:35 2019
4
5@author: Fulang WU
6"""
7
8"""定义一个函数,用于读取目标文件夹下的多个雷达基数据"""
9#读取指定文件夹中的指定文件类型的文件名
10import os
11def get_filename(path,fileType):
12 file_name =[]
13 final_name = []
14 for files in os.listdir(path): #root为目录路径 #dirs为路径下的子目录 #files为路径下的所有非子目录
15 if fileType in files:
16 file_name.append(files.replace(fileType,''))#生成不带‘.bin’后缀的文件名组成的列表
17 final_name = [path +item +fileType for item in file_name]#生成‘.bin’后缀的文件名组成的绝对路径列表
18 return final_name #输出列表
19"""-----------------------------------------------------------------------------------------------------------"""
20
21
22
23"""读取目标文件夹下的多个雷达基数据"""
24Dir = "/Users/zhpfu/Dropbox/Code_Fortress/00_My_Python_Library/Radar_data_process/Method_2/data/" #目标文件夹
25fileType = '.bin' #雷达基数据后缀名
26#sa_radar_file = Dir+"Z_RADR_I_Z9571_20180304115800_O_DOR_SA_CAP.bin"
27sa_radar_file = get_filename(Dir,fileType) #读取
28print(sa_radar_file)
29"""----------------------------------------------------------------------"""
30
31"""---------------------------绘制雷达图像-------------------------------"""
32import cinrad
33from cinrad.io import CinradReader, StandardData
34from cinrad.visualize import PPI
35import matplotlib.ticker as mticker
36from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
37
38
39ele = 0 #第1个仰角
40radius = 230 #绘制图像的范围大小
41
42for nFiles in range(len(sa_radar_file)):
43
44 f = CinradReader(sa_radar_file[nFiles]) #老版本数据
45 rl = [f.get_data(i, 230, 'REF') for i in f.angleindex_r]
46 vcs = cinrad.easycalc.VCS(rl)
47 sec = vcs.get_section(start_cart=(117.0, 31.2), end_cart=(120., 32.4)) # 传入经纬度坐标
48 fig = cinrad.visualize.PPI(rl[ele]) #0代表第1个仰角
49
50 fig.plot_range_rings(radius, color='white', linewidth=1.0) #绘制圆圈
51 for i in range(0,radius-30,50):
52 fig.plot_range_rings(i, color='white', linewidth=1.0) #绘制圆圈
53
54 fig.plot_cross_section(sec) #绘制垂直剖面
55
56 """
57 设置经纬度
58 """
59 liner = fig.geoax.gridlines(draw_labels=True,linewidth=2, color='gray', alpha=0.5, linestyle='--')
60 liner.xlabels_top = False
61 liner.ylabels_right = False
62 liner.xformatter = LONGITUDE_FORMATTER
63 liner.yformatter = LATITUDE_FORMATTER
64 liner.xlabel_style = {'size': 18, 'color': 'white'}
65 #liner.xlabel_style = {'color': 'red', 'weight': 'bold'}
66 liner.ylabel_style = {'size': 18, 'color': 'white'}
67
68 #保存图像
69 fig(Dir)
1(PyCINRAD) ➜ Method_2 python PPI.py
2['/Users/zhpfu/Dropbox/Code_Fortress/00_My_Python_Library/Radar_data_process/Method_2/data/Z_RADR_I_Z9250_20160701001000_O_DOR_SA_CAP.bin']
3(366, 230)
4(366, 230)
5
6
7(PyCINRAD) ➜ Method_2 PYTHON PPI.VCS.py
8['/Users/zhpfu/Dropbox/Code_Fortress/00_My_Python_Library/Radar_data_process/Method_2/data/Z_RADR_I_Z9250_20160701001000_O_DOR_SA_CAP.bin']
9(366, 230)
10(366, 230)
11(367, 230)
12(367, 230)
13(372, 230)
14(372, 230)
15(372, 230)
16(372, 230)
17/Users/zhpfu/anaconda3/envs/PyCINRAD/lib/python3.6/site-packages/cinrad-1.3.3-py3.6-macosx-10.7-x86_64.egg/cinrad/io/io.py:310: UserWarning: Requested data range exceed max range in this tilt
18 warnings.warn('Requested data range exceed max range in this tilt')
19(372, 230)
20(372, 230)
21(368, 230)
22(368, 230)
23(365, 230)
24(365, 230)
25(363, 230)
26(363, 230)
27(360, 230)
28(360, 230)
运行方式:
进到PyCINRAD包的ui文件夹?:
python main_ui.pyw
打开后,一顿点点点,选择雷达基数据,需要注意的是必须文件名类似于“Z_RADR_I_Z9250_20160701001000_O_DOR_SA_CAP.bin”,不然无法读取。 可视化界面不是很稳定,比较简单的功能!
PyCINRAD其实提供了很丰富的接口,除了可视化之外,对于数据的提取、网格化、分辨率调整都比较灵活,能够支持主要的天气雷达。功能完备!值得深入研究,无论是业务还是科研,都是良好的利器!
Mac上不设置是不支持中文输出,有几个关键点需要注意下: 1.在visualize文件下utils.py添加
1[code=python]import matplotlib.pyplot as plt
2plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签
3plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号
4plt.rcParams['font.family']=['SimHei'][/code]
2.StationNames.xlsx文件确保是包含中文站点名称的(附件名称修改为StationNames.xlsx);并且放到data目录下; PPI的RAD站点名就可以正常显示了。
3.针对提示:
1/Users/zhpfu/anaconda3/envs/PyCINRAD/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88
2 return f(*args, **kwds)
3Cython is not installed, velocity dealias function cannot be used
解决办法:
pip uninstall cinrad
再从GitHub上git clone最新的文件,进到文件夹内:
python setup.py install
即可。
4.针对警告:
1/Users/zhpfu/anaconda3/envs/PyCINRAD/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88
2 return f(*args, **kwds)
3
4解决办法很简单,使用更低版本numpy即可:
5(PyCINRAD) ➜ pip install numpy==1.14.5
6Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
7Collecting numpy==1.14.5
8 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/f6/cd/b2c50b5190b66c711c23ef23c41d450297eb5a54d2033f8dcb3b8b13ac85/numpy-1.14.5-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (4.7MB)
9 |████████████████████████████████| 4.7MB 714kB/s
10Installing collected packages: numpy
11 Found existing installation: numpy 1.15.0
12 Uninstalling numpy-1.15.0:
13 Successfully uninstalled numpy-1.15.0
14Successfully installed numpy-1.14.5
以上是一些问题解决办法!仅供参考!
问题:PyCINRAD目前还不支持CD的PPI绘制?后续再处理吧!
报错如下:
1Traceback (most recent call last):
2 File "PPI_CD.py", line 36, in <module>
3 r = f.get_data(5, 100, 'REF')
4 File "/Users/zhpfu/anaconda3/envs/PyCINRAD/lib/python3.6/site-packages/cinrad-1.3.3-py3.6.egg/cinrad/io/io.py", line 360, in get_data
5 x, y, z, d, a = self.projection(reso)
6 File "/Users/zhpfu/anaconda3/envs/PyCINRAD/lib/python3.6/site-packages/cinrad-1.3.3-py3.6.egg/cinrad/io/io.py", line 371, in projection
7 lonx, latx = get_coordinate(r, theta, self.elev, self.stationlon, self.stationlat, h_offset=h_offset)
8 File "/Users/zhpfu/anaconda3/envs/PyCINRAD/lib/python3.6/site-packages/cinrad-1.3.3-py3.6.egg/cinrad/projection.py", line 62, in get_coordinate
9 deltav = np.cos(azimuth) * distance * np.cos(elev * deg2rad)
10AttributeError: 'NoneType' object has no attribute 'cos'
1.网址 https://github.com/CyanideCN/PyCINRAD 2.网址 http://bbs.06climate.com/forum.php?mod=viewthread&tid=88822&extra=&page=1 3.网址 http://bbs.06climate.com/forum.php?mod=viewthread&tid=88702&extra=page%3D1 4.网址 http://bbs.06climate.com/forum.php?mod=viewthread&tid=88702