Skip to content

Commit abac2f1

Browse files
committed
fix parameter limits and improve their scripting docs, as per #254
1 parent eb0198e commit abac2f1

File tree

4 files changed

+54
-33
lines changed

4 files changed

+54
-33
lines changed

GSASII/GSASIIctrlGUI.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@
4444
#from . import GSASIIstrMain as G2stMn
4545
from . import GSASIImiscGUI as G2IO
4646
from .tutorialIndex import tutorialIndex
47-
if sys.version_info[0] >= 3:
48-
unicode = str
49-
basestring = str
5047

5148
# Define a short names for convenience
5249
DULL_YELLOW = (230,230,190)
@@ -406,7 +403,7 @@ def __init__(self,parent,loc,key,nDig=None,notBlank=True,xmin=None,xmax=None,
406403
self.type = int
407404
elif 'float' in str(type(val)):
408405
self.type = float
409-
elif isinstance(val,str) or isinstance(val,unicode):
406+
elif isinstance(val,str):
410407
self.type = str
411408
elif val is None:
412409
raise Exception("ValidatedTxtCtrl error: value of "+str(key)+
@@ -4762,11 +4759,7 @@ def __init__(self,G2frame,title,parmDict,varyList,fullVaryList,
47624759
self.frozenList = []
47634760
# make lists of variables of different types along with lists of parameter names, histogram #s, phase #s,...
47644761
self.parmNames = sorted(list(parmDict.keys()))
4765-
if '2' in platform.python_version_tuple()[0]:
4766-
basestr = basestring
4767-
else:
4768-
basestr = str
4769-
splitNames = [item.split(':') for item in self.parmNames if len(item) > 3 and not isinstance(self.parmDict[item],basestr)]
4762+
splitNames = [item.split(':') for item in self.parmNames if len(item) > 3 and not isinstance(self.parmDict[item],str)]
47704763
globNames = [':'.join(item) for item in splitNames if not item[0] and not item[1]]
47714764
if len(globNames):
47724765
self.choiceDict['Global'] = G2obj.SortVariables(globNames)
@@ -5022,11 +5015,7 @@ def __init__(self, parent):
50225015
def SetContents(self,parent):
50235016
self.varList = []
50245017
for name in parent.choiceDict[parent.parmChoice]:
5025-
if '2' in platform.python_version_tuple()[0]:
5026-
basestr = basestring
5027-
else:
5028-
basestr = str
5029-
if isinstance(parent.parmDict[name],basestr): continue
5018+
if isinstance(parent.parmDict[name],str): continue
50305019
if 'Refined' in parent.listSel and (name not in parent.fullVaryList
50315020
) and (name not in parent.varyList):
50325021
continue
@@ -5281,19 +5270,24 @@ def SetWildAfter(d,name,wname,mode):
52815270
# Callbacks to display info in table
52825271
def OnGetItemText(self, item, col):
52835272
name = self.varList[item]
5273+
atmParNam = None
5274+
if name.split(':')[2].startswith('dA'):
5275+
atmParNam = name.replace(':dA',':A')
52845276
if col == 0:
52855277
return str(item)
52865278
elif col == 1:
5279+
if atmParNam: return atmParNam
52875280
return name
52885281
elif col == 2:
52895282
if name in self.parmWin.fullVaryList and name in self.parmWin.frozenList:
5290-
return "F"
5283+
return "F"
52915284
elif name in self.parmWin.varyList:
52925285
return "R"
52935286
elif name in self.parmWin.fullVaryList:
52945287
return "C"
52955288
return ""
52965289
elif col == 3:
5290+
if atmParNam: name = atmParNam
52975291
try:
52985292
value = G2fil.FormatSigFigs(self.parmWin.parmDict[name])
52995293
except ValueError:

GSASII/GSASIIscriptable.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2843,8 +2843,12 @@ def imageMultiDistCalib(self,imageList=None,verbose=False):
28432843
return parmDict,covData
28442844

28452845
def set_Frozen(self, variable=None, histogram=None, mode='remove'):
2846-
'''Removes one or more Frozen variables (or adds one)
2847-
(See :ref:`Parameter Limits<ParameterLimits>` description.)
2846+
'''Removes one or more Frozen variables (or adds one),
2847+
where parameters are frozen after refining outside the
2848+
range where their values are allowed due to parameter
2849+
limits, when these limits are set.
2850+
(See :ref:`Parameter Limits<ParameterLimits>` description
2851+
and :meth:`G2Project.set_Controls` for setting limits.)
28482852
Note that use of this
28492853
will cause the project to be saved if not already done so.
28502854
@@ -2916,7 +2920,10 @@ def set_Frozen(self, variable=None, histogram=None, mode='remove'):
29162920
return True
29172921

29182922
def get_Frozen(self, histogram=None):
2919-
'''Gets a list of Frozen variables.
2923+
'''Gets a list of Frozen variables, where parameters are
2924+
frozen after refining outside the range where their values
2925+
are allowed due to parameter limits, when these limits are
2926+
set.
29202927
(See :ref:`Parameter Limits<ParameterLimits>` description.)
29212928
Note that use of this
29222929
will cause the project to be saved if not already done so.
@@ -3010,8 +3017,11 @@ def get_Controls(self, control, variable=None):
30103017
def set_Controls(self, control, value, variable=None):
30113018
'''Set project controls.
30123019
3013-
Note that use of this with control set to parmMin or parmMax
3014-
will cause the project to be saved if not already done so.
3020+
Controls determine how refinements are performed, including
3021+
setting lower (parmMin) or upper limits (parmMax) values
3022+
for parameters where you choose to set refinement limits.
3023+
Note that use of this with to set to parmMin or parmMax
3024+
will cause the project to be saved, if not already done so.
30153025
30163026
:param str control: the item to be set. See below for allowed values.
30173027
:param value: the value to be set.
@@ -3029,8 +3039,9 @@ def set_Controls(self, control, value, variable=None):
30293039
Ignored for non-sequential fits.
30303040
* ``'Reverse Seq'``: when True, sequential refinement is performed on the
30313041
reversed list of histograms.
3032-
* ``'parmMin'`` & ``'parmMax'``: set a maximum or minimum value for a refined
3033-
parameter. Note that variable will be a GSAS-II variable name,
3042+
* ``'parmMin'`` & ``'parmMax'``: set a minimum or maximum value
3043+
for a refined
3044+
parameter. Note that *variable* will be a GSAS-II variable name,
30343045
optionally with * specified for a histogram or atom number and
30353046
value must be a float.
30363047
(See :ref:`Parameter Limits<ParameterLimits>` description.)

GSASII/GSASIIstrMain.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -566,15 +566,15 @@ def Refine(GPXfile,dlg=None,makeBack=True,refPlotUpdate=None,newLeBail=False,all
566566
# add indirectly computed uncertainties into the esd dict
567567
sigDict.update(G2mv.ComputeDepESD(covMatrix,varyList))
568568
G2stIO.PrintIndependentVars(parmDict,varyList,sigDict,pFile=printFile)
569+
# check for variables outside their allowed range, reset and freeze them
570+
frozen = dropOOBvars(varyList,parmDict,sigDict,Controls,parmFrozenList)
569571
G2stMth.ApplyRBModels(parmDict,Phases,rigidbodyDict,True)
570572
G2stIO.SetRigidBodyModels(parmDict,sigDict,rigidbodyDict,printFile)
571573
G2stIO.SetPhaseData(parmDict,sigDict,Phases,rbIds,covData,restraintDict,printFile)
572574
G2stIO.SetISOmodes(parmDict,sigDict,Phases,printFile)
573575
G2stIO.SetHistogramPhaseData(parmDict,sigDict,Phases,Histograms,calcControls,
574576
pFile=printFile,covMatrix=covMatrix,varyList=varyList)
575577
G2stIO.SetHistogramData(parmDict,sigDict,Histograms,calcControls,pFile=printFile)
576-
# check for variables outside their allowed range, reset and freeze them
577-
frozen = dropOOBvars(varyList,parmDict,sigDict,Controls,parmFrozenList)
578578
# covData['depSig'] = G2stIO.PhFrExtPOSig # created in G2stIO.SetHistogramData, no longer used?
579579
covData['depSigDict'] = {i:(parmDict[i],sigDict[i]) for i in parmDict if i in sigDict}
580580
if len(frozen):
@@ -1201,17 +1201,20 @@ def dropOOBvars(varyList,parmDict,sigDict,Controls,parmFrozenList):
12011201
if parmMinDict or parmMaxDict:
12021202
for name in varyList:
12031203
if name not in parmDict: continue
1204+
atmParNam = name
1205+
if name.split(':')[2].startswith('dA'):
1206+
atmParNam = name.replace(':dA',':A')
12041207
n,val = G2obj.prmLookup(name,parmMinDict)
12051208
if n is not None:
1206-
if parmDict[name] < parmMinDict[n]:
1207-
parmDict[name] = parmMinDict[n]
1209+
if parmDict[atmParNam] < parmMinDict[n]:
1210+
parmDict[atmParNam] = parmMinDict[n]
12081211
sigDict[name] = 0.0
12091212
freeze.append(name)
12101213
continue
12111214
n,val = G2obj.prmLookup(name,parmMaxDict)
12121215
if n is not None:
1213-
if parmDict[name] > parmMaxDict[n]:
1214-
parmDict[name] = parmMaxDict[n]
1216+
if parmDict[atmParNam] > parmMaxDict[n]:
1217+
parmDict[atmParNam] = parmMaxDict[n]
12151218
sigDict[name] = 0.0
12161219
freeze.append(name)
12171220
continue

docs/source/GSASIIscriptable.rst

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ Class :class:`~GSASIIscriptable.G2Project`
234234
---------------------------------------------
235235

236236
All GSASIIscriptable scripts will need to create a :class:`~GSASIIscriptable.G2Project` object
237-
either for a new GSAS-II project or to read in an existing project (.gpx) file.
238-
The most commonly used routines in this object are:
237+
either for a new GSAS-II project or to read in an existing project (.gpx) file.
238+
The table below is not complete but does contain the most commonly used methods in this object:
239239

240240
.. tabularcolumns:: |l|p{3.in}|
241241

@@ -256,18 +256,26 @@ method Use
256256

257257
:meth:`~GSASIIscriptable.G2Project.add_single_histogram` Used to read in a single crystal diffraction dataset into a project file.
258258

259-
:meth:`~GSASIIscriptable.G2Project.histogram` Finds a histogram from an object, name or random id reference, returning a
260-
a :class:`~GSASIIscriptable.G2PwdrData` or :class:`~GSASIIscriptable.G2Single` object.
259+
:meth:`~GSASIIscriptable.G2Project.add_SmallAngle` Adds a small-angle scattering histogram to a project
261260

262261
:meth:`~GSASIIscriptable.G2Project.histograms` Provides a list of histograms in the current project, as :class:`~GSASIIscriptable.G2PwdrData` or
263262
as :class:`~GSASIIscriptable.G2Single` objects.
264263

264+
:meth:`~GSASIIscriptable.G2Project.histogram` Finds a histogram from an object, name or random id reference, returning a
265+
a :class:`~GSASIIscriptable.G2PwdrData` or :class:`~GSASIIscriptable.G2Single` object.
266+
265267
:meth:`~GSASIIscriptable.G2Project.histType` Determines the histogram type from an object, name or random id reference.
266268

267269
:meth:`~GSASIIscriptable.G2Project.phases` Provides a list of phases defined in the current project, as :class:`~GSASIIscriptable.G2Phase` objects
268270

271+
:meth:`~GSASIIscriptable.G2Project.phase` Finds a phase from an object, name or random id reference, returning a
272+
a :class:`~GSASIIscriptable.G2Phase` object.
273+
269274
:meth:`~GSASIIscriptable.G2Project.images` Provides a list of images in the current project, as :class:`~GSASIIscriptable.G2Image` objects
270275

276+
:meth:`~GSASIIscriptable.G2Project.image` Finds an image from an object, name or random id reference, returning a
277+
a :class:`~GSASIIscriptable.G2Image` object.
278+
271279
:meth:`~GSASIIscriptable.G2Project.pdfs` Provides a list of PDFs in the current project, as :class:`~GSASIIscriptable.G2PDF` objects
272280

273281
:meth:`~GSASIIscriptable.G2Project.seqref` Returns a :class:`~GSASIIscriptable.G2SeqRefRes` object if there are Sequential Refinement results
@@ -281,7 +289,8 @@ method Use
281289
These actions can be performed also in :meth:`~GSASIIscriptable.G2Project.do_refinements`.
282290
:meth:`~GSASIIscriptable.G2Project.get_Variable` Retrieves the value and esd for a parameter
283291
:meth:`~GSASIIscriptable.G2Project.get_Covariance` Retrieves values and covariance for a set of refined parameters
284-
:meth:`~GSASIIscriptable.G2Project.set_Controls` Set overall GSAS-II control settings such as number of cycles and to set up a sequential
292+
:meth:`~GSASIIscriptable.G2Project.set_Controls` Set overall GSAS-II control settings such as number of cycles and to set parameter limits.
293+
This is also used to set up a sequential
285294
fit. (Also see :meth:`~GSASIIscriptable.G2Project.get_Controls` to read values.)
286295
:meth:`~GSASIIscriptable.G2Project.imageMultiDistCalib` Performs a global calibration fit with images at multiple distance settings.
287296
:meth:`~GSASIIscriptable.G2Project.get_Constraints` Retrieves :ref:`constraint definition <Constraint_definitions_table>` entries.
@@ -290,6 +299,10 @@ method Use
290299
:meth:`~GSASIIscriptable.G2Project.add_EqnConstr` Adds an equation-type constraint on two or more variables
291300
:meth:`~GSASIIscriptable.G2Project.add_NewVarConstr` Adds an new variable as a constraint on two or more variables
292301
:meth:`~GSASIIscriptable.G2Project.ComputeWorstFit` Determines the parameters that will have the greatest impact on the fit if refined
302+
:meth:`~GSASIIscriptable.G2Project.get_Frozen` Find variables where parameters have refined out of the parameter limit ranges.
303+
Note that parameter limits are set using :meth:`~GSASIIscriptable.G2Project.set_Controls`.
304+
:meth:`~GSASIIscriptable.G2Project.set_Frozen` Adds or removes variables from the list where parameters have refined outside of their limits.
305+
Note that parameter limits are set using :meth:`~GSASIIscriptable.G2Project.set_Controls`.
293306
==================================================================== ===============================================================================================================
294307

295308
.. _Class_G2Phase:

0 commit comments

Comments
 (0)