rypy91 commited on
Commit
f70850f
·
verified ·
1 Parent(s): fa9433f

Upload extract_h5.py

Browse files

Example for data usage.

Files changed (1) hide show
  1. extract_h5.py +16 -0
extract_h5.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import h5py
2
+
3
+ # File path
4
+ filename = 'frac_pull_z_15044.h5'
5
+
6
+ # Save data to dictionary
7
+ data_dict = {}
8
+
9
+ # Open and traverse the HDF5 file
10
+ with h5py.File(filename, 'r') as f:
11
+ def collect_datasets(name, obj):
12
+ if isinstance(obj, h5py.Dataset):
13
+ print(f"Loading dataset: {name}, shape: {obj.shape}, dtype: {obj.dtype}")
14
+ data_dict[name] = obj[()] # Load entire dataset into memory
15
+
16
+ f.visititems(collect_datasets) # walk through h5 and collect in data_dict