def __init__(self): super(StartMain, self).__init__() uic.loadUi('GUI.ui', self) self.DoReconstruction.clicked.connect(self.reconstruct_current) self.SaveCurrentRecData.clicked.connect(self.save_current_rec_data) self.SaveLasingRecData.clicked.connect(self.save_lasing_rec_data) self.CloseAll.clicked.connect(self.clear_rec_plots) self.ObtainStreakerFromLive.clicked.connect( self.obtain_streaker_settings_from_live) self.CalibrateStreaker.clicked.connect(self.calibrate_streaker) self.GapReconstruction.clicked.connect(self.gap_reconstruction) self.ClearCalibPlots.clicked.connect(self.clear_calib_plots) self.ClearGapRecPlots.clicked.connect(self.clear_gap_recon_plots) self.LoadCalibration.clicked.connect(self.load_calibration) self.CalibrateScreen.clicked.connect(self.calibrate_screen) self.ClearScreenPlots.clicked.connect(self.clear_screen_plots) self.ObtainReconstructionData.clicked.connect( self.obtain_reconstruction) self.ObtainLasingOnData.clicked.connect(self.obtainLasingOn) self.ObtainLasingOffData.clicked.connect(self.obtainLasingOff) self.ReconstructLasing.clicked.connect(self.reconstruct_all_lasing) self.ObtainR12.clicked.connect(self.obtain_r12_0) self.StreakerSelect.activated.connect(self.update_streaker) self.BeamlineSelect.activated.connect(self.update_streaker) self.update_streaker() # Default strings in gui fields hostname = socket.gethostname() if 'psi' in hostname or 'lc6a' in hostname or 'lc7a' in hostname: default_dir = '/sf/data/measurements/2021/05/18/' date = datetime.now() save_dir = date.strftime('/sf/data/measurements/%Y/%m/%d/') elif hostname == 'desktop': default_dir = '/storage/data_2021-05-18/' save_dir = '/storage/tmp_reconstruction/' elif hostname == 'pubuntu': default_dir = '/home/work/data_2021-05-18/' save_dir = '/home/work/tmp_reconstruction/' screen_calib_file = default_dir + 'Passive_data_20201003T231958.mat' bunch_length_meas_file = default_dir + '119325494_bunch_length_meas.h5' #recon_data_file = default_dir+'2021_05_18-17_41_02_PassiveReconstruction.h5' lasing_file_off = default_dir + '2021_05_18-21_45_00_Lasing_False_SARBD02-DSCR050.h5' lasing_file_on = default_dir + '2021_05_18-21_41_35_Lasing_True_SARBD02-DSCR050.h5' streaker_calib_file = default_dir + '2021_05_18-22_11_36_Calibration_SARUN18-UDCP020.h5' screen_X0 = 898.02e-6 streaker_offsets = 0, 364e-6 delta_gap = 0, -62e-6 pulse_energy = 180e-6 self.DirectCalibration.setText('%i' % (screen_X0 * 1e6)) self.StreakerDirect0.setText('%i' % (streaker_offsets[0] * 1e6)) self.StreakerDirect1.setText('%i' % (streaker_offsets[1] * 1e6)) self.StreakerGapDelta0.setText('%i' % (delta_gap[0] * 1e6)) self.StreakerGapDelta1.setText('%i' % (delta_gap[1] * 1e6)) self.LasingEnergyInput.setText('%i' % (pulse_energy * 1e6)) self.ImportCalibration.setText(screen_calib_file) self.ReconstructionDataLoad.setText(lasing_file_off) self.BunchLengthMeasFile.setText(bunch_length_meas_file) self.SaveDir.setText(save_dir) self.LasingOnDataLoad.setText(lasing_file_on) self.LasingOffDataLoad.setText(lasing_file_off) self.SaveDir.setText(save_dir) self.LoadCalibrationFilename.setText(streaker_calib_file) self.ForwardBlmeasFilename.setText(bunch_length_meas_file) ds = config.get_default_tracker_settings() gs = config.get_default_gauss_recon_settings() self.StructLength1.setText('%.2f' % ds['struct_lengths'][0]) self.StructLength2.setText('%.2f' % ds['struct_lengths'][1]) self.N_Particles.setText('%i' % ds['n_particles']) self.TransEmittanceX.setText('%i' % round(ds['n_emittances'][0] * 1e9)) self.TransEmittanceY.setText('%i' % round(ds['n_emittances'][1] * 1e9)) self.ScreenSmoothen.setText('%i' % round(ds['smoothen'] * 1e6)) self.ProfileSmoothen.setText('%i' % round(ds['bp_smoothen'] * 1e15)) self.SelfConsistentCheck.setChecked(gs['self_consistent']) self.UseQuadCheck.setChecked(ds['quad_wake']) self.OverrideQuadCheck.setChecked(ds['override_quad_beamsize']) self.QuadBeamsize1.setText('%.2f' % (ds['quad_x_beamsize'][0] * 1e6)) self.QuadBeamsize2.setText('%.2f' % (ds['quad_x_beamsize'][1] * 1e6)) self.SigTfsStart.setText('%i' % round(gs['sig_t_range'][0] * 1e15)) self.SigTfsStop.setText('%i' % round(gs['sig_t_range'][-1] * 1e15)) self.SigTSize.setText('%i' % len(gs['sig_t_range'])) self.TmpDir.setText(config.tmp_elegant_dir) self.ScreenBins.setText('%i' % ds['screen_bins']) self.ScreenLength.setText('%i' % ds['len_screen']) self.ScreenCutoff.setText('%.4f' % ds['screen_cutoff']) self.ProfileCutoff.setText('%.4f' % ds['profile_cutoff']) self.ProfileExtent.setText('%i' % round(gs['tt_halfrange'] * 2 * 1e15)) self.Charge.setText('%i' % round(gs['charge'] * 1e12)) if elog is not None: self.logbook = elog.open( 'https://elog-gfa.psi.ch/SwissFEL+commissioning+data/') self.current_rec_dict = None self.lasing_rec_dict = None ## Handle plots def get_new_tab(fig, title): new_tab = QtWidgets.QWidget() layout = PyQt5.Qt.QVBoxLayout() new_tab.setLayout(layout) canvas = FigureCanvasQTAgg(fig) toolbar = NavigationToolbar2QT(canvas, self) layout.addWidget(canvas) layout.addWidget(toolbar) tab_index = self.tabWidget.addTab(new_tab, title) return tab_index, canvas self.reconstruction_fig, self.reconstruction_plot_handles = analysis.reconstruction_figure( ) self.rec_plot_tab_index, self.rec_canvas = get_new_tab( self.reconstruction_fig, 'I Rec.') self.streaker_calib_fig, self.streaker_calib_plot_handles = sc.streaker_calibration_figure( ) self.streaker_calib_plot_tab_index, self.streaker_calib_canvas = get_new_tab( self.streaker_calib_fig, 'Calib.') self.gap_recon_fig, self.gap_recon_plot_handles = sc.gap_recon_figure() self.gap_recon_tab_index, self.gap_recon_canvas = get_new_tab( self.gap_recon_fig, 'Gap rec.') self.screen_calib_fig, self.screen_calib_plot_handles = analysis.screen_calibration_figure( ) self.screen_calib_plot_tab_index, self.screen_calib_canvas = get_new_tab( self.screen_calib_fig, 'Screen') self.all_lasing_fig, self.all_lasing_plot_handles = lasing.lasing_figure( ) self.all_lasing_tab_index, self.all_lasing_canvas = get_new_tab( self.all_lasing_fig, 'All lasing')
import myplotstyle as ms elegant_matrix.set_tmp_dir('~/tmp_elegant/') ms.closeall() hostname = gethostname() if hostname == 'desktop': data_dir = '/storage/data_2021-05-19/' elif hostname == 'pc11292.psi.ch': data_dir = '/sf/data/measurements/2021/05/19/' elif hostname == 'pubuntu': data_dir = '/mnt/data/data_2021-05-19/' data_dir1 = data_dir.replace('19', '18') tracker_kwargs = config.get_default_tracker_settings() tracker_kwargs['len_screen'] = 1000 tracker_kwargs['n_particles'] = int(50e3) recon_kwargs = config.get_default_gauss_recon_settings() tracker = tracking.Tracker(**tracker_kwargs) #data_file = data_dir+'2021_05_19-14_49_38_Lasing_False_SARBD02-DSCR050.h5' #data_file = data_dir + '2021_05_19-14_24_05_Calibration_SARUN18-UDCP020.h5' data_file = data_dir1 + '2021_05_18-23_07_20_Calibration_SARUN18-UDCP020.h5' data_dict = h5_storage.loadH5Recursive(data_file) raw_data = data_dict['raw_data'] meta_data = data_dict['meta_data'] offset_index = -1
data_dir1 + '2021_05_18-23_32_12_Calibration_SARUN18-UDCP020.h5') #streaker_calib_files = (data_dir1+'2021_05_19-00_13_25_Calibration_SARUN18-UDCP020.h5', data_dir1+'2021_05_19-00_24_47_Calibration_SARUN18-UDCP020.h5') strong_streak_file = data_dir1 + '2021_05_18-23_43_39_Lasing_False_SARBD02-DSCR050.h5' weak_streak_file = data_dir2 + '2021_05_19-14_14_22_Calibration_SARUN18-UDCP020.h5' meta_data_strong = h5_storage.loadH5Recursive( strong_streak_file)['meta_data_begin'] meta_data_weak = h5_storage.loadH5Recursive( weak_streak_file)['raw_data']['meta_data_begin'] n_streaker = 1 charge = 200e-12 tracker = tracking.Tracker(**config.get_default_tracker_settings()) sc = streaker_calibration.StreakerCalibration( 'Aramis', n_streaker, 10e-3, fit_gap=True, fit_order=False, proj_cutoff=tracker.screen_cutoff) for scf in streaker_calib_files: sc.add_file(scf) streaker_offset = sc.fit_type('centroid')['streaker_offset'] tracker.set_simulator(sc.meta_data) gauss_kwargs = config.get_default_gauss_recon_settings() if calibrate_gap: