使用 Python 库处理 NetCDF 文件,示例代码可能如下所示:
导入警告
warnings.filterwarnings("忽略")
将 matplotlib.pyplot 导入为 plt
将 numpy 导入为 np
将熊猫导入为 pd
% matplotlib 内联
从 netCDF4 导入数据集
从 mpl_toolkits.basemap 导入底图
从 pyproj 导入 Proj
将 matplotlib.cm 导入为 cm
导入日期时间
文件 = “test.nc”
rootgrp = 数据集(文件,“r”)
x = rootgrp['longitude'][:] # 0-359, step = 1
y = rootgrp['latitude'][:] # -90~90, step =1
tmp = rootgrp['TMP_2maboveground'][:][0] # shape(181,360)
dt = datetime.datetime(1970,1,1) + datetime.timedelta(seconds = rootgrp['time'][0])
fig = plt.figure(dpi=150)
m = 底图(投影='mill',lat_ts=10,llcrnrlon=x.min(),
urcrnrlon=x.max(),llcrnrlat=y.min(),urcrnrlat=y.max(),分辨率='c')
xx, yy = m(*np.meshgrid(x,y))
m.pcolormesh(xx,yy,tmp-273.15,shading='flat',cmap=plt.cm.jet)
m.colorbar(location='right')
m.drawcoastlines()
m.drawparallels(np.arange(-90.,120.,30.), 标签=[1,0,0,0], fontsize=10)
m.drawmeridians(np.arange(0.,360.,60.),标签=[0,0,0,1],字体大小=10)
plt.title("{}, GFS, 温度 (C) ".format(dt.strftime('%Y-%m-%d %H:%M UTC')))
plt.show()