You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 27 Next »

Background


Access via web-api


The ROM SAF data is downloaded from the ECMWF public datasets service using web-api, which is a "programmatic approach" for data download with python scripts . We will not reproduce the all existing documentation here, but we will note some key steps required to download the data and provide the main links. Firstly, you will need to download the appropriate python modules to run the python download scripts. For example, the python scripts will contain "from ecmwfapi import" commands, like in this simple example, retrieving a monthly mean zonal wind at 1000 hPa, in netcdf format (More complex retrieval scripts are provided here):


#!/usr/bin/env python
#

from ecmwfapi import ECMWFDataServer

# To run this example, you need an API key
# available from https://api.ecmwf.int/v1/key/

server = ECMWFDataServer(verbose=1)

server.retrieve({
'dataset' : "rom_saf_3198",
'stream' : "moda",
'levtype' : "pl",
'levelist': "1000",
'date' : "20150301",
'type' : "an",
'param' : "131.128",
'grid' : "0.5/0.5",
'format' : "netcdf",
'target' : "rom_saf_3198.nc"
})

General information related to downloading the data via web-api, is described here:

https://confluence.ecmwf.int/display/WEBAPI/Web-API+Downloads

Specifically, follow the steps here to install the latest code version:

https://pypi.org/project/ecmwf-api-client/

Briefly, install this with the pip command:

pip install ecmwf-api-client

You will now have the modules needed in the python scripts. (I actually needed this command for the ECMWF system pip install --user ecmwf-api-client because of local permissions).

Login and retrieve your "key":

Login at:

https://apps.ecmwf.int/auth/login/

Retrieve your key at:

https://api.ecmwf.int/v1/key/

Create and paste the "key" information in here:

$HOME/.ecmwfapirc

You will also need to accept the terms before you can access the data with web-api otherwise you will get an error when you run the script.


#!/usr/bin/env python
import calendar
from ecmwfapi import ECMWFDataServer
server = ECMWFDataServer()

def retrieve_rom_saf():
"""
A function to demonstrate how to iterate efficiently over several years and months etc
for a particular rom_saf request.
Change the variables below to adapt the iteration to your needs.
You can use the variable 'target' to organise the requested data in files as you wish.
In the example below the data are organised in files per month. (eg "rom_saf_daily_201510.nc")
"""
yearStart = 2014
yearEnd = 2014
monthStart = 1
monthEnd = 12
for year in list(range(yearStart, yearEnd + 1)):
for month in list(range(monthStart, monthEnd + 1)):
startDate = '%04d%02d%02d' % (year, month, 1)
numberOfDays = calendar.monthrange(year, month)[1]
lastDate = '%04d%02d%02d' % (year, month, numberOfDays)
target = "rom_saf_daily_%04d%02d.nc" % (year, month)
requestDates = (startDate + "/TO/" + lastDate)
rom_saf_request(requestDates, target)

def rom_saf_request(requestDates, target):
"""
An ROM SAF request for analysis pressure level data.
Change the keywords below to adapt it to your needs.
(eg to add or to remove levels, parameters, times etc)
Request cost per day is 112 fields, 14.2326 Mbytes
"""
server.retrieve({
"class": "ea", # do not change
"dataset": "rom_saf_3198", # or "rom_saf_3199"
"expver": "3198", # or "3199"
"stream": "oper", # do not change
"type": "an", # analysis (versus forecast, fc)
"date": requestDates, # dates, set automatically from above
"levtype": "pl", # pressure level data (versus surface, sfc, and model level, ml)
"levelist": "100/500/700/750/850/925/1000", # levels, required only with levtype:pl and levtype:ml
"param": "129.128/130.128", # here: Geopotential (z), Temperature (T), Specific humidity (q), Zonal wind (u), meridional wind (v); see http://apps.ecmwf.int/codes/grib/param-db
"target": target, # output file name, set automatically from above
"time": "00/06/12/18", # times of analysis (with type:an), or initialization time of forecast (with type:fc)
"grid": "1.5/1.5", # Optional for GRIB, required for NetCDF. The horizontal resolution in decimal degrees. If not set, the archived grid as specified in the data documentation is used.
"format": "netcdf", # Optional. Output in NetCDF format. Requires that you also specify 'grid'. If not set, data is delivered in GRIB format, as archived.
})
if __name__ == '__main__':
retrieve_rom_saf()




  • No labels