利用python下载ECMWF数据

本文指导如何注册ECMWF账号,安装并使用web-API客户端,获取下载key,并修改样例程序来下载ECMWF的interim气压层数据。详细步骤包括:注册账号、安装python包、获取API key并创建配置文件,以及调整样例程序以指定下载的时间、变量、垂直层和地理范围。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.注册ECMWF数据下载账号;

2.下载 ECMWF web-API client version in python,下载网址为https://software.ecmwf.int/wiki/display/WEBAPI/Web-API+Downloads,然后pip install 下载的包即可

3.登录账号获取下载数据的key,网址https://api.ecmwf.int/v1/key/,然后将获取的信息保存成名为.ecmwfapirc文件,windows放置在 C:\Users\<USERNAME>\.ecmwfapirc,文件内容样例如下:

{
    "url"   "<a href="https://api.ecmwf.int/v1" "="" style="border-radius: 0px; background: 0px center; border: 0px; bottom: auto; float: none; height: auto; left: auto; line-height: 20px; margin: 0px; outline: 0px; overflow: visible; padding: 0px; position: static; right: auto; top: auto; vertical-align: baseline; width: auto; box-sizing: content-box; min-height: inherit; color: rgb(0, 51, 102) !important;">https://api.ecmwf.int/v1",
    "key"   "XXXXXXXXXXXXXXXXXXXXXX",
    "email" "john.smith@example.com"
}

4.修改需要下载数据的pytho程序样例。重点修改下载的时间,变量(变量编号或变量名),垂直层以及覆盖的区域。ECMWF网站上有关说明:https://softwarepythonchen.ecmwf.int/wiki/display/WEBAPI/Accessing+ECMWF+data+servers+in+batch

5.所附程序为下载ECMWF interim气压层的数据

#!/usr/bin/python
#-*-coding: UTF-8 -*-
from ecmwfapi import ECMWFDataServer

server = ECMWFDataServer()

# This script downloads ERA-Interim forecasts, on pressure levels.
# Adapt the script to your requirements.
# The data volume for all pressure level data is about 5GB per day, and all pressure level data for more than a single day will exceed the WebAPI limit of 600.000 fields. Thus please restrict the download to what you really need.
# It is likely you need to split your request, this is best done by time periods, ie. first download for month 1, then for month 2, etc.
year=['2012','2013','2014','2015','2016','2017']
month=['05','06','07','08','09']
day=['31','30','31','31','30']
for i in year[0:6]:
    k=0
    for j in month[0:5]:
        print i+'-'+j+'-01/to/'+i+'-'+j+'-'+day[k]
        server.retrieve({
        # Specify the ERA-Interim data archive. Don't change.
            "class": "ei",
            "dataset": "interim",
            "expver": "1",
            "stream": "oper",
            # pressure levels (levtype:pl), all available levels (levelist)
            "levtype": "pl",
            "levelist": "100/200/225/250/300/350/400/450/500/550/600/650/700/750/775/800/825/850/875/900/925/950/975/1000",
            # forecast (type:fc), from both daily forecast runs (time) with all available forecast steps (step, in hours)
            "type": "an",
            "time": "00/06/12/18",
            "step": "0",
            # all available parameters, for codes see http://apps.ecmwf.int/codes/grib/param-db
            "param": "60.128/129.128/130.128/131.128/132.128/133.128/135.128/138.128/155.128/157.128",
            # two days worth of data
            "date": i+'-'+j+'-01/to/'+i+'-'+j+'-'+day[k],
            # in 0.75 degrees lat/lon
            "grid": "0.75/0.75",
            # optionally restrict area to Europe (in N/W/S/E).
            #"area": "75/-20/10/60",
            # Optionally get output in NetCDF format. However, for NetCDF timestamps (time+step) must not overlap, so use e.g. "time":"00:00:00/12:00:00","step":"12"
            "format" : "netcdf",
            # set an output file name
            "target": "E:\\ERA-Interim\\"+i+"-"+j+"-01to"+i+"-"+j+"-"+day[k]+"-pl.nc"
        })
        k = k + 1
print "Download finished"


评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值