5.00: '/sf/data/measurements/2021/04/25/2021_04_25-17_37_20_Lasing_False_SARBD02-DSCR050.h5', -4.4: '/sf/data/measurements/2021/04/25/2021_04_25-17_40_15_Lasing_False_SARBD02-DSCR050.h5', -4.42: '/sf/data/measurements/2021/04/25/2021_04_25-17_41_26_Lasing_False_SARBD02-DSCR050.h5', -4.38: '/sf/data/measurements/2021/04/25/2021_04_25-17_42_51_Lasing_False_SARBD02-DSCR050.h5', -4.36: '/sf/data/measurements/2021/04/25/2021_04_25-17_44_59_Lasing_False_SARBD02-DSCR050.h5', } screen_analysis = analysis.analyze_screen_calibration(screen_file) screen_center = screen_analysis['x0'] print('Screen center module', screen_center*1e6, 'um') calib_dict = h5_storage.loadH5Recursive(calib_file) raw_data = calib_dict['raw_data'] result0 = analysis.analyze_streaker_calibration(raw_data, True) print('Module streaker center', result0['meta_data']['streaker_offset']*1e6, 'um') mask = np.logical_and(raw_data['streaker_offsets'] < 5.04e-3, raw_data['streaker_offsets'] > -0.0044) #mask = np.ones_like(raw_data['streaker_offsets'], dtype=bool) raw_data['streaker_offsets'] = raw_data['streaker_offsets'][mask] raw_data['pyscan_result']['image'] = raw_data['pyscan_result']['image'][mask] print(raw_data['streaker_offsets']) ms.figure('Screen projections') subplot = ms.subplot_factory(1,1) sp_proj = subplot(1, title='Screen projections', xlabel='x (mm)', ylabel='Intensity (arb. units)') screen_data = h5_storage.loadH5Recursive(screen_file) image = screen_data['pyscan_result']['image'][0]
elegant_matrix.set_tmp_dir('~/tmp_elegant/') center_plot = 'Mean' hostname = gethostname() if hostname == 'desktop': basedir = '/storage/data_2021-03-16/' archiver_dir = '/storage/Philipp_data_folder/archiver_api_data/' elif hostname == 'pc11292.psi.ch': basedir = '/sf/data/measurements/2021/03/16/' elif hostname == 'pubuntu': basedir = '/mnt/data/data_2021-03-16/' archiver_dir = '/mnt/data/archiver_api_data/' streaker_calib_file = basedir + '2021_03_16-20_07_45_Calibration_SARUN18-UDCP020.h5' streaker_calib = analysis.analyze_streaker_calibration(streaker_calib_file, True) streaker_offset = streaker_calib['meta_data']['streaker_offset'] #print('WARNING') #streaker_offset -= 20e-6 screen_calib_file = basedir + '2021_03_16-20_14_10_Screen_Calibration_data_SARBD02-DSCR050.h5' screen_calib = analysis.analyze_screen_calibration(screen_calib_file, False) x0 = screen_calib['x0'] beamsize = screen_calib['beamsize'] blmeas = basedir + '113875557_bunch_length_meas.h5' blmeas = basedir + '113876237_bunch_length_meas.h5' tt_halfrange = 200e-15 charge = 200e-12
gap_mm = 10 projections = np.zeros( [len(dict_['Image']), len(dict_['Image'][0]), len(x_axis)], dtype=np.float32) for a, b in itertools.product(range(len(dict_['Image'])), range(len(dict_['Image'][0]))): projections[a, b] = dict_['Image'][a][b].sum(axis=-1) new_dict = { 'streaker_offsets': new_offsets, 'screen': screen, 'n_images': projections.shape[1], 'streaker': streaker, 'pyscan_result': { 'x_axis_m': x_axis, 'projx': projections, }, 'meta_data': { streaker + ':GAP': gap_mm, }, } h5_storage.saveH5Recursive(matfile.replace('.mat', '_new.h5'), new_dict) streaker_analysis = analysis.analyze_streaker_calibration(new_dict) plt.show()
import matplotlib.pyplot as plt import socket import h5_storage import analysis plt.close('all') hostname = socket.gethostname() if 'psi' in hostname or 'lc6a' in hostname or 'lc7a' in hostname: default_dir = '/sf/data/measurements/2021/04/25/' archiver_dir = '/afs/psi.ch/intranet/SF/Beamdynamics/Philipp/data/archiver_api_data/' elif hostname == 'desktop': default_dir = '/storage/data_2021-04-25/' archiver_dir = '/storage/Philipp_data_folder/archiver_api_data/' elif hostname == 'pubuntu': default_dir = '/home/work/data_2021-04-25/' archiver_dir = '/home/work/archiver_api_data/' streaker_calib_file = default_dir + '2021_04_25-16_55_25_Calibration_SARUN18-UDCP020.h5' data_dict = h5_storage.loadH5Recursive(streaker_calib_file) analysis.analyze_streaker_calibration(data_dict['raw_data']) plt.show()
data_dir = '/storage/data_2021-03-16/' elif hostname == 'pc11292.psi.ch': data_dir = '/sf/data/measurements/2021/03/16/' elif hostname == 'pubuntu': data_dir = '/mnt/data/data_2021-03-16/' fig, plot_handles = analysis.streaker_calibration_figure() fig.subplots_adjust(wspace=0.3) streaker_calib_file = data_dir + '2021_03_16-20_07_45_Calibration_SARUN18-UDCP020.h5' streaker_calib = h5_storage.loadH5Recursive(streaker_calib_file) #streaker_calib['raw_data']['streaker_offsets'] = streaker_calib['raw_data']['streaker_offsets'][:-1] #streaker_calib['raw_data']['pyscan_result']['image'] = streaker_calib['raw_data']['pyscan_result']['image'][:-1] analyzed = analysis.analyze_streaker_calibration(streaker_calib['raw_data'], plot_handles=plot_handles) print('Streaker offset [um]: %.3f' % (analyzed['meta_data']['streaker_offset'] * 1e6)) images = streaker_calib['raw_data']['pyscan_result']['image'].astype(float) x_axis = streaker_calib['raw_data']['pyscan_result']['x_axis'].astype(float) streaker_offsets = streaker_calib['raw_data']['streaker_offsets'] - 377e-6 n_offsets = images.shape[0] n_images = images.shape[1] #sp_ctr = np.inf #nx, ny = 3, 3 #subplot = ms.subplot_factory(ny, nx) # # #for n_offset in range(n_offsets):
default_dir + '2021_04_25-16_55_25_Calibration_SARUN18-UDCP020.h5', ] ms.figure('Compare streaker calibrations') subplot = ms.subplot_factory(2,2) sp_ctr = 1 sp_center = subplot(sp_ctr, title='Centroid shift', xlabel='Streaker center (mm)', ylabel='Beam X centroid (mm)') sp_ctr += 1 sp_sizes = subplot(sp_ctr, title='Size increase', xlabel='Streaker center (mm)', ylabel='Beam X rms (mm)') sp_ctr += 1 for ctr, calib_file in enumerate(streaker_calib_files): dict0 = h5_storage.loadH5Recursive(calib_file)['raw_data'] dict_ = analysis.analyze_streaker_calibration(dict0)['meta_data'] plt.suptitle(calib_file) streaker_offset = dict_['streaker_offset'] screen_x0 = dict_['screen_x0'] offsets = dict_['offsets'] xx_plot = (offsets-streaker_offset)*1e3 yy_plot = dict_['centroid_mean'] - screen_x0 color = sp_center.errorbar(xx_plot, yy_plot*1e3, yerr=dict_['centroid_std']*1e3, label=ctr, ls='None', lw=3)[0].get_color() sp_center.plot((dict_['fit_xx']-streaker_offset)*1e3, (dict_['fit_reconstruction']-screen_x0)*1e3, color=color, ls='--') yy_plot = dict_['rms_mean'] - screen_x0 sp_sizes.errorbar(xx_plot, yy_plot*1e3, yerr=dict_['rms_std']*1e3, label=ctr, ls='None') sp_center.legend()
from h5_storage import loadH5Recursive import analysis plt.close('all') hostname = gethostname() if hostname == 'desktop': data_dir = '/storage/data_2021-05-18/' elif hostname == 'pc11292.psi.ch': data_dir = '/sf/data/measurements/2021/05/18/' elif hostname == 'pubuntu': data_dir = '/mnt/data/data_2021-05-18/' #calib_data = loadH5Recursive(data_dir+'2021_05_18-23_07_20_Calibration_SARUN18-UDCP020.h5')['raw_data'] #calib_data2 = loadH5Recursive(data_dir+'2021_05_18-23_32_12_Calibration_SARUN18-UDCP020.h5')['raw_data'] # #calib_dict = analysis.analyze_streaker_calibration(calib_data, do_plot=True, fit_order=False)['meta_data'] #calib_dict2 = analysis.analyze_streaker_calibration(calib_data2, do_plot=True, fit_order=False)['meta_data'] # #print('%i' % (calib_dict['streaker_offset']*1e6), calib_dict['order_fit'], True) #print('%i' % (calib_dict2['streaker_offset']*1e6), calib_dict2['order_fit'], False) calib_data = loadH5Recursive( data_dir + '2021_05_18-22_11_36_Calibration_SARUN18-UDCP020.h5')['raw_data'] calib_dict = analysis.analyze_streaker_calibration( calib_data, do_plot=True, fit_order=False)['meta_data'] plt.show()