def analysis(g): spectrum_lamdwidth_fwhm = np.zeros_like(g.z) spectrum_lamdwidth_std = np.zeros_like(g.z) for zz in range(g.nZ): spectrum_lamdwidth_fwhm[zz] = None spectrum_lamdwidth_std[zz] = None if np.sum(g.spec[:, zz]) != 0: pos, width, arr = fwhm3(g.spec[:, zz]) if width != None: if arr[0] == arr[-1]: dlambda = abs(g.freq_lamd[pos] - g.freq_lamd[pos - 1]) else: dlambda = abs( (g.freq_lamd[arr[0]] - g.freq_lamd[arr[-1]]) / (arr[0] - arr[-1])) spectrum_lamdwidth_fwhm[ zz] = dlambda * width / g.freq_lamd[pos] # spectrum_lamdwidth_fwhm[zz] = abs(g.freq_lamd[arr[0]] - g.freq_lamd[arr[-1]]) / g.freq_lamd[pos] # the FWHM of spectral line (error when peakpos is at the edge of lamdscale) spectrum_lamdwidth_std[zz] = std_moment( g.freq_lamd, g.spec[:, zz]) / n_moment(g.freq_lamd, g.spec[:, zz], 0, 1) ######### end of section copied from genesis_plot.py brightness = g.energy / spectrum_lamdwidth_std for i in range(len(g.z)): if g.z[i] < 1: brightness[i] = 0 return g.energy, spectrum_lamdwidth_std, g.z, brightness, g.p_int, g.xrms, g.yrms, g.I, g.s
def evalBeamWithGenesis(dir, run=True, startcharge=250, genesis_file='NEW_SHORT_NOM_TD_v7.in', beam_file='CLA-FMS-APER-02.hdf5'): # Genesis run: data={'gen_file': genesis_file, 'file_pout': dir, 'file_beam':'beamfile.txt', 'i_scan':0, 'gen_launch':'', 'stat_run':1, 'idump':0, 'i_edist':0, 'i_beam':0, 'i_rad':0, 'i_dpa':0, 'i_dfl':0, 'i_HDF5':1, 'HDF5_file': dir+'/'+beam_file, 'i_match': 0} if run: data['gen_launch'] = '/opt/OpenMPI-3.1.3/bin/mpiexec --timeout 600 -np 12 /opt/Genesis/bin/genesis2 < tmp.cmd 2>&1 > /dev/null' else: data['gen_launch'] = '' f = FEL_sim(data) A_inp = f.read_GEN_input_file() g = f.GEN_simul_preproc(A_inp, dirno=dir, startcharge=startcharge) p = map(np.mean, zip(*g.p_int)) g.Lsat, g.Lsatindex = find_saturation(p, g.z) # this section is copied from genesis_plot.py - to calculate bandwidth spectrum_lamdwidth_fwhm = np.zeros_like(g.z) spectrum_lamdwidth_std = np.zeros_like(g.z) for zz in range(g.nZ): spectrum_lamdwidth_fwhm[zz] = None spectrum_lamdwidth_std[zz] = None if np.sum(g.spec[:,zz])!=0: pos, width, arr = fwhm3(g.spec[:, zz]) if width != None: if arr[0] == arr[-1]: dlambda = abs(g.freq_lamd[pos] - g.freq_lamd[pos-1]) else: dlambda = abs( (g.freq_lamd[arr[0]] - g.freq_lamd[arr[-1]]) / (arr[0] - arr[-1]) ) spectrum_lamdwidth_fwhm[zz] = dlambda * width / g.freq_lamd[pos] # spectrum_lamdwidth_fwhm[zz] = abs(g.freq_lamd[arr[0]] - g.freq_lamd[arr[-1]]) / g.freq_lamd[pos] # the FWHM of spectral line (error when peakpos is at the edge of lamdscale) spectrum_lamdwidth_std[zz] = std_moment(g.freq_lamd, g.spec[:, zz]) / n_moment(g.freq_lamd, g.spec[:, zz], 0, 1) ######### end of section copied from genesis_plot.py brightness = g.energy / spectrum_lamdwidth_std for i in range(len(g.z)): if g.z[i] < 5: brightness[i] = 0 max = np.argmax(brightness) maxe = np.argmax(g.energy) g.spectrum_lamdwidth_std = spectrum_lamdwidth_std return g.energy[max], g.spectrum_lamdwidth_std[max], g.z[max], g.energy[maxe], g.spectrum_lamdwidth_std[maxe], g.z[maxe], g.bunch_length, g
def evalBeamWithGenesis(dir, dirno=1): # Genesis run: data = { 'gen_file': 'NEW_SHORT_NOM_TD_v7.in', 'file_pout': outputdir, 'file_beam': 'beamfile.txt', 'i_scan': 0, 'gen_launch': '/opt/OpenMPI-3.1.3/bin/mpiexec --timeout 300 -np 5 /opt/Genesis/bin/genesis2 < tmp.cmd 2>&1 > /dev/null', 'stat_run': 1, 'idump': 0, 'i_edist': 0, 'i_beam': 0, 'i_rad': 0, 'i_dpa': 0, 'i_dfl': 0, 'i_HDF5': 1, 'HDF5_file': dir + '/' + 'CLA-FMS-APER-01.hdf5', 'i_match': 0 } f = FEL_sim(data) A_inp = f.read_GEN_input_file() g = f.GEN_simul_preproc(A_inp, dirno=dirno) # this section is copied from genesis_plot.py - to calculate bandwidth spectrum_lamdwidth_fwhm = np.zeros_like(g.z) spectrum_lamdwidth_std = np.zeros_like(g.z) for zz in range(g.nZ): spectrum_lamdwidth_fwhm[zz] = None spectrum_lamdwidth_std[zz] = None if np.sum(g.spec[:, zz]) != 0: pos, width, arr = fwhm3(g.spec[:, zz]) if width != None: if arr[0] == arr[-1]: dlambda = abs(g.freq_lamd[pos] - g.freq_lamd[pos - 1]) else: dlambda = abs( (g.freq_lamd[arr[0]] - g.freq_lamd[arr[-1]]) / (arr[0] - arr[-1])) spectrum_lamdwidth_fwhm[ zz] = dlambda * width / g.freq_lamd[pos] # spectrum_lamdwidth_fwhm[zz] = abs(g.freq_lamd[arr[0]] - g.freq_lamd[arr[-1]]) / g.freq_lamd[pos] # the FWHM of spectral line (error when peakpos is at the edge of lamdscale) spectrum_lamdwidth_std[zz] = std_moment( g.freq_lamd, g.spec[:, zz]) / n_moment(g.freq_lamd, g.spec[:, zz], 0, 1) ######### end of section copied from genesis_plot.py return g.energy[-1], spectrum_lamdwidth_std[-1]
def evalBeamWithGenesis(ind, zpos=s): print 'in evalBeamWithGenesis\n\n\n' print ind # copy file to backup location with random file name (needs better identifier...) if os.path.exists('scan_0/ip_seed_-1/run.0.gout') == True: os.system('cp scan_0/ip_seed_-1/run.0.gout genesis_out/run%i.out' % random.randint(10000, 99999)) os.system('rm -R scan_0') # normalise so that every list of rands adds to 1, then write beamfile sum_rands = sum(ind) norm_rands = ind / sum_rands sum_norm_rands = sum(norm_rands) current = norm_rands * av_current * num_slices write_beamfile('beamfile.txt', zpos, current) # Genesis run: data = { 'gen_file': 'NEW_SHORT_NOM_TD_v7.in', 'file_pout': outputdir, 'file_beam': 'beamfile.txt', 'i_scan': 0, 'gen_launch': 'genesis2.0', 'stat_run': 1, 'idump': 0, 'i_edist': 0, 'i_beam': 1, 'i_rad': 0, 'i_dpa': 0, 'i_dfl': 0 } #f = FEL_simulation_block.FEL_simulation_block(data) f = FEL_sim(data) A_inp = f.read_GEN_input_file() g = f.GEN_simul_preproc(A_inp) # this section is copied from genesis_plot.py - to calculate bandwidth spectrum_lamdwidth_fwhm = np.zeros_like(g.z) spectrum_lamdwidth_std = np.zeros_like(g.z) for zz in range(g.nZ): spectrum_lamdwidth_fwhm[zz] = None spectrum_lamdwidth_std[zz] = None if np.sum(g.spec[:, zz]) != 0: pos, width, arr = fwhm3(g.spec[:, zz]) if width != None: if arr[0] == arr[-1]: dlambda = abs(g.freq_lamd[pos] - g.freq_lamd[pos - 1]) else: dlambda = abs( (g.freq_lamd[arr[0]] - g.freq_lamd[arr[-1]]) / (arr[0] - arr[-1])) spectrum_lamdwidth_fwhm[ zz] = dlambda * width / g.freq_lamd[pos] # spectrum_lamdwidth_fwhm[zz] = abs(g.freq_lamd[arr[0]] - g.freq_lamd[arr[-1]]) / g.freq_lamd[pos] # the FWHM of spectral line (error when peakpos is at the edge of lamdscale) spectrum_lamdwidth_std[zz] = std_moment( g.freq_lamd, g.spec[:, zz]) / n_moment(g.freq_lamd, g.spec[:, zz], 0, 1) ######### end of section copied from genesis_plot.py #return Emax #print spectrum_lamdwidth_fwhm[-1] print 'bandwidth = ', spectrum_lamdwidth_std[-1] print 'pulse energy =', g.energy[-1] return g.energy[-1], spectrum_lamdwidth_std[-1]