气ython风雨 发表于 2024-5-5 19:57:38

不用 SHP 文件进行气象绘图的三种方式


不用 SHP 文件进行气象绘图的三种方式
========================================

01 前言
在气象绘图中,使用 SHP 文件经常会带来一些麻烦。为了摆脱对 SHP 文件的依赖,我们需要思考如何直接进行绘图而不受其限制。本文将介绍三种不使用 SHP 文件进行气象绘图的工具。

02 项目目标
本项目旨在解决在气象作图过程中对 SHP 文件的依赖问题。

03 项目方法
在以下内容中,将详细介绍三种不使用 SHP 文件进行气象绘图的方法,帮助读者更好地进行气象数据可视化。

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

05 安装库
!pip install frykit -i <a href="https://pypi.mirrors.ustc.edu.cn/simple/" target="_blank">https://pypi.mirrors.ustc.edu.cn/simple/</a>
#从指定镜像下载安装工具包,镜像URL可自行修改
!pip install cnmaps --user <a href="https://pypi.mirrors.ustc.edu.cn/simple/" target="_blank">https://pypi.mirrors.ustc.edu.cn/simple/</a>
#从指定镜像下载安装工具包,镜像URL可自行修改
06 导入库与链接数据库
# Resolve the latest GFS dataset
import metpy
from siphon.catalog import TDSCatalog
from datetime import datetime
import frykit.plot as fplt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.gridspec as gridspec
import matplotlib.pyplot as plt
import metpy.calc as mpcalc
from metpy.units import units
from netCDF4 import num2date
import numpy as np
import scipy.ndimage as ndimage
from siphon.ncss import NCSS
from siphon.catalog import TDSCatalog
# Set up access via NCSS
gfs_catalog = ('http://thredds.ucar.edu/thredds/catalog/grib/NCEP/GFS/'
               'Global_0p5deg/catalog.xml?dataset=grib/NCEP/GFS/Global_0p5deg/Best')
cat = TDSCatalog(gfs_catalog)
ncss = cat.datasets.subset()
07 获取绘图需要变量
# Query for Latest GFS Run
now = datetime.utcnow()
query = ncss.query()
query.lonlat_box(north=60, south=15, east=130, west=100).time((datetime(2024, 3, 18, 18)))
query.accept('netcdf4')
query.variables('Apparent_temperature_height_above_ground', 'Dewpoint_temperature_height_above_ground')
data =ncss.get_data(query)
08 数据处理
lon = data.variables['longitude'][:]
lat = data.variables['latitude'][:]

times = data.variables.dimensions]
vtime = num2date(times[:], units=times.units)
## 地上两米的露点温度与温度
ts = data.variables['Apparent_temperature_height_above_ground']
td = data.variables['Dewpoint_temperature_height_above_ground']
09 绘图部分
010 frykit
代码 :fplt.add_cn_province(ax)
/opt/conda/lib/python3.9/site-packages/cartopy/mpl/gridliner.py:451: UserWarning: The .xlabels_top attribute is deprecated. Please use .top_labels to toggle visibility instead.
warnings.warn('The .xlabels_top attribute is deprecated. Please '
/opt/conda/lib/python3.9/site-packages/cartopy/mpl/gridliner.py:487: UserWarning: The .ylabels_right attribute is deprecated. Please use .right_labels to toggle visibility instead.
warnings.warn('The .ylabels_right attribute is deprecated. Please '

011 cnmaps
代码:draw_maps(get_adm_maps(level='省'), linewidth=0.8, color='k')/opt/conda/lib/python3.9/site-packages/cartopy/mpl/gridliner.py:451: UserWarning: The .xlabels_top attribute is deprecated. Please use .top_labels to toggle visibility instead.
warnings.warn('The .xlabels_top attribute is deprecated. Please '
/opt/conda/lib/python3.9/site-packages/cartopy/mpl/gridliner.py:487: UserWarning: The .ylabels_right attribute is deprecated. Please use .right_labels to toggle visibility instead.
warnings.warn('The .ylabels_right attribute is deprecated. Please '

012 meteva
代码:add_china_map_2basemap(ax, name="province", edgecolor='k', lw=0.5, encoding='gbk', grid0=None)





文章来源于公众号:气python风雨
页: [1]
查看完整版本: 不用 SHP 文件进行气象绘图的三种方式