XPD HDF5 files: data analysis and visualization

In [1]:
%pylab inline
Populating the interactive namespace from numpy and matplotlib
In [2]:
#import necessary python modules
import os
import h5py
import numpy as np
import matplotlib.pyplot as plt
In [3]:
file_prefix = 'FELsource_out_';data_dir = 'data/99';num_run='99'
filename = os.path.join(data_dir, file_prefix + str(num_run).zfill(7) + '.h5')
f = h5py.File(filename,'r')
In [4]:
def print_name(name, obj):
    if isinstance(obj, h5py.Dataset):
        print 'Dataset:', name
    elif isinstance(obj, h5py.Group):
        print 'Group:', name
In [5]:
with h5py.File(filename, 'r')  as h5f: # file will be closed when we exit from WITH scope
    h5f.visititems(print_name) # print all strustures names
Group: data
Dataset: data/arrEhor
Dataset: data/arrEver
Group: history
Group: history/parent
Group: history/parent/info
Dataset: history/parent/info/data_description
Dataset: history/parent/info/package_version
Group: history/parent/misc
Dataset: history/parent/misc/FAST2XYDAT
Dataset: history/parent/misc/angular_distribution
Dataset: history/parent/misc/gain_curve
Dataset: history/parent/misc/intensity
Dataset: history/parent/misc/nzc
Dataset: history/parent/misc/spot_size
Dataset: history/parent/misc/temporal_struct
Group: misc
Dataset: misc/electricField
Dataset: misc/resizing
Group: params
Group: params/Mesh
Dataset: params/Mesh/nSlices
Dataset: params/Mesh/nx
Dataset: params/Mesh/ny
Dataset: params/Mesh/sliceMax
Dataset: params/Mesh/sliceMin
Dataset: params/Mesh/xMax
Dataset: params/Mesh/xMin
Dataset: params/Mesh/yMax
Dataset: params/Mesh/yMin
Dataset: params/Mesh/zCoord
Dataset: params/Rx
Dataset: params/Ry
Dataset: params/dRx
Dataset: params/dRy
Dataset: params/nval
Dataset: params/photonEnergy
Dataset: params/wDomain
Dataset: params/wEFieldUnit
Dataset: params/wSpace
Dataset: params/xCentre
Dataset: params/yCentre
Dataset: version
In [6]:
with h5py.File(filename, 'r')  as h5f: # file will be closed when we exit from WITH scope
    fast2xydat = h5f['history/parent/info/data_description'].value
    spot_size =            h5f['history/parent/misc/spot_size'].value
    angular_distribution = h5f['history/parent/misc/angular_distribution'].value
    gain_curve =           h5f['history/parent/misc/gain_curve'].value
    temporal_struct =      h5f['history/parent/misc/temporal_struct'].value
    intensity = h5f['history/parent/misc/intensity'].value 
    xmin = h5f['params/Mesh/xMin'].value
    xmax = h5f['params/Mesh/xMax'].value
    ymin = h5f['params/Mesh/yMin'].value
    ymax = h5f['params/Mesh/yMax'].value
    nzc = h5f['history/parent/misc/nzc'].value
    #spectrum0 = h5f['history/parent/detail/misc/spectrum_xy0'].value

Gain curve

In [8]:
fig, ax1 = plt.subplots()
ax1.plot(gain_curve[:,1]*1.e-2,gain_curve[:,2]*1.e3,'m-',label = '$G(z)$')
ax1.grid(True)
ax1.set_xlim(min(gain_curve[:,1])*1.e-2,max(gain_curve[:,1])*1.e-2)
ax1.set_xlabel('undulator length z [m]')
ax1.set_ylabel('Pulse energy $G$ [$\mu$J]')
ax2 = ax1.twiny()
ax2.plot(gain_curve[:,0],gain_curve[:,2]*1.e3,'m^',label = '$G(nzc)$' )
ax2.set_xlim(min(gain_curve[:,0]),max(gain_curve[:,0]))
ax2.set_xlabel('nzc')
lines1, labels1 = ax1.get_legend_handles_labels()
lines2, labels2 = ax2.get_legend_handles_labels()
ax2.legend(lines1 + lines2, labels1 + labels2, loc=0)
plt.show()

Time structure

In [9]:
plt.plot(temporal_struct[:,0],temporal_struct[:,1]*1e-9,'b-')
plt.title('Pulse time structure')
plt.xlabel('[fs]')
plt.ylabel('[GW]')
plt.show()
    

Pulse intensity distribution

In [10]:
plt.figure(figsize=(20, 7))
plt.subplot(131)
plt.imshow(intensity*1e3,extent=[xmin*1e3,xmax*1e3,ymin*1e3,ymax*1e3])
plt.xlabel('mm')
plt.ylabel('mm')
#plt.colorbar(orientation='horizontal')
plt.subplot(132)
plt.plot(spot_size[:,0],spot_size[:,1],'ro')
plt.title('Spot size')
plt.xlim(0,0.02)
plt.xlabel('[cm]')
plt.show()
In [11]:
plt.plot(angular_distribution[:,0]*1e6,angular_distribution[:,1],'bv')
plt.title('Far field angular divergence')
plt.xlim(0,10.)
plt.xlabel('[$\mu$rad]')
plt.show()
    
In [ ]: