分享两个下载era5数据的脚本(根据实际仅需要改动时间、变量、气压层、时次即可使用),由中国科学技术大学-大气科学先进计算实验室提供。在使用之前,需要先配置CDS API,点击https://cds.climate.copernicus.eu/api-how-to即可跳转至配置教程。
下载高空
代码语言:javascript复制#!/usr/bin/python3
import cdsapi
import os
import pandas as pd
import numpy as np
c = cdsapi.Client()
var_list = ['geopotential', 'relative_humidity', 'temperature',
'u_component_of_wind', 'v_component_of_wind']
start_date = '20070101'
end_date = '20071231'
start_year = int(start_date[:4])
end_year = int(end_date[:4])
year_list = np.arange(start_year, end_year 1)
year_list = year_list.astype(str)
for iyear in year_list:
path = './' iyear
if os.path.exists(path):
print("file exist")
else:
os.mkdir(path)
year_start_date = iyear "0101"
year_end_date = end_date if int(end_date) < int(iyear)*10000 1231 else iyear "1231"
date_list = pd.date_range(year_start_date, year_end_date).strftime("%Y%m%d").tolist()
for idate in date_list:
date_name = path "/" idate "-pl.grib"
if os.path.exists(date_name):
continue
c.retrieve(
'reanalysis-era5-pressure-levels',
{
'product_type': 'reanalysis',
'format': 'grib',
'pressure_level': [
'1', '2', '3',
'5', '7', '10',
'20', '30', '50',
'70', '100', '125',
'150', '175', '200',
'225', '250', '300',
'350', '400', '450',
'500', '550', '600',
'650', '700', '750',
'775', '800', '825',
'850', '875', '900',
'925', '950', '975',
'1000',
],
'variable': var_list,
'year': iyear,
'month': idate[4:6],
'day': idate[6:8],
'time': [
'00:00', '06:00', '12:00',
'18:00',
],
},
date_name)
print('ok')
下载地面
代码语言:javascript复制#!/usr/bin/python3
import cdsapi
import os
import pandas as pd
import numpy as np
c = cdsapi.Client()
var_list = ['10m_u_component_of_wind', '10m_v_component_of_wind', '2m_dewpoint_temperature',
'2m_temperature', 'land_sea_mask', 'mean_sea_level_pressure',
'sea_ice_cover', 'sea_surface_temperature', 'skin_temperature',
'snow_depth', 'soil_temperature_level_1', 'soil_temperature_level_2',
'soil_temperature_level_3', 'soil_temperature_level_4', 'surface_pressure',
'volumetric_soil_water_layer_1', 'volumetric_soil_water_layer_2', 'volumetric_soil_water_layer_3',
'volumetric_soil_water_layer_4']
start_date = '20070101'
end_date = '20071231'
start_year = int(start_date[:4])
end_year = int(end_date[:4])
year_list = np.arange(start_year, end_year 1)
year_list = year_list.astype(str)
for iyear in year_list:
path = './' iyear
if os.path.exists(path):
print("file exist")
else:
os.mkdir(path)
year_start_date = iyear "0101"
year_end_date = end_date if int(end_date) < int(iyear)*10000 1231 else iyear "1231"
date_list = pd.date_range(year_start_date, year_end_date).strftime("%Y%m%d").tolist()
for idate in date_list:
date_name = path "/" idate "-sfc.grib"
if os.path.exists(date_name):
continue
c.retrieve(
'reanalysis-era5-single-levels',
{
'product_type': 'reanalysis',
'format': 'grib',
'variable': var_list,
'year': iyear,
'month': idate[4:6],
'day': idate[6:8],
'time': [
'00:00', '06:00', '12:00',
'18:00',
],
},
date_name)
print('ok')
并行下载
气象学家公众号提供了并行下载的脚本,有需要的可以了解一下
并行下载ERA5数据的python脚本