Changeset 3068


Ignore:
Timestamp:
Sep 12, 2017 10:54:45 AM (4 years ago)
Author:
vondreele
Message:

fix parameter display to show nan (crashed before)
trap with error if any parameter is nan
skip postprocessing for failed refinements (IfOK=False)
fix Jacobian to use GetProfileDervMP

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIpy3.py

    r2574 r3068  
    142142            return '0.0'
    143143    # negative numbers, leave room for a sign
    144     if val < 0: maxdigits -= 1
     144    if np.isnan(val):
     145        return str(val)
     146    if val < 0: maxdigits -= 1       
    145147    if abs(val) < 1e-99 or abs(val) > 9.999e99:
    146148        decimals = min(maxdigits-6,sigfigs)
     
    156158        fmt = "{" + (":{:d}.{:d}g".format(maxdigits,decimals))+"}"
    157159    elif abs(val) < 1: # small numbers, add to decimal places
    158         decimals = sigfigs - int(np.log10(abs(val)))
     160        decimals = sigfigs - int(np.log10(np.abs(val)))
    159161        fmt = "{" + (":{:d}.{:d}f".format(maxdigits,decimals))+"}"
    160162    else: # larger numbers, remove decimal places
    161         decimals = sigfigs - 1 - int(np.log10(abs(val)))
     163        decimals = sigfigs - 1 - int(np.log10(np.abs(val)))
    162164        if decimals <= 0:
    163165            fmt = "{" + (":{:d}.0f".format(maxdigits))+"}."
  • trunk/GSASIIstrMain.py

    r3049 r3068  
    5454        begin = time.time()
    5555        values =  np.array(G2stMth.Dict2Values(parmDict, varyList))
     56        if np.any(np.isnan(values)):
     57            raise G2obj.G2Exception('ERROR - nan found in LS parameters - use Calculate/View LS parms to locate')
    5658        # test code to compute GOF and save for external repeat
    5759        #args = ([Histograms,Phases,restraintDict,rigidbodyDict],parmDict,varyList,calcControls,pawleyLookup,dlg)
     
    135137                        del(varyList[ipvt-1])
    136138                        break
    137     G2stMth.GetFobsSq(Histograms,Phases,parmDict,calcControls)
     139    if IfOK:
     140        G2stMth.GetFobsSq(Histograms,Phases,parmDict,calcControls)
    138141    return IfOK,Rvals,result,covMatrix,sig
    139142
     
    212215        IfOK,Rvals,result,covMatrix,sig = RefineCore(Controls,Histograms,Phases,restraintDict,
    213216            rigidbodyDict,parmDict,varyList,calcControls,pawleyLookup,ifPrint,printFile,dlg)
    214         sigDict = dict(zip(varyList,sig))
    215         newCellDict = G2stMth.GetNewCellParms(parmDict,varyList)
    216         newAtomDict = G2stMth.ApplyXYZshifts(parmDict,varyList)
    217         covData = {'variables':result[0],'varyList':varyList,'sig':sig,'Rvals':Rvals,
    218                    'varyListStart':varyListStart,
    219                    'covMatrix':covMatrix,'title':GPXfile,'newAtomDict':newAtomDict,
    220                    'newCellDict':newCellDict,'freshCOV':True}
    221         # add the uncertainties into the esd dictionary (sigDict)
    222         sigDict.update(G2mv.ComputeDepESD(covMatrix,varyList,parmDict))
    223         G2mv.PrintIndependentVars(parmDict,varyList,sigDict,pFile=printFile)
    224         G2stMth.ApplyRBModels(parmDict,Phases,rigidbodyDict,True)
    225         G2stIO.SetRigidBodyModels(parmDict,sigDict,rigidbodyDict,printFile)
    226         G2stIO.SetPhaseData(parmDict,sigDict,Phases,rbIds,covData,restraintDict,printFile)
    227         G2stIO.SetHistogramPhaseData(parmDict,sigDict,Phases,Histograms,calcControls['FFtables'],pFile=printFile)
    228         G2stIO.SetHistogramData(parmDict,sigDict,Histograms,calcControls['FFtables'],pFile=printFile)
    229         G2stIO.SetUsedHistogramsAndPhases(GPXfile,Histograms,Phases,rigidbodyDict,covData,makeBack)
    230         printFile.close()
    231         print ' Refinement results are in file: '+ospath.splitext(GPXfile)[0]+'.lst'
    232         print ' ***** Refinement successful *****'
     217        if IfOK:
     218            sigDict = dict(zip(varyList,sig))
     219            newCellDict = G2stMth.GetNewCellParms(parmDict,varyList)
     220            newAtomDict = G2stMth.ApplyXYZshifts(parmDict,varyList)
     221            covData = {'variables':result[0],'varyList':varyList,'sig':sig,'Rvals':Rvals,
     222                       'varyListStart':varyListStart,
     223                       'covMatrix':covMatrix,'title':GPXfile,'newAtomDict':newAtomDict,
     224                       'newCellDict':newCellDict,'freshCOV':True}
     225            # add the uncertainties into the esd dictionary (sigDict)
     226            sigDict.update(G2mv.ComputeDepESD(covMatrix,varyList,parmDict))
     227            G2mv.PrintIndependentVars(parmDict,varyList,sigDict,pFile=printFile)
     228            G2stMth.ApplyRBModels(parmDict,Phases,rigidbodyDict,True)
     229            G2stIO.SetRigidBodyModels(parmDict,sigDict,rigidbodyDict,printFile)
     230            G2stIO.SetPhaseData(parmDict,sigDict,Phases,rbIds,covData,restraintDict,printFile)
     231            G2stIO.SetHistogramPhaseData(parmDict,sigDict,Phases,Histograms,calcControls['FFtables'],pFile=printFile)
     232            G2stIO.SetHistogramData(parmDict,sigDict,Histograms,calcControls['FFtables'],pFile=printFile)
     233            G2stIO.SetUsedHistogramsAndPhases(GPXfile,Histograms,Phases,rigidbodyDict,covData,makeBack)
     234            printFile.close()
     235            print ' Refinement results are in file: '+ospath.splitext(GPXfile)[0]+'.lst'
     236            print ' ***** Refinement successful *****'
     237        else:
     238            print '****ERROR - Refinement failed'
     239            raise G2obj.G2Exception('****ERROR - Refinement failed')
    233240    except G2obj.G2Exception,Msg:
    234241        printFile.close()
     
    236243
    237244#for testing purposes!!!
    238     if DEBUG:
     245    if DEBUG and IfOK:
    239246#needs: values,HistoPhases,parmDict,varylist,calcControls,pawleyLookup
    240247        import cPickle
  • trunk/GSASIIstrMath.py

    r3048 r3068  
    40704070            xB = np.searchsorted(x,Limits[0])
    40714071            xF = np.searchsorted(x,Limits[1])+1
    4072             dMdvh = np.sqrt(w[xB:xF])*getPowderProfileDerv(parmDict,x[xB:xF],
    4073                 varylist,Histogram,Phases,rigidbodyDict,calcControls,pawleyLookup,dependentVars)
     4072            dMdvh = np.sqrt(w[xB:xF])*getPowderProfileDervMP([parmDict,x[xB:xF],
     4073                varylist,Histogram,Phases,rigidbodyDict,calcControls,pawleyLookup,dependentVars])
    40744074        elif 'HKLF' in histogram[:4]:
    40754075            Histogram = Histograms[histogram]
Note: See TracChangeset for help on using the changeset viewer.