Esempio n. 1
0
    def rebinfiles(self):
        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()))
        pstep = float(eval(self.Pres.get()))
        kstep = float(eval(self.Posts.get()))
        trunbef = float(eval(self.before.get())) / 1000
        trunaft = float(eval(self.after.get())) / 1000

        self.spectra = self.filesel.spectra
        for item in self.spectra:
            print "pippo1"
            rebdata = bt.dat_Truncate(item.data, trunbef, trunaft)
            rebdata = bt.rebin(rebdata,
                               0,
                               Eo,
                               predg,
                               postedg,
                               pstep,
                               xstep,
                               kstep,
                               file='',
                               msgStream=None)
            writefile = item.fullfilename + ".reb"
            item.bm29write(writefile, rebdata)
Esempio n. 2
0
 def plot(self):
     #print self.Edgep
     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()))
     pstep = float(eval(self.Pres.get()))
     kstep = float(eval(self.Posts.get()))
     trunbef = float(eval(self.before.get())) / 1000
     trunaft = float(eval(self.after.get())) / 1000
     item = self.filesel.spectra[0]
     rebdata = bt.dat_Truncate(item.data, trunbef, trunaft)
     try:
         rebdata = bt.rebin(rebdata,
                            0,
                            Eo,
                            predg,
                            postedg,
                            pstep,
                            xstep,
                            kstep,
                            file='',
                            msgStream=None)
     except bt.RebinError, e:
         self.graph = utility.Graph(e.parameter)
         self.graph.plot([item.E, rebdata[:, 0] * 1000],
                         [item.Mu, rebdata[:, 1]],
                         ["original", "Truncated"],
                         e.parameter + "\n only truncated data")
         return
Esempio n. 3
0
    def Perform(self):
        global linear_comb
        global sel  # define the range of spectra used
        global x_array
        sel=ut.string_range(self._sel.get())
        x_array=self.file_sel.x_array[0]
        start, end =  self.retr_ranges()    
        Lista_Standard=LinComb.standard_list()
        def float2(x):
            try:
                return float(x)
            except:
                return None
        for item in self.Standard_list:
            if item._active.get():
                if item._label.get() in Lista_Standard.keys():
                   item._label.set(item._label.get()[:-1]+str(self.Standard_list.index(item))) 
                Lista_Standard.add(LinComb.standard(label=item._label.get(),
                                                x=item.file_sel.spectra[0].x,
                                                y=item.file_sel.spectra[0].y,
                                                x0=x_array,
                                                value=float2(item._start_value.get()),
                                                fix=float2(item._fix.get()),
                                                mini=float2(item._mini.get()),
                                                maxi=float2(item._maxi.get())
                                                ))
                



        linear_comb=list()
        trunc=lambda x : bt.dat_Truncate([x_array,self.file_sel.spectra[x].y], start, end)
        #for the column in selected spectra
        for column in sel:
            x,y=trunc(column)
            linear_comb.append(LinComb.LinComb(
                               x,y, Lista_Standard))

        self.Coeff=list()
        self.Coeff_error=list()
        self.residual=list()
        self.total=list()
        self.total_error=list()
        self.chisq=list()
        # non so perche??
        linear_comb[0].solve()
        for item in linear_comb:
            item.solve()
            value=[par.param.value for par in item.standards_list.itervalues()]
            error=[par.stderr for par in item.standards_list.Standard_Parameters.itervalues()]
            self.Coeff.append(value)
            self.Coeff_error.append(error) 
            self.total.append(sum(value))
            self.total_error.append(sum(error))            
            self.residual.append(item.result.residual)
            self.chisq.append(item.result.chisqr)
        #print self.Coeff    
        self.Coeff=numpy.transpose(numpy.array(self.Coeff))    
        self.Coeff_error=numpy.transpose(numpy.array(self.Coeff_error)) 
        print "#"*20,"\nFit Done"
Esempio n. 4
0
 def calc(self):
     """calculate derivative and interpoolated x"""
     if self.interpolation !=0:
         self.x_deriv=numpy.arange(self.lim1,self.lim2,self.interpolation)
     else:    
         self.x_deriv=bt.dat_Truncate(PPset.spectra[0].energy, self.lim1, self.lim2)            
     if len(PPset.spectra)!=0:
         PPset.spectra[self.num_der].bm29derE(sampling=self.x_deriv, L1=self.lim1,
                                                    L2=self.lim2, s=self.smoot/100) 
         PPset.spectra[self.num_der].deriv=PPset.spectra[self.num_der].E_MuFp
         PPset.spectra[self.num_der].x_int=self.x_deriv          
Esempio n. 5
0
 def calc(self):
     """calculate derivative and interpoolated x"""
     if self.interpolation != 0:
         self.x_deriv = numpy.arange(self.lim1, self.lim2,
                                     self.interpolation)
     else:
         self.x_deriv = bt.dat_Truncate(PPset.spectra[0].energy, self.lim1,
                                        self.lim2)
     if len(PPset.spectra) != 0:
         PPset.spectra[self.num_der].bm29derE(sampling=self.x_deriv,
                                              L1=self.lim1,
                                              L2=self.lim2,
                                              s=self.smoot / 100)
         PPset.spectra[self.num_der].deriv = PPset.spectra[
             self.num_der].E_MuFp
         PPset.spectra[self.num_der].x_int = self.x_deriv
Esempio n. 6
0
 def Perform(self):
     global spectra
     global spectra_tot
     global x_array 
     global x_array_t
     sel=ut.string_range(self._sel.get())
     x_array=self.file_sel.spectra[0].x
     start, end =  self.retr_ranges()    
     spectra_tot=ut.datalize(self.file_sel.spectra[0].y)
     for i in sel[1:]:
         spectra_tot =ut.datalize(spectra_tot,self.file_sel.spectra[i].y)
     spectra=ut.datalize(x_array, spectra_tot)
     spectra = bt.dat_Truncate(spectra, start, end)
     x_array_t=spectra[:,0]
     spectra =spectra[:,1:]
     spectra=spectra.astype("double")
Esempio n. 7
0
  def rebinfiles(self):
    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())) 
    pstep = float(eval(self.Pres.get()))
    kstep = float(eval(self.Posts.get()))     
    trunbef= float(eval(self.before.get()))/1000
    trunaft= float(eval(self.after.get()))/1000  

    self.spectra = self.filesel.spectra
    for item in self.spectra:
        print "pippo1"
        rebdata=bt.dat_Truncate(item.data, trunbef, trunaft)    
        rebdata = bt.rebin(rebdata, 0, Eo, predg, postedg, pstep, xstep, kstep, file='', msgStream=None) 
        writefile = item.fullfilename +".reb"
        item.bm29write(writefile,rebdata)
Esempio n. 8
0
 def plot(self):
   #print self.Edgep 
   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())) 
   pstep = float(eval(self.Pres.get()))                            
   kstep = float(eval(self.Posts.get()))     
   trunbef= float(eval(self.before.get()))/1000
   trunaft= float(eval(self.after.get()))/1000  
   item = self.filesel.spectra[0]
   rebdata = bt.dat_Truncate(item.data, trunbef, trunaft)
   try:                
      rebdata=bt.rebin(rebdata, 0, Eo, predg, postedg, pstep, xstep, kstep, file='', msgStream=None)
   except bt.RebinError, e: 
      self.graph = utility.Graph(e.parameter)
      self.graph.plot([item.E,rebdata[:,0]*1000], [item.Mu,rebdata[:,1]],["original","Truncated"],e.parameter+"\n only truncated data")
      return
Esempio n. 9
0
    def Perform(self):
        global linear_comb
        global sel  # define the range of spectra used
        global x_array
        sel = ut.string_range(self._sel.get())
        start, end = self.retr_ranges()
        x_all = self.file_sel.x_array[0]
        x_array = bt.dat_Truncate(x_all, start, end)
        Lista_Standard = LinComb.standard_list()

        def float2(x):
            '''test if a value is a float'''
            try:
                return float(x)
            except:
                return None

        # define the list of standart to be used in the refinement
        for item in self.Standard_list:
            try:
                if item._active.get():
                    if item._label.get() in Lista_Standard.keys():
                        # change already used label
                        labelx = '%s%d' % (item._label.get()[:-1],
                                           self.Standard_list.index(item))
                        item._label.set(labelx)

                    Lista_Standard.add(
                        LinComb.standard(label=item._label.get(),
                                         x=item.file_sel.spectra[0].x,
                                         y=item.file_sel.spectra[0].y,
                                         x0=x_array,
                                         value=float2(item._start_value.get()),
                                         fix=float2(item._fix.get()),
                                         mini=float2(item._mini.get()),
                                         maxi=float2(item._maxi.get())))
            except ValueError as err:
                if 'Found x value not in the domain' in err:
                    a = 'Found x value outside %s ranges,' % item._label.get()
                    a = '%s\nfitting range will be decreased' % a
                    messager = a = '%s\nPlease Fit again\n' % a
                    newmin = item.file_sel.spectra[0].x.min()
                    newmin = newmin if newmin > x_array.min() else x_array.min(
                    )
                    self._fromf.set(str(round(newmin + 0.5)))
                    newmax = item.file_sel.spectra[0].x.max()
                    newmax = newmax if newmax < x_array.max() else x_array.max(
                    )
                    self._tof.set(str(round(newmax - 0.5)))
                    print messager
                    tkMessageBox.showinfo("Please fit again\n", messager)
                    raise ValueError('Found x value not in the domain')
                else:
                    raise ValueError(err)

        linear_comb = list()
        trunc = lambda x: bt.dat_Truncate([x_all, self.file_sel.spectra[x].y],
                                          start, end)
        #for the column in selected spectra
        for column in sel:
            #pylab.plot(x_array,self.file_sel.spectra[column].y, 'o')
            x, y = trunc(column)
            linear_comb.append(LinComb.LinComb(x, y, Lista_Standard))

        self.Coeff = list()
        self.Coeff_error = list()
        self.residual = list()
        self.total = list()
        self.total_error = list()
        self.chisq = list()
        # non so perche??
        linear_comb[0].solve()
        ## fine test
        pb = ttk.Progressbar(self.Quadro_Par4,
                             orient='horizontal',
                             mode='determinate',
                             maximum=len(linear_comb))
        pb.pack(side=LEFT, anchor=W, expand=1, fill=X)
        for j, item in enumerate(linear_comb):
            if j != 0:
                item.standards_list.Standard_Parameters = linear_comb[
                    j - 1].result.params
            item.solve()
            value = [par.value for par in item.result.params.itervalues()]
            error = [par.stderr for par in item.result.params.itervalues()]
            self.Coeff.append(value)
            self.Coeff_error.append(error)
            self.total.append(sum(value))
            self.total_error.append(sum(error))
            self.residual.append(item.result.residual)
            self.chisq.append(item.result.chisqr)
            pb.step()
            pb.update_idletasks()
        pb.destroy()
        self.Coeff = numpy.transpose(numpy.array(self.Coeff))
        self.Coeff_error = numpy.transpose(numpy.array(self.Coeff_error))
        print "#" * 20, "\nFit Done"
Esempio n. 10
0
    def Perform(self):
        param = PPset.spectra.call_pe
        #-----------------Max derivate  ---------------------
        if self._check_deriv.get():
            header = list(PPset.spectra.header)
            print "\n ---Derivative Calculation---", num_deriv
            if num_deriv:
                for item in PPset.spectra:
                    if __verbose__: print "Xanes derivative"
                    item.bm29Num_der(window_len=self.smoot,
                                     step=self.interpolation,
                                     L1=float(self._deriv_start.get()),
                                     L2=float(self._deriv_end.get()),
                                     repeat=self.smoot_repeat)
                self.derivate_PlSa_But.x_array = [
                    item.NumDer.x_int for item in PPset.spectra
                ]
                self.derivate_PlSa_But.y_array = [
                    item.NumDer.deriv for item in PPset.spectra
                ]
                self.derivate_PlSa_But.comments = [
                    header for item in PPset.spectra
                ]
            else:
                if self.interpolation != 0:
                    self.x_deriv=numpy.arange(float(self._deriv_start.get()), \
                                              float(self._deriv_end.get()),  \
                                              self.interpolation)
                else:
                    self.x_deriv=bt.dat_Truncate(PPset.spectra[0].energy, \
                                                   float(self._deriv_start.get()), \
                                                   float(self._deriv_end.get()))
                for item in PPset.spectra:
                    if __verbose__: print "Xanes derivative"
                    item.bm29derE(sampling=self.x_deriv, L1=float(self._deriv_start.get()),\
                                  L2=float(self._deriv_end.get()), s=self.smoot/100)
                self.derivate_PlSa_But.x_array = [
                    self.x_deriv for item in PPset.spectra
                ]
                self.derivate_PlSa_But.y_array = [
                    item.E_MuFp for item in PPset.spectra
                ]
                self.derivate_PlSa_But.comments = [
                    header for item in PPset.spectra
                ]


            c1 ="# Derivative calc. between "+ self._deriv_start.get() + \
                                         " and "+ self._deriv_end.get()+"\n"
            #item.append(c1)
            if num_deriv:
                c1 = "# Num. derivative calc.  with smoot= %1.8f ," \
                               "interpolation= %1.4f, repeated= %2d\n" %(
                          self.smoot, self.interpolation ,self.smoot_repeat)
            else:
                c1 = "# Spl derivative  calc.  with smoot= %1.8f ,"\
                                            "interpolation= %1.4f\n" %(
                                            self.smoot, self.interpolation)

            self.derivate_PlSa_But.comments[0].append(c1)
            self.derivate_PlSa_But.comments[0].append("#L E  Derivate_smot" +
                                                      str(self.smoot) + "\n")

            self.Max_PlSa_But.x_array = [PPset.x]
            self.Max_PlSa_But.comments = []
            self.Max_PlSa_But.comments.append(
                list(self.derivate_PlSa_But.comments[0]))
            self.Max_PlSa_But.comments[0][-1] = "#  index   Derivate_Max\n"
            for item in PPset.spectra:
                self.Max_PlSa_But.y_array = [[
                    item.NumDer.x_int[numpy.argmax(item.NumDer.deriv)]
                    for item in PPset.spectra
                ]]

        #-----------------XANES norm  ---------------------
        if self._check_xan.get():
            print "\n ---XANES Normalization---"
            header = list(PPset.spectra.header)
            pb = ttk.Progressbar(self.quadro_perform,
                                 orient='horizontal',
                                 mode='determinate',
                                 maximum=len(PPset.spectra))
            pb.pack(side=LEFT, anchor=W, expand=1, fill=X)
            for item in PPset.spectra:
                if __verbose__: print "Xanes norm"
                pb.step()
                pb.update_idletasks()
                item.XANES_Norm(**param)
            if __verbose__: print "Xanes norm done"
            pb.destroy()
            #self._check_xan.set(0)
            #put some reasonable value in the other case
            self._deriv_start.set(round(PPset.spectra[0].e0 - 50, 2))
            self._deriv_end.set(round(PPset.spectra[0].e0 + 80, 2))
            self._INTxan_start.set(round(PPset.spectra[0].e0 - 50, 2))
            self._INTxan_end.set(round(PPset.spectra[0].e0 + 80, 2))
            self.Xanes_PlSa_But.x_array = [
                item.energy for item in PPset.spectra
            ]
            if self._xflatten.get() and True or False:
                self.Xanes_PlSa_But.y_array = [
                    item.flat for item in PPset.spectra
                ]
            else:
                self.Xanes_PlSa_But.y_array = [
                    item.norm for item in PPset.spectra
                ]
            self.Xanes_PlSa_But.comments = [header for item in PPset.spectra]
            ##comment how calculated XANES norm
            c1 = "# Xanes normalization calc. with "
            for i in ['e0', 'pre1', 'pre2']:
                c1 += "%s = %s, " % (i, str(PPset.spectra.call_pe[i]))
            self.Xanes_PlSa_But.comments[0].append(c1 + '\n')
            c2 = "# Xanes normalization calc. with"
            for i in ['norm1', 'norm2']:
                c1 += "%s = %s, " % (i, str(PPset.spectra.call_pe[i]))
            c2 += ", flatted= " + str(self._xflatten.get() and True or False)
            self.Xanes_PlSa_But.comments[0].append(c2 + '\n')
            #add nuovo E Norm for all comments
            self.Xanes_PlSa_But.comments[0].append("# E  Nor\n")

            #-----------------iff e0---------------------
            self.Eo_PlSa_But.x_array = [PPset.x]
            self.Eo_PlSa_But.comments = []
            self.Eo_PlSa_But.comments.append(list(header[:-1]))
            ##comment
            self.Eo_PlSa_But.comments[0].append("#  index  iff_Eo\n")
            self.Eo_PlSa_But.y_array = [[item.e0 for item in PPset.spectra]]
            #-----------------iff ej---------------------
            self.Ej_PlSa_But.x_array = [PPset.x]
            self.Ej_PlSa_But.comments = []
            self.Ej_PlSa_But.comments.append(list(header[:-1]))
            self.Ej_PlSa_But.comments[0].append("# index  iff_Ej\n")
            self.Ej_PlSa_But.y_array = [[
                item.edge_step for item in PPset.spectra
            ]]
            #-----------------Integral---------------------
        if self._check_INT.get():
            self.INTxan_PlSa_But.x_array = [PPset.x]
            self.INTxan_PlSa_But.comments = []
            self.INTxan_PlSa_But.comments.append(
                list(self.Xanes_PlSa_But.comments[0]))

            self.INTxan_PlSa_But.comments[0].append(
                "# Int Eo cAlculated with parameter %s , %s%s" %
                (str(self._INTxan_start.get()), str(
                    self._INTxan_end.get()), "\n"))
            self.INTxan_PlSa_But.comments[0].append("#L  INDEX  Int\n")
            x1 = float(eval(self._INTxan_start.get()))
            x2 = float(eval(self._INTxan_end.get()))
            if self._xflatten.get() and True or False:
                for i in PPset.spectra:
                    i.INTxan = i.bm29int(L1=x1, L2=x2, attribute='flat')
            else:
                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"
Esempio n. 11
0
    def Perform(self):
        param=PPset.spectra.call_pe
        #-----------------Max derivate  ---------------------    
        if self._check_deriv.get():
            header=list(PPset.spectra.header)
            print "\n ---Derivative Calculation---" , num_deriv
            if num_deriv:    
                for item in PPset.spectra:
                    if __verbose__: print "Xanes derivative"
                    item.bm29Num_der(window_len=self.smoot, step=self.interpolation,
                                              L1=float(self._deriv_start.get()),
                                                L2=float(self._deriv_end.get()),
                                                       repeat=self.smoot_repeat)
                self.derivate_PlSa_But.x_array= [item.NumDer.x_int for item in PPset.spectra]
                self.derivate_PlSa_But.y_array= [item.NumDer.deriv for item in PPset.spectra]
                self.derivate_PlSa_But.comments= [header for item in PPset.spectra]
            else:    
                if self.interpolation !=0:
                    self.x_deriv=numpy.arange(float(self._deriv_start.get()), \
                                              float(self._deriv_end.get()),  \
                                              self.interpolation)
                else:
                    self.x_deriv=bt.dat_Truncate(PPset.spectra[0].energy, \
                                                   float(self._deriv_start.get()), \
                                                   float(self._deriv_end.get()))
                for item in PPset.spectra:
                    if __verbose__: print "Xanes derivative"
                    item.bm29derE(sampling=self.x_deriv, L1=float(self._deriv_start.get()),\
                                  L2=float(self._deriv_end.get()), s=self.smoot/100) 
                self.derivate_PlSa_But.x_array= [self.x_deriv for item in PPset.spectra]
                self.derivate_PlSa_But.y_array= [item.E_MuFp for item in PPset.spectra]
                self.derivate_PlSa_But.comments= [header for item in PPset.spectra]                    
                    
            for item in self.derivate_PlSa_But.comments: 
                c1 ="# Derivative calc. between "+ self._deriv_start.get() + \
                                             " and "+ self._deriv_end.get()+"\n"
                #item.append(c1)
                if num_deriv:
                    c1 = "# Num. derivative calc.  with smoot= %1.8f ," \
                                   "interpolation= %1.4f, repeated444= %2d\n" %(
                              self.smoot, self.interpolation ,self.smoot_repeat)
                else:
                    c1 = "# Spl derivative  calc.  with smoot= %1.8f ,"\
                                                "interpolation= %1.4f\n" %(
                                                self.smoot, self.interpolation)
                item.append(c1)
                item.append("#L E  Derivate_smot"+str(self.smoot)+"\n")    
         
            self.Max_PlSa_But.x_array= [PPset.x]
            self.Max_PlSa_But.comments=[]                                 
            self.Max_PlSa_But.comments.append(header)
            c1 ="# Max derivative calc. between "+ self._deriv_start.get()+" and "+ self._deriv_end.get()+"\n"
            self.Max_PlSa_But.comments[0].append(c1)
            if num_deriv: 
                c1 = "# Max derivative calc.  with smoot= %1.8f ,interpolation= %1.4f, repeated= %1.4f\n" %(
                                                self.smoot, self.interpolation,self.smoot_repeat)
            self.Max_PlSa_But.comments[0].append(c1)
            self.Max_PlSa_But.comments[0].append(PPset.spectra.header)
            self.Max_PlSa_But.comments[0].append( "#L  index   Derivate_Max\n")
            for item in PPset.spectra:
                self.Max_PlSa_But.y_array= [[item.NumDer.x_int[numpy.argmax(item.NumDer.deriv)] for item in PPset.spectra]]        



        #-----------------XANES norm  ---------------------  
        if self._check_xan.get():
            print "\n ---XANES Normalization---"      
            header=list(PPset.spectra.header)
            pb = ttk.Progressbar(self.quadro_perform, orient='horizontal', 
                                             mode='determinate',
                                             maximum=len(PPset.spectra))
            pb.pack(side = LEFT,anchor = W, expand = 1, fill = X)            
            for item in PPset.spectra:
                if __verbose__: print "Xanes norm"
                pb.step()
                pb.update_idletasks()
                item.XANES_Norm(**param)
            if __verbose__: print "Xanes norm done"
            pb.destroy()
            #self._check_xan.set(0)
            #put some reasonable value in the other case
            self._deriv_start.set(round(PPset.spectra[0].e0 -50, 2))
            self._deriv_end.set(round(PPset.spectra[0].e0 +80, 2))            
            self._INTxan_start.set(round(PPset.spectra[0].e0 -50, 2))
            self._INTxan_end.set(round(PPset.spectra[0].e0 +80, 2))
            self.Xanes_PlSa_But.x_array= [item.energy for item in PPset.spectra]
            if self._xflatten.get() and True or False:
                self.Xanes_PlSa_But.y_array= [item.flat for item in PPset.spectra]
            else:
                self.Xanes_PlSa_But.y_array= [item.norm for item in PPset.spectra]
            self.Xanes_PlSa_But.comments= [header for item in PPset.spectra]
            ##comment how calculated XANES norm
            c1 ="# Xanes normalization calc. with "
            for i in ['e0','pre1','pre2']: c1+="%s = %s, " %(i, str(PPset.spectra.call_pe[i]))
            self.Xanes_PlSa_But.comments[0].append(c1+'\n')
            c2 = "# Xanes normalization calc. with"
            for i in ['norm1', 'norm2']: c1+="%s = %s, " %(i, str(PPset.spectra.call_pe[i]))
            c2+=", flatted= "+str(self._xflatten.get() and True or False)
            self.Xanes_PlSa_But.comments[0].append(c2+'\n')
            #add nuovo E Norm for all comments
            self.Xanes_PlSa_But.comments[0].append("# E  Nor\n")
    
            #-----------------iff e0---------------------
            self.Eo_PlSa_But.x_array= [PPset.x]
            self.Eo_PlSa_But.comments=[]
            self.Eo_PlSa_But.comments.append(list(header[:-1]))
            ##comment
            self.Eo_PlSa_But.comments[0].append( "#  index  iff_Eo\n")
            self.Eo_PlSa_But.y_array= [[item.e0 for item in PPset.spectra]]        
            #-----------------iff ej---------------------
            self.Ej_PlSa_But.x_array= [PPset.x]
            self.Ej_PlSa_But.comments=[]
            self.Ej_PlSa_But.comments.append(list(header[:-1]))
            self.Ej_PlSa_But.comments[0].append( "# index  iff_Ej\n")
            self.Ej_PlSa_But.y_array= [[item.edge_step for item in PPset.spectra]]
            #-----------------Integral---------------------
        if self._check_INT.get():
            self.INTxan_PlSa_But.x_array= [PPset.x]
            self.INTxan_PlSa_But.comments=[]
            self.INTxan_PlSa_But.comments.append(list(self.Xanes_PlSa_But.comments[0]))
                
            self.INTxan_PlSa_But.comments[0].append( 
                                 "# Int Eo cAlculated with parameter %s , %s%s"
                                               %(str(self._INTxan_start.get()), 
                                             str(self._INTxan_end.get()),"\n"))
            self.INTxan_PlSa_But.comments[0].append( "#L  INDEX  Int\n")
            x1=float(eval(self._INTxan_start.get()))
            x2=float(eval(self._INTxan_end.get()))
            if self._xflatten.get() and True or False:
               for i in PPset.spectra:i.INTxan= i.bm29int(L1=x1, L2=x2, attribute='flat')
            else :
               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"    
Esempio n. 12
0
    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()
Esempio n. 13
0
    def Perform(self):
        global linear_comb
        global sel  # define the range of spectra used
        global x_array
        sel = ut.string_range(self._sel.get())
        x_array = self.file_sel.x_array[0]
        start, end = self.retr_ranges()
        Lista_Standard = LinComb.standard_list()

        def float2(x):
            try:
                return float(x)
            except:
                return None

        for item in self.Standard_list:
            if item._active.get():
                if item._label.get() in Lista_Standard.keys():
                    item._label.set(item._label.get()[:-1] +
                                    str(self.Standard_list.index(item)))
                Lista_Standard.add(
                    LinComb.standard(label=item._label.get(),
                                     x=item.file_sel.spectra[0].x,
                                     y=item.file_sel.spectra[0].y,
                                     x0=x_array,
                                     value=float2(item._start_value.get()),
                                     fix=float2(item._fix.get()),
                                     mini=float2(item._mini.get()),
                                     maxi=float2(item._maxi.get())))

        linear_comb = list()
        trunc = lambda x: bt.dat_Truncate(
            [x_array, self.file_sel.spectra[x].y], start, end)
        #for the column in selected spectra
        for column in sel:
            x, y = trunc(column)
            linear_comb.append(LinComb.LinComb(x, y, Lista_Standard))

        self.Coeff = list()
        self.Coeff_error = list()
        self.residual = list()
        self.total = list()
        self.total_error = list()
        self.chisq = list()
        # non so perche??
        linear_comb[0].solve()
        for item in linear_comb:
            item.solve()
            value = [
                par.param.value for par in item.standards_list.itervalues()
            ]
            error = [
                par.stderr for par in
                item.standards_list.Standard_Parameters.itervalues()
            ]
            self.Coeff.append(value)
            self.Coeff_error.append(error)
            self.total.append(sum(value))
            self.total_error.append(sum(error))
            self.residual.append(item.result.residual)
            self.chisq.append(item.result.chisqr)
        #print self.Coeff
        self.Coeff = numpy.transpose(numpy.array(self.Coeff))
        self.Coeff_error = numpy.transpose(numpy.array(self.Coeff_error))
        print "#" * 20, "\nFit Done"
Esempio n. 14
0
    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()