Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.


  • The objective of this example is to demonstrate how to iterate efficiently over some years, for a particular ERA-Interim, monthly, pressure level request.
  • At this point you may wish to have a look on the  ERA-Interim data availability  
  • The request below can be used as a starting point, however you need to keep in mind that you have to adapt it to your needseg to set the keyword, values according to your requirements (eg add or remove 'param', 'levtype', etc).
  • In this way you can extend this example to download a longer period or even the whole ERA-Interim dataset.

  • (warning) Please note that at the moment only decade 2010 is available.

Code Block
#!/usr/bin/env python
import calendar
from ecmwfapi import ECMWFDataServer
server = ECMWFDataServer()
def retrieve_era_interim():
       A function to demonstrate how to retrieve ERA-Interim monthly means data.    
       Change the variables below to adapt to your needs.
       ERA-Interim monthly data is timestamped to the first of the month, hence dates
       have to be specified as a list in this format:
       Data is stored on one tape per decade, so for efficiency we split the date range into
       decades, hence we get multiple date lists by decade:
       In the example below the output data are organised as one file per decade:
       Please note that at the moment only decade 2010 is available.
    yearStart = 1995                        # adjust to your requirements - as of 2017-07 only 2010-01-01 onwards is available
    yearEnd = 2015                          # adjust to your requirements
    months = [1,2,3,4,5,6,7,8,9,10,11,12]   # adjust to your requirements
    years = range(yearStart, yearEnd+1)
    print 'Years: ',years
    decades = list(set([divmod(i, 10)[0] for i in years]))
    decades = [x * 10 for x in decades]
    print 'Decades:', decades
# loop through decades and create a month list
    for d in decades:
        for y in years:
            if ((divmod(y,10)[0])*10) == d:
                for m in months:
                    requestDates = requestDates+str(y)+(str(m)).zfill(2)+'01/'
        requestDates = requestDates[:-1]
        print 'Requesting dates: ', requestDates
        target = 'era_interim_moda_%d'% (d)    # specifies the output file name
        print 'Output file: ', target
        era_interim_request(requestDates, d, target)
# the actual data request
def era_interim_request(requestDates, decade, target):
        Change the keywords below to adapt to your needs.
        The easiest way to do this is:
        1. go to
        2. click through to the parameters you want, for any date
        3. click 'View the MARS request'
        "class": "ei",              # do not change
        "dataset": "interim",       # do not change
        'expver': '1',              # do not change
        'stream': 'moda',           # monthly means of daily means
        'type': 'an',               # analysis (versus forecast, fc)
        'levtype': 'sfc',           # surface data (versus pressure level, pl, and model level, ml)
        'param': 'sst/msl',         # here: sea surface temperature (param 34) and mean sea level pressure (param 151)
        'grid': '0.75/0.75',        # horizontal resolution of output in degrees lat/lon
        'format': 'netcdf',         # get output in netcdf; only works with regular grids; for GRIB remove this line
        'date': requestDates,       # dates, set automatically from above
        'decade': decade,           # decade set automatically from above
        'target': target            # output file name, set automatically from above

if __name__ == '__main__':