def get_intens_stat_q_bins_arr(self): """Returns <I>(t, q-static) 2D array""" #if self.intens_stat_q_bins_vs_t != None : return self.intens_stat_q_bins_vs_t if not os.path.exists(self.fname_int_stat_q): msg = 'The file: %s is not available' % (self.fname_int_stat_q) gu.confirm_dialog_box(cp.guimain, msg) return None self.intens_stat_q_bins_vs_t = gu.get_array_from_file( self.fname_int_stat_q)[:, 1:] # trim column with event number if self.intens_stat_q_bins_vs_t != None: logger.info( 'I(t,q-stat) is taken from file ' + fnm.path_cora_split_int_static_q(), __name__) return self.intens_stat_q_bins_vs_t else: msg = 'I(t,q-stat) file: %s is not available' % ( fnm.path_cora_split_int_static_q()) msg+= '\nTo produce this file: \n1) in GUI "View Results", click on button "q stat"'\ + '\n2) in GUI "Run/Split" click on button "Run" and repeat processing.' logger.info(msg, __name__) gu.confirm_dialog_box(cp.guimain, msg) return np.ones((self.rows, self.cols), dtype=np.uint8)
def get_intens_stat_q_bins_arr(self) : """Returns <I>(t, q-static) 2D array""" #if self.intens_stat_q_bins_vs_t != None : return self.intens_stat_q_bins_vs_t if not os.path.exists(self.fname_int_stat_q) : msg = 'The file: %s is not available' % (self.fname_int_stat_q) gu.confirm_dialog_box(cp.guimain, msg) return None self.intens_stat_q_bins_vs_t = gu.get_array_from_file(self.fname_int_stat_q)[:,1:] # trim column with event number if self.intens_stat_q_bins_vs_t != None : logger.info('I(t,q-stat) is taken from file ' + fnm.path_cora_split_int_static_q(), __name__) return self.intens_stat_q_bins_vs_t else : msg = 'I(t,q-stat) file: %s is not available' % (fnm.path_cora_split_int_static_q()) msg+= '\nTo produce this file: \n1) in GUI "View Results", click on button "q stat"'\ + '\n2) in GUI "Run/Split" click on button "Run" and repeat processing.' logger.info(msg, __name__) gu.confirm_dialog_box(cp.guimain, msg) return np.ones((self.rows,self.cols), dtype=np.uint8)
def make_psana_cfg_file_for_cora_split_v1(self): self.path_in = apputils.AppDataPath( 'CorAna/scripts/psana-cora-split.cfg').path() self.path_out = fnm.path_cora_split_psana_cfg() self.d_subs = { 'FNAME_XTC': fnm.path_data_xtc_cond(), 'SKIP': str(cp.bat_data_start.value() - 1), 'EVENTS': str(cp.bat_data_end.value() - cp.bat_data_start.value() + 1), 'IMG_REC_MODULE': str(cp.bat_img_rec_mod.value()), 'DETINFO': str(cp.bat_det_info.value()), 'PATH_PREFIX_CORA': str(fnm.path_prefix_cora()), 'IMG_NPARTS': str(cp.bat_img_nparts.value()), 'FNAME_PEDS_AVE': fnm.path_pedestals_ave(), 'FNAME_DATA_AVE': fnm.path_data_ave(), 'FNAME_DATA_RMS': fnm.path_data_rms() } fname_imon_cfg = fnm.path_cora_split_imon_cfg() self.make_imon_cfg_file(fname_imon_cfg) self.d_subs['FNAME_IMON_CFG'] = str(fname_imon_cfg) if cp.lld_type.value() == 'ADU': # ['NONE', 'ADU', 'RMS'] self.d_subs['THRESHOLD_ADU'] = str(cp.lld_adu.value()) self.d_subs['DO_CONST_THR'] = 'true' self.d_subs['THRESHOLD_NRMS'] = '0' self.d_subs['FNAME_PEDS_RMS'] = '' elif cp.lld_type.value() == 'RMS': self.d_subs['THRESHOLD_ADU'] = '0' self.d_subs['DO_CONST_THR'] = 'false' self.d_subs['THRESHOLD_NRMS'] = str(cp.lld_rms.value()) self.d_subs['FNAME_PEDS_RMS'] = fnm.path_pedestals_rms() else: self.d_subs['THRESHOLD_ADU'] = '0' self.d_subs['DO_CONST_THR'] = 'false' self.d_subs['THRESHOLD_NRMS'] = '0' self.d_subs['FNAME_PEDS_RMS'] = '' if os.path.lexists(fnm.path_cora_split_map_static_q()): self.d_subs['FNAME_MAP_BINS'] = fnm.path_cora_split_map_static_q() else: self.d_subs['FNAME_MAP_BINS'] = '' self.d_subs['FNAME_INT_BINS'] = fnm.path_cora_split_int_static_q() self.d_subs['NUMBER_OF_BINS'] = str(cp.ana_stat_part_q.value()) #self.print_substitution_dict() #self.make_cfg_file() txt_cfg = self.text_for_section() self.save_cfg_file(txt_cfg, self.path_out)
def make_psana_cfg_file_for_cora_split_v1 (self) : self.path_in = apputils.AppDataPath('CorAna/scripts/psana-cora-split.cfg').path() self.path_out = fnm.path_cora_split_psana_cfg() self.d_subs = {'FNAME_XTC' : fnm.path_data_xtc_cond(), 'SKIP' : str( cp.bat_data_start.value() - 1 ), 'EVENTS' : str( cp.bat_data_end.value() - cp.bat_data_start.value() + 1 ), 'IMG_REC_MODULE' : str( cp.bat_img_rec_mod.value() ), 'DETINFO' : str( cp.bat_det_info.value() ), 'PATH_PREFIX_CORA': str( fnm.path_prefix_cora() ), 'IMG_NPARTS' : str( cp.bat_img_nparts.value() ), 'FNAME_PEDS_AVE' : fnm.path_pedestals_ave(), 'FNAME_DATA_AVE' : fnm.path_data_ave(), 'FNAME_DATA_RMS' : fnm.path_data_rms() } fname_imon_cfg = fnm.path_cora_split_imon_cfg() self.make_imon_cfg_file (fname_imon_cfg) self.d_subs['FNAME_IMON_CFG' ] = str( fname_imon_cfg ) if cp.lld_type.value() == 'ADU' : # ['NONE', 'ADU', 'RMS'] self.d_subs['THRESHOLD_ADU' ] = str( cp.lld_adu.value() ) self.d_subs['DO_CONST_THR' ] = 'true' self.d_subs['THRESHOLD_NRMS'] = '0' self.d_subs['FNAME_PEDS_RMS'] = '' elif cp.lld_type.value() == 'RMS' : self.d_subs['THRESHOLD_ADU' ] = '0' self.d_subs['DO_CONST_THR' ] = 'false' self.d_subs['THRESHOLD_NRMS'] = str( cp.lld_rms.value() ) self.d_subs['FNAME_PEDS_RMS'] = fnm.path_pedestals_rms() else : self.d_subs['THRESHOLD_ADU' ] = '0' self.d_subs['DO_CONST_THR' ] = 'false' self.d_subs['THRESHOLD_NRMS'] = '0' self.d_subs['FNAME_PEDS_RMS'] = '' if os.path.lexists( fnm.path_cora_split_map_static_q() ) : self.d_subs['FNAME_MAP_BINS' ] = fnm.path_cora_split_map_static_q() else : self.d_subs['FNAME_MAP_BINS' ] = '' self.d_subs['FNAME_INT_BINS' ] = fnm.path_cora_split_int_static_q() self.d_subs['NUMBER_OF_BINS' ] = str( cp.ana_stat_part_q.value() ) #self.print_substitution_dict() #self.make_cfg_file() txt_cfg = self.text_for_section() self.save_cfg_file(txt_cfg, self.path_out)
def add_cfg_trailer_for_cora_split (self) : self.path_in = apputils.AppDataPath('CorAna/scripts/psana-cora-split-trailer.cfg').path() self.d_subs = {'DETINFO' : str( cp.bat_det_info.value() ), 'PATH_PREFIX_CORA': str( fnm.path_prefix_cora() ), 'IMG_NPARTS' : str( cp.bat_img_nparts.value() ), 'FNAME_PEDS_AVE' : fnm.path_pedestals_ave(), 'FNAME_DATA_AVE' : fnm.path_data_ave(), 'FNAME_DATA_RMS' : fnm.path_data_rms() } fname_imon_cfg = fnm.path_cora_split_imon_cfg() self.make_imon_cfg_file (fname_imon_cfg) self.d_subs['FNAME_IMON_CFG' ] = str( fname_imon_cfg ) if cp.lld_type.value() == 'ADU' : # ['NONE', 'ADU', 'RMS'] self.d_subs['THRESHOLD_ADU' ] = str( cp.lld_adu.value() ) self.d_subs['DO_CONST_THR' ] = 'true' self.d_subs['THRESHOLD_NRMS'] = '0' self.d_subs['FNAME_PEDS_RMS'] = '' elif cp.lld_type.value() == 'RMS' : self.d_subs['THRESHOLD_ADU' ] = '0' self.d_subs['DO_CONST_THR' ] = 'false' self.d_subs['THRESHOLD_NRMS'] = str( cp.lld_rms.value() ) self.d_subs['FNAME_PEDS_RMS'] = fnm.path_pedestals_rms() else : self.d_subs['THRESHOLD_ADU' ] = '0' self.d_subs['DO_CONST_THR' ] = 'false' self.d_subs['THRESHOLD_NRMS'] = '0' self.d_subs['FNAME_PEDS_RMS'] = '' if os.path.lexists( fnm.path_cora_split_map_static_q() ) : self.d_subs['FNAME_MAP_BINS' ] = fnm.path_cora_split_map_static_q() else : self.d_subs['FNAME_MAP_BINS' ] = '' self.d_subs['FNAME_INT_BINS' ] = fnm.path_cora_split_int_static_q() self.d_subs['NUMBER_OF_BINS' ] = str( cp.ana_stat_part_q.value() ) #self.print_substitution_dict() self.str_of_modules += ' ImgAlgos.ImgCalib ImgAlgos.ImgIntMonCorr ImgAlgos.ImgIntForBins ImgAlgos.ImgVsTimeSplitInFiles ImgAlgos.ImgAverage' self.txt_cfg_body += self.text_for_section()
def add_cfg_trailer_for_cora_split(self): self.path_in = apputils.AppDataPath( 'CorAna/scripts/psana-cora-split-trailer.cfg').path() self.d_subs = { 'DETINFO': str(cp.bat_det_info.value()), 'PATH_PREFIX_CORA': str(fnm.path_prefix_cora()), 'IMG_NPARTS': str(cp.bat_img_nparts.value()), 'FNAME_PEDS_AVE': fnm.path_pedestals_ave(), 'FNAME_DATA_AVE': fnm.path_data_ave(), 'FNAME_DATA_RMS': fnm.path_data_rms() } fname_imon_cfg = fnm.path_cora_split_imon_cfg() self.make_imon_cfg_file(fname_imon_cfg) self.d_subs['FNAME_IMON_CFG'] = str(fname_imon_cfg) if cp.lld_type.value() == 'ADU': # ['NONE', 'ADU', 'RMS'] self.d_subs['THRESHOLD_ADU'] = str(cp.lld_adu.value()) self.d_subs['DO_CONST_THR'] = 'true' self.d_subs['THRESHOLD_NRMS'] = '0' self.d_subs['FNAME_PEDS_RMS'] = '' elif cp.lld_type.value() == 'RMS': self.d_subs['THRESHOLD_ADU'] = '0' self.d_subs['DO_CONST_THR'] = 'false' self.d_subs['THRESHOLD_NRMS'] = str(cp.lld_rms.value()) self.d_subs['FNAME_PEDS_RMS'] = fnm.path_pedestals_rms() else: self.d_subs['THRESHOLD_ADU'] = '0' self.d_subs['DO_CONST_THR'] = 'false' self.d_subs['THRESHOLD_NRMS'] = '0' self.d_subs['FNAME_PEDS_RMS'] = '' if os.path.lexists(fnm.path_cora_split_map_static_q()): self.d_subs['FNAME_MAP_BINS'] = fnm.path_cora_split_map_static_q() else: self.d_subs['FNAME_MAP_BINS'] = '' self.d_subs['FNAME_INT_BINS'] = fnm.path_cora_split_int_static_q() self.d_subs['NUMBER_OF_BINS'] = str(cp.ana_stat_part_q.value()) #self.print_substitution_dict() self.str_of_modules += ' ImgAlgos.ImgCalib ImgAlgos.ImgIntMonCorr ImgAlgos.ImgIntForBins ImgAlgos.ImgVsTimeSplitInFiles ImgAlgos.ImgAverage' self.txt_cfg_body += self.text_for_section()
class RecordsFromFiles: """Access to the time records from the file """ rows = cp.bat_img_rows.value() cols = cp.bat_img_cols.value() size = cp.bat_img_size.value() fname_time = fnm.path_cora_split_time_ind() fname_int_stat_q = fnm.path_cora_split_int_static_q() fname_q_ave_static = fnm.path_cora_split_q_ave_static() fname_imon = fnm.path_data_scan_monitors_data() fname_imon_cfg = fnm.path_cora_split_imon_cfg() fname_data_ave = fnm.path_data_ave() #----------------------------- def __init__(self): """Constructor. @param fname the file name for ... """ #self.intens_stat_q_bins_vs_t = None #self.time_arr = None pass #----------------------------- def get_time_records_arr(self): etr = EventTimeRecords(self.fname_time) logger.info('Get time records array from file: ' + self.fname_time, __name__) self.time_arr = etr.get_arr_for_plot() return self.time_arr def print_time_records_arr(self): msg = 'time records: ind_ev, t, dt, ind_t:\n' for rec in self.time_arr: msg += str(rec) + '\n' logger.info(msg, __name__) print msg #----------------------------- def get_q_ave_for_stat_q_bins(self): return gu.get_array_from_file(self.fname_q_ave_static) #----------------------------- def get_intens_stat_q_bins_arr(self): """Returns <I>(t, q-static) 2D array""" #if self.intens_stat_q_bins_vs_t != None : return self.intens_stat_q_bins_vs_t if not os.path.exists(self.fname_int_stat_q): msg = 'The file: %s is not available' % (self.fname_int_stat_q) gu.confirm_dialog_box(cp.guimain, msg) return None self.intens_stat_q_bins_vs_t = gu.get_array_from_file( self.fname_int_stat_q)[:, 1:] # trim column with event number if self.intens_stat_q_bins_vs_t != None: logger.info( 'I(t,q-stat) is taken from file ' + fnm.path_cora_split_int_static_q(), __name__) return self.intens_stat_q_bins_vs_t else: msg = 'I(t,q-stat) file: %s is not available' % ( fnm.path_cora_split_int_static_q()) msg+= '\nTo produce this file: \n1) in GUI "View Results", click on button "q stat"'\ + '\n2) in GUI "Run/Split" click on button "Run" and repeat processing.' logger.info(msg, __name__) gu.confirm_dialog_box(cp.guimain, msg) return np.ones((self.rows, self.cols), dtype=np.uint8) 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 get_intens_stat_q_bins(self): """Returns <I>(q-static) averaged over all events""" arr = self.get_intens_stat_q_bins_arr() nevts = arr.shape[0] self.intens_stat_q_bins_aver = np.sum(arr, axis=0) / nevts return self.intens_stat_q_bins_aver def print_intens_stat_q_bins(self): nevts = self.intens_stat_q_bins_vs_t.shape[0] msg = '<I>(q-static) averaged over %d events:\n' % nevts msg += str(self.intens_stat_q_bins_aver) + '\n' logger.info(msg, __name__) print msg #----------------------------- # BldInfo(FEEGasDetEnergy) FEEGasDetEnergy 1 1 1 1 0 0 -1.0000 -1.0000 1.0000 # BldInfo(XCS-IPM-02) XCS-IPM-02 1 1 1 1 0 0 -1.0000 -1.0000 1.0000 # BldInfo(XCS-IPM-mono) XCS-IPM-mono 1 1 1 1 0 1 0.0200 0.5000 0.2600 # DetInfo(XcsBeamline.1:Ipimb.4) Ipimb.4 1 1 1 1 0 0 -1.0000 -1.0000 1.0000 # DetInfo(XcsBeamline.1:Ipimb.5) Ipimb.5 1 1 1 1 0 0 -1.0000 -1.0000 1.0000 def values_from_rec(self, rec): return str(rec[0]), str(rec[1]), int(rec[2]), int(rec[3]), int(rec[4]), int(rec[5]), int(rec[6]), int(rec[7]), \ float(rec[8]), float(rec[9]), float(rec[10]) def get_imon_cfg_pars(self): logger.info('get_imon_cfg_pars', __name__) list_recs = gu.get_text_list_from_file(self.fname_imon_cfg) if list_recs == None: self.list_of_imon_cfg_pars = None return self.list_of_imon_cfg_pars = map(self.values_from_rec, list_recs) return self.list_of_imon_cfg_pars def print_imon_cfg_pars(self): msg = 'Parameters from imon config file: ' + self.fname_imon_cfg + '\n' for rec in self.get_imon_cfg_pars(): msg += str(rec) + '\n' logger.info(msg, __name__) print msg def listMaskForIMonChannels(self, imon): list_of_recs = self.get_imon_cfg_pars() rec = list_of_recs[imon] return rec[2:6] def nparrMaskForIMonChannels(self, imon): return np.array(self.listMaskForIMonChannels(imon), dtype=int) def printMaskForIMonChannels(self, imon): msg = 'Mask for imon %d channels: ' % (imon) + str( self.nparrMaskForIMonChannels(imon)) logger.info(msg, __name__) print msg #----------------------------- 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 printIMonArray(self, imon): msg = 'Sum of intensity monitor channels for imon %d ' % (imon) + '\n' msg += str(self.getIMonArray(imon)) print msg #----------------------------- def get_data_ave_array(self): arr = gu.get_array_from_file(self.fname_data_ave) if arr == None: return np.ones((self.rows, self.cols), dtype=np.uint8) return arr