Skip to main content

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

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 (this README for now) 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) pass without any warnings or errors. The easiest way to do this is to install the requirements in requirements/dev.txt and run tox:

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

License

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

Release files for pupygrib 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pupygrib 0.4.0
File Size Uploaded
pupygrib-0.4.0.tar.gz 587.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pupygrib 0.4.0
File Interpreter ABI Platform
pupygrib-0.4.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 613.2 kB

Release files / pupygrib-0.4.0.tar.gz

Download URL pupygrib-0.4.0.tar.gz
Size 587.4 kB
Tags Source
SHA-256 checksum
How to use checksums
0af52a20fe7208d941799d54595d413e043884cdbe3db81e4e10f25eaf834ecf
BLAKE2b-256 checksum
How to use checksums
f5a2517c89e8e9e577ee8a51ff8da48ab92b83599152674023cde277b6059a03
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8

Release files / pupygrib-0.4.0-py2.py3-none-any.whl

Download URL pupygrib-0.4.0-py2.py3-none-any.whl
Size 25.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
3048d984dae85925c725dbb8ed2580d8076ff5c0d35a2e2228188b01638634f6
BLAKE2b-256 checksum
How to use checksums
0a0da949b8641b305c35b19c11699fdb03af3609f8da9924bfc9c835a1512ea9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8

Release history Release notifications | RSS feed

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.1

2 release files

This release

0.4.0 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page