循环批量下载ERA5数据

目录

1. 选取并提交数据

2. 选择合适的下载方式

3. 之前的循环批量下载程序

 4. 修改程序

5.本地测试的结果

6. 服务器测试

 

1. 选取并提交数据

Copernicus Climate Data Store | Copernicus Climate Data Storeicon-default.png?t=N7T8https://cds.climate.copernicus.eu/cdsapp#!/dataset/reanalysis-era5-pressure-levels?tab=form选择合适的参数、时间和区域。

2. 选择合适的下载方式

本人采用python进行下载,选择官网数据的show API request选项,会出现以下的程序

import cdsapi

c = cdsapi.Client()

c.retrieve(
    'reanalysis-era5-pressure-levels',
    {
        'product_type': 'reanalysis',
        'variable': [
            'divergence', 'relative_humidity', 'specific_humidity',
            'temperature', 'u_component_of_wind', 'v_component_of_wind',
            'vertical_velocity',
        ],
        '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',
        ],
        'year': '2014',
        'month': '03',
        'day': [
            '08', '09', '10',
            '11', '12', '13',
            '14',
        ],
        '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': [
            38, -180, -38,
            180,
        ],
        'format': 'grib',
    },
    'download.grib')

对运行程序可能有用的: How to use the CDS API | Copernicus Climate Data Store

3. 之前的循环批量下载程序

# -*- coding: utf-8 -*-
"""
Created on Sun Feb 27 17:57:04 2022

@author: lsl
"""

import cdsapi
import time

c = cdsapi.Client()

Number1 = 2008-2008+1 # year 2010-2007+1
for x in range(Number1):
    year = 2008+x
    #time.sleep(60)
    Number2 = 1 # month
    for y in range(Number2):
        month = 10 + y
        #time.sleep(60)        
        Number3 =31-10+1
        for z in range(Number3):#day
            day =10+z
            #time.sleep(60)
            c.retrieve(
                'reanalysis-era5-pressure-levels',   
                {                
                    'product_type': 'reanalysis',
                    'format': 'netcdf',
                    'variable': 'vertical_velocity',
                    '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',
                    ],
                    'year': str(year),
                    'month':str(month),# 1-9:'0'+str(month)   10-12:str(month)
                    'day':str(day), # 1-9:'0'+str(day)   10-31:str(day)
                    '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': [
                        12,-180,-20,-163,
                    ],
                },
            'w_'+str(year)+'_'+str(month)+'_'+str(day)+'_CP2.nc')

 4. 修改程序

为了得到逐小时的ERA5数据,程序修改如下

# -*- coding: utf-8 -*-
"""
Created on Tue Nov 14 15:49:48 2023

@author: blingblingleilei
"""
### 2014.03.8-9 10-23点

import cdsapi
# import time

c = cdsapi.Client()

Number1 = 2014-2014+1 # year 2015-2014+1
for x in range(Number1): # 从0到Number1,不包括Number1
    year = 2014 + x  # 下载2014年的数据
    #time.sleep(60)
    Number2 = 3-3+1 # month
    for y in range(Number2):
        month = 3 + y  #下载3月份的数据
        #time.sleep(60)        
        Number3 = 9-8+1  #下载8号到9号的数据
        for z in range(Number3): #day
            day = 8 + z
            #time.sleep(60)
            Number4 = 23-10+1 # 10到23点
            for k in range(Number4): # hour
                hour = 10 + k
                c.retrieve(
                    'reanalysis-era5-pressure-levels',   # ERA5的具体产品
                    {                
                        'product_type': 'reanalysis',
                        'format': 'netcdf',
                        'variable': [
                            'divergence', 'relative_humidity', 'specific_humidity',
                            'temperature', 'u_component_of_wind', 'v_component_of_wind',
                            'vertical_velocity',
                        ],
                        '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',
                        ],
                        'year': str(year),               
                        'month':'0'+str(month),# 1-9:'0'+str(month)   10-12:str(month)
                        'day':'0'+str(day), # 1-9:'0'+str(day)   10-31:str(day)
                        'time': str(hour)+':00',# 0-9:'0'+str(hour)+':00'    10-23:+str(hour)+':00' 
                        'area': [
                            38,-180,-38,180,
                        ],
                    },
                    'ERA5_'+str(year)+'_'+str(month)+'_'+str(day)+'_'+str(hour)+'_tropical.nc')

5.本地测试的结果

平均3-5分钟一个,10个月的数据:10月*30天*24时*(3-5min)=360h-600h=15天-25天

6. 服务器测试

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值