简体   繁体   English

在python中读取hdf5时为空子数据集

[英]Empty subdatasets when reading hdf5 in python

I am trying to read a hdf5 image in python (it's my first time). 我正在尝试在python中读取hdf5图像(这是我的第一次)。 In hdfview I see the subdatasets with no problem, but in Python, I can't read them. 在hdfview中,我看到的subdatasets没有问题,但是在Python中,我看不到它们。 When I do: 当我做:

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

It gives: 它给:

Traceback (most recent call last): File "", line 1, in sub=f.GetSubDatasets()[0][0] 追溯(最近一次通话):文件“”,第1行,位于sub = f.GetSubDatasets()[0] [0]

IndexError: list index out of range IndexError:列表索引超出范围

Any idea of why does it happen? 知道为什么会发生吗?

I found how to do it with h5py, in case it helps anyone, here is it: 我发现如何用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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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