下载ERA5-Land数据的准备工作
注册并获取CDS API密钥:访问Copernicus Climate Data Store (CDS) 官网(https://cds.climate.copernicus.eu/),完成账号注册。在用户页面找到API密钥,保存为$HOME/.cdsapirc文件,内容格式如下:
url: https://cds.climate.copernicus.eu/api/v2 key: UID:API-key安装必要Python库:
pip install cdsapi xarray numpy通过CDS API下载数据
使用cdsapi库直接请求数据,示例代码下载2020年1月的日均2米气温数据:
import cdsapi c = cdsapi.Client() c.retrieve( 'reanalysis-era5-land', { 'variable': '2m_temperature', 'year': '2020', 'month': '01', 'day': list(range(1, 32)), 'time': ['00:00', '12:00'], 'format': 'netcdf', }, 'era5_land_temp.nc' )https://www.zhihu.com/zvideo/1994564245371756984/
https://www.zhihu.com/zvideo/1994564243933128684/
https://www.zhihu.com/zvideo/1994564244046378913/
https://www.zhihu.com/zvideo/1994564243635327027/
https://www.zhihu.com/zvideo/1994564242402191321/
https://www.zhihu.com/zvideo/1994564241835988775/
https://www.zhihu.com/zvideo/1994564240472831811/
https://www.zhihu.com/zvideo/1994564239864644278/
https://www.zhihu.com/zvideo/1994564238644115391/
https://www.zhihu.com/zvideo/1994564237973021265/
https://www.zhihu.com/zvideo/1994564237306139680/
https://www.zhihu.com/zvideo/1994564236173668797/
https://www.zhihu.com/zvideo/1994564236026872280/
https://www.zhihu.com/zvideo/1994564235682935847/
https://www.zhihu.com/zvideo/1994564235234129467/
https://www.zhihu.com/zvideo/1994564235129287151/
https://www.zhihu.com/zvideo/1994564234152002275/
批量下载多时间范围数据
对于跨年/月的大批量下载,建议分时段请求以避免超时:
years = ['2019', '2020'] months = [f'{m:02d}' for m in range(1,13)] for year in years: for month in months: c.retrieve( 'reanalysis-era5-land', { 'variable': 'soil_temperature_level_1', 'year': year, 'month': month, 'time': '00:00', 'format': 'grib' }, f'era5_land_soil_{year}{month}.grib' )数据处理与可视化
使用xarray处理下载的NetCDF文件:
import xarray as xr ds = xr.open_dataset('era5_land_temp.nc') # 转换为摄氏温度并计算月平均 ds['t2m'] = ds['t2m'] - 273.15 monthly_mean = ds.groupby('time.month').mean()绘制空间分布图:
import matplotlib.pyplot as plt monthly_mean['t2m'].isel(month=0).plot() plt.title('January Average Temperature') plt.savefig('temp_map.png')注意事项
ERA5-Land数据延迟约3个月,实时数据需选择ERA5T临时产品。不同变量可能存储在独立的数据集(如reanalysis-era5-land-monthly-means提供月度统计量)。GRIB格式文件建议用cfgrib引擎读取:
ds = xr.open_dataset('era5_land.grib', engine='cfgrib')