【MODIS\VIIRS】h5文件信息查看python代码
import os
import h5py
输入文件夹路径
input_folder = ‘D:\2_data\VNP212025001_033’
筛选出 .h5 文件
h5_files = [f for f in os.listdir(input_folder) if f.endswith(‘.h5’)]
if not h5_files:
print(“未找到 HDF5 文件,请检查输入文件夹。”)
else:
# 选择第一个 HDF5 文件
h5_file_name = h5_files[0]
h5_file_path = os.path.join(input_folder, h5_file_name)
print(f"尝试打开的文件路径: {h5_file_path}")
try:
# 使用 h5py 打开 HDF5 文件
with h5py.File(h5_file_path, 'r') as h5_file:
def print_all_paths(group, current_path=''):
for key in group.keys():
# 替换键中的空格
clean_key = key.replace(" ", "_")
new_path = f"{current_path}/{clean_key}" if current_path else clean_key
item = group[key]
if isinstance(item, h5py.Group):
print(f"Group: {new_path}")
print_all_paths(item, new_path)
else:
print(f"Dataset: {new_path}")
print("HDF5 文件的完整结构:")
print_all_paths(h5_file)
except OSError as e:
print(f"打开文件时出错: {e}")C](这里写自定义目录标题)