def onedfit(self, usemoments=True, annotate=True, vheight=True, height=0, negamp=None,**kwargs): self.ngauss = 1 self.auto = True self.setfitspec() if usemoments: # this can be done within gaussfit but I want to save them self.guesses = gaussfitter.onedmoments( self.specplotter.vind[self.gx1:self.gx2], self.spectofit[self.gx1:self.gx2], vheight=vheight,negamp=negamp,**kwargs) if vheight is False: self.guesses = [height]+self.guesses else: if negamp: self.guesses = [height,-1,0,1] else: self.guesses = [height,1,0,1] mpp,model,mpperr,chi2 = gaussfitter.onedgaussfit( self.specplotter.vind[self.gx1:self.gx2], self.spectofit[self.gx1:self.gx2], err=self.errspec[self.gx1:self.gx2], vheight=vheight, params=self.guesses, **self.fitkwargs) self.chi2 = chi2 self.dof = self.gx2-self.gx1-self.ngauss*3-vheight if vheight: self.specplotter.baseline.baselinepars = mpp[:1] # first item in list form self.model = model - mpp[0] else: self.model = model self.residuals = self.spectofit[self.gx1:self.gx2] - self.model self.modelpars = mpp[1:].tolist() self.modelerrs = mpperr[1:].tolist() self.modelplot = self.specplotter.axis.plot( self.specplotter.vind[self.gx1:self.gx2], self.model+self.specplotter.offset, color=self.fitcolor, linewidth=0.5) if annotate: self.annotate() if vheight: self.specplotter.baseline.annotate()
def onedfit(self, usemoments=True, annotate=True, vheight=True, height=0, negamp=None,**kwargs): self.ngauss = 1 self.auto = True self.setfitspec() if usemoments: # this can be done within gaussfit but I want to save them self.guesses = gaussfitter.onedmoments( self.specplotter.vind[self.gx1:self.gx2], self.spectofit[self.gx1:self.gx2], vheight=vheight,negamp=negamp,**kwargs) if vheight is False: self.guesses = [height]+self.guesses else: if negamp: self.guesses = [height,-1,0,1] else: self.guesses = [height,1,0,1] mpp,model,mpperr,chi2 = gaussfitter.onedgaussfit( self.specplotter.vind[self.gx1:self.gx2], self.spectofit[self.gx1:self.gx2], err=self.errspec[self.gx1:self.gx2], vheight=vheight, params=self.guesses, **self.fitkwargs) self.chi2 = chi2 self.dof = self.gx2-self.gx1-self.ngauss*3-vheight if vheight: self.specplotter.baseline.baselinepars = mpp[:1] # first item in list form self.model = model - mpp[0] else: self.model = model self.residuals = self.spectofit[self.gx1:self.gx2] - self.model self.modelpars = mpp[1:].tolist() self.modelerrs = mpperr[1:].tolist() self.modelplot = self.specplotter.axis.plot( self.specplotter.vind[self.gx1:self.gx2], self.model+self.specplotter.offset, color=self.fitcolor, linewidth=0.5) if annotate: self.annotate() if vheight: self.specplotter.baseline.annotate()
def selectregion(self,event): if self.nclicks_b1 == 0: self.gx1 = argmin(abs(event.xdata-self.specplotter.vind)) self.nclicks_b1 += 1 elif self.nclicks_b1 == 1: self.gx2 = argmin(abs(event.xdata-self.specplotter.vind)) self.nclicks_b1 -= 1 if self.gx1 > self.gx2: self.gx1,self.gx2 = self.gx2,self.gx1 if abs(self.gx1-self.gx2) > 3: # can't fit w/ fewer data than pars self.fitregion = self.specplotter.axis.plot( self.specplotter.vind[self.gx1:self.gx2], self.specplotter.spectrum[self.gx1:self.gx2]+self.specplotter.offset, drawstyle='steps-mid', color='c') if self.guesses == []: self.guesses = gaussfitter.onedmoments( self.specplotter.vind[self.gx1:self.gx2], self.spectofit[self.gx1:self.gx2], vheight=0) self.ngauss = 1 self.auto = True else: print "Fitting region is too small (channels %i:%i). Try again." % (self.gx1,self.gx2)
def selectregion(self,event): if self.nclicks_b1 == 0: self.gx1 = argmin(abs(event.xdata-self.specplotter.vind)) self.nclicks_b1 += 1 elif self.nclicks_b1 == 1: self.gx2 = argmin(abs(event.xdata-self.specplotter.vind)) self.nclicks_b1 -= 1 if self.gx1 > self.gx2: self.gx1,self.gx2 = self.gx2,self.gx1 if abs(self.gx1-self.gx2) > 3: # can't fit w/ fewer data than pars self.fitregion = self.specplotter.axis.plot( self.specplotter.vind[self.gx1:self.gx2], self.specplotter.spectrum[self.gx1:self.gx2]+self.specplotter.offset, drawstyle='steps-mid', color='c') if self.guesses == []: self.guesses = gaussfitter.onedmoments( self.specplotter.vind[self.gx1:self.gx2], self.spectofit[self.gx1:self.gx2], vheight=0) self.ngauss = 1 self.auto = True else: print("Fitting region is too small (channels %i:%i). Try again." % (self.gx1,self.gx2))