Versions Compared

Key

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

...

Monthly data

When you extract monthly means, the monthly means are timestamped to the first day of the month, and you have to extract for exactly these dates. So to extract monthly means for all of 2015 you need to use this syntax to specify dates:

...

Code Block
languagepy
titleCode example
linenumberstrue
collapsetrue
#!/usr/bin/env python

# This script extracts the average daily precipitation for each month.

from datetime import datetime, timedelta

# Change the start and end dates to your desired date range. Monthly data is specified as the 1st of the month.
# For example, to get January 1979 to December 1980, use (1979, 1, 1) and (1980, 12, 1), respectively

start = datetime(1979, 1, 1)
end = datetime(1980, 12, 1)

datelist = [start.strftime('%Y-%m-%d')]
while start <= end:
    start += timedelta(days=32)
    datelist.append( datetime(start.year, start.month, 1).strftime('%Y-%m-%d') )
	datestring = "/".join(datelist)  

from ecmwfapi import ECMWFDataServer
serverc = ECMWFDataServercdsapi.Client()
serverc.retrieve({
    "class": "ei",
    "dataset": "interim",'reanalysis-era-interim',{
    "'date"': datestring,
    "expver": "1",
    "grid": "'grid': '0.75/0.75"',
    "'levtype"': "'sfc"',
    "'param"': "'tp"',
    "'step"': "'0-/12"',
    "'stream"': "'mdfa"',
    "'type"': "'fc"',
    "'area" ': "'75/-15/30/35"',
    "'format"': "'netcdf"',
    "target": ",
},'tp-mdfa-197901to198012.nc",
}')


Info
iconfalse

This document has been produced in the context of the Copernicus Climate Change Service (C3S).

The activities leading to these results have been contracted by the European Centre for Medium-Range Weather Forecasts, operator of C3S on behalf of the European Union (Delegation agreement signed on 11/11/2014). All information in this document is provided "as is" and no guarantee or warranty is given that the information is fit for any particular purpose.

The users thereof use the information at their sole risk and liability. For the avoidance of all doubt, the European Commission and the European Centre for Medium-Range Weather Forecasts have no liability in respect of this document, which is merely representing the author's view.

...