简体   繁体   中英

Python gdal to read HDF5 with enbedded compression

I am trying to access HDF5 with the compressed image datablok. I use the classical command gdal

f = gdal.Open(path+product)

but this seems not working since the file is pointing to none has you can see below

Starting processing proba database
processing PROBAV_L1C_20131009_092303_2_V001.HDF5
None
processing PROBAV_L1C_20130925_092925_2_V001.HDF5
None
Processing complete

I would like to ask if there is someone can give me some indication how to handle hdf5 which gdal without using h5py which does not support compressed datablock as well.

Thanks

It couldn't open the file, either because it couldn't see the path, or you don't have an HDF5 driver for Python. The behaviour returning None is expected behaivour , but can be modified to raise an exception if it cannot open the file:

from osgeo import gdal
gdal.UseExceptions()

if not gdal.GetDriverByName('HDF5'):
    raise Exception('HDF5 driver is not available')

I think you miss protocol before Open .

This works for me with other Proba images:

from os import gddal
path="PROBAV_L2A_20140321_031709_2_333M_V001.HDF5"
product="LEVEL2A/GEOMETRY/SAA"    
f = gdal.Open("HDF5:\"{}\"://{}".format(path,product))
f.ReadAsArray()

You could also read the complete name using GetSubDatasets which returns a list of tuples :

ds = gdal.Open(path)
subdataset_read = ds.GetSubDatasets()[0]
print("Subdataset: ",subdataset_read)
ds_sub = gdal.Open(subdataset_read[0],
                   gdal.GA_ReadOnly)
ds_sub.ReadAsArray() 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM