Versions Compared

Key

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

...

Retrieval of "moda" files


The request below will retrieve all the available moda files from 200702 to 201512. This particular example is retrieving the 70 hPa zonal wind from rom_saf_22. The retrieval is grouped into decades rom_saf_moda_2000 contains the information from 200702 to 200912, and rom_saf-moda_2010 contains the information from 201001 to 201512.  




Code Block
languagepy
!/usr/bin/env python
import calendar
from ecmwfapi import ECMWFDataServer
server = ECMWFDataServer()
  
def retrieve_romsaf_data():
    '''     
       A function to demonstrate how to retrieve rom_saf monthly mean data.    
       Change the variables below to adapt to your needs.
 
       ROM SAF monthly data is timestamped to the first of the month, hence dates
       have to be specified as a listin this format:
       '20070201/20070301/20070401/.../20151101/20151201'.
       Note that 20070101 is not available 
 
       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:
       '20070201/20070201/20000301/.../20051101/20051201'
       In the example below the output data are organised as one file per decade:
       'romsaf_moda_2010'
       Please note that only decades 2000-2010 are available. The First available moda is 20070201!
    '''
    yearStart = 2007                           # adjust to your requirements - only 2007-02-01 to 2015-12-01 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
    months_2007 = [2,3,4,5,6,7,8,9,10,11,12]   # specific for 2007 because 200701 not computed

    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]
    decades.sort()
    print 'Decades:', decades
 
# loop through decades and create a month list
    for d in decades:
        requestDates=''
        for y in years:
            if ((divmod(y,10)[0])*10) == d:                
		if y == 2007:
		    for m in months_2007:
                       requestDates = requestDates+str(y)+(str(m)).zfill(2)+'01/'
                else:
		    for m in months:
                       requestDates = requestDates+str(y)+(str(m)).zfill(2)+'01/'
        
	requestDates = requestDates[:-1]
        print 'Requesting dates: ', requestDates
        target = 'romsaf_moda_22_%d.grb'% (d)    # specifies the output file name
        print 'Output file: ', target
        romsaf_request(requestDates, d, target)
 
# the actual data request
def romsaf_request(requestDates, decade, target):
    '''
        Change the keywords below to adapt to your needs.
        The easiest way to do this is:
        1. go to https://apps.ecmwf.int/mars-catalogue/?class=ea&stream=moda&expver=22
        2. click through to the parameters you want, for any date
        3. click 'View the MARS request'
    '''
    server.retrieve({
        'class': 'ea',              # do not change
        'dataset': 'rom_saf_22',    # or rom_saf_21
        'expver': '22',             # or 21
        'stream': 'moda',           # monthly means of daily means
        'type': 'an',               # analysis (versus forecast, fc)
        'levtype': 'pl',            # pressure data (versus pressure level, pl, and model level, ml)
        'levelist': '70',           # levels, required only with levtype:pl and levtype:ml
        'param': '131',             # zonal wind
        "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.
        '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__':
    retrieve_romsaf_data()

...