相信大家刚接触到micaps数据是一头雾水,还好有对应的可视化库。
今天给大家演示两种micaps站点数据的快速绘制方法。
导入可视化库
import meteva.base as meb
import metpy.calc as mpcalc
import metpy.plots as mpplots
from metpy.units import units
from metpy.calc import reduce_point_density
import matplotlib.pyplot as plt
import numpy as np
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.io.shapereader import BasicReader
from cartopy.mpl.gridliner import LATITUDE_FORMATTER, LONGITUDE_FORMATTER
plt.rcParams['font.sans-serif'] = ['Source Han Sans CN']
plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号
Warning: ecCode
数据读取:micaps第三类数据
provinces = BasicReader('/home/mw/input/china1656/china_map/china_map/China_Province_2022.shp')
filename = "/home/mw/input/meteva2260/t.000" # 替换为你的micaps文件路径
sta = meb.read_stadata_from_micaps3(filename)
sta.head()
| level | time | dtime | id | lon | lat | data0 |
0 | 0 | 2022-09-04 17:00:00 | 0 | 56473 | 102.77 | 28.95 | 16.8 |
1 | 0 | 2022-09-04 17:00:00 | 0 | 56263 | 101.88 | 30.88 | 11.9 |
2 | 0 | 2022-09-04 17:00:00 | 0 | 56593 | 104.92 | 28.58 | 23.1 |
3 | 0 | 2022-09-04 17:00:00 | 0 | 56491 | 104.57 | 28.70 | 21.7 |
4 | 0 | 2022-09-04 17:00:00 | 0 | 56290 | 104.18 | 30.78 | 19.6 |
数据处理
# 读取经度、纬度、温度
lons = sta["lon"].values
lats = sta["lat"].values
方法一:使用metpy站点绘制
创建图形
fig = plt.figure(figsize=(15, 12))
ax = fig.add_subplot(111,projection=ccrs.PlateCarree())
ax.add_feature(cfeature.LAND)
ax.add_feature(cfeature.OCEAN)
ax.add_feature(cfeature.COASTLINE)
ax.set_extent( [110, 120, 20, 25])
创建站点图
stationplot = mpplots.StationPlot(ax, lons, lats, transform=ccrs.PlateCarree(),
fontsize=10)
绘制温度分布
stationplot.plot_parameter('NW', temperature, formatter=lambda v: format(v, '.1f'))
ax.add_geometries(provinces.geometries(), linewidth=.5, edgecolor='black', crs=ccrs.PlateCarree(),
facecolor='none')
gl = ax.gridlines(
draw_labels=True,
alpha=0.5,
linewidth=1,
'k', color=
'--') linestyle=
# 关闭顶端标签 gl.xlabels_top = False
# 关闭右侧标签 gl.ylabels_right = False
# x轴设为经度格式 gl.xformatter = LONGITUDE_FORMATTER
# y轴设为纬度格式 gl.yformatter = LATITUDE_FORMATTER
plt.show()
方法二:使用meteva库内置函数绘制
map_extend = [110, 120, 20, 25]
axs = meb.creat_axs(
1,
map_extend,
sup_title="2022年9月4日t2",
add_index=[
"a"],
sup_fontsize=8)
image = meb.add_scatter_text(axs[0], sta, tag=0, font_size=8,cmap =meb.cmaps.temp_2m)