2017-06-11 24 views
0

我想读取python中的hdf5图像(这是我第一次)。在hdfview中,我看到subdatasets没有问题,但在Python中,我无法阅读它们。当我这样做:在python中读取hdf5时的空子数据集

f = gdal.Open(fileName, gdalconst.GA_ReadOnly) 
sub = f.GetSubDatasets()[0][0] 

它提供:

Traceback (most recent call last): File "", line 1, in sub=f.GetSubDatasets()[0][0]

IndexError: list index out of range

的它为什么发生任何想法?

+0

你试过h5py? – MishaVacic

回答

0

我发现如何与h5py做到这一点,如果它可以帮助任何人,这里是:

f=h5py.File(fileName, "r") # Opens the file in reading mode 
datasetNames=[n for n in f.keys()] # identifies the datasets included in the image 
# for n in datasetNames: print(n) # print the names of the different datasets 
lat=f['LATITUDE'] # LATITUDE is a dataset in my file 
lat_at=lat.attrs['SCALING_FACTOR'] # SCALING_FACTOR is an attribut of the dataset LATITUDE