warning:
这篇文章距离上次修改已过260天,其中的内容可能已经有所变动。
import matplotlib.pyplot as plt
import numpy as np
from metpy.units import units
import xarray as xr
from metpy.calc import dewpoint, theta
from metpy.plots import plot_crosshairs, plot_barb, plot_dove_tail_vorticity, plot_planet
era5_file = 'era5_data.nc'
era5 = xr.open_dataset(era5_file)
lat = 40.0
lon = -105.0
u = era5['u'][0, :, :].values * units('m/s')
v = era5['v'][0, :, :].values * units('m/s')
t = era5['temperature'][0, :, :].values * units('K')
td = era5['dewpoint_temperature'][0, :, :].values * units('K')
hgt = era5['geopotential'][0, :, :].values * units('m^2/s^2')
rh = np.clip(dewpoint(t, td).to('degC'), 0, None)
evaporation = (
6.112 * np.exp(5419. / (t - rh)) * (hgt / 9.8) ** 2
) * units('mm/day')
fig = plt.figure(figsize=(12, 9))
ax = fig.add_subplot(1, 1, 1, projection=era5.metpy.cartopy_crs)
ax.contourf(era5['level'].values, era5.metpy.y, era5.metpy.x, hgt.m, 15, cmap='Spectral_r')
plot_planet(era5.metpy.y, era5.metpy.x, evaporation, cmap='viridis', norm=None, ax=ax)
plot_barb(era5.metpy.y, era5.metpy.x, u, v, ax=ax)
plot_dove_tail_vorticity(era5.metpy.y, era5.metpy.x, u, v, ax=ax)
plot_crosshairs(lat, lon, ax=ax, linewidth=2)
ax.set_title(f'ERA5 Wind, Vorticity, and Evaporation at {lat:.2f}°N, {lon:.2f}°W')
ax.set_xlabel('Longitude')
ax.set_ylabel('Latitude')
plt.legend()
plt.savefig('era5_map.png', bbox_inches='tight', pad_inches=0.1)
plt.show()
这段代码假设您已经有了ERA5数据,并且存储在了一个名为era5_data.nc
的netCDF文件中。代码读取了该文件,并选择了一个特定的站点来绘制风速、风向、笛卡尔流向和笛卡尔强度、水汽通量散度图以及站点坐标。最终保存了一个名为era5_map.png
的图像文件。
评论已关闭