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.6 or later (3.6-3.8 are tested).
  • Numpy (1.12-1.18 are tested).

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 (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-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+).

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.5.1.tar.gz (587.4 kB view details)

Uploaded Source

Built Distribution

pupygrib-0.5.1-py3-none-any.whl (26.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pupygrib-0.5.1.tar.gz
  • Upload date:
  • Size: 587.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.10

File hashes

Hashes for pupygrib-0.5.1.tar.gz
Algorithm Hash digest
SHA256 e4b3a7369cf69737dd801121c129b7649444f0d717145fbdbc48d1a38f2958bc
MD5 99fe5cbd35b0038fa3f70ee7197387fd
BLAKE2b-256 6de5a3daa5256a1efbfbd814bb2060c2e1fe585de36875cdf2dd16bf0ba10a10

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pupygrib-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 26.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.10

File hashes

Hashes for pupygrib-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f0faa8ef728b651751a3f8d627281072a6762618ad1f0e0fcdceb6bf455896ac
MD5 d309e3fcb8b49119fa57a2f3157744ee
BLAKE2b-256 a8184bdee17019c1cad094f7534faaf04c51e879b1035cd2d03f25b443227f8a

See more details on using hashes here.

Supported by

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