Created
July 6, 2023 20:17
-
-
Save edvb/963d2ae933a7ed2c7c8ef29e24a03939 to your computer and use it in GitHub Desktop.
Display metadata for H5 run file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Created on June 22, 2023 | |
@author: Ed van Bruggen (evanbruggen@umass.edu) | |
""" | |
import sys | |
import h5py | |
import pprint | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument('h5file') | |
parser.add_argument('-q', dest='quite_mode', action='store_true') | |
parser.add_argument('-v', dest='quite_mode', action='store_false') | |
parser.set_defaults(quite_mode=False) | |
args = parser.parse_args() | |
extra_attrs = [ 'AcquisitionMode', 'LowerLevel', 'Offset', 'OffsetTime', 'Preamp', 'Quota', | |
'Range', 'SampleTime', 'Shaper', 'ShaperGain1', 'ShaperGain2', 'SlowControlUser', | |
'TemperatureMean', 'TemperatureStdDev', 'TriggerSlope', 'TriggerSource', 'Xe(g)' ] | |
# Print all group's metadata | |
with h5py.File(args.h5file, 'r') as hdf: | |
print(f"Run metadata: {dict(hdf['RunData'].attrs)}") | |
for groupname in list(hdf['RunData'].keys()): | |
metadata = dict(hdf['RunData'][groupname].attrs) | |
print(f"{groupname}:") | |
print(f"size: {hdf['RunData'][groupname][:].shape[1]}") | |
if args.quite_mode: # if in quite mode don't print extra attributes | |
for attr in extra_attrs: | |
metadata.pop(attr) | |
pprint.pprint(metadata) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment