ERA5数据批量下载

ERA5再分析资料批量下载的python实现

ERA5再分析数据集是欧洲气象中心的第五代再分析数据产品,涵盖了海洋\近地面\高空各种要素。

本文介绍了一种使用IDM下载器接管下载内容的高效下载方法,较官网提供的方法更为快速、高效


1. 环境配置


网络上有较多详细描述,官网也提供了具体如何操作,可参考以下知乎文章https://zhuanlan.zhihu.com/p/581829748。文章也提供了下载方法,但本文介绍一种更为高效的方式。


2. IDM下载工具


IDM是一款非常高效的下载工具,读者可自行搜索、下载、安装。这里提供一个安装包https://pan.baidu.com/s/1G2sXOE8_jZxhoLHPL7cf1g 提取码:hhhh

IDM接管下载数据


3. 数据下载IDM接管


#!/usr/bin/python

import cdsapi
import urllib3
import os
import numpy as np
from subprocess import call

def idmDownloader(task_url, folder_path, file_name):
    """
    IDM下载器
    :param task_url: 下载任务地址
    :param folder_path: 存放文件夹
    :param file_name: 文件名
    :return:
    """
    # IDM安装目录
    idm_engine = "D:\\Program Files (x86)\\IDMnoad-v6.40.11\\IDM\\IDMan.exe"
    # 将任务添加至队列
    call([idm_engine, '/d', task_url, '/p', folder_path, '/f', file_name, '/a'])
    # 开始任务队列
    call([idm_engine, '/s'])

# download data from: https://cds.climate.copernicus.eu/cdsapp#!/dataset/reanalysis-era5-pressure-levels?tab=form
urllib3.disable_warnings()
c = cdsapi.Client()

# define the pressure levels you want download
pressure_level = ['100','200','300','400','500','600',
                    '700','750','800','850','900','925','950','1000']

# define the years you want to download
yearstart = 2022
yearend = 2022

# define spatial limits of download
north = 47.75
west = 96
south = 16
east = 127.75

variable = ['geopotential']
name_list = ['GP']
years = np.array(range(yearstart, yearend + 1), dtype="str")
area = [north, west, south, east]

def change_path(pl_para):
    file_path = "z" + pl
    dirs = os.path.join("D:/tmp/download/", file_path)
    if not os.path.exists(dirs):
        os.makedirs(dirs)
        os.chdir(dirs)
    else:
        os.chdir(dirs)


for year in years:
    for pl in pressure_level:
        change_path(pl)
        for name, var in zip(name_list, variable):
            r = c.retrieve(
                'reanalysis-era5-pressure-levels',
                {
                    'product_type': 'reanalysis',
                    'format': 'netcdf',
                    'pressure_level': pl,
                    'variable': var,
                    'year': year,
                    'month': [
                        '01', '02', '03',
                        '04', '05', '06',
                        '07','08', '09',
                        '10', '11', '12',
                    ],
                    'day': [
                        '01', '02', '03',
                        '04', '05', '06',
                        '07', '08', '09',
                        '10', '11', '12',
                        '13', '14', '15',
                        '16', '17', '18',
                        '19', '20', '21',
                        '22', '23', '24',
                        '25', '26', '27',
                        '28', '29', '30',
                        '31',
                    ],
                    'time': [
                        '00:00', '01:00', '02:00',
                        '03:00', '04:00', '05:00',
                        '06:00', '07:00', '08:00',
                        '09:00', '10:00', '11:00',
                        '12:00', '13:00', '14:00',
                        '15:00', '16:00', '17:00',
                        '18:00', '19:00', '20:00',
                        '21:00', '22:00', '23:00'
                    ],
                    'area': area,
                    'format': 'netcdf',
                },
                )
            url = r.location
            path = os.getcwd()  
            filename = name + pl + '_' + year + '.nc'
            idmDownloader(url, path, filename)  # 添加进IDM中下载
    print('data of {} is OK!'.format(year))
  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值