Versions Compared

Key

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

...

The tables below show the mapping. Below that is some example Python code showing how this information can be used with ecCodes to identify the model and variable of each field in a GRIB file.

ModelcentresubCentre
CHIMERE85200
DEHM85203
EMEP880
Ensemble median852
EURAD-IM85201
GEM-AQ85204
LOTOS-EUROS990
MATCH8298
MOCAGE851
SILAM860


VariableparameterNumberconstituentType
Alder pollen5962100
Ammonia09
Birch pollen5962101
Carbon monoxide04
Dust062001
Grass pollen5962300
Nitrogen dioxide05
Nitrogen monoxide011
Non-methane VOCs060013
Olive pollen5964002
Ozone00
Particulate matter < 10um (PM10)040008
Particulate matter < 2.5um (PM2.5)040009
Peroxyacyl nitrates (PANs)060018
PM10 from wildfires062096
Ragweed pollen5962200
Secondary inorganic aerosol (SIA)062099
Sulphur dioxide08


Code Block
from eccodes import codes_grib_new_from_file, codes_get, codes_release

grib_file = 'cams_AQ_forecast.grib'

# Dictionary matching ADS API key/value pairs to grib key/value pairs
definitions = {
    'variable': {
        'ozone': {
            'parameterNumber': 0,   # Mass density kg/m3
            'constituentType': 0},
        'carbon_monoxide': {
            'parameterNumber': 0,
            'constituentType': 4},
        'ammonia': {
            'parameterNumber': 0,
            'constituentType': 9},
        'non_methane_vocs': {
            'parameterNumber': 0,
            'constituentType': 60013},
        'nitrogen_monoxide': {
            'parameterNumber': 0,
            'constituentType': 11},
        'nitrogen_dioxide': {
            'parameterNumber': 0,
            'constituentType': 5},
        'peroxyacyl_nitrates': {
            'parameterNumber': 0,
            'constituentType': 60018},
        'particulate_matter_10um': {
            'parameterNumber': 0,
            'constituentType': 40008},
        'particulate_matter_2.5um': {
            'parameterNumber': 0,
            'constituentType': 40009},
        'pm10_wildfires': {
            'parameterNumber': 0,
            'constituentType': 62096},
        'sulphur_dioxide': {
            'parameterNumber': 0,
            'constituentType': 8},
        'birch_pollen': {
            'parameterNumber': 59,     # Number Concentration (1/m3)
            'constituentType': 62101},
        'grass_pollen': {
            'parameterNumber': 59,
            'constituentType': 62300},
        'olive_pollen': {
            'parameterNumber': 59,
            'constituentType': 64002},
        'ragweed_pollen': {
            'parameterNumber': 59,
            'constituentType': 62200},
        'alder_pollen': {
            'parameterNumber': 59,
            'constituentType': 62100},
        'dust': {
            'parameterNumber': 0,      # Mass density kg/m3
            'constituentType': 62001},
        'secondary_inorganic_aerosol': {
            'parameterNumber': 0,
            'constituentType': 62099}
    },
    'model': {
        'chimere': {
            'centre': 85,      # France
            'subCentre': 200},
        'emep': {
            'centre': 88,      # Oslo
            'subCentre': 0},
        'ensemble': {
            'centre': 85,      # France
            'subCentre': 2},
        'euradim': {
            'centre': 85,      # France
            'subCentre': 201},
        'match': {
            'centre': 82,      # Norrkoping
            'subCentre': 98},
        'mocage': {
            'centre': 85,      # Meteo France
            'subCentre': 1},
        'silam': {
            'centre': 86,      # Helsinki
            'subCentre': 0},
        'lotos': {
            'centre': 99,
            'subCentre': 0},
        'gemaq': {
            'centre': 85,
            'subCentre': 204},
        'dehm': {
            'centre': 85,
            'subCentre': 203}
    }
}


def identify_field(msg):
    """Return a dict identifying the input grib message"""

    field = {}
    for api_key, value_to_grib in definitions.items():
        for api_value, grib_defn in value_to_grib.items():

            # Does this message match the key/value pairs in grib_defn?
            match = True
            for grib_key, grib_value in grib_defn.items():
                msg_value = codes_get(msg, grib_key,
                                      ktype=type(grib_value))
                if msg_value != grib_value:
                    match = False
                    break
            if match:
                field[api_key] = api_value

        if api_key not in field:
            raise Exception('Unrecognised field')

    return field


# Loop over messages in a grib file, identifying all fields
count = 0
with open(grib_file) as f:
    while True:
        msg = codes_grib_new_from_file(f)
        if msg is None:
            break
        count += 1

        try:
            field = identify_field(msg)
        finally:
            codes_release(msg)

        print('Field ' + str(count) + ' is: ' + repr(field))

...