Changeset 299 for trunk/GSASIIpwd.py


Ignore:
Timestamp:
Jun 10, 2011 4:17:35 AM (12 years ago)
Author:
vondreele
Message:

Add progress bar to peak fit

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIpwd.py

    r296 r299  
    724724            print '%s'%(('Peak'+str(i+1)).center(8)),ptstr
    725725           
    726     def errPeakProfile(values, xdata, ydata, weights, parmdict, varylist,bakType):       
     726    def errPeakProfile(values, xdata, ydata, weights, parmdict, varylist,bakType,dlg):       
    727727        parmdict.update(zip(varylist,values))
    728         return np.sqrt(weights)*(ydata-getPeakProfile(parmdict,xdata,varylist,bakType))
     728        M = np.sqrt(weights)*(ydata-getPeakProfile(parmdict,xdata,varylist,bakType))
     729        Rwp = min(100.,np.sqrt(np.sum(M**2)/np.sum(weights*ydata**2))*100.)
     730        if dlg:
     731            dlg.Update(Rwp,newmsg='%s%8.3f%s'%('Peak fit Rwp =',Rwp,'%'))
     732        return M
    729733       
    730734    x,y,w,yc,yb,yd = data               #these are numpy arrays!
     
    743747        values =  np.array(ValuesOut(parmDict, varyList))
    744748        if FitPgm == 'LSQ':
    745             result = so.leastsq(errPeakProfile,values,
    746                 args=(x[xBeg:xFin],y[xBeg:xFin],w[xBeg:xFin],parmDict,varyList,bakType),full_output=True)
     749            dlg = wx.ProgressDialog('Residual','Peak fit Rwp = ',101.0,
     750            style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_REMAINING_TIME)
     751            screenSize = wx.ClientDisplayRect()
     752            Size = dlg.GetSize()
     753            dlg.SetPosition(wx.Point(screenSize[2]-Size[0]-305,screenSize[1]+5))
     754            try:
     755                result = so.leastsq(errPeakProfile,values,
     756                    args=(x[xBeg:xFin],y[xBeg:xFin],w[xBeg:xFin],parmDict,varyList,bakType,dlg),full_output=True)
     757            finally:
     758                dlg.Destroy()
    747759            runtime = time.time()-begin   
    748760            print 'Number of function calls:',result[2]['nfev'],' Number of observations: ',xFin-xBeg,' Number of parameters: ',len(varyList)
    749761            print "%s%8.3f%s " % ('fitpeak time =',runtime,'s')
    750762            ValuesIn(parmDict, varyList, result[0])
    751             chisq = np.sum(errPeakProfile(result[0],x[xBeg:xFin],y[xBeg:xFin],w[xBeg:xFin],parmDict,varyList,bakType)**2)
     763            chisq = np.sum(errPeakProfile(result[0],x[xBeg:xFin],y[xBeg:xFin],w[xBeg:xFin],parmDict,varyList,bakType,0)**2)
    752764            Rwp = np.sqrt(chisq/np.sum(w[xBeg:xFin]*y[xBeg:xFin]**2))*100.      #to %
    753765            GOF = chisq/(xFin-xBeg-len(varyList))
Note: See TracChangeset for help on using the changeset viewer.