Skip to content

Commit 50a9273

Browse files
committed
modified OnSaveAll to save extended instprm entry
1 parent 9e5bfce commit 50a9273

File tree

5 files changed

+45
-16
lines changed

5 files changed

+45
-16
lines changed

GSASII/GSASIIconstrGUI.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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/GSASIIfiles.py

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def makePdabcDict(pdabcString):
147147

148148
#create empty lists to hold values
149149
d = []
150-
ToF = []
150+
TOF = []
151151
alp = []
152152
bet = []
153153
sig = []
@@ -158,15 +158,15 @@ def makePdabcDict(pdabcString):
158158
if len(entry) != 5:
159159
raise Exception("Error interpreting pdabc entry in .instprm file. Entries must have exactly 5 comma separated values")
160160
d.append(float(entry[0]))
161-
ToF.append(float(entry[1]))
161+
TOF.append(float(entry[1]))
162162
alp.append(float(entry[2]))
163163
bet.append(float(entry[3]))
164164
sig.append(float(entry[4]))
165165
nPdabc += 1
166166

167167
pdabcDict = {
168168
"d":d,
169-
"TOF":ToF,
169+
"TOF":TOF,
170170
"alp":alp,
171171
"bet":bet,
172172
"sig":sig
@@ -304,15 +304,15 @@ def SetPowderInstParms(Iparm, rd):
304304
key = Ipab+' '
305305
print("looking for key: ", key)
306306
Npab = int(Iparm[Ipab+' '].strip())
307-
Inst2['Pdabc'] = []
307+
Inst2['pdabc'] = []
308308
for i in range(Npab):
309309
k = Ipab+str(i+1).rjust(2)
310310
s = Iparm[k].split()
311-
Inst2['Pdabc'].append([float(t) for t in s])
312-
Inst2['Pdabc'] = np.array(Inst2['Pdabc'])
313-
Inst2['Pdabc'].T[3] += Inst2['Pdabc'].T[0]*Inst1['difC'][0] #turn 3rd col into TOF
311+
Inst2['pdabc'].append([float(t) for t in s])
312+
Inst2['pdabc'] = np.array(Inst2['pdabc'])
313+
Inst2['pdabc'].T[3] += Inst2['pdabc'].T[0]*Inst1['difC'][0] #turn 3rd col into TOF
314314

315-
print(f"loaded resolution data with {Inst2['Pdabc'].shape} shape" )
315+
print(f"loaded resolution data with {Inst2['pdabc'].shape} shape" )
316316
if 'INS 1I ITYP' in Iparm:
317317
s = Iparm['INS 1I ITYP'].split()
318318
Ityp = int(s[0])
@@ -367,7 +367,8 @@ def ReadInstprm(instLines, bank, Sample={}):
367367
determined by instrument settings or information
368368
from the instprm file are placed here.
369369
:returns: bank,instdict where bank is the sample parameter set
370-
number and instdict is the instrument parameter dict
370+
number and instdict is a list containing the regular instrument parameter dict
371+
and the "extended" dict, currently only containing pdabc entries (if they exist)
371372
372373
Note if 'Type' is set as Debye-Scherrer or Bragg-Brentano this will be used and
373374
will set defaults in the sample parameters. Otherwise, a single-wavelength file
@@ -484,12 +485,13 @@ def ReadInstprm(instLines, bank, Sample={}):
484485

485486
return bank,[makeInstDict(newItems, newVals, len(newVals)*[False]), iparm1]
486487

487-
def WriteInstprm(fp, InstPrm, Sample={}, bank=None):
488+
def WriteInstprm(fp, InstPrm, InstPrm1, Sample={}, bank=None):
488489
'''Write the contents of a GSAS-II (new) .instprm instrument parameter file
489490
ToDo: use this inside G2frame.OnSave and G2frame.OnSaveAll
490491
491492
:param file fp: Pointer to open file to be written.
492493
:param dict InstPrm: Instrument parameters
494+
:param dict InstPrm1: "extended" instrument parameters
493495
:param dict Sample: Sample parameters (optional)
494496
:param int bank: Bank number. If not None (default), this causes
495497
a "#Bank" heading to be placed in the file before the
@@ -510,6 +512,28 @@ def WriteInstprm(fp, InstPrm, Sample={}, bank=None):
510512
for item in ('Gonio. radius','InstrName'):
511513
if not Sample.get(item): continue
512514
fp.write(f"{indent}{item}:{Sample[item]}\n")
515+
516+
#handle pdabc entries.
517+
if InstPrm1:
518+
if "pdabc" in InstPrm1:
519+
520+
#extract lists from InstPrm1["pdabc"] dictionary
521+
d = InstPrm1["pdabc"]["d"]
522+
tof = InstPrm1["pdabc"]["TOF"]
523+
alp = InstPrm1["pdabc"]["alp"]
524+
bet = InstPrm1["pdabc"]["bet"]
525+
sig = InstPrm1["pdabc"]["sig"]
526+
527+
#build output string
528+
i = 0
529+
resString = f"pdabc:\"\"\"{d[i]:.4f}, {tof[i]:8.1f}, {alp[i]:8.6f}, {bet[i]:8.6f}, {sig[i]:8.6f}\n"
530+
for i in range(1,len(d)-1):
531+
resString+=f"{d[i]:7.4f}, {tof[i]:8.1f}, {alp[i]:8.6f}, {bet[i]:8.6f}, {sig[i]:8.6f}\n"
532+
533+
resString+=f"{d[-1]:7.4f}, {tof[-1]:8.1f}, {alp[-1]:8.6f}, {bet[-1]:8.6f}, {sig[-1]:8.6f}\"\"\"\n"
534+
535+
#write output string
536+
fp.write(resString)
513537

514538
def LoadImportRoutines(prefix, errprefix=None, traceback=False):
515539
'''Routine to locate GSASII importers matching a prefix string.

GSASII/GSASIIpwdGUI.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2700,7 +2700,7 @@ def OnSave(event):
27002700
# make sure extension is .instprm
27012701
filename = os.path.splitext(filename)[0]+'.instprm'
27022702
File = open(filename,'w')
2703-
G2fil.WriteInstprm(File, data, Sample)
2703+
G2fil.WriteInstprm(File, data, Sample)
27042704
File.close()
27052705
print ('Instrument parameters saved to: '+filename)
27062706
finally:
@@ -2735,13 +2735,14 @@ def OnSaveAll(event):
27352735
for hist in saveList:
27362736
Id = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,hist)
27372737
inst = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,Id,'Instrument Parameters'))[0]
2738+
inst1 = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,Id,'Instrument Parameters'))[1] #pdabc dictionary
27382739
Sample = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,Id,'Sample Parameters'))
27392740
if 'Bank' not in inst: #patch
27402741
bank = 1
27412742
if 'Bank' in hist:
27422743
bank = int(hist.split('Bank')[1])
27432744
inst['Bank'] = [bank,bank,0]
2744-
G2fil.WriteInstprm(File, inst, Sample, inst['Bank'][0])
2745+
G2fil.WriteInstprm(File, inst, inst1, Sample, inst['Bank'][0])
27452746
File.close()
27462747
finally:
27472748
dlg.Destroy()
@@ -3072,7 +3073,7 @@ def MakeLamSizer():
30723073
elemKeysLst.append(['2-theta',1])
30733074
dspLst.append([10,2])
30743075
refFlgElem.append(None)
3075-
if 'Pdabc' in Inst2:
3076+
if 'pdabc' in Inst2:
30763077
Items = ['sig-0','sig-1','sig-2','sig-q','X','Y','Z']
30773078
subSizer.Add(wx.StaticText(G2frame.dataWindow,-1,' difC: '),0,WACV)
30783079
txt = '%8.2f'%(insVal['difC'])

GSASII/GSASIIscriptable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4997,7 +4997,7 @@ def setSampleProfile(self, histname, parmType, mode, val1, val2=None, axis=None,
49974997
d[0] = 'uniaxial'
49984998
d[1][0] = float(val1)
49994999
d[1][1] = float(val2)
5000-
if LGmix is not None: d[1][2] = float(LGmix)
5000+
if LGmix is not None: d[1][2] = float( LGmix)
50015001

50025002
def HAPvalue(self, param=None, newValue=None, targethistlist='all'):
50035003
"""Retrieves or sets individual HAP parameters for one histogram or

GSASII/GSASIIstrMath.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3877,7 +3877,11 @@ def SavePartial(phase,y):
38773877
im = 1 #offset in SS reflection list
38783878
Dij = GetDij(phfx,SGData,parmDict)
38793879
A = [parmDict[pfx+'A%d'%(i)]+Dij[i] for i in range(6)] #TODO: need to do something if Dij << 0.
3880+
3881+
#TEST
3882+
print(f"phase: {Phase['General']['Name']} A is : {A}")
38803883
G,g = G2lat.A2Gmat(A) #recip & real metric tensors
3884+
print(f"phase: {Phase['General']['Name']} G is : {G}")
38813885
if np.any(np.diag(G)<0.):
38823886
msg = 'Invalid metric tensor for phase #{}\n ({})'.format(
38833887
pId,Phase['General']['Name'])
@@ -4040,7 +4044,7 @@ def SavePartial(phase,y):
40404044
Uniq = np.inner(refl[:3],SGMT)
40414045
refl[5+im] = GetReflPos(refl,im,0.0,A,pfx,hfx,phfx,calcControls,parmDict) #corrected reflection position - #TODO - what about tabluated offset?
40424046
Lorenz = sind(abs(parmDict[hfx+'2-theta'])/2)*refl[4+im]**4 #TOF Lorentz correction
4043-
# refl[5+im] += GetHStrainShift(refl,im,SGData,phfx,hfx,calcControls,parmDict) #apply hydrostatic strain shift
4047+
refl[5+im] += GetHStrainShift(refl,im,SGData,phfx,hfx,calcControls,parmDict) #apply hydrostatic strain shift
40444048
refl[6+im:8+im] = GetReflSigGamTOF(refl,im,G,GB,phfx,calcControls,parmDict,histDict1,hfx) #peak sig & gam
40454049
refl[12+im:14+im] = GetReflAlpBet(refl,im,hfx,parmDict) #TODO - skip if alp, bet tabulated?
40464050
refl[11+im],refl[15+im],refl[16+im],refl[17+im] = GetIntensityCorr(refl,im,Uniq,G,g,pfx,phfx,hfx,SGData,calcControls,parmDict)

0 commit comments

Comments
 (0)