Versions Compared

Key

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

...

Code Block
languagepy
#!/usr/bin/env python
from ecmwfapi import ECMWFDataServer
server = ECMWFDataServer()

origin = "ammc"
modelVersionDate = "2014-01-01"

def retrieve_BoM_reforecast():
    """
       A function to demonstrate how to iterate efficiently over all hindcastYears, hindcastMonths etc
       for a particular BoM_reforecast_request.
       Change the variables below to adapt the iteration to your needs 
    """
    hindcastYearStart = 1981
    hindcastYearEnd = 2013
    hindcastMonthStart = 1
    hindcastMonthEnd = 12
    hindcastDays = list(range(1, 27, 5)) # BoM availability is every 5 days: 1, 6, 11, 16, 21, 26 

    for hindcastYear in list(range(hindcastYearStart, hindcastYearEnd + 1)):
        for hindcastMonth in list(range(hindcastMonthStart, hindcastMonthEnd + 1)):
            hindcastDates = []
            for hindcastDay in hindcastDays:
                hindcastDate = '%04d%02d%02d' % (
                    hindcastYear, hindcastMonth, hindcastDay)
                hindcastDates.append(hindcastDate)
            target
            sfcTarget = "%s%04d%02d%s.grb" % (origin, hindcastYear, hindcastMonth, "sfc")
            BoM_reforecast_cf_pl_request("/".join(hindcastDates), sfcTarget)

            plTarget = "%s%04d%02d%s%04d%02d%s.grb" % (origin, hindcastYear, hindcastMonth, "pl")
            BoM_reforecast_cf_pl_request("/".join(hindcastDates), targetplTarget)

def BoM_reforecast_cf_pl_request(hindcastDate, target):
    """
       A BoM reforecast, control forecast, pressure level, request. 
       Change the keywords below to adapt it to your needs.
    """
    server.retrieve({
        "class": "s2",
        "dataset": "s2s",
        "date": modelVersionDate,
        "expver": "prod",
        "hdate": hindcastDate,
        "levtype": "pl",
        "levelist": "500/700/850/925/10001/2/3/4/5/6/7/8/9/10/11/12/13/14/15/16/17/18/19/20/21/22/23/24/25/26/27/28/29/30/31/32",
        "origin": origin,
        "param": "130/131/132/133/135/156",
        "step": "24/to/1488/by/24",
        "stream": "enfh",
        "target": target,
        "time": "00",
        "number": "1/to/32",
        "type": "pf",
    })

def BoM_reforecast_cf_sfc_request(hindcastDate, target):
    """
       A BoM reforecast, control forecast, sfc request. 
       Change the keywords below to adapt it to your needs.
    """
    server.retrieve({
        "class": "s2",
        "dataset": "s2s",
        "date": modelVersionDate,
        "expver": "prod",
        "hdate": hindcastDate,
        "levtype": "sfc",
        "origin": origin,
        "param": "31/34/121/122/136/146/147/151/167/168/169/175/176/177/179/180/181/235/228086/228095/228096/228141/228143/228144/228164/228228",
        "step": "24/to/7201488/by/24",
        "stream": "enfh",
        "target": target,
        "time": "00",
        "number": "1/to/32",
        "type": "pf",
    })


if if __name__ == '__main__':
    retrieve_BoM_reforecast()     

...