Skip to content

Commit ce60e5a

Browse files
mguthriembriantoby
andauthored
Resolution lookup (#188)
* added ability to process pdabc entry in instprm to make second iParm dictionary * created extra dictionary histDict1 and passed it as an extra parameter to every function that previously had as a parameter parmDict, a large dictionary of refinable parameters that contains the original histDict * first working version that can load and apply a tabluated sig value to the regular sig parametersation for TOF * modified OnSaveAll to save extended instprm entry * ugh forgot to save some changes * remove tracing print * fix code for alp/bet lookup in plot peak widths * fix interpolation routines for single-peak fitting and alpha, beta vs Q plotting * single peak fitting: set unrefined alpha, beta & sigma from pdabc when in use --------- Co-authored-by: BHT <[email protected]>
1 parent 72c3c8a commit ce60e5a

10 files changed

+249
-92
lines changed

GSASII/GSASIIconstrGUI.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ def CheckConstraints(G2frame,Phases,Histograms,data,newcons=[],reqVaryList=None,
381381
# get Hist and HAP info
382382
hapVary, hapDict, controlDict = G2stIO.GetHistogramPhaseData(Phases, Histograms, Print=False, resetRefList=False)
383383
parmDict.update(hapDict)
384-
histVary, histDict, controlDict = G2stIO.GetHistogramData(Histograms, Print=False)
384+
histVary, histDict, histDict1, controlDict = G2stIO.GetHistogramData(Histograms, Print=False)
385385
parmDict.update(histDict)
386386

387387
# TODO: twining info needed?
@@ -1659,7 +1659,7 @@ def OnShowISODISTORT(event):
16591659
hapList += wildList
16601660
else:
16611661
hapList = wildList
1662-
histVary,histDict,controlDict = G2stIO.GetHistogramData(histDict,Print=False)
1662+
histVary,histDict,histDict1,controlDict = G2stIO.GetHistogramData(histDict,Print=False)
16631663
histList = list(histDict.keys())
16641664
histList.sort()
16651665
if seqHistList: # convert histogram # to wildcard

GSASII/GSASIIdataGUI.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5179,7 +5179,7 @@ def MakeLSParmDict(self,seqHist=None):
51795179
Natoms,atomIndx,phaseVary,phaseDict,pawleyLookup,FFtable,EFtable,ORBtables,BLtable,MFtable,maxSSwave = \
51805180
G2stIO.GetPhaseData(Phases,RestraintDict=None,rbIds=rbIds,Print=False)
51815181
hapVary,hapDict,controlDict = G2stIO.GetHistogramPhaseData(Phases,histDict,Print=False,resetRefList=False)
5182-
histVary,histDict,controlDict = G2stIO.GetHistogramData(histDict,Print=False)
5182+
histVary,histDict,histDict1, controlDict = G2stIO.GetHistogramData(histDict,Print=False)
51835183
varyList = rbVary+phaseVary+hapVary+histVary
51845184
parmDict.update(rbDict)
51855185
parmDict.update(phaseDict)

GSASII/GSASIIfiles.py

Lines changed: 98 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,55 @@ def makeInstDict(names,data,codes):
169169
inst[item] = list(inst[item])
170170
return inst
171171

172+
def makePdabcDict(pdabcString):
173+
'''
174+
if a pdabc entry is found in an instprm file, it will exist as a single string
175+
each row is delineated by a newline and must contains 5 comma separated values
176+
specifying d,TOF,alp,bet,sig.
177+
178+
This function will parse that string into a dictionary and then return it within
179+
a container dictionary
180+
'''
181+
182+
if type(pdabcString) != str:
183+
raise Exception("Error interpreting pdabc entry in .instprm file. Entry must be a string")
184+
185+
lines = pdabcString.split("\n")
186+
187+
if len(lines) == 0:
188+
print("Warning: pdabc entry found in .instprm file is empty")
189+
return {} #no information, return empty dict
190+
191+
#create empty lists to hold values
192+
d = []
193+
TOF = []
194+
alp = []
195+
bet = []
196+
sig = []
197+
nPdabc = 0
198+
for line in lines:
199+
if line: #skip empty lines
200+
entry = line.split(",")
201+
if len(entry) != 5:
202+
raise Exception("Error interpreting pdabc entry in .instprm file. Entries must have exactly 5 comma separated values")
203+
d.append(float(entry[0]))
204+
TOF.append(float(entry[1]))
205+
alp.append(float(entry[2]))
206+
bet.append(float(entry[3]))
207+
sig.append(float(entry[4]))
208+
nPdabc += 1
209+
210+
pdabcDict = {
211+
"d":d,
212+
"TOF":TOF,
213+
"alp":alp,
214+
"bet":bet,
215+
"sig":sig
216+
}
217+
218+
print(f"PDABC entry found and {nPdabc} lines successfully loaded")
219+
return {"pdabc":pdabcDict}
220+
172221
def SetPowderInstParms(Iparm, rd):
173222
'''extracts values from instrument parameters in rd.instdict
174223
or in array Iparm.
@@ -292,16 +341,21 @@ def SetPowderInstParms(Iparm, rd):
292341
Inst1 = makeInstDict(names,data,codes)
293342
Inst1['Bank'] = [Bank,Bank,0]
294343
Inst2 = {}
344+
295345
if pfType < 0:
296346
Ipab = 'INS 1PAB'+str(-pfType)
347+
key = Ipab+' '
348+
print("looking for key: ", key)
297349
Npab = int(Iparm[Ipab+' '].strip())
298-
Inst2['Pdabc'] = []
350+
Inst2['pdabc'] = []
299351
for i in range(Npab):
300352
k = Ipab+str(i+1).rjust(2)
301353
s = Iparm[k].split()
302-
Inst2['Pdabc'].append([float(t) for t in s])
303-
Inst2['Pdabc'] = np.array(Inst2['Pdabc'])
304-
Inst2['Pdabc'].T[3] += Inst2['Pdabc'].T[0]*Inst1['difC'][0] #turn 3rd col into TOF
354+
Inst2['pdabc'].append([float(t) for t in s])
355+
Inst2['pdabc'] = np.array(Inst2['pdabc'])
356+
Inst2['pdabc'].T[3] += Inst2['pdabc'].T[0]*Inst1['difC'][0] #turn 3rd col into TOF
357+
358+
print(f"loaded resolution data with {Inst2['pdabc'].shape} shape" )
305359
if 'INS 1I ITYP' in Iparm:
306360
s = Iparm['INS 1I ITYP'].split()
307361
Ityp = int(s[0])
@@ -356,7 +410,8 @@ def ReadInstprm(instLines, bank, Sample={}):
356410
determined by instrument settings or information
357411
from the instprm file are placed here.
358412
:returns: bank,instdict where bank is the sample parameter set
359-
number and instdict is the instrument parameter dict
413+
number and instdict is a list containing the regular instrument parameter dict
414+
and the "extended" dict, currently only containing pdabc entries (if they exist)
360415
361416
Note if 'Type' is set as Debye-Scherrer or Bragg-Brentano this will be used and
362417
will set defaults in the sample parameters. Otherwise, a single-wavelength file
@@ -461,21 +516,33 @@ def ReadInstprm(instLines, bank, Sample={}):
461516
Sample.update({'Type':'Debye-Scherrer','Absorption':[0.,False],'DisplaceX':[0.,False],
462517
'DisplaceY':[0.,False]})
463518
Sample.update(NewSample)
464-
return bank,[makeInstDict(newItems, newVals, len(newVals)*[False]), {}]
465519

466-
def WriteInstprm(fp, InstPrm, Sample={}, bank=None):
520+
#if pdabc exists, process it, then delete from original lists
521+
if "pdabc" in newItems:
522+
idx = newItems.index('pdabc')
523+
iparm1 = makePdabcDict(newVals[idx]) #returns new dictionary with pdabc data
524+
del newItems[idx]
525+
del newVals[idx]
526+
else:
527+
iparm1 = {}
528+
529+
return bank,[makeInstDict(newItems, newVals, len(newVals)*[False]), iparm1]
530+
531+
def WriteInstprm(fp, InstPrm, InstPrm1, Sample={}, bank=None):
467532
'''Write the contents of a GSAS-II (new) .instprm instrument parameter file
468533
ToDo: use this inside G2frame.OnSave and G2frame.OnSaveAll
469534
470535
:param file fp: Pointer to open file to be written.
471536
:param dict InstPrm: Instrument parameters
537+
:param dict InstPrm1: "extended" instrument parameters
472538
:param dict Sample: Sample parameters (optional)
473539
:param int bank: Bank number. If not None (default), this causes
474540
a "#Bank" heading to be placed in the file before the
475541
parameters are written.
476542
'''
477543
if bank is not None:
478-
fp.write(f"#Bank {bank}: GSAS-II instrument parameter file; do not add/delete items!\n")
544+
#somehow, somewhere bank is becoming a float. Ensure it is an int here:
545+
fp.write(f"#Bank {int(bank)}: GSAS-II instrument parameter file; do not add/delete items!\n")
479546
indent = ' '
480547
else:
481548
fp.write("#GSAS-II instrument parameter file; do not add/delete items!\n")
@@ -490,6 +557,28 @@ def WriteInstprm(fp, InstPrm, Sample={}, bank=None):
490557
if not Sample.get(item): continue
491558
fp.write(f"{indent}{item}:{Sample[item]}\n")
492559

560+
# handle pdabc entries.
561+
if InstPrm1:
562+
if "pdabc" in InstPrm1:
563+
564+
#extract lists from InstPrm1["pdabc"] dictionary
565+
d = InstPrm1["pdabc"]["d"]
566+
tof = InstPrm1["pdabc"]["TOF"]
567+
alp = InstPrm1["pdabc"]["alp"]
568+
bet = InstPrm1["pdabc"]["bet"]
569+
sig = InstPrm1["pdabc"]["sig"]
570+
571+
#build output string
572+
i = 0
573+
resString = f"pdabc:\"\"\"{d[i]:.4f}, {tof[i]:8.1f}, {alp[i]:8.6f}, {bet[i]:8.6f}, {sig[i]:8.6f}\n"
574+
for i in range(1,len(d)-1):
575+
resString+=f"{d[i]:7.4f}, {tof[i]:8.1f}, {alp[i]:8.6f}, {bet[i]:8.6f}, {sig[i]:8.6f}\n"
576+
577+
resString+=f"{d[-1]:7.4f}, {tof[-1]:8.1f}, {alp[-1]:8.6f}, {bet[-1]:8.6f}, {sig[-1]:8.6f}\"\"\"\n"
578+
579+
#write output string
580+
fp.write(resString)
581+
493582
# version of LoadImportRoutines from before switch to "main"
494583
# def _old_LoadImportRoutines(prefix, errprefix=None, traceback=False):
495584
# '''Routine to locate GSASII importers matching a prefix string.
@@ -1966,7 +2055,7 @@ def loadParmDict(self,computeSU=False):
19662055
self.parmDict.update(phaseDict)
19672056
hapVary,hapDict,controlDict = G2stIO.GetHistogramPhaseData(Phases,Histograms,Print=False,resetRefList=False)
19682057
self.parmDict.update(hapDict)
1969-
histVary,histDict,controlDict = G2stIO.GetHistogramData(Histograms,Print=False)
2058+
histVary,histDict,histDict1, controlDict = G2stIO.GetHistogramData(Histograms,Print=False)
19702059
self.parmDict.update(histDict)
19712060
self.parmDict.update(zip(
19722061
covDict.get('varyList',[]),

GSASII/GSASIImath.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5123,18 +5123,19 @@ def setPeakparms(Parms,Parms2,pos,mag,ifQ=False,useFit=False):
51235123
pos = Parms['difC']*dsp
51245124
else:
51255125
dsp = pos/Parms['difC'][1]
5126-
if 'Pdabc' in Parms2:
5126+
if 'pdabc' in Parms2 and len(Parms2['pdabc']):
51275127
for x in ['sig-0','sig-1','sig-2','sig-q','X','Y','Z']:
51285128
ins[x] = Parms.get(x,[0.0,0.0])[ind]
5129-
Pdabc = Parms2['Pdabc'].T
5130-
alp = np.interp(dsp,Pdabc[0],Pdabc[1])
5131-
bet = np.interp(dsp,Pdabc[0],Pdabc[2])
5129+
Pdabc = Parms2['pdabc']
5130+
alp = np.interp(dsp,Pdabc['d'],Pdabc['alp'])
5131+
bet = np.interp(dsp,Pdabc['d'],Pdabc['bet'])
5132+
sig = np.interp(dsp,Pdabc['d'],Pdabc['sig'])
51325133
else:
51335134
for x in ['alpha','beta-0','beta-1','beta-q','sig-0','sig-1','sig-2','sig-q','X','Y','Z']:
51345135
ins[x] = Parms.get(x,[0.0,0.0])[ind]
51355136
alp = getTOFalpha(ins,dsp)
51365137
bet = getTOFbeta(ins,dsp)
5137-
sig = getTOFsig(ins,dsp)
5138+
sig = getTOFsig(ins,dsp)
51385139
gam = getTOFgamma(ins,dsp)
51395140
XY = [pos,0,mag,1,alp,0,bet,0,sig,0,gam,0]
51405141
elif 'C' in Parms['Type'][0] or 'LF' in Parms['Type'][0]:

GSASII/GSASIImiscGUI.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,7 @@ def mkParmDictfromTree(G2frame,sigDict=None):
13171317
parmDict.update(phaseDict)
13181318
hapVary,hapDict,controlDict = G2stIO.GetHistogramPhaseData(Phases,Histograms,Print=False,resetRefList=False)
13191319
parmDict.update(hapDict)
1320-
histVary,histDict,controlDict = G2stIO.GetHistogramData(Histograms,Print=False)
1320+
histVary,histDict,histDict1, controlDict = G2stIO.GetHistogramData(Histograms,Print=False)
13211321
parmDict.update(histDict)
13221322
parmDict.update(zip(
13231323
covDict.get('varyList',[]),

0 commit comments

Comments
 (0)