ECWMF下载s2s回算数据-批量下载

注意事项:

当大小不一样的时候说明下载的时候有损坏,所以下载完之后要检查一下。

解决办法:删掉,然后重新运行下面的下载代码,因为这段代码已经包括自动检测已有的文件是否存在

from ecmwfapi import ECMWFDataServer
import os
server = ECMWFDataServer()
origin = "ecmf"

def retrieve_ECMWF_reforecast():
    # Step 1: Select a Model Version Date
    # modelVersionDates = ["2019-10-24"]
    # modelVersionDates = ["2019-01-03", "2019-01-07", "2019-01-10", "2019-01-14", "2019-01-17", "2019-01-21", "2019-01-24", "2019-01-28", "2019-01-31",
    #                      "2019-02-04", "2019-02-07", "2019-02-11", "2019-02-14", "2019-02-18", "2019-02-21", "2019-02-25", "2019-02-28",
    #                      "2019-03-04", "2019-03-07", "2019-03-11", "2019-03-14", "2019-03-18", "2019-03-21", "2019-03-25", "2019-03-28",
    #                      "2019-04-01", "2019-04-04", "2019-04-08", "2019-04-11", "2019-04-15", "2019-04-18", "2019-04-22", "2019-04-25", "2019-04-29",
    #                      "2019-05-02", "2019-05-06", "2019-05-09", "2019-05-13", "2019-05-16", "2019-05-20", "2019-05-23", "2019-05-27", "2019-05-30",
    #                      "2019-06-03", "2019-06-06", "2019-06-10", "2019-06-13", "2019-06-17", "2019-06-20", "2019-06-24", "2019-06-27",
    #                      "2019-07-01", "2019-07-04", "2019-07-08", "2019-07-11", "2019-07-15", "2019-07-18", "2019-07-22", "2019-07-25", "2019-07-29",
    #                      "2019-08-01", "2019-08-05", "2019-08-08", "2019-08-12", "2019-08-15", "2019-08-19", "2019-08-22", "2019-08-26", "2019-08-29",
    #                      "2019-09-02", "2019-09-05", "2019-09-09", "2019-09-12", "2019-09-16", "2019-09-19", "2019-09-23", "2019-09-26", "2019-09-30",
    #                      "2019-10-03", "2019-10-07", "2019-10-10", "2019-10-14", "2019-10-17", "2019-10-21", "2019-10-24", "2019-10-28", "2019-10-31",
    #                      "2019-11-04", "2019-11-07", "2019-11-11", "2019-11-14", "2019-11-18", "2019-11-21", "2019-11-25", "2019-11-28",
    #                      "2019-12-02", "2019-12-05", "2019-12-09", "2019-12-12", "2019-12-16", "2019-12-19", "2019-12-23", "2019-12-26", "2019-12-30",
    #                      ]
    modelVersionDates = ["2023-01-02", "2023-01-05", "2023-01-09", "2023-01-12", "2023-01-16", "2023-01-19", "2023-01-23", "2023-01-26", "2023-01-30",
                         "2023-02-02", "2023-02-06", "2023-02-09", "2023-02-13", "2023-02-16", "2023-02-20", "2023-02-23", "2023-02-27",
                         "2023-03-02", "2023-03-06", "2023-03-09", "2023-03-13", "2023-03-16", "2023-03-20", "2023-03-23", "2023-03-27", "2023-03-30",
                         "2023-04-03", "2023-04-06", "2023-04-10", "2023-04-13", "2023-04-17", "2023-04-20", "2023-04-24", "2023-04-27",
                         "2023-05-01", "2023-05-04", "2023-05-08", "2023-05-11", "2023-05-15", "2023-05-18", "2023-05-22", "2023-05-25", "2023-05-29",
                         "2023-06-01", "2023-06-05", "2023-06-08", "2023-06-12", "2023-06-15", "2023-06-19", "2023-06-22", "2023-06-26", "2023-06-29",
                         "2023-07-03", "2023-07-06", "2023-07-10", "2023-07-13", "2023-07-17", "2023-07-20", "2023-07-24", "2023-07-27", "2023-07-31",
                         "2023-08-03", "2023-08-07", "2023-08-10", "2023-08-14", "2023-08-17", "2023-08-21", "2023-08-24", "2023-08-28", "2023-08-31",
                         "2023-09-04", "2023-09-07", "2023-09-11", "2023-09-14", "2023-09-18", "2023-09-21", "2023-09-25", "2023-09-28",
                         "2023-10-02", "2023-10-05", "2023-10-09", "2023-10-12", "2023-10-16", "2023-10-19", "2023-10-23", "2023-10-26", "2023-10-30",
                         "2023-11-02", "2023-11-06", "2023-11-09", "2023-11-13", "2023-11-16", "2023-11-20", "2023-11-23", "2023-11-27", "2023-11-30",
                         "2023-12-04", "2023-12-07", "2023-12-11", "2023-12-14", "2023-12-18", "2023-12-21", "2023-12-25", "2023-12-28"]
    # modelVersionDates = ["2019-04-25", "2019-04-29",
    #                      "2019-05-02", "2019-05-06", "2019-05-09", "2019-05-13", "2019-05-16", "2019-05-20", "2019-05-23", "2019-05-27", "2019-05-30",
    #                      "2019-06-03", "2019-06-06", "2019-06-10", "2019-06-13", "2019-06-17", "2019-06-20", "2019-06-24", "2019-06-27",
    #                      "2019-07-01", "2019-07-04", "2019-07-08", "2019-07-11", "2019-07-15", "2019-07-18", "2019-07-22", "2019-07-25", "2019-07-29",
    #                      "2019-08-01", "2019-08-05", "2019-08-08", "2019-08-12", "2019-08-15", "2019-08-19", "2019-08-22", "2019-08-26", "2019-08-29",
    #                      "2019-09-02", "2019-09-05", "2019-09-09", "2019-09-12", "2019-09-16", "2019-09-19", "2019-09-23", "2019-09-26", "2019-09-30",
    #                      ]
    # modelVersionDates = ["2019-05-27"]

    # Step 2: Set the hindcast Dates you wish to request
    hindcastYearStart = 2003
    hindcastYearEnd = 2022
    for modelVersionDate in modelVersionDates:
        mm = modelVersionDate[5:7]
        dd = modelVersionDate[8:10]
        for hindcastYear in list(range(hindcastYearStart, hindcastYearEnd + 1)):
            hindcastDate =  str(hindcastYear)+ mm+dd
            # print(hindcastDate)
            cfsfcTarget = "/data/ecv850/s2s_"+origin+ "_2023_"+hindcastDate+"_v850_cf.nc"
            pfsfcTarget = "/data/ecv850/s2s_"+origin+ "_2023_"+hindcastDate+"_v850_pf.nc"
            # print(cfplTarget) 
            if os.path.exists(pfsfcTarget) and os.path.getsize(pfsfcTarget):
                print(pfsfcTarget,'exist')
            else:
                try:
                    ECMWF_reforecast_cf_sfc_request(hindcastDate,modelVersionDate,cfsfcTarget)
                    ECMWF_reforecast_pf_sfc_request(hindcastDate,modelVersionDate,pfsfcTarget)
                except:
                    print('0')
        
def ECMWF_reforecast_cf_sfc_request(hindcastDate,modelVersionDate,target):
    server.retrieve({
        "class": "s2",
        "dataset": "s2s",
        "date": modelVersionDate,
        "expver": "prod",
        "hdate": hindcastDate,
        "levtype": "pl",
        "levelist": "850",
        "origin": origin,
        "param": "132",
        "step": "0/to/1104/by/24",
        "stream": "enfh",
        "time": "00",
        "type": "cf",
        "format": "netcdf",
        "target": target,
    })
    
def ECMWF_reforecast_pf_sfc_request(hindcastDate,modelVersionDate,target):
    server.retrieve({
        "class": "s2",
        "dataset": "s2s",
        "date": modelVersionDate,
        "expver": "prod",
        "hdate": hindcastDate,
        "levtype": "pl",
        "levelist": "850",
        "origin": origin,
        "param": "132",
        "step": "0/to/1104/by/24",
        "stream": "enfh",
        "time": "00",
        "number": "1/2/3/4/5/6/7/8/9/10",
        "type": "pf",
        "format": "netcdf",
        "target": target,    
    })

if __name__ == '__main__':
  retrieve_ECMWF_reforecast()

 

  • 5
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值