def getIMonArray(self,imon): logger.info('getIMonArray for imon %d '%(imon), __name__) arr_all = gu.get_array_from_file(self.fname_imon) if arr_all == None : return None logger.info('Array shape: ' + str(arr_all.shape), __name__) ibase = 1+imon*4 arr_imon = arr_all[:,ibase:ibase+4] #print 'arr_imon:\n', arr_imon #print 'arr_imon.shape:', arr_imon.shape #mask = self.maskForIMonChannels(imon) #npmask = np.array(mask,dtype=float) npmask = self.nparrMaskForIMonChannels(imon) size = arr_imon.shape[0] npcol1 = np.ones(size) X,Y = np.meshgrid(npmask,npcol1) arr_prod = (arr_imon * X) arr_sum = arr_prod.sum(1) #print 'npmask=', npmask #print 'size=', size #print X #print X.shape #print arr_imon #print arr_imon.shape #print arr_prod #print arr_prod.shape return arr_sum
def on_cbx(self): #if self.cbx_dark.hasFocus() : par = cp.vc_cbx_show_more par.setValue( self.cbx_more.isChecked() ) msg = 'on_cbx - set status of parameter vc_cbx_show_more: ' + str(par.value()) logger.info(msg, __name__ ) self.setButtonState()
def onTabBar(self): tab_ind = self.tab_bar.currentIndex() tab_name = str(self.tab_bar.tabText(tab_ind)) cp.current_tab.setValue( tab_name ) msg = 'Selected tab: %i - %s' % (tab_ind, tab_name) logger.info(msg, __name__) self.guiSelector()
def print_intens_stat_q_bins_arr(self) : msg = 'Intensity in static q bins vs event:\n' for rec in self.intens_stat_q_bins_vs_t : msg += '%10.3f %10.3f %10.3f %10.3f ...\n' % \ (rec[0], rec[1], rec[2], rec[3]) logger.info(msg, __name__) print msg
def onEdit(self): if self.edi_ccdset_pixsize.isModified() : self.edi = self.edi_ccdset_pixsize self.par = cp.ccdset_pixsize self.tit = 'ccdset_pixsize' elif self.edi_ccdset_adcsatu.isModified() : self.edi = self.edi_ccdset_adcsatu self.par = cp.ccdset_adcsatu self.tit = 'ccdset_adcsatu' elif self.edi_ccdset_aduphot.isModified() : self.edi = self.edi_ccdset_aduphot self.par = cp.ccdset_aduphot self.tit = 'ccdset_aduphot' elif self.edi_ccdset_ccdeff.isModified() : self.edi = self.edi_ccdset_ccdeff self.par = cp.ccdset_ccdeff self.tit = 'ccdset_ccdeff' elif self.edi_ccdset_ccdgain.isModified() : self.edi = self.edi_ccdset_ccdgain self.par = cp.ccdset_ccdgain self.tit = 'ccdset_ccdgain' else : return # no-modification self.edi.setModified(False) self.par.setValue( self.edi.displayText() ) msg = 'onEdit - set value of ' + self.tit + ': ' + str( self.par.value()) logger.info(msg, __name__ )
def makeTabBar(self,mode=None) : #if mode != None : self.tab_bar.close() self.tab_bar = QtGui.QTabBar() #Uses self.list_run_types self.ind_tab_info = self.tab_bar.addTab( self.list_run_types[0] ) self.ind_tab_split = self.tab_bar.addTab( self.list_run_types[1] ) self.ind_tab_proc = self.tab_bar.addTab( self.list_run_types[2] ) self.ind_tab_merge = self.tab_bar.addTab( self.list_run_types[3] ) self.ind_tab_auto = self.tab_bar.addTab( self.list_run_types[4] ) self.tab_bar.setTabTextColor(self.ind_tab_info , QtGui.QColor('green')) self.tab_bar.setTabTextColor(self.ind_tab_split, QtGui.QColor('red')) self.tab_bar.setTabTextColor(self.ind_tab_proc , QtGui.QColor('gray')) self.tab_bar.setTabTextColor(self.ind_tab_merge, QtGui.QColor('blue')) self.tab_bar.setTabTextColor(self.ind_tab_auto , QtGui.QColor('black')) self.tab_bar.setShape(QtGui.QTabBar.RoundedNorth) #self.tab_bar.setTabEnabled(1, False) #self.tab_bar.setTabEnabled(2, False) #self.tab_bar.setTabEnabled(3, False) #self.tab_bar.setTabEnabled(4, False) try : tab_index = self.list_run_types.index(cp.current_run_tab.value()) except : tab_index = 3 cp.current_run_tab.setValue(self.list_run_types[tab_index]) self.tab_bar.setCurrentIndex(tab_index) logger.info(' make_tab_bar - set mode: ' + cp.current_run_tab.value(), __name__) self.connect(self.tab_bar, QtCore.SIGNAL('currentChanged(int)'), self.onTabBar)
def list_of_group_copy_cmds(self): list_of_fnames = cp.guidirtree.get_list_of_checked_item_names() dst_calib_dir = fnm.path_to_calib_dir() dst_fname = '%s-%s.data' % (self.str_run_from, self.str_run_to) #print 'dst_calib_dir:', dst_calib_dir #print 'dst_fname:', dst_fname list_of_cmds = [] for fname in list_of_fnames : #print ' split fname', fname fields = fname.split('/') if len(fields) < 5 : logger.info('File %s has a un-expected path: ' % fname, __name__) continue if fields[-5] != 'calib' : logger.info('File %s is not from "calib" directory: ' % fname, __name__) continue dst_path = os.path.join(dst_calib_dir, fields[-4], fields[-3], fields[-2], dst_fname) cmd = 'cp %s %s' % (fname, dst_path) list_of_cmds.append(cmd) return list_of_cmds
def get_random_img(sp) : logger.info('get_random_img(): standard_exponential', __name__) #arr = mu + sigma*np.random.standard_normal(size=2400) #arr = np.arange(2400) sp.arr2d = 100*np.random.standard_exponential(sp.size) sp.arr2d.shape = (sp.rows,sp.cols) return sp.arr2d
def onButDeploy(self): logger.debug('onButDeploy', __name__) if self.script == 'Select' : msg = 'Script for processing metrology file is not selected.... Select it first and evaluate constants (Item 4)' logger.warning(msg, __name__) return if self.source_name == 'Select' : msg = 'Detector is not selected. Select it first...' logger.warning(msg, __name__) return list_of_cmds = self.list_of_copy_cmds() txt = '\nList of commands for tentetive file deployment:' for cmd in list_of_cmds : txt += '\n' + cmd logger.info(txt, __name__) msg = 'Approve commands \njust printed in the logger' if self.approveCommand(self.butDeploy, msg) : for cmd in list_of_cmds : fd.procDeployCommand(cmd, 'metrology-alignment') #print 'Command for deployer: ', cmd if cp.guistatus is not None : cp.guistatus.updateStatusInfo()
def onButEvaluate(self): logger.debug('onButEvaluate', __name__) det = self.get_detector_selected() if det is None : return list_of_metrology_scripts = cp.dict_of_metrology_scripts[det] if self.script == 'Select' : msg = 'Script for processing metrology file is not selected. Select it first...' logger.warning(msg, __name__) return #print 'list_of_metrology_scripts', list_of_metrology_scripts #for CSPAD script CSPADV1 if det == cp.list_of_dets[0] and self.script == list_of_metrology_scripts[0] : msg = 'Evaluate parameters for %s using script %s' % (det, self.script) logger.info(msg, __name__) self.procCspadV1() # for other detectors and scripts for now... else : msg = 'Script %s is not yet implemented for detector %s...' % (self.script, det) logger.warning(msg, __name__) return
def set_file_name(sp, fname=None) : sp.cor_arr = None sp.g2_vs_itau_arr = None if fname == None : sp.fname = cp.res_fname.value() else : sp.fname = fname logger.info('Use file with results:' + sp.fname, __name__)
def onButView(self): logger.info('onButView', __name__) if self.but_Ip .hasFocus() : self.selectedOption( 0, '<Ip> map, ', show_tau=True) elif self.but_If .hasFocus() : self.selectedOption( 1, '<If> map, ', show_tau=True) elif self.but_I2 .hasFocus() : self.selectedOption( 2, '<Ip x If>, ', show_tau=True) elif self.but_g2raw .hasFocus() : self.selectedOption( 3, 'g2 raw map, ', show_tau=True) elif self.but_X .hasFocus() : self.selectedOption( 4, 'X map') elif self.but_Y .hasFocus() : self.selectedOption( 5, 'Y map') elif self.but_R .hasFocus() : self.selectedOption( 6, 'R map') elif self.but_P .hasFocus() : self.selectedOption( 7, 'Phi map') elif self.but_Q .hasFocus() : self.selectedOption( 8, 'Q map' ) elif self.but_P_st .hasFocus() : self.selectedOption( 9, 'Phi map for static bins') elif self.but_Q_st .hasFocus() : self.selectedOption( 10, 'Q map for static bins') elif self.but_P_dy .hasFocus() : self.selectedOption( 11, 'Phi map for dynamic bins') elif self.but_Q_dy .hasFocus() : self.selectedOption( 12, 'Q map for dynamic bins') elif self.but_QP_st .hasFocus() : self.selectedOption( 13, 'Q-Phi map for static bins') elif self.but_QP_dy .hasFocus() : self.selectedOption( 14, 'Q-Phi map for dynamic bins') elif self.but_1oIp .hasFocus() : self.selectedOption( 15, '1/<Ip> norm. map for static bins, ', show_tau=True) elif self.but_1oIf .hasFocus() : self.selectedOption( 16, '1/<If> norm. map for static bins, ', show_tau=True) elif self.but_g2map .hasFocus() : self.selectedOption( 17, 'g2 map, ', show_tau=True) elif self.but_g2dy .hasFocus() : self.selectedOption( 18, 'g2 map for dynamic bins, ', show_tau=True) elif self.but_g2tau .hasFocus() : self.selectedOption( 19, 'g2 vs itau') #elif self.but_g2tau_gr .hasFocus() : self.selectedOption( 20, 'g2(tau) for dynamic bins') elif self.but_mask_img_lims.hasFocus() : self.selectedOption( 30, 'Mask image limits') elif self.but_mask_blemish .hasFocus() : self.selectedOption( 31, 'Mask blemish') elif self.but_mask_hotpix .hasFocus() : self.selectedOption( 32, 'Mask hot pixels') elif self.but_mask_regs .hasFocus() : self.selectedOption( 33, 'Mask for good regions') elif self.but_mask_total .hasFocus() : self.selectedOption( 34, 'Mask total') else : logger.warning('Request for non-implemented button ...', __name__) self.drawPlot()
def confirm_dialog_box(parent=None, text='Please confirm that you aware!', title='Please acknowledge') : """Pop-up MODAL box for confirmation""" mesbox = QtGui.QMessageBox(parent, windowTitle=title, text=text, standardButtons=QtGui.QMessageBox.Ok) #standardButtons=QtGui.QMessageBox.Save | QtGui.QMessageBox.Discard | QtGui.QMessageBox.Cancel) #mesbox.setDefaultButton(QtGui.QMessageBox.Ok) #mesbox.setMinimumSize(400, 200) #style = "background-color: rgb(255, 200, 220); color: rgb(0, 0, 100);" # Pinkish #style = "background-color: rgb(255, 255, 220); color: rgb(0, 0, 0);" # Yellowish #mesbox.setStyleSheet (style) clicked = mesbox.exec_() # DISPLAYS THE QMessageBox HERE #if clicked == QtGui.QMessageBox.Save : # logger.info('Saving is requested', __name__) #elif clicked == QtGui.QMessageBox.Discard : # logger.info('Discard is requested', __name__) #else : # logger.info('Cancel is requested', __name__) #return clicked logger.info('You acknowkeged that saw the message:\n' + text, 'confirm_dialog_box') return
def save_q_average_for_stat_q_bins_in_file(sp) : arr = sp.get_q_average_for_stat_q_bins()[:-1] # trim the overflow bin path = fnm.path_cora_split_q_ave_static() #print 'arr.:\n', arr #print 'arr.shape:', arr.shape logger.info('Save <q> for static q bins in file: ' + path, __name__) np.savetxt(path, arr, fmt='%f', delimiter=' ')
def onBox(self): self.fname = str( self.box_file.currentText() ) logger.info('onBox - selected file: ' + self.fname, __name__) if self.fname == '' : return self.list_of_supported = 'cfg', 'log', 'txt', 'txt-tmp' self.str_of_supported = '' for ext in self.list_of_supported : self.str_of_supported += ' ' + ext #print 'self.fname = ', self.fname #print 'self.list_of_files', self.list_of_files if self.list_of_files.index(self.fname) == 0 : self.setStatus(0, 'Waiting for file selection...') self.box_txt.setText('Click on file-box and select the file from pop-up list...') elif os.path.lexists(self.fname) : ext = os.path.splitext(self.fname)[1].lstrip('.') if ext in self.list_of_supported : self.box_txt.setText(gu.load_textfile(self.fname)) self.setStatus(0, 'Status: enjoy browsing the selected file...') else : self.box_txt.setText('Sorry, but this browser supports text files with extensions:' + self.str_of_supported + '\nTry to select another file...') self.setStatus(1, 'Status: ' + ext + '-file is not supported...') else : self.box_txt.setText( 'Selected file is not avaliable...\nTry to select another file...') self.setStatus(2, 'Status: WARNING: FILE IS NOT AVAILABLE!')
def on_cbx(self): #if self.cbx_dark.hasFocus() : par = cp.bat_dark_is_used par.setValue( self.cbx_dark.isChecked() ) msg = 'on_cbx - set status of parameter bat_dark_is_used: ' + str(par.value()) logger.info(msg, __name__ ) self.setButtonState()
def on_cbx(self): #if self.cbx_data .hasFocus() : par = cp.is_active_data_gui par.setValue( self.cbx_data.isChecked() ) msg = 'on_cbx - set status of parameter is_active_data_gui: ' + str(par.value()) logger.info(msg, __name__ ) self.setButtonState()
def onCBox(self): #if self.cbx_use .hasFocus() : par = cp.elog_post_cbx_state par.setValue( self.cbx_use.isChecked() ) msg = 'onCBox - set status of ' + str(par.name()) + ': ' + str(par.value()) logger.info(msg, __name__ ) self.setFieldsStyle()
def changeFilePermissions(self, path): msg = 'Change permissions for file: %s' % path logger.info(msg, __name__) #st = os.stat(path) #os.chmod(path, st.st_mode | stat.S_IEXEC) os.system('chmod 670 %s' % path)
def create_directory(dir) : if os.path.exists(dir) : logger.info('Directory exists: ' + dir, __name__) else : os.makedirs(dir) #os.fchmod(dir,770) logger.info('Directory created: ' + dir, __name__)
def get_mask_total(self): shape = self.widgimage.get_img_shape() if self.verb : print 'get_img_shape():', shape self.mask_total = None for i, obj in enumerate(self.get_list_of_objs_for_mask()) : if obj.isSelected : continue # Loop over ROI-type objects if self.mask_total == None : self.mask_total = obj.get_obj_mask(shape) else : self.mask_total = np.logical_or(self.mask_total, obj.get_obj_mask(shape)) msg = 'mask for ROI-type object %i is ready...' % (i) logger.info(msg, __name__ ) for i, obj in enumerate(self.get_list_of_objs_for_mask()) : if not obj.isSelected : continue # Loop over inversed objects if self.mask_total == None : self.mask_total = obj.get_obj_mask(shape) else : self.mask_total = np.logical_and(self.mask_total, obj.get_obj_mask(shape)) msg = 'mask for inversed object %i is ready...' % (i) logger.info(msg, __name__ ) if self.y_is_flip : self.mask_total = np.flipud(gu.arr_rot_n90(self.mask_total, self.ccd_rot_n90)) else : rot_ang = self.ccd_rot_n90 if self.ccd_rot_n90 == 90 : rot_ang=270 if self.ccd_rot_n90 == 270 : rot_ang=90 self.mask_total = gu.arr_rot_n90(self.mask_total, rot_ang) return self.mask_total
def on_but_show(self): """Prints the list of commands for deployment of calibration file(s)""" #str_run_number = '%04d' % self.run_number list_of_deploy_commands, list_of_sources = \ fdmets.get_list_of_deploy_commands_and_sources_dark(self.run_number, self.get_gui_run().strRunRange()) msg = '\n' + 50*'-' + '\nTentative deployment commands:\n' + '\n'.join(list_of_deploy_commands) logger.info(msg, __name__)
def onCBox(self): #if self.cbx_use .hasFocus() : par = cp.ccdcorr_blemish par.setValue( self.cbx_use.isChecked() ) msg = 'onCBox - set status of ccdcorr_blemish: ' + str(par.value()) logger.info(msg, __name__ ) self.setButtonState()
def onButDeploy(self): """Deploys the calibration file(s)""" list_of_deploy_commands, list_of_sources = self.get_list_of_deploy_commands_and_sources() msg = 'Deploy calibration file(s):' if list_of_deploy_commands == [] : msg += 'List of commands IS EMPTY !!!' logger.info(msg, __name__) return list_src_cbx = [[src,True] for src in list_of_sources] resp = gu.changeCheckBoxListInPopupMenu(list_src_cbx, win_title='Confirm Deployment') if resp != 1 : logger.info('Deployment is cancelled!', __name__) return #for cmd,[src,cbx] in zip(list_of_deploy_commands, list_src_cbx) : # print cbx, src, '\n', cmd, '\n' # if cbx : fd.procDeployCommand(cmd) for cmd in list_of_deploy_commands : #print 'cmd: ', cmd if self.is_allowed_command(cmd, list_src_cbx) : fd.procDeployCommand(cmd,'calib-dark') if cp.guistatus is not None : cp.guistatus.updateStatusInfo()
def onCBox(self): if self.cbx_res_ascii_out .hasFocus() : self.cbx = self.cbx_res_ascii_out self.par = cp.res_ascii_out self.tit = 'res_ascii_out' elif self.cbx_res_fit1 .hasFocus() : self.cbx = self.cbx_res_fit1 self.par = cp.res_fit1 self.tit = 'res_fit1' elif self.cbx_res_fit2 .hasFocus() : self.cbx = self.cbx_res_fit2 self.par = cp.res_fit2 self.tit = 'res_fit2' elif self.cbx_res_fit_cust .hasFocus() : self.cbx = self.cbx_res_fit_cust self.par = cp.res_fit_cust self.tit = 'res_fit_cust' elif self.cbx_res_png_out .hasFocus() : self.cbx = self.cbx_res_png_out self.par = cp.res_png_out self.tit = 'res_png_out' elif self.cbx_res_save_log .hasFocus() : self.cbx = self.cbx_res_save_log self.par = cp.res_save_log self.tit = 'res_save_log' self.par.setValue( self.cbx.isChecked() ) msg = 'onCBox - set status of ' + self.tit + ': ' + str( self.par.value()) logger.info(msg, __name__ )
def on_but_srcs(self) : """Print sources from RegDB """ self.exportLocalPars() txt = '\n' + 50*'-' + '\nSources from DB:\n' \ + cp.blsp.txt_of_sources_in_run() logger.info(txt, __name__)
def onStop(self): msg = 'onStop - buttons status should be updated now for %s' % (self.str_run_number) logger.info(msg, __name__) self.but_go.setEnabled(True) self.but_go.setText('Go') #self.setStatusStyleOfButtons() self.updateButtons()
def batch_job_submit(command, queue='psnehq', log_file='batch-log.txt') : if os.path.lexists(log_file) : remove_file(log_file) out, err = subproc(['bsub', '-q', queue, '-o', log_file, command]) line_fields = out.split() if line_fields[0] != 'Job' : msg = 'EXIT: Unexpected response at batch submission:\nout: %s \nerr: %s'%(out, err) print msg logger.warning(msg, __name__) #sys.exit(msg) job_id_str = 'JOB_ID_IS_UNKNOWN' else : job_id_str = line_fields[1].strip('<').rstrip('>') if err != '' : msg = '' if 'job being submitted without an AFS token' in err : msg = err + ' This warning does not matter for jobs on LCLS NFS, continue' else : msg = '\n' + 80*'!' + '\n' + err + 80*'!' + '\n' logger.warning(msg, __name__) logger.info(out, __name__) return job_id_str, out, err
def on_but_show(self): """Prints the list of commands for deployment of calibration file(s)""" list_of_deploy_commands, list_of_sources = self.get_gui_run().get_list_of_deploy_commands_and_sources() msg = '\n' + 50*'-' + '\nTentative deploy command(s):' for cmd in list_of_deploy_commands : msg += '\n' + cmd logger.info(msg, __name__)
def print_q_average_for_stat_q_bins(sp) : q_ave = sp.get_q_average_for_stat_q_bins() msg = '<q> for static q bins:\n' msg += str(q_ave) #for i, q in enumerate(q_ave) : # msg += ' q(%3d)=%10.4f \n' % (i, q) logger.info(msg, __name__)
def onEditPrefix(self): logger.debug('onEditPrefix', __name__) cp.fname_prefix.setValue(str(self.edi_fname_prefix.displayText())) logger.info( 'Set file name common prefix: ' + str(cp.fname_prefix.value()), __name__)
def itemCollapsed(self, ind): item = self.model.itemFromIndex(ind) item.setIcon(cp.icon_folder_closed) msg = 'Item collapsed: %s' % item.text() logger.info(msg, __name__)
def on_io_but(self): but, ind, fname = self.get_pushed_io_but() but_text = str(but.text()) msg = but_text + ', default file name: ' + str(fname) logger.debug(msg, __name__ ) if self.verb : print msg if fname == None : path0 = '.' else : path0 = fname if but_text == self.list_of_io_tits[0] : # 'Load Img' self.setStatus(1, 'Waiting\nfor input...') path = gu.get_open_fname_through_dialog_box(self, path0, but_text, filter='*.txt *.npy') if path == None : self.setStatus() return self.setStatus(2, 'WAIT!\nLoad image') arr = gu.get_array_from_file(path) self.parent.set_image_array_new(arr, title='Image from '+path ) self.setStatus(0, 'Image \nloaded') if but_text == self.list_of_io_tits[1] : # 'Load Forms' self.setStatus(1, 'Waiting\nfor input') path = gu.get_open_fname_through_dialog_box(self, path0, but_text, filter='*.txt') if path == None : self.setStatus() return msg='Load shaping-objects for mask from file: ' + path logger.debug(msg, __name__ ) if self.verb : print msg #text = gu.get_text_file_content(path) self.setStatus(2,'WAIT\nLoad forms') f=open(path,'r') for str_of_pars in f : self.add_obj(str_of_pars.rstrip('\n')) f.close() self.setStatus(0, 'Forms\nloaded') if but_text == self.list_of_io_tits[2] : # 'Save Forms' #self.parent.set_image_array_new( get_array2d_for_test(), title='New array' ) if self.list_of_objs_for_mask_is_empty() : return self.setStatus(1, 'Waiting\nfor input...') path = gu.get_save_fname_through_dialog_box(self, path0, but_text, filter='*.txt') if path == None : self.setStatus() return msg='Save shaping-objects for mask in file: ' + path logger.debug(msg, __name__ ) self.setStatus(2, 'WAIT!\nSave forms') f=open(path,'w') for obj in self.get_list_of_objs_for_mask() : str_of_pars = obj.get_str_of_pars() if self.verb : print str_of_pars f.write(str_of_pars + '\n') f.close() self.setStatus(0, 'Forms\nsaved') if but_text == self.list_of_io_tits[3] : # 'Save Mask' if self.list_of_objs_for_mask_is_empty() : return self.setStatus(2, 'WAIT!\nMask is\nprocessing') self.enforceStatusRepaint() #print 'WAIT for mask processing' mask_total = self.get_mask_total() self.parent.set_image_array_new(mask_total, title='Mask') #self.parent.set_image_array_new( get_array2d_for_test(), title='New array' ) self.setStatus(1, 'Waiting\nfor input...') path = gu.get_save_fname_through_dialog_box(self, path0, but_text, filter='*.txt') if path == None : self.setStatus() return np.savetxt(path, mask_total, fmt='%1i', delimiter=' ') self.setStatus(0, 'Mask\nis saved') if but_text == self.list_of_io_tits[4] : # 'Save Inv-Mask' if self.list_of_objs_for_mask_is_empty() : return self.setStatus(2, 'Wait!\nInv-mask is\nprocessing') self.enforceStatusRepaint() mask_total = ~self.get_mask_total() self.parent.set_image_array_new(mask_total, title='Inverse Mask') self.setStatus(1, 'Waiting\nfor input') path = gu.get_save_fname_through_dialog_box(self, path0, but_text, filter='*.txt') if path == None : self.setStatus() return np.savetxt(path, mask_total, fmt='%1i', delimiter=' ') self.setStatus(0, 'Mask\nis ready') if but_text == self.list_of_io_tits[5] : # 'Print Forms' #self.parent.set_image_array_new( get_array2d_for_test(), title='New array' ) msg = '\nForm parameters for composition of the mask' if self.verb : print msg logger.info(msg, __name__ ) for obj in self.get_list_of_objs_for_mask() : str_of_pars = obj.get_str_of_pars() if self.verb : print str_of_pars logger.info(str_of_pars) if but_text == self.list_of_io_tits[6] : # 'Clear Forms' self.setStatus(2, 'WAIT!\nremoving\nforms') self.set_lines .remove_all_objs_from_img_by_call() self.set_rectangles.remove_all_objs_from_img_by_call() self.set_circles .remove_all_objs_from_img_by_call() self.set_wedges .remove_all_objs_from_img_by_call() self.set_polygons .remove_all_objs_from_img_by_call() self.setStatus(0, 'Forms\nremoved')
def print_files_for_list(self, list_of_files, comment=''): logger.info('Print files for list ' + comment, __name__) for fname in list_of_files: logger.info(fname)
def onEdiMaxThr(self): str_value = str(self.edi_max_thr.displayText()) cp.mask_max_thr.setValue(float(str_value)) logger.info('Set hot pixel MAX threshold: %s' % str_value, __name__)
def save_cfg_file (self, text, path) : msg = 'Save configuration file: %s' % path logger.info(msg,__name__) if self.do_test_print : print msg gu.save_textfile(text, path)
def on_edi_bat_start(self): if (not cp.is_active_data_gui.value()): return cp.bat_data_start.setValue(int(self.edi_bat_start.displayText())) logger.info('Set bat_data_start =' + str(cp.bat_data_start.value()), __name__)
def on_box_orient(self): orient_selected = self.box_orient.currentText() cp.ccd_orient.setValue(orient_selected) logger.info('on_box_orient - orient_selected: ' + orient_selected, __name__)
def onEdiTo(self): logger.debug('onEdiTo', __name__ ) self.str_run_to = str( self.edi_to.displayText() ) msg = 'Set the run validity range up to %s' % self.str_run_to logger.info(msg, __name__ ) self.setStyleButtons()
def onEdiFrom(self): logger.debug('onEdiFrom', __name__ ) self.str_run_from = str( self.edi_from.displayText() ) msg = 'Set the run validity range from %s' % self.str_run_from logger.info(msg, __name__ ) self.setStyleButtons()
def switch_ip(): url = 'http://ip.dobel.cn/switch-ip' get_content(url, my_headers) logger.info('switch ip')
def onEdiDarkEnd(self): str_value = str(self.edi_dark_end.displayText()) cp.bat_dark_end.setValue(int(str_value)) logger.info('Set last event for dark run: %s' % str_value, __name__)
def onBoxBatQueue(self): queue_selected = self.box_bat_queue.currentText() cp.bat_queue.setValue(queue_selected) logger.info('onBoxBatQueue - queue_selected: ' + queue_selected, __name__)
def onClose(self): logger.info('onClose', __name__) self.close()
def onEdiDarkStart(self): str_value = str(self.edi_dark_start.displayText()) cp.bat_dark_start.setValue(int(str_value)) logger.info('Set start event for dark run: %s' % str_value, __name__)
def getfos(fos_list): path_result_json = os.path.join(os.getcwd(), "result", "json") path_result = os.path.join(os.getcwd(), "result", "fosdata") # 重载 for fos in fos_list: if isinstance(fos, int): fos_id = fos else: fos_id = fos["id"] if fos_id in _RECORD_SET: continue url = _HOST.format(str(fos_id)) tries = 0 js = None file_path = os.path.join(path_result_json, str(id)) if os.path.exists(file_path): try: with open(file_path, "r", encoding="utf-8") as f: js = json.loads(f.read()) tries = _MAXRETRY except Exception: os.remove(file_path) while tries < _MAXRETRY: tries += 1 try: html = _get_page(url) # save_str_to_file(os.path.join(path_result_json, str(fos_id)), html) js = json.loads(html.strip()) break except Exception as e: if tries < _MAXRETRY: logger.info( _ERRORMESSAGE.format(str(fos_id), str(e)) + " | tries: %d" % tries) else: logger.error( _ERRORMESSAGE.format(str(fos_id), str(e)) + " | tries: %d" % tries) time.sleep(tries) if js is None: continue list_pfos = [] if "parentFieldsOfStudy" in js.keys(): list_pfos = js["parentFieldsOfStudy"] list_rfos = [] if "relatedFieldsOfStudy" in js.keys(): list_rfos = js["relatedFieldsOfStudy"] list_cfos = [] if "childFieldsOfStudy" in js.keys(): list_cfos = js["childFieldsOfStudy"] fosdata = { "id": fos_id, "name": js["entity"]["dfn"], "pfos": list_pfos, "rfos": list_rfos, "cfos": list_cfos } save_dict_to_file(path_result, fosdata, "a") logger.info(_INFOMESSAGE.format(str(fos_id))) # 将爬取过的页面加入到 RECORD 集合中 _RECORD_SET.add(fos_id) if len(list_cfos) > 1: getfos(list_cfos)
def onEdiRmsThr(self): str_value = str(self.edi_rms_thr.displayText()) cp.mask_rms_thr.setValue(float(str_value)) logger.info('Set hot pixel RMS threshold: %s' % str_value, __name__)
def on_edit_nbins(self): self.fig.myNBins = int(self.edi_nbins.displayText()) logger.info( 'Set for spectrum the number of bins =' + str(self.fig.myNBins), __name__) self.widgimage.processDraw()
def __init__(self, jmeterPath, filepath, executionType, ExecutionParam=[]): getSystemInformation() global executionFlag os.chdir(jmeterPath) if ExecutionParam == []: try: executionFlag = True # starting thread 1 printInfo("Executing Script : " + filepath) t1 = threading.Thread(target=getPerfData, args=()) t1.start() #os.system("jmeter.bat -n -t"+ filepath) #output = subprocess.check_output("jmeter.bat -n -t"+ filepath, shell=True) #proc = subprocess.Popen(["jmeter.bat", "-n","-t", filepath], stdout=subprocess.PIPE, shell=True) logger.info("Starting JMeter") p = subprocess.Popen(["jmeter.bat", "-n", "-t", filepath], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) output = p.stdout.read() filtered = lines = filter(lambda x: x.strip(), output) logger.info(filtered) #p.stdin.write(input) #(out, err) = proc.communicate() #print("program output:", out) executionFlag = False t1.join() printSuccess("Execution Complete") except: printFailure("FAILED") else: iteration = ExecutionParam['iteration'] rampup = ExecutionParam['rampup'] concurrency = ExecutionParam['concurrency'] timeout = ExecutionParam['timeout'] url = ExecutionParam['url'] if "ips" in ExecutionParam: ips = ExecutionParam['ips'] if executionType == "distributed": try: executionFlag = True t1 = threading.Thread(target=getPerfData, args=()) # starting thread 1 t1.start() os.system("jmeter.bat -n -t " + filepath + " -r -Gusers=" + str(concurrency) + " -Grampup=" + str(rampup) + " -Gcount=" + str(iteration) + " -Gduration=" + str(timeout) + " -GUrl=" + str(url)) executionFlag = False printSuccess("Execution Complete") except: executionFlag = False t1.join() printFailure("FAILED") elif executionType == "masterhub": logger.info("Execution Started") remoteExecution("COMMAND::" + (" -r -Gusers=" + str(concurrency) + " -Grampup=" + str(rampup) + " -Gcount=" + str(iteration) + " -Gduration=" + str(timeout) + " -GUrl=" + str(url))) else: try: executionFlag = True t1 = threading.Thread(target=getPerfData, args=()) t1.start() logger.info("Starting JMeter") os.system("jmeter.bat -n -t " + filepath + " -Gusers=" + str(concurrency) + " -Grampup=" + str(rampup) + " -Gcount=" + str(iteration) + " -Gduration=" + str(timeout) + " -GUrl=" + str(url)) executionFlag = False t1.join() printSuccess("Execution Complete") except: executionFlag = False t1.join() #printError(exe) printFailure("FAILED")
def setDir(self, txt='Select'): self.calib_dir_src.setValue(txt) self.ediDir.setText(self.calib_dir_src.value()) logger.info('Set source calibration directory: ' + str(txt), __name__) self.updateDirTree()
def check_files_for_list(self, list_of_files, comment=''): logger.info('Check files for list ' + comment, __name__) for fname in list_of_files: msg = '%s is %s' % (fname.ljust(100), self.dict_status[os.path.lexists(fname)]) logger.info(msg)
def onDefault(self): logger.info( 'onDefault - Set default values of configuration parameters.', __name__) cp.setDefaultValues() self.fnameEdit.setText(cp.fname_cp.value())
def setExp(self, txt='Select'): self.exp_name_src.setValue(txt) self.butExp.setText(txt + self.char_expand) if txt == 'Select': self.list_of_exp = None logger.info('Source experiment selected: ' + str(txt), __name__)
def updateDirTree(self): logger.info('Update calibration directory', __name__) if cp.guidirtree is None: return cp.guidirtree.update_dir_tree(self.calib_dir_src.value())
def on_cbox_logy(self): logger.info('Set log10 for Y scale', __name__) self.fig.myLogYIsOn = self.cbox_logy.isChecked() self.fig.myZmin = None self.fig.myZmax = None self.widgimage.processDraw()
def onPrint(self): logger.info('onPrint', __name__) cp.printParameters()
def on_cbox_grid(self): logger.info('On/Off grid.', __name__) self.fig.myGridIsOn = self.cbox_grid.isChecked() self.widgimage.processDraw()
def itemExpanded(self, ind): item = self.model.itemFromIndex(ind) item.setIcon(cp.icon_folder_open) msg = 'Item expanded: %s' % item.text() logger.info(msg, __name__)
def on_edi_bat_end(self): if (not cp.is_active_data_gui.value()): return cp.bat_data_end.setValue(int(self.edi_bat_end.displayText())) logger.info('Set bat_data_end =' + str(cp.bat_data_end.value()), __name__) self.set_fields()
def onSave(self): fname = cp.fname_cp.value() logger.info( 'onSave - save all configuration parameters in file: ' + fname, __name__) cp.saveParametersInFile(fname)