Changeset 2697


Ignore:
Timestamp:
Feb 9, 2017 1:40:39 PM (7 years ago)
Author:
vondreele
Message:

put colList for seqTable in G2frame it has persistence when plot is revised
put SeqPseudoVars? & SeqParFitEqList? in data (SeqResult?) so are local to each type of sequential result. Remove from Controls except for seqRefine (this may change).
Use parmDict instead of indepVarDict in AddNewParFitEqList? - allows more choice of parameters for functions
clear both SeqPseudoVars? & SeqParFitEqList? for a new sequential fit

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIgrid.py

    r2696 r2697  
    29312931              * 'newCellDict' - refined cell parameters after shifts to A0-A5 from Dij terms applied'
    29322932    """
    2933     ''' there is an issue here: #TODO move stuff from Controls to the specific SeqData tree entry (e.g. use data instead of Controls)
    2934         make SeqData creation save old pseudoVars, etc. in the various places it is rebuilt
    2935         check validity of pseudoVars, ect. against current variable set
    2936     '''
    29372933    def GetSampleParms():
    2938         '''Make a dictionary of the sample parameters are not the same over the
    2939         refinement series.
     2934        '''Make a dictionary of the sample parameters that are not the same over the
     2935        refinement series. Controls here is local
    29402936        '''
    29412937        if 'IMG' in histNames[0]:
     
    29752971        plotName = variableLabels.get(colName,colName)
    29762972        plotName = plotSpCharFix(plotName)
    2977         return plotName,colList[col],colSigs[col]
     2973        return plotName,G2frame.colList[col],G2frame.colSigs[col]
    29782974           
    29792975    def PlotSelect(event):
     
    31813177    def EnablePseudoVarMenus():
    31823178        'Enables or disables the PseudoVar menu items that require existing defs'
    3183         if Controls['SeqPseudoVars']:
     3179        if data['SeqPseudoVars']:
    31843180            val = True
    31853181        else:
     
    31903186    def DelPseudoVar(event):
    31913187        'Ask the user to select a pseudo var expression to delete'
    3192         choices = Controls['SeqPseudoVars'].keys()
     3188        choices = data['SeqPseudoVars'].keys()
    31933189        selected = G2G.ItemSelector(
    31943190            choices,G2frame.dataFrame,
     
    31983194        if selected is None: return
    31993195        for item in selected:
    3200             del Controls['SeqPseudoVars'][choices[item]]
     3196            del data['SeqPseudoVars'][choices[item]]
    32013197        if selected:
    32023198            UpdateSeqResults(G2frame,data,G2frame.dataDisplay.GetSize()) # redisplay variables
     
    32043200    def EditPseudoVar(event):
    32053201        'Edit an existing pseudo var expression'
    3206         choices = Controls['SeqPseudoVars'].keys()
     3202        choices = data['SeqPseudoVars'].keys()
    32073203        if len(choices) == 1:
    32083204            selected = 0
     
    32163212            dlg = G2exG.ExpressionDialog(
    32173213                G2frame.dataDisplay,PSvarDict,
    3218                 Controls['SeqPseudoVars'][choices[selected]],
     3214                data['SeqPseudoVars'][choices[selected]],
    32193215                header="Edit the PseudoVar expression",
    32203216                VarLabel="PseudoVar #"+str(selected+1),
     
    32233219            if newobj:
    32243220                calcobj = G2obj.ExpressionCalcObj(newobj)
    3225                 del Controls['SeqPseudoVars'][choices[selected]]
    3226                 Controls['SeqPseudoVars'][calcobj.eObj.expression] = newobj
     3221                del data['SeqPseudoVars'][choices[selected]]
     3222                data['SeqPseudoVars'][calcobj.eObj.expression] = newobj
    32273223                UpdateSeqResults(G2frame,data,G2frame.dataDisplay.GetSize()) # redisplay variables
    32283224       
    32293225    def AddNewPseudoVar(event):
    32303226        'Create a new pseudo var expression'
    3231         dlg = G2exG.ExpressionDialog(
    3232             G2frame.dataDisplay,PSvarDict,
     3227        dlg = G2exG.ExpressionDialog(G2frame.dataDisplay,PSvarDict,
    32333228            header='Enter an expression for a PseudoVar here',
    3234             VarLabel = "New PseudoVar",
    3235             fit=False)
     3229            VarLabel = "New PseudoVar",fit=False)
    32363230        obj = dlg.Show(True)
    32373231        dlg.Destroy()
    32383232        if obj:
    32393233            calcobj = G2obj.ExpressionCalcObj(obj)
    3240             Controls['SeqPseudoVars'][calcobj.eObj.expression] = obj
     3234            data['SeqPseudoVars'][calcobj.eObj.expression] = obj
    32413235            UpdateSeqResults(G2frame,data,G2frame.dataDisplay.GetSize()) # redisplay variables
    32423236           
     
    32793273        dlg.Destroy()
    32803274        if obj:
    3281             Controls['SeqPseudoVars'][obj.expression] = obj
     3275            data['SeqPseudoVars'][obj.expression] = obj
    32823276            UpdateSeqResults(G2frame,data,G2frame.dataDisplay.GetSize()) # redisplay variables
    32833277
     
    33273321        dlg.Destroy()
    33283322        if obj:
    3329             Controls['SeqPseudoVars'][obj.expression] = obj
     3323            data['SeqPseudoVars'][obj.expression] = obj
    33303324            UpdateSeqResults(G2frame,data,G2frame.dataDisplay.GetSize()) # redisplay variables
    33313325           
     
    34253419    def EnableParFitEqMenus():
    34263420        'Enables or disables the Parametric Fit menu items that require existing defs'
    3427         if Controls['SeqParFitEqList']:
     3421        if data['SeqParFitEqList']:
    34283422            val = True
    34293423        else:
     
    34533447            eqObjList = [eqObj,]
    34543448        else:
    3455             eqObjList = Controls['SeqParFitEqList']
     3449            eqObjList = data['SeqParFitEqList']
    34563450        UseFlags = G2frame.SeqTable.GetColValues(0)         
    34573451        for obj in eqObjList:
     
    34673461            indepVars = obj.GetIndependentVars()
    34683462            # loop over each datapoint
    3469             for j,row in enumerate(zip(*colList)):
     3463            for j,row in enumerate(zip(*G2frame.colList)):
    34703464                if not UseFlags[j]: continue
    34713465                # assemble equations to fit
     
    34763470                # values and sigs for current value of dependent var
    34773471                calcobj.depVal = row[indx]
    3478                 calcobj.depSig = colSigs[indx][j]
     3472                calcobj.depSig = G2frame.colSigs[indx][j]
    34793473                calcObjList.append(calcobj)
    34803474        # varied parameters
     
    35213515            # loop over each datapoint
    35223516            fitvals = []
    3523             for j,row in enumerate(zip(*colList)):
     3517            for j,row in enumerate(zip(*G2frame.colList)):
    35243518                calcobj.SetupCalc(
    35253519                    {var:row[i] for i,var in enumerate(colLabels) if var in indepVars}
    35263520                    )
    35273521                fitvals.append(calcobj.EvalExpression())
    3528             G2plt.PlotSelectedSequence(
    3529                 G2frame,[indx],GetColumnInfo,SelectXaxis,
    3530                 fitnum,fitvals)
     3522            G2plt.PlotSelectedSequence(G2frame,[indx],GetColumnInfo,SelectXaxis,fitnum,fitvals)
    35313523
    35323524    def SingleParEqFit(eqObj):
     
    35353527    def DelParFitEq(event):
    35363528        'Ask the user to select function to delete'
    3537         txtlst = [obj.GetDepVar()+' = '+obj.expression for obj in Controls['SeqParFitEqList']]
     3529        txtlst = [obj.GetDepVar()+' = '+obj.expression for obj in data['SeqParFitEqList']]
    35383530        selected = G2G.ItemSelector(
    35393531            txtlst,G2frame.dataFrame,
     
    35423534            header='Delete equation')
    35433535        if selected is None: return
    3544         Controls['SeqParFitEqList'] = [obj for i,obj in enumerate(Controls['SeqParFitEqList']) if i not in selected]
     3536        data['SeqParFitEqList'] = [obj for i,obj in enumerate(data['SeqParFitEqList']) if i not in selected]
    35453537        EnableParFitEqMenus()
    3546         if Controls['SeqParFitEqList']: DoParEqFit(event)
     3538        if data['SeqParFitEqList']: DoParEqFit(event)
    35473539       
    35483540    def EditParFitEq(event):
    35493541        'Edit an existing parametric equation'
    3550         txtlst = [obj.GetDepVar()+' = '+obj.expression for obj in Controls['SeqParFitEqList']]
     3542        txtlst = [obj.GetDepVar()+' = '+obj.expression for obj in data['SeqParFitEqList']]
    35513543        if len(txtlst) == 1:
    35523544            selected = 0
     
    35603552            dlg = G2exG.ExpressionDialog(
    35613553                G2frame.dataDisplay,indepVarDict,
    3562                 Controls['SeqParFitEqList'][selected],
     3554                data['SeqParFitEqList'][selected],
    35633555                depVarDict=depVarDict,
    35643556                header="Edit the formula for this minimization function",
     
    35663558            newobj = dlg.Show(True)
    35673559            if newobj:
    3568                 Controls['SeqParFitEqList'][selected] = newobj
     3560                data['SeqParFitEqList'][selected] = newobj
    35693561                EnableParFitEqMenus()
    3570             if Controls['SeqParFitEqList']: DoParEqFit(event)
     3562            if data['SeqParFitEqList']: DoParEqFit(event)
    35713563
    35723564    def AddNewParFitEq(event):
     
    35753567        # compile the variable names used in previous freevars to avoid accidental name collisions
    35763568        usedvarlist = []
    3577         for obj in Controls['SeqParFitEqList']:
     3569        for obj in data['SeqParFitEqList']:
    35783570            for var in obj.freeVars:
    35793571                if obj.freeVars[var][0] not in usedvarlist: usedvarlist.append(obj.freeVars[var][0])
    35803572
    3581         dlg = G2exG.ExpressionDialog(
    3582             G2frame.dataDisplay,indepVarDict,
    3583             depVarDict=depVarDict,
     3573        dlg = G2exG.ExpressionDialog(G2frame.dataDisplay,parmDict,depVarDict=depVarDict,
    35843574            header='Define an equation to minimize in the parametric fit',
    3585             ExtraButton=['Fit',SingleParEqFit],
    3586             usedVars=usedvarlist)
     3575            ExtraButton=['Fit',SingleParEqFit],usedVars=usedvarlist)
    35873576        obj = dlg.Show(True)
    35883577        dlg.Destroy()
    35893578        if obj:
    3590             Controls['SeqParFitEqList'].append(obj)
     3579            data['SeqParFitEqList'].append(obj)
    35913580            EnableParFitEqMenus()
    3592             if Controls['SeqParFitEqList']: DoParEqFit(event)
     3581            if data['SeqParFitEqList']: DoParEqFit(event)
    35933582               
    35943583    def CopyParFitEq(event):
     
    35963585        # compile the variable names used in previous freevars to avoid accidental name collisions
    35973586        usedvarlist = []
    3598         for obj in Controls['SeqParFitEqList']:
     3587        for obj in data['SeqParFitEqList']:
    35993588            for var in obj.freeVars:
    36003589                if obj.freeVars[var][0] not in usedvarlist: usedvarlist.append(obj.freeVars[var][0])
    3601         txtlst = [obj.GetDepVar()+' = '+obj.expression for obj in Controls['SeqParFitEqList']]
     3590        txtlst = [obj.GetDepVar()+' = '+obj.expression for obj in data['SeqParFitEqList']]
    36023591        if len(txtlst) == 1:
    36033592            selected = 0
     
    36093598                header='Copy equation')
    36103599        if selected is not None:
    3611             newEqn = copy.deepcopy(Controls['SeqParFitEqList'][selected])
     3600            newEqn = copy.deepcopy(data['SeqParFitEqList'][selected])
    36123601            for var in newEqn.freeVars:
    36133602                newEqn.freeVars[var][0] = G2obj.MakeUniqueLabel(newEqn.freeVars[var][0],usedvarlist)
     
    36203609            newobj = dlg.Show(True)
    36213610            if newobj:
    3622                 Controls['SeqParFitEqList'].append(newobj)
     3611                data['SeqParFitEqList'].append(newobj)
    36233612                EnableParFitEqMenus()
    3624             if Controls['SeqParFitEqList']: DoParEqFit(event)
     3613            if data['SeqParFitEqList']: DoParEqFit(event)
    36253614                                           
    36263615    def GridSetToolTip(row,col):
     
    36283617        as a tooltip
    36293618        '''
    3630         if colSigs[col]:
    3631             return u'\u03c3 = '+str(colSigs[col][row])
     3619        if G2frame.colSigs[col]:
     3620            return u'\u03c3 = '+str(G2frame.colSigs[col][row])
    36323621        return ''
    36333622       
     
    36903679    data['variableLabels'] = variableLabels
    36913680    Histograms,Phases = G2frame.GetUsedHistogramsAndPhasesfromTree()
    3692     Controls = G2frame.PatternTree.GetItemPyData(GetPatternTreeItemId(G2frame,G2frame.root,'Controls'))
     3681#    Controls = G2frame.PatternTree.GetItemPyData(GetPatternTreeItemId(G2frame,G2frame.root,'Controls'))
    36933682    # create a place to store Pseudo Vars & Parametric Fit functions, if not present
    3694     if 'SeqPseudoVars' not in Controls: Controls['SeqPseudoVars'] = {}
    3695     if 'SeqParFitEqList' not in Controls: Controls['SeqParFitEqList'] = []
     3683    if 'SeqPseudoVars' not in data: data['SeqPseudoVars'] = {}
     3684    if 'SeqParFitEqList' not in data: data['SeqParFitEqList'] = []
    36963685    histNames = data['histNames']
    36973686    if G2frame.dataDisplay:
     
    38203809    histNames = foundNames
    38213810    nRows = len(histNames)
    3822     colList = [nRows*[True]]
    3823     colSigs = [None]
     3811    G2frame.colList = [nRows*[True]]
     3812    G2frame.colSigs = [None]
    38243813    colLabels = ['Use']
    38253814    Types = [wg.GRID_VALUE_BOOL]
    38263815    # start with Rwp values
    38273816    if 'IMG ' not in histNames[0][:4]:
    3828         colList += [[data[name]['Rvals']['Rwp'] for name in histNames]]
    3829         colSigs += [None]
     3817        G2frame.colList += [[data[name]['Rvals']['Rwp'] for name in histNames]]
     3818        G2frame.colSigs += [None]
    38303819        colLabels += ['Rwp']
    38313820        Types += [wg.GRID_VALUE_FLOAT+':10,3',]
    38323821    # add % change in Chi^2 in last cycle
    3833     if histNames[0][:4] not in ['SASD','IMG '] and Controls.get('ShowCell'):
    3834         colList += [[100.*data[name]['Rvals'].get('DelChi2',-1) for name in histNames]]
    3835         colSigs += [None]
     3822    if histNames[0][:4] not in ['SASD','IMG '] and data.get('ShowCell'):
     3823        G2frame.colList += [[100.*data[name]['Rvals'].get('DelChi2',-1) for name in histNames]]
     3824        G2frame.colSigs += [None]
    38363825        colLabels += [u'\u0394\u03C7\u00B2 (%)']
    38373826        Types += [wg.GRID_VALUE_FLOAT,]
     
    38393828    # add changing sample parameters to table
    38403829    for key in sampleParms:
    3841         colList += [sampleParms[key]]
    3842         colSigs += [None]
     3830        G2frame.colList += [sampleParms[key]]
     3831        G2frame.colSigs += [None]
    38433832        colLabels += [key]
    38443833        Types += [wg.GRID_VALUE_FLOAT,]
     
    38473836        sampleDict[name] = dict(zip(sampleParms.keys(),[sampleParms[key][i] for key in sampleParms.keys()]))
    38483837    # add unique cell parameters TODO: review this where the cell symmetry changes (when possible)
    3849     if Controls.get('ShowCell',False):
     3838    if data.get('ShowCell',False):
    38503839        for pId in sorted(RecpCellTerms):
    38513840            pfx = str(pId)+'::' # prefix for A values from phase
     
    38773866                cells += [[c[i] for i in uniqCellIndx[pId]]+[vol]]
    38783867                cellESDs += [[cE[i] for i in uniqCellIndx[pId]]+[cE[-1]]]
    3879             colList += zip(*cells)
    3880             colSigs += zip(*cellESDs)
     3868            G2frame.colList += zip(*cells)
     3869            G2frame.colSigs += zip(*cellESDs)
    38813870    # sort out the variables in their selected order
    38823871    varcols = 0
     
    39093898        esds.append([data[name]['sig'][s] if s is not None else None for s in sellist])
    39103899        #GSASIIpath.IPyBreak()
    3911     colList += zip(*vals)
    3912     colSigs += zip(*esds)
     3900    G2frame.colList += zip(*vals)
     3901    G2frame.colSigs += zip(*esds)
    39133902    # compute and add weight fractions to table if varied
    39143903    for phase in Phases:
     
    39303919            sigwtFrList.append(sig)
    39313920        colLabels.append(str(Phases[phase]['pId'])+':*:WgtFrac')
    3932         colList += [wtFrList]
    3933         colSigs += [sigwtFrList]
     3921        G2frame.colList += [wtFrList]
     3922        G2frame.colSigs += [sigwtFrList]
    39343923               
    39353924    # tabulate constrained variables, removing histogram numbers if needed
     
    39523941        colLabels.append(var)
    39533942        Types += [wg.GRID_VALUE_FLOAT,]
    3954         colSigs += [depSigDict[var]]
    3955         colList += [depValDict[var]]
     3943        G2frame.colSigs += [depSigDict[var]]
     3944        G2frame.colList += [depValDict[var]]
    39563945
    39573946    # add atom parameters to table
     
    39593948    Types += len(atomLookup)*[wg.GRID_VALUE_FLOAT]
    39603949    for parm in sorted(atomLookup):
    3961         colList += [[data[name]['newAtomDict'][atomLookup[parm]][1] for name in histNames]]
     3950        G2frame.colList += [[data[name]['newAtomDict'][atomLookup[parm]][1] for name in histNames]]
    39623951        if atomLookup[parm] in data[histNames[0]]['varyList']:
    39633952            col = data[histNames[0]]['varyList'].index(atomLookup[parm])
    3964             colSigs += [[data[name]['sig'][col] for name in histNames]]
     3953            G2frame.colSigs += [[data[name]['sig'][col] for name in histNames]]
    39653954        else:
    3966             colSigs += [None] # should not happen
     3955            G2frame.colSigs += [None] # should not happen
    39673956    # evaluate Pseudovars, their ESDs and add them to grid
    3968     for expr in Controls['SeqPseudoVars']:
    3969         obj = Controls['SeqPseudoVars'][expr]
     3957    for expr in data['SeqPseudoVars']:
     3958        obj = data['SeqPseudoVars'][expr]
    39703959        calcobj = G2obj.ExpressionCalcObj(obj)
    39713960        valList = []
     
    40124001        if not esdList:
    40134002            esdList = None
    4014         colList += [valList]
    4015         colSigs += [esdList]
     4003        G2frame.colList += [valList]
     4004        G2frame.colSigs += [esdList]
    40164005        colLabels += [expr]
    40174006        Types += [wg.GRID_VALUE_FLOAT,]
     
    40264015    # Also dicts of dependent (depVarDict) & independent vars (indepVarDict)
    40274016    # for Parametric fitting from the data table
    4028     parmDict = dict(zip(colLabels,zip(*colList)[0])) # scratch dict w/all values in table
    4029     parmDict.update(
    4030         {var:val for var,val in data[name].get('newCellDict',{}).values()} #  add varied reciprocal cell terms
    4031     )
     4017    parmDict = dict(zip(colLabels,zip(*G2frame.colList)[0])) # scratch dict w/all values in table
     4018    parmDict.update({var:val for var,val in data[name].get('newCellDict',{}).values()}) #  add varied reciprocal cell terms
     4019    del parmDict['Use']
    40324020    name = histNames[0]
    40334021
     
    40404028    for i,var in enumerate(colLabels):
    40414029        if var == 'Use': continue
    4042         if colList[i][0] is None:
     4030        if G2frame.colList[i][0] is None:
    40434031            val,sig = firstValueDict.get(var,[None,None])
    4044         elif colSigs[i]:
    4045             val,sig = colList[i][0],colSigs[i][0]
     4032        elif G2frame.colSigs[i]:
     4033            val,sig = G2frame.colList[i][0],G2frame.colSigs[i][0]
    40464034        else:
    4047             val,sig = colList[i][0],None
     4035            val,sig = G2frame.colList[i][0],None
    40484036        if val is None:
    40494037            continue
    4050         elif sig is None:
     4038        elif sig is None or sig == 0.:
    40514039            indepVarDict[var] = val
    40524040        elif striphist(var) not in Dlookup:
     
    40584046    G2frame.dataDisplay = G2G.GSGrid(parent=G2frame.dataFrame)
    40594047    G2frame.SeqTable = G2G.Table(
    4060         [list(cl) for cl in zip(*colList)],     # convert from columns to rows
     4048        [list(cl) for cl in zip(*G2frame.colList)],     # convert from columns to rows
    40614049        colLabels=colLabels,rowLabels=histNames,types=Types)
    40624050    G2frame.dataDisplay.SetTable(G2frame.SeqTable, True)
  • trunk/GSASIIimgGUI.py

    r2696 r2697  
    192192                    SeqResult = G2frame.PatternTree.GetItemPyData(Id)
    193193                else:
    194                     SeqResult = {}
    195194                    Id = G2frame.PatternTree.AppendItem(parent=G2frame.root,text='Sequential image calibration results')
    196                     G2frame.PatternTree.SetItemPyData(Id,SeqResult)
     195                SeqResult = {'SeqPseudoVars':{},'SeqParFitEqList':[]}
    197196                items = dlg.GetSelections()
    198197                G2frame.EnablePlot = False
     
    217216                    SeqResult[name] = {'variables':vals,'varyList':varyList,'sig':sigList,'Rvals':[],
    218217                        'covMatrix':np.eye(len(varyList)),'title':name,'parmDict':parmDict}
    219                 SeqResult['histNames'] = Names
     218                SeqResult['histNames'] = Names               
     219                G2frame.PatternTree.SetItemPyData(Id,SeqResult)
    220220        finally:
    221221            dlg.Destroy()
     
    19401940                Id = G2frame.PatternTree.AppendItem(parent=G2frame.root,text='Sequential strain fit results')
    19411941                G2frame.PatternTree.SetItemPyData(Id,SeqResult)
     1942            SeqResult.update({'SeqPseudoVars':{},'SeqParFitEqList':[]})
    19421943        else:
    19431944            dlg.Destroy()
  • trunk/GSASIIplot.py

    r2694 r2697  
    41704170        if event.key == 's':
    41714171            G2frame.seqXaxis = G2frame.seqXselect()
    4172             Draw()
     4172            wx.CallAfter(Draw)
    41734173        elif event.key == 't':
    41744174            dlg = G2G.MultiStringDialog(G2frame,'Set titles & labels',[' Title ',' x-Label ',' y-Label '],
  • trunk/GSASIIpwdGUI.py

    r2695 r2697  
    538538            Id = G2frame.PatternTree.AppendItem(parent=G2frame.root,text='Sequential peak fit results')
    539539            G2frame.PatternTree.SetItemPyData(Id,SeqResult)
     540        SeqResult = {'SeqPseudoVars':{},'SeqParFitEqList':[]}
    540541        Reverse = False
    541542        CopyForward = False
     
    40364037                G2frame.PatternTree.SetItemPyData(Id,SeqResult)
    40374038            SeqResult['histNames'] = choices
     4039            SeqResult = {'SeqPseudoVars':{},'SeqParFitEqList':[]}
    40384040        else:
    40394041            dlg.Destroy()
     
    53835385                    Id = G2frame.PatternTree.AppendItem(parent=G2frame.root,text='Sequential PDF peak fit results')
    53845386                    G2frame.PatternTree.SetItemPyData(Id,SeqResult)
     5387                SeqResult = {'SeqPseudoVars':{},'SeqParFitEqList':[]}
    53855388                items = dlg.GetSelections()
    53865389                G2frame.EnablePlot = False
Note: See TracChangeset for help on using the changeset viewer.