A light-weight pure Python GRIB reader. This project has moved to https://gitlab.com/gorilladev/pupygrib

Mattias Jakobsson c5c7f40cd9 Added notice about move to gitlab 5 years ago
pupygrib b2e188ae2f Made simple grid unpacking cast to 64-bit floats 6 years ago
tests 1430e34568 Added tests to catch overflows 6 years ago
.gitignore e53ada8b60 Added .dir-locals.el to .gitignore 6 years ago
CHANGES.md 8a276d2e77 Updated the change log 6 years ago
LICENSE.txt 508d44ee87 Initial commit of an empty project structure 8 years ago
MANIFEST.in 6bdd78617c Updated the MANIFEST.in 6 years ago
README.md c5c7f40cd9 Added notice about move to gitlab 5 years ago
requirements.txt ec68264927 Added twine and wheel to the development requirements 6 years ago
setup.cfg 79d45cb080 Documented the use of black and configured flake8 for it 6 years ago
setup.py 7e1d4fb547 Bumped version number to 0.3.0 6 years ago
tox.ini c78e26bb0d Added support for Python 3.6 7 years ago

README.md

Pupygrib

This project has moved to https://gitlab.com/gorilladev/pupygrib

Pupygrib (pronounced puppy grib and short for PUre PYthon GRIB) is a light-weight pure Python GRIB reader. It's purpose is to extract data from GRIB files with as little effort as possible. The user can then freely choose how to further process the data (read: pupygrib will not help you).

Features

This project is in the alpha phase, which means that many planned features are missing and implemented features are not well tested. It also means that the API may change in future version. The implemented features are:

  • Iterate over and extract the raw fields from GRIB edition 1 messages in a file.
  • Extract simply packed grid-point data values from GRIB edition 1 messages.
  • Extract the coordinates for these values if they are on a latitude/longitude grid.

The planned features are:

  • Be able to easily identify (filter) the messages.
  • Be able to extract the data values for other packings.
  • Be able to extract the coordinates of other grid types.
  • Support for GRIB edition 2.

Requirements

  • Python 2.7, 3.4, 3.5 or 3.6. Earlier Python 3 versions may work, but they are not tested.
  • Numpy
  • Six

pip will automatically install the latter two.

Installation

$ pip install pupygrib

Usage

To use pupygrib, you will need a good understanding of the GRIB format, especially since table lookups are not yet implemented. ECMWF provides an overview of GRIB edition 1 and edition 2 that can be used as references.

Iterate over the messages in a GRIB file and extract the coordinates and values:

>>> import pupygrib
>>> with open('tests/data/regular_latlon_surface.grib1', 'rb') as stream:
...     for i, msg in enumerate(pupygrib.read(stream), 1):
...         lons, lats = msg.get_coordinates()
...         values = msg.get_values()
...         print("Message {}: {:.3f} {}".format(i, values.mean(), lons.shape))
...
Message 1: 291.585 (31, 16)

Access a section of a GRIB message and print its fields:

>>> with open('tests/data/regular_latlon_surface.grib1', 'rb') as stream:
...     msg, = pupygrib.read(stream)
>>> sorted(msg[0].fieldnames)  # fieldnames is a set, so we can't trust the order
['editionNumber', 'identifier', 'totalLength']
>>> msg[0].totalLength
1100
>>> msg[3] is None  # the bit-map section is not included in this message
True

Development

Pull requests are most welcome! I do ask that you add test cases and update the documentation for any new features. Run the code through the auto-formatter black and make sure that all checks (coding style, unit tests, and the manifest, respectively) pass without any warnings or errors. Tox should have at least one supported Python 2 and Python 3 version available.

$ black pupygrib tests
$ flake8
$ tox
$ check-manifest

These tools can easily be installed by pip by using the requirements.txt file in the repository:

$ pip install -r requirements.txt

License

Pupygrib is being developed by Mattias Jakobsson at SMHI. It is released under the GNU General Public License v3 or later (GPLv3+).