1.配置key
https://cds.climate.copernicus.eu/api-how-to 获取key
修改配置文件,把url和key复制进行
vim $HOME/.cdsapirc
2.下载
根据要求修改年和月份等变量
import cdsapi
import calendar
import concurrent.futures
import os
def download_month_data(year, month):
year_dir = f'/data0/era5/v/{year}'
os.makedirs(year_dir, exist_ok=True)
c = cdsapi.Client()
month_str = f'{month:02d}'
days_in_month = calendar.monthrange(year, month)[1]
days = [f'{day:02d}' for day in range(1, days_in_month + 1)]
times = [f'{hour:02d}:00' for hour in range(24)]
file_path = f'{year_dir}/{year}{month_str}.nc'
c.retrieve(
'reanalysis-era5-pressure-levels',
{
'product_type': 'reanalysis',
'format': 'netcdf',
'variable': ['v_component_of_wind'],
'pressure_level': ['50', '100', '150', '200', '250', '300', '400', '500', '600', '700', '850', '925', '1000'],
'year': str(year),
'month': month_str,
'day': days,
'time': times,
'area': [90, -180, -90, 180],
},
file_path
)
years = [2023, 2022, 2021, 2020, 2019, 2018, 2017, 2016, 2015, 2014, 2013, 2012, 2011]
with concurrent.futures.ThreadPoolExecutor(max_workers=12) as executor:
futures = []
for year in years:
for month in range(1, 13):
futures.append(executor.submit(download_month_data, year, month))
for future in concurrent.futures.as_completed(futures):
future.result()
print("所有下载已完成。")