@@ -5552,49 +5552,52 @@ def OnRefine(self,event):
55525552 text += ('\n WARNING: Marquardt factor raised to point where steepest descents dominates fitting;' +
55535553 ' minimum may not have been reached or your result may be a false minimum.' +
55545554 ' You should reconsider which parameters you refine: check covariance matrix.\n ' )
5555- text += '\n Load new result?'
55565555 #breakpoint()
5557- # assemble a list of changed parameters
5558- # tbl = []
5559- # for i in Rvals['parmDictAfterFit']:
5560- # if i not in Rvals['parmDictBeforeFit']: continue
5561- # if (Rvals['parmDictAfterFit'][i] != Rvals['parmDictBeforeFit'][i] or
5562- # #np.isclose(Rvals['parmDictAfterFit'][i],Rvals['parmDictBeforeFit'][i])
5563- # i in Rvals['parmDictvaryList']):
5564- # txt = ''
5565- # v = G2obj.getVarDescr(i)
5566- # if v is not None and v[-1] is not None:
5567- # txt = G2obj.fmtVarDescr(i)
5568- # tbl.append((i,Rvals['parmDictBeforeFit'][i],Rvals['parmDictAfterFit'][i],txt))
5569- dlg2 = wx .MessageDialog (self ,text ,
5570- f'Refinement results, Rw={ Rw :.3f} ' ,
5571- wx .OK | wx .CANCEL )
5556+ tbl = [] # assemble a list of changed parameters
5557+ for i in Rvals .get ('parmDictAfterFit' ,{}):
5558+ if i not in Rvals ['parmDictBeforeFit' ]: continue
5559+ mag = max (abs (Rvals ['parmDictAfterFit' ][i ]),
5560+ abs (Rvals ['parmDictBeforeFit' ][i ]))
5561+ diff = abs (Rvals ['parmDictAfterFit' ][i ]- Rvals ['parmDictBeforeFit' ][i ])
5562+ if mag < 1e-5 and diff < 1e-7 : continue
5563+ if diff / mag < 1e-5 : continue
5564+ txt = ''
5565+ v = G2obj .getVarDescr (i )
5566+ if v is not None and v [- 1 ] is not None :
5567+ txt = G2obj .fmtVarDescr (i )
5568+ tbl .append ((i ,Rvals ['parmDictBeforeFit' ][i ],Rvals ['parmDictAfterFit' ][i ],txt ))
5569+ lbl = f'Refinement results, Rw={ Rw :.3f} '
5570+ #ans = G2G.G2AfterFit(self,text,lbl,tbl)
5571+ text += '\n Load new result?'
5572+ dlg2 = wx .MessageDialog (self ,text ,lbl ,wx .OK | wx .CANCEL )
55725573 dlg2 .CenterOnParent ()
5574+ ans = False
55735575 try :
5574- if dlg2 .ShowModal () == wx .ID_OK :
5575- self .reloadFromGPX (rtext ,Rvals )
5576- G2IO .LogCellChanges (self )
5577- # parameter logging into notebook
5578- txt = ''
5579- if Controls .get ('LoggedVars' ) and 'parmDictAfterFit' in Rvals :
5580- txt = ''
5581- for i in sorted (Controls ['LoggedVars' ]):
5582- if i not in Rvals ['parmDictAfterFit' ]: continue
5583- if txt : txt += ', '
5584- txt += (f'{ i } : { Rvals ["parmDictAfterFit" ][i ]:.7g} ' )
5585- elif GSASIIpath .GetConfigValue ('LogAllVars' ) and 'parmDictAfterFit' in Rvals :
5586- txt = ''
5587- for c ,i in enumerate (Rvals ['parmDictvaryList' ]):
5588- if i not in Rvals ['parmDictAfterFit' ]: continue
5589- if txt : txt += ', '
5590- txt += (f'{ i } : { Rvals ["parmDictAfterFit" ][i ]:.7g} ' )
5591- if txt : self .AddToNotebook (txt ,'VALS' ,False )
5592- if refPlotUpdate :
5593- refPlotUpdate ({},restore = True )
5594- refPlotUpdate = None
5595- self .ResetPlots ()
5576+ ans = dlg2 .ShowModal ()
55965577 finally :
55975578 dlg2 .Destroy ()
5579+ if ans == wx .ID_OK : # refinement has been accepted save, log & display
5580+ self .reloadFromGPX (rtext ,Rvals )
5581+ G2IO .LogCellChanges (self )
5582+ # log parameters into notebook
5583+ txt = ''
5584+ if Controls .get ('LoggedVars' ) and 'parmDictAfterFit' in Rvals :
5585+ txt = ''
5586+ for i in sorted (Controls ['LoggedVars' ]):
5587+ if i not in Rvals ['parmDictAfterFit' ]: continue
5588+ if txt : txt += ', '
5589+ txt += (f'{ i } : { Rvals ["parmDictAfterFit" ][i ]:.7g} ' )
5590+ elif GSASIIpath .GetConfigValue ('LogAllVars' ) and 'parmDictAfterFit' in Rvals :
5591+ txt = ''
5592+ for c ,i in enumerate (Rvals ['parmDictvaryList' ]):
5593+ if i not in Rvals ['parmDictAfterFit' ]: continue
5594+ if txt : txt += ', '
5595+ txt += (f'{ i } : { Rvals ["parmDictAfterFit" ][i ]:.7g} ' )
5596+ if txt : self .AddToNotebook (txt ,'VALS' ,False )
5597+ if refPlotUpdate : # restore plot if liveplot in use
5598+ refPlotUpdate ({},restore = True )
5599+ refPlotUpdate = None
5600+ self .ResetPlots () # delete any plots that have not been updated
55985601 elif 'psing' in Rvals :
55995602 if 'msg' in Rvals :
56005603 msg = 'Refinement results:\n \n '
@@ -7601,15 +7604,28 @@ def onPlotNotebook():
76017604 pos = []
76027605 for l in data :
76037606 if '[REF]' in l : c += 1
7604- if '[VALS]' not in l : continue
7605- v = {i .split (' : ' )[0 ].strip () : i .split (' : ' )[1 ]
7606- for i in l [6 :].split (',' )}
7607- if target not in v : continue
7608- try :
7609- vals .append (float (v [target ]))
7610- pos .append (c )
7611- except :
7612- pass
7607+ if '[VALS]' in l :
7608+ v = {i .split (' : ' )[0 ].strip () : i .split (' : ' )[1 ]
7609+ for i in l [6 :].split (',' )}
7610+ if target not in v :
7611+ continue
7612+ try :
7613+ vals .append (float (v [target ]))
7614+ pos .append (c )
7615+ except :
7616+ pass
7617+ if '[CEL]' in l :
7618+ ph = l .split ('Phase' )[1 ].split ()[0 ]
7619+ hst = l .split ('Hist' )[1 ].split (':' )[0 ].strip ()
7620+ vars = [i .split ('=' )[0 ] for i in l .split (':' )[1 ].split ()]
7621+ vars = [f'{ v } [p{ ph } _h{ hst } ]' for v in vars ]
7622+ if target not in vars : continue
7623+ values = [i .split ('=' )[1 ].split ('(' )[0 ] for i in l .split (':' )[1 ].split ()]
7624+ try :
7625+ vals .append (float (dict (zip (vars ,values ))[target ]))
7626+ pos .append (c )
7627+ except :
7628+ pass
76137629 X = np .array (pos )
76147630 Y = np .array (vals )
76157631 if len (Y ) == 0 :
@@ -7686,8 +7702,13 @@ def onPlotNotebook():
76867702 # find recorded parameters
76877703 v = []
76887704 for l in data :
7689- if '[VALS]' not in l : continue
7690- v += [i .split (' : ' )[0 ].strip () for i in l [6 :].split (',' ) if i .strip ()]
7705+ if '[VALS]' in l :
7706+ v += [i .split (' : ' )[0 ].strip () for i in l [6 :].split (',' ) if i .strip ()]
7707+ if '[CEL]' in l :
7708+ ph = l .split ('Phase' )[1 ].split ()[0 ]
7709+ hst = l .split ('Hist' )[1 ].split (':' )[0 ].strip ()
7710+ vars = [i .split ('=' )[0 ] for i in l .split (':' )[1 ].split ()]
7711+ v += [f'{ v } [p{ ph } _h{ hst } ]' for v in vars ]
76917712 plotable = ['Rw' ,'GOF' ]
76927713 plotable += sorted (list (set (v )))
76937714 NBplotLbl = {'none' :True }
@@ -7749,6 +7770,8 @@ def onPlotNotebook():
77497770 # indent all but timestamps
77507771 for l in line .strip ().split ('\n ' ):
77517772 if not first : textBox .AppendText ("\n " )
7773+ if prefix == 'VALS' :
7774+ l = 'Values: ' + l .replace (' : ' ,'=' )
77527775 textBox .AppendText (' ' + l .strip ())
77537776 first = False
77547777 else :
0 commit comments