Skip to content

Commit

Permalink
make recursive_copy() work both ways
Browse files Browse the repository at this point in the history
  • Loading branch information
kerberizer committed Sep 13, 2024
1 parent 3239da1 commit 1d9c872
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/rcapi/services/convertor_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,21 @@ async def solr2image(solr_url,domain,figsize=(6,4),extraprm=None):
rs.close


def recursive_copy(src_group : h5py.Group, dst_group : h5py.Group,level=0):
def recursive_copy(
src_group: h5py.Group | h5pyd.Group, dst_group: h5py.Group | h5pyd.Group, level=0
):
# every File instance is also an HDF5 group
# Copy attributes of the current group
for attr_name, attr_value in src_group.attrs.items():
dst_group.attrs[attr_name] = attr_value
for index,key in enumerate(src_group):
try:
item = src_group[key]
if isinstance(item, h5pyd.Group):
if isinstance(item, (h5py.Group, h5pyd.Group)):
# Create the group in the destination file
new_group = dst_group.create_group(key)
recursive_copy(item, new_group,level+1)
elif isinstance(item, h5pyd.Dataset):
elif isinstance(item, (h5py.Dataset, h5pyd.Dataset)):
if item.shape == (): # Scalar dataset
# Copy the scalar value directly
dst_dataset = dst_group.create_dataset(key, data=item[()])
Expand Down

0 comments on commit 1d9c872

Please sign in to comment.