| DocumentationThe ecCodes Python API is documented at: There are examples of how to use it at: Other useful resources: | 
Login to ecs-login and work in your $SCRATCH
| $> cd $SCRATCH | 
Make a copy of the practicals directory in your $SCRATCH to Atos:
| $> tar –xvf /home/trx/grib_practicals.tar | 
This will create a directory in your $SCRATCH called grib_practicals containing the GRIB data files for this tutorial.
There are sub-directories for each practical:
| $> ls $SCRATCH/grib_practicals inspect modify python | 
For this tutorial cd to the python directory:
| $> cd $SCRATCH/grib_practicals/python | 
| Remember to load the ecmwf-toolbox and python3 ! 
 | 
This tutorial covers the following topics:
| 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
Run the Python script unchanged and redirect the output to a file using:
| $> ./eccodes_demo.py > output | 
Look at the text information written to the file called output. Compare with the output obtained with the grib_ls and grib_dump commands:
| $> grib_ls grib_file.grib ... $> grib_dump grib_file.grib | 
| 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. |