def set_Energy(self): self.Energy_row=[] self._function.get() if self._c_range.get(): before =float(self.before.get()) after=float(self.after.get()) else: before, after= None, None if self._function.get() == "-I0": Y= lambda x: -x.I0/abs(max(-x.I0)) elif self._function.get() == 'Ref.': Y= lambda x: x.ref elif self._function.get() == 'Ref.der.': for item in fil_spec: item.bm29derRef() Y= lambda x: x.E_RefFp/max(x.E_RefFp) elif self._function.get() == 'Cal. Mu': Y= lambda x: x.Mu elif self._function.get() == 'Cal. der.': self.calibsel.spectra[0].bm29derRef() Y= lambda x: x.E_Fp/max(x.E_MuFp) if self._c_range.get(): L = lambda objecto,x: x.compress((objecto.E>before)&(objecto.E<after)) else: L = lambda objecto,x: x if self._All_spectra.get() =='first spectra ': if self._function.get() =='Cal. Mu' or self._function.get() =='Cal. der.': print "\nnot clear input\nasking to use first sample and calibration...." splinex1y1 = interpolate.splrep(fil_spec[0].E,Y(fil_spec[0])) elif self._All_spectra.get() =='Calibration sample': if self._function.get() =='Ref.' or self._function.get() =='Ref.der.': print "\nATTENTION you are using reference of calibration file\n" raise ValueError() try: splinex1y1 = interpolate.splrep(self.calibsel.spectra[0].E,Y(self.calibsel.spectra[0])) except: self.calibsel.spectra[0]=bm29.bm29file(self.calibsel.spectra[0].data) self.calibsel.spectra[0].bm29derE() if self._function.get() == 'Ref.': splinex1y1 = interpolate.splrep(self.calibsel.spectra[0].E, self.calibsel.spectra[0].Mu) elif self._function.get() == 'Ref.der.': splinex1y1 = interpolate.splrep(self.calibsel.spectra[0].E, self.calibsel.spectra[0].E_MuFp) self.standard_Energy=bt.max_range(fil_spec[0].E, Y(fil_spec[0]),before,after) for item in fil_spec: self.Energy_row.append(float(ut.fitcalibration(x2=L(item,item.E), y2=L(item,Y(item)), param=[0],splinex1y1=splinex1y1)))
def browse_command(self): self.filenames = [] if self.singlefile: filenames = tkFileDialog.askopenfilename() ### print filenames, type(filenames) self.filenames.append(filenames) else: filenames = tkFileDialog.askopenfilenames() filenames = Tk._default_root.tk.splitlist(filenames) self.filenames = sorted(filenames) self.spectra =[] try: for i in self.filenames: self.spectra.append(bm29.bm29file(i, All_Column=self.All_Column)) except bm29.FileFormatError, e: for i in self.filenames: self.spectra.append(bm29.disperati(i))
def browse_command(self): self.filenames = [] if self.singlefile: filenames = tkFileDialog.askopenfilename() ### #print filenames, type(filenames) self.filenames.append(filenames) else: filenames = tkFileDialog.askopenfilenames() filenames = Tk._default_root.tk.splitlist(filenames) self.filenames = sorted(filenames) self.spectra =[] try: for i in self.filenames: self.spectra.append(bm29.bm29file(i, All_Column=self.All_Column)) except bm29.FileFormatError, e: for i in self.filenames: self.spectra.append(bm29.disperati(i))
def opensfile(self): filenames=ut.browse_single() os.chdir(os.path.dirname(filenames)) with open(filenames) as fil: buffero=fil.readlines() PPfs_spec.other_pro={} header=[it for it in buffero[0:PPset.max_head] if not(ut.getfloats(it))] attri=[it for it in header if '# PPAttrib' in it] for op in attri: name, line= op.split(':') name= name.split('# PPAttrib')[1].strip() PPfs_spec.other_pro[name]=numpy.array(ut.getfloats(line)) PPfs_spec.header=[it for it in header if not('# PPAttrib' in it)] buffero=numpy.loadtxt(fname=buffero, skiprows =len(header)) energy, data =numpy.hsplit(buffero,[1]) for mu in data.T: PPset.filesel_spectra.append(bm29.bm29file([energy.flatten(),mu])) return
def opensfile(self): filenames = ut.browse_single() os.chdir(os.path.dirname(filenames)) with open(filenames) as fil: buffero = fil.readlines() PPfs_spec.other_pro = {} header = [ it for it in buffero[0:PPset.max_head] if not (ut.getfloats(it)) ] attri = [it for it in header if '# PPAttrib' in it] for op in attri: name, line = op.split(':') name = name.split('# PPAttrib')[1].strip() PPfs_spec.other_pro[name] = numpy.array(ut.getfloats(line)) PPfs_spec.header = [it for it in header if not ('# PPAttrib' in it)] buffero = numpy.loadtxt(fname=buffero, skiprows=len(header)) energy, data = numpy.hsplit(buffero, [1]) for mu in data.T: PPset.filesel_spectra.append(bm29.bm29file([energy.flatten(), mu])) return
print "\n---module XANES done\n" if __name__ == "__main__": import bm29 filenames = [ "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0000_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0001_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0002_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0003_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0004_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0005_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0006_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0007_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0008_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0009_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0010_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0011_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0012_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0013_0.up" ] filenames = filenames * 5 for i in filenames: PPset.spectra.append(bm29.bm29file(i)) PPset.spectra.header = ['#pipppo\n', '#questo eun test\n'] PPset.x = range(1, len(PPset.spectra) + 1) radice = Tk() radice.title("XANES GUI") pippo = XANES(radice) radice.mainloop()
for i in PPset.spectra:i.INTxan= i.bm29int(L1=x1, L2=x2, attribute='nor') self.INTxan_PlSa_But.y_array= [[item.INTxan for item in PPset.spectra]] print "\n---module XANES done\n" if __name__ == "__main__": import bm29 filenames=["D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0000_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0001_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0002_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0003_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0004_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0005_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0006_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0007_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0008_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0009_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0010_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0011_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0012_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0013_0.up"] filenames=filenames*5 for i in filenames: PPset.spectra.append(bm29.bm29file(i)) PPset.spectra.header=['#pipppo\n','#questo eun test\n'] PPset.x=range(1,len(PPset.spectra)+1) radice = Tk() radice.title("XANES GUI") pippo = XANES(radice) radice.mainloop()
def opens2(self): def linesplit(line): # create a line that is splitted in a list for itemchar in self._ChaSpl.get(): line=line.replace(itemchar,' ') return line.split() fil_spec.header=self.text.gettext() fil_spec.header=fil_spec.header.split('\n') fil_spec.header=[item+'\n' for item in fil_spec.header[0:PPset.max_head] if not(getfloats(item))] #------------- Search if is necessary to add # in front of the file TF=lambda x: False if x[0]=='#' else True if any([TF(i) for i in fil_spec.header]): for i,item in enumerate(fil_spec.header): fil_spec.header[i]='#'+item fil_spec.header.append('# first file header relevant properties' \ '(sample temperature, ring current etc) could' \ 'be saved in the define_x tab\n') # define the attributes fil_spec.other_pro=dict() texto=self.text.gettext().split('\n') for item in self.attribute_list: item.name=item._name.get() iline=linesplit(texto[item.line]) item.field=iline.index(item.value) fil_spec.other_pro[item._name.get()]=[] #Define correspondance col position cols=numpy.array(map(int,[item._position.get() for item in self.column_list if item._check.get()]))-1 colsname=[item._label for item in self.column_list if item._check.get()] # Main cycle open all files pb = ttk.Progressbar(self.top_attr, orient='horizontal', mode='determinate', maximum=len(self.filenames)) pb.pack(side=TOP,expand=NO, fill=X,anchor=N) try: for j,item in enumerate(self.filenames): with open(item) as f: data=f.readlines() i_array=numpy.loadtxt(fname=data, skiprows =len(fil_spec.header), usecols=cols).T energy=i_array[colsname.index('E')].squeeze() if 'Mu' in colsname: mu=i_array[colsname.index('Mu')].squeeze() fil_spec.append(bm29.bm29file([energy,mu])) else: I0=i_array[colsname.index('I0')].squeeze() I1=i_array[colsname.index('I1')].squeeze() if self._mode.get()=="transmission":mu=numpy.log(I0/I1) elif self._mode.get()=="fluorescence":mu=I1/I0 fil_spec.append(bm29.bm29file([energy,mu])) fil_spec[-1].I0=I0 if 'Ref' in colsname: fil_spec[-1].ref=i_array[colsname.index('Ref')].squeeze() elif ('I2' in colsname) and ('I2' in colsname): I2=i_array[colsname.index('I2')].squeeze() I1=i_array[colsname.index('I1')].squeeze() fil_spec[-1].ref=numpy.log(I1/I2) for item in self.attribute_list: iline=linesplit(data[item.line]) fil_spec.other_pro[item.name].append(iline[item.field]) pb['value']=j pb.update_idletasks() except : print "\n\nError reading the file {}\n".format(item) # Main cycle other_pro for item in fil_spec.other_pro.keys(): try: fil_spec.other_pro[item]= numpy.array(map( float,fil_spec.other_pro[item])) except ValueError: pass #print fil_spec.other_pro deriv=max(numpy.gradient(fil_spec[0].mu)) dspac= 3.13467 if E<22500 else 1.63702 for item in fil_spec: item.dspac=dspac pb['value']= len(self.filenames) self.top.destroy()
def set_Energy(self): self.Energy_row = [] self._function.get() if self._c_range.get(): before = float(self.before.get()) after = float(self.after.get()) else: before, after = None, None if self._function.get() == "-I0": Y = lambda x: -x.I0 / abs(max(-x.I0)) elif self._function.get() == 'Ref.': Y = lambda x: x.ref elif self._function.get() == 'Ref.der.': for item in fil_spec: item.bm29derRef() Y = lambda x: x.E_RefFp / max(x.E_RefFp) elif self._function.get() == 'Cal. Mu': Y = lambda x: x.Mu elif self._function.get() == 'Cal. der.': self.calibsel.spectra[0].bm29derRef() Y = lambda x: x.E_Fp / max(x.E_MuFp) if self._c_range.get(): L = lambda objecto, x: x.compress( (objecto.E > before) & (objecto.E < after)) else: L = lambda objecto, x: x if self._All_spectra.get() == 'first spectra ': if self._function.get() == 'Cal. Mu' or self._function.get( ) == 'Cal. der.': print "\nnot clear input\nasking to use first sample and calibration...." splinex1y1 = interpolate.splrep(fil_spec[0].E, Y(fil_spec[0])) elif self._All_spectra.get() == 'Calibration sample': if self._function.get() == 'Ref.' or self._function.get( ) == 'Ref.der.': print "\nATTENTION you are using reference of calibration file\n" raise ValueError() try: splinex1y1 = interpolate.splrep(self.calibsel.spectra[0].E, Y(self.calibsel.spectra[0])) except: self.calibsel.spectra[0] = bm29.bm29file( self.calibsel.spectra[0].data) self.calibsel.spectra[0].bm29derE() if self._function.get() == 'Ref.': splinex1y1 = interpolate.splrep(self.calibsel.spectra[0].E, self.calibsel.spectra[0].Mu) elif self._function.get() == 'Ref.der.': splinex1y1 = interpolate.splrep( self.calibsel.spectra[0].E, self.calibsel.spectra[0].E_MuFp) self.standard_Energy = bt.max_range(fil_spec[0].E, Y(fil_spec[0]), before, after) for item in fil_spec: self.Energy_row.append( float( ut.fitcalibration(x2=L(item, item.E), y2=L(item, Y(item)), param=[0], splinex1y1=splinex1y1)))
def opens2(self): def linesplit(line): # create a line that is splitted in a list for itemchar in self._ChaSpl.get(): line = line.replace(itemchar, ' ') return line.split() fil_spec.header = self.text.gettext() fil_spec.header = fil_spec.header.split('\n') fil_spec.header = [ item + '\n' for item in fil_spec.header[0:PPset.max_head] if not (getfloats(item)) ] #------------- Search if is necessary to add # in front of the file TF = lambda x: False if x[0] == '#' else True if any([TF(i) for i in fil_spec.header]): for i, item in enumerate(fil_spec.header): fil_spec.header[i] = '#' + item fil_spec.header.append('# first file header relevant properties' \ '(sample temperature, ring current etc) could' \ 'be saved in the define_x tab\n') # define the attributes fil_spec.other_pro = dict() texto = self.text.gettext().split('\n') for item in self.attribute_list: item.name = item._name.get() iline = linesplit(texto[item.line]) item.field = iline.index(item.value) fil_spec.other_pro[item._name.get()] = [] #Define correspondance col position cols = numpy.array( map(int, [ item._position.get() for item in self.column_list if item._check.get() ])) - 1 colsname = [ item._label for item in self.column_list if item._check.get() ] # Main cycle open all files pb = ttk.Progressbar(self.top_attr, orient='horizontal', mode='determinate', maximum=len(self.filenames)) pb.pack(side=TOP, expand=NO, fill=X, anchor=N) try: for j, item in enumerate(self.filenames): with open(item) as f: data = f.readlines() i_array = numpy.loadtxt(fname=data, skiprows=len(fil_spec.header), usecols=cols).T energy = i_array[colsname.index('E')].squeeze() if 'Mu' in colsname: mu = i_array[colsname.index('Mu')].squeeze() fil_spec.append(bm29.bm29file([energy, mu])) else: I0 = i_array[colsname.index('I0')].squeeze() I1 = i_array[colsname.index('I1')].squeeze() if self._mode.get() == "transmission": mu = numpy.log(I0 / I1) elif self._mode.get() == "fluorescence": mu = I1 / I0 fil_spec.append(bm29.bm29file([energy, mu])) fil_spec[-1].I0 = I0 if 'Ref' in colsname: fil_spec[-1].ref = i_array[colsname.index('Ref')].squeeze() elif ('I2' in colsname) and ('I2' in colsname): I2 = i_array[colsname.index('I2')].squeeze() I1 = i_array[colsname.index('I1')].squeeze() fil_spec[-1].ref = numpy.log(I1 / I2) for item in self.attribute_list: iline = linesplit(data[item.line]) fil_spec.other_pro[item.name].append(iline[item.field]) pb['value'] = j pb.update_idletasks() except: print "\n\nError reading the file {}\n".format(item) # Main cycle other_pro for item in fil_spec.other_pro.keys(): try: fil_spec.other_pro[item] = numpy.array( map(float, fil_spec.other_pro[item])) except ValueError: pass #print fil_spec.other_pro deriv = max(numpy.gradient(fil_spec[0].mu)) dspac = 3.13467 if E < 22500 else 1.63702 for item in fil_spec: item.dspac = dspac pb['value'] = len(self.filenames) self.top.destroy()
def Perform(self): PPset.spectra = PPset.listum() PP_spec = PPset.spectra PP_spec.header = list(PPfs_spec.header) PP_spec.other_pro = dict() #print type(PPset.spectra.other_pro) aver = self._aver.get() #filesel define the index to keep filesel = ut.string_range(self._from_tof.get()) Eo = float(eval(self.Edgep.get())) predg = float(eval(self.Prep.get())) postedg = float(eval(self.Postp.get())) xstep = float(eval(self.Edges.get())) pstep = float(eval(self.Pres.get())) kstep = float(eval(self.Posts.get())) trunbef = float(eval(self.before.get())) trunaft = float(eval(self.after.get())) #print aver , start #------------------Averafges------------------------------ if self._c_aver.get() and (aver > 1): #progress bar for line in PP_spec.header: if '# averaged each' in line: PP_spec.header.remove(line) PP_spec.header.append( "# averaged each {0:4d} spectra,\n".format(aver)) #self.lista_iter define the number of index of filesel to average for item in range(0, len(filesel), aver): list_ave = [PPfs_spec[ii] for ii in filesel[item:item + aver]] E, Mu = bt.spectra_average([[i.energy, i.mu] for i in list_ave]) PP_spec.append(bm29.bm29file([E, Mu])) #average properties part = len(filesel) % aver full = len(filesel) - part for option in PPfs_spec.other_pro: ar_fl = PPfs_spec.other_pro[option][filesel] print ar_fl.shape, ar_fl[:full].shape ar_fl_full = numpy.mean(ar_fl[:full].reshape(-1, aver), axis=1) ar_fl_part = ar_fl[full + 1:].mean() if part > 0 else [] PP_spec.other_pro[option] = numpy.append( ar_fl_full, ar_fl_part) else: for item in [PPfs_spec[i] for i in filesel]: data = numpy.transpose(numpy.vstack((item.E, item.Mu))) PP_spec.append(bm29.bm29file(data)) PP_spec.other_pro = dict(PPfs_spec.other_pro) #------------------Truncate------------------------------ if self._c_Trun.get(): PP_spec.header = [ item for item in PP_spec.header if not ("# truncate" in item) ] PP_spec.header.append("# truncate between {0:5.9f}" +\ "and{1:5.9f} ".format(trunbef, trunaft)) for i, item in enumerate(PP_spec): data = numpy.transpose(numpy.vstack((item.E, item.Mu))) data = bt.dat_Truncate(data, trunbef, trunaft) PP_spec[i].energy, PP_spec[i].mu = map(numpy.ravel, numpy.hsplit(data, 2)) #spectra[i]=bm29.bm29file(data) #------------------Rebin------------------------------ if self._c_Rebin.get(): PP_spec.header = [ item for item in PP_spec.header if not ('# rebin' in item) ] PP_spec.header.append("# rebin with param. {0:5.7f},{1:5.7f},"\ "{2:5.7f},{3:5.7f},{4:5.7f},{5:5.7f}\n".format( Eo, predg, postedg, pstep, xstep, kstep)) pb = ttk.Progressbar(self.quadro_buttonp1, orient='horizontal', mode='determinate', maximum=len(PP_spec)) pb.pack(side=LEFT, anchor=W, expand=1, fill=X) for i, item in enumerate(PP_spec): data = numpy.transpose(numpy.vstack((item.energy, item.mu))) pb.step() pb.update_idletasks() try: data = bt.rebin(data, 0, Eo, predg, postedg, pstep, xstep, kstep, file='', msgStream=None) PP_spec[i] = (bm29.bm29file(data)) except bt.RebinError, self.rebinerror: top = Toplevel() Label(top, text="Rebin not performed " + self.rebinerror.parameter).pack(expand=YES) break pb.destroy()
if __name__ == "__main__": filenames = [ "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0000_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0001_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0002_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0003_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0004_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0005_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0006_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0007_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0008_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0009_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0010_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0011_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0012_0.up" ] filenames = filenames * 2 for i in filenames: PPfs_spec.append(bm29.bm29file(i)) PPfs_spec.header = ['# fddffgdfd\n', '# questa e una prova\n'] PPfs_spec.other_pro = {} PPset.x = range(1, len(PP_spec) + 1) radice = Tk() radice.title("Avesel") pippo = Avesel(radice) pippo.before.set(round(min(PPfs_spec[0].energy), 2)) pippo.after.set(round(max(PPfs_spec[0].energy), 2)) pippo._from_tof.set("1-" + str(len(PPset.filesel_spectra))) radice.mainloop()
def Perform(self): PPset.spectra=PPset.listum() PP_spec=PPset.spectra PP_spec.header=list(PPfs_spec.header) PP_spec.other_pro=dict() #print type(PPset.spectra.other_pro) aver = self._aver.get() #filesel define the index to keep filesel = ut.string_range(self._from_tof.get()) Eo = float(eval(self.Edgep.get())) predg= float(eval(self.Prep.get())) postedg = float(eval(self.Postp.get())) xstep = float(eval(self.Edges.get())) pstep = float(eval(self.Pres.get())) kstep = float(eval(self.Posts.get())) trunbef= float(eval(self.before.get())) trunaft= float(eval(self.after.get())) #print aver , start #------------------Averafges------------------------------ if self._c_aver.get() and (aver>1): #progress bar for line in PP_spec.header: if '# averaged each' in line:PP_spec.header.remove(line) PP_spec.header.append("# averaged each {0:4d} spectra,\n".format(aver)) #self.lista_iter define the number of index of filesel to average for item in range(0,len(filesel),aver): list_ave=[PPfs_spec[ii] for ii in filesel[item:item+aver]] E, Mu = bt.spectra_average([[i.energy,i.mu] for i in list_ave]) PP_spec.append(bm29.bm29file([E,Mu])) #average properties part=len(filesel)%aver full=len(filesel)-part for option in PPfs_spec.other_pro: ar_fl=PPfs_spec.other_pro[option][filesel] print ar_fl.shape, ar_fl[:full].shape ar_fl_full=numpy.mean(ar_fl[:full].reshape(-1, aver), axis=1) ar_fl_part=ar_fl[full+1:].mean() if part>0 else [] PP_spec.other_pro[option]=numpy.append(ar_fl_full,ar_fl_part) else: for item in [PPfs_spec[i] for i in filesel]: data = numpy.transpose(numpy.vstack((item.E,item.Mu))) PP_spec.append(bm29.bm29file(data)) PP_spec.other_pro=dict(PPfs_spec.other_pro) #------------------Truncate------------------------------ if self._c_Trun.get(): PP_spec.header=[item for item in PP_spec.header if not("# truncate" in item)] PP_spec.header.append("# truncate between {0:5.9f}" +\ "and{1:5.9f} ".format(trunbef, trunaft)) for i,item in enumerate(PP_spec): data = numpy.transpose(numpy.vstack((item.E,item.Mu))) data = bt.dat_Truncate(data, trunbef, trunaft) PP_spec[i].energy, PP_spec[i].mu = map(numpy.ravel, numpy.hsplit(data,2)) #spectra[i]=bm29.bm29file(data) #------------------Rebin------------------------------ if self._c_Rebin.get(): PP_spec.header=[item for item in PP_spec.header if not('# rebin' in item)] PP_spec.header.append("# rebin with param. {0:5.7f},{1:5.7f},"\ "{2:5.7f},{3:5.7f},{4:5.7f},{5:5.7f}\n".format( Eo, predg, postedg, pstep, xstep, kstep)) pb = ttk.Progressbar(self.quadro_buttonp1, orient='horizontal', mode='determinate', maximum=len(PP_spec)) pb.pack(side = LEFT,anchor = W, expand = 1, fill = X) for i,item in enumerate(PP_spec): data = numpy.transpose(numpy.vstack((item.energy,item.mu))) pb.step() ;pb.update_idletasks() try: data=bt.rebin(data, 0, Eo, predg, postedg, pstep, xstep, kstep, file='', msgStream=None) PP_spec[i]=(bm29.bm29file(data)) except bt.RebinError, self.rebinerror: top = Toplevel() Label(top, text = "Rebin not performed " + self.rebinerror.parameter).pack(expand = YES) break pb.destroy()
pass if __name__ == "__main__": filenames=["D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0000_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0001_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0002_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0003_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0004_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0005_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0006_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0007_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0008_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0009_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0010_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0011_0.up", "D:/home/cprestip/mes documents/data_fit/bordeaux/Run4_bordeax/Ca2Mn3O8/raw/Ca2Mn3O8_ramp1_H2_0012_0.up"] filenames=filenames*2 for i in filenames: PPfs_spec.append(bm29.bm29file(i)) PPfs_spec.header=['# fddffgdfd\n','# questa e una prova\n'] PPfs_spec.other_pro={} PPset.x=range(1,len(PP_spec)+1) radice = Tk() radice.title("Avesel") pippo = Avesel(radice) pippo.before.set(round(min(PPfs_spec[0].energy),2)) pippo.after.set(round(max(PPfs_spec[0].energy),2)) pippo._from_tof.set("1-"+str(len(PPset.filesel_spectra))) radice.mainloop()