- Timestamp:
- Sep 28, 2020 1:23:10 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIdataGUI.py
r4573 r4578 5037 5037 lamMax = Msg.get('lamMax',0.001) 5038 5038 lst = os.path.splitext(os.path.abspath(self.GSASprojectfile))[0] 5039 text = 'Detailed results are in ' + lst + '.lst\n\nLoad new result?' 5039 text = 'Detailed results are in ' + lst + '.lst\n' 5040 if 'GOF0' in Msg and 'GOF' in Msg: 5041 text += '\nReduced Chi^2 before refinement={:.3f} and after={:.3f}\n'.format( 5042 Msg['GOF0']**2,Msg['GOF']**2) 5043 if 'Max shft/sig' in Msg: 5044 text += '\nMax shift/sigma={:.3f}\n'.format(Msg['Max shft/sig']) 5045 if 'msg' in Msg: text += '\n' + Msg['msg'] + '\n' 5046 text += '\nLoad new result?' 5040 5047 if lamMax >= 10.: 5041 5048 text += '\nWARNING: Steepest descents dominates;'+ \ -
trunk/GSASIImath.py
r4560 r4578 166 166 Lam = np.zeros((n,n)) 167 167 Xvec = np.zeros(len(x0)) 168 chisq00 = None 168 169 while icycle < maxcyc: 169 170 time0 = time.time() … … 172 173 nfev += 1 173 174 chisq0 = np.sum(M**2) 175 if chisq00 is None: chisq00 = chisq0 174 176 Yvec,Amat = Hess(x0,*args) 175 177 Adiag = np.sqrt(np.diag(Amat)) … … 234 236 Bmat = Bmat/Anorm 235 237 return [x0,Bmat,{'num cyc':icycle,'fvec':M,'nfev':nfev,'lamMax':lamMax,'psing':[], 236 'SVD0':Nzero,'Converged': ifConverged, 'DelChi2':deltaChi2,'Xvec':Xvec }]238 'SVD0':Nzero,'Converged': ifConverged, 'DelChi2':deltaChi2,'Xvec':Xvec, 'chisq0':chisq00}] 237 239 except nl.LinAlgError: 238 240 G2fil.G2Print('ouch #2 linear algebra error in making v-cov matrix', mode='error') … … 240 242 if maxcyc: 241 243 psing = list(np.where(np.diag(nl.qr(Amat)[1]) < 1.e-14)[0]) 242 return [x0,None,{'num cyc':icycle,'fvec':M,'nfev':nfev,'lamMax':lamMax,'psing':psing,'SVD0':-1,'Xvec':None }]244 return [x0,None,{'num cyc':icycle,'fvec':M,'nfev':nfev,'lamMax':lamMax,'psing':psing,'SVD0':-1,'Xvec':None, 'chisq0':chisq00}] 243 245 244 246 def HessianSVD(func,x0,Hess,args=(),ftol=1.49012e-8,xtol=1.e-6, maxcyc=0,lamda=-3,Print=False,refPlotUpdate=None): … … 298 300 if Print: 299 301 G2fil.G2Print(' Hessian SVD refinement on %d variables:'%(n)) 302 chisq00 = None 300 303 while icycle < maxcyc: 301 304 time0 = time.time() … … 303 306 nfev += 1 304 307 chisq0 = np.sum(M**2) 308 if chisq00 is None: chisq00 = chisq0 305 309 Yvec,Amat = Hess(x0,*args) 306 310 Adiag = np.sqrt(np.diag(Amat)) … … 347 351 Bmat = Bmat/Anorm 348 352 return [x0,Bmat,{'num cyc':icycle,'fvec':M,'nfev':nfev,'lamMax':0.,'psing':[], 349 'SVD0':Nzero,'Converged': ifConverged, 'DelChi2':deltaChi2}] 353 'SVD0':Nzero,'Converged': ifConverged, 'DelChi2':deltaChi2, 354 'chisq0':chisq00}] 350 355 except nl.LinAlgError: 351 356 G2fil.G2Print('ouch #2 linear algebra error in making v-cov matrix', mode='error') … … 353 358 if maxcyc: 354 359 psing = list(np.where(np.diag(nl.qr(Amat)[1]) < 1.e-14)[0]) 355 return [x0,None,{'num cyc':icycle,'fvec':M,'nfev':nfev,'lamMax':0.,'psing':psing,'SVD0':-1}] 360 return [x0,None,{'num cyc':icycle,'fvec':M,'nfev':nfev,'lamMax':0.,'psing':psing,'SVD0':-1, 361 'chisq0':chisq00}] 356 362 357 363 def getVCov(varyNames,varyList,covMatrix): -
trunk/GSASIIobj.py
r4534 r4578 1141 1141 1142 1142 1143 .. _ParameterLimits: 1144 1145 .. index:: 1146 single: Parameter limits 1147 1148 Parameter Limits 1149 ------------------------------ 1150 1151 One of the most often requested "enhancements" for GSAS-II would be the inclusion 1152 of constraints to force parameters such as occupancies or Uiso values to stay within 1153 expected ranges. While it is possible for users to supply their own restraints that would 1154 perform this by supplying an appropriate expression with the "General" restraints, the 1155 GSAS-II authors do not feel that use of restraints or constraints are a good solution for 1156 this common problem where parameters refine to non-physical values. This is because when 1157 this occurs, most likely one of the following cases is occurring: 1158 1159 #. there is a significant problem 1160 with the model, for example for an x-ray fit if an O atom is placed where a S is actually 1161 present, the Uiso will refine artificially small or the occupancy much larger than unity 1162 to try to compensate for the missing electrons; or 1163 1164 #. the data are simply insensitive 1165 to the parameter or combination of parameters, for example unless very high-Q data 1166 are included, the effects of a occupancy and Uiso value can have compensating effects, 1167 so an assumption must be made; likewise, with neutron data natural-abundance V atoms 1168 are nearly invisible due to weak coherent scattering. No parameters can be fit for a 1169 V atom with neutrons. 1170 1171 #. the parameter is non-physical (such as a negative Uiso value) but within 1172 two sigma (sigma = standard uncertainty, aka e.s.d.) of a reasonable value, 1173 in which case the 1174 value is not problematic as it is experimentally indistinguishable from an 1175 expected value. 1176 1177 #. there is a systematic problem with the data (experimental error) 1178 1179 In all these cases, this situation needs to be reviewed by a crystallographer to decide 1180 how to best determine a structural model for these data. An implementation with a constraint 1181 or restraint is likely to simply hide the problem from the user, making it more probable 1182 that a poor model choice is obtained. 1183 1184 What GSAS-II does implement is to allow users to specify ranges for parameters 1185 that works by disabling 1186 refinement of parameters that refine beyond either a lower limit or an upper limit, where 1187 either or both may be optionally specified. Parameters limits are specified in the Controls 1188 tree entry in dicts named as ``Controls['parmMaxDict']`` and ``Controls['parmMinDict']``, where 1189 the keys are named using the standard GSAS-II variable 1190 (see :func:`getVarDescr` and :func:`CompileVarDesc`) or with a variable name, where a 1191 wildcard ('*') is used for histogram number or atom number (phase number is intentionally not 1192 allowed as a wildcard as it makes little sense to group together different phases). Note 1193 that func:`prmLookup` is used to see if a name matches a wildcard. The upper or lower limit 1194 is placed into these dicts as a float value. These values can be edited using the window 1195 created by the Calculate/"View LS parms" menu command or in scripting with the 1196 :meth:`GSASIIscriptable.G2Project.set_Controls` function. 1197 In the GUI, a checkbox labeled "match all histograms/atoms" is used to insert a wildcard 1198 into the appropriate part of the variable name. 1199 1200 When a refinement is conducted, routine :func:`GSASIIstrMain.dropOOBvars` is used to 1201 find parameters that have refined to values outside their limits. If this occurs, the parameter 1202 is set to the limiting value and the variable name is added to a list of frozen variables kept in the 1203 ``Controls['parmFrozen']`` dict. In a sequential refinement, this is kept as a list in 1204 ``Controls['parmFrozen'][histogram]`` (where the key is the histogram name) or in 1205 ``Controls['parmFrozen']['FrozenList']`` for a non-sequential fit. 1206 This allows different variables 1207 to be frozen in each section of a sequential fit. 1208 Frozen parameters are not included in refinements through removal from the 1209 list of parameters to be refined (``varyList``) in :func:`GSASIIstrMain.Refine` or 1210 :func:`GSASIIstrMain.SeqRefine`. Once a variable is frozen, it will not be refined in any 1211 future refinements unless the the variable is removed (manually) from the list. This can also 1212 be done with the Calculate/"View LS parms" menu window or ... 1213 1143 1214 *Classes and routines* 1144 1215 ---------------------- -
trunk/GSASIIplot.py
r4573 r4578 209 209 timeDebug = GSASIIpath.GetConfigValue('Show_timing',False) 210 210 obsInCaption = True # include the observed, calc,... items in the plot caption (PlotPatterns) 211 mplv = eval(mpl.__version__.replace('.',','))212 211 213 212 #matplotlib 2.0.x dumbed down Paired to 16 colors - … … 333 332 334 333 def ToolBarDraw(self): 334 mplv = eval(mpl.__version__.replace('.',',')) 335 335 if mplv[0] >= 3 and mplv[1] >= 3: 336 336 self.toolbar.canvas.draw_idle() … … 10575 10575 10576 10576 def SetupLegendPick(legend,new,delay=5): 10577 mplv = eval(mpl.__version__.replace('.',',')) 10577 10578 legend.delay = delay*1000 # Hold time in ms for clear; 0 == forever 10578 10579 for line in legend.get_lines(): -
trunk/GSASIIpwdGUI.py
r4567 r4578 1520 1520 1521 1521 def OnPeaks(event): 1522 'Respond to a change in the number of background peaks' 1522 1523 data[1]['nPeaks'] = int(peaks.GetValue()) 1523 1524 M = len(data[1]['peaksList']) … … 1531 1532 if N == 0: 1532 1533 CalcBack(G2frame.PatternId) 1533 G2plt.PlotPatterns(G2frame,plotType='PWDR') 1534 G2plt.PlotPatterns(G2frame,plotType='PWDR') 1535 # this callback is crashing wx when there is an open 1536 # peaksGrid cell editor, at least on Mac. Code below 1537 # should fix this, but it does not. 1538 # https://stackoverflow.com/questions/64082199/wxpython-grid-destroy-with-open-celleditor-crashes-python-even-with-disablece 1539 if peaksGrid and peaksGrid.IsCellEditControlEnabled(): 1540 # complete any grid edits in progress 1541 #print('closing') 1542 peaksGrid.HideCellEditControl() 1543 peaksGrid.DisableCellEditControl() 1544 #wx.CallLater(100,peaksGrid.Destroy) # crashes python 1534 1545 wx.CallAfter(UpdateBackground,G2frame,data) 1535 1546 … … 1567 1578 peaksSizer.Add(topSizer) 1568 1579 G2frame.dataWindow.currentGrids = [] 1580 peaksGrid = None 1569 1581 if data[1]['nPeaks']: 1570 1582 peaksSizer.Add(wx.StaticText(G2frame.dataWindow,-1,' Peak list:'),0,WACV) -
trunk/GSASIIscriptable.py
r4551 r4578 3360 3360 raise Exception('{} is an invalid control value'.format(control)) 3361 3361 3362 def set_Controls(self, control, value ):3362 def set_Controls(self, control, value, variable=None): 3363 3363 '''Set project controls 3364 3364 3365 3365 :param str control: the item to be set. See below for allowed values. 3366 3366 :param value: the value to be set. 3367 :param str variable: used only with control set to "parmMin" or "parmMax" 3367 3368 3368 3369 Allowed values for parameter control: … … 3378 3379 * Reverse Seq: when True, sequential refinement is performed on the 3379 3380 reversed list of histograms. 3381 * parmMin & parmMax: set a maximum or minimum value for a refined 3382 parameter. Note that variable will be a GSAS-II variable name, 3383 optionally with * specified for a histogram or atom number and 3384 value must be a float. 3385 (See :ref:`Parameter Limits<ParameterLimits>` description.) 3380 3386 3381 3387 .. seealso:: 3382 3388 :meth:`get_Controls` 3383 3389 ''' 3390 if control.startswith('parmM'): 3391 if not variable: 3392 raise Exception('set_Controls requires a value for variable for control=parmMin or parmMax') 3393 for key in ('parmMinDict','parmMaxDict','parmFrozen'): 3394 if key not in self.data['Controls']['data']: self.data['Controls']['data'][key] = {} 3384 3395 if control == 'cycles': 3385 3396 self.data['Controls']['data']['max cyc'] = int(value) … … 3398 3409 .format(i,j)) 3399 3410 self.data['Controls']['data']['Seq Data'] = histlist 3411 elif control == 'parmMin' or control == 'parmMax': 3412 self.data['Controls']['data'][control+'Dict'][variable] = float(value) 3400 3413 else: 3401 3414 raise Exception('{} is an invalid control value'.format(control)) -
trunk/GSASIIstrMain.py
r4534 r4578 61 61 ifPrint = False 62 62 Rvals = {} 63 chisq0 = None 63 64 while True: 64 65 begin = time.time() … … 91 92 Rvals['lamMax'] = result[2]['lamMax'] 92 93 Controls['Marquardt'] = -3 #reset to default 94 if 'chisq0' in result[2] and chisq0 is None: 95 chisq0 = result[2]['chisq0'] 93 96 elif 'Hessian SVD' in Controls['deriv type']: 94 97 maxCyc = Controls['max cyc'] … … 102 105 break 103 106 ncyc = result[2]['num cyc']+1 107 if 'chisq0' in result[2] and chisq0 is None: 108 chisq0 = result[2]['chisq0'] 104 109 else: #'numeric' 105 110 result = so.leastsq(G2stMth.errRefine,values,full_output=True,ftol=Ftol,epsfcn=1.e-8,factor=Factor, … … 182 187 if IfOK: 183 188 G2stMth.GetFobsSq(Histograms,Phases,parmDict,calcControls) 189 if chisq0 is not None: 190 Rvals['GOF0'] = np.sqrt(chisq0/(Histograms['Nobs']-len(varyList))) 184 191 return IfOK,Rvals,result,covMatrix,sig 185 192 … … 293 300 G2stIO.SetHistogramPhaseData(parmDict,sigDict,Phases,Histograms,calcControls['FFtables'],pFile=printFile) 294 301 G2stIO.SetHistogramData(parmDict,sigDict,Histograms,calcControls['FFtables'],pFile=printFile) 295 if len(frozen) > 0: 296 G2fil.G2Print( 297 ' {} variables were outside limits and were frozen (now {} frozen total)\n' 298 .format(len(frozen),len(parmFrozenList))) 302 if len(frozen): 303 msg = ('Warning: {} variable(s) refined outside limits and were frozen ({} total frozen)' 304 .format(len(frozen),len(parmFrozenList)) 305 ) 306 G2fil.G2Print(msg) 307 Rvals['msg'] = msg 308 elif len(parmFrozenList): 309 msg = ('Note: a total of {} variable(s) are frozen due to refining outside limits' 310 .format(len(parmFrozenList)) 311 ) 312 G2fil.G2Print('Note: ',msg) 313 Rvals['msg'] = msg 299 314 G2stIO.SetUsedHistogramsAndPhases(GPXfile,Histograms,Phases,rigidbodyDict,covData,parmFrozenList,makeBack) 300 315 printFile.close() -
trunk/atmdata.py
r4337 r4578 1190 1190 'N':[ 1.8845, 9.161, 2.0746, 4.042, -.1318, 1.723, .0000, .000, .0020, 2.00]}, 1191 1191 } 1192 ''' 1193 unused j<0> 1192 1193 pass # placed here so that the following is not processed by Sphinx as a doc string 1194 ''' # unused unused terms follow 1195 j<0> 1194 1196 W_6s15d5 FFj0A=0.3811 FFj0a=62.707 FFj0B=0.7523 FFj0b=21.434 FFj0C=12.5449 FFj0c=2.702 FFj0D=12.4130 FFj0d=2.674 FFj0E=0.0023 0.0365 1195 1197 W_6s25d4 FFj0A=0.3653 FFj0a=53.965 FFj0B=0.7926 FFj0b=20.078 FFj0C=0.8142 FFj0c=3.030 FFj0D=0.6581 FFj0d=2.476 FFj0E=0.0023 0.0247 -
trunk/defaultIparms.py
r3157 r4578 34 34 defaultIparm_lbl = [] 35 35 defaultIparms = [] 36 37 pass # placed here so that the following is not processed by Sphinx as a doc string 36 38 ''' the phrase 'lab data' in the following makes the default goniometer type='Bragg-Brentano' 37 39 otherwise it is set to 'Debye-Scherrer'
Note: See TracChangeset
for help on using the changeset viewer.