[Gdal-dev] HDF EOS: cannot retrieve band scale and offset

Andrey Kiselev dron at ak4719.spb.edu
Thu Oct 18 10:57:48 EDT 2007


On Thu, Oct 11, 2007 at 09:34:45AM -0700, Jan Cermak wrote:
> From a MODIS MYD021km file I am trying to read band data including 
> offset and scaling factors. Band data works just fine, but I can't get 
> offset and scale. Without offset and scale the data is completely 
> useless, so this seems to be a major issue to me.
> 
> Here is some sample code:
> 
> dsobj = 
> gdal.Open('HDF4_EOS:EOS_SWATH:"myfile.hdf":MODIS_SWATH_Type_L1B:EV_1KM_RefSB')
> bandobj = dsobj.GetRasterBand(1)
> scale = bandobj.GetScale()
> offset = bandobj.GetOffset()
> 
> scale and offset variables are empty.
> 
> I am using yesterday's stable branch nightly.
> A sample file is at
> ftp://ladsweb.nascom.nasa.gov/allData/5/MYD021KM/2006/220/MYD021KM.A2006220.1330.005.2007140045620.hdf
> 
> For this file and data set, HDFView yields:
> radiance_scales = 
> 0.0072957743,0.0051752976,0.0037723905,0.0029522364,0.0023176796,0.001162374,5.6182046E-4,0.0011558639,4.1845915E-4,9.5770456E-4,6.215421E-4,0.006355153,0.009465027,0.0069601014,0.0027906199
> radiance_offsets = 
> 316.9722,316.9722,316.9722,316.9722,316.9722,316.9722,316.9722,316.9722,316.9722,316.9722,316.9722,316.9722,316.9722,316.9722,316.9722

Hi Jan,

Finally I have solved this problem. These data now fetched and added to
the list of metadata, so you can use it in you code:

$ gdalinfo HDF4_EOS:EOS_SWATH:"MYD021KM.A2006220.1330.005.2007140045620.hdf":MODIS_SWATH_Type_L1B:EV_1KM_RefSB

Driver: HDF4Image/HDF4 Dataset
Files: MYD021KM.A2006220.1330.005.2007140045620.hdf
Size is 1354, 2030

.....

  radiance_scales=0.007295774, 0.005175298, 0.003772391, 0.002952236, 0.00231768, 0.001162374, 0.0005618205, 0.001155864, 0.0004184592, 0.0009577046, 0.0006215421, 0.006355153, 0.009465027, 0.006960101, 0.00279062
  radiance_offsets=316.9722, 316.9722, 316.9722, 316.9722, 316.9722, 316.9722, 316.9722, 316.9722, 316.9722, 316.9722, 316.9722, 316.9722, 316.9722, 316.9722, 316.9722
  radiance_units=Watts/m^2/micrometer/steradian
  reflectance_scales=1.348291e-05, 8.769159e-06, 6.162684e-06, 5.057901e-06, 3.954835e-06, 2.42613e-06, 1.172643e-06, 2.478778e-06, 8.973959e-07, 2.389224e-06, 2.062774e-06, 2.196517e-05, 3.504297e-05, 2.574762e-05, 2.468974e-05
  reflectance_offsets=316.9722, 316.9722, 316.9722, 316.9722, 316.9722, 316.9722, 316.9722, 316.9722, 316.9722, 316.9722, 316.9722, 316.9722, 316.9722, 316.9722, 316.9722
  reflectance_units=none
  corrected_counts_scales=0.126194, 0.126194, 0.126194, 0.126194, 0.126194, 0.126194, 0.126194, 0.126194, 0.126194, 0.126194, 0.126194, 0.126194, 0.126194, 0.126194, 0.126194
  corrected_counts_offsets=316.9722, 316.9722, 316.9722, 316.9722, 316.9722, 316.9722, 316.9722, 316.9722, 316.9722, 316.9722, 316.9722, 316.9722, 316.9722, 316.9722, 316.9722
  corrected_counts_units=counts

It is not possible to use our Scale/Offset methods, because driver
doesn't know what metadata record should be used for any given product,
but you can easily parse it yourself:

>>> ds = gdal.Open('HDF4_EOS:EOS_SWATH:MYD021KM.A2006220.1330.005.2007140045620.hdf:MODIS_SWATH_Type_L1B:EV_1KM_RefSB')
>>> md = ds.GetMetadata()
>>> scales = map(float,md['radiance_scales'].split(','))
>>> offsets = map(float,md['radiance_offsets'].split(','))
>>> print "%f/%f" % (scales[0],offsets[0])
0.007296/316.972200

Best regards,
Andrey

-- 
Andrey V. Kiselev
ICQ# 26871517



More information about the Gdal-dev mailing list