Skip to main content

A light-weight pure Python GRIB reader

Project description

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 3.7 or later (3.7-3.9 are tested). 3.8 or later is recommended for the better typing support.
  • Numpy 1.15-1.21 are tested with compatible Python versions.

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 time, 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()
...         time = msg.get_time()
...         values = msg.get_values()
...         print("Message {}: {} {:.3f} {}".format(i, time, values.mean(), lons.shape))
...
Message 1: 2008-02-06 12:00:00 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.is_.fieldnames)  # fieldnames is a set, so we can't trust the order
['editionNumber', 'identifier', 'totalLength']
>>> msg[0].totalLength
1100
>>> msg.bitmap is None  # the bit-map section is not included in this message
True

Development

Pull requests (against the develop branch) are most welcome! I do ask that you add test cases and update the documentation (this README for now) for any new features. Run the code through the auto-formatters black and isort and make sure that all checks (coding style, static type check, unit tests, and the manifest) pass without any warnings or errors. The easiest way to do this is to install the requirements in requirements/dev.txt and run nox:

$ pip install -r requirements/dev.txt
$ nox

License

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

Change log

0.9.0

  • Fix reading bitmaps were numberOfUnusedBitsAtEndOfSection3 is zero (!3).
  • Use a declarative setuptools configuration. This requires setuptools >= 42.

0.8.0

  • Drop support for Python 3.6.
  • Add official support for numpy 1.20 and 1.21.
  • Add basic type annotations for numpy's data structures.
  • Use PEP 585 and 604 in the type annotations.

0.7.0

  • Add type annotations to the source code.
  • Revise the Message classes to better support typing. The sections of a GRIB message are now rather accessed by name than by index.
  • Add a get_time() method to the message classes.
  • Add official support for Python 3.9.

0.6.1

  • Fix unpacking messages with an odd number of 12-bit values.
  • Add official support for NumPy 1.19

0.6.0

  • Add support for 24 bits per value packing (contributed by @uranix in !1).

0.5.1

  • Fix edge cases in zero-padded GRIB files.
  • Add official support for Python 3.8 and NumPy 1.18.

0.5.0

  • Added support for grib files with zero-padded messages.

0.4.1

  • Disabled universal wheel

0.4.0

  • Dropped support for Python 3.5 and older.
  • Added support for 12 bits per value packing.
  • Moved the code repo to gitlab.com for CI facilities.

0.3.0

  • Fixed a silent overflow error on unpacking simple grid data (PR #1)
  • Formatted the code with the black.

0.2.0

  • Added a filename attribute to Message instances.
  • Added official support for Python 3.6.
  • Changed home page to repo at notabug.org.

0.1.0

  • Initial release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pupygrib-0.9.0.tar.gz (678.3 kB view details)

Uploaded Source

Built Distribution

pupygrib-0.9.0-py3-none-any.whl (29.4 kB view details)

Uploaded Python 3

File details

Details for the file pupygrib-0.9.0.tar.gz.

File metadata

  • Download URL: pupygrib-0.9.0.tar.gz
  • Upload date:
  • Size: 678.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.7

File hashes

Hashes for pupygrib-0.9.0.tar.gz
Algorithm Hash digest
SHA256 4937fc08bf678c6c4303a55b27aa07126fa2b2d8a4a5dfb6dedb6b1009a78ab1
MD5 6059eb4d17d6505c44c06507e397812c
BLAKE2b-256 0e62cf8969ab658d1d23034fc86e190fd83a5f29ad5b663db7a6c964196441ff

See more details on using hashes here.

File details

Details for the file pupygrib-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: pupygrib-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 29.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.7

File hashes

Hashes for pupygrib-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cfa19c4cc17099da7534b5bc7cc4c91939eb4661657992b12a509d9ed428a4a2
MD5 1cc0ecba49c6739026f0f9ce6bf7b1fe
BLAKE2b-256 9582972bbbdafca6e62f2ff5ec8201dbbe13b535b81cb894af1bf16f88b19d6d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page