fix(x_ray_align): cleanup of commented code 2
This commit is contained in:
@@ -9,7 +9,7 @@ import numpy as np
|
||||
|
||||
from bec_lib import bec_logger
|
||||
|
||||
#from csaxs_bec.bec_ipython_client.plugins.cSAXS import epics_get, epics_put, fshopen, fshclose
|
||||
# from csaxs_bec.bec_ipython_client.plugins.cSAXS import epics_get, epics_put, fshopen, fshclose
|
||||
|
||||
logger = bec_logger.logger
|
||||
# import builtins to avoid linter errors
|
||||
@@ -24,7 +24,7 @@ if TYPE_CHECKING:
|
||||
|
||||
class XrayEyeAlign:
|
||||
# pixel calibration, multiply to get mm
|
||||
test_wo_movments=True
|
||||
test_wo_movements = True
|
||||
PIXEL_CALIBRATION = 0.1 / 113 # .2 with binning
|
||||
|
||||
def __init__(self, client, flomni: Flomni) -> None:
|
||||
@@ -35,16 +35,16 @@ class XrayEyeAlign:
|
||||
self.alignment_values = {}
|
||||
self.flomni.reset_correction()
|
||||
self.flomni.reset_tomo_alignment_fit()
|
||||
|
||||
@property
|
||||
def gui(self):
|
||||
return self.flomni.xeyegui
|
||||
|
||||
|
||||
def _reset_init_values(self):
|
||||
self.shift_xy = [0, 0]
|
||||
self._xray_fov_xy = [0, 0]
|
||||
|
||||
def update_frame(self,keep_shutter_open=False):
|
||||
def update_frame(self, keep_shutter_open=False):
|
||||
|
||||
self.flomni.flomnigui_show_xeyealign()
|
||||
if not dev.cam_xeye.live_mode_enabled.get():
|
||||
@@ -65,40 +65,44 @@ class XrayEyeAlign:
|
||||
print("Staying in live view, shutter is and remains open!")
|
||||
|
||||
def tomo_rotate(self, val: float):
|
||||
if not self.test_wo_movments:
|
||||
if not self.test_wo_movements:
|
||||
umv(self.device_manager.devices.fsamroy, val)
|
||||
|
||||
def get_tomo_angle(self):
|
||||
return self.device_manager.devices.fsamroy.readback.get()
|
||||
|
||||
def update_fov(self, k: int):
|
||||
self._xray_fov_xy[0] = max(getattr(dev.omny_xray_gui, f"width_x_{k}").get(), self._xray_fov_xy[0])
|
||||
self._xray_fov_xy[1] = max(getattr(dev.omny_xray_gui, f"width_y_{k}").get(), self._xray_fov_xy[1])
|
||||
|
||||
self._xray_fov_xy[0] = max(
|
||||
getattr(dev.omny_xray_gui, f"width_x_{k}").get(), self._xray_fov_xy[0]
|
||||
)
|
||||
self._xray_fov_xy[1] = max(
|
||||
getattr(dev.omny_xray_gui, f"width_y_{k}").get(), self._xray_fov_xy[1]
|
||||
)
|
||||
|
||||
def movement_buttons_enabled(self, enablex: bool, enabley: bool):
|
||||
self.gui.on_motors_enable(enablex,enabley)
|
||||
self.gui.on_motors_enable(enablex, enabley)
|
||||
|
||||
def send_message(self, msg: str):
|
||||
print(f"In alginment GUI: {msg}")
|
||||
self.gui.user_message = msg
|
||||
|
||||
def align(self,keep_shutter_open=False):
|
||||
def align(self, keep_shutter_open=False):
|
||||
self.flomni.flomnigui_show_xeyealign()
|
||||
if not keep_shutter_open:
|
||||
print("This routine can be called with paramter keep_shutter_open=True to keep the shutter always open")
|
||||
print(
|
||||
"This routine can be called with paramter keep_shutter_open=True to keep the shutter always open"
|
||||
)
|
||||
self.send_message("Getting things ready. Please wait...")
|
||||
|
||||
self.gui.enable_submit_button(False)
|
||||
|
||||
#Initialize xray align device
|
||||
#clear potential pending movement requests
|
||||
# Initialize xray align device
|
||||
# clear potential pending movement requests
|
||||
dev.omny_xray_gui.mvx.set(0)
|
||||
dev.omny_xray_gui.mvy.set(0)
|
||||
#reset submit channel
|
||||
# reset submit channel
|
||||
dev.omny_xray_gui.submit.set(0)
|
||||
|
||||
|
||||
self.movement_buttons_enabled(False, False)
|
||||
|
||||
# reset shift xy and fov params
|
||||
@@ -108,8 +112,8 @@ class XrayEyeAlign:
|
||||
|
||||
self.flomni.flomnigui_show_xeyealign()
|
||||
self.flomni.flomnigui_raise()
|
||||
|
||||
if not self.test_wo_movments:
|
||||
|
||||
if not self.test_wo_movements:
|
||||
self.tomo_rotate(0)
|
||||
|
||||
self.flomni.feye_in()
|
||||
@@ -119,7 +123,7 @@ class XrayEyeAlign:
|
||||
self.flomni.feedback_enable_with_reset()
|
||||
|
||||
# disable movement buttons
|
||||
self.movement_buttons_enabled(False,False)
|
||||
self.movement_buttons_enabled(False, False)
|
||||
|
||||
sample_name = self.flomni.sample_get_name(0)
|
||||
self.gui.sample_name = sample_name
|
||||
@@ -127,7 +131,7 @@ class XrayEyeAlign:
|
||||
# this makes sure we are in a defined state
|
||||
self.flomni.feedback_disable()
|
||||
|
||||
if not self.test_wo_movments:
|
||||
if not self.test_wo_movements:
|
||||
self.flomni.fosa_out()
|
||||
|
||||
fsamx_in = self.flomni._get_user_param_safe("fsamx", "in")
|
||||
@@ -145,8 +149,9 @@ class XrayEyeAlign:
|
||||
while True:
|
||||
if dev.omny_xray_gui.submit.get() == 1:
|
||||
|
||||
|
||||
self.alignment_values[k] = getattr(dev.omny_xray_gui, f"xval_x_{k}").get() / 2 * self.PIXEL_CALIBRATION # in mm
|
||||
self.alignment_values[k] = (
|
||||
getattr(dev.omny_xray_gui, f"xval_x_{k}").get() / 2 * self.PIXEL_CALIBRATION
|
||||
) # in mm
|
||||
print(f"Clicked position {k}: x {self.alignment_values[k]}")
|
||||
rtx_position = dev.rtx.readback.get() / 1000
|
||||
print(f"Current rtx position {rtx_position}")
|
||||
@@ -159,14 +164,14 @@ class XrayEyeAlign:
|
||||
self.gui.enable_submit_button(False)
|
||||
|
||||
self.flomni.feedback_disable()
|
||||
if not self.test_wo_movments:
|
||||
if not self.test_wo_movements:
|
||||
fsamx_in = self.flomni._get_user_param_safe("fsamx", "in")
|
||||
umv(dev.fsamx, fsamx_in)
|
||||
|
||||
self.flomni.foptics_out()
|
||||
|
||||
time.sleep(0.5)
|
||||
|
||||
|
||||
self.flomni.feedback_enable_with_reset()
|
||||
|
||||
self.update_frame(keep_shutter_open)
|
||||
@@ -191,13 +196,13 @@ class XrayEyeAlign:
|
||||
elif k == 5: # received sample center value at samroy 270 and done
|
||||
self.send_message("done...")
|
||||
self.gui.enable_submit_button(False)
|
||||
self.movement_buttons_enabled(False,False)
|
||||
self.movement_buttons_enabled(False, False)
|
||||
self.update_fov(k)
|
||||
break
|
||||
|
||||
k += 1
|
||||
dev.omny_xray_gui.step.set(k)
|
||||
#reset submit channel
|
||||
# reset submit channel
|
||||
dev.omny_xray_gui.submit.set(0)
|
||||
_xrayeyalignmvx = dev.omny_xray_gui.mvx.get()
|
||||
if _xrayeyalignmvx != 0:
|
||||
@@ -212,7 +217,7 @@ class XrayEyeAlign:
|
||||
_xrayeyalignmvy = dev.omny_xray_gui.mvy.get()
|
||||
if _xrayeyalignmvy != 0:
|
||||
self.flomni.feedback_disable()
|
||||
if not self.test_wo_movments:
|
||||
if not self.test_wo_movements:
|
||||
umvr(dev.fsamy, _xrayeyalignmvy / 1000)
|
||||
time.sleep(2)
|
||||
dev.omny_xray_gui.mvy.set(0)
|
||||
@@ -224,19 +229,16 @@ class XrayEyeAlign:
|
||||
fovx = self._xray_fov_xy[0] * self.PIXEL_CALIBRATION * 1000 / 2
|
||||
fovy = self._xray_fov_xy[1] * self.PIXEL_CALIBRATION * 1000 / 2
|
||||
|
||||
|
||||
self.tomo_rotate(0)
|
||||
|
||||
umv(dev.rtx, 0)
|
||||
|
||||
if keep_shutter_open:
|
||||
if self.flomni.OMNYTools.yesno("Close the shutter now?","y"):
|
||||
if self.flomni.OMNYTools.yesno("Close the shutter now?", "y"):
|
||||
dev.omnyfsh.fshclose()
|
||||
self.gui.on_live_view_enabled(False)
|
||||
print("setting 'XOMNYI-XEYE-ACQ:0'")
|
||||
|
||||
|
||||
|
||||
print(
|
||||
f"The largest field of view from the xrayeyealign was \nfovx = {fovx:.0f} microns, fovy"
|
||||
f" = {fovy:.0f} microns"
|
||||
@@ -245,15 +247,14 @@ class XrayEyeAlign:
|
||||
|
||||
print("Then LOAD ALIGNMENT PARAMETERS by running flomni.read_alignment_offset()\n")
|
||||
|
||||
|
||||
def write_output(self):
|
||||
file = os.path.expanduser("~/Data10/specES1/internal/xrayeye_alignmentvalues")
|
||||
if not os.path.exists(file):
|
||||
os.makedirs(os.path.dirname(file), exist_ok=True)
|
||||
|
||||
|
||||
with open(file, "w") as alignment_values_file:
|
||||
alignment_values_file.write("angle\thorizontal\n")
|
||||
|
||||
|
||||
# Initialize an empty list to store fovx values
|
||||
fovx_list = []
|
||||
fovx_offsets = np.zeros(5) # holds offsets for k = 1..5
|
||||
@@ -269,11 +270,13 @@ class XrayEyeAlign:
|
||||
alignment_values_file.write(f"{fovx_x}\t{fovx_offset * 1000}\n")
|
||||
|
||||
# Now build final numpy array:
|
||||
data = np.array([
|
||||
[0, 45, 90, 135, 180], # angles
|
||||
fovx_offsets*1000, # fovx_offset values
|
||||
[0, 0, 0, 0, 0]
|
||||
])
|
||||
data = np.array(
|
||||
[
|
||||
[0, 45, 90, 135, 180], # angles
|
||||
fovx_offsets * 1000, # fovx_offset values
|
||||
[0, 0, 0, 0, 0],
|
||||
]
|
||||
)
|
||||
self.gui.submit_fit_array(data)
|
||||
print(f"fit submited with {data}")
|
||||
print("todo mirko: submitted data is 1000 fold in amplitude")
|
||||
|
||||
Reference in New Issue
Block a user