Changeset 2698 for trunk


Ignore:
Timestamp:
Feb 10, 2017 12:30:28 PM (8 years ago)
Author:
vondreele
Message:

work over sequentia fit stuff - allow all parameters shown in table to be used in pseudoVariables & in fit equations.
Allow for gaps in columns
Sequential results can be accumulated
Allow for not used results & gaps in column averages

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/GSASIIgrid.py

    r2697 r2698  
    2424import random as ran
    2525import numpy as np
     26import numpy.ma as ma
    2627import scipy.optimize as so
    2728import GSASIIpath
     
    30063007        'average the selected columns from menu command'
    30073008        cols = sorted(G2frame.dataDisplay.GetSelectedCols()) # ignore selection order
     3009        useCol = -np.array(G2frame.SeqTable.GetColValues(0),dtype=bool)
    30083010        if cols:
    30093011            for col in cols:
    3010                 ave = np.mean(GetColumnInfo(col)[1])
    3011                 sig = np.std(GetColumnInfo(col)[1])
     3012                items = GetColumnInfo(col)[1]
     3013                noneMask = np.array([item is None for item in items])
     3014                info = ma.array(items,mask=useCol+noneMask)
     3015                ave = ma.mean(ma.compressed(info))
     3016                sig = ma.std(ma.compressed(info))
    30123017                print ' Average for '+G2frame.SeqTable.GetColLabelValue(col)+': '+'%.6g'%(ave)+' +/- '+'%.6g'%(sig)
    30133018        else:
     
    34373442        for calcobj in calcObjList:
    34383443            calcobj.UpdateVars(varyList,Values)
    3439             result.append((calcobj.depVal-calcobj.EvalExpression())/calcobj.depSig)
     3444            if calcobj.depSig:
     3445                result.append((calcobj.depVal-calcobj.EvalExpression())/calcobj.depSig)
     3446            else:
     3447                result.append(calcobj.depVal-calcobj.EvalExpression())
    34403448        return result
    34413449
     
    34693477                calcobj.SetupCalc(indepVarDict)               
    34703478                # values and sigs for current value of dependent var
     3479                if row[indx] is None: continue
    34713480                calcobj.depVal = row[indx]
    34723481                calcobj.depSig = G2frame.colSigs[indx][j]
     
    34803489        try:
    34813490            result = so.leastsq(ParEqEval,varyValues,full_output=True,   #ftol=Ftol,
    3482                                 args=(calcObjList,varyList)
    3483                                 )
     3491                args=(calcObjList,varyList))
    34843492            values = result[0]
    34853493            covar = result[1]
    34863494            if covar is None:
    34873495                raise Exception
     3496            chisq = np.sum(result[2]['fvec']**2)
     3497            GOF = np.sqrt(chisq/(len(calcObjList)-len(varyList)))
    34883498            esdDict = {}
    34893499            for i,avar in enumerate(varyList):
     
    34933503            return
    34943504        print('==== Fit Results ====')
     3505        print '  chisq =  %.2f, GOF = %.2f'%(chisq,GOF)
    34953506        for obj in eqObjList:
    34963507            obj.UpdateVariedVars(varyList,values)
     
    35163527            fitvals = []
    35173528            for j,row in enumerate(zip(*G2frame.colList)):
    3518                 calcobj.SetupCalc(
    3519                     {var:row[i] for i,var in enumerate(colLabels) if var in indepVars}
    3520                     )
     3529                calcobj.SetupCalc({var:row[i] for i,var in enumerate(colLabels) if var in indepVars})
    35213530                fitvals.append(calcobj.EvalExpression())
    35223531            G2plt.PlotSelectedSequence(G2frame,[indx],GetColumnInfo,SelectXaxis,fitnum,fitvals)
     
    35503559                header='Edit equation')
    35513560        if selected is not None:
    3552             dlg = G2exG.ExpressionDialog(
    3553                 G2frame.dataDisplay,indepVarDict,
    3554                 data['SeqParFitEqList'][selected],
    3555                 depVarDict=depVarDict,
     3561            dlg = G2exG.ExpressionDialog(G2frame.dataDisplay,VarDict,
     3562                data['SeqParFitEqList'][selected],depVarDict=VarDict,
    35563563                header="Edit the formula for this minimization function",
    35573564                ExtraButton=['Fit',SingleParEqFit])
     
    35713578                if obj.freeVars[var][0] not in usedvarlist: usedvarlist.append(obj.freeVars[var][0])
    35723579
    3573         dlg = G2exG.ExpressionDialog(G2frame.dataDisplay,parmDict,depVarDict=depVarDict,
     3580        dlg = G2exG.ExpressionDialog(G2frame.dataDisplay,VarDict,depVarDict=VarDict,
    35743581            header='Define an equation to minimize in the parametric fit',
    35753582            ExtraButton=['Fit',SingleParEqFit],usedVars=usedvarlist)
     
    36023609                newEqn.freeVars[var][0] = G2obj.MakeUniqueLabel(newEqn.freeVars[var][0],usedvarlist)
    36033610            dlg = G2exG.ExpressionDialog(
    3604                 G2frame.dataDisplay,indepVarDict,
    3605                 newEqn,
    3606                 depVarDict=depVarDict,
     3611                G2frame.dataDisplay,VarDict,newEqn,depVarDict=VarDict,
    36073612                header="Edit the formula for this minimization function",
    36083613                ExtraButton=['Fit',SingleParEqFit])
     
    36793684    data['variableLabels'] = variableLabels
    36803685    Histograms,Phases = G2frame.GetUsedHistogramsAndPhasesfromTree()
    3681 #    Controls = G2frame.PatternTree.GetItemPyData(GetPatternTreeItemId(G2frame,G2frame.root,'Controls'))
     3686    Controls = G2frame.PatternTree.GetItemPyData(GetPatternTreeItemId(G2frame,G2frame.root,'Controls'))
    36823687    # create a place to store Pseudo Vars & Parametric Fit functions, if not present
    36833688    if 'SeqPseudoVars' not in data: data['SeqPseudoVars'] = {}
     
    38203825        Types += [wg.GRID_VALUE_FLOAT+':10,3',]
    38213826    # add % change in Chi^2 in last cycle
    3822     if histNames[0][:4] not in ['SASD','IMG '] and data.get('ShowCell'):
     3827    if histNames[0][:4] not in ['SASD','IMG '] and Controls.get('ShowCell'):
    38233828        G2frame.colList += [[100.*data[name]['Rvals'].get('DelChi2',-1) for name in histNames]]
    38243829        G2frame.colSigs += [None]
     
    38363841        sampleDict[name] = dict(zip(sampleParms.keys(),[sampleParms[key][i] for key in sampleParms.keys()]))
    38373842    # add unique cell parameters TODO: review this where the cell symmetry changes (when possible)
    3838     if data.get('ShowCell',False):
     3843    if Controls.get('ShowCell',False):
    38393844        for pId in sorted(RecpCellTerms):
    38403845            pfx = str(pId)+'::' # prefix for A values from phase
     
    40134018    PSvarDict.update(sampleParms)
    40144019    UpdateParmDict(PSvarDict)
    4015     # Also dicts of dependent (depVarDict) & independent vars (indepVarDict)
     4020    # Also dicts of variables
    40164021    # for Parametric fitting from the data table
    40174022    parmDict = dict(zip(colLabels,zip(*G2frame.colList)[0])) # scratch dict w/all values in table
     
    40244029    # this does not work for refinements that have differing numbers of variables.
    40254030    #raise Exception
    4026     indepVarDict = {}     #  values in table w/o ESDs
    4027     depVarDict = {}
     4031    VarDict = {}
    40284032    for i,var in enumerate(colLabels):
    4029         if var == 'Use': continue
     4033        if var in ['Use','Rwp',u'\u0394\u03C7\u00B2 (%)']: continue
    40304034        if G2frame.colList[i][0] is None:
    40314035            val,sig = firstValueDict.get(var,[None,None])
     
    40344038        else:
    40354039            val,sig = G2frame.colList[i][0],None
    4036         if val is None:
    4037             continue
     4040        if val is None: continue
    40384041        elif sig is None or sig == 0.:
    4039             indepVarDict[var] = val
     4042            VarDict[var] = val
    40404043        elif striphist(var) not in Dlookup:
    4041             depVarDict[var] = val
     4044            VarDict[var] = val
    40424045    # add recip cell coeff. values
    4043     depVarDict.update({var:val for var,val in data[name].get('newCellDict',{}).values()})
     4046    VarDict.update({var:val for var,val in data[name].get('newCellDict',{}).values()})
    40444047
    40454048    G2frame.dataFrame.currentGrids = []
  • TabularUnified trunk/GSASIIobj.py

    r2695 r2698  
    878878    'FreePrm2':'Sample voltage (V)',
    879879    'FreePrm3':'Applied load (MN)',
    880     'SeqPseudoVars':{},'SeqParFitEqList':[],'ShowCell':False,
     880    'ShowCell':False,
    881881    }
    882882'''Values to be used as defaults for the initial contents of the ``Controls``
  • TabularUnified trunk/GSASIIpwdGUI.py

    r2697 r2698  
    552552        dlg = wx.ProgressDialog('Sequential peak fit','Data set name = '+names[0],len(names),
    553553            style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_REMAINING_TIME|wx.PD_CAN_ABORT)
    554         Controls = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.root, 'Controls'))
    555554        controls = {'deriv type':'analytic','min dM/M':0.0001,}
    556         Controls['ShowCell'] = False
    557555        print 'Peak Fitting with '+controls['deriv type']+' derivatives:'
    558556        oneCycle = False
  • TabularUnified trunk/GSASIIstrIO.py

    r2658 r2698  
    545545           
    546546    print 'GPX file save successful'
     547   
     548def GetSeqResult(GPXfile):
     549    '''
     550    Needs doc string
     551   
     552    :param str GPXfile: full .gpx file name
     553    '''
     554    fl = open(GPXfile,'rb')
     555    SeqResult = {}
     556    while True:
     557        try:
     558            data = cPickle.load(fl)
     559        except EOFError:
     560            break
     561        datum = data[0]
     562        if datum[0] == 'Sequential results':
     563            SeqResult = datum[1]
     564    fl.close()
     565    return SeqResult
    547566   
    548567def SetSeqResult(GPXfile,Histograms,SeqResult):
  • TabularUnified trunk/GSASIIstrMain.py

    r2557 r2698  
    280280    if Controls.get('Reverse Seq'):
    281281        histNames.reverse()
    282     SeqResult = {}
     282    SeqResult = G2stIO.GetSeqResult(GPXfile)
     283#    SeqResult = {'SeqPseudoVars':{},'SeqParFitEqList':[]}
    283284    makeBack = True
    284285    Histo = {}
Note: See TracChangeset for help on using the changeset viewer.