From d4f460561e9b53b48112a4d4f3c321bb3522e35a Mon Sep 17 00:00:00 2001 From: "Brian R. Pauw" Date: Wed, 5 Jul 2023 17:16:32 +0200 Subject: [PATCH] expanding functionality to start unrolling from a subtree --- pyscicat/hdf5/scientific_metadata.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pyscicat/hdf5/scientific_metadata.py b/pyscicat/hdf5/scientific_metadata.py index 8fe8533..4fe18f8 100644 --- a/pyscicat/hdf5/scientific_metadata.py +++ b/pyscicat/hdf5/scientific_metadata.py @@ -92,7 +92,7 @@ def unwind( def scientific_metadata( - filename, excludeRootEntry: bool = True, skipKeyList: list = [] + filename, excludeRootEntry: bool = True, skipKeyList: list = [], startPath:str="/" ) -> dict: """ Goals: @@ -106,6 +106,7 @@ def scientific_metadata( scientificMetadata=scientific_metadata(Path('./my_file.h5'), skipKeyList=['sasdata1']) If the root branch is singular, it can be omitted from the output dictionary by setting excludeRootEntry to True + The start path from where to traverse the tree can be specified with the "startPath" argument. """ # ensure the filename argument is of class Path @@ -116,7 +117,7 @@ def scientific_metadata( with h5py.File(filename, "r") as h5f: # let's see if we can do this simpler metadata = dict() # .fromkeys(prior_keys) - unwind(h5f, "/", metadata, skipKeyList=skipKeyList) + unwind(h5f, startPath, metadata, skipKeyList=skipKeyList) # first metadata entry is empty, so enter one level deeper. if len(metadata.keys()) == 1 and list(metadata.keys())[0] == "":