多进程批量下载era5再分析数据

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("所有下载已完成。")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值