Info |
---|
DocumentationThe ecCodes Python API is documented at: There are examples of how to use it at: Other useful resources: |
Preliminaries
Login to ecs-login and work in your $SCRATCH
...
Tip | ||
---|---|---|
Remember to load the ecmwf-toolbox and python3 !
|
This tutorial covers the following topics:
Table of Content Zone | ||||
---|---|---|---|---|
|
...
Info | ||
---|---|---|
| ||
Using the Python API to decode messages in a GRIB file |
The directory contains an example Python script called eccodes_demo.py which decodes data via a call to a function called grib_dump and some GRIB messages to be decoded in a file called grib_file.grib
...
No Format |
---|
$> grib_ls grib_file.grib ... $> grib_dump grib_file.grib |
Your challenge is to change the Python script eccodes_demo.py to replace the call to the function codes_dump with several calls to codes_get or codes_get_array to decode the values for the edition, date, time, paramId (or shortName) and level keys. Add your own print statements to output this information.
Expand | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||
The part of the script to change is in the example function, specifically line 47 should be commented (add a '#' to the start of the line containing "codes_dump(gid)") and replaced with calls to codes_get for each key value needed:
A possible solution is:
This example solution goes a little further than needed and also decodes and prints the first 20 data values for each message as well as the maximum, minimum and average of all the data values. |