Changeset 2049


Ignore:
Timestamp:
Nov 13, 2015 12:10:39 PM (8 years ago)
Author:
toby
Message:

Fix Todd's peakfit crash

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIpwd.py

    r2023 r2049  
    13241324    table as well as selected items in the background.
    13251325
    1326     :param str FitPgm: type of fit to perform. At present "LSQ" is the only
    1327       option that works
     1326    :param str FitPgm: type of fit to perform. At present this is ignored.
    13281327    :param list Peaks: a list of peaks. Each peak entry is a list with 8 values:
    13291328      four values followed by a refine flag where the values are: position, intensity,
     
    16131612        Rvals = {}
    16141613        badVary = []
    1615         if FitPgm == 'LSQ':
    1616             try:
    1617                 result = so.leastsq(errPeakProfile,values,Dfun=devPeakProfile,full_output=True,ftol=Ftol,col_deriv=True,
    1618                    args=(x[xBeg:xFin],y[xBeg:xFin],w[xBeg:xFin],dataType,parmDict,varyList,bakType,dlg))
    1619                 ncyc = int(result[2]['nfev']/2)
    1620             finally:
    1621                 if dlg: dlg.Destroy()
    1622             runtime = time.time()-begin   
    1623             chisq = np.sum(result[2]['fvec']**2)
    1624             Values2Dict(parmDict, varyList, result[0])
    1625             Rvals['Rwp'] = np.sqrt(chisq/np.sum(w[xBeg:xFin]*y[xBeg:xFin]**2))*100.      #to %
    1626             Rvals['GOF'] = chisq/(xFin-xBeg-len(varyList))       #reduced chi^2
    1627             print 'Number of function calls:',result[2]['nfev'],' Number of observations: ',xFin-xBeg,' Number of parameters: ',len(varyList)
    1628             if ncyc:
    1629                 print 'fitpeak time = %8.3fs, %8.3fs/cycle'%(runtime,runtime/ncyc)
    1630             print 'Rwp = %7.2f%%, chi**2 = %12.6g, reduced chi**2 = %6.2f'%(Rvals['Rwp'],chisq,Rvals['GOF'])
    1631             sig = [0]*len(varyList)
    1632             if len(varyList) == 0: break  # if nothing was refined
    1633             try:
    1634                 sig = np.sqrt(np.diag(result[1])*Rvals['GOF'])
    1635                 if np.any(np.isnan(sig)):
    1636                     print '*** Least squares aborted - some invalid esds possible ***'
    1637                 break                   #refinement succeeded - finish up!
    1638             except ValueError:          #result[1] is None on singular matrix
    1639                 print '**** Refinement failed - singular matrix ****'
    1640                 Ipvt = result[2]['ipvt']
    1641                 for i,ipvt in enumerate(Ipvt):
    1642                     if not np.sum(result[2]['fjac'],axis=1)[i]:
    1643                         print 'Removing parameter: ',varyList[ipvt-1]
    1644                         badVary.append(varyList[ipvt-1])
    1645                         del(varyList[ipvt-1])
    1646                         break
    1647                 else: # nothing removed
     1614        result = so.leastsq(errPeakProfile,values,Dfun=devPeakProfile,full_output=True,ftol=Ftol,col_deriv=True,
     1615               args=(x[xBeg:xFin],y[xBeg:xFin],w[xBeg:xFin],dataType,parmDict,varyList,bakType,dlg))
     1616        ncyc = int(result[2]['nfev']/2)
     1617        runtime = time.time()-begin   
     1618        chisq = np.sum(result[2]['fvec']**2)
     1619        Values2Dict(parmDict, varyList, result[0])
     1620        Rvals['Rwp'] = np.sqrt(chisq/np.sum(w[xBeg:xFin]*y[xBeg:xFin]**2))*100.      #to %
     1621        Rvals['GOF'] = chisq/(xFin-xBeg-len(varyList))       #reduced chi^2
     1622        print 'Number of function calls:',result[2]['nfev'],' Number of observations: ',xFin-xBeg,' Number of parameters: ',len(varyList)
     1623        if ncyc:
     1624            print 'fitpeak time = %8.3fs, %8.3fs/cycle'%(runtime,runtime/ncyc)
     1625        print 'Rwp = %7.2f%%, chi**2 = %12.6g, reduced chi**2 = %6.2f'%(Rvals['Rwp'],chisq,Rvals['GOF'])
     1626        sig = [0]*len(varyList)
     1627        if len(varyList) == 0: break  # if nothing was refined
     1628        try:
     1629            sig = np.sqrt(np.diag(result[1])*Rvals['GOF'])
     1630            if np.any(np.isnan(sig)):
     1631                print '*** Least squares aborted - some invalid esds possible ***'
     1632            break                   #refinement succeeded - finish up!
     1633        except ValueError:          #result[1] is None on singular matrix
     1634            print '**** Refinement failed - singular matrix ****'
     1635            Ipvt = result[2]['ipvt']
     1636            for i,ipvt in enumerate(Ipvt):
     1637                if not np.sum(result[2]['fjac'],axis=1)[i]:
     1638                    print 'Removing parameter: ',varyList[ipvt-1]
     1639                    badVary.append(varyList[ipvt-1])
     1640                    del(varyList[ipvt-1])
    16481641                    break
    1649         elif FitPgm == 'BFGS':
    1650             print 'Other program here'
    1651             return {}
    1652        
     1642            else: # nothing removed
     1643                break
     1644    if dlg: dlg.Destroy()
    16531645    sigDict = dict(zip(varyList,sig))
    16541646    yb[xBeg:xFin] = getBackground('',parmDict,bakType,dataType,x[xBeg:xFin])[0]
  • trunk/GSASIIpwdGUI.py

    r2024 r2049  
    424424       
    425425    def OnLSQPeakFit(event):
    426         if not G2frame.GSASprojectfile:            #force a save of the gpx file so SaveState can wirte in the same directory
     426        if not G2frame.GSASprojectfile:            #force a save of the gpx file so SaveState can write in the same directory
    427427            G2frame.OnFileSaveas(event)
    428428        OnPeakFit('LSQ')
Note: See TracChangeset for help on using the changeset viewer.