气ython风雨 发表于 2024-5-25 12:15:06

xarray 系列 | 怎么使用ERA5再分析数据绘制气象要素廓线


前言
前段时间有读者来信问再分析数据的气象要素廓线怎么绘制,近期小编可以腾出手做个简单示例

今天我们测试如何使用Python中的两个强大库——xarray与pynio,来读取ERA5(European Centre for Medium-Range Weather Forecasts Reanalysis 5th Generation)提供的GRIB(GRIdded Binary)格式数据,并绘制指定经纬度站点的风速廓线。ERA5以其高时空分辨率和全球覆盖范围,为科学研究和应用提供了丰富的气象信息。接下来,我们将通过一系列步骤详细展示这一过程。

⏰ 温馨提示
由于可视化代码过长隐藏,可点击基于ERA5 GRIB数据的气象要素廓线与Hovmoller图绘制运行Fork查看
🔜🔜若没有成功加载可视化图,点击运行可以查看
ps:隐藏代码在【代码已被隐藏】所在行,点击所在行,可以看到该行的最右角,会出现个三角形,点击查看即可

使用xarray直接读取GRIB文件
xarray允许您指定不同的引擎来处理不同格式的数据。对于GRIB文件,可以使用pynio引擎直接读取

In :
import xarray as xr

file_path = '/home/mw/input/era51824/ERA5-2023-08_pl.nc'
engine = 'pynio'
dataset = xr.open_dataset(file_path, engine=engine)
u_wind = dataset['u']
v_wind = dataset['v']
In :
u_wind
Out:



定位指定经纬度站点
确定您感兴趣的经纬度坐标(例如,target_lat =40,target_lon = 120)。使用xarray的sel方法找到最接近该点的格点数据

In :
target_lat, target_lon = 40, 120
nearest_point = dataset.sel(longitude=target_lon, latitude=target_lat, method='nearest')
nearest_point
Out:



In :
wind_speed
Out:




计算风速与绘制廓线
计算风速并绘制垂直廓线(风速随高度的变化分布)

In :
import matplotlib.pyplot as plt
import numpy as np
wind_speed = np.sqrt(nearest_point['u'] ** 2 + nearest_point['v'] ** 2)

fig, ax = plt.subplots(figsize=(10, 12))

# 绘制风速廓线
ax.plot(wind_speed.values, nearest_point['level'].values, 'b', linewidth=2)# 使用蓝色线条绘制风速曲线

# 设置轴标签
plt.xlabel('Wind Speed (m/s)')
plt.ylabel('Pressure Level (hPa)')
plt.title(f'Wind Speed Profile at ({target_lat:.2f}, {target_lon:.2f})')
# 反转 y 轴(从大气顶部向下到地面)
ax.invert_yaxis()

# 添加网格线
ax.grid(True)

# 显示图形
plt.show()


Hovmoller图(高度为x轴)


Hovmoller图(高度为y轴)




文章来源于公众号:气python风雨

两盏明 发表于 2024-6-7 13:12:40

非常好帖子,使我眼泪下降!请问能否提供ERA5-2023-08_pl.nc的文件,我想自己试试

CeciliaMum 发表于 2024-6-27 23:56:55

casino games online usa blackjack

Don't wait any longer to experience the thrill of online slots. Join our casino games real money app today and embark on an adventure filled with fun, excitement, and endless opportunities to win. With our wide selection of games, generous bonuses, and secure environment, there's no better place to play. Sign up now and start spinning the reels for your chance to hit the jackpot!
页: [1]
查看完整版本: xarray 系列 | 怎么使用ERA5再分析数据绘制气象要素廓线