加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

使用python读取HDF4文件 – 多个具有相同名称的数据集

发布时间:2020-12-20 13:07:46 所属栏目:Python 来源:网络整理
导读:我有一个我需要用 python阅读的HDF4文件.为此,我使用pyhdf.在大多数情况下,我很高兴使用SD类打开文件: import pyhdf.SD as SDhdf = SD.SD(hdfFile) 然后继续 v1 = hdf.select('Data set 1')v2 = hdf.select('Data set 2') 但是我在HDF文件中有几个组,并且一
我有一个我需要用 python阅读的HDF4文件.为此,我使用pyhdf.在大多数情况下,我很高兴使用SD类打开文件:

import pyhdf.SD  as SD
hdf = SD.SD(hdfFile)

然后继续

v1 = hdf.select('Data set 1')
v2 = hdf.select('Data set 2')

但是我在HDF文件中有几个组,并且一些变量出现在具有相同名称的多个组中:

在第1组中,我有数据集3,在第2组中,所以我的选择命令只会选择其中一个(我不知道哪一个?).

有没有一种简单的方法可以从第1组中选择(读取)数据集3,然后从第2组中选择?

我看过V和VS模块.我找到了一个示例脚本,它将循环遍历所有组和子组等,并找到所有变量(数据集).但我现在有了如何将这些变量连接到父级的想法,因为我知道它们属于哪个组.

解决方法

我认为pyhdf可能不是这个特定任务的最佳选择.你看过 PyNIO吗?

从HDF section of their documentation开始:

PyNIO has a read-only ability to understand HDF Vgroups. When a variable that is part of a Vgroup is encountered,PyNIO appends a double underscore and the group number to the end of the variable name. This ensures that the variable will have a unique name,relative to variables that belong to other Vgroups. It also provides two additional attributes to the variable: hdf_group,whose value is the HDF string name of the group,and hdf_group_id,whose value is the same as the group number appended to the end of the variable name.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读