Optimize ang2hkl functions to accept inverted UB directly

This commit is contained in:
usov_i 2023-01-25 20:40:46 +01:00
parent dfef1eadd9
commit dd262ab6cd
3 changed files with 12 additions and 14 deletions

View File

@ -975,7 +975,7 @@ def calculate_hkl(scan, index):
gammad = scan["gamma"][index] gammad = scan["gamma"][index]
om = scan["omega"][index] om = scan["omega"][index]
nud = scan["nu"] nud = scan["nu"]
ub = scan["ub"] ub_inv = np.linalg.inv(scan["ub"])
geometry = scan["zebra_mode"] geometry = scan["zebra_mode"]
if geometry == "bi": if geometry == "bi":
@ -990,7 +990,7 @@ def calculate_hkl(scan, index):
for xi in np.arange(IMAGE_W): for xi in np.arange(IMAGE_W):
for yi in np.arange(IMAGE_H): for yi in np.arange(IMAGE_H):
h[yi, xi], k[yi, xi], l[yi, xi] = pyzebra.ang2hkl( h[yi, xi], k[yi, xi], l[yi, xi] = pyzebra.ang2hkl(
wave, ddist, gammad, om, chi, phi, nud, ub, xi, yi wave, ddist, gammad, om, chi, phi, nud, ub_inv, xi, yi
) )
return h, k, l return h, k, l

View File

@ -138,7 +138,7 @@ class PlotHKL:
chi = scan["chi"] chi = scan["chi"]
phi = scan["phi"] phi = scan["phi"]
nud = 0 # 1d detector nud = 0 # 1d detector
ub = scan["ub"] ub_inv = np.linalg.inv(scan["ub"])
counts = scan["counts"] counts = scan["counts"]
wave = scan["wavelength"] wave = scan["wavelength"]
@ -153,18 +153,18 @@ class PlotHKL:
res_x = [] res_x = []
res_y = [] res_y = []
for _om in np.linspace(om[0], om[-1], num=res_N): for _om in np.linspace(om[0], om[-1], num=res_N):
expr1 = ang2hkl_1d(wave, gammad, _om + res / 2, chi, phi, nud, ub) expr1 = ang2hkl_1d(wave, gammad, _om + res / 2, chi, phi, nud, ub_inv)
expr2 = ang2hkl_1d(wave, gammad, _om - res / 2, chi, phi, nud, ub) expr2 = ang2hkl_1d(wave, gammad, _om - res / 2, chi, phi, nud, ub_inv)
hkl_temp = M @ (np.abs(expr1 - expr2) / 2) hkl_temp = M @ (np.abs(expr1 - expr2) / 2)
res_x.append(hkl_temp[0]) res_x.append(hkl_temp[0])
res_y.append(hkl_temp[1]) res_y.append(hkl_temp[1])
# Get first and final hkl # Get first and final hkl
hkl1 = ang2hkl_1d(wave, gammad, om[0], chi, phi, nud, ub) hkl1 = ang2hkl_1d(wave, gammad, om[0], chi, phi, nud, ub_inv)
hkl2 = ang2hkl_1d(wave, gammad, om[-1], chi, phi, nud, ub) hkl2 = ang2hkl_1d(wave, gammad, om[-1], chi, phi, nud, ub_inv)
# Get hkl at best intensity # Get hkl at best intensity
hkl_m = ang2hkl_1d(wave, gammad, om[np.argmax(counts)], chi, phi, nud, ub) hkl_m = ang2hkl_1d(wave, gammad, om[np.argmax(counts)], chi, phi, nud, ub_inv)
# Estimate intensity for marker size scaling # Estimate intensity for marker size scaling
y_bkg = [counts[0], counts[-1]] y_bkg = [counts[0], counts[-1]]

View File

@ -361,21 +361,19 @@ def angtohkl(wave, ddist, gammad, om, ch, ph, nud, x, y):
) )
def ang2hkl(wave, ddist, gammad, om, ch, ph, nud, ub, x, y): def ang2hkl(wave, ddist, gammad, om, ch, ph, nud, ub_inv, x, y):
"""Calculate hkl-indices of a reflection from its position (x,y,angles) at the 2d-detector""" """Calculate hkl-indices of a reflection from its position (x,y,angles) at the 2d-detector"""
ga, nu = det2pol(ddist, gammad, nud, x, y) ga, nu = det2pol(ddist, gammad, nud, x, y)
z1 = z1frmd(wave, ga, om, ch, ph, nu) z1 = z1frmd(wave, ga, om, ch, ph, nu)
ubinv = np.linalg.inv(ub) hkl = ub_inv @ z1
hkl = ubinv @ z1
return hkl return hkl
def ang2hkl_1d(wave, ga, om, ch, ph, nu, ub): def ang2hkl_1d(wave, ga, om, ch, ph, nu, ub_inv):
"""Calculate hkl-indices of a reflection from its position (angles) at the 1d-detector""" """Calculate hkl-indices of a reflection from its position (angles) at the 1d-detector"""
z1 = z1frmd(wave, ga, om, ch, ph, nu) z1 = z1frmd(wave, ga, om, ch, ph, nu)
ubinv = np.linalg.inv(ub) hkl = ub_inv @ z1
hkl = ubinv @ z1
return hkl return hkl