Versions Compared

Key

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

...

  • Let's see how we can change the script above to iterate over several hindcastYears, hindcastMonths and hindcastDays efficiently
  • Each hindcastDate is written into a separate file by setting the variable "target" accordingly.
  • Please note that the objective of this python script example is only to demonstrate how to make a MARS request efficient . You by iterating properly. 
  • It can be used as a starting point however you need to adapt it to your needseg:
    • to set the keywords values (eg hindcastYear)  according to your needs. (warning) Don't forget to check the availability!
    • to make it more "pythonic" (wink)
    • etc

(smile) By setting the variable "target" accordingly you can have each hindcastDate to be written on a separate file .

Code Block
languagepy
#!/usr/bin/env python
from ecmwfapi import ECMWFDataServer
server = ECMWFDataServer()
def retrieve_data(hindcastDate):
    target = "target_s2s_%s.grb" % hindcastDate
    server.retrieve({
       "class": "s2",
       "dataset": "s2s",
       "date": "2014-05-01",
       "expver": "prod",
       "hdate": hindcastDate,
       "levtype": "sfc",
       "origin": "babj",
       "param": "165",
       "step": "0",
       "stream": "enfh",
       "target": target,
       "time": "00",
       "type": "cf",
})

for hindcastYear in ["2012", "2013"]:
    for hindcastMonth in ["08", "09"]:
        for hindcastDay in ["01", "02"]:
            hindcastDate = hindcastYear+hindcastMonth+hindcastDay
            retrieve_data(hindcastDate)

...