Skip to content

Commit

Permalink
G5list: add --layer option for speed (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdegeus committed Mar 5, 2022
1 parent 7e7a7ff commit 4c16aca
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions GooseHDF5/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1239,14 +1239,18 @@ def _G5list_parser():
Return parser for :py:func:`G5list`.
"""

desc = "List datasets (or groups of datasets) in a HDF5-file"
desc = """List datasets (or groups of datasets) in a HDF5-file.
Note that if you have a really big file the ``--layer`` option can be much faster than
searching the entire file.
"""
parser = argparse.ArgumentParser(description=desc)
parser.add_argument("-D", "--datasets", action="store_true", help="Print only datasets")
parser.add_argument("-d", "--max-depth", type=int, help="Maximum depth to display")
parser.add_argument("-f", "--fold", action="append", help="Fold paths")
parser.add_argument("-i", "--info", action="store_true", help="Print info: shape, dtype")
parser.add_argument("-l", "--long", action="store_true", help="--info but with attributes")
parser.add_argument("-r", "--root", default="/", help="Start somewhere in the path-tree")
parser.add_argument("-L", "--layer", type=str, help="Print paths at a specific layer")
parser.add_argument("-v", "--version", action="version", version=version)
parser.add_argument("source")
return parser
Expand All @@ -1266,10 +1270,15 @@ def G5list(args: list[str]):

with h5py.File(args.source, "r") as source:

paths = list(getdatasets(source, root=args.root, max_depth=args.max_depth, fold=args.fold))
if not args.datasets:
paths += getgroups(source, root=args.root, has_attrs=True, max_depth=args.max_depth)
paths = sorted(list(set(paths)))
if args.layer is not None:
paths = sorted(join(args.layer, i, root=True) for i in source[args.layer])
else:
paths = list(
getdatasets(source, root=args.root, max_depth=args.max_depth, fold=args.fold)
)
if not args.datasets:
paths += getgroups(source, root=args.root, has_attrs=True, max_depth=args.max_depth)
paths = sorted(list(set(paths)))

if args.info:
print_info(source, paths)
Expand Down

0 comments on commit 4c16aca

Please sign in to comment.