Python versione Bignami - Il modulo grib_api
import grib_api
for grib in grib_api.read("file.grib"):
    # grib_api keys can be accessed like a dict
    print "centre:", grib["originatingCentre"]
    print "subcentre:", grib["subCentre"]
    # Like a dict, you can use keys() to list the keys
    print "grib_api keys:", grib.keys()
    # The grid of data is read as a NumPY array
    values = grib["values"]
    print numpy.average(values)
    # grib_api also georeferences data producing arrays of latitudes and
    # longitudes
    latitudes = grib["latitudes"]
    longitudes = grib["longitudes"]
    # Edit a grib just by assigning values
    grib["generatingProcessIdentifier"] = 98
    # Modify the gridded data
    vals = grib["values"]
    vals[1] = 123.456
    grib["values"] = vals
    # Reencode the grib, with the modifications
    buf = grib.encode()
    print "Length of encoded grib:", len(buf)
    # Decode a grib from a string
    grib1 = grib_api.decode(buf)
    # You can also convert a grib into a real dictionary, which will however
    # use more memory than the grib
    d = grib.as_dict()
Il modulo grib_api ha solo due metodi:
- grib_api.read(nomefile): legge un file, restituendo un generatore di GRIB
- grib_api.decode(stringa): decodifica un GRIB da una stringa
Gli oggetti grib si comportano come dizionari: le chiavi di grib_api possono essere lette e scritte usando le parentesi quadre.
Oltre all'accesso in stile dizionario, gli oggetti grib hanno tre metodi:
- grib.keys()restituisce una lista con tutte le chiavi definite nel grib
- grib.encode()codifica il grib in una stringa
- grib.as_dict()restituisce un dizionario python con tutte le chiavi e i valori trovati nel grib