...
| Code Block | ||
|---|---|---|
| ||
#!/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
# BoM availability is every 5 days: 1, 6, 11, 16, 21, 26
hindcastDays = list(range(1, 27, 5))
#Step 1:Iterate over all the available hindcastYear(s)
for hindcastYear in list(range(hindcastYearStart, hindcastYearEnd + 1)):
#Step 2: Iterate over all the available hindcastMonths(s)
for hindcastMonth in list(range(hindcastMonthStart, hindcastMonthEnd + 1)):
hindcastDates = []
#Step 3: Create the list of the available hindcastDates
for hindcastDay in hindcastDays:
hindcastDate = '%04d%02d%02d' % (
hindcastYear, hindcastMonth, hindcastDay)
hindcastDates.append(hindcastDate)
#Step #Get4: Get all the available perturbed forecast, pressure level data
pfplTarget = "%s_%s_%04d%02d.grb" % (
origin, "pfpl", hindcastYear, hindcastMonth)
BoM_reforecast_cf_pl_request("/".join(hindcastDates), pfplTarget)
#Step 5: Get all the #Getavailable perturbed forecast, surface data
pfsfcTarget = "%s_%s_%04d%02d.grb" % (
origin, "pfsfc", hindcastYear, hindcastMonth)
BoM_reforecast_cf_sfc_request("/".join(hindcastDates), pfsfcTarget)
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": "1/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/1488/by/24",
"stream": "enfh",
"target": target,
"time": "00",
"number": "1/to/32",
"type": "pf",
})
if __name__ == '__main__':
retrieve_BoM_reforecast()
|
...