- Timestamp:
- Feb 10, 2017 12:30:28 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/GSASIIgrid.py ¶
r2697 r2698 24 24 import random as ran 25 25 import numpy as np 26 import numpy.ma as ma 26 27 import scipy.optimize as so 27 28 import GSASIIpath … … 3006 3007 'average the selected columns from menu command' 3007 3008 cols = sorted(G2frame.dataDisplay.GetSelectedCols()) # ignore selection order 3009 useCol = -np.array(G2frame.SeqTable.GetColValues(0),dtype=bool) 3008 3010 if cols: 3009 3011 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)) 3012 3017 print ' Average for '+G2frame.SeqTable.GetColLabelValue(col)+': '+'%.6g'%(ave)+' +/- '+'%.6g'%(sig) 3013 3018 else: … … 3437 3442 for calcobj in calcObjList: 3438 3443 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()) 3440 3448 return result 3441 3449 … … 3469 3477 calcobj.SetupCalc(indepVarDict) 3470 3478 # values and sigs for current value of dependent var 3479 if row[indx] is None: continue 3471 3480 calcobj.depVal = row[indx] 3472 3481 calcobj.depSig = G2frame.colSigs[indx][j] … … 3480 3489 try: 3481 3490 result = so.leastsq(ParEqEval,varyValues,full_output=True, #ftol=Ftol, 3482 args=(calcObjList,varyList) 3483 ) 3491 args=(calcObjList,varyList)) 3484 3492 values = result[0] 3485 3493 covar = result[1] 3486 3494 if covar is None: 3487 3495 raise Exception 3496 chisq = np.sum(result[2]['fvec']**2) 3497 GOF = np.sqrt(chisq/(len(calcObjList)-len(varyList))) 3488 3498 esdDict = {} 3489 3499 for i,avar in enumerate(varyList): … … 3493 3503 return 3494 3504 print('==== Fit Results ====') 3505 print ' chisq = %.2f, GOF = %.2f'%(chisq,GOF) 3495 3506 for obj in eqObjList: 3496 3507 obj.UpdateVariedVars(varyList,values) … … 3516 3527 fitvals = [] 3517 3528 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}) 3521 3530 fitvals.append(calcobj.EvalExpression()) 3522 3531 G2plt.PlotSelectedSequence(G2frame,[indx],GetColumnInfo,SelectXaxis,fitnum,fitvals) … … 3550 3559 header='Edit equation') 3551 3560 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, 3556 3563 header="Edit the formula for this minimization function", 3557 3564 ExtraButton=['Fit',SingleParEqFit]) … … 3571 3578 if obj.freeVars[var][0] not in usedvarlist: usedvarlist.append(obj.freeVars[var][0]) 3572 3579 3573 dlg = G2exG.ExpressionDialog(G2frame.dataDisplay, parmDict,depVarDict=depVarDict,3580 dlg = G2exG.ExpressionDialog(G2frame.dataDisplay,VarDict,depVarDict=VarDict, 3574 3581 header='Define an equation to minimize in the parametric fit', 3575 3582 ExtraButton=['Fit',SingleParEqFit],usedVars=usedvarlist) … … 3602 3609 newEqn.freeVars[var][0] = G2obj.MakeUniqueLabel(newEqn.freeVars[var][0],usedvarlist) 3603 3610 dlg = G2exG.ExpressionDialog( 3604 G2frame.dataDisplay,indepVarDict, 3605 newEqn, 3606 depVarDict=depVarDict, 3611 G2frame.dataDisplay,VarDict,newEqn,depVarDict=VarDict, 3607 3612 header="Edit the formula for this minimization function", 3608 3613 ExtraButton=['Fit',SingleParEqFit]) … … 3679 3684 data['variableLabels'] = variableLabels 3680 3685 Histograms,Phases = G2frame.GetUsedHistogramsAndPhasesfromTree() 3681 #Controls = G2frame.PatternTree.GetItemPyData(GetPatternTreeItemId(G2frame,G2frame.root,'Controls'))3686 Controls = G2frame.PatternTree.GetItemPyData(GetPatternTreeItemId(G2frame,G2frame.root,'Controls')) 3682 3687 # create a place to store Pseudo Vars & Parametric Fit functions, if not present 3683 3688 if 'SeqPseudoVars' not in data: data['SeqPseudoVars'] = {} … … 3820 3825 Types += [wg.GRID_VALUE_FLOAT+':10,3',] 3821 3826 # 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'): 3823 3828 G2frame.colList += [[100.*data[name]['Rvals'].get('DelChi2',-1) for name in histNames]] 3824 3829 G2frame.colSigs += [None] … … 3836 3841 sampleDict[name] = dict(zip(sampleParms.keys(),[sampleParms[key][i] for key in sampleParms.keys()])) 3837 3842 # 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): 3839 3844 for pId in sorted(RecpCellTerms): 3840 3845 pfx = str(pId)+'::' # prefix for A values from phase … … 4013 4018 PSvarDict.update(sampleParms) 4014 4019 UpdateParmDict(PSvarDict) 4015 # Also dicts of dependent (depVarDict) & independent vars (indepVarDict)4020 # Also dicts of variables 4016 4021 # for Parametric fitting from the data table 4017 4022 parmDict = dict(zip(colLabels,zip(*G2frame.colList)[0])) # scratch dict w/all values in table … … 4024 4029 # this does not work for refinements that have differing numbers of variables. 4025 4030 #raise Exception 4026 indepVarDict = {} # values in table w/o ESDs 4027 depVarDict = {} 4031 VarDict = {} 4028 4032 for i,var in enumerate(colLabels): 4029 if var == 'Use': continue4033 if var in ['Use','Rwp',u'\u0394\u03C7\u00B2 (%)']: continue 4030 4034 if G2frame.colList[i][0] is None: 4031 4035 val,sig = firstValueDict.get(var,[None,None]) … … 4034 4038 else: 4035 4039 val,sig = G2frame.colList[i][0],None 4036 if val is None: 4037 continue 4040 if val is None: continue 4038 4041 elif sig is None or sig == 0.: 4039 indepVarDict[var] = val4042 VarDict[var] = val 4040 4043 elif striphist(var) not in Dlookup: 4041 depVarDict[var] = val4044 VarDict[var] = val 4042 4045 # 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()}) 4044 4047 4045 4048 G2frame.dataFrame.currentGrids = [] -
TabularUnified trunk/GSASIIobj.py ¶
r2695 r2698 878 878 'FreePrm2':'Sample voltage (V)', 879 879 'FreePrm3':'Applied load (MN)', 880 'S eqPseudoVars':{},'SeqParFitEqList':[],'ShowCell':False,880 'ShowCell':False, 881 881 } 882 882 '''Values to be used as defaults for the initial contents of the ``Controls`` -
TabularUnified trunk/GSASIIpwdGUI.py ¶
r2697 r2698 552 552 dlg = wx.ProgressDialog('Sequential peak fit','Data set name = '+names[0],len(names), 553 553 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'))555 554 controls = {'deriv type':'analytic','min dM/M':0.0001,} 556 Controls['ShowCell'] = False557 555 print 'Peak Fitting with '+controls['deriv type']+' derivatives:' 558 556 oneCycle = False -
TabularUnified trunk/GSASIIstrIO.py ¶
r2658 r2698 545 545 546 546 print 'GPX file save successful' 547 548 def 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 547 566 548 567 def SetSeqResult(GPXfile,Histograms,SeqResult): -
TabularUnified trunk/GSASIIstrMain.py ¶
r2557 r2698 280 280 if Controls.get('Reverse Seq'): 281 281 histNames.reverse() 282 SeqResult = {} 282 SeqResult = G2stIO.GetSeqResult(GPXfile) 283 # SeqResult = {'SeqPseudoVars':{},'SeqParFitEqList':[]} 283 284 makeBack = True 284 285 Histo = {}
Note: See TracChangeset
for help on using the changeset viewer.