Package: h5analysis
CLS H5AnalysisThis is a library to analyse, plot, and export HDF5 data. The package is meant to provide a framework to load data into jupyter and enable data interaction.InstallationInstall the package from PyPi with the pip package manager. This is the recommended way to obtain a copy for your local machine and will install all required dependencies.$ pip install h5analysisYou will also needJupyter Notebooktogether with python 3 on your local machine.In case that certain widgets aren't rendered properly, make sure to enable the appropriate jupyter extensions$ jupyter nbextension enable --py widgetsnbextensionRunningLaunch your local jupyter installation with$ jupyter notebookExamplesLoad the required moduleBefore you start, you will need to import the required h5analysis package, and enable bokeh plotting.## Setup necessarry inputs
from h5analysis.LoadData import *
from h5analysis.config import h5Config
from bokeh.io import show, output_notebook
output_notebook(hide_banner=True)All data loaders require a proper configuration variable which is beamline/data format specific. An example configuration for the CLS REIXS beamline may look like this:config = h5Config()

config.key("SCAN_{scan:03d}",'scan')
config.sca_folder('Data')

config.sca('Mono Energy','Data/beam')
config.sca('Mesh Current','Data/i0')
config.sca('Sample Current','Data/tey')
config.sca('TEY','Data/tey','Data/i0')
config.sca("MCP Energy", 'Data/mcpMCA_scale')
config.sca("SDD Energy", 'Data/sddMCA_scale')
config.sca("XEOL Energy", 'Data/xeolMCA_scale')

config.mca('SDD','Data/sddMCA','Data/sddMCA_scale',None)
config.mca('MCP','Data/mcpMCA','Data/mcpMCA_scale',None)
config.mca('XEOL','Data/xeolMCA','Data/xeolMCA_scale',None)

config.stack('mcpSTACK','Data/mcp_a_img','Data/mcpMCA_scale',None,None)1d plotssca = Load1d()
sca.load(config,'FileName.h5','x_stream','y_stream',1,2,3,4)  # Loads multiple scans individually
sca.add(config,'FileName.h5','x_stream','y_stream',1,2,3,4)  # Adds multiple scans
sca.subtract(config,'FileName.h5','x_stream','y_stream',1,2,3,4,norm=False) # Subtracts scans from the first scan
sca.xlim(lower_lim,upper_lim) # Sets the horizontal axis plot region
sca.ylim(lower_lim,upper_lim) # Sets the vertical axis plot region
sca.plot_legend("pos string as per bokeh") # Determines a specific legend position
sca.vline(position) # Draws a vertical line
sca.hline(position) # Draws a horizontal line
sca.label(pos_x,pos_y,'Text') # Adds a label to the plot
sca.plot() # Plots the defined object
sca.exporter() # Exports the data by calling an exporter widgetCreate "Loader" objectEnter the file name of the scan to analyse ('FileName.h5')Options forx_streamquantities include:All quantities contained in the sca folder(s) specified in the configAll SCA specified in the configOptions fory_streamquantities include:All quantities contained in the sca folder(s) specified in the configAll SCA specified in the configAll MCA specified in the config with applied ROIAll STACK specified in the config with two applied ROIsList all scans to analyse (comma-separated)Set optional flags. Options include:norm(Normalizes to [0,1])xcoffset(Defines a constant shift in the x-stream)xoffset(Takes a list of tuples and defines a polynomial fit of the x-stream)ycoffset(Defines a constant shift in the y-stream)yoffset(Takes a list of tuples and defines a polynomial fit of the y-stream)
e.g. offset = [(100,102),(110,112),(120,121)]grid_x(Takes a list with three arguments to apply 1d interpolation gridding)
e.g. grid_x = [Start Energy, Stop Energy, Delta]savgol(Takes a list with two or three arguments to apply data smoothing and derivatives)
e.g. savgol = [Window length, Polynomial order, deriavtive] as specified in the scipy Savitzky-Golay filterbinsize(int, allows to perform data binning to improve Signal-to-Noise)legend_items(dict={scan_number:"name"}, overwrites generic legend names; works for theloadmethod)legend_item(str, overwrites generic legend name in theadd/subtractmethod)2d ImagesNote: Can only load one scan at a time!General loader for MCA detector dataload2d = Load2d()
load2d.load(config,'Filename.h5','x_stream','detector',1)
load2d.plot()
load2d.exporter()Create "Loader" objectEnter the file name of the scan to analyse ('FileName.h5')Options forx_streamquantities include:All quantities contained in the sca folder(s) specified in the configAll SCA specified in the configOptions fordetectorquantities include:All MCA specified in the configAll STACK specified in the config with applied ROISelect scan to analyse (comma-separated)Set optional flags. Options include:norm(Normalizes to [0,1])xcoffset(Defines a constant shift in the x-stream)xoffset(Takes a list of tuples and defines a polynomial fit of the x-stream)ycoffset(Defines a constant shift in the y-stream)yoffset(Takes a list of tuples and defines a polynomial fit of the y-stream)
e.g. offset = [(100,102),(110,112),(120,121)]grid_x(Takes a list with three arguments to apply 1d interpolation gridding)
e.g. grid_x = [Start Energy, Stop Energy, Delta]norm_by(Normalizes to specified stream)2d histogrammesh = LoadMesh()
mesh.load(config,'Filename.h5','x_stream','y_stream','z_stream',24)
mesh.plot()
mesh.exporter()Create "Loader" objectEnter the file name of the scan to analyse ('FileName.h5')Options forx_streamquantities include:All quantities contained in the sca folder(s) specified in the configAll SCA specified in the configAll MCA specified in the config with ROI specifiedAll STACK specified in the config with two ROIs specifiedOptions fory_streamquantities include:All quantities contained in the sca folder(s) specified in the configAll SCA specified in the configAll MCA specified in the config with ROI specifiedAll STACK specified in the config with two ROIs specifiedOptions forz_streamquantities include:All quantities contained in the sca folder(s) specified in the configAll SCA specified in the configAll MCA specified in the config with ROI specifiedAll STACK specified in the config with two ROIs specifiedSpecify scan to analyseSet optional flags. Options include:norm(Normalizes to [0,1])xcoffset(Defines a constant shift in the x-stream)xoffset(Takes a list of tuples and defines a polynomial fit of the x-stream)ycoffset(Defines a constant shift in the y-stream)yoffset(Takes a list of tuples and defines a polynomial fit of the y-stream)
e.g. offset = [(100,102),(110,112),(120,121)]3d ImagesNote: Can only load one scan at a time!load3d = Load2d()
load3d.load(config,'Filename.h5','ind_stream','stack',1)
load3d.plot()
load3d.export()Create "Loader" objectEnter the file name of the scan to analyse ('FileName.h5')Enter SCA name for independent stream, corresponding to length of first axis.Options forstackquantities include:All STACK specified in the configSelect scan to analyseSet optional flags. Options include:norm(Normalizes to [0,1])xcoffset(Defines a constant shift in the x-stream)xoffset(Takes a list of tuples and defines a polynomial fit of the x-stream)ycoffset(Defines a constant shift in the y-stream)yoffset(Takes a list of tuples and defines a polynomial fit of the y-stream)
e.g. offset = [(100,102),(110,112),(120,121)]grid_x(Takes a list with three arguments to apply 1d interpolation gridding)
e.g. grid_x = [Start Energy, Stop Energy, Delta]norm_by(Normalizes to specified stream)Meta Databl = LoadBeamline()
bl.load(config,'Filename.h5','path to variable')
bl.plot()Create "Loader" objectEnter the file name of the scan to analyse ('FileName.h5')Options forpath to variablequantities include:All directory paths within the specified h5 fileSpreadsheetdf = getSpreadsheet(config,'Filename.h5', average = False,columns=None)Create "Loader" objectEnter the file name of the scan to analyse ('FileName.h5')3a. Specify average booleanIf False, return all data (even if 1d array)If True, return average of 1d array where applicable3b. Options forcolumnsquantities include:Custom dictionary with column headers and quantities, see example below:columns = dict()

columns['Command'] = 'command'
columns['Sample Stage (ssh)'] = 'Endstation/Motors/ssh'
columns['Sample Stage (ssv)'] = 'Endstation/Motors/ssv'
columns['Sample Stage (ssd)'] = 'Endstation/Motors/ssd'
columns['Spectrometer (XES dist)'] = 'Endstation/Motors/spd'
columns['Spectrometer (XES angl)'] = 'Endstation/Motors/spa'
columns['Flux 4-Jaw (mm)'] = 'Beamline/Apertures/4-Jaw_2/horz_gap'
columns['Mono Grating'] = '/Beamline/Monochromator/grating'
columns['Mono Mirror'] = '/Beamline/Monochromator/mirror'
columns['Polarization'] = 'Beamline/Source/EPU/Polarization'
#columns['Comment'] = 'command'
columns['Status'] = 'status'