Select to view content in your preferred language

How does one get the metadata of each band of a grib file using rasterio?

1222
1
02-03-2022 12:09 AM
HaniMalik
New Contributor

Is there a way to see the metadata of each band of a grib file using rasterio? Using gdal this can be accomplished by:

import gdal

path = r"D:\path\to\somewhere.grib"

ds = gdal.Open(path)  

for band in range(1, ds.RasterCount):
    print(ds.GetRasterBand(band).GetMetadata())

an example of one band's metadata from a GFS grib using the method above is as follows

{'GRIB_COMMENT': 'Temperature [C]', 'GRIB_DISCIPLINE': '0(Meteorological)', 'GRIB_ELEMENT': 'TMP', 'GRIB_FORECAST_SECONDS': '21600 sec', 'GRIB_IDS': 'CENTER=7(US-NCEP) SUBCENTER=0 MASTER_TABLE=2 LOCAL_TABLE=1 SIGNF_REF_TIME=1(Start_of_Forecast) REF_TIME=2022-02-02T06:00:00Z PROD_STATUS=0(Operational) TYPE=1(Forecast)', 'GRIB_PDS_PDTN': '0', 'GRIB_PDS_TEMPLATE_ASSEMBLED_VALUES': '0 0 2 0 96 0 0 1 6 1 0 0 255 0 0', 'GRIB_PDS_TEMPLATE_NUMBERS': '0 0 2 0 96 0 0 0 1 0 0 0 6 1 0 0 0 0 0 255 0 0 0 0 0', 'GRIB_REF_TIME': '  1643781600 sec UTC', 'GRIB_SHORT_NAME': '0-SFC', 'GRIB_UNIT': '[C]', 'GRIB_VALID_TIME': '  1643803200 sec UTC'}

I'm trying to get this same information but using rasterio instead. Is this possible? So far I've tried

import rasterio 

with rasterio.open(file) as src:
    print(src.descriptions)
    print(src.meta)
    print(src.profile)

with the closest being src.descriptions. However, it only gave the following

('0[-] SFC="Ground or water surface"')

It seems to be only getting a piece of the metadata. Does anyone know how to get the rest?

0 Kudos
1 Reply
Luke_Pinner
MVP Regular Contributor

rasterio isn't part of the ArcGIS suite of software, you might be better off asking on the rasterio group or GIS StackExchange.

0 Kudos