Exemple #1
0
 def __replot__(self):
     xlim = pyplot.xlim()
     ylim = pyplot.ylim()
     pyplot.clf()
     # -- spectrum
     pyplot.plot(self.wlTable, self.spectrum, 'k')
     # -- continuum
     pyplot.plot(self.wlTable[self.whereCont],
                 self.spectrum[self.whereCont],
                 '.', color='orange', alpha=0.5)
     # -- model
     #print self.model
     pyplot.plot(self.wlTable,
                 dpfit.meta(self.wlTable, self.model),
                 color='red', linewidth=3, alpha=0.5)
     pyplot.xlim(xlim[0], xlim[1])
     pyplot.ylim(ylim[0], ylim[1])
     return
Exemple #2
0
 def __handler__(self, event):
     """
     React to a click of the mouse: will fit a line (Lorentzian) on
     the line. Private method, not to be called by the user.
     """
     if event.name=='button_press_event' and \
            event.button==1:
         # -- set first limit for fit
         self.wlMIN = event.xdata
        
     if event.name=='button_release_event' and \
            event.button==1: 
         # -- set second limit
         self.wlMAX = event.xdata
         # -- invert min and max if needed
         try:
             if self.wlMAX<self.wlMIN:
                 self.wlMIN, self.wlMAX = self.wlMAX, self.wlMIN
         except:
             pass
         if event.key==keyCont:
             # -- add range to continuum 
             self.whereCont.extend(np.where((self.wlTable<=self.wlMAX)*
                 (self.wlTable>=self.wlMIN))[0])
             self.__fitContinuum__()
             self.__replot__()
         elif event.key==keyGauss:
             # --    
             g = set(filter(lambda k: k.split(';')[0]=='gaussian',
                            self.model.keys()))
             N = str(len(g)/3+1)
             if self.wlMIN == self.wlMAX:
                 cont = dpfit.meta(event.xdata, self.model)
                 self.model['gaussian;'+N+':MU']=event.xdata
                 self.model['gaussian;'+N+':AMP']=event.ydata-cont
                 self.model['gaussian;'+N+':SIGMA']=1e-3*event.xdata
             else:
                 w = np.where((self.wlTable>=self.wlMIN)*
                             (self.wlTable<=self.wlMAX))
                 cont = dpfit.meta(self.wlTable[w].mean(), self.model)
                 self.model['gaussian;'+N+':MU']=self.wlTable[w].mean()
                 self.model['gaussian;'+N+':AMP']=self.spectrum[w].min()-cont
                 self.model['gaussian;'+N+':SIGMA']=(self.wlMAX-self.wlMIN)/2   
             self.__fitAll__()
             self.__replot__()
         elif event.key==keyLorent:
             # --    
             g = set(filter(lambda k: k.split(';')[0]=='lorentzian',
                            self.model.keys()))
             N = str(len(g)/3+1)
             if self.wlMIN == self.wlMAX:
                 cont = dpfit.meta(event.xdata, self.model)
                 self.model['lorentzian;'+N+':MU']=event.xdata
                 self.model['lorentzian;'+N+':AMP']=event.ydata-cont
                 self.model['lorentzian;'+N+':GAMMA']=1e-3*event.xdata
             else:
                 w = np.where((self.wlTable>=self.wlMIN)*
                             (self.wlTable<=self.wlMAX))
                 cont = dpfit.meta(self.wlTable[w].mean(), self.model)
                 self.model['lorentzian;'+N+':MU']=self.wlTable[w].mean()
                 self.model['lorentzian;'+N+':AMP']=self.spectrum[w].min()-cont
                 self.model['lorentzian;'+N+':GAMMA']=(self.wlMAX-self.wlMIN)/2
             self.__fitAll__()
             self.__replot__()
     return