Warning |
---|
Note: The high-level Python interface was always experimental and has been removed (from version 1.4.0). Please use metview, cfgrib and/or pdbufr instead. |
Deprecated Python classes
The following Python classes have been removed:
In addition to the low-level C-like interface, there are now Python classes that can be used to represent the objects of interest whilst processing GRIB and BUFR messages.
In addition to the low-level C-like interface, there are now Python classes that can be used to work with GRIB and BUFR messages in a more object-oriented manner.
GribFile and BufrFile: Classes that implement access to a GRIB/BUFR file that closes itself and its messages when it is no longer needed.
GribMessage and BufrMessage: Classes that implement access to a GRIB/BUFR message that allows access to the message's key-value pairs in a dictionary-like manner and closes the message when it is no longer needed, coordinating this with its host file.
GribFiles and BufrFiles can be treated mostly as regular files and used as context managers, as can GribMessages/BufrMessages. Each of these classes destructs itself and any child instances appropriately.
Details
...
Tabs Page |
---|
|
Code Block |
---|
language | py |
---|
linenumbers | true |
---|
| class GribFile
# A GRIB file handle meant for use in a context manager.
# Individual messages can be accessed using the ``next`` method. Of course,
# it is also possible to iterate over each message in the file::
>>> with GribFile(filename) as grib:
... # Print number of messages in file
... len(grib)
... # Open all messages in file
... for msg in grib:
... print(msg[key_name])
... len(grib.open_messages)
>>> # When the file is closed, any open messages are closed
>>> len(grib.open_messages) |
|
Tabs Page |
---|
|
Code Block |
---|
language | py |
---|
linenumbers | true |
---|
| class GribMessage
#A GRIB message.
#Each ``GribMessage`` is stored as a key/value pair in a dictionary-like
#structure. It can be used in a context manager or by itself. When the
#``GribFile`` it belongs to is closed, the ``GribFile`` closes any open
#``GribMessage``s that belong to it. If a ``GribMessage`` is closed before
#its ``GribFile`` is closed, it informs the ``GribFile`` of its closure.
#Scalar and vector values are set appropriately through the same method.
#``GribMessage``s can be instantiated from a ``GribFile``, cloned from
#other ``GribMessage``s or taken from samples. Iterating over the members
#of a ``GribFile`` extracts the ``GribMessage``s it contains until the
#``GribFile`` is exhausted.
#Usage::
>>> with GribFile(filename) as grib:
... # Access a key from each message
... for msg in grib:
... print(msg[key_name])
... # Report number of keys in message
... len(msg)
... # Report message size in bytes
... msg.size
... # Report keys in message
... msg.keys()
... # Set scalar value
... msg[scalar_key] = 5
... # Check key's value
... msg[scalar_key]
... msg[key_name]
... # Array values are set transparently
... msg[array_key] = [1, 2, 3]
... # Messages can be written to file
... with open(testfile, "w") as test:
... msg.write(test)
... # Messages can be cloned from other messages
... msg2 = GribMessage(clone=msg)
... # If desired, messages can be closed manually or used in with
... msg.close() |
|
Tabs Page |
---|
|
Code Block |
---|
language | py |
---|
linenumbers | true |
---|
| #A BUFR file handle meant for use in a context manager.
#Individual messages can be accessed using the ``next`` method. Of course,
#it is also possible to iterate over each message in the file::
>>> with BufrFile(filename) as bufr:
... # Print number of messages in file
... len(bufr)
... # Open all messages in file
... for msg in bufr:
... print(msg[key_name])
... len(bufr.open_messages)
>>> # When the file is closed, any open messages are closed
>>> len(bufr.open_messages) |
|
.
GribIndex: A class that implements a GRIB index that allows access to the indexing functionality.
These were in the directory "eccodes/high_level".
...
...
language | py |
---|
linenumbers | true |
---|
...