Changeset 1396
- Timestamp:
- Jun 25, 2014 6:20:41 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIexprGUI.py
r1378 r1396 280 280 if val: 281 281 self.varValue[v] = val 282 wx.CallAfter(self.ShowVars ())282 wx.CallAfter(self.ShowVars) 283 283 284 284 def Show(self,mode=True): … … 289 289 self.Layout() 290 290 self.mainsizer.Fit(self) 291 self.SendSizeEvent() # force repaint 291 292 if self.ShowModal() == wx.ID_OK: 292 293 # store the edit results in the object and return it … … 482 483 self.varbox.Refresh() 483 484 self.Layout() 485 self.mainsizer.Fit(self) 486 self.SendSizeEvent() # force repaint 484 487 return 485 488 -
trunk/GSASIIgrid.py
r1390 r1396 113 113 114 114 [ wxID_INSTPRMRESET,wxID_CHANGEWAVETYPE,wxID_INSTCOPY, wxID_INSTFLAGCOPY, wxID_INSTLOAD, 115 wxID_INSTSAVE, 116 ] = [wx.NewId() for item in range( 6)]115 wxID_INSTSAVE, wxID_INSTONEVAL 116 ] = [wx.NewId() for item in range(7)] 117 117 118 118 [ wxID_UNDO,wxID_LSQPEAKFIT,wxID_LSQONECYCLE,wxID_RESETSIGGAM,wxID_CLEARPEAKS,wxID_AUTOSEARCH, … … 413 413 414 414 def _onLoseFocus(self,event): 415 # wx 2.9 patch: may be unregistered changes since backspace is not seen 416 i,j= wx.__version__.split('.')[0:2] 417 if int(i)+int(j)/10. > 2.8: 418 if self.Validator: self.Validator.TestValid(self) 419 # end patch 415 420 if self.evaluated: 416 421 self.EvaluateExpression() … … 422 427 **self.OnLeaveArgs) 423 428 424 def _onLeaveWindow(self,event):425 if self.evaluated:426 self.EvaluateExpression()427 elif self.result is not None: # show formatted result, as Bob wants428 self._setValue(self.result[self.key])429 # def _onLeaveWindow(self,event): 430 # if self.evaluated: 431 # self.EvaluateExpression() 432 # elif self.result is not None: # show formatted result, as Bob wants 433 # self._setValue(self.result[self.key]) 429 434 430 435 def EvaluateExpression(self): … … 2592 2597 # self.InstEdit.Append(help='Change radiation type (Ka12 - synch)', 2593 2598 # id=wxID_CHANGEWAVETYPE, kind=wx.ITEM_NORMAL,text='Change radiation') 2599 self.InstEdit.Append(id=wxID_INSTONEVAL, kind=wx.ITEM_NORMAL,text='Set one value', 2600 help='Set one instrument parameter value across multiple histograms') 2601 2594 2602 self.PostfillDataMenu() 2595 2603 … … 4045 4053 def EnableParFitEqMenus(): 4046 4054 'Enables or disables the Parametric Fit menu items that require existing defs' 4047 if Controls['SeqParFitEq s']:4055 if Controls['SeqParFitEqList']: 4048 4056 val = True 4049 4057 else: … … 4071 4079 calcObjList = [] # expression objects, ready to go for each data point 4072 4080 if eqObj is not None: 4073 eqObj Dict = {eqObj.expression:eqObj}4081 eqObjList = [eqObj,] 4074 4082 else: 4075 eqObj Dict = Controls['SeqParFitEqs']4076 for expr in eqObjDict.keys():4077 obj = eqObjDict[expr]4083 eqObjList = Controls['SeqParFitEqList'] 4084 for obj in eqObjList: 4085 expr = obj.expression 4078 4086 # assemble refined vars for this equation 4079 4087 varyValueDict.update({var:val for var,val in obj.GetVariedVarVal()}) … … 4102 4110 if not varyList: 4103 4111 print 'no variables to refine!' 4104 else: 4105 try: 4106 print 'Fit Results' 4107 result = so.leastsq(ParEqEval,varyValues,full_output=True, #ftol=Ftol, 4108 args=(calcObjList,varyList) 4109 ) 4110 values = result[0] 4111 covar = result[1] 4112 if covar is None: 4113 raise Exception 4114 for i,(var,val) in enumerate(zip(varyList,values)): 4115 print ' ',var,' =',G2mth.ValEsd(val,np.sqrt(covar[i,i])) 4116 except: 4117 print 'Fit failed' 4118 return 4112 return 4113 try: 4114 result = so.leastsq(ParEqEval,varyValues,full_output=True, #ftol=Ftol, 4115 args=(calcObjList,varyList) 4116 ) 4117 values = result[0] 4118 covar = result[1] 4119 if covar is None: 4120 raise Exception 4121 esdDict = {} 4122 for i,avar in enumerate(varyList): 4123 esdDict[avar] = np.sqrt(covar[i,i]) 4124 except: 4125 print('====> Fit failed') 4126 return 4127 print('==== Fit Results ====') 4128 for obj in eqObjList: 4129 ind = ' ' 4130 print(' '+obj.GetDepVar()+' = '+obj.expression) 4131 for var in obj.assgnVars: 4132 print(ind+var+' = '+obj.assgnVars[var]) 4133 for var in obj.freeVars: 4134 avar = "::"+obj.freeVars[var][0] 4135 val = obj.freeVars[var][1] 4136 if obj.freeVars[var][2]: 4137 print(ind+var+' = '+avar + " = " + G2mth.ValEsd(val,esdDict[avar])) 4138 else: 4139 print(ind+var+' = '+avar + " =" + G2mth.ValEsd(val,0)) 4119 4140 # create a plot for each parametric variable 4120 for fitnum,expr in enumerate(sorted(eqObjDict)): 4121 obj = eqObjDict[expr] 4141 for fitnum,obj in enumerate(eqObjList): 4122 4142 obj.UpdateVariedVars(varyList,values) 4123 4143 calcobj = G2obj.ExpressionCalcObj(obj) … … 4142 4162 def DelParFitEq(event): 4143 4163 'Ask the user to select function to delete' 4144 choices = sorted(Controls['SeqParFitEqs'].keys()) 4145 txtlst = [Controls['SeqParFitEqs'][i].GetDepVar()+' = '+i for i in choices] 4164 txtlst = [obj.GetDepVar()+' = '+obj.expression for obj in Controls['SeqParFitEqList']] 4146 4165 selected = ItemSelector( 4147 4166 txtlst,G2frame.dataFrame, 4148 4167 multiple=True, 4149 title='Select a parametric equation to remove',4168 title='Select a parametric equation(s) to remove', 4150 4169 header='Delete equation') 4151 4170 if selected is None: return 4152 for item in selected: 4153 del Controls['SeqParFitEqs'][choices[item]] 4171 Controls['SeqParFitEqList'] = [obj for i,obj in enumerate(Controls['SeqParFitEqList']) if i not in selected] 4154 4172 EnableParFitEqMenus() 4155 if Controls['SeqParFitEq s']: DoParEqFit(event)4173 if Controls['SeqParFitEqList']: DoParEqFit(event) 4156 4174 4157 4175 def EditParFitEq(event): 4158 4176 'Edit an existing parametric equation' 4159 choices = sorted(Controls['SeqParFitEqs'].keys()) 4160 txtlst = [Controls['SeqParFitEqs'][i].GetDepVar()+' = '+i for i in choices] 4161 if len(choices) == 1: 4177 txtlst = [obj.GetDepVar()+' = '+obj.expression for obj in Controls['SeqParFitEqList']] 4178 if len(txtlst) == 1: 4162 4179 selected = 0 4163 4180 else: … … 4170 4187 dlg = G2exG.ExpressionDialog( 4171 4188 G2frame.dataDisplay,indepVarDict, 4172 Controls['SeqParFitEq s'][choices[selected]],4189 Controls['SeqParFitEqList'][selected], 4173 4190 depVarDict=depVarDict, 4174 4191 header="Edit the formula for this minimization function", … … 4177 4194 if newobj: 4178 4195 calcobj = G2obj.ExpressionCalcObj(newobj) 4179 del Controls['SeqParFitEqs'][choices[selected]] 4180 Controls['SeqParFitEqs'][calcobj.eObj.expression] = newobj 4196 Controls['SeqParFitEqList'][selected] = newobj 4181 4197 EnableParFitEqMenus() 4182 if Controls['SeqParFitEqs']: DoParEqFit(event)4198 if Controls['SeqParFitEqList']: DoParEqFit(event) 4183 4199 4184 4200 def AddNewParFitEq(event): 4185 4201 'Create a new parametric equation to be fit to sequential results' 4186 4202 4187 # compile the variable names in previous freevars to avoid accidental name collisions4203 # compile the variable names used in previous freevars to avoid accidental name collisions 4188 4204 usedvarlist = [] 4189 for eq,obj in Controls['SeqParFitEqs'].items(): 4205 for obj in Controls['SeqParFitEqList']: 4206 eq = obj.expression 4190 4207 for var in obj.freeVars: 4191 4208 if obj.freeVars[var][0] not in usedvarlist: usedvarlist.append(obj.freeVars[var][0]) … … 4200 4217 dlg.Destroy() 4201 4218 if obj: 4202 calcobj = G2obj.ExpressionCalcObj(obj) 4203 Controls['SeqParFitEqs'][calcobj.eObj.expression] = obj 4219 Controls['SeqParFitEqList'].append(obj) 4204 4220 EnableParFitEqMenus() 4205 if Controls['SeqParFitEq s']: DoParEqFit(event)4221 if Controls['SeqParFitEqList']: DoParEqFit(event) 4206 4222 4207 4223 def GridSetToolTip(row,col): … … 4265 4281 # create a place to store Pseudo Vars & Parametric Fit functions, if needed 4266 4282 if 'SeqPseudoVars' not in Controls: Controls['SeqPseudoVars'] = {} 4267 if 'SeqParFitEq s' not in Controls: Controls['SeqParFitEqs'] = {}4283 if 'SeqParFitEqList' not in Controls: Controls['SeqParFitEqList'] = [] 4268 4284 histNames = data['histNames'] 4269 4285 if G2frame.dataDisplay: -
trunk/GSASIIplot.py
r1386 r1396 2402 2402 number (or None) as the X-axis selection 2403 2403 ''' 2404 G2frame.seqXselect = SelectX2405 try:2406 G2frame.seqXaxis2407 except:2408 G2frame.seqXaxis = None2409 2410 2404 def OnMotion(event): 2411 2405 if event.xdata and event.ydata: #avoid out of frame errors … … 2420 2414 Draw() 2421 2415 2422 if fitnum is None:2423 label = 'Sequential refinement'2424 else:2425 label = 'Parametric fit #'+str(fitnum+1)2426 try:2427 plotNum = G2frame.G2plotNB.plotList.index(label)2428 Page = G2frame.G2plotNB.nb.GetPage(plotNum)2429 Page.figure.clf()2430 Plot = Page.figure.gca()2431 if not Page.IsShown():2432 Page.Show()2433 except ValueError:2434 Plot = G2frame.G2plotNB.addMpl(label).gca()2435 plotNum = G2frame.G2plotNB.plotList.index(label)2436 Page = G2frame.G2plotNB.nb.GetPage(plotNum)2437 Page.canvas.mpl_connect('key_press_event', OnKeyPress)2438 Page.canvas.mpl_connect('motion_notify_event', OnMotion)2439 Page.Choice = ['s to select plot x-axis',]2440 Page.keyPress = OnKeyPress2441 Page.seqYaxisList = ColumnList2442 Page.seqTableGet = TableGet2443 Page.fitvals = fitvals2444 2445 2416 def Draw(): 2446 2417 Page.SetFocus() … … 2473 2444 Plot.set_xlabel(xName) 2474 2445 Page.canvas.draw() 2446 2447 G2frame.seqXselect = SelectX 2448 try: 2449 G2frame.seqXaxis 2450 except: 2451 G2frame.seqXaxis = None 2452 2453 if fitnum is None: 2454 label = 'Sequential refinement' 2455 else: 2456 label = 'Parametric fit #'+str(fitnum+1) 2457 try: 2458 plotNum = G2frame.G2plotNB.plotList.index(label) 2459 Page = G2frame.G2plotNB.nb.GetPage(plotNum) 2460 Page.figure.clf() 2461 Plot = Page.figure.gca() 2462 if not Page.IsShown(): 2463 Page.Show() 2464 except ValueError: 2465 Plot = G2frame.G2plotNB.addMpl(label).gca() 2466 plotNum = G2frame.G2plotNB.plotList.index(label) 2467 Page = G2frame.G2plotNB.nb.GetPage(plotNum) 2468 Page.canvas.mpl_connect('key_press_event', OnKeyPress) 2469 Page.canvas.mpl_connect('motion_notify_event', OnMotion) 2470 Page.Choice = ['s to select plot x-axis',] 2471 Page.keyPress = OnKeyPress 2472 Page.seqYaxisList = ColumnList 2473 Page.seqTableGet = TableGet 2474 Page.fitvals = fitvals 2475 2475 2476 Draw() 2477 G2frame.G2plotNB.nb.SetSelection(plotNum) # raises plot tab 2476 2478 2477 2479 ################################################################################
Note: See TracChangeset
for help on using the changeset viewer.