%pylab inline
#import necessary python modules
import os
import h5py
import numpy as np
import matplotlib.pyplot as plt
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')
def print_name(name, obj):
if isinstance(obj, h5py.Dataset):
print 'Dataset:', name
elif isinstance(obj, h5py.Group):
print 'Group:', name
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
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
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()
plt.plot(temporal_struct[:,0],temporal_struct[:,1]*1e-9,'b-')
plt.title('Pulse time structure')
plt.xlabel('[fs]')
plt.ylabel('[GW]')
plt.show()
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()
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()