def test_read(self): logbook = elog.open('https://elog-gfa.psi.ch/SwissFEL+test/') message, attributes, attachments = logbook.read(23) print(message) self.assertEqual(message, 'Test from shell', "Unable to retrieve message")
def test_edit(self): logbook = elog.open('https://elog-gfa.psi.ch/SwissFEL+test/') logbook.post('hehehehehe', msg_id=55, attributes={ "Title": 'A new one BLABLA', "When": 1510657172 })
def test_get_last_message_id(self): from datetime import datetime logbook = elog.open('https://elog-gfa.psi.ch/SwissFEL+test/') msg_id = logbook.post('This is message text is new') message_id = logbook.get_last_message_id() print(msg_id) print(message_id) self.assertEqual(msg_id, message_id, "Created message does not show up as last edited message")
def getDefaultElogInstance(self, url, **kwargs): from pathlib import Path home = str(Path.home()) if not ("user" in kwargs.keys()): kwargs.update(dict(user=_getuser())) if not ("password" in kwargs.keys()): try: with open(os.path.join(home, ".elog_psi"), "r") as f: _pw = f.read().strip() except: print("Enter elog password for user: %s" % kwargs["user"]) _pw = _getpass() kwargs.update(dict(password=_pw)) return _elog_ha.open(url, **kwargs), kwargs["user"]
def getDefaultElogInstance(url, **kwargs): from pathlib import Path home = str(Path.home()) if not ('user' in kwargs.keys()): kwargs.update(dict(user=_getuser())) if not ('password' in kwargs.keys()): try: with open(os.path.join(home, '.elog_psi'), 'r') as f: _pw = f.read().strip() except: print('Enter elog password for user: %s' % kwargs['user']) _pw = _getpass() kwargs.update(dict(password=_pw)) return _elog_ha.open(url, **kwargs), kwargs['user']
def test_get_message_ids(self): logbook = elog.open('https://elog-gfa.psi.ch/SwissFEL+test/') message_ids = logbook.get_message_ids() print(len(message_ids)) print(message_ids)
def test_search(self): logbook = elog.open('https://elog-gfa.psi.ch/SwissFEL+test/') ids = logbook.search("Powersupply") print(ids)
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')
def test_search_dict(self): logbook = elog.open('https://elog-gfa.psi.ch/SwissFEL+test/') ids = logbook.search({"subtext": "Powersupply"}) print(ids)
def test_search_empty(self): logbook = elog.open('https://elog-gfa.psi.ch/SwissFEL+test/') ids = logbook.search("") print(ids)
def test_edit(self): logbook = elog.open('https://elog-gfa.psi.ch/SwissFEL+test/') logbook.post('hehehehehe', msg_id=55, attributes={"Title": 'A new one BLABLA', "When": 1510657172})