Calculate angles in the detector center

For #41
This commit is contained in:
usov_i 2021-10-19 17:33:09 +02:00
parent c5faa0a55a
commit fc4e9c12cf
2 changed files with 63 additions and 1 deletions

View File

@ -36,6 +36,7 @@ from bokeh.models import (
Spacer, Spacer,
Spinner, Spinner,
TableColumn, TableColumn,
Tabs,
Title, Title,
WheelZoomTool, WheelZoomTool,
) )
@ -168,6 +169,34 @@ def create():
omega = np.ones((IMAGE_H, IMAGE_W)) * det_data["omega"][index] omega = np.ones((IMAGE_H, IMAGE_W)) * det_data["omega"][index]
image_source.data.update(gamma=[gamma], nu=[nu], omega=[omega]) image_source.data.update(gamma=[gamma], nu=[nu], omega=[omega])
# update detector center angles
det_c_x = int(IMAGE_W / 2)
det_c_y = int(IMAGE_H / 2)
if det_data["zebra_mode"] == "nb":
gamma_c = gamma[det_c_y, det_c_x]
nu_c = nu[det_c_y, det_c_x]
omega_c = omega[det_c_y, det_c_x]
chi_c = None
phi_c = None
else: # zebra_mode == "bi"
wave = det_data["wave"]
ddist = det_data["ddist"]
gammad = det_data["gamma"][index]
om = det_data["omega"][index]
ch = det_data["chi"][index]
ph = det_data["phi"][index]
nud = det_data["nu"]
nu_c = 0
chi_c, phi_c, gamma_c, omega_c = pyzebra.ang_proc(
wave, ddist, gammad, om, ch, ph, nud, det_c_x, det_c_y
)
detcenter_table_source.data.update(
gamma=[gamma_c], nu=[nu_c], omega=[omega_c], chi=[chi_c], phi=[phi_c],
)
def update_overview_plot(): def update_overview_plot():
h5_data = det_data["data"] h5_data = det_data["data"]
n_im, n_y, n_x = h5_data.shape n_im, n_y, n_x = h5_data.shape
@ -653,6 +682,22 @@ def create():
index_position=None, index_position=None,
) )
detcenter_table_source = ColumnDataSource(dict(gamma=[], omega=[], chi=[], phi=[], nu=[]))
detcenter_table = DataTable(
source=detcenter_table_source,
columns=[
TableColumn(field="gamma", title="Gamma", formatter=num_formatter, width=70),
TableColumn(field="omega", title="Omega", formatter=num_formatter, width=70),
TableColumn(field="chi", title="Chi", formatter=num_formatter, width=70),
TableColumn(field="phi", title="Phi", formatter=num_formatter, width=70),
TableColumn(field="nu", title="Nu", formatter=num_formatter, width=70),
],
height=150,
width=350,
autosize_mode="none",
index_position=None,
)
def add_event_button_callback(): def add_event_button_callback():
pyzebra.fit_event( pyzebra.fit_event(
det_data, det_data,
@ -746,6 +791,13 @@ def create():
) )
# Final layout # Final layout
peak_tables = Tabs(
tabs=[
Panel(child=events_table, title="Actual peak center"),
Panel(child=detcenter_table, title="Peak in the detector center"),
]
)
import_layout = column( import_layout = column(
data_source, upload_div, upload_button, upload_hdf_div, upload_hdf_button, file_select data_source, upload_div, upload_button, upload_hdf_div, upload_hdf_button, file_select
) )
@ -760,7 +812,7 @@ def create():
layout_controls = column( layout_controls = column(
row(metadata_table, index_spinner, column(Spacer(height=25), index_slider)), row(metadata_table, index_spinner, column(Spacer(height=25), index_slider)),
row(column(add_event_button, remove_event_button), events_table), row(column(add_event_button, remove_event_button), peak_tables),
) )
layout_overview = column( layout_overview = column(

View File

@ -372,6 +372,16 @@ def ang2hkl(wave, ddist, gammad, om, ch, ph, nud, ub, x, y):
return hkl return hkl
def ang_proc(wave, ddist, gammad, om, ch, ph, nud, x, y):
"""Utility function to calculate ch, ph, ga, om
"""
ga, nu = det2pol(ddist, gammad, nud, x, y)
z1 = z1frmd(wave, ga, om, ch, ph, nu)
ch2, ph2 = eqchph(z1)
ch, ph, ga, om = fixdnu(wave, z1, ch2, ph2, nu)
return ch, ph, ga, om
def gauss(x, *p): def gauss(x, *p):
"""Defines Gaussian function """Defines Gaussian function