雷达系列:两种基于雷达基数据绘制雷达CAPPI图的方式

文摘   2024-09-19 18:55   广东  

两种基于雷达基数据绘制雷达CAPPI图的方式

个人信息

公众号:气python风雨

Image Name

关注我获取更多学习资料,第一时间收到我的Python学习资料,也可获取我的联系方式沟通合作

温馨提示

由于可视化代码过长隐藏,可点击运行Fork查看
若没有成功加载可视化图,点击运行可以查看
ps:隐藏代码在【代码已被隐藏】所在行,点击所在行,可以看到该行的最右角,会出现个三角形,点击查看即可

前言

前不久pyart库更新了cappi函数,那么我们来进行一波测试

项目目标

本项目旨在解决在气象作图过程中CAPPI计算与绘图问题

项目方法

在以下内容中,将详细介绍两种方法进行CAPPI计算与绘图,帮助读者更好地进行气象数据可视化。

更新依赖库

!pip install --upgrade arm-pyart  -i https://pypi.mirrors.ustc.edu.cn/simple/
Looking in indexes: https://pypi.mirrors.ustc.edu.cn/simple/
Requirement already satisfied: arm-pyart in /opt/conda/lib/python3.9/site-packages (1.17.0)
Collecting arm-pyart
Downloading https://mirrors.ustc.edu.cn/pypi/packages/11/ea/90db3ef2b24f97a5dd6addf0f1627688db120298908dec067fa8e80b466b/arm_pyart-1.19.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.8 MB)
[2K [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m13.8/13.8 MB[0m [31m77.6 MB/s[0m eta [36m0:00:00[0m00:01[0m00:01[0m
[?25hRequirement already satisfied: matplotlib in /opt/conda/lib/python3.9/site-packages (from arm-pyart) (3.8.3)
Requirement already satisfied: pandas in /opt/conda/lib/python3.9/site-packages (from arm-pyart) (2.0.3)
Requirement already satisfied: xarray!=0.21.0 in /opt/conda/lib/python3.9/site-packages (from arm-pyart) (2024.2.0)
Requirement already satisfied: pooch in /opt/conda/lib/python3.9/site-packages (from arm-pyart) (1.8.1)
Requirement already satisfied: cartopy in /opt/conda/lib/python3.9/site-packages (from arm-pyart) (0.23.0)
Requirement already satisfied: pint in /opt/conda/lib/python3.9/site-packages (from arm-pyart) (0.23)
Requirement already satisfied: s3fs in /opt/conda/lib/python3.9/site-packages (from arm-pyart) (0.4.2)
Requirement already satisfied: fsspec in /opt/conda/lib/python3.9/site-packages (from arm-pyart) (2022.3.0)
Collecting xradar>=0.5.0
Downloading https://mirrors.ustc.edu.cn/pypi/packages/3d/50/df2ae4f0d6a12afc65b4212ae5e2ee280dadf924f24a6c9e407c5541c3b0/xradar-0.6.4-py3-none-any.whl (116 kB)
[2K [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m116.9/116.9 kB[0m [31m7.0 MB/s[0m eta [36m0:00:00[0m
[?25hRequirement already satisfied: cftime in /opt/conda/lib/python3.9/site-packages (from arm-pyart) (1.6.3)
Requirement already satisfied: numpy in /opt/conda/lib/python3.9/site-packages (from arm-pyart) (1.26.4)
Collecting mda-xdrlib
Downloading https://mirrors.ustc.edu.cn/pypi/packages/4f/4b/5fe3a00833a9f9775b3c237624a6212798167278ffe10fe0de04f58612d0/mda_xdrlib-0.2.0-py3-none-any.whl (14 kB)
Collecting netCDF4>=1.7.0
Downloading https://mirrors.ustc.edu.cn/pypi/packages/ab/26/98e91ff4751824015f9ea7674bf7681537f1269b715bf794338b383de14f/netCDF4-1.7.1.post2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (9.0 MB)
[2K [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m9.0/9.0 MB[0m [31m55.0 MB/s[0m eta [36m0:00:00[0m00:01[0m:00:01[0m
[?25hRequirement already satisfied: scipy in /opt/conda/lib/python3.9/site-packages (from arm-pyart) (1.11.4)
Requirement already satisfied: open-radar-data in /opt/conda/lib/python3.9/site-packages (from arm-pyart) (0.0.9)
Requirement already satisfied: certifi in /opt/conda/lib/python3.9/site-packages (from netCDF4>=1.7.0->arm-pyart) (2024.2.2)
Requirement already satisfied: packaging>=22 in /opt/conda/lib/python3.9/site-packages (from xarray!=0.21.0->arm-pyart) (23.2)
Requirement already satisfied: tzdata>=2022.1 in /opt/conda/lib/python3.9/site-packages (from pandas->arm-pyart) (2024.1)
Requirement already satisfied: python-dateutil>=2.8.2 in /opt/conda/lib/python3.9/site-packages (from pandas->arm-pyart) (2.8.2)
Requirement already satisfied: pytz>=2020.1 in /opt/conda/lib/python3.9/site-packages (from pandas->arm-pyart) (2022.1)
Requirement already satisfied: h5py>=3.0.0 in /opt/conda/lib/python3.9/site-packages (from xradar>=0.5.0->arm-pyart) (3.8.0)
Requirement already satisfied: dask in /opt/conda/lib/python3.9/site-packages (from xradar>=0.5.0->arm-pyart) (2024.2.0)
Requirement already satisfied: pyproj in /opt/conda/lib/python3.9/site-packages (from xradar>=0.5.0->arm-pyart) (3.4.1)
Requirement already satisfied: h5netcdf>=1.0.0 in /opt/conda/lib/python3.9/site-packages (from xradar>=0.5.0->arm-pyart) (1.3.0)
Requirement already satisfied: xarray-datatree>=0.0.10 in /opt/conda/lib/python3.9/site-packages (from xradar>=0.5.0->arm-pyart) (0.0.14)
Requirement already satisfied: lat-lon-parser in /opt/conda/lib/python3.9/site-packages (from xradar>=0.5.0->arm-pyart) (1.3.0)
Requirement already satisfied: xmltodict in /opt/conda/lib/python3.9/site-packages (from xradar>=0.5.0->arm-pyart) (0.13.0)
Requirement already satisfied: cmweather in /opt/conda/lib/python3.9/site-packages (from xradar>=0.5.0->arm-pyart) (0.3.2)
Requirement already satisfied: shapely>=1.7 in /opt/conda/lib/python3.9/site-packages (from cartopy->arm-pyart) (1.8.5.post1)
Requirement already satisfied: pyshp>=2.3 in /opt/conda/lib/python3.9/site-packages (from cartopy->arm-pyart) (2.3.1)
Requirement already satisfied: pillow>=8 in /opt/conda/lib/python3.9/site-packages (from matplotlib->arm-pyart) (9.4.0)
Requirement already satisfied: kiwisolver>=1.3.1 in /opt/conda/lib/python3.9/site-packages (from matplotlib->arm-pyart) (1.4.2)
Requirement already satisfied: fonttools>=4.22.0 in /opt/conda/lib/python3.9/site-packages (from matplotlib->arm-pyart) (4.33.3)
Requirement already satisfied: contourpy>=1.0.1 in /opt/conda/lib/python3.9/site-packages (from matplotlib->arm-pyart) (1.2.0)
Requirement already satisfied: importlib-resources>=3.2.0 in /opt/conda/lib/python3.9/site-packages (from matplotlib->arm-pyart) (5.7.1)
Requirement already satisfied: pyparsing>=2.3.1 in /opt/conda/lib/python3.9/site-packages (from matplotlib->arm-pyart) (3.0.9)
Requirement already satisfied: cycler>=0.10 in /opt/conda/lib/python3.9/site-packages (from matplotlib->arm-pyart) (0.11.0)
Requirement already satisfied: typing-extensions in /opt/conda/lib/python3.9/site-packages (from pint->arm-pyart) (4.7.1)
Requirement already satisfied: requests>=2.19.0 in /opt/conda/lib/python3.9/site-packages (from pooch->arm-pyart) (2.27.1)
Requirement already satisfied: platformdirs>=2.5.0 in /opt/conda/lib/python3.9/site-packages (from pooch->arm-pyart) (4.2.0)
Requirement already satisfied: botocore>=1.12.91 in /opt/conda/lib/python3.9/site-packages (from s3fs->arm-pyart) (1.34.51)
Requirement already satisfied: urllib3<1.27,>=1.25.4 in /opt/conda/lib/python3.9/site-packages (from botocore>=1.12.91->s3fs->arm-pyart) (1.26.9)
Requirement already satisfied: jmespath<2.0.0,>=0.7.1 in /opt/conda/lib/python3.9/site-packages (from botocore>=1.12.91->s3fs->arm-pyart) (1.0.1)
Requirement already satisfied: mpi4py>=3.0.2 in /opt/conda/lib/python3.9/site-packages (from h5py>=3.0.0->xradar>=0.5.0->arm-pyart) (3.1.5)
Requirement already satisfied: zipp>=3.1.0 in /opt/conda/lib/python3.9/site-packages (from importlib-resources>=3.2.0->matplotlib->arm-pyart) (3.8.0)
Requirement already satisfied: six>=1.5 in /opt/conda/lib/python3.9/site-packages (from python-dateutil>=2.8.2->pandas->arm-pyart) (1.16.0)
Requirement already satisfied: charset-normalizer~=2.0.0 in /opt/conda/lib/python3.9/site-packages (from requests>=2.19.0->pooch->arm-pyart) (2.0.12)
Requirement already satisfied: idna<4,>=2.5 in /opt/conda/lib/python3.9/site-packages (from requests>=2.19.0->pooch->arm-pyart) (3.3)
Requirement already satisfied: partd>=1.2.0 in /opt/conda/lib/python3.9/site-packages (from dask->xradar>=0.5.0->arm-pyart) (1.2.0)
Requirement already satisfied: toolz>=0.10.0 in /opt/conda/lib/python3.9/site-packages (from dask->xradar>=0.5.0->arm-pyart) (0.12.1)
Requirement already satisfied: importlib-metadata>=4.13.0 in /opt/conda/lib/python3.9/site-packages (from dask->xradar>=0.5.0->arm-pyart) (7.0.1)
Requirement already satisfied: click>=8.1 in /opt/conda/lib/python3.9/site-packages (from dask->xradar>=0.5.0->arm-pyart) (8.1.3)
Requirement already satisfied: cloudpickle>=1.5.0 in /opt/conda/lib/python3.9/site-packages (from dask->xradar>=0.5.0->arm-pyart) (2.0.0)
Requirement already satisfied: pyyaml>=5.3.1 in /opt/conda/lib/python3.9/site-packages (from dask->xradar>=0.5.0->arm-pyart) (5.4.1)
Requirement already satisfied: locket in /opt/conda/lib/python3.9/site-packages (from partd>=1.2.0->dask->xradar>=0.5.0->arm-pyart) (1.0.0)
Installing collected packages: mda-xdrlib, netCDF4, xradar, arm-pyart
Attempting uninstall: netCDF4
Found existing installation: netCDF4 1.6.5
Uninstalling netCDF4-1.6.5:
Successfully uninstalled netCDF4-1.6.5
Attempting uninstall: xradar
Found existing installation: xradar 0.4.3
Uninstalling xradar-0.4.3:
Successfully uninstalled xradar-0.4.3
Attempting uninstall: arm-pyart
Found existing installation: arm_pyart 1.17.0
Uninstalling arm_pyart-1.17.0:
Successfully uninstalled arm_pyart-1.17.0
[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
meteva 1.8.3 requires netCDF4<=1.6.5,>=1.4.2, but you have netcdf4 1.7.1.post2 which is incompatible.[0m[31m
[0mSuccessfully installed arm-pyart-1.19.1 mda-xdrlib-0.2.0 netCDF4-1.7.1.post2 xradar-0.6.4

PY-ART

当前最流行的雷达开源库pyart在最新版本更新了cappi的函数pyart.retrieve.cappi

import matplotlib.pyplot as pltimport pyartfrom pycwr.io import read_autoPATH='/home/mw/input/pycwr5461/Z_RADR_I_Z9898_20190828181529_O_DOR_SAD_CAP_FMT (1).bin.bz2'PRD = read_auto(PATH)radar = PRD.ToPyartRadar()# Create CAPPI at 2,000 meters for the 'reflectivity' fieldcappi = pyart.retrieve.create_cappi(    radar, fields=["reflectivity"], height=3000)
# Create RadarMapDisplay objects for both PPI and CAPPIradar_display = pyart.graph.RadarMapDisplay(radar)cappi_display = pyart.graph.RadarMapDisplay(cappi)
# Plotting the PPI and CAPPI for comparisonfig, ax = plt.subplots(1, 2, figsize=(13, 5))
# Plot PPI for 'reflectivity' fieldradar_display.plot_ppi("reflectivity",cmap="CN_ref", vmin=-5, vmax=75, ax=ax[0])ax[0].set_title("PPI Reflectivity")
# Plot CAPPI for 'reflectivity' fieldcappi_display.plot_ppi("reflectivity",cmap="CN_ref", vmin=-5, vmax=75, ax=ax[1])ax[1].set_title("CAPPI Reflectivity at 3000 meters")
# Show the plotsplt.show()

左图为ppi,右图为cappi

PYCWR

import matplotlib.pyplot as pltimport numpy as npfrom pycwr.draw.RadarPlot import Graph, plot_xy
# 创建一个新的图形,并设置为1行2列的子图布局fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(14, 6))
# 绘制PPI图像graph = Graph(PRD)graph.plot_ppi(ax1, 0, "dBZ", cmap="CN_ref") # 0代表第一层, dBZ代表反射率产品ax1.set_title("PPI Plot", fontsize=16)ax1.set_xlabel("Distance From Radar In East (km)", fontsize=14)ax1.set_ylabel("Distance From Radar In North (km)", fontsize=14)
# 准备CAPPI数据x1d = np.arange(-230000, 230001, 1000) # x方向1km等间距, -150km~150km范围y1d = np.arange(-230000, 230001, 1000) # y方向1km等间距, -150km~150km范围PRD.add_product_CAPPI_xy(XRange=x1d, YRange=y1d, level_height=3000) # level height units:metersgrid_x, grid_y = np.meshgrid(x1d, y1d, indexing="ij")
# 绘制CAPPI图像plot_xy(ax2, grid_x, grid_y, PRD.product.CAPPI_3000) # 画图显示ax2.set_title("CAPPI Plot at 2000m", fontsize=16)ax2.set_xlabel("Distance From Radar In East (km)", fontsize=14)ax2.set_ylabel("Distance From Radar In North (km)", fontsize=14)
# 调整布局以防止标签重叠plt.tight_layout()# 显示图像plt.show()

小结

两者CAPPI插值出来的结果不太一致,真让人头大
明显看出pyart的函数应该在某个地方判断有问题,导致绘制出的cappi图像位置不合理
pycwr的计算结果明显合理多了
可能是插值算法的区别,pyart源码中使用了RectBivariateSpline插值
pycwr应该是使用了IDW插值
还是实践出真知,新出的算法还需多多复盘


气python风雨
主要发一些涉及大气科学的Python文章与个人学习备忘录
 最新文章