Skip to content

Commit f9e6ed3

Browse files
committed
bring TOFgroup up to date with main
Merge remote-tracking branch 'origin/main' into TOFgroup
2 parents 2019dbb + dbb1a02 commit f9e6ed3

18 files changed

+1051
-178
lines changed

GSASII/GSASIIdataGUI.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,7 +1619,7 @@ def GetDefaultParms(self,rd):
16191619
else:
16201620
rd.instmsg = 'default: '+dI.defaultIparm_lbl[res]
16211621
inst1,inst2 = self.ReadPowderInstprm(dI.defaultIparms[res],bank,rd)
1622-
if rd.instdict.get('wave'):
1622+
if rd.instdict.get('wave') and 'Lam' in inst1:
16231623
inst1['Lam'][0] = rd.instdict.get('wave')
16241624
inst1['Lam'][1] = rd.instdict.get('wave')
16251625
return [inst1,inst2]
@@ -8317,12 +8317,16 @@ def OnMergeHKL(event):
83178317
if newHKL[5+Super] > 0.:
83188318
mergeRef.append(list(newHKL))
83198319
dlg.Destroy()
8320-
print(' Duplicate reflection statistics:')
8320+
mtext = ' Duplicate reflection statistics:'
8321+
print(mtext)
8322+
Comments.append(mtext)
83218323
for ihkl in range(MaxN):
83228324
try:
8323-
print('Ndup hkl:',ihkl+1,' Number: ',Nmerge[ihkl+1][0],' Rej:',Nmerge[ihkl+1][1])
8325+
mtext = 'Ndup hkl: %d Number: %d Rej: %d'%(ihkl+1,Nmerge[ihkl+1][0],Nmerge[ihkl+1][1])
83248326
except KeyError:
8325-
print('Ndup hkl:',ihkl+1,' Number: ',0)
8327+
mtext = 'Ndup hkl: %d Number: 0'%(ihkl+1)
8328+
print(mtext)
8329+
Comments.append(mtext)
83268330
if Super:
83278331
mergeRef = G2mth.sortArray(G2mth.sortArray(G2mth.sortArray(G2mth.sortArray(mergeRef,3),2),1),0)
83288332
else:
@@ -8665,6 +8669,8 @@ def OnEditMag(**args):
86658669
Super = 0
86668670
SuperVec = []
86678671
refList = data[1]['RefList']
8672+
nRef = refList.shape[0]
8673+
mainSizer.Add(wx.StaticText(G2frame.dataWindow,label=' Total Nref: %d'%nRef))
86688674
FoMax = np.max(refList.T[5+data[1].get('Super',0)])
86698675
page = G2frame.G2plotNB.nb.GetSelection()
86708676
tab = ''

GSASII/GSASIIddataGUI.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ def OnFixVals(event):
940940
UseList[G2frame.hist]['Extinction'][2].update({'Ma':[1.0,False]})
941941
UseList[G2frame.hist]['Extinction'][2].update({'Mb':[0.0,False]})
942942
if 'Mc' not in UseList[G2frame.hist]['Extinction'][2]:
943-
UseList[G2frame.hist]['Extinction'][2].update({'Mc':[1.0,False]})
943+
UseList[G2frame.hist]['Extinction'][2].update({'Mc':[0.0,False]})
944944
elif 'PWDR' in UseList[G2frame.hist]['Histogram']:
945945
if 'LeBail' not in UseList[G2frame.hist]:
946946
UseList[G2frame.hist]['LeBail'] = False

GSASII/GSASIIobj.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,8 @@ def ReInitialize(self):
14331433
self.instdict = {} # place items here that will be transferred to the instrument parameters
14341434
self.pwdparms = {} # place parameters that are transferred directly to the tree
14351435
# here (typically from an existing GPX file)
1436+
self.selections = []
1437+
self.dnames = []
14361438
######################################################################
14371439
class ImportSmallAngleData(ImportBaseclass):
14381440
'''Defines a base class for the reading of files with small angle data.

GSASII/GSASIIpwd.py

Lines changed: 120 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,6 +2422,33 @@ def errPeakPos(values,peakDsp,peakPos,peakWt,dataType,parmDict,varyList):
24222422
else:
24232423
return peakWt*(calcPos-peakPos)
24242424

2425+
def dervPeakPos(values,peakDsp,peakPos,peakWt,dataType,parmDict,varyList):
2426+
dMdv = np.zeros(shape=(len(varyList),len(peakDsp)))
2427+
calcPos = G2lat.getPeakPos(dataType,parmDict,peakDsp)
2428+
if dataType[2] in ['A','B','C']:
2429+
const = 0.18/(np.pi*parmDict['radius'])
2430+
for iv,vary in enumerate(varyList):
2431+
if vary == 'Zero':
2432+
dMdv[iv,:] = 1.0
2433+
if vary == 'DisplaceX':
2434+
dMdv[iv,:] = -const*npcosd(calcPos)
2435+
if vary == 'DisplaceY':
2436+
dMdv[iv,:] = -const*npsind(calcPos)
2437+
if vary == 'Shift':
2438+
dMdv[iv,:] = -const*npcosd(calcPos/2.0)
2439+
if vary == 'Lam':
2440+
dpr = 180./np.pi
2441+
k = 1.0-parmDict['Lam']**2/(4.0*peakDsp**2)
2442+
k = dpr/np.sqrt(k)
2443+
dMdv[iv,:] = k/peakDsp
2444+
if vary == 'DifC':
2445+
dMdv[iv,:] = peakDsp
2446+
if vary == 'DifA':
2447+
dMdv[iv,:] = peakDsp**2
2448+
if vary == 'DifB':
2449+
dMdv[iv,:] = 1.0/peakDsp
2450+
return np.sqrt(peakWt)*dMdv
2451+
24252452
def errPeakAlp(values,peakDsp,peakAlp,peakWt,dataType,parmDict,varyList):
24262453
parmDict.update(dict(zip(varyList,values)))
24272454
if dataType[2] in ['A','B']:
@@ -2431,6 +2458,19 @@ def errPeakAlp(values,peakDsp,peakAlp,peakWt,dataType,parmDict,varyList):
24312458
calcAlp = parmDict['alpha']/peakDsp
24322459
return peakWt*(calcAlp-peakAlp)
24332460

2461+
def dervPeakAlp(values,peakDsp,peakAlp,peakWt,dataType,parmDict,varyList):
2462+
dMdv = np.zeros(shape=(len(varyList),len(peakDsp)))
2463+
if dataType[2] in ['A','B']:
2464+
calcPos = G2lat.getPeakPos(dataType,parmDict,peakDsp)
2465+
for iv,vary in enumerate(varyList):
2466+
if vary == 'alpha':
2467+
dMdv[iv,:] = 1.0/peakDsp
2468+
if vary == 'alpha-0':
2469+
dMdv[iv,:] = 1.0
2470+
if vary == 'alpha-1':
2471+
dMdv[iv,:] = npsind(calcPos/2.)
2472+
return np.sqrt(peakWt)*dMdv
2473+
24342474
def errPeakBet(values,peakDsp,peakBet,peakWt,dataType,parmDict,varyList):
24352475
parmDict.update(dict(zip(varyList,values)))
24362476
if dataType[2] in ['A','B']:
@@ -2439,6 +2479,22 @@ def errPeakBet(values,peakDsp,peakBet,peakWt,dataType,parmDict,varyList):
24392479
else: #'T'
24402480
calcBet = parmDict['beta-0']+parmDict['beta-1']/peakDsp**4+parmDict['beta-q']/peakDsp**2
24412481
return peakWt*(calcBet-peakBet)
2482+
2483+
def dervPeakBet(values,peakDsp,peakBet,peakWt,dataType,parmDict,varyList):
2484+
dMdv = np.zeros(shape=(len(varyList),len(peakDsp)))
2485+
if dataType[2] in ['A','B']:
2486+
calcPos = G2lat.getPeakPos(dataType,parmDict,peakDsp)
2487+
for iv,vary in enumerate(varyList):
2488+
if vary == 'beta-0':
2489+
dMdv[iv,:] = 1.0
2490+
if vary == 'beta-1':
2491+
if dataType[2] in ['A','B']:
2492+
dMdv[iv,:] = npsind(calcPos/2.)
2493+
else:
2494+
dMdv[iv,:] = 1.0/peakDsp**4
2495+
if vary == 'beta-q':
2496+
dMdv[iv,:] = 1.0/peakDsp**2
2497+
return np.sqrt(peakWt)*dMdv
24422498

24432499
def errPeakSig(values,peakDsp,peakSig,peakWt,dataType,parmDict,varyList):
24442500
parmDict.update(dict(zip(varyList,values)))
@@ -2450,6 +2506,30 @@ def errPeakSig(values,peakDsp,peakSig,peakWt,dataType,parmDict,varyList):
24502506
calcSig = parmDict['sig-0']+parmDict['sig-1']*peakDsp**2+parmDict['sig-2']*peakDsp**4+parmDict['sig-q']*peakDsp
24512507
return peakWt*(calcSig-peakSig)
24522508

2509+
def dervPeakSig(values,peakDsp,peakSig,peakWt,dataType,parmDict,varyList):
2510+
dMdv = np.zeros(shape=(len(varyList),len(peakDsp)))
2511+
if dataType[2] in ['A','B','C']:
2512+
calcPos = G2lat.getPeakPos(dataType,parmDict,peakDsp)
2513+
tp = nptand(calcPos/2.0)
2514+
for iv,vary in enumerate(varyList):
2515+
if vary == 'U':
2516+
dMdv[iv,:] = tp**2
2517+
if vary == 'V':
2518+
dMdv[iv,:] = tp
2519+
if vary == 'W':
2520+
dMdv[iv,:] = 1.
2521+
else:
2522+
for iv,vary in enumerate(varyList):
2523+
if vary == 'sig-0':
2524+
dMdv[iv,:] = 1.0
2525+
if vary == 'sig-1':
2526+
dMdv[iv,:] = peakDsp**2
2527+
if vary == 'sig-2':
2528+
dMdv[iv,:] = peakDsp**4
2529+
if vary == 'sig-q':
2530+
dMdv[iv,:] = peakDsp
2531+
return np.sqrt(peakWt)*dMdv
2532+
24532533
def outResult():
24542534
chisq = np.sum(result[2]['fvec']**2)
24552535
GOF = chisq/(len(peakPos)-len(posVary)) #reduced chi^2
@@ -2464,36 +2544,30 @@ def outResult():
24642544
return []
24652545
return sig
24662546

2467-
dataType = Inst['Type'][0]
2468-
peakPos,peakDsp,peakPosWt = SetPosData()
2469-
posDict,posVary = SetPosParms()
2470-
sigDsp,peakSig,peakSigWt = SetSigData()
2471-
sigDict,sigVary = SetSigParms()
2472-
if dataType[2] in ['A','B','T']:
2473-
alpDsp,peakAlp,peakAlpWt = SetAlpData()
2474-
alpDict,alpVary = SetAlpParms()
2475-
betDsp,peakBet,peakBetWt = SetBetData()
2476-
betDict,betVary = SetBetParms()
2477-
2547+
dataType = Inst['Type'][0]
24782548
parmDict = {}
24792549
Sigmas = {}
2550+
peakPos,peakDsp,peakPosWt = SetPosData()
2551+
posDict,posVary = SetPosParms()
24802552
parmDict.update(posDict)
24812553
if len(peakPos) > 5 and len(posVary):
24822554
values = np.array(Dict2Values(parmDict, posVary))
2483-
result = so.leastsq(errPeakPos,values,full_output=True,ftol=0.000001,
2484-
args=(peakDsp,peakPos,peakPosWt,dataType,parmDict,posVary))
2555+
result = so.leastsq(errPeakPos,values,Dfun=dervPeakPos,full_output=True,ftol=0.000001,
2556+
col_deriv=True,args=(peakDsp,peakPos,peakPosWt,dataType,parmDict,posVary))
24852557
G2fil.G2Print('Position calibration:')
24862558
Values2Dict(parmDict, posVary, result[0])
24872559
sig = outResult()
24882560
if len(sig):
24892561
Sigmas.update(zip(posVary,sig))
24902562
GetInstParms(parmDict)
2491-
parmDict = {}
2563+
# parmDict = {}
2564+
sigDsp,peakSig,peakSigWt = SetSigData()
2565+
sigDict,sigVary = SetSigParms()
24922566
parmDict.update(sigDict)
24932567
if len(peakSig) > 5 and len(sigVary):
24942568
values = np.array(Dict2Values(parmDict, sigVary))
2495-
result = so.leastsq(errPeakSig,values,full_output=True,ftol=0.000001,
2496-
args=(sigDsp,peakSig,peakSigWt,dataType,parmDict,sigVary))
2569+
result = so.leastsq(errPeakSig,values,Dfun=dervPeakSig,full_output=True,ftol=0.000001,
2570+
col_deriv=True,args=(sigDsp,peakSig,peakSigWt,dataType,parmDict,sigVary))
24972571
G2fil.G2Print('Sigma calibration:')
24982572
Values2Dict(parmDict, sigVary, result[0])
24992573
sig = outResult()
@@ -2503,12 +2577,14 @@ def outResult():
25032577
else:
25042578
G2fil.G2Print(' Sigma not calibrated: insufficient data or not selected')
25052579
if dataType[2] in ['A','B','T']:
2506-
parmDict = {}
2580+
# parmDict = {}
2581+
alpDsp,peakAlp,peakAlpWt = SetAlpData()
2582+
alpDict,alpVary = SetAlpParms()
25072583
parmDict.update(alpDict)
25082584
if len(peakAlp) > 5 and len(alpVary):
25092585
values = np.array(Dict2Values(parmDict, alpVary))
2510-
result = so.leastsq(errPeakAlp,values,full_output=True,ftol=0.000001,
2511-
args=(alpDsp,peakAlp,peakAlpWt,dataType,parmDict,alpVary))
2586+
result = so.leastsq(errPeakAlp,values,Dfun=dervPeakAlp,full_output=True,ftol=0.000001,
2587+
col_deriv=True,args=(alpDsp,peakAlp,peakAlpWt,dataType,parmDict,alpVary))
25122588
G2fil.G2Print('Alpha calibration:')
25132589
Values2Dict(parmDict, alpVary, result[0])
25142590
sig = outResult()
@@ -2517,12 +2593,14 @@ def outResult():
25172593
GetInstParms(parmDict)
25182594
else:
25192595
G2fil.G2Print(' Alpha not calibrated: insufficient data or not selected')
2520-
parmDict = {}
2596+
# parmDict = {}
2597+
betDsp,peakBet,peakBetWt = SetBetData()
2598+
betDict,betVary = SetBetParms()
25212599
parmDict.update(betDict)
25222600
if len(peakBet) > 5 and len(betVary):
25232601
values = np.array(Dict2Values(parmDict, betVary))
2524-
result = so.leastsq(errPeakBet,values,full_output=True,ftol=0.000001,
2525-
args=(betDsp,peakBet,peakBetWt,dataType,parmDict,betVary))
2602+
result = so.leastsq(errPeakBet,values,Dfun=dervPeakBet,full_output=True,ftol=0.000001,
2603+
col_deriv=True,args=(betDsp,peakBet,peakBetWt,dataType,parmDict,betVary))
25262604
G2fil.G2Print('Beta calibration:')
25272605
Values2Dict(parmDict, betVary, result[0])
25282606
sig = outResult()
@@ -2691,8 +2769,13 @@ def BackgroundPrint(Background,sigDict):
26912769
if 'BF mult' in sigDict:
26922770
print('Background file mult: %.3f(%d)'%(Background[1]['background PWDR'][1],int(1000*sigDict['BF mult'])))
26932771

2694-
def SetInstParms(Inst):
2772+
def SetInstParms(Inst,peakVary):
2773+
# superesses refinement of instrument parameters if any corresponding peak parameter is refined
26952774
dataType = Inst['Type'][0]
2775+
noAlp = any([True for vary in peakVary if 'alp' in vary])
2776+
noBet = any([True for vary in peakVary if 'bet' in vary])
2777+
noSig = any([True for vary in peakVary if 'sig' in vary])
2778+
# noGam = any([True for vary in peakVary if 'gam' in vary])
26962779
insVary = []
26972780
insNames = []
26982781
insVals = []
@@ -2701,7 +2784,19 @@ def SetInstParms(Inst):
27012784
insVals.append(Inst[parm][1])
27022785
if parm in ['U','V','W','X','Y','Z','SH/L','I(L2)/I(L1)','alpha','A','B','C',
27032786
'beta-0','beta-1','beta-q','sig-0','sig-1','sig-2','sig-q','alpha-0','alpha-1'] and Inst[parm][2]:
2704-
insVary.append(parm)
2787+
if 'alp' in parm and noAlp:
2788+
Inst[parm][2] = False
2789+
continue
2790+
elif 'bet' in parm and noBet:
2791+
Inst[parm][2] = False
2792+
continue
2793+
elif ('sig' in parm or parm in ['U','V','W']) and noSig:
2794+
Inst[parm][2] = False
2795+
continue
2796+
# elif parm in ['X','Y','Z'] and noGam:
2797+
# Inst[parm][2] = False
2798+
# continue
2799+
insVary.append(parm)
27052800
instDict = dict(zip(insNames,insVals))
27062801
if 'SH/L' in instDict:
27072802
instDict['SH/L'] = max(instDict['SH/L'],0.002)
@@ -2925,8 +3020,8 @@ def errPeakProfile(values,xdata,ydata,fixback,weights,dataType,parmdict,varylist
29253020
xFin = np.searchsorted(x,Limits[1])+1
29263021
# find out what is varied
29273022
bakType,bakDict,bakVary = SetBackgroundParms(Background)
2928-
dataType,insDict,insVary = SetInstParms(Inst)
29293023
peakDict,peakVary = SetPeaksParms(Inst['Type'][0],Peaks)
3024+
dataType,insDict,insVary = SetInstParms(Inst,peakVary)
29303025
parmDict = {}
29313026
parmDict.update(bakDict)
29323027
parmDict.update(insDict)

GSASII/GSASIIscriptable.py

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -588,13 +588,36 @@ def load_pwd_from_reader(reader, instprm, existingnames=[],bank=None):
588588
HistName = 'PWDR ' + G2obj.StripUnicode(reader.idstring, '_')
589589
HistName = G2obj.MakeUniqueLabel(HistName, existingnames)
590590

591-
try:
592-
Iparm1, Iparm2 = instprm
593-
except ValueError:
591+
# get instrumental parameters from reader...
592+
if instprm is None:
593+
try:
594+
Iparm1, Iparm2 = reader.pwdparms['Instrument Parameters']
595+
print('Instrument parameters supplied in data file')
596+
except KeyError as err:
597+
Iparm1 = None # signal error rather than raise exception inside an exception handler
598+
if Iparm1 is None:
599+
msg = "The data file does not have any instrument params associated with it and none were provided."
600+
raise Exception(msg)
601+
602+
# ...or from a file...
603+
elif isinstance(instprm, str):
594604
Iparm1, Iparm2 = load_iprms(instprm, reader, bank=bank)
595605
G2fil.G2Print('Instrument parameters read:',reader.instmsg)
596-
except TypeError: # instprm is None, get iparms from reader
597-
Iparm1, Iparm2 = reader.pwdparms['Instrument Parameters']
606+
607+
# ...or from an input...
608+
elif (
609+
isinstance(instprm, (list, tuple))
610+
and len(instprm) == 2
611+
and all(isinstance(i, dict) for i in instprm)
612+
):
613+
Iparm1, Iparm2 = instprm
614+
print('Instrument parameters supplied in script')
615+
616+
# ...else raise an error.
617+
else:
618+
msg = f"load_pwd... Error: Invalid instprm entered ({instprm!r})"
619+
raise Exception(msg)
620+
598621

599622
if 'T' in Iparm1['Type'][0]:
600623
if not reader.clockWd and reader.GSAS:
@@ -1058,14 +1081,20 @@ def add_powder_histogram(self, datafile, iparams=None, phases=[],
10581081
if not multiple: pwdrreaders = pwdrreaders[0:1]
10591082
histlist = []
10601083
if URL:
1061-
iparmfile = downloadFile(iparams)
1062-
else:
1084+
instprm = downloadFile(iparams)
1085+
elif iparams:
10631086
try:
1064-
iparmfile = os.path.abspath(os.path.expanduser(iparams))
1065-
except:
1066-
pass
1087+
instprm = os.path.abspath(os.path.expanduser(iparams))
1088+
except TypeError: # iparams is not a file path
1089+
if isinstance(iparams, (list, tuple)):
1090+
instprm = iparams
1091+
else:
1092+
raise Exception(f"add_powder_histogram Error: Invalid iparams supplied ({iparams!r})")
1093+
else:
1094+
instprm = None # will error out unless the reader supplies them
1095+
10671096
for r in pwdrreaders:
1068-
histname, new_names, pwdrdata = load_pwd_from_reader(r, iparmfile,
1097+
histname, new_names, pwdrdata = load_pwd_from_reader(r, instprm,
10691098
[h.name for h in self.histograms()],bank=instbank)
10701099
if histname in self.data:
10711100
G2fil.G2Print("Warning - redefining histogram", histname)
@@ -3184,13 +3213,17 @@ def get_Covariance(self,varList):
31843213
covArray = np.divide(np.divide(covMatrix,xvar),xvar.T)
31853214
31863215
'''
3216+
for i in ('covMatrix','varyList','variables'):
3217+
if i not in self['Covariance']['data']:
3218+
raise G2ScriptException(f'No {i} found in project, has a refinement been run?')
31873219
missing = [i for i in varList if i not in self['Covariance']['data']['varyList']]
31883220
if missing:
31893221
G2fil.G2Print('Warning: Variable(s) {} were not found in the varyList'.format(missing))
31903222
return None
3191-
if 'parmDict' not in self['Covariance']['data']:
3192-
raise G2ScriptException('No parameters found in project, has a refinement been run?')
3193-
vals = [self['Covariance']['data']['parmDict'][i] for i in varList]
3223+
parmDict = dict(zip(
3224+
self['Covariance']['data']['varyList'],
3225+
self['Covariance']['data']['variables']))
3226+
vals = [parmDict[i] for i in varList]
31943227
cov = G2mth.getVCov(varList,
31953228
self['Covariance']['data']['varyList'],
31963229
self['Covariance']['data']['covMatrix'])

GSASII/GSASIIstrMath.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3587,7 +3587,7 @@ def GetHStrainShiftDerv(refl,im,SGData,phfx,hfx,calcControls,parmDict):
35873587
dDijDict[item] *= refl[5+im]/refl[4+im]**2
35883588
else:
35893589
for item in dDijDict:
3590-
dDijDict[item] *= -parmDict[hfx+'difC']*refl[4+im]**3/2.
3590+
dDijDict[item] *= -parmDict[hfx+'difC']*refl[4+im]**2
35913591
return dDijDict
35923592

35933593
def GetDij(phfx,SGData,parmDict):

0 commit comments

Comments
 (0)