Код: Выделить всё
group_names = ["Group1", "Group2"]
# Open the input HDF5 file
with h5py.File(input_file, "r") as f:
for group_name in group_names:
for key in f.keys():
# Check if the key matches the desired group_name and contains "radius"
if group_name in key and "radius" in key:
# Define the group path
group_path = f[key]
# Open a new HDF5 file for writing
with h5py.File(path + f"{group_name}.h5", "w") as h5_out:
# Copy attributes
for attr in group_path.attrs:
h5_out.attrs[attr] = group_path.attrs[attr]
# Copy datasets
for dataset_name, dataset in group_path.items():
# Copy the dataset directly to the root of the new file
h5_out.create_dataset(dataset_name, data=dataset[...], **dataset.attrs)
print(f"Copied contents of group '{key}' to '{output_file}' without the extra layer.")
Код: Выделить всё
HDF5 "input_file.h5" {
FILE_CONTENTS {
group /
group /Group1
dataset /Group1/data
group /Group2
dataset /Group2/data
}}
Подробнее здесь: https://stackoverflow.com/questions/793 ... om-h5-file
Мобильная версия