使用适用于python的h5py包读取hdf文件时出错 [英] Error in reading hdf file using h5py package for python

查看:99
本文介绍了使用适用于python的h5py包读取hdf文件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我从 MODIS 网站.链接中提供了一个样本文件.我正在使用以下代码行读取hdf文件:

I want to extract data from hdf files that I downloaded from MODIS website. A sample file is provided in the link. I am reading the hdf file by using the following lines of code:

>>> import h5py
>>> f = h5py.File( 'MYD08_M3.A2002182.051.2008334061251.psgscs_000500751197.hdf', 'r' )

我得到的错误:

Traceback (most recent call last):
    File "<pyshell#3>", line 1, in <module>
f = h5py.File( 'MYD08_M3.A2002182.051.2008334061251.psgscs_000500751197.hdf', 'r' )
    File "C:\Python27\lib\site-packages\h5py\_hl\files.py", line 165, in __init__
fid = make_fid(name, mode, userblock_size, fapl)
    File "C:\Python27\lib\site-packages\h5py\_hl\files.py", line 57, in make_fid
fid = h5f.open(name, h5f.ACC_RDONLY, fapl=fapl)
    File "h5f.pyx", line 70, in h5py.h5f.open (h5py\h5f.c:1640)
IOError: unable to open file (File accessability: Unable to open file)

我尝试了其他来自不同来源的其他hdf文件,但遇到了相同的错误.这似乎是什么错?

I have tried several other hdf files from different sources but I am getting the same error. What seems to be the fault here?

推荐答案

我认为可能存在两个可能的问题:

I think there could be two possible problems:

1)由于文件扩展名是"hdf",因此这可能是HDF4文件. HDF5文件通常具有".hdf5"或".h5·"扩展名.我不确定h5py是否能够读取HDF4文件.

1) As the file extension is "hdf", maybe this is a HDF4 file. HDF5 files normally have ".hdf5" or ".h5·" extension. I am not sure if h5py is able to read HDF4 files.

2)也许您必须更改文件本身的权限.如果您使用的是Linux机器,请尝试:chmod +r file.hdf

2) Perhaps you have to change permissions to the file itself. If you are in a linux machine try: chmod +r file.hdf

您可以尝试使用 HDFView 打开文件.该软件可在多个平台上使用.您可以使用它很容易地检查文件的属性.

You can try to open your file with HDFView. This software is available in several platforms. You can check the properties of the files very easily with it.

这篇关于使用适用于python的h5py包读取hdf文件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆