ERA5再分析数据集是欧洲气象中心的第五代再分析数据产品,涵盖了海洋\近地面\高空各种要素。
本文介绍了一种使用IDM下载器接管下载内容的高效下载方法,较官网提供的方法更为快速、高效
网络上有较多详细描述,官网也提供了具体如何操作,可参考以下知乎文章https://zhuanlan.zhihu.com/p/581829748。文章也提供了下载方法,但本文介绍一种更为高效的方式。
IDM是一款非常高效的下载工具,读者可自行搜索、下载、安装。这里提供一个安装包https://pan.baidu.com/s/1G2sXOE8_jZxhoLHPL7cf1g 提取码:hhhh
#!/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))