Skip to content

Commit 5e1207e

Browse files
committed
revise parameter logging; prepare to show parameter shifts after fit
1 parent abd9a56 commit 5e1207e

2 files changed

Lines changed: 39 additions & 20 deletions

File tree

GSASII/GSASIIdataGUI.py

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5538,33 +5538,57 @@ def OnRefine(self,event):
55385538
rtext = 'LS Refinement: Rw = %.3f%%, GOF = %.2f, Nobs = %d, Nvar = %d'%(Rvals['Rwp'],Rvals['GOF'],Rvals['Nobs'],Rvals['Nvars'])
55395539
lamMax = Rvals.get('lamMax',0.001)
55405540
lst = os.path.splitext(os.path.abspath(self.GSASprojectfile))[0]
5541-
text = 'Detailed results are in ' + lst + '.lst\n'
5541+
text = f'Detailed results are in file {os.path.split(lst)[1]}.lst in directory {os.path.split(lst)[0]}\n'
55425542
if 'GOF0' in Rvals and 'GOF' in Rvals:
5543-
text += '\nFinal Reduced Chi^2: {:.3f} (before ref: {:.3f})\n'.format(
5544-
Rvals['GOF']**2,Rvals['GOF0']**2)
5543+
text += f"\nFinal Reduced Chi^2: {Rvals['GOF']**2:.3f}"
5544+
text += f"\n (before refinement: {Rvals['GOF0']**2:.3f})\n"
55455545
if Rvals.get('Max shft/sig') is not None:
55465546
rtext += ', Max delt/sig = {:.3f}'.format(Rvals['Max shft/sig'])
55475547
text += '\nMax shift/sigma={:.3f}\n'.format(Rvals['Max shft/sig'])
55485548
if 'msg' in Rvals: text += '\n' + Rvals['msg'] + '\n'
55495549
if 'Aborted' in Rvals:
55505550
text += '\nWARNING: Minimizer halted because chi**2 increased\n'
55515551
if lamMax >= 10.:
5552-
text += '\nWARNING: Steepest descents dominates;'+ \
5553-
' minimum may not have been reached or result may be false minimum.'+ \
5554-
' You should reconsider which parameters you refine. Check covariance matrix.\n'
5552+
text += ('\nWARNING: Marquardt factor raised to point where steepest descents dominates fitting;'+
5553+
' minimum may not have been reached or your result may be a false minimum.'+
5554+
' You should reconsider which parameters you refine: check covariance matrix.\n')
55555555
text += '\nLoad new result?'
5556-
dlg2 = wx.MessageDialog(self,text,'Refinement results, Rw =%.3f'%(Rw),wx.OK|wx.CANCEL)
5556+
#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)
55575572
dlg2.CenterOnParent()
55585573
try:
55595574
if dlg2.ShowModal() == wx.ID_OK:
55605575
self.reloadFromGPX(rtext,Rvals)
55615576
G2IO.LogCellChanges(self)
5562-
if Rvals.get('LoggedVals'):
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:
55635586
txt = ''
5564-
for p,v in Rvals['LoggedVals'].items():
5587+
for c,i in enumerate(Rvals['parmDictvaryList']):
5588+
if i not in Rvals['parmDictAfterFit']: continue
55655589
if txt: txt += ', '
5566-
txt += (f'{p} : {v:.7g}')
5567-
self.AddToNotebook(txt,'VALS',False)
5590+
txt += (f'{i} : {Rvals["parmDictAfterFit"][i]:.7g}')
5591+
if txt: self.AddToNotebook(txt,'VALS',False)
55685592
if refPlotUpdate:
55695593
refPlotUpdate({},restore=True)
55705594
refPlotUpdate = None

GSASII/GSASIIstrMain.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ def Refine(GPXfile,dlg=None,makeBack=True,refPlotUpdate=None,newLeBail=False,all
544544
printFile.write(135*'-'+'\n')
545545
Rvals = {}
546546
G2mv.Dict2Map(parmDict) # impose constraints initially
547+
parmDictBefore = copy.deepcopy(parmDict)
547548
if allDerivs: #============= develop partial derivative map
548549
derivDict = AllPrmDerivs(Controls, Histograms, Phases, restraintDict,
549550
rigidbodyDict, parmDict, varyList, calcControls,pawleyLookup,symHold,dlg)
@@ -641,15 +642,9 @@ def Refine(GPXfile,dlg=None,makeBack=True,refPlotUpdate=None,newLeBail=False,all
641642

642643
# document the refinement further: RB, constraints, restraints, what's varied
643644
Rvals['varyList'] = 'Varied: ' + ', '.join(varyList)
644-
newValDict = {}
645-
if Controls.get('LoggedVars'): # parameter logging
646-
newValDict = {i:float(parmDict[i]) for i in
647-
sorted(Controls['LoggedVars'])
648-
if i in parmDict}
649-
elif GSASIIpath.GetConfigValue('LogAllVars'):
650-
newValDict = {i:float(parmDict[i]) for c,i in enumerate(varyList)
651-
if c<50 and i in parmDict}
652-
if newValDict: Rvals['LoggedVals'] = newValDict
645+
Rvals['parmDictBeforeFit'] = parmDictBefore
646+
Rvals['parmDictAfterFit'] = copy.deepcopy(parmDict)
647+
Rvals['parmDictvaryList'] = copy.copy(varyList)
653648
s = G2mv.VarRemapSumm()
654649
if s: Rvals['contrSumm'] = f'Constraints: {s}'
655650
Rvals['restrSumm'] = G2stIO.SummRestraints(restraintDict)

0 commit comments

Comments
 (0)