Changeset 2697
- Timestamp:
- Feb 9, 2017 1:40:39 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIgrid.py
r2696 r2697 2931 2931 * 'newCellDict' - refined cell parameters after shifts to A0-A5 from Dij terms applied' 2932 2932 """ 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 rebuilt2935 check validity of pseudoVars, ect. against current variable set2936 '''2937 2933 def GetSampleParms(): 2938 '''Make a dictionary of the sample parameters are not the same over the2939 refinement series. 2934 '''Make a dictionary of the sample parameters that are not the same over the 2935 refinement series. Controls here is local 2940 2936 ''' 2941 2937 if 'IMG' in histNames[0]: … … 2975 2971 plotName = variableLabels.get(colName,colName) 2976 2972 plotName = plotSpCharFix(plotName) 2977 return plotName, colList[col],colSigs[col]2973 return plotName,G2frame.colList[col],G2frame.colSigs[col] 2978 2974 2979 2975 def PlotSelect(event): … … 3181 3177 def EnablePseudoVarMenus(): 3182 3178 'Enables or disables the PseudoVar menu items that require existing defs' 3183 if Controls['SeqPseudoVars']:3179 if data['SeqPseudoVars']: 3184 3180 val = True 3185 3181 else: … … 3190 3186 def DelPseudoVar(event): 3191 3187 'Ask the user to select a pseudo var expression to delete' 3192 choices = Controls['SeqPseudoVars'].keys()3188 choices = data['SeqPseudoVars'].keys() 3193 3189 selected = G2G.ItemSelector( 3194 3190 choices,G2frame.dataFrame, … … 3198 3194 if selected is None: return 3199 3195 for item in selected: 3200 del Controls['SeqPseudoVars'][choices[item]]3196 del data['SeqPseudoVars'][choices[item]] 3201 3197 if selected: 3202 3198 UpdateSeqResults(G2frame,data,G2frame.dataDisplay.GetSize()) # redisplay variables … … 3204 3200 def EditPseudoVar(event): 3205 3201 'Edit an existing pseudo var expression' 3206 choices = Controls['SeqPseudoVars'].keys()3202 choices = data['SeqPseudoVars'].keys() 3207 3203 if len(choices) == 1: 3208 3204 selected = 0 … … 3216 3212 dlg = G2exG.ExpressionDialog( 3217 3213 G2frame.dataDisplay,PSvarDict, 3218 Controls['SeqPseudoVars'][choices[selected]],3214 data['SeqPseudoVars'][choices[selected]], 3219 3215 header="Edit the PseudoVar expression", 3220 3216 VarLabel="PseudoVar #"+str(selected+1), … … 3223 3219 if newobj: 3224 3220 calcobj = G2obj.ExpressionCalcObj(newobj) 3225 del Controls['SeqPseudoVars'][choices[selected]]3226 Controls['SeqPseudoVars'][calcobj.eObj.expression] = newobj3221 del data['SeqPseudoVars'][choices[selected]] 3222 data['SeqPseudoVars'][calcobj.eObj.expression] = newobj 3227 3223 UpdateSeqResults(G2frame,data,G2frame.dataDisplay.GetSize()) # redisplay variables 3228 3224 3229 3225 def AddNewPseudoVar(event): 3230 3226 'Create a new pseudo var expression' 3231 dlg = G2exG.ExpressionDialog( 3232 G2frame.dataDisplay,PSvarDict, 3227 dlg = G2exG.ExpressionDialog(G2frame.dataDisplay,PSvarDict, 3233 3228 header='Enter an expression for a PseudoVar here', 3234 VarLabel = "New PseudoVar", 3235 fit=False) 3229 VarLabel = "New PseudoVar",fit=False) 3236 3230 obj = dlg.Show(True) 3237 3231 dlg.Destroy() 3238 3232 if obj: 3239 3233 calcobj = G2obj.ExpressionCalcObj(obj) 3240 Controls['SeqPseudoVars'][calcobj.eObj.expression] = obj3234 data['SeqPseudoVars'][calcobj.eObj.expression] = obj 3241 3235 UpdateSeqResults(G2frame,data,G2frame.dataDisplay.GetSize()) # redisplay variables 3242 3236 … … 3279 3273 dlg.Destroy() 3280 3274 if obj: 3281 Controls['SeqPseudoVars'][obj.expression] = obj3275 data['SeqPseudoVars'][obj.expression] = obj 3282 3276 UpdateSeqResults(G2frame,data,G2frame.dataDisplay.GetSize()) # redisplay variables 3283 3277 … … 3327 3321 dlg.Destroy() 3328 3322 if obj: 3329 Controls['SeqPseudoVars'][obj.expression] = obj3323 data['SeqPseudoVars'][obj.expression] = obj 3330 3324 UpdateSeqResults(G2frame,data,G2frame.dataDisplay.GetSize()) # redisplay variables 3331 3325 … … 3425 3419 def EnableParFitEqMenus(): 3426 3420 'Enables or disables the Parametric Fit menu items that require existing defs' 3427 if Controls['SeqParFitEqList']:3421 if data['SeqParFitEqList']: 3428 3422 val = True 3429 3423 else: … … 3453 3447 eqObjList = [eqObj,] 3454 3448 else: 3455 eqObjList = Controls['SeqParFitEqList']3449 eqObjList = data['SeqParFitEqList'] 3456 3450 UseFlags = G2frame.SeqTable.GetColValues(0) 3457 3451 for obj in eqObjList: … … 3467 3461 indepVars = obj.GetIndependentVars() 3468 3462 # loop over each datapoint 3469 for j,row in enumerate(zip(* colList)):3463 for j,row in enumerate(zip(*G2frame.colList)): 3470 3464 if not UseFlags[j]: continue 3471 3465 # assemble equations to fit … … 3476 3470 # values and sigs for current value of dependent var 3477 3471 calcobj.depVal = row[indx] 3478 calcobj.depSig = colSigs[indx][j]3472 calcobj.depSig = G2frame.colSigs[indx][j] 3479 3473 calcObjList.append(calcobj) 3480 3474 # varied parameters … … 3521 3515 # loop over each datapoint 3522 3516 fitvals = [] 3523 for j,row in enumerate(zip(* colList)):3517 for j,row in enumerate(zip(*G2frame.colList)): 3524 3518 calcobj.SetupCalc( 3525 3519 {var:row[i] for i,var in enumerate(colLabels) if var in indepVars} 3526 3520 ) 3527 3521 fitvals.append(calcobj.EvalExpression()) 3528 G2plt.PlotSelectedSequence( 3529 G2frame,[indx],GetColumnInfo,SelectXaxis, 3530 fitnum,fitvals) 3522 G2plt.PlotSelectedSequence(G2frame,[indx],GetColumnInfo,SelectXaxis,fitnum,fitvals) 3531 3523 3532 3524 def SingleParEqFit(eqObj): … … 3535 3527 def DelParFitEq(event): 3536 3528 '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']] 3538 3530 selected = G2G.ItemSelector( 3539 3531 txtlst,G2frame.dataFrame, … … 3542 3534 header='Delete equation') 3543 3535 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] 3545 3537 EnableParFitEqMenus() 3546 if Controls['SeqParFitEqList']: DoParEqFit(event)3538 if data['SeqParFitEqList']: DoParEqFit(event) 3547 3539 3548 3540 def EditParFitEq(event): 3549 3541 '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']] 3551 3543 if len(txtlst) == 1: 3552 3544 selected = 0 … … 3560 3552 dlg = G2exG.ExpressionDialog( 3561 3553 G2frame.dataDisplay,indepVarDict, 3562 Controls['SeqParFitEqList'][selected],3554 data['SeqParFitEqList'][selected], 3563 3555 depVarDict=depVarDict, 3564 3556 header="Edit the formula for this minimization function", … … 3566 3558 newobj = dlg.Show(True) 3567 3559 if newobj: 3568 Controls['SeqParFitEqList'][selected] = newobj3560 data['SeqParFitEqList'][selected] = newobj 3569 3561 EnableParFitEqMenus() 3570 if Controls['SeqParFitEqList']: DoParEqFit(event)3562 if data['SeqParFitEqList']: DoParEqFit(event) 3571 3563 3572 3564 def AddNewParFitEq(event): … … 3575 3567 # compile the variable names used in previous freevars to avoid accidental name collisions 3576 3568 usedvarlist = [] 3577 for obj in Controls['SeqParFitEqList']:3569 for obj in data['SeqParFitEqList']: 3578 3570 for var in obj.freeVars: 3579 3571 if obj.freeVars[var][0] not in usedvarlist: usedvarlist.append(obj.freeVars[var][0]) 3580 3572 3581 dlg = G2exG.ExpressionDialog( 3582 G2frame.dataDisplay,indepVarDict, 3583 depVarDict=depVarDict, 3573 dlg = G2exG.ExpressionDialog(G2frame.dataDisplay,parmDict,depVarDict=depVarDict, 3584 3574 header='Define an equation to minimize in the parametric fit', 3585 ExtraButton=['Fit',SingleParEqFit], 3586 usedVars=usedvarlist) 3575 ExtraButton=['Fit',SingleParEqFit],usedVars=usedvarlist) 3587 3576 obj = dlg.Show(True) 3588 3577 dlg.Destroy() 3589 3578 if obj: 3590 Controls['SeqParFitEqList'].append(obj)3579 data['SeqParFitEqList'].append(obj) 3591 3580 EnableParFitEqMenus() 3592 if Controls['SeqParFitEqList']: DoParEqFit(event)3581 if data['SeqParFitEqList']: DoParEqFit(event) 3593 3582 3594 3583 def CopyParFitEq(event): … … 3596 3585 # compile the variable names used in previous freevars to avoid accidental name collisions 3597 3586 usedvarlist = [] 3598 for obj in Controls['SeqParFitEqList']:3587 for obj in data['SeqParFitEqList']: 3599 3588 for var in obj.freeVars: 3600 3589 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']] 3602 3591 if len(txtlst) == 1: 3603 3592 selected = 0 … … 3609 3598 header='Copy equation') 3610 3599 if selected is not None: 3611 newEqn = copy.deepcopy( Controls['SeqParFitEqList'][selected])3600 newEqn = copy.deepcopy(data['SeqParFitEqList'][selected]) 3612 3601 for var in newEqn.freeVars: 3613 3602 newEqn.freeVars[var][0] = G2obj.MakeUniqueLabel(newEqn.freeVars[var][0],usedvarlist) … … 3620 3609 newobj = dlg.Show(True) 3621 3610 if newobj: 3622 Controls['SeqParFitEqList'].append(newobj)3611 data['SeqParFitEqList'].append(newobj) 3623 3612 EnableParFitEqMenus() 3624 if Controls['SeqParFitEqList']: DoParEqFit(event)3613 if data['SeqParFitEqList']: DoParEqFit(event) 3625 3614 3626 3615 def GridSetToolTip(row,col): … … 3628 3617 as a tooltip 3629 3618 ''' 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]) 3632 3621 return '' 3633 3622 … … 3690 3679 data['variableLabels'] = variableLabels 3691 3680 Histograms,Phases = G2frame.GetUsedHistogramsAndPhasesfromTree() 3692 Controls = G2frame.PatternTree.GetItemPyData(GetPatternTreeItemId(G2frame,G2frame.root,'Controls'))3681 # Controls = G2frame.PatternTree.GetItemPyData(GetPatternTreeItemId(G2frame,G2frame.root,'Controls')) 3693 3682 # 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'] = [] 3696 3685 histNames = data['histNames'] 3697 3686 if G2frame.dataDisplay: … … 3820 3809 histNames = foundNames 3821 3810 nRows = len(histNames) 3822 colList = [nRows*[True]]3823 colSigs = [None]3811 G2frame.colList = [nRows*[True]] 3812 G2frame.colSigs = [None] 3824 3813 colLabels = ['Use'] 3825 3814 Types = [wg.GRID_VALUE_BOOL] 3826 3815 # start with Rwp values 3827 3816 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] 3830 3819 colLabels += ['Rwp'] 3831 3820 Types += [wg.GRID_VALUE_FLOAT+':10,3',] 3832 3821 # 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] 3836 3825 colLabels += [u'\u0394\u03C7\u00B2 (%)'] 3837 3826 Types += [wg.GRID_VALUE_FLOAT,] … … 3839 3828 # add changing sample parameters to table 3840 3829 for key in sampleParms: 3841 colList += [sampleParms[key]]3842 colSigs += [None]3830 G2frame.colList += [sampleParms[key]] 3831 G2frame.colSigs += [None] 3843 3832 colLabels += [key] 3844 3833 Types += [wg.GRID_VALUE_FLOAT,] … … 3847 3836 sampleDict[name] = dict(zip(sampleParms.keys(),[sampleParms[key][i] for key in sampleParms.keys()])) 3848 3837 # 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): 3850 3839 for pId in sorted(RecpCellTerms): 3851 3840 pfx = str(pId)+'::' # prefix for A values from phase … … 3877 3866 cells += [[c[i] for i in uniqCellIndx[pId]]+[vol]] 3878 3867 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) 3881 3870 # sort out the variables in their selected order 3882 3871 varcols = 0 … … 3909 3898 esds.append([data[name]['sig'][s] if s is not None else None for s in sellist]) 3910 3899 #GSASIIpath.IPyBreak() 3911 colList += zip(*vals)3912 colSigs += zip(*esds)3900 G2frame.colList += zip(*vals) 3901 G2frame.colSigs += zip(*esds) 3913 3902 # compute and add weight fractions to table if varied 3914 3903 for phase in Phases: … … 3930 3919 sigwtFrList.append(sig) 3931 3920 colLabels.append(str(Phases[phase]['pId'])+':*:WgtFrac') 3932 colList += [wtFrList]3933 colSigs += [sigwtFrList]3921 G2frame.colList += [wtFrList] 3922 G2frame.colSigs += [sigwtFrList] 3934 3923 3935 3924 # tabulate constrained variables, removing histogram numbers if needed … … 3952 3941 colLabels.append(var) 3953 3942 Types += [wg.GRID_VALUE_FLOAT,] 3954 colSigs += [depSigDict[var]]3955 colList += [depValDict[var]]3943 G2frame.colSigs += [depSigDict[var]] 3944 G2frame.colList += [depValDict[var]] 3956 3945 3957 3946 # add atom parameters to table … … 3959 3948 Types += len(atomLookup)*[wg.GRID_VALUE_FLOAT] 3960 3949 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]] 3962 3951 if atomLookup[parm] in data[histNames[0]]['varyList']: 3963 3952 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]] 3965 3954 else: 3966 colSigs += [None] # should not happen3955 G2frame.colSigs += [None] # should not happen 3967 3956 # 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] 3970 3959 calcobj = G2obj.ExpressionCalcObj(obj) 3971 3960 valList = [] … … 4012 4001 if not esdList: 4013 4002 esdList = None 4014 colList += [valList]4015 colSigs += [esdList]4003 G2frame.colList += [valList] 4004 G2frame.colSigs += [esdList] 4016 4005 colLabels += [expr] 4017 4006 Types += [wg.GRID_VALUE_FLOAT,] … … 4026 4015 # Also dicts of dependent (depVarDict) & independent vars (indepVarDict) 4027 4016 # 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'] 4032 4020 name = histNames[0] 4033 4021 … … 4040 4028 for i,var in enumerate(colLabels): 4041 4029 if var == 'Use': continue 4042 if colList[i][0] is None:4030 if G2frame.colList[i][0] is None: 4043 4031 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] 4046 4034 else: 4047 val,sig = colList[i][0],None4035 val,sig = G2frame.colList[i][0],None 4048 4036 if val is None: 4049 4037 continue 4050 elif sig is None :4038 elif sig is None or sig == 0.: 4051 4039 indepVarDict[var] = val 4052 4040 elif striphist(var) not in Dlookup: … … 4058 4046 G2frame.dataDisplay = G2G.GSGrid(parent=G2frame.dataFrame) 4059 4047 G2frame.SeqTable = G2G.Table( 4060 [list(cl) for cl in zip(* colList)], # convert from columns to rows4048 [list(cl) for cl in zip(*G2frame.colList)], # convert from columns to rows 4061 4049 colLabels=colLabels,rowLabels=histNames,types=Types) 4062 4050 G2frame.dataDisplay.SetTable(G2frame.SeqTable, True) -
trunk/GSASIIimgGUI.py
r2696 r2697 192 192 SeqResult = G2frame.PatternTree.GetItemPyData(Id) 193 193 else: 194 SeqResult = {}195 194 Id = G2frame.PatternTree.AppendItem(parent=G2frame.root,text='Sequential image calibration results') 196 G2frame.PatternTree.SetItemPyData(Id,SeqResult)195 SeqResult = {'SeqPseudoVars':{},'SeqParFitEqList':[]} 197 196 items = dlg.GetSelections() 198 197 G2frame.EnablePlot = False … … 217 216 SeqResult[name] = {'variables':vals,'varyList':varyList,'sig':sigList,'Rvals':[], 218 217 'covMatrix':np.eye(len(varyList)),'title':name,'parmDict':parmDict} 219 SeqResult['histNames'] = Names 218 SeqResult['histNames'] = Names 219 G2frame.PatternTree.SetItemPyData(Id,SeqResult) 220 220 finally: 221 221 dlg.Destroy() … … 1940 1940 Id = G2frame.PatternTree.AppendItem(parent=G2frame.root,text='Sequential strain fit results') 1941 1941 G2frame.PatternTree.SetItemPyData(Id,SeqResult) 1942 SeqResult.update({'SeqPseudoVars':{},'SeqParFitEqList':[]}) 1942 1943 else: 1943 1944 dlg.Destroy() -
trunk/GSASIIplot.py
r2694 r2697 4170 4170 if event.key == 's': 4171 4171 G2frame.seqXaxis = G2frame.seqXselect() 4172 Draw()4172 wx.CallAfter(Draw) 4173 4173 elif event.key == 't': 4174 4174 dlg = G2G.MultiStringDialog(G2frame,'Set titles & labels',[' Title ',' x-Label ',' y-Label '], -
trunk/GSASIIpwdGUI.py
r2695 r2697 538 538 Id = G2frame.PatternTree.AppendItem(parent=G2frame.root,text='Sequential peak fit results') 539 539 G2frame.PatternTree.SetItemPyData(Id,SeqResult) 540 SeqResult = {'SeqPseudoVars':{},'SeqParFitEqList':[]} 540 541 Reverse = False 541 542 CopyForward = False … … 4036 4037 G2frame.PatternTree.SetItemPyData(Id,SeqResult) 4037 4038 SeqResult['histNames'] = choices 4039 SeqResult = {'SeqPseudoVars':{},'SeqParFitEqList':[]} 4038 4040 else: 4039 4041 dlg.Destroy() … … 5383 5385 Id = G2frame.PatternTree.AppendItem(parent=G2frame.root,text='Sequential PDF peak fit results') 5384 5386 G2frame.PatternTree.SetItemPyData(Id,SeqResult) 5387 SeqResult = {'SeqPseudoVars':{},'SeqParFitEqList':[]} 5385 5388 items = dlg.GetSelections() 5386 5389 G2frame.EnablePlot = False
Note: See TracChangeset
for help on using the changeset viewer.