Commit 18450d18 authored by Ludvig Isaksson's avatar Ludvig Isaksson
Browse files

cds complete added

parent 24533d91
# Copernicus Climate Change Service regional reanalysis for Europe - User Examples # Copernicus Climate Change Service regional reanalysis for Europe - User Examples
This project contains example code for users of the Copernicus Climate Change Service regional reanalysis for Europe (C3S_322_Lot1) data. More information about the service can be found at the [Copernicus Climate Change Service regional reanalysis for Europe website](https://climate.copernicus.eu/copernicus-regional-reanalysis-europe-cerra). This project contains example code for users of the Copernicus Climate Change Service regional reanalysis for Europe (C3S_322_Lot1) data. More information about the service can be found at the [Copernicus Climate Change Service regional reanalysis for Europe website](https://climate.copernicus.eu/copernicus-regional-reanalysis-europe-cerra).
The reanalysis data used here were initially produced within the FP7 pre-operational UERRA project.<br /> The reanalysis data used here were initially produced within the FP7 pre-operational UERRA project.<br />
More information about the reanalyses systems and data can be found at the [UERRA website](http://www.uerra.eu/). More information about the reanalyses systems and data can be found at the [UERRA website](http://www.uerra.eu/).
## CDS retrieval examples ## CDS retrieval examples
All data produced within the Copernicus Climate Change Service regional reanalysis for Europe and the pre-operational UERRA project are publicly available for download. The analyses are listed in the [Copernicus Climate Data Store (CDS)](https://cds.climate.copernicus.eu/cdsapp#!/search?type=dataset&text=uerra) and can be downloaded via the Copernicus Climate Data Store API (CDS API). All data produced within the Copernicus Climate Change Service regional reanalysis for Europe and the pre-operational UERRA project are publicly available for download. The analyses are listed in the [Copernicus Climate Data Store (CDS)](https://cds.climate.copernicus.eu/cdsapp#!/search?type=dataset&text=uerra) and can also be examined and downloaded using the CDS web GUI. The complete datasets (including forecast data) can only be downloaded via the Copernicus Climate Data Store API (CDS API) or the ECMWF MARS system.
The examples provided here use the python CDS API client. The examples provided here use the python CDS API client.
Information about prerequisites for running these examples can be found at the [CDS website](https://cds.climate.copernicus.eu/api-how-to). Information about prerequisites for running these examples can be found at the [CDS website](https://cds.climate.copernicus.eu/api-how-to).
The folder ["cds_retrieve_analyses_examples"](cds_retrieve_analyses_examples/) contains an example python script for retrieving analysis data from the Copernicus Climate Change Service regional reanalysis for Europe via the CDS API.<br /> The folder ["cds_retrieve_analyses_examples"](cds_retrieve_analyses_examples/) contains an example python script for retrieving analysis data from the Copernicus Climate Change Service regional reanalysis for Europe via the CDS API.<br />
Modify the date, time and parameter to match your specific needs. Modify the date, time and parameter to match your specific needs.
## MARS retrieval examples The folder ["cds_retrieve_complete_examples"](cds_retrieve_analyses_examples/) contains example python scripts for retrieving forecast data from the Copernicus Climate Change Service regional reanalysis for Europe via the CDS API.<br />
All the data produced are publicly available for download via the ECMWF MARS system. Modify the date, time and parameter to match your specific needs.
The examples provided here uses the python ECMWF Web-API client.
Information about prerequisites for running these examples can be found at the [ECMWF website](https://software.ecmwf.int/wiki/display/WEBAPI/Access+ECMWF+Public+Datasets). ## MARS retrieval examples
All the data produced are publicly available for download via the ECMWF MARS system.
The folder ["mars_retrieve_examples"](mars_retrieve_examples/) contains example python scripts for retrieving temperature and 24 hour precipitation data from the Copernicus Climate Change Service regional reanalysis for Europe reanalysis via the ECMWF MARS system.<br /> The examples provided here uses the python ECMWF Web-API client.
Modify the time, parameters, levels etc. to match your specific needs. Information about prerequisites for running these examples can be found at the [ECMWF website](https://software.ecmwf.int/wiki/display/WEBAPI/Access+ECMWF+Public+Datasets).
The folder ["mars_retrieve_total"](mars_retrieve_total/) contains python scripts for retrieving all datasets from the Copernicus Climate Change Service regional reanalysis for Europe reanalysis via the ECMWF MARS system.<br /> The folder ["mars_retrieve_examples"](mars_retrieve_examples/) contains example python scripts for retrieving temperature and 24 hour precipitation data from the Copernicus Climate Change Service regional reanalysis for Europe reanalysis via the ECMWF MARS system.<br />
The scripts are provided as a complete base showing all available data. Please note that this means a lot of data. Modify the time, parameters, levels etc. to match your specific needs. Modify the time, parameters, levels etc. to match your specific needs.
## Create forcing data for NEMO-Nordic The folder ["mars_retrieve_total"](mars_retrieve_total/) contains python scripts for retrieving all datasets from the Copernicus Climate Change Service regional reanalysis for Europe reanalysis via the ECMWF MARS system.<br />
The folder ["create_forcing_for_NEMO"](create_forcing_for_NEMO/) contains a script system, which can be used to prepare forcing data for NEMO-Nordic (a regional ocean model). The scripts retrieve hourly data from MARS and mix analyses and forecasts. Then, the data is post-processed for the usage with NEMO-Nordic. For instance, relative humidity is transferred to specific humidity. At the end, the data is stored in netcdf-format as needed by NEMO. The scripts are provided as a complete base showing all available data. Please note that this means a lot of data. Modify the time, parameters, levels etc. to match your specific needs.
## Create forcing data for NEMO-Nordic
The folder ["create_forcing_for_NEMO"](create_forcing_for_NEMO/) contains a script system, which can be used to prepare forcing data for NEMO-Nordic (a regional ocean model). The scripts retrieve hourly data from MARS and mix analyses and forecasts. Then, the data is post-processed for the usage with NEMO-Nordic. For instance, relative humidity is transferred to specific humidity. At the end, the data is stored in netcdf-format as needed by NEMO.
#!/usr/bin/env python #!/usr/bin/env python
import cdsapi import cdsapi
import calendar import calendar
c = cdsapi.Client() c = cdsapi.Client()
def retrieve_uerra(): def retrieve_uerra():
""" """
A function to demonstrate how to iterate over several years and months etc A function to demonstrate how to iterate over several years and months etc
for a particular UERRA request for origin UERRA-HARMONIE. for a particular UERRA request for origin UERRA-HARMONIE.
Change the variables below to adapt the iteration to your needs. Change the variables below to adapt the iteration to your needs.
You can use the variable 'targetFile' to organise the requested data in files as you wish. You can use the variable 'targetFile' to organise the requested data in files as you wish.
In the example below the data are organised in files per month. In the example below the data are organised in files per month.
""" """
yearStart = 2015 yearStart = 2015
yearEnd = 2015 yearEnd = 2015
monthStart = 1 monthStart = 1
monthEnd = 12 monthEnd = 12
for year in list(range(yearStart, yearEnd + 1)): for year in list(range(yearStart, yearEnd + 1)):
for month in list(range(monthStart, monthEnd + 1)): for month in list(range(monthStart, monthEnd + 1)):
numberOfDays = calendar.monthrange(year, month)[1] numberOfDays = calendar.monthrange(year, month)[1]
targetFile = "ofile_%04d%02d.grb" % (year, month) targetFile = "ofile_%04d%02d.grb" % (year, month)
requestDates = ['{:02}'.format(i) for i in range(1, numberOfDays+1)] requestDates = ['{:02}'.format(i) for i in range(1, numberOfDays+1)]
requestMonth = '{:02}'.format(month) requestMonth = '{:02}'.format(month)
requestYear = '{:04}'.format(year) requestYear = '{:04}'.format(year)
uerra_request(requestYear, requestMonth, requestDates, targetFile) uerra_request(requestYear, requestMonth, requestDates, targetFile)
def uerra_request(reqYear, reqMonth, reqDates, target): def uerra_request(reqYear, reqMonth, reqDates, target):
""" """
A UERRA request for 2 metre temperature every 6th hour. A UERRA request for 2 metre temperature every 6th hour.
Origin uerra_harmonie, surface level, analysis fields. Origin uerra_harmonie, surface level, analysis fields.
Request cost per day is 4 fields, 1.8 Mbytes. Request cost per day is 4 fields, 1.8 Mbytes.
""" """
c.retrieve( c.retrieve(
'reanalysis-uerra-europe-single-levels', 'reanalysis-uerra-europe-single-levels',
{ {
'format':'grib', 'format':'grib',
'variable':'2m_temperature', 'variable':'2m_temperature',
'year':reqYear, 'year':reqYear,
'month':reqMonth, 'month':reqMonth,
'day':reqDates, 'day':reqDates,
'time':['00:00','06:00','12:00','18:00'], 'time':['00:00','06:00','12:00','18:00'],
'origin':'uerra_harmonie' 'origin':'uerra_harmonie'
}, },
target) target)
if __name__ == '__main__': if __name__ == '__main__':
retrieve_uerra() retrieve_uerra()
# CDS analyses data retrieval examples # CDS analyses data retrieval examples
All data produced within the Copernicus Climate Change Service regional reanalysis for Europe and the pre-operational UERRA project are publicly available for download. All data produced within the Copernicus Climate Change Service regional reanalysis for Europe and the pre-operational UERRA project are publicly available for download.
This is an example of retrieving UERRA analyses data from one of the [CDS listed datasets](https://cds.climate.copernicus.eu/cdsapp#!/search?type=dataset&text=uerra). Please note that only the analyses are available via CDS. All other data (e.g. hourly forecasts) must be downloaded via the ECMWF MARS system. See examples in the ["mars_retrieve_examples"](./../mars_retrieve_examples/) folder. This is an example of retrieving UERRA analyses data from one of the [CDS listed datasets](https://cds.climate.copernicus.eu/cdsapp#!/search?type=dataset&text=uerra). Please note that this retrieval method is only applicable for analyses data. All other data (e.g. hourly forecasts) must be downloaded via the methods described in the ["cds_retrieve_complete_examples"](./../cds_retrieve_complete_examples/) folder or the ["mars_retrieve_examples"](./../mars_retrieve_examples/) folder.
Before running this script it is recommended to explore the available data and the corresponding CDS API requests by browsing the [CDS datasets](https://cds.climate.copernicus.eu/cdsapp#!/search?type=dataset&text=uerra). Before running this script it is recommended to explore the available data and the corresponding CDS API requests by browsing the [CDS datasets](https://cds.climate.copernicus.eu/cdsapp#!/search?type=dataset&text=uerra).
Then modify the time, parameter and data origin in the script to match your specific needs. Then modify the time, parameter and data origin in the script to match your specific needs.
The example provided here uses the python CDS API client. The example provided here uses the python CDS API client.
Information about prerequisites for running this example can be found at the [CDS website](https://cds.climate.copernicus.eu/api-how-to). Information about prerequisites for running this example can be found at the [CDS website](https://cds.climate.copernicus.eu/api-how-to).
## General information ## General information
This project contains example code for users of the Copernicus Climate Change Service regional reanalysis for Europe (C3S_322_Lot1) data. This project contains example code for users of the Copernicus Climate Change Service regional reanalysis for Europe (C3S_322_Lot1) data.
More information about the service can be found at the [Copernicus Climate Change Service regional reanalysis for Europe website](https://climate.copernicus.eu/copernicus-regional-reanalysis-europe-cerra). More information about the service can be found at the [Copernicus Climate Change Service regional reanalysis for Europe website](https://climate.copernicus.eu/copernicus-regional-reanalysis-europe-cerra).
The reanalysis data were initially produced within the FP7 pre-operational UERRA project. The reanalysis data were initially produced within the FP7 pre-operational UERRA project.
More information about the reanalyses systems and data can be found at the [UERRA website](http://www.uerra.eu/). More information about the reanalyses systems and data can be found at the [UERRA website](http://www.uerra.eu/).
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
# Create forcing data for NEMO-Nordic # Create forcing data for NEMO-Nordic
These scripts are an example of how the UERRA data can be used for input to other model systems, in this case the NEMO-Nordic (a regional ocean model). These scripts are an example of how the UERRA data can be used for input to other model systems, in this case the NEMO-Nordic (a regional ocean model).
The objectives of the scripts The objectives of the scripts
----------------------------- -----------------------------
These scripts will: These scripts will:
1. download the needed, 1. download the needed,
2. extract the region needed for NEMO-Nordic, 2. extract the region needed for NEMO-Nordic,
3. convert the units as needed for NEMO-Nordic, 3. convert the units as needed for NEMO-Nordic,
4. save the final files as netCDF. 4. save the final files as netCDF.
Instructions Instructions
------------ ------------
Basically, users have only to adopt the "Configure section" in the Basically, users have only to adopt the "Configure section" in the
main script - Create_NEMO_forcing_from_UERRA.py main script - Create_NEMO_forcing_from_UERRA.py
1. Set the dates your are interested in. 1. Set the dates your are interested in.
2. Define directories for downloaded data, the final data, and 2. Define directories for downloaded data, the final data, and
a directory for temporary files. a directory for temporary files.
Then, all you have to do is to run the main script... Then, all you have to do is to run the main script...
Create_NEMO_forcing_from_UERRA.py Create_NEMO_forcing_from_UERRA.py
Good to know Good to know
------------ ------------
The scripts need some time to run. Especially the downloading of data The scripts need some time to run. Especially the downloading of data
from the MARS archive takes time. Here, we are talking about days if from the MARS archive takes time. Here, we are talking about days if
you want to produce forcing data for longer periods (several years). you want to produce forcing data for longer periods (several years).
A rough estimate is about six hours for each year. However, this depends A rough estimate is about six hours for each year. However, this depends
on your system as well as the load on MARS. on your system as well as the load on MARS.
You will need some disk space. For each year you will need around 50GB You will need some disk space. For each year you will need around 50GB
space. space.
Technical details Technical details
----------------- -----------------
The scripts were developed and tested with Python 2.7.9. The scripts were developed and tested with Python 2.7.9.
The scripts use [CDO](http://mpimet.mpg.de/cdo) commands to a large degree so the CDO python bindings need to be installed. The scripts use [CDO](http://mpimet.mpg.de/cdo) commands to a large degree so the CDO python bindings need to be installed.
Below is info from the cdo -V command:<br> Below is info from the cdo -V command:<br>
Climate Data Operators version 1.7.0 (http://mpimet.mpg.de/cdo)<br> Climate Data Operators version 1.7.0 (http://mpimet.mpg.de/cdo)<br>
Features: DATA PTHREADS OpenMP4 HDF5 NC4/HDF5 OPeNDAP Z PROJ.4 SSE2<br> Features: DATA PTHREADS OpenMP4 HDF5 NC4/HDF5 OPeNDAP Z PROJ.4 SSE2<br>
Libraries: HDF5/1.8.14 proj/4.7<br> Libraries: HDF5/1.8.14 proj/4.7<br>
Filetypes: srv ext ieg grb grb2 nc nc2 nc4 nc4c CDI library version : 1.7.0<br> CGRIBEX library version : 1.7.3 <br> Filetypes: srv ext ieg grb grb2 nc nc2 nc4 nc4c CDI library version : 1.7.0<br> CGRIBEX library version : 1.7.3 <br>
GRIB_API library version : 1.14.0 <br> GRIB_API library version : 1.14.0 <br>
netCDF library version : 4.3.2<br> netCDF library version : 4.3.2<br>
HDF5 library version : 1.8.14<br> HDF5 library version : 1.8.14<br>
Moreover, to fetch data from the MARS archive, you will need the Moreover, to fetch data from the MARS archive, you will need the
corresponding modules. Please find out on [ECMWF's website](https://software.ecmwf.int/wiki/display/WEBAPI/Access+ECMWF+Public+Datasets). corresponding modules. Please find out on [ECMWF's website](https://software.ecmwf.int/wiki/display/WEBAPI/Access+ECMWF+Public+Datasets).
Otherwise, used modules should be standard. Otherwise, used modules should be standard.
Overview on the order of called routines Overview on the order of called routines
---------------------------------------- ----------------------------------------
Create_NEMO_forcing_from_UERRA.py<br> Create_NEMO_forcing_from_UERRA.py<br>
==> Get_UERRA_data.py<br> ==> Get_UERRA_data.py<br>
&nbsp;&nbsp;&nbsp;&nbsp;==> a) Get_UERRA_data.py<br> &nbsp;&nbsp;&nbsp;&nbsp;==> a) Get_UERRA_data.py<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;==> Forecasts<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;==> Forecasts<br>
&nbsp;&nbsp;&nbsp;&nbsp;==> b) Get_UERRA_data.py<br> &nbsp;&nbsp;&nbsp;&nbsp;==> b) Get_UERRA_data.py<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;==> Analyses<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;==> Analyses<br>
&nbsp;&nbsp;&nbsp;&nbsp;==> c) Get_UERRA_data.py<br> &nbsp;&nbsp;&nbsp;&nbsp;==> c) Get_UERRA_data.py<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;==> Precipitation (differences incorporated)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;==> Precipitation (differences incorporated)<br>
==> Convert_for_NEMO.py<br> ==> Convert_for_NEMO.py<br>
&nbsp;&nbsp;&nbsp;&nbsp;==> a) Convert_for_NEMO.py<br> &nbsp;&nbsp;&nbsp;&nbsp;==> a) Convert_for_NEMO.py<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;==> Precipitation<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;==> Precipitation<br>
&nbsp;&nbsp;&nbsp;&nbsp;==> b) Convert_for_NEMO.py<br> &nbsp;&nbsp;&nbsp;&nbsp;==> b) Convert_for_NEMO.py<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;==> Parameters with analysis<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;==> Parameters with analysis<br>
&nbsp;&nbsp;&nbsp;&nbsp;==> c) Convert_for_NEMO.py<br> &nbsp;&nbsp;&nbsp;&nbsp;==> c) Convert_for_NEMO.py<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;==> Radiation<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;==> Radiation<br>
&nbsp;&nbsp;&nbsp;&nbsp;==> d) Convert_for_NEMO.py<br> &nbsp;&nbsp;&nbsp;&nbsp;==> d) Convert_for_NEMO.py<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;==> Humidity<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;==> Humidity<br>
## General information ## General information
This project contains example code for users of the Copernicus Climate Change Service regional reanalysis for Europe (C3S_322_Lot1) data. This project contains example code for users of the Copernicus Climate Change Service regional reanalysis for Europe (C3S_322_Lot1) data.
More information about the service can be found at the [Copernicus Climate Change Service regional reanalysis for Europe website](https://climate.copernicus.eu/copernicus-regional-reanalysis-europe-cerra). More information about the service can be found at the [Copernicus Climate Change Service regional reanalysis for Europe website](https://climate.copernicus.eu/copernicus-regional-reanalysis-europe-cerra).
The reanalysis data were initially produced within the FP7 pre-operational UERRA project. The reanalysis data were initially produced within the FP7 pre-operational UERRA project.
More information about the reanalyses systems and data can be found at the [UERRA website](http://www.uerra.eu/). More information about the reanalyses systems and data can be found at the [UERRA website](http://www.uerra.eu/).
File mode changed from 100644 to 100755
#!/usr/bin/env python #!/usr/bin/env python
import calendar import calendar
from ecmwfapi import ECMWFDataServer from ecmwfapi import ECMWFDataServer
server = ECMWFDataServer() server = ECMWFDataServer()
def retrieve_uerra_lfpw(): def retrieve_uerra_lfpw():
""" """
A function to demonstrate how to iterate efficiently over several years and months etc A function to demonstrate how to iterate efficiently over several years and months etc
for a particular UERRA request for origin Meteo France. for a particular UERRA request for origin Meteo France.
Change the variables below to adapt the iteration to your needs. Change the variables below to adapt the iteration to your needs.
You can use the variable 'target' to organise the requested data in files as you wish. You can use the variable 'target' to organise the requested data in files as you wish.
In the example below the data are organised in files per month. In the example below the data are organised in files per month.
""" """
yearStart = 2015 yearStart = 2015
yearEnd = 2015 yearEnd = 2015
monthStart = 1 monthStart = 1
monthEnd = 12 monthEnd = 12
for year in list(range(yearStart, yearEnd + 1)): for year in list(range(yearStart, yearEnd + 1)):
for month in list(range(monthStart, monthEnd + 1)): for month in list(range(monthStart, monthEnd + 1)):
startDate = '%04d%02d%02d' % (year, month, 1) startDate = '%04d%02d%02d' % (year, month, 1)
numberOfDays = calendar.monthrange(year, month)[1] numberOfDays = calendar.monthrange(year, month)[1]
lastDate = '%04d%02d%02d' % (year, month, numberOfDays) lastDate = '%04d%02d%02d' % (year, month, numberOfDays)
target = "ofile_%04d%02d.grb" % (year, month) target = "ofile_%04d%02d.grb" % (year, month)
requestDates = (startDate + "/TO/" + lastDate) requestDates = (startDate + "/TO/" + lastDate)
uerra_lfpw_request(requestDates, target) uerra_lfpw_request(requestDates, target)
def uerra_lfpw_request(requestDates, target): def uerra_lfpw_request(requestDates, target):
""" """
A UERRA request for 2 metre temperature every 6 hours. A UERRA request for 2 metre temperature every 6 hours.
Origin Meteo France, surface level, analysis fields. Origin Meteo France, surface level, analysis fields.
Request cost per day is 4 fields, 8.7 Mbytes. Request cost per day is 4 fields, 8.7 Mbytes.
""" """
server.retrieve({ server.retrieve({
"class": "ur", "class": "ur",
"stream": "oper", "stream": "oper",
"type": "an", "type": "an",
"dataset": "uerra", "dataset": "uerra",
"origin" : "lfpw", "origin" : "lfpw",
"date": requestDates, "date": requestDates,
"expver": "prod", "expver": "prod",
"levtype": "sfc", "levtype": "sfc",
"param": "167", "param": "167",
"target": target, "target": target,
"time": "00/06/12/18" "time": "00/06/12/18"
}) })
if __name__ == '__main__': if __name__ == '__main__':
retrieve_uerra_lfpw() retrieve_uerra_lfpw()
#!/usr/bin/env python #!/usr/bin/env python
import calendar import calendar
from ecmwfapi import ECMWFDataServer from ecmwfapi import ECMWFDataServer
server = ECMWFDataServer() server = ECMWFDataServer()
def retrieve_uerra_eswi(): def retrieve_uerra_eswi():
""" """
A function to demonstrate how to iterate efficiently over several years and months etc A function to demonstrate how to iterate efficiently over several years and months etc
for a particular UERRA request for origin SMHI. for a particular UERRA request for origin SMHI.
Change the variables below to adapt the iteration to your needs. Change the variables below to adapt the iteration to your needs.
You can use the variable 'target' to organise the requested data in files as you wish. You can use the variable 'target' to organise the requested data in files as you wish.
In the example below the data are organised in files per month. In the example below the data are organised in files per month.
""" """
yearStart = 2016 yearStart = 2016
yearEnd = 2016 yearEnd = 2016
monthStart = 1 monthStart = 1
monthEnd = 12 monthEnd = 12
for year in list(range(yearStart, yearEnd + 1)): for year in list(range(yearStart, yearEnd + 1)):
for month in list(range(monthStart, monthEnd + 1)): for month in list(range(monthStart, monthEnd + 1)):
startDate = '%04d%02d%02d' % (year, month, 1) startDate = '%04d%02d%02d' % (year, month, 1)
numberOfDays = calendar.monthrange(year, month)[1] numberOfDays = calendar.monthrange(year, month)[1]
lastDate = '%04d%02d%02d' % (year, month, numberOfDays) lastDate = '%04d%02d%02d' % (year, month, numberOfDays)
target = "ofile_%04d%02d.grb" % (year, month) target = "ofile_%04d%02d.grb" % (year, month)
requestDates = (startDate + "/TO/" + lastDate) requestDates = (startDate + "/TO/" + lastDate)
uerra_eswi_request(requestDates, target) uerra_eswi_request(requestDates, target)
def uerra_eswi_request(requestDates, target): def uerra_eswi_request(requestDates, target):
""" """
A UERRA request for 2 metre temperature every hour. A UERRA request for 2 metre temperature every hour.
Origin SMHI, surface level, forecast fields. Origin SMHI, surface level, forecast fields.
Request cost per day is 24 fields, 11 Mbytes. Request cost per day is 24 fields, 11 Mbytes.
""" """
server.retrieve({ server.retrieve({
"class": "ur", "class": "ur",
"stream": "oper", "stream": "oper",
"type": "fc", "type": "fc",
"dataset": "uerra", "dataset": "uerra",
"origin" : "eswi", "origin" : "eswi",
"date": requestDates, "date": requestDates,
"expver": "prod", "expver": "prod",
"levtype": "sfc", "levtype": "sfc",
"param": "167", "param": "167",
"target": target, "target": target,
"time": "00/06/12/18", "time": "00/06/12/18",
"step": "1/2/3/4/5/6", "step": "1/2/3/4/5/6",
}) })
if __name__ == '__main__': if __name__ == '__main__':
retrieve_uerra_eswi() retrieve_uerra_eswi()
#!/usr/bin/env python #!/usr/bin/env python
import calendar import calendar
from ecmwfapi import ECMWFDataServer from ecmwfapi import ECMWFDataServer
server = ECMWFDataServer() server = ECMWFDataServer()
def retrieve_uerra_lfpw(): def retrieve_uerra_lfpw():
""" """
A function to demonstrate how to iterate efficiently over several years and months etc A function to demonstrate how to iterate efficiently over several years and months etc
for a particular UERRA request for origin Meteo France. for a particular UERRA request for origin Meteo France.
Change the variables below to adapt the iteration to your needs. Change the variables below to adapt the iteration to your needs.
You can use the variable 'target' to organise the requested data in files as you wish. You can use the variable 'target' to organise the requested data in files as you wish.
In the example below the data are organised in files per month. In the example below the data are organised in files per month.
""" """
yearStart = 2015 yearStart = 2015
yearEnd = 2015 yearEnd = 2015
monthStart = 1 monthStart = 1
monthEnd = 12 monthEnd = 12
for year in list(range(yearStart, yearEnd + 1)): for year in list(range(yearStart, yearEnd + 1)):
for month in list(range(monthStart, monthEnd + 1)): for month in list(range(monthStart, monthEnd + 1)):
startDate = '%04d%02d%02d' % (year, month, 1) startDate = '%04d%02d%02d' % (year, month, 1)
numberOfDays = calendar.monthrange(year, month)[1] numberOfDays = calendar.monthrange(year, month)[1]
lastDate = '%04d%02d%02d' % (year, month, numberOfDays) lastDate = '%04d%02d%02d' % (year, month, numberOfDays)
target = "ofile_%04d%02d.grb" % (year, month) target = "ofile_%04d%02d.grb" % (year, month)
requestDates = (startDate + "/TO/" + lastDate) requestDates = (startDate + "/TO/" + lastDate)
uerra_lfpw_request(requestDates, target) uerra_lfpw_request(requestDates, target)
def uerra_lfpw_request(requestDates, target): def uerra_lfpw_request(requestDates, target):
""" """
A UERRA request for total precipitation every 24 hours at 06 UTC. A UERRA request for total precipitation every 24 hours at 06 UTC.
Origin Meteo France, surface level, analysis fields. Origin Meteo France, surface level, analysis fields.
Request cost per day is 1 field, 2.2 Mbytes.