Page tree
Skip to end of metadata
Go to start of metadata

You can use a Python program to extract ERA-Interim and other data remotely from ECMWF's archive system MARS. For an introduction see here.

Daily data

When extracting ERA-Interim daily data from the data archive at ECMWF you can specify:

A single date, for example the 1st of January 2015:

   "date": "2015-01-01",

Multiple distinct dates, for example the 1st of each month in 2015:

   "date": "2015-01-01/2015-02-01/2015-03-01/2015-04-01/2015-05-01/2015-06-01/2015-07-01/2015-08-01/2015-09-01/2015-10-01/2015-11-01/2015-12-01",

A date range, for example all days from 1st of January to 28th of February 2015:

   "date": "2015-01-01/to/2015-02-28",

You can write a date either as YYYY-MM-DD or as YYYYMMDD.

Monthly data

When you extract monthly means, the monthly means are timestamped to the first day of the month, and you have to extract for exactly these dates. So to extract monthly means for all of 2015 you need to use this syntax to specify dates:

    "date": "20150101/20150201/20150301/20150401/20150501/20150601/20150701/20150801/20150901/20151001/20151101/20151201",

You can write a date either as YYYY-MM-DD or as YYYYMMDD.

Code example
#!/usr/bin/env python

# This script extracts the average daily precipitation for each month.

from datetime import datetime, timedelta

# Change the start and end dates to your desired date range. Monthly data is specified as the 1st of the month.
# For example, to get January 1979 to December 1980, use (1979, 1, 1) and (1980, 12, 1), respectively

start = datetime(1979, 1, 1)
end = datetime(1980, 12, 1)

datelist = [start.strftime('%Y-%m-%d')]
while start <= end:
    start += timedelta(days=32)
    datelist.append( datetime(start.year, start.month, 1).strftime('%Y-%m-%d') )
datestring = "/".join(datelist)

from ecmwfapi import ECMWFDataServer
server = ECMWFDataServer()
    "class": "ei",
    "dataset": "interim",
    "date": datestring,
    "expver": "1",
    "grid": "0.75/0.75",
    "levtype": "sfc",
    "param": "tp",
    "step": "0-12",
    "stream": "mdfa",
    "type": "fc",
    "area" : "75/-15/30/35",
    "format": "netcdf",
    "target": "",