4

I'm trying to use GDAL in python to get only the temperature band from this GRIB file that has 2 bands. I can't just do temp_band = ds.GetRasterBand(1) because sometimes, but not always, the grib files contain the temp error data in band 1 and the temp data in band 2.

When I open the GRIB file using the DEGRIB viewer (tkdegrib) it says the bands have Short Names TMP and TMPERR. But when I use GDAL to list the band metadata, this information seems to get lost as GRIB_SHORT_NAME = 2-HTGL for both bands. I'm not sure if this is a bug in GDAL or if I'm doing something wrong. How can I reliably figure out which band is which?

Below I pasted what info GDAL gives for each band using GetMetadata() on each of the bands.

BAND 1: __len__ = {int} 13 'GRIB_COMMENT' (84646000) = {str} 'Temperature [C]' 'GRIB_ELEMENT' (84646128) = {str} 'TMP' 'GRIB_FORECAST_SECONDS' (84524608) = {str} '0 sec' 'GRIB_PDS_PDTN' (84646256) = {str} '0' 'GRIB_PDS_TEMPLATE_NUMBERS' (75911216) = {str} '0 0 7 0 109 0 0 0 1 0 0 0 0 103 0 0 0 0 2 255 0 0 0 0 0' 'GRIB_REF_TIME' (84646320) = {str} '1445904000 sec UTC' 'GRIB_SHORT_NAME' (84646384) = {str} '2-HTGL' 'GRIB_UNIT' (84646448) = {str} '[C]' 'GRIB_VALID_TIME' (84646512) = {str} '1445904000 sec UTC' 'STATISTICS_MAXIMUM' (84636416) = {str} '-271.77999999523' 'STATISTICS_MEAN' (84646576) = {str} '-271.84386028282' 'STATISTICS_MINIMUM' (84636632) = {str} '-272.64000000954' 'STATISTICS_STDDEV' (84636776) = {str} '0.078593326710491'

BAND 2: __len__ = {int} 11 'GRIB_COMMENT' (84646640) = {str} 'Temperature [C]' 'GRIB_ELEMENT' (84646768) = {str} 'TMP' 'GRIB_FORECAST_SECONDS' (84636920) = {str} '0 sec' 'GRIB_REF_TIME' (84646832) = {str} '1445904000 sec UTC' 'GRIB_SHORT_NAME' (84646896) = {str} '2-HTGL' 'GRIB_UNIT' (84646960) = {str} '[C]' 'GRIB_VALID_TIME' (84647024) = {str} '1445904000 sec UTC' 'STATISTICS_MAXIMUM' (84637136) = {str} '34.129998779297' 'STATISTICS_MEAN' (84647152) = {str} '14.876380973386' 'STATISTICS_MINIMUM' (84637208) = {str} '-9.1300109863281' 'STATISTICS_STDDEV' (84637352) = {str} '9.028231730951'

  • You need the 'GRIB_ELEMENT' metadata item. – user10353 Nov 4 '15 at 17:54
  • 'GRIB_ELEMENT' = 'TMP' for both bands, so I can't use it to differentiate between TMP and TMPERR. – apricity Nov 5 '15 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.