Opened 14 years ago

Closed 14 years ago

#2462 closed defect (fixed)

Incorrect subdatasets handling in python bindings

Reported by: antonio Owned by: warmerdam
Priority: normal Milestone: 1.5.4
Component: GDAL_Raster Version: 1.5.2
Severity: normal Keywords: HDF5


I'm using GDAL 1.5.2 in Debian Sid x64 I have an HDF5 file with 2 datasets "/MBI" and "/QLK":

$ gdalinfo -nogcp -nomd -stats test-subdatasets.h5 
Driver: HDF5/Hierarchical Data Format Release 5
Files: test-subdatasets.h5
Size is 512, 512
Coordinate System is `'
  SUBDATASET_0_DESC=[200x200] //MBI (8-bit unsigned integer)
  SUBDATASET_1_DESC=[10x10] //QLK (8-bit unsigned character)
Corner Coordinates:
Upper Left  (    0.0,    0.0)
Lower Left  (    0.0,  512.0)
Upper Right (  512.0,    0.0)
Lower Right (  512.0,  512.0)
Center      (  256.0,  256.0)

When I open the dataset from python I only get on subdataset:

Python 2.5.2 (r252:60911, Jun 25 2008, 18:03:42) 
[GCC 4.3.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from osgeo import gdal
>>> d = gdal.Open('test-subdatasets.h5')
>>> d.GetSubDatasets()
[('HDF5:"test-subdatasets.h5"://QLK', '[10x10] //QLK (8-bit unsigned character)')]

The "/MBI" subdataset is missing.

Attachments (1)

test-subdatasets.h5 (1.8 KB ) - added by antonio 14 years ago.
Test HDF5 file.

Download all attachments as: .zip

Change History (6)

by antonio, 14 years ago

Attachment: test-subdatasets.h5 added

Test HDF5 file.

comment:1 by hobu, 14 years ago

Component: PythonBindingsGDAL_Raster
Owner: changed from hobu to warmerdam

comment:2 by warmerdam, 14 years ago

Resolution: worksforme
Status: newclosed

I have been unable to reproduce this problem on my AMD64 ubuntu system using GDAL trunk. It works fine for me.

Python 2.5.1 (r251:54863, Oct  5 2007, 13:50:07) 
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gdal
/home/warmerda/gdal/swig/python/build/lib.linux-x86_64-2.5/osgeo/ DeprecationWarning: was placed in a namespace, it is now available as osgeo.gdal
>>> ds = gdal.Open('test-subdatasets.h5')
GDAL: GDALOpen(test-subdatasets.h5, this=0x84f010) succeeds as HDF5.
>>> print ds.GetMetadata('SUBDATASETS')
{'SUBDATASET_0_DESC': '[200x200] //MBI (8-bit unsigned integer)', 'SUBDATASET_1_NAME': 'HDF5:"test-subdatasets.h5"://QLK', 'SUBDATASET_0_NAME': 'HDF5:"test-subdatasets.h5"://MBI', 'SUBDATASET_1_DESC': '[10x10] //QLK (8-bit unsigned character)'}

I *suspect* you are using a different version of the GDAL library from Python than from the commandline but it is hard to say why it isn't working for you. Please reopen if you have specific suggestions for how I might reproduce the problem.

comment:3 by warmerdam, 14 years ago

Keywords: HDF5 added
Milestone: 1.5.4

in reply to:  3 comment:4 by antonio, 14 years ago

Resolution: worksforme
Status: closedreopened

Replying to warmerdam: Indeed it works if you use "GetMetadata" but still not works using "GetSubDatasets":

In [1]: from osgeo import gdal

In [2]: d = gdal.Open('test-subdatasets.h5')

In [3]: d.GetSubDatasets()
  '[10x10] //QLK (8-bit unsigned character)')]

In [4]: d.GetMetadata('SUBDATASETS')
{'SUBDATASET_0_DESC': '[200x200] //MBI (8-bit unsigned integer)',
 'SUBDATASET_0_NAME': 'HDF5:"test-subdatasets.h5"://MBI',
 'SUBDATASET_1_DESC': '[10x10] //QLK (8-bit unsigned character)',
 'SUBDATASET_1_NAME': 'HDF5:"test-subdatasets.h5"://QLK'}

comment:5 by warmerdam, 14 years ago

Milestone: 1.5.4
Resolution: fixed
Status: reopenedclosed

Doh! I had forgotten such a thing existed, and didn't read carefully.

On inspection I see that the HDF5 driver improperly returns subdatasets numbered from zero instead of one, and that the Python implementation of GetSubDatsets() assumes a start from 1 as per the specification in the data model document.

I have corrected the HDF5 driver to return subdatsets numbered started from one in trunk (r16062), 1.6 branch (r16063) and 1.5 branch (r16064).

Thanks for the report and the followup.

Note: See TracTickets for help on using tickets.