Skip to content

Commit c02a681

Browse files
committed
fixing unit issue in Shkl. Units are now in degrees and correctly scaled to be additive with U and Y respectively.
1 parent 97d9bd2 commit c02a681

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

hexrd/powder/wppf/peakfunctions.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ def _gaussian_fwhm(uvw, P, gamma_ani_sqr, eta_mixing, tth, dsp):
7272
tanth = np.tan(th)
7373
cth2 = np.cos(th) ** 2.0
7474
sig2_ani = gamma_ani_sqr * (1.0 - eta_mixing) ** 2 * dsp**4
75+
# sig2_ani is in radians and does not have the 1E4 factor
76+
# built in to U. we will add it here
77+
sig2_ani = np.degrees(sig2_ani) * 1e4
7578
sigsqr = (U + sig2_ani) * tanth**2 + V * tanth + W + P / cth2
7679
if sigsqr <= 0.0:
7780
sigsqr = 1.0e-12
@@ -99,6 +102,9 @@ def _lorentzian_fwhm(xy, xy_sf, gamma_ani_sqr, eta_mixing, tth, dsp):
99102
tanth = np.tan(th)
100103
cth = np.cos(th)
101104
sig_ani = np.sqrt(gamma_ani_sqr) * eta_mixing * dsp**2
105+
# sig2_ani is in radians and does not have the 1E2 factor
106+
# built in to Y. we will add it here
107+
sig_ani = np.degrees(sig_ani) * 1e2
102108
gamma = (X + xy_sf) / cth + (Y + sig_ani) * tanth
103109
return gamma * 1e-2
104110

@@ -212,16 +218,17 @@ def _unit_lorentzian(p, x):
212218
f = gamma / ((x - x0) ** 2 + gamma**2)
213219
return f
214220

221+
215222
@njit(cache=True, nogil=True)
216223
def _heaviside(x, x0):
217224
y = np.empty_like(x)
218225
for ii in np.arange(x.size):
219-
if x[ii] < 0.:
220-
y[ii] = 0.
221-
elif x[ii] == 0.:
226+
if x[ii] < 0.0:
227+
y[ii] = 0.0
228+
elif x[ii] == 0.0:
222229
y[ii] = x0
223230
else:
224-
y[ii] = 1.
231+
y[ii] = 1.0
225232

226233
return y
227234

@@ -245,24 +252,24 @@ def _split_unit_gaussian(p, x):
245252
y : numpy.ndarray
246253
intensity of split gaussian function
247254
'''
248-
x0 = p[0]
255+
x0 = p[0]
249256
fwhm_l = p[1]
250257
fwhm_r = p[2]
251258

252259
sigma_l = fwhm_l / gauss_width_fact
253260
sigma_r = fwhm_r / gauss_width_fact
254261

255-
heav_l = _heaviside(x0-x, 1.0)
256-
heav_r = _heaviside(x-x0, 1.0)
262+
heav_l = _heaviside(x0 - x, 1.0)
263+
heav_r = _heaviside(x - x0, 1.0)
257264

258265
p_l = np.array([x0, fwhm_l])
259266
p_r = np.array([x0, fwhm_r])
260267

261268
gauss_l = _unit_gaussian(p_l, x)
262269
gauss_r = _unit_gaussian(p_r, x)
263270

264-
return (gauss_l*heav_l +
265-
gauss_r*heav_r)
271+
return gauss_l * heav_l + gauss_r * heav_r
272+
266273

267274
# =========================================================
268275
# 1-D split pseudo-voight functions
@@ -299,8 +306,8 @@ def _split_unit_pv(p, x):
299306
fwhm_g_r = p[3]
300307
fwhm_l_r = p[4]
301308

302-
heav_l = _heaviside(x0-x, 1.0)
303-
heav_r = _heaviside(x-x0, 1.0)
309+
heav_l = _heaviside(x0 - x, 1.0)
310+
heav_r = _heaviside(x - x0, 1.0)
304311

305312
eta_l, fwhm_l = _mixing_factor_pv(fwhm_g_l, fwhm_l_l)
306313
eta_r, fwhm_r = _mixing_factor_pv(fwhm_g_r, fwhm_l_r)
@@ -313,16 +320,17 @@ def _split_unit_pv(p, x):
313320
gamma_r = fwhm_r / lorentz_width_fact
314321

315322
g_l = _unit_gaussian(np.array([x0, fwhm_l]), x)
316-
l_l = _unit_lorentzian(np.array([x0, fwhm_l]), x)*gamma_l
323+
l_l = _unit_lorentzian(np.array([x0, fwhm_l]), x) * gamma_l
317324

318325
g_r = _unit_gaussian(np.array([x0, fwhm_r]), x)
319-
l_r = _unit_lorentzian(np.array([x0, fwhm_r]), x)*gamma_r
326+
l_r = _unit_lorentzian(np.array([x0, fwhm_r]), x) * gamma_r
320327

321328
pv_l = eta_l * l_l + (1.0 - eta_l) * g_l
322329

323330
pv_r = eta_r * l_r + (1.0 - eta_r) * g_r
324331

325-
return pv_l*heav_l + pv_r*heav_r
332+
return pv_l * heav_l + pv_r * heav_r
333+
326334

327335
@njit(cache=True, nogil=True)
328336
def _mixing_factor_pv(fwhm_g, fwhm_l):
@@ -390,7 +398,6 @@ def _func_h(tau, tth_r):
390398

391399
@njit(cache=True, nogil=True)
392400
def _func_W(HoL, SoL, tau, tau_min, tau_infl, tth):
393-
394401
if tth < np.pi / 2.0:
395402
if tau >= 0.0 and tau <= tau_infl:
396403
res = 2.0 * min(HoL, SoL)
@@ -615,7 +622,6 @@ def computespectrum_pvfcj(
615622
np.array([Iobs.shape[0], tth.shape[0], dsp.shape[0], hkl.shape[0]])
616623
)
617624
for ii in prange(nref):
618-
619625
II = Iobs[ii]
620626
t = tth[ii]
621627
d = dsp[ii]
@@ -648,7 +654,6 @@ def computespectrum_pvtch(
648654
np.array([Iobs.shape[0], tth.shape[0], dsp.shape[0], hkl.shape[0]])
649655
)
650656
for ii in prange(nref):
651-
652657
II = Iobs[ii]
653658
t = tth[ii]
654659
d = dsp[ii]
@@ -691,7 +696,6 @@ def computespectrum_pvpink(
691696
np.array([Iobs.shape[0], tth.shape[0], dsp.shape[0], hkl.shape[0]])
692697
)
693698
for ii in prange(nref):
694-
695699
II = Iobs[ii]
696700
t = tth[ii]
697701
d = dsp[ii]

0 commit comments

Comments
 (0)