fixes. ready for first merge.

This commit is contained in:
Holler Mirko
2024-10-08 17:10:43 +02:00
committed by wakonig_k
parent 3ae62c8ff9
commit 20a4f4d0bc
8 changed files with 98 additions and 76 deletions

View File

@@ -1521,7 +1521,7 @@ class Flomni(
angles = np.flip(angles)
for angle in angles:
self.progress["subtomo"] = subtomo_number
self.progress["subtomo_projection"] = angles.index(angle)
self.progress["subtomo_projection"] = np.where(angles == angle)[0][0]
self.progress["subtomo_total_projections"] = 180 / self.tomo_angle_stepsize
self.progress["projection"] = (subtomo_number - 1) * self.progress[
"subtomo_total_projections"
@@ -1701,7 +1701,7 @@ class Flomni(
def _print_progress(self):
print("\x1b[95mProgress report:")
print(f"Tomo type: ....................... {self.progress['tomo_type']}")
print(f"Projection: ...................... {self.progress['projection']}")
print(f"Projection: ...................... {self.progress['projection']:.0f}")
print(f"Total projections expected ....... {self.progress['total_projections']}")
print(f"Angle: ........................... {self.progress['angle']}")
print(f"Current subtomo: ................. {self.progress['subtomo']}")

View File

@@ -922,7 +922,7 @@ class OMNY(
angles = np.flip(angles)
for angle in angles:
self.progress["subtomo"] = subtomo_number
self.progress["subtomo_projection"] = angles.index(angle)
self.progress["subtomo_projection"] = np.where(angles == angle)[0][0]
self.progress["subtomo_total_projections"] = 180 / self.tomo_angle_stepsize
self.progress["projection"] = (subtomo_number - 1) * self.progress[
"subtomo_total_projections"
@@ -1103,7 +1103,7 @@ class OMNY(
def _print_progress(self):
print("\x1b[95mProgress report:")
print(f"Tomo type: ....................... {self.progress['tomo_type']}")
print(f"Projection: ...................... {self.progress['projection']}")
print(f"Projection: ...................... {self.progress['projection']:.0f}")
print(f"Total projections expected ....... {self.progress['total_projections']}")
print(f"Angle: ........................... {self.progress['angle']}")
print(f"Current subtomo: ................. {self.progress['subtomo']}")
@@ -1202,7 +1202,7 @@ class OMNY(
with open(tomo_scan_numbers_file, "a+") as out_file:
# pylint: disable=undefined-variable
out_file.write(
f"{scan_number} {angle} {dev.fsamroy.read()['fsamroy']['value']:.3f} {self.tomo_id} {subtomo_number} {0} {self.sample_name}\n"
f"{scan_number} {angle} {dev.osamroy.read()['osamroy']['value']:.3f} {self.tomo_id} {subtomo_number} {0} {self.sample_name}\n"
)
def tomo_scan_projection(self, angle: float):

0
csaxs_bec/device_configs/bec_device_config_sastt.yaml Executable file → Normal file
View File

View File

@@ -1,31 +1,31 @@
############################################################
#################### IDS Camera ######################
############################################################
# cam200:
# description: Camera200
# deviceClass: csaxs_bec.devices.ids_cameras.ids_camera.IDSCamera
# deviceConfig:
# camera_ID: 200
# bits_per_pixel: 24
# channels: 3
# m_n_colormode: 1
# enabled: true
# onFailure: buffer
# readOnly: false
# readoutPriority: async
cam200:
description: Camera200
deviceClass: csaxs_bec.devices.ids_cameras.ids_camera.IDSCamera
deviceConfig:
camera_ID: 200
bits_per_pixel: 24
channels: 3
m_n_colormode: 1
enabled: true
onFailure: buffer
readOnly: false
readoutPriority: async
# cam201:
# description: Camera201
# deviceClass: csaxs_bec.devices.ids_cameras.ids_camera.IDSCamera
# deviceConfig:
# camera_ID: 201
# bits_per_pixel: 24
# channels: 3
# m_n_colormode: 1
# enabled: true
# onFailure: buffer
# readOnly: false
# readoutPriority: async
cam201:
description: Camera201
deviceClass: csaxs_bec.devices.ids_cameras.ids_camera.IDSCamera
deviceConfig:
camera_ID: 201
bits_per_pixel: 24
channels: 3
m_n_colormode: 1
enabled: true
onFailure: buffer
readOnly: false
readoutPriority: async
# cam202:
# description: Camera202

View File

@@ -17,7 +17,8 @@ class IDSCustomPrepare(CustomDetectorMixin):
self.ueye = ueye
self.h_cam = None
self.s_info =None
self._live_data_thread = None
self.data_thread = None
self.thread_event = None
@@ -144,15 +145,17 @@ class IDSCustomPrepare(CustomDetectorMixin):
startmeasureframerate=True
Gain = False
#start thread to receive data
self._start_data_thread()
#Start live mode of camera immediately
self.parent.start_live_mode()
def _start_data_thread(self):
self._live_data_thread = threading.Thread(target=self._receive_data_from_camera, daemon = True)
self._live_data_thread.start()
self.thread_event = threading.Event()
self.data_thread = threading.Thread(target=self._receive_data_from_camera, daemon = True)
self.data_thread.start()
def _receive_data_from_camera(self):
while True:
while not self.thread_event.is_set():
# In order to display the image in an OpenCV window we need to...
# ...extract the data of our image memory
@@ -163,48 +166,68 @@ class IDSCustomPrepare(CustomDetectorMixin):
# ...reshape it in an numpy array...
frame = np.reshape(array,(self.height.value, self.width.value, self.bytes_per_pixel))
self.parent.image_data.put(frame)
self.parent._run_subs(sub_type=self.parent.SUB_MONITOR, value=frame)
if self.parent._destroyed is True:
break
time.sleep(0.1)
def on_trigger(self):
self.parent._run_subs(self.parent.SUB_MONITOR, value=self.parent.image_data.get())
pass
# self.parent._run_subs(sub_type=self.parent.SUB_MONITOR, value=self.parent.image_data.get())
class IDSCamera(PSIDetectorBase):
USER_ACCESS = ["custom_prepare"]
custom_prepare_cls = IDSCustomPrepare
USER_ACCESS = ["start_live_mode", "stop_live_mode"]
custom_prepare_cls = IDSCustomPrepare
image_data = Cpt(SetableSignal, value=0, kind=Kind.omitted)
image_data = Cpt(SetableSignal, value=np.empty((100,100)), kind=Kind.omitted)
SUB_MONITOR = "device_monitor_2d"
_default_sub = SUB_MONITOR
SUB_MONITOR = "device_monitor_2d"
_default_sub = SUB_MONITOR
def __init__(self,
prefix="",
*,
name:str,
camera_ID: int,
bits_per_pixel: int,
channels: int,
m_n_colormode: int,
kind=None,
parent=None,
device_manager=None,
**kwargs):
super().__init__(prefix, name=name, kind=kind, parent=parent, device_manager=device_manager, **kwargs)
self.camera_ID = camera_ID
self.bits_per_pixel = bits_per_pixel
self.channels = channels
self.m_n_colormode = m_n_colormode
self.wait_for_connection()
def __init__(self,
prefix="",
*,
name:str,
camera_ID: int,
bits_per_pixel: int,
channels: int,
m_n_colormode: int,
kind=None,
parent=None,
device_manager=None,
**kwargs):
super().__init__(prefix, name=name, kind=kind, parent=parent, device_manager=device_manager, **kwargs)
self.camera_ID = camera_ID
self.bits_per_pixel = bits_per_pixel
self.channels = channels
self.m_n_colormode = m_n_colormode
self.wait_for_connection()
def wait_for_connection(self, all_signals=False, timeout=10):
super().wait_for_connection(all_signals, timeout)
self.custom_prepare.on_connection_established()
def wait_for_connection(self, all_signals=False, timeout=10):
super().wait_for_connection(all_signals, timeout)
self.custom_prepare.on_connection_established()
def destroy(self):
"""Extend Ophyds destroy function to kill the data thread"""
self.stop_live_mode()
super().destroy()
def start_live_mode(self):
if self.custom_prepare.data_thread is not None:
self.stop_live_mode()
self.custom_prepare._start_data_thread()
def stop_live_mode(self):
""" Stopping the camera live mode.
"""
if self.custom_prepare.thread_event is not None:
self.custom_prepare.thread_event.set()
if self.custom_prepare.data_thread is not None:
self.custom_prepare.data_thread.join()
self.custom_prepare.thread_event = None
self.custom_prepare.data_thread = None
"""from pyueye import ueye

View File

@@ -82,10 +82,9 @@ class OMNYGalilReadbackSignal(GalilSignalRO):
try:
rt = self.parent.device_manager.devices["rtx"]
if rt.enabled:
rt.obj.controller.set_rotation_angle(val[self.parent.name]["value"])
rt.obj.controller.set_rotation_angle(val[self.parent.name]["value"]-25+54)
except KeyError:
logger.warning("Failed to set RT value during ogalil readback.")
# val[self.parent.name]["value"] = val[self.parent.name]["value"]+25
return val

View File

@@ -59,8 +59,8 @@ class OMNYFermatScan(SyncFlyScanBase):
Args:
fovx(float) [um]: Fov in the piezo plane (i.e. piezo range). Max 200 um
fovy(float) [um]: Fov in the piezo plane (i.e. piezo range). Max 100 um
cenx(float) [mm]: center position in x.
ceny(float) [mm]: center position in y.
cenx(float) [um]: center position in x.
ceny(float) [um]: center position in y.
exp_time(float) [s]: exposure time
step(float) [um]: stepsize
zshift(float) [um]: shift in z
@@ -70,7 +70,7 @@ class OMNYFermatScan(SyncFlyScanBase):
Returns:
Examples:
>>> scans.omny_fermat_scan(fovx=20, fovy=25, cenx=0.02, ceny=0, zshift=0, angle=0, step=0.5, exp_time=0.01)
>>> scans.omny_fermat_scan(fovx=20, fovy=25, cenx=10, ceny=0, zshift=0, angle=0, step=2, exp_time=0.01)
"""
super().__init__(parameter=parameter, **kwargs)
@@ -162,19 +162,19 @@ class OMNYFermatScan(SyncFlyScanBase):
wait_type="move", device=["rtx", "rtz"], wait_group="prepare_setup_part2"
)
yield from self._transfer_positions_to_omny()
#yield from self.omny_osamx_to_scan_center()
yield from self.omny_osamx_to_scan_center()
def omny_osamx_to_scan_center(self):
# get last setpoint
osamroy_current_setpoint = yield from self.stubs.send_rpc_and_wait(
"osamroy", "user_setpoint.get"
osamx_current_setpoint = yield from self.stubs.send_rpc_and_wait(
"osamx", "user_setpoint.get"
)
omny_samx_in = self._get_user_param_safe("osamx","in")
if np.fabs(osamroy_current_setpoint-(omny_samx_in+self.cenx/1000)) > 0.025:
if np.fabs(osamx_current_setpoint-(omny_samx_in+self.cenx/1000)) > 0.025:
logger.info("Moving osamx to scan center")
self.device_manager.devices["osamx"].read_only = False
yield from self.stubs.send_rpc_and_wait("osamx", 'controller.socket_put_confirmed("axspeed[0]=100")')
yield from self.stubs.set(device="osamx", value=self.cenx/1000, wait_group="osamx_mv")
# yield from self.stubs.send_rpc_and_wait("osamx", "controller.socket_put_confirmed('axspeed[0]=1000')")
yield from self.stubs.set(device="osamx", value=omny_samx_in+self.cenx/1000, wait_group="osamx_mv")
yield from self.stubs.wait(wait_type="move", device="osamx", wait_group="osamx_mv")
self.device_manager.devices["osamx"].read_only = True
time.sleep(4)