apply black formating

Co-authored-by: Ivan Usov <ivan.a.usov@gmail.com>
This commit is contained in:
zaharko 2020-04-23 10:46:00 +02:00
parent a287b78245
commit 6a3ca53de1
3 changed files with 231 additions and 177 deletions

View File

@ -77,6 +77,7 @@ def update_image():
image_glyph.color_mapper.low = im_min image_glyph.color_mapper.low = im_min
image_glyph.color_mapper.high = im_max image_glyph.color_mapper.high = im_max
def calculate_hkl(setup_type="nb_bi"): def calculate_hkl(setup_type="nb_bi"):
h = np.empty(shape=(IMAGE_H, IMAGE_W)) h = np.empty(shape=(IMAGE_H, IMAGE_W))
k = np.empty(shape=(IMAGE_H, IMAGE_W)) k = np.empty(shape=(IMAGE_H, IMAGE_W))
@ -435,6 +436,7 @@ def auto_toggle_callback(state):
update_image() update_image()
auto_toggle = Toggle(label="Auto Range", active=True, button_type="default") auto_toggle = Toggle(label="Auto Range", active=True, button_type="default")
auto_toggle.on_click(auto_toggle_callback) auto_toggle.on_click(auto_toggle_callback)

View File

@ -1,5 +1,6 @@
import h5py import h5py
def read_h5meta(filepath): def read_h5meta(filepath):
"""Read and parse content of a h5meta file. """Read and parse content of a h5meta file.
@ -57,6 +58,7 @@ def read_detector_data(filepath):
return det_data return det_data
def open_h5meta(filepath): def open_h5meta(filepath):
"""Open h5meta file like *.cami """Open h5meta file like *.cami

View File

@ -4,6 +4,7 @@ from scipy.optimize import curve_fit
from matplotlib import pyplot as plt from matplotlib import pyplot as plt
import pyzebra import pyzebra
def z4frgn(wave, ga, nu): def z4frgn(wave, ga, nu):
"""CALCULATES DIFFRACTION VECTOR IN LAB SYSTEM FROM GA AND NU """CALCULATES DIFFRACTION VECTOR IN LAB SYSTEM FROM GA AND NU
@ -18,13 +19,14 @@ def z4frgn(wave,ga,nu):
pir = 180 / np.pi pir = 180 / np.pi
gar = ga / pir gar = ga / pir
nur = nu / pir nur = nu / pir
z4 = [0., 0., 0.] z4 = [0.0, 0.0, 0.0]
z4[0] = (sin(gar) * cos(nur)) / wave z4[0] = (sin(gar) * cos(nur)) / wave
z4[1]=( cos(gar)*cos(nur)-1. )/wave z4[1] = (cos(gar) * cos(nur) - 1.0) / wave
z4[2] = (sin(nur)) / wave z4[2] = (sin(nur)) / wave
return z4 return z4
def phimat(phi): def phimat(phi):
"""BUSING AND LEVY CONVENTION ROTATION MATRIX FOR PHI OR OMEGA """BUSING AND LEVY CONVENTION ROTATION MATRIX FOR PHI OR OMEGA
@ -48,6 +50,7 @@ def phimat(phi):
return dum return dum
def z1frnb(wave, ga, nu, om): def z1frnb(wave, ga, nu, om):
"""CALCULATE DIFFRACTION VECTOR Z1 FROM GA, OM, NU, ASSUMING CH=PH=0 """CALCULATE DIFFRACTION VECTOR Z1 FROM GA, OM, NU, ASSUMING CH=PH=0
@ -65,6 +68,7 @@ def z1frnb(wave,ga,nu,om):
return z3 return z3
def chimat(chi): def chimat(chi):
"""BUSING AND LEVY CONVENTION ROTATION MATRIX FOR CHI """BUSING AND LEVY CONVENTION ROTATION MATRIX FOR CHI
@ -88,6 +92,7 @@ def chimat(chi):
return dum return dum
def z1frz3(z3, chi, phi): def z1frz3(z3, chi, phi):
"""CALCULATE Z1 = [PHI]T.[CHI]T.Z3 """CALCULATE Z1 = [PHI]T.[CHI]T.Z3
@ -108,6 +113,7 @@ def z1frz3(z3,chi,phi):
return z1 return z1
def z1frmd(wave, ga, om, chi, phi, nu): def z1frmd(wave, ga, om, chi, phi, nu):
"""CALCULATE DIFFRACTION VECTOR Z1 FROM CH, PH, GA, OM, NU """CALCULATE DIFFRACTION VECTOR Z1 FROM CH, PH, GA, OM, NU
@ -122,6 +128,7 @@ def z1frmd(wave,ga,om,chi,phi,nu):
return z1 return z1
def det2pol(ddist, gammad, nud, x, y): def det2pol(ddist, gammad, nud, x, y):
"""CONVERTS FROM DETECTOR COORDINATES TO POLAR COORDINATES """CONVERTS FROM DETECTOR COORDINATES TO POLAR COORDINATES
@ -150,6 +157,7 @@ def det2pol(ddist,gammad,nud,x,y):
return gamma, nu return gamma, nu
def eqchph(z1): def eqchph(z1):
"""CALCULATE CHI, PHI TO PUT THE VECTOR Z1 IN THE EQUATORIAL PLANE """CALCULATE CHI, PHI TO PUT THE VECTOR Z1 IN THE EQUATORIAL PLANE
@ -292,6 +300,7 @@ def fixdnu(wave,z1,ch2,ph2,nu):
# for test run: # for test run:
# angtohkl(wave=1.18,ddist=616,gammad=48.66,om=-22.80,ch=0,ph=0,nud=0,x=128,y=64) # angtohkl(wave=1.18,ddist=616,gammad=48.66,om=-22.80,ch=0,ph=0,nud=0,x=128,y=64)
def angtohkl(wave, ddist, gammad, om, ch, ph, nud, x, y): def angtohkl(wave, ddist, gammad, om, ch, ph, nud, x, y):
"""finds hkl-indices of a reflection from its position (x,y,angles) at the 2d-detector """finds hkl-indices of a reflection from its position (x,y,angles) at the 2d-detector
@ -305,16 +314,44 @@ def angtohkl(wave,ddist,gammad,om,ch,ph,nud,x,y):
# define ub matrix if testing angtohkl(wave=1.18,ddist=616,gammad=48.66,om=-22.80,ch=0,ph=0,nud=0,x=128,y=64) against f90: # define ub matrix if testing angtohkl(wave=1.18,ddist=616,gammad=48.66,om=-22.80,ch=0,ph=0,nud=0,x=128,y=64) against f90:
# ub = np.array([-0.0178803,-0.0749231,0.0282804,-0.0070082,-0.0368001,-0.0577467,0.1609116,-0.0099281,0.0006274]).reshape(3,3) # ub = np.array([-0.0178803,-0.0749231,0.0282804,-0.0070082,-0.0368001,-0.0577467,0.1609116,-0.0099281,0.0006274]).reshape(3,3)
ub = np.array([0.04489,0.02045,-0.2334,-0.06447,0.00129,-0.16356,-0.00328,0.2542,0.0196]).reshape(3,3) ub = np.array(
print('The input values are: ga=', gammad, ', om=', om, ', ch=', ch, ', ph=', ph, ', nu=', nud, ', x=', x, ', y=', y) [0.04489, 0.02045, -0.2334, -0.06447, 0.00129, -0.16356, -0.00328, 0.2542, 0.0196]
).reshape(3, 3)
print(
"The input values are: ga=",
gammad,
", om=",
om,
", ch=",
ch,
", ph=",
ph,
", nu=",
nud,
", x=",
x,
", y=",
y,
)
ga, nu = det2pol(ddist, gammad, nud, x, y) ga, nu = det2pol(ddist, gammad, nud, x, y)
print('The calculated actual angles are: ga=', ga, ', om=', om, ', ch=', ch, ', ph=', ph, ', nu=', nu) print(
"The calculated actual angles are: ga=",
ga,
", om=",
om,
", ch=",
ch,
", ph=",
ph,
", nu=",
nu,
)
z1 = z1frmd(wave, ga, om, ch, ph, nu) z1 = z1frmd(wave, ga, om, ch, ph, nu)
print('The diffraction vector is:', z1[0],z1[1],z1[2]) print("The diffraction vector is:", z1[0], z1[1], z1[2])
ubinv = np.linalg.inv(ub) ubinv = np.linalg.inv(ub)
@ -322,12 +359,23 @@ def angtohkl(wave,ddist,gammad,om,ch,ph,nud,x,y):
k = ubinv[1, 0] * z1[0] + ubinv[1, 1] * z1[1] + ubinv[1, 2] * z1[2] k = ubinv[1, 0] * z1[0] + ubinv[1, 1] * z1[1] + ubinv[1, 2] * z1[2]
l = ubinv[2, 0] * z1[0] + ubinv[2, 1] * z1[1] + ubinv[2, 2] * z1[2] l = ubinv[2, 0] * z1[0] + ubinv[2, 1] * z1[1] + ubinv[2, 2] * z1[2]
print('The Miller indexes are:', h,k,l) print("The Miller indexes are:", h, k, l)
ch2, ph2 = eqchph(z1) ch2, ph2 = eqchph(z1)
ch, ph, ga, om = fixdnu(wave, z1, ch2, ph2, nu) ch, ph, ga, om = fixdnu(wave, z1, ch2, ph2, nu)
print('Bisecting angles to put reflection into the detector center: ga=', ga, ', om=', om, ', ch=', ch, ', ph=', ph, ', nu=', nu) print(
"Bisecting angles to put reflection into the detector center: ga=",
ga,
", om=",
om,
", ch=",
ch,
", ph=",
ph,
", nu=",
nu,
)
def ang2hkl(wave, ddist, gammad, om, ch, ph, nud, ub, x, y): def ang2hkl(wave, ddist, gammad, om, ch, ph, nud, ub, x, y):
@ -340,6 +388,7 @@ def ang2hkl(wave, ddist, gammad, om, ch, ph, nud, ub, x, y):
return hkl return hkl
def gauss(x, *p): def gauss(x, *p):
"""Defines Gaussian function """Defines Gaussian function
@ -350,7 +399,8 @@ def gauss(x, *p):
Gaussian function Gaussian function
""" """
A, mu, sigma = p A, mu, sigma = p
return A*np.exp(-(x-mu)**2/(2.*sigma**2)) return A * np.exp(-((x - mu) ** 2) / (2.0 * sigma ** 2))
def box_int(file, box): def box_int(file, box):
"""Calculates center of the peak in the NB-geometry angles and Intensity of the peak """Calculates center of the peak in the NB-geometry angles and Intensity of the peak
@ -376,7 +426,7 @@ def box_int(file,box):
om = dat["rot_angle"][fr0:frN] om = dat["rot_angle"][fr0:frN]
cnts = np.sum(dat["data"][fr0:frN, j0:jN, i0:iN], axis=(1, 2)) cnts = np.sum(dat["data"][fr0:frN, j0:jN, i0:iN], axis=(1, 2))
p0 = [1., 0., 1.] p0 = [1.0, 0.0, 1.0]
coeff, var_matrix = curve_fit(gauss, range(len(cnts)), cnts, p0=p0) coeff, var_matrix = curve_fit(gauss, range(len(cnts)), cnts, p0=p0)
frC = fr0 + coeff[1] frC = fr0 + coeff[1]
@ -393,16 +443,16 @@ def box_int(file,box):
plt.subplot(131) plt.subplot(131)
plt.plot(range(len(cnts)), cnts) plt.plot(range(len(cnts)), cnts)
plt.plot(x_fit, y_fit) plt.plot(x_fit, y_fit)
plt.ylabel('Intensity in the box') plt.ylabel("Intensity in the box")
plt.xlabel('Frame N of the box') plt.xlabel("Frame N of the box")
label='om' label = "om"
# gamma fit # gamma fit
sliceXY = dat["data"][fr0:frN, j0:jN, i0:iN] sliceXY = dat["data"][fr0:frN, j0:jN, i0:iN]
sliceXZ = np.sum(sliceXY, axis=1) sliceXZ = np.sum(sliceXY, axis=1)
sliceYZ = np.sum(sliceXY, axis=2) sliceYZ = np.sum(sliceXY, axis=2)
projX = np.sum(sliceXZ, axis=0) projX = np.sum(sliceXZ, axis=0)
p0 = [1., 0., 1.] p0 = [1.0, 0.0, 1.0]
coeff, var_matrix = curve_fit(gauss, range(len(projX)), projX, p0=p0) coeff, var_matrix = curve_fit(gauss, range(len(projX)), projX, p0=p0)
x = i0 + coeff[1] x = i0 + coeff[1]
# gamma plot # gamma plot
@ -411,12 +461,12 @@ def box_int(file,box):
plt.subplot(132) plt.subplot(132)
plt.plot(range(len(projX)), projX) plt.plot(range(len(projX)), projX)
plt.plot(x_fit, y_fit) plt.plot(x_fit, y_fit)
plt.ylabel('Intensity in the box') plt.ylabel("Intensity in the box")
plt.xlabel('X-pixel of the box') plt.xlabel("X-pixel of the box")
# nu fit # nu fit
projY = np.sum(sliceYZ, axis=0) projY = np.sum(sliceYZ, axis=0)
p0 = [1., 0., 1.] p0 = [1.0, 0.0, 1.0]
coeff, var_matrix = curve_fit(gauss, range(len(projY)), projY, p0=p0) coeff, var_matrix = curve_fit(gauss, range(len(projY)), projY, p0=p0)
y = j0 + coeff[1] y = j0 + coeff[1]
# nu plot # nu plot
@ -425,9 +475,9 @@ def box_int(file,box):
plt.subplot(133) plt.subplot(133)
plt.plot(range(len(projY)), projY) plt.plot(range(len(projY)), projY)
plt.plot(x_fit, y_fit) plt.plot(x_fit, y_fit)
plt.ylabel('Intensity in the box') plt.ylabel("Intensity in the box")
plt.xlabel('Y-pixel of the box') plt.xlabel("Y-pixel of the box")
ga, nu = pyzebra.det2pol(ddist, sttC, nuC, x, y) ga, nu = pyzebra.det2pol(ddist, sttC, nuC, x, y)
return ga[0], omP, nu[0], Int # x0,y0,x0_fit,y0_fit,x1,y1,x1_fit,y1_fit,x2,y2,x2_fit,y2_fit return ga[0], omP, nu[0], Int