Python interface to map GRIB files to the NetCDF Common Data Model following the CF Conventions. The high level API is designed to support a GRIB backend for xarray and it is inspired by NetCDF-python and h5netcdf. Low level access and decoding is performed via the ECMWF ecCodes library.
Features:
map a GRIB file to a set of N-dimensional variables following the NetCDF Common Data Model,
map CF Conventions attributes coordinate and data variables,
access data variable values from disk efficiently,
provisional xarray GRIB driver,
no write support yet.
Installation
The package is installed from PyPI with:
$ pip install cfgrib
System dependencies
The python module depends on the ECMWF ecCodes library that must be installed on the system and accessible as a shared library. Some Linux distributions ship a binary version of ecCodes that may be installed with the standard package manager. On Ubuntu 18.04 use the command:
$ sudo apt-get install libeccodes0
On a MacOS with HomeBrew use:
$ brew install eccodes
As an alternative you may install the official source distribution by following the ecCodes instructions at https://software.ecmwf.int/wiki/display/ECC/ecCodes+installation
Note that ecCodes support for the Windows operating system is experimental.
You may run a simple self-check command to ensure that your system is set up correctly:
$ python -m cfgrib --selfcheck Found: ecCodes v2.7.0. Your system is ready.
Usage
First, you need a well-formed GRIB file, if you don’t have one at hand you can download our ERA5 on pressure levels sample:
$ wget http://download.ecmwf.int/test-data/cfgrib/era5-levels-members.grib
Dataset / Variable API
You may try out the high level API in a python interpreter:
>>> import cfgrib
>>> ds = cfgrib.Dataset.frompath('era5-levels-members.grib')
>>> ds.attributes['GRIB_edition']
1
>>> ds.dimensions.items()
[('number', 10), ('forecast_reference_time', 4), ('air_pressure', 2), ('latitude', 61), ('longitude', 120)]
>>> sorted(ds.variables)
['air_pressure', 'forecast_period', 'forecast_reference_time', 'latitude', 'longitude', 'number', 't', 'time', 'z']
>>> var = ds.variables['t']
>>> var.dimensions
('number', 'forecast_reference_time', 'air_pressure', 'latitude', 'longitude')
>>> var.data[:, :, :, :, :].mean()
262.92133
Provisional xarray GRIB driver
If you have xarray installed cfgrib can open a GRIB file as a xarray.Dataset:
$ pip install xarray
In a Python interpreter try:
>>> from cfgrib import xarray_store
>>> ds = xarray_store.open_dataset('era5-levels-members.grib')
>>> ds
<xarray.Dataset>
Dimensions: (latitude: 61, level: 2, longitude: 120, number: 10, time: 4)
Coordinates:
* number (number) int64 0 1 2 3 4 5 6 7 8 9
* time (time) datetime64[ns] 2017-01-01 2017-01-01T12:00:00 ...
step timedelta64[ns] ...
* level (level) float64 8.5e+04 5e+04
* latitude (latitude) float64 90.0 87.0 84.0 81.0 78.0 75.0 72.0 69.0 ...
* longitude (longitude) float64 0.0 3.0 6.0 9.0 12.0 15.0 18.0 21.0 24.0 ...
valid_time (time) datetime64[ns] ...
Data variables:
z (number, time, level, latitude, longitude) float32 ...
t (number, time, level, latitude, longitude) float32 ...
Attributes:
GRIB_edition: 1
GRIB_centre: ecmf
GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
GRIB_subCentre: 0
GRIB_table2Version: 128
history: GRIB to CDM+CF via cfgrib-0.8.0/ecCodes-2.7.0
Lower level APIs
Lower level APIs are not stable and should not be considered public yet. In particular the internal Python 3 ecCodes bindings are not compatible with the standard ecCodes python module.
Contributing
Contributions are very welcome. Please see the CONTRIBUTING.rst document for the best way to help. If you encounter any problems, please file an issue along with a detailed description.
Lead developer:
Alessandro Amici - B-Open
Main contributors:
Baudouin Raoult - ECMWF
Iain Russell - ECMWF
Leonardo Barcaroli - B-Open
Aureliana Barghini - B-Open
See also the list of contributors who participated in this project.
License
Copyright 2017-2018 European Centre for Medium-Range Weather Forecasts (ECMWF).
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Metadata
Release files for cfgrib 0.8.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cfgrib-0.8.1.tar.gz | 2.3 MB | Without provenance | Details for cfgrib-0.8.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cfgrib-0.8.1-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for cfgrib-0.8.1-py2.py3-none-any.whl |
Total release size: 2.3 MB
Release files / cfgrib-0.8.1.tar.gz
| Download URL | cfgrib-0.8.1.tar.gz |
|---|---|
| Size | 2.3 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ec50c122a18f0ac897afa8ca6932d8806f367fb0003f65ff967e96e5c88fa1a7
|
|
BLAKE2b-256 checksum How to use checksums |
74296c0f39038ef07da21d6b65881cdc8bdf5f7cdcfe49f180c3b92f1c4e88f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / cfgrib-0.8.1-py2.py3-none-any.whl
| Download URL | cfgrib-0.8.1-py2.py3-none-any.whl |
|---|---|
| Size | 26.4 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
52bd55971b620dfe0998119d98c0e4163fb097f9df0c0e3e6653113133e79a48
|
|
BLAKE2b-256 checksum How to use checksums |
c82c4f85bfda07db177bca8d95813a1afae8e90bb6d07bb994a07f8de9e9598b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for cfgrib 0.8.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.