You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 13 Next »

Step-by-step guide

Local definitions are required when one needs to store information which is not part of the standard GRIB header. This would typically be a mars key (like class, stream, type and version number or experiment identifier, expver) or information that the data producer wants to have in each GRIB for convenience.

  1. Local definitions have a version, and they are stored in different sections depending on the GRIB edition:

  2. In ecCodes, local definitions are defined using a combination of the originating centre and the version of the local definition:

    /usr/local/share/eccodes/definitions/grib[edition]/local.[centre].[localDefinitionNumber].def
  3. For example, ECMWF's local definition 1 for GRIB 1 data is defined in a file called:

    /usr/local/share/eccodes/definitions/grib1/local.98.1.def
  4. A sample local definition is defined here:

    local.98.1.def
    template mars_labeling "grib1/mars_labeling.def";
    
    unsigned[1] perturbationNumber           : dump;
    alias       number = perturbationNumber;
    
    unsigned[1] numberOfForecastsInEnsemble  : dump;
    alias       totalNumber=numberOfForecastsInEnsemble;
    
    pad padding_local1_1(1);
  5. and the MARS labelling present on each ECMWF local definition is included from a separate file mars_labelling.def, which is shown below:

    /usr/local/share/eccodes/definitions/grib1/mars_labelling.def
    codetable[1] marsClass   "mars/class.table" = "od" : dump,lowercase;
    codetable[1] marsType    "mars/type.table" = "an" : dump,string_type,lowercase;
    codetable[2] marsStream  "mars/stream.table" = "oper" : dump,lowercase ;
    ksec1expver[4] experimentVersionNumber = "0001" : dump;
    
    alias mars.class  = marsClass;
    alias mars.type   = marsType;
    alias mars.stream = marsStream;
    alias mars.expver = experimentVersionNumber;
  6. Example of a GRIB2 local definition

    Suppose we want to add a GRIB2 local definition for a given centre (let's say code 87). The local definition will have some integer keys and a string key.
    So first we create the file "grib2LocalSectionNumber.87.table" and place it in the definitions/grib2 directory. This is a codetable with codes for the local definition numbers and a brief description.

    grib2LocalSectionNumber.87.table
    0 0 Empty local section
    1 1 Example local definition for centre 87
    255 255 MISSING
  7. Now create the file "local.87.def" which is a template for all the local definitions for this centre:

    local.87.def
    # Local section for example
    alias localDefinitionNumber=grib2LocalSectionNumber;
    template  localSection  "grib2/local.[centreForLocal:l].[grib2LocalSectionNumber:l].def";
    # MARS Labelling
    template mars_labeling "grib2/mars_labeling.def";
    position offsetAfterLocalSection;

    Here we assume we need the MARS keys as well (this allows archiving such GRIB messages)

  8. Now let's finally create the actual local definition (number 1):

    local.87.1.def
    unsigned[2] myVersion : dump ;
    ascii[10]   myName    : dump ;
    unsigned[1] myNumber  : dump ;

    Here we assign 2 bytes to the myVersion field (a positive integer), 10 bytes to the ASCII character string myName and 1 byte to the final myNumber integer.

  9. Creating your own tables

    Sites can create their own tables in order to adapt ecCodes to their needs. The clear candidates for site specific tables are:

    • class, used at ECMWF to define a system (like operations: od or research: rd) or a project (like ERA-40: e4, ERA-Interim: ei, MACC: mc or TIGGE: ti). Examples of mars classes used at ECMWF are listed on the webmars catalogue
    • stream, used at ECMWF to define a forecasting system within a class (like oper for the deterministic system, enfo for ensemble forecast or seas for seasonal forecast). Examples of mars streams under class od used at ECMWF are listed on the webmars catalogue
  10. In order to override the above, you can create files with your own content, for example:

    /usr/site/eccodes/definitions/mars/class.table
    # GRIBcode   Acronym    Long name
    1            so         Site operations
    2            sr         Site research
    /usr/site/eccodes/definitions/mars/stream.table
    # GRIBcode   Acronym    Long name
    1001         eebc       Ensemble using ECMWF data as Boundary Conditions
    1002         eeic       Ensemble using ECMWF data as Initial Conditions
  11. Another candidate for local adaptation is the handling of local parameters. The standard parameter descriptions are contained in the files name.def, paramId.def, shortName.def and units.def in directories:

    /usr/local/share/eccodes/definitions/grib[edition]
  12. The parameter descriptions for a given centre are contained in the files directories:

    /usr/local/share/eccodes/definitions/grib[edition]/localConcepts/[centre:s]
  13. The following are examples of the contents for the above files in order to handle ECMWF parameter Geopotential in GRIB edition 1:

    /usr/local/share/eccodes/definitions/grib1/localConcepts/ecmf/name.def
    #Geopotential
    'Geopotential' = {
             table2Version = 128 ;
             indicatorOfParameter = 129 ;
            }
    /usr/local/share/eccodes/definitions/grib1/localConcepts/ecmf/paramId.def
     #Geopotential
    '129' = {
             table2Version = 128 ;
             indicatorOfParameter = 129 ;
            }
    /usr/local/share/eccodes/definitions/grib1/localConcepts/ecmf/shortName.def
    #Geopotential
    'z' = {
             table2Version = 128 ;
             indicatorOfParameter = 129 ;
            } 
    /usr/local/share/eccodes/definitions/grib1/localConcepts/ecmf/units.def
    #Geopotential
    'm**2 s**-2' = {
             table2Version = 128 ;
             indicatorOfParameter = 129 ;
            }
  14. In GRIB edition 2, the contents of the same files for parameter Geopotential are:

    /usr/local/share/eccodes/definitions/grib2/localConcepts/ecmf/name.def
    #Geopotential
    'Geopotential' = {
             discipline = 0 ;
             parameterCategory = 3 ;
             parameterNumber = 4 ;
            }
    /usr/local/share/eccodes/definitions/grib2/localConcepts/ecmf/paramId.def
     #Geopotential
    '129' = {
             discipline = 0 ;
             parameterCategory = 3 ;
             parameterNumber = 4 ;
            }
    /usr/local/share/eccodes/definitions/grib2/localConcepts/ecmf/shortName.def
    #Geopotential
    'z' = {
             discipline = 0 ;
             parameterCategory = 3 ;
             parameterNumber = 4 ;
            }
    /usr/local/share/eccodes/definitions/grib2/localConcepts/ecmf/units.def
    #Geopotential
    'm**2 s**-2' = {
             discipline = 0 ;
             parameterCategory = 3 ;
             parameterNumber = 4 ;
            }
  15. Install and test your changes

    ecCodes can be instructed to search for definition files in one or more directory trees with environment variable ECCODES_DEFINITION_PATH. All the site specific files have to be stored in a sub-directory tree similar to the hierarchy of the ecCodes distribution. Then, the site specific directory has to be included first in the search path. For example:

    ECCODES_DEFINITION_PATH=/usr/site/eccodes/definitions:/usr/local/share/eccodes/definitions

    The tool codes_info will tell you if you are using this environment variable or using the standard location for definitions.

  16. To test the local definition we added earlier, you can take a GRIB2 sample file and change its centre to 87 and add the local definition to it:

    > grib_set -s centre=87,setLocalDefinition=1,localDefinitionNumber=1 GRIB2.tmpl out.grib2

    Now dump the out.grib2 file to check its section 2 contents to make sure your local definition keys are there

    (smile)


See the slides in this Training course presentation.
Also the How-To Article GRIB: Converting edition 1 to 2 (The "Local configuration" section)



  • No labels