How to extract DATA_ENCODING creation option type from an input grib2 file for use in the output grib2 file

Shane Mill - NOAA Affiliate

Hey everyone,

I know that grib2 isn't commonly used by this community so I apologize that I keep bringing it up... You can probably tell that I am super fond of it! Anyways, all kidding aside, I am very impressed with the abilities of Rasterio and how responsive this community has been.

In a previous topic, Sean and I discussed that creation options for a specific driver can be assigned when opening a grib file in writing mode.
ie. "with, 'w', driver='GRIB',dtype='float64'.....DATA_ENCODING='COMPLEX_PACKING',SPATIAL_DIFFERENCING_ORDER=2) as ds:"

The grib2 specific creation options can be found here:

This works well in terms of creating a grib2 file encoded in a way that can be read by gdalinfo, toolsUI, and other grib2 readers. What I want/need to figure out now is how to be able to extract the DATA_ENCODING and SPATIAL_DIFFERENCING_ORDER from an input grib2 file so that these creation options don't need to be hardcoded when creating a new grib2 file. In other words, say that you have model data in an input grib2 file, and you create a new grib2 file with a new derived parameter that is derived from two bands in the input grib2 file. I would want the DATA_ENCODING to be the same for both the input and output grib2 file.

Many of the creation options are tracked in the metadata, but as far as I can tell, DATA_ENCODING is not. I'm wondering if it actually is somewhere and I'm just missing it. 

At this link (, Sean, you have indicated that the GDAL API doesn't track creation options, but you were able to develop this in Rasterio. Going back to, It looks like all of the Product Identification and Definition is either tracked in src.meta, src.profile, or src.tags(band#). It doesn't appear that Data Encoding is.

I just wanted to see if you (or anyone else) had any feedback on this or know if there is anyway of extracting the type of data encoding from an input file.

Thanks as always!

Join to automatically receive all group messages.