@@ -169,6 +169,55 @@ def makeInstDict(names,data,codes):
169
169
inst [item ] = list (inst [item ])
170
170
return inst
171
171
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
+
172
221
def SetPowderInstParms (Iparm , rd ):
173
222
'''extracts values from instrument parameters in rd.instdict
174
223
or in array Iparm.
@@ -292,16 +341,21 @@ def SetPowderInstParms(Iparm, rd):
292
341
Inst1 = makeInstDict (names ,data ,codes )
293
342
Inst1 ['Bank' ] = [Bank ,Bank ,0 ]
294
343
Inst2 = {}
344
+
295
345
if pfType < 0 :
296
346
Ipab = 'INS 1PAB' + str (- pfType )
347
+ key = Ipab + ' '
348
+ print ("looking for key: " , key )
297
349
Npab = int (Iparm [Ipab + ' ' ].strip ())
298
- Inst2 ['Pdabc ' ] = []
350
+ Inst2 ['pdabc ' ] = []
299
351
for i in range (Npab ):
300
352
k = Ipab + str (i + 1 ).rjust (2 )
301
353
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" )
305
359
if 'INS 1I ITYP' in Iparm :
306
360
s = Iparm ['INS 1I ITYP' ].split ()
307
361
Ityp = int (s [0 ])
@@ -356,7 +410,8 @@ def ReadInstprm(instLines, bank, Sample={}):
356
410
determined by instrument settings or information
357
411
from the instprm file are placed here.
358
412
: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)
360
415
361
416
Note if 'Type' is set as Debye-Scherrer or Bragg-Brentano this will be used and
362
417
will set defaults in the sample parameters. Otherwise, a single-wavelength file
@@ -461,21 +516,33 @@ def ReadInstprm(instLines, bank, Sample={}):
461
516
Sample .update ({'Type' :'Debye-Scherrer' ,'Absorption' :[0. ,False ],'DisplaceX' :[0. ,False ],
462
517
'DisplaceY' :[0. ,False ]})
463
518
Sample .update (NewSample )
464
- return bank ,[makeInstDict (newItems , newVals , len (newVals )* [False ]), {}]
465
519
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 ):
467
532
'''Write the contents of a GSAS-II (new) .instprm instrument parameter file
468
533
ToDo: use this inside G2frame.OnSave and G2frame.OnSaveAll
469
534
470
535
:param file fp: Pointer to open file to be written.
471
536
:param dict InstPrm: Instrument parameters
537
+ :param dict InstPrm1: "extended" instrument parameters
472
538
:param dict Sample: Sample parameters (optional)
473
539
:param int bank: Bank number. If not None (default), this causes
474
540
a "#Bank" heading to be placed in the file before the
475
541
parameters are written.
476
542
'''
477
543
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 " )
479
546
indent = ' '
480
547
else :
481
548
fp .write ("#GSAS-II instrument parameter file; do not add/delete items!\n " )
@@ -490,6 +557,28 @@ def WriteInstprm(fp, InstPrm, Sample={}, bank=None):
490
557
if not Sample .get (item ): continue
491
558
fp .write (f"{ indent } { item } :{ Sample [item ]} \n " )
492
559
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
+
493
582
# version of LoadImportRoutines from before switch to "main"
494
583
# def _old_LoadImportRoutines(prefix, errprefix=None, traceback=False):
495
584
# '''Routine to locate GSASII importers matching a prefix string.
@@ -1966,7 +2055,7 @@ def loadParmDict(self,computeSU=False):
1966
2055
self .parmDict .update (phaseDict )
1967
2056
hapVary ,hapDict ,controlDict = G2stIO .GetHistogramPhaseData (Phases ,Histograms ,Print = False ,resetRefList = False )
1968
2057
self .parmDict .update (hapDict )
1969
- histVary ,histDict ,controlDict = G2stIO .GetHistogramData (Histograms ,Print = False )
2058
+ histVary ,histDict ,histDict1 , controlDict = G2stIO .GetHistogramData (Histograms ,Print = False )
1970
2059
self .parmDict .update (histDict )
1971
2060
self .parmDict .update (zip (
1972
2061
covDict .get ('varyList' ,[]),
0 commit comments