# this guide requires python 3.6 import sys sys.version import numpy as np import h5py # open the file read-only, with error handling try: h5 = h5py.File("pshell-20200824-191714-ManipulatorScan.h5", "r") except OSError: print("error opening file") # just checkin' print(h5.file.filename) # what's inside the file at top level? h5.keys() # the general group contains the experiment metadata general = h5['general'] general.keys() # authors is an array, the other ones are singletons # call the decode method to convert to string print([v.decode() for v in general['authors']]) print(general['pgroup'][()].decode()) print(general['sample'][()].decode()) # most files contain just one scan group. # XPS spectra, e.g., can contain multiple scans. # # what's inside a scan group? h5['scan 1'].keys() import matplotlib.pyplot as plt # the datasets (all items except 'attrs' and 'meta') contain the measured data # they are represented as numpy datasets and can be plotted directly plt.plot(h5['scan 1']['ManipulatorPhi'], h5['scan 1']['Counts']) # the attrs group contains beamline status h5['scan 1']['attrs'].keys() # create a shortcut to the first scan group # scan1 and h5['scan 1'] can be used interchangeably scan1 = h5['scan 1'] print(scan1) # a scan group also contains direct 'attributes' # note that 'attributes' is used with several different meanings - unfortunately: # - the scan group contains another group called 'attrs' # - the scan group has 'attributes', which are represented in h5py by the 'attrs' attribute :-o # scan1.attrs.keys() # number of scan dimensions print(scan1.attrs['Dimensions']) # number of scan steps print(scan1.attrs['Steps']) # number of iterations (XPS spectra only) try: print(scan1.attrs['Iterations']) except KeyError: print("(no iterations)") # number of passes print(scan1.attrs['Passes']) # start and end time in microseconds print((scan1.attrs['End'] - scan1.attrs['Start']) / 1000 / 60) # list of scan positioners scan1.attrs['Writables'] # remember to cast to string scan1.attrs['Writables'][0].decode() # list of detectors scan1.attrs['Readables'] # note - these are the names of the datasets in the scan group! scan1.keys()