data = np.array(item_pointer) if verbose: print "dataset: path=", item_path, " , shape=", data.shape, \ " , dtype=", data.dtype except: sys.exit("Path " + path + " is not valid") # ------------------------------------------------------------------------------ if __name__ == "__main__": # print "len(sys.argv)=", len(sys.argv) if len(sys.argv) in [2,3]: h5_data = sys.argv[1] verbose = 1 if len(sys.argv) == 3: verbose = int(sys.argv[2]) # print "verbose=", verbose else: sys.exit("\nUsage: h5_dump_summary.py <h5_file_or_dir> \n") file_list = h5lib.get_file_list(h5_data, "") # Parse the contexts of entire file, and dump its summary as text for h5_file in file_list: print "\nParsing file ", h5_file, "\n" base_name = os.path.basename(h5_file) h5_root = h5py.File(h5_file, "r") path = '/' parse_h5_item(h5_root, path, verbose)
# If the top hash group is specified, return its keys; # otherwise, return the keys of all top hash groups if __name__ == "__main__": if len(sys.argv) in [2,3,4]: h5_data = sys.argv[1] hash_group = '' if len(sys.argv) >= 3: hash_group = sys.argv[2] match_string = '' if len(sys.argv) == 4: match_string = sys.argv[3] else: sys.exit("\nUsage: h5_get_keys.py <h5_file_or_dir> [ <hash_group> [ match_string ] ] \n") file_list = h5lib.get_file_list(h5_data, match_string) for h5_file in file_list: orig_h5 = h5py.File(h5_file, "r") top_groups = h5lib.get_child_group_names(orig_h5) if len(hash_group) > 0: path_items = [hash_group, "keyNames", "keyNames"] key_list = h5lib.get_value_pointer_by_path_items(orig_h5, path_items) print h5_file, ",", hash_group, ": keys=", np.array(key_list).tolist() elif re.search("meta", h5_file): key_list = orig_h5.keys() print h5_file, ": keys=", np.array(key_list).tolist() for k in key_list: key_list2 = orig_h5[k].keys() if len(key_list2) > 1: print h5_file, ", ", k, ": keys2=", np.array(key_list2).tolist()
if __name__ == "__main__": if len(sys.argv) >= 1: h5_data = sys.argv[1] path_items = [] if len(sys.argv) >= 2: path_items = sys.argv[2:] else: sys.exit( "\nUsage: h5_get_value_by_path_items.py <h5_file_or_dir> [ <group(s)> ] \n" ) verbose = 0 # Compile a file list file_list = h5lib.get_file_list(h5_data, "meta") print "file_list=", file_list # Handle files in the file list for h5_file in file_list: orig_h5 = h5py.File(h5_file, "r") # Extract path in a given file value_pointer = "" try: value_pointer = h5lib.get_value_pointer_by_path_items( orig_h5, path_items) print h5_file + ": value_pointer.name=", value_pointer.name keys = value_pointer.keys() print "group: num_items=", len(keys), " items=" + str(keys) except:
data = np.array(item_pointer) if verbose: print "dataset: path=", item_path, " , shape=", data.shape, \ " , dtype=", data.dtype, " data=", data.tolist() except: sys.exit("Path " + path + " is not valid") # ------------------------------------------------------------------------------ if __name__ == "__main__": # print "len(sys.argv)=", len(sys.argv) if len(sys.argv) in [2, 3]: h5_data = sys.argv[1] verbose = 1 if len(sys.argv) == 3: verbose = int(sys.argv[2]) # print "verbose=", verbose else: sys.exit("\nUsage: h5_dump_all.py <h5_file_or_dir> \n") file_list = h5lib.get_file_list(h5_data, "") # Parse the contexts of entire file, and dump its summary as text for h5_file in file_list: print "\nParsing file ", h5_file, "\n" base_name = os.path.basename(h5_file) h5_root = h5py.File(h5_file, "r") path = '/' parse_h5_item(h5_root, path, verbose)