Skip to content
Snippets Groups Projects
Commit a34c5150 authored by Alexis GAMELIN's avatar Alexis GAMELIN
Browse files

Add a new tool to copy a HDF5 file to a different HDF5 version

parent 20c9a759
No related branches found
No related tags found
No related merge requests found
...@@ -25,4 +25,4 @@ from mbtrack2.tracking.monitors.plotting import (plot_bunchdata, ...@@ -25,4 +25,4 @@ from mbtrack2.tracking.monitors.plotting import (plot_bunchdata,
plot_beamspectrum, plot_beamspectrum,
streak_beamspectrum) streak_beamspectrum)
from mbtrack2.tracking.monitors.tools import merge_files from mbtrack2.tracking.monitors.tools import (merge_files, copy_files)
\ No newline at end of file \ No newline at end of file
...@@ -71,5 +71,36 @@ def merge_files(files_prefix, files_number, file_name=None): ...@@ -71,5 +71,36 @@ def merge_files(files_prefix, files_number, file_name=None):
f[group][dataset_name][tuple(slice_list)] = fi[group][dataset_name] f[group][dataset_name][tuple(slice_list)] = fi[group][dataset_name]
fi.close() fi.close()
f.close() f.close()
def copy_files(source, copy, version=None):
"""
Copy a source hdf5 file into another hdf5 file using a different HDF5
version.
The function assumes that the source file has only a single group layer.
Parameters
----------
source : str
Name of the source file.
copy : str
Name of the copy file.
version : str, optional
Version number of the copy file.
"""
if version == None:
version = 'v108'
f = hp.File(source + ".hdf5", "r")
h = hp.File(copy + ".hdf5", "a", libver=('earliest', version))
## Copy file
for group in list(f):
h.require_group(group)
for dataset_name in list(f[group]):
h[group][dataset_name] = f[group][dataset_name][()]
f.close()
h.close()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment