ERA5提供的下载代码
#!/usr/bin/env python
import cdsapi
c = ()
(
'reanalysis-era5-land',
{
'format': 'netcdf',
'variable': [
'2m_temperature', 'leaf_area_index_high_vegetation', 'leaf_area_index_low_vegetation',
'snow_cover', 'soil_temperature_level_1', 'surface_pressure',
'total_precipitation', 'volumetric_soil_water_layer_1',
],
'year': [
'2015',
],
'month': [
'01',
],
'day': [
'01',
],
'time': [
'06:00',
],
},
'')
在ERA5提供的下载代码上做了些改动,可以实现逐小时下载。为了加速下载,还使用简单的多线程(根据电脑性能确定线程数目根据电脑性能确定线程数目)。Overview - CDO - Project Management Service在ERA5提供的下载代码上做了些改动,可以实现逐小时下载。为了加速下载,还使用简单的多线程(根据电脑性能确定线程数目根据电脑性能确定线程数目)。/projects/cdo
#!/usr/bin/env python3
import time
import multiprocessing
from multiprocessing import Pool
import cdsapi
def job1(z):
"""
:param z:
:return:
"""
return f(z[0], z[1])
def f(start,end):
c = ()
ff=open('','r')
filelist=()
lines=filelist.split('\n')
# print(len(lines)-1)
for i in range(start,end,1):
fields = lines[i].split('-') #split data
year = fields[0]
month = fields[1]
day = fields[2]
print('Download %s-%s-%s data'% (year,month,day))
(
'reanalysis-era5-land',
{
'format': 'netcdf',
'variable': [
'2m_temperature',
],
'year': year,
'month': month,
'day': day,
'time': [
'12:00',
],
'format': 'netcdf'
},
'CDS%s%s%s'% (year,month,day)+'.nc')
print('Datafile CDS%s%s%s'% (year,month,day)+'.nc download successful')
# return start,end
if __name__ == '__main__':
time1=()
pool = (16)##根据电脑性能确定线程数目:/weixin_45775343/article/details/102694881
data_list=[]
for i in range(10,70,10):
a,b=i-10,i
data_list.append((a,b))
print(data_list)
res = (job1, data_list)
time2=()
print(res)
()
()
print('总共耗时:' + str(time2 - time1) + 's')
利用cdo选择和裁剪区域。Climate Data Operators (CDO)处理NC文件比较快捷,具体操作见官方说明文档Overview - CDO - Project Management ServiceOverview - CDO - Project Management Service
script_abs=$(readlink -f "$0")
script_dir=$(dirname $script_abs)
mkdir cutted
dir=./CDS
for file in $dir/*
do
new_file=${file##*/}
cdo selvar,t2m -sellonlatbox,0,360,-90,90 $file $script_dir/cutted/$new_file
done
为了加速数据处理,shell脚本可采用并行操作
bash data_selected1.sh &
bash data_selected2.sh &
wait
echo "Finish"