Skip to content

Commit da5c5b7

Browse files
committed
add pos derivatives & reorder calls to fix issues
1 parent b81d8e3 commit da5c5b7

File tree

1 file changed

+35
-16
lines changed

1 file changed

+35
-16
lines changed

GSASII/GSASIIpwd.py

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2427,6 +2427,27 @@ def dervPeakPos(values,peakDsp,peakPos,peakWt,dataType,parmDict,varyList):
24272427
calcPos = G2lat.getPeakPos(dataType,parmDict,peakDsp)
24282428
if dataType[2] in ['A','B','C']:
24292429
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
24302451

24312452
def errPeakAlp(values,peakDsp,peakAlp,peakWt,dataType,parmDict,varyList):
24322453
parmDict.update(dict(zip(varyList,values)))
@@ -2523,31 +2544,25 @@ def outResult():
25232544
return []
25242545
return sig
25252546

2526-
dataType = Inst['Type'][0]
2527-
peakPos,peakDsp,peakPosWt = SetPosData()
2528-
posDict,posVary = SetPosParms()
2529-
sigDsp,peakSig,peakSigWt = SetSigData()
2530-
sigDict,sigVary = SetSigParms()
2531-
if dataType[2] in ['A','B','T']:
2532-
alpDsp,peakAlp,peakAlpWt = SetAlpData()
2533-
alpDict,alpVary = SetAlpParms()
2534-
betDsp,peakBet,peakBetWt = SetBetData()
2535-
betDict,betVary = SetBetParms()
2536-
2547+
dataType = Inst['Type'][0]
25372548
parmDict = {}
25382549
Sigmas = {}
2550+
peakPos,peakDsp,peakPosWt = SetPosData()
2551+
posDict,posVary = SetPosParms()
25392552
parmDict.update(posDict)
25402553
if len(peakPos) > 5 and len(posVary):
25412554
values = np.array(Dict2Values(parmDict, posVary))
2542-
result = so.leastsq(errPeakPos,values,Dfun=None,full_output=True,ftol=0.000001,
2543-
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))
25442557
G2fil.G2Print('Position calibration:')
25452558
Values2Dict(parmDict, posVary, result[0])
25462559
sig = outResult()
25472560
if len(sig):
25482561
Sigmas.update(zip(posVary,sig))
25492562
GetInstParms(parmDict)
2550-
parmDict = {}
2563+
# parmDict = {}
2564+
sigDsp,peakSig,peakSigWt = SetSigData()
2565+
sigDict,sigVary = SetSigParms()
25512566
parmDict.update(sigDict)
25522567
if len(peakSig) > 5 and len(sigVary):
25532568
values = np.array(Dict2Values(parmDict, sigVary))
@@ -2562,7 +2577,9 @@ def outResult():
25622577
else:
25632578
G2fil.G2Print(' Sigma not calibrated: insufficient data or not selected')
25642579
if dataType[2] in ['A','B','T']:
2565-
parmDict = {}
2580+
# parmDict = {}
2581+
alpDsp,peakAlp,peakAlpWt = SetAlpData()
2582+
alpDict,alpVary = SetAlpParms()
25662583
parmDict.update(alpDict)
25672584
if len(peakAlp) > 5 and len(alpVary):
25682585
values = np.array(Dict2Values(parmDict, alpVary))
@@ -2576,7 +2593,9 @@ def outResult():
25762593
GetInstParms(parmDict)
25772594
else:
25782595
G2fil.G2Print(' Alpha not calibrated: insufficient data or not selected')
2579-
parmDict = {}
2596+
# parmDict = {}
2597+
betDsp,peakBet,peakBetWt = SetBetData()
2598+
betDict,betVary = SetBetParms()
25802599
parmDict.update(betDict)
25812600
if len(peakBet) > 5 and len(betVary):
25822601
values = np.array(Dict2Values(parmDict, betVary))

0 commit comments

Comments
 (0)