From e80379d63111b04e0548740dd10497db4b7dd4a5 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Mon, 18 Sep 2023 12:11:42 +0200 Subject: [PATCH 001/151] Fixing the ambiguity with Poller value and .any --- mxcubecore/Command/Tango.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/mxcubecore/Command/Tango.py b/mxcubecore/Command/Tango.py index d6e8b6d35f..3616b95a79 100644 --- a/mxcubecore/Command/Tango.py +++ b/mxcubecore/Command/Tango.py @@ -21,6 +21,7 @@ import logging import gevent import gevent.event +import numpy as np try: import Queue as queue @@ -323,18 +324,23 @@ def get_info(self): self._device_initialized.wait(timeout=3) return self.device.get_attribute_config(self.attribute_name) - def update(self, value=Poller.NotInitializedValue): + - if value == Poller.NotInitializedValue: + def update(self, value=None): + if value is None: value = self.get_value() elif isinstance(value, tuple): value = list(value) - elif isinstance(value, numpy.ndarray): - value = value.tolist() + elif isinstance(value, np.ndarray): + if (value == Poller.NotInitializedValue).all(): + value = self.get_value() + else: + value = value.tolist() self.value = value self.emit("update", value) + def get_value(self): if self.read_as_str: value = self.device.read_attribute( From 5f29dc6316e2fb5c20159a6733225a2b29d1e889 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Mon, 18 Sep 2023 12:42:20 +0200 Subject: [PATCH 002/151] P11Collect additional debug after upgrade --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 124 +++++++++++------- 1 file changed, 75 insertions(+), 49 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index 3171a52753..c2f1b2e9d9 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -39,24 +39,42 @@ from mxcubecore.Command.Tango import DeviceProxy +import gevent +import time +import numpy as np +import logging +import os +import sys +import math +import h5py import triggerUtils +from tango import DeviceProxy, DevState FILE_TIMEOUT = 5 class P11Collect(AbstractCollect): + def __init__(self, *args): super(P11Collect, self).__init__(*args) + def init(self): + + super(P11Collect,self).init() + + # os.system("/opt/xray/bin/adxv -socket -colors Gray -rings &") + + # os.system("/bin/bash /gpfs/local/shared/MXCuBE/STRELA/start_viewer_zmq.sh") + + self.default_speed = self.get_property("omega_default_speed", 130) - self.turnback_time = self.get_property("turnback_time", 0.1) - self.filter_server_name = self.get_property("filterserver") - self.mono_server_name = self.get_property("monoserver") + self.turnback_time = self.get_property("turnback_time", 0.3) + self.filter_server_name = self.get_property('filterserver') + self.mono_server_name = self.get_property('monoserver') self.filter_server = DeviceProxy(self.filter_server_name) self.mono_server = DeviceProxy(self.mono_server_name) - self.diffr = HWR.beamline.diffractometer self.lower_bound_ch = self.get_channel_object("acq_lower_bound") self.upper_bound_ch = self.get_channel_object("acq_upper_bound") @@ -66,26 +84,9 @@ def __init__(self, *args): self.acq_off_cmd = self.get_command_object("acq_off") self.acq_window_off_cmd = self.get_command_object("acq_window_off") - self.latest_frames = 1 - self.acq_speed = 1.0 - self.init_ok = False - self.latest_h5_filename = "TEST_master.h5" - - def init(self): - super(P11Collect, self).init() - - # os.system("/opt/xray/bin/adxv -socket -colors Gray -rings &") - - # os.system("/bin/bash /gpfs/local/shared/MXCuBE/STRELA/start_viewer_zmq.sh") - - if None in [ - self.lower_bound_ch, - self.upper_bound_ch, - self.acq_arm_cmd, - self.acq_on_cmd, - self.acq_off_cmd, - self.acq_window_off_cmd, - ]: + if None in [self.lower_bound_ch, self.upper_bound_ch, + self.acq_arm_cmd, self.acq_on_cmd, self.acq_off_cmd, + self.acq_window_off_cmd]: self.init_ok = False self.log.debug("lower_bound_ch: %s" % self.lower_bound_ch) self.log.debug("upper_bound_ch: %s" % self.upper_bound_ch) @@ -95,7 +96,6 @@ def init(self): self.log.debug("acq_window_off_cmd: %s" % self.acq_window_off_cmd) else: self.init_ok = True - @task def move_motors(self, motor_position_dict): HWR.beamline.diffractometer.wait_omega() @@ -339,21 +339,32 @@ def collect_std_collection(self, start_angle, stop_angle): :param stop_angle: The stop_angle parameter is the final angle at which the collection should stop """ + HWR.beamline.diffractometer.wait_omega() - self.omega_mv(start_angle, self.default_speed) - + start_pos = start_angle - self.turnback_time*self.acq_speed + stop_pos = stop_angle + self.turnback_time*self.acq_speed + + + self.log.debug("#COLLECT# Running OMEGA through the std acquisition") if start_angle <= stop_angle: - self.lower_bound_ch.set_value(start_angle) - self.upper_bound_ch.set_value(stop_angle) + self.lower_bound_ch.set_value(start_angle) + self.upper_bound_ch.set_value(stop_angle) + else: - self.lower_bound_ch.set_value(stop_angle) - self.upper_bound_ch.set_value(start_angle) - self.acq_arm_cmd() + self.lower_bound_ch.set_value(stop_angle) + self.upper_bound_ch.set_value(start_angle) - final_pos = stop_angle + self.acq_speed * self.turnback_time - self.omega_mv(final_pos, self.acq_speed) + self.omega_mv(start_pos, self.default_speed) + self.acq_arm_cmd() + self.omega_mv(stop_pos, self.acq_speed) + time.sleep(0.5) + self.acq_off_cmd() + self.acq_window_off_cmd() + self.omega_mv(stop_angle, self.acq_speed) + HWR.beamline.diffractometer.wait_omega() + def collect_characterisation( self, start_angle, img_range, nimages, angle_inc, exp_time @@ -374,7 +385,7 @@ def collect_characterisation( diffr = HWR.beamline.diffractometer - self.log.debug("#COLLECT# Running OMEGA through the char acquisition") + self.log.debug("#COLLECT# Running OMEGA through the characteristation acquisition") self.omega_mv(start_angle, self.default_speed) @@ -382,26 +393,36 @@ def collect_characterisation( print("collecting image %s" % img_no) start_at = start_angle + angle_inc * img_no stop_angle = start_at + img_range * 1.0 + #print("======= CHARACTERISATION Adding angle and range to the header...") + #Add start angle to the header + #detector = HWR.beamline.detector + #detector.set_eiger_start_angle(start_at) + + # Add angle increment to the header + #detector.set_eiger_angle_increment(angle_inc) + print("collecting image %s, angle %f" % (img_no, start_at)) if start_at >= stop_angle: - init_pos = start_at - self.acq_speed * self.turnback_time + init_pos = start_at #- self.acq_speed * self.turnback_time # init_pos = start_at - 1.5 else: - init_pos = start_at + self.acq_speed * self.turnback_time + init_pos = start_at #+ self.acq_speed * self.turnback_time # init_pos = start_at + 1.5 - self.omega_mv(init_pos, self.default_speed) - self.collect_std_collection(start_angle, stop_angle) - diffr.set_omega_velocity(self.default_speed) - self.acq_window_off_cmd() - self.acq_off_cmd() - self.log.debug( - "======= collect_characterisation Waiting =======================================" - ) + # self.omega_mv(init_pos, self.default_speed) + self.collect_std_collection(start_at, stop_angle) + + #This part goes to standard collection. Otherwise it produces phantom openings. + # diffr.set_omega_velocity(self.default_speed) + # self.acq_window_off_cmd() + # self.acq_off_cmd() + self.log.debug("======= collect_characterisation Waiting =======================================") - # Let adxv know whether it is + #Let adxv know whether it is # self.adxv_notify(self.latest_h5_filename,img_no+1) + + # time.sleep(1) def adxv_notify(self, image_filename, image_num=1): """ @@ -439,12 +460,17 @@ def acquisition_cleanup(self): try: diffr = HWR.beamline.diffractometer detector = HWR.beamline.detector - diffr.set_omega_velocity(self.default_speed) - self.acq_window_off_cmd() + detector.stop_acquisition() + diffr.wait_omega() + # ================= + #It is probably already finished in a standard collection. self.acq_off_cmd() + self.acq_window_off_cmd() + # ================== + diffr.set_omega_velocity(self.default_speed) self.log.debug("#COLLECT# Closing detector cover") diffr.detector_cover_close(wait=True) - detector.stop_acquisition() + except RuntimeError: self.log.error(traceback.format_exc()) From d2b8c35ecb5df5038c677a6ce3b200ddc4e5a1fb Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Mon, 18 Sep 2023 12:11:42 +0200 Subject: [PATCH 003/151] Fixing the ambiguity with Poller value and .any --- mxcubecore/Command/Tango.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mxcubecore/Command/Tango.py b/mxcubecore/Command/Tango.py index 96e998e14e..6f5c98f84f 100644 --- a/mxcubecore/Command/Tango.py +++ b/mxcubecore/Command/Tango.py @@ -21,6 +21,7 @@ import logging import gevent import gevent.event +import numpy as np try: import Queue as queue @@ -319,7 +320,7 @@ def get_info(self): self._device_initialized.wait(timeout=3) return self.device.get_attribute_config(self.attribute_name) - def update(self, value=Poller.NotInitializedValue): + # start with checking if we have a numpy array, as comparing # numpy.ndarray to Poller.NotInitializedValue raises a ValueError exception @@ -333,6 +334,7 @@ def update(self, value=Poller.NotInitializedValue): self.value = value self.emit("update", value) + def get_value(self): if self.read_as_str: value = self.device.read_attribute( From ba7d34cbbac791deddee39c070fe525eec442036 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Mon, 18 Sep 2023 12:42:20 +0200 Subject: [PATCH 004/151] P11Collect additional debug after upgrade --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 124 +++++++++++------- 1 file changed, 75 insertions(+), 49 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index 3171a52753..c2f1b2e9d9 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -39,24 +39,42 @@ from mxcubecore.Command.Tango import DeviceProxy +import gevent +import time +import numpy as np +import logging +import os +import sys +import math +import h5py import triggerUtils +from tango import DeviceProxy, DevState FILE_TIMEOUT = 5 class P11Collect(AbstractCollect): + def __init__(self, *args): super(P11Collect, self).__init__(*args) + def init(self): + + super(P11Collect,self).init() + + # os.system("/opt/xray/bin/adxv -socket -colors Gray -rings &") + + # os.system("/bin/bash /gpfs/local/shared/MXCuBE/STRELA/start_viewer_zmq.sh") + + self.default_speed = self.get_property("omega_default_speed", 130) - self.turnback_time = self.get_property("turnback_time", 0.1) - self.filter_server_name = self.get_property("filterserver") - self.mono_server_name = self.get_property("monoserver") + self.turnback_time = self.get_property("turnback_time", 0.3) + self.filter_server_name = self.get_property('filterserver') + self.mono_server_name = self.get_property('monoserver') self.filter_server = DeviceProxy(self.filter_server_name) self.mono_server = DeviceProxy(self.mono_server_name) - self.diffr = HWR.beamline.diffractometer self.lower_bound_ch = self.get_channel_object("acq_lower_bound") self.upper_bound_ch = self.get_channel_object("acq_upper_bound") @@ -66,26 +84,9 @@ def __init__(self, *args): self.acq_off_cmd = self.get_command_object("acq_off") self.acq_window_off_cmd = self.get_command_object("acq_window_off") - self.latest_frames = 1 - self.acq_speed = 1.0 - self.init_ok = False - self.latest_h5_filename = "TEST_master.h5" - - def init(self): - super(P11Collect, self).init() - - # os.system("/opt/xray/bin/adxv -socket -colors Gray -rings &") - - # os.system("/bin/bash /gpfs/local/shared/MXCuBE/STRELA/start_viewer_zmq.sh") - - if None in [ - self.lower_bound_ch, - self.upper_bound_ch, - self.acq_arm_cmd, - self.acq_on_cmd, - self.acq_off_cmd, - self.acq_window_off_cmd, - ]: + if None in [self.lower_bound_ch, self.upper_bound_ch, + self.acq_arm_cmd, self.acq_on_cmd, self.acq_off_cmd, + self.acq_window_off_cmd]: self.init_ok = False self.log.debug("lower_bound_ch: %s" % self.lower_bound_ch) self.log.debug("upper_bound_ch: %s" % self.upper_bound_ch) @@ -95,7 +96,6 @@ def init(self): self.log.debug("acq_window_off_cmd: %s" % self.acq_window_off_cmd) else: self.init_ok = True - @task def move_motors(self, motor_position_dict): HWR.beamline.diffractometer.wait_omega() @@ -339,21 +339,32 @@ def collect_std_collection(self, start_angle, stop_angle): :param stop_angle: The stop_angle parameter is the final angle at which the collection should stop """ + HWR.beamline.diffractometer.wait_omega() - self.omega_mv(start_angle, self.default_speed) - + start_pos = start_angle - self.turnback_time*self.acq_speed + stop_pos = stop_angle + self.turnback_time*self.acq_speed + + + self.log.debug("#COLLECT# Running OMEGA through the std acquisition") if start_angle <= stop_angle: - self.lower_bound_ch.set_value(start_angle) - self.upper_bound_ch.set_value(stop_angle) + self.lower_bound_ch.set_value(start_angle) + self.upper_bound_ch.set_value(stop_angle) + else: - self.lower_bound_ch.set_value(stop_angle) - self.upper_bound_ch.set_value(start_angle) - self.acq_arm_cmd() + self.lower_bound_ch.set_value(stop_angle) + self.upper_bound_ch.set_value(start_angle) - final_pos = stop_angle + self.acq_speed * self.turnback_time - self.omega_mv(final_pos, self.acq_speed) + self.omega_mv(start_pos, self.default_speed) + self.acq_arm_cmd() + self.omega_mv(stop_pos, self.acq_speed) + time.sleep(0.5) + self.acq_off_cmd() + self.acq_window_off_cmd() + self.omega_mv(stop_angle, self.acq_speed) + HWR.beamline.diffractometer.wait_omega() + def collect_characterisation( self, start_angle, img_range, nimages, angle_inc, exp_time @@ -374,7 +385,7 @@ def collect_characterisation( diffr = HWR.beamline.diffractometer - self.log.debug("#COLLECT# Running OMEGA through the char acquisition") + self.log.debug("#COLLECT# Running OMEGA through the characteristation acquisition") self.omega_mv(start_angle, self.default_speed) @@ -382,26 +393,36 @@ def collect_characterisation( print("collecting image %s" % img_no) start_at = start_angle + angle_inc * img_no stop_angle = start_at + img_range * 1.0 + #print("======= CHARACTERISATION Adding angle and range to the header...") + #Add start angle to the header + #detector = HWR.beamline.detector + #detector.set_eiger_start_angle(start_at) + + # Add angle increment to the header + #detector.set_eiger_angle_increment(angle_inc) + print("collecting image %s, angle %f" % (img_no, start_at)) if start_at >= stop_angle: - init_pos = start_at - self.acq_speed * self.turnback_time + init_pos = start_at #- self.acq_speed * self.turnback_time # init_pos = start_at - 1.5 else: - init_pos = start_at + self.acq_speed * self.turnback_time + init_pos = start_at #+ self.acq_speed * self.turnback_time # init_pos = start_at + 1.5 - self.omega_mv(init_pos, self.default_speed) - self.collect_std_collection(start_angle, stop_angle) - diffr.set_omega_velocity(self.default_speed) - self.acq_window_off_cmd() - self.acq_off_cmd() - self.log.debug( - "======= collect_characterisation Waiting =======================================" - ) + # self.omega_mv(init_pos, self.default_speed) + self.collect_std_collection(start_at, stop_angle) + + #This part goes to standard collection. Otherwise it produces phantom openings. + # diffr.set_omega_velocity(self.default_speed) + # self.acq_window_off_cmd() + # self.acq_off_cmd() + self.log.debug("======= collect_characterisation Waiting =======================================") - # Let adxv know whether it is + #Let adxv know whether it is # self.adxv_notify(self.latest_h5_filename,img_no+1) + + # time.sleep(1) def adxv_notify(self, image_filename, image_num=1): """ @@ -439,12 +460,17 @@ def acquisition_cleanup(self): try: diffr = HWR.beamline.diffractometer detector = HWR.beamline.detector - diffr.set_omega_velocity(self.default_speed) - self.acq_window_off_cmd() + detector.stop_acquisition() + diffr.wait_omega() + # ================= + #It is probably already finished in a standard collection. self.acq_off_cmd() + self.acq_window_off_cmd() + # ================== + diffr.set_omega_velocity(self.default_speed) self.log.debug("#COLLECT# Closing detector cover") diffr.detector_cover_close(wait=True) - detector.stop_acquisition() + except RuntimeError: self.log.error(traceback.format_exc()) From df5dfd36bc865d093b432691a40cb6f965956976 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 09:53:30 +0200 Subject: [PATCH 005/151] Force upgrade from the develop to avoid merging conflict --- mxcubecore/Command/Tango.py | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/mxcubecore/Command/Tango.py b/mxcubecore/Command/Tango.py index 722059903b..96e998e14e 100644 --- a/mxcubecore/Command/Tango.py +++ b/mxcubecore/Command/Tango.py @@ -21,7 +21,6 @@ import logging import gevent import gevent.event -import numpy as np try: import Queue as queue @@ -320,9 +319,8 @@ def get_info(self): self._device_initialized.wait(timeout=3) return self.device.get_attribute_config(self.attribute_name) - + def update(self, value=Poller.NotInitializedValue): -<<<<<<< HEAD # start with checking if we have a numpy array, as comparing # numpy.ndarray to Poller.NotInitializedValue raises a ValueError exception if isinstance(value, numpy.ndarray): @@ -331,23 +329,10 @@ def get_info(self): value = self.get_value() elif isinstance(value, tuple): value = list(value) -======= - def update(self, value=None): - if value is None: - value = self.get_value() - elif isinstance(value, tuple): - value = list(value) - elif isinstance(value, np.ndarray): - if (value == Poller.NotInitializedValue).all(): - value = self.get_value() - else: - value = value.tolist() ->>>>>>> p11_develop self.value = value self.emit("update", value) - def get_value(self): if self.read_as_str: value = self.device.read_attribute( From de981e70122fee3f7c2255f7fd2ea3e4e9b4e83e Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 10:34:20 +0200 Subject: [PATCH 006/151] Added missing warnings module --- mxcubecore/HardwareObjects/ISPyBClient.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mxcubecore/HardwareObjects/ISPyBClient.py b/mxcubecore/HardwareObjects/ISPyBClient.py index 34797ad402..56475e92bb 100644 --- a/mxcubecore/HardwareObjects/ISPyBClient.py +++ b/mxcubecore/HardwareObjects/ISPyBClient.py @@ -8,6 +8,7 @@ from pprint import pformat from collections import namedtuple from datetime import datetime +import warnings try: from urlparse import urljoin From 24c07c71a92789a7ec07dd2c79671eba288482a2 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 11:20:37 +0200 Subject: [PATCH 007/151] Enabled back explicit check on if beamtimeid is open --- mxcubecore/HardwareObjects/DESY/P11Session.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Session.py b/mxcubecore/HardwareObjects/DESY/P11Session.py index fc959c288a..2e00a81615 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Session.py +++ b/mxcubecore/HardwareObjects/DESY/P11Session.py @@ -85,8 +85,7 @@ def info_set_defaults(self): self.beamtime_info["rootPath"] = PATH_FALLBACK def is_beamtime_open(self): - return True - # return self.is_writable_dir( os.path.join(PATH_BEAMTIME, self.raw_data_folder_name) ) + return self.is_writable_dir( os.path.join(PATH_BEAMTIME, self.raw_data_folder_name) ) def is_commissioning_open(self): return self.is_writable_dir( From d22d705a3467f4b45619946a6b0bc5f91200a2a6 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 11:29:10 +0200 Subject: [PATCH 008/151] Added debug info in case beamtime ID is not opened --- mxcubecore/HardwareObjects/DESY/P11Session.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mxcubecore/HardwareObjects/DESY/P11Session.py b/mxcubecore/HardwareObjects/DESY/P11Session.py index 2e00a81615..4e1abb1f16 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Session.py +++ b/mxcubecore/HardwareObjects/DESY/P11Session.py @@ -85,6 +85,12 @@ def info_set_defaults(self): self.beamtime_info["rootPath"] = PATH_FALLBACK def is_beamtime_open(self): + self.log.debug("=========== CHECKING IF BEAMTIME ID IS OPEN... ============") + if self.is_writable_dir(os.path.join(PATH_BEAMTIME, self.raw_data_folder_name)): + self.log.debug("=========== BEAMTIME IS OPEN (/gpfs/current exists) ============") + else: + self.log.debug("=========== NO BEMTIME ID IS OPEN (check /gpfs/current) ============") + return self.is_writable_dir( os.path.join(PATH_BEAMTIME, self.raw_data_folder_name) ) def is_commissioning_open(self): From 4a38247d430217671c848fdbe10c21e4d98bfef3 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 16:58:08 +0200 Subject: [PATCH 009/151] Added beamtime info as a property --- mxcubecore/HardwareObjects/DESY/P11Session.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mxcubecore/HardwareObjects/DESY/P11Session.py b/mxcubecore/HardwareObjects/DESY/P11Session.py index 4e1abb1f16..f2fdfce8b0 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Session.py +++ b/mxcubecore/HardwareObjects/DESY/P11Session.py @@ -116,6 +116,9 @@ def get_current_proposal_number(self): info = self.get_beamtime_info() return info["proposalId"] + def get_beamtime_info(self): + return self.beamtime_info + def read_beamtime_info(self): self.log.debug("=========== READING BEAMTIME INFO ============") if os.path.exists(PATH_BEAMTIME): From 480ec3eb2c4037785a6da8d71b80bafeffc64dca Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 16:59:56 +0200 Subject: [PATCH 010/151] Added additional debug messages for shutter --- mxcubecore/HardwareObjects/DESY/P11Shutter.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mxcubecore/HardwareObjects/DESY/P11Shutter.py b/mxcubecore/HardwareObjects/DESY/P11Shutter.py index 3a147822dc..1fe79adaed 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Shutter.py +++ b/mxcubecore/HardwareObjects/DESY/P11Shutter.py @@ -133,9 +133,12 @@ def update_shutter_state(self, state=None): if state is None: state = self.chan_state.get_value() + self.log.debug(" SHUTTER state changed") if state[0] == 3: + self.log.debug(" P11SHUTTER IS OPEN") value = self.VALUES.OPEN else: + self.log.debug(" P11SHUTTER IS CLOSED") value = self.VALUES.CLOSED # else: @@ -146,6 +149,7 @@ def update_shutter_state(self, state=None): self.update_value(value) + self.log.debug(" update shutter state done") return value def simulated_update(self): From 56d2cad17e5ffdeede8173cd406103c7ee2b5fc3 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 17:01:42 +0200 Subject: [PATCH 011/151] Fixed get_properties naming (Bixente) --- mxcubecore/HardwareObjects/MotorsNPosition.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/MotorsNPosition.py b/mxcubecore/HardwareObjects/MotorsNPosition.py index c28ab9f24d..286826be3d 100644 --- a/mxcubecore/HardwareObjects/MotorsNPosition.py +++ b/mxcubecore/HardwareObjects/MotorsNPosition.py @@ -121,7 +121,7 @@ def load_positions(self): def get_position_list(self): return list(self._positions.keys()) - def get_properties_(self, position_index, property_name): + def get_properties(self, position_index, property_name): """ returns property with name property_name for position_index if position_index is None returns OrderedDict with property_name for all positions From a07b2ec37f13ccd9f2bf11bd6c6ac6c02d60849d Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 17:04:04 +0200 Subject: [PATCH 012/151] Removed faulty login_type=user fot P11 --- mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py b/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py index d1f259cb7a..3a6e24119e 100644 --- a/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py +++ b/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py @@ -26,8 +26,6 @@ def init(self): "PROPOSAL NUMBER is %s" % self.simulated_prop_number ) - self.loginType = "user" - def update_data_collection(self, mx_collection, wait=False): mx_collection["beamline_name"] = "P11" ISPyBClient.update_data_collection(self, mx_collection, wait) From be6c17001ee8d1f3364e977eed446a1ab61eac18 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 17:06:43 +0200 Subject: [PATCH 013/151] Removed is_open() as a function and assigned is_closed() as a property for shutter-like objects inside P11 HO (Bixente) --- mxcubecore/HardwareObjects/DESY/P11DetectorCover.py | 8 +------- mxcubecore/HardwareObjects/DESY/P11FastShutter.py | 2 ++ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py index e246d7646b..1f1e208f20 100644 --- a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py +++ b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py @@ -197,13 +197,7 @@ def simulated_update(self): self.update_value(value) return value - def is_open(self): - """Check if the shutter is open. - Returns: - (bool): True if open, False otherwise. - """ - return self.get_value() == self.VALUES.OPEN - + @property def is_closed(self): """Check if the shutter is closed. Returns: diff --git a/mxcubecore/HardwareObjects/DESY/P11FastShutter.py b/mxcubecore/HardwareObjects/DESY/P11FastShutter.py index 4b4ae4c6e5..ebe924a395 100644 --- a/mxcubecore/HardwareObjects/DESY/P11FastShutter.py +++ b/mxcubecore/HardwareObjects/DESY/P11FastShutter.py @@ -67,9 +67,11 @@ def init(self): def get_value(self): return self.update_fast_shutter() + @property def is_open(self): return self.get_value() == self.VALUES.OPEN + @property def is_closed(self): return self.get_value() == self.VALUES.CLOSED From 3e58e8d903853f237d4e9e53d0c12f1b55632b1e Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 17:07:35 +0200 Subject: [PATCH 014/151] Added is_open as a property inside P11NanoDiff (Bixente) --- mxcubecore/HardwareObjects/DESY/P11NanoDiff.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py b/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py index e327c48faa..10fe34b321 100644 --- a/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py +++ b/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py @@ -737,9 +737,9 @@ def detector_cover_close(self, wait=True): def wait_detcover(self, state, timeout=60): start_time = time.time() while time.time() - start_time > timeout: - if state == "open" and self.detcover_hwobj.is_open(): + if state == "open" and self.detcover_hwobj.is_open: break - elif state == "close" and self.detcover_hwobj.is_closed(): + elif state == "close" and self.detcover_hwobj.is_closed: break gevent.sleep(0.5) @@ -802,8 +802,8 @@ def update_phase(self, value=None): omega_pos = self.get_omega_position() - cover_open = self.detcover_hwobj.is_open() - cover_closed = self.detcover_hwobj.is_closed() + cover_open = self.detcover_hwobj.is_open + cover_closed = self.detcover_hwobj.is_closed blight_in = self.backlight_hwobj.is_in() blight_out = self.backlight_hwobj.is_out() collim = self.collimator_hwobj.get_position() From 2a6a21edb885fa94017c561f0b31a247fca6fa63 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 17:26:57 +0200 Subject: [PATCH 015/151] Fixed other get_properties typos which were preventing loading --- mxcubecore/HardwareObjects/MotorsNPosition.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/MotorsNPosition.py b/mxcubecore/HardwareObjects/MotorsNPosition.py index 286826be3d..ab28f896e8 100644 --- a/mxcubecore/HardwareObjects/MotorsNPosition.py +++ b/mxcubecore/HardwareObjects/MotorsNPosition.py @@ -161,7 +161,7 @@ def set_position(self, posname): posidx = -1 for name in self._positions: posidx += 1 - if posname == self.get_properties_(posidx, "posname"): + if posname == self.get_properties(posidx, "posname"): self._set_value(posidx) return From 5d7ca117738257014ce1e83cfe34284edd5cf26b Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 17:04:04 +0200 Subject: [PATCH 016/151] Removed faulty login_type=user for P11 --- mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py b/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py index d1f259cb7a..3a6e24119e 100644 --- a/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py +++ b/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py @@ -26,8 +26,6 @@ def init(self): "PROPOSAL NUMBER is %s" % self.simulated_prop_number ) - self.loginType = "user" - def update_data_collection(self, mx_collection, wait=False): mx_collection["beamline_name"] = "P11" ISPyBClient.update_data_collection(self, mx_collection, wait) From c20ec81337c2fadcfb83deb73d9d282c2b11e8a9 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 17:06:43 +0200 Subject: [PATCH 017/151] Removed is_open() as a function and assigned is_closed() as a property for shutter-like objects inside P11 HO (Bixente) --- mxcubecore/HardwareObjects/DESY/P11DetectorCover.py | 8 +------- mxcubecore/HardwareObjects/DESY/P11FastShutter.py | 2 ++ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py index e246d7646b..1f1e208f20 100644 --- a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py +++ b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py @@ -197,13 +197,7 @@ def simulated_update(self): self.update_value(value) return value - def is_open(self): - """Check if the shutter is open. - Returns: - (bool): True if open, False otherwise. - """ - return self.get_value() == self.VALUES.OPEN - + @property def is_closed(self): """Check if the shutter is closed. Returns: diff --git a/mxcubecore/HardwareObjects/DESY/P11FastShutter.py b/mxcubecore/HardwareObjects/DESY/P11FastShutter.py index 4b4ae4c6e5..ebe924a395 100644 --- a/mxcubecore/HardwareObjects/DESY/P11FastShutter.py +++ b/mxcubecore/HardwareObjects/DESY/P11FastShutter.py @@ -67,9 +67,11 @@ def init(self): def get_value(self): return self.update_fast_shutter() + @property def is_open(self): return self.get_value() == self.VALUES.OPEN + @property def is_closed(self): return self.get_value() == self.VALUES.CLOSED From 7574477d814b606858b6ea28acb21d845a197d6a Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 17:07:35 +0200 Subject: [PATCH 018/151] Added is_open as a property inside P11NanoDiff (Bixente) --- mxcubecore/HardwareObjects/DESY/P11NanoDiff.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py b/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py index e327c48faa..10fe34b321 100644 --- a/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py +++ b/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py @@ -737,9 +737,9 @@ def detector_cover_close(self, wait=True): def wait_detcover(self, state, timeout=60): start_time = time.time() while time.time() - start_time > timeout: - if state == "open" and self.detcover_hwobj.is_open(): + if state == "open" and self.detcover_hwobj.is_open: break - elif state == "close" and self.detcover_hwobj.is_closed(): + elif state == "close" and self.detcover_hwobj.is_closed: break gevent.sleep(0.5) @@ -802,8 +802,8 @@ def update_phase(self, value=None): omega_pos = self.get_omega_position() - cover_open = self.detcover_hwobj.is_open() - cover_closed = self.detcover_hwobj.is_closed() + cover_open = self.detcover_hwobj.is_open + cover_closed = self.detcover_hwobj.is_closed blight_in = self.backlight_hwobj.is_in() blight_out = self.backlight_hwobj.is_out() collim = self.collimator_hwobj.get_position() From b4b8f9bf9a9f9b4cf9b185c7c6793900352b8967 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 17:26:57 +0200 Subject: [PATCH 019/151] Fixed other get_properties typos which were preventing loading --- mxcubecore/HardwareObjects/MotorsNPosition.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/MotorsNPosition.py b/mxcubecore/HardwareObjects/MotorsNPosition.py index 286826be3d..ab28f896e8 100644 --- a/mxcubecore/HardwareObjects/MotorsNPosition.py +++ b/mxcubecore/HardwareObjects/MotorsNPosition.py @@ -161,7 +161,7 @@ def set_position(self, posname): posidx = -1 for name in self._positions: posidx += 1 - if posname == self.get_properties_(posidx, "posname"): + if posname == self.get_properties(posidx, "posname"): self._set_value(posidx) return From f3bd7d5e96ab72bc315c0e63afafaf2910873ede Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Thu, 5 Oct 2023 15:35:55 +0200 Subject: [PATCH 020/151] Fixed shutter openning wainting forever (Bixente) --- mxcubecore/HardwareObjects/DESY/P11Shutter.py | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Shutter.py b/mxcubecore/HardwareObjects/DESY/P11Shutter.py index 1fe79adaed..8202549f10 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Shutter.py +++ b/mxcubecore/HardwareObjects/DESY/P11Shutter.py @@ -22,6 +22,7 @@ import gevent import urllib from mxcubecore.HardwareObjects.abstract.AbstractShutter import AbstractShutter +import mxcubecore.HardwareObjects.abstract.AbstractShutter as absshut from mxcubecore.BaseHardwareObjects import HardwareObjectState from enum import Enum, unique @@ -85,6 +86,8 @@ def init(self): else: self.simulated_update() + self.update_state(self.STATES.READY) + super(AbstractShutter, self).init() def get_value(self): @@ -105,25 +108,39 @@ def _set_value(self, value): if self.simulation: self.simulated_opened = open_it self.simulated_moving = True - gevent.spawn(self.simul_do) + self.t1 = gevent.spawn(self.simul_do) + self.t1.link(self.do_finish) + self.t1.link_exception(self.do_finish_exc) else: if open_it: self.do_open() else: self.do_close() self.cmd_started = time.time() + self.log.debug(" ### setting value value for shutter done") def do_open(self, timeout=3): + self.log.debug(" OPENING SHUTTER (web request)") result = urllib.request.urlopen(self.url_open, None, timeout).readlines() + self.log.debug(" OPENING SHUTTER (web request) retured") def do_close(self, timeout=3): + self.log.debug(" CLOSING SHUTTER (web request)") result = urllib.request.urlopen(self.url_close, None, timeout).readlines() + self.log.debug(" CLOSING SHUTTER (web request) retured") def simul_do(self): + self.log.debug("### starting simulated shutter move") gevent.sleep(1) self.simulated_moving = False self.log.debug("### updating simulated shutter") self.simulated_update() + self.log.debug("### ending simulated shutter move") + + def do_finish(self, t=None): + self.log.debug("### simulated finished") + def do_finish_exc(self, exc=None): + self.log.debug("### simulated finished with exception") def update_shutter_state(self, state=None): """Updates shutter state @@ -134,6 +151,7 @@ def update_shutter_state(self, state=None): state = self.chan_state.get_value() self.log.debug(" SHUTTER state changed") + if state[0] == 3: self.log.debug(" P11SHUTTER IS OPEN") value = self.VALUES.OPEN From 75621a3ebe8bdb1c402317b24a12ed843ea8c5c5 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Fri, 6 Oct 2023 17:32:07 +0200 Subject: [PATCH 021/151] Added preliminary flux HO for P11 --- mxcubecore/HardwareObjects/DESY/P11Flux.py | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 mxcubecore/HardwareObjects/DESY/P11Flux.py diff --git a/mxcubecore/HardwareObjects/DESY/P11Flux.py b/mxcubecore/HardwareObjects/DESY/P11Flux.py new file mode 100644 index 0000000000..ae64c4ca83 --- /dev/null +++ b/mxcubecore/HardwareObjects/DESY/P11Flux.py @@ -0,0 +1,72 @@ +# +# Project: MXCuBE +# https://github.com/mxcube +# +# This file is part of MXCuBE software. +# +# MXCuBE is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# MXCuBE is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with MXCuBE. If not, see . + +from random import random +from mxcubecore.HardwareObjects.abstract.AbstractFlux import AbstractFlux + +from mxcubecore import HardwareRepository as HWR + +__credits__ = ["MXCuBE collaboration"] +__category__ = "General" + + +class P11Flux(AbstractFlux): + + # default_flux - for initialising mockup + default_flux = 5e12 + + def __init__(self, name): + AbstractFlux.__init__(self, name) + + self.measured_flux_list = [] + self.measured_flux_dict = {} + self.current_flux_dict = {} + + def init(self): + + self.measure_flux() + + def get_value(self): + """Get flux at current transmission in units of photons/s""" + + """ FLUX IS CHEETED HERE - NOWERE ELSE!""" + return self.current_flux_dict["flux"] + + def measure_flux(self): + """Measures intesity""" + beam_size = HWR.beamline.beam.get_beam_size() + transmission = HWR.beamline.transmission.get_value() + flux = self.default_flux * (1 + random()) + + self.measured_flux_list = [ + { + "size_x": beam_size[0], + "size_y": beam_size[1], + "transmission": transmission, + "flux": flux, + } + ] + + self.measured_flux_dict = self.measured_flux_list[0] + self.current_flux_dict = self.measured_flux_list[0] + + self.emit( + "fluxInfoChanged", + {"measured": self.measured_flux_dict, "current": self.current_flux_dict}, + ) From 30ddf3ae2109bf64dbdad328765a32047e4e2071 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Fri, 6 Oct 2023 19:18:03 +0200 Subject: [PATCH 022/151] Upgraded the characterisation part for P11 using EDNA --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 68 ++++++++++--------- .../DESY/P11EDNACharacterisation.py | 33 ++++++++- 2 files changed, 68 insertions(+), 33 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index c2f1b2e9d9..0912c90293 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -126,6 +126,7 @@ def data_collection_hook(self): self.diffr = HWR.beamline.diffractometer detector = HWR.beamline.detector + dc_pars = self.current_dc_parameters collection_type = dc_pars["experiment_type"] @@ -199,8 +200,12 @@ def data_collection_hook(self): ) # Filepath to the EDNA processing - # filepath = os.path.join(basepath,"%s_%d" % (prefix, runno)) + #filepath = os.path.join(basepath,"%s_%d" % (prefix, runno)) + + #setting up xds_dir for characterisation (used there internally to create dirs) + self.current_dc_parameters["xds_dir"] = os.path.join(basepath,"%s_%d" % (prefix, runno)) + self.log.debug( "======= CURRENT FILEPATH: " + str(filepath) @@ -282,23 +287,24 @@ def data_collection_hook(self): # os.system("/opt/dectris/albula/4.0/bin/albula "+self.latest_h5_filename +" &") # os.system("adxv "+self.latest_h5_filename +" &") + #TODO: Remove for now creation of the snapshots and processing html. # Open index_html - os.system("firefox /gpfs/current/processed/index.html") + #os.system("firefox /gpfs/current/processed/index.html") # Create diffraction snapshots - for i in range(nframes): - os.system( - "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " - + self.latest_h5_filename - + " --output " - + os.path.join( - basepath, prefix, "screening_" + str(runno).zfill(3) - ) - + "/" - + " --image_number " - + str(i + 1) - ) - +# for i in range(nframes): +# os.system( +# "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " +# + self.latest_h5_filename +# + " --output " +# + os.path.join( +# basepath, prefix, "screening_" + str(runno).zfill(3) +# ) +# + "/" +# + " --image_number " +# + str(i + 1) +# ) +# else: self.collect_std_collection(start_angle, stop_angle) self.generate_xds_template() @@ -307,21 +313,21 @@ def data_collection_hook(self): # os.system("killall albula") # os.system("/opt/dectris/albula/4.0/bin/albula "+self.latest_h5_filename +" &") - # Open index_html - os.system("firefox /gpfs/current/processed/index.html") - - # Create diffraction snapshots - os.system( - "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " - + self.latest_h5_filename - + " --output " - + os.path.join( - basepath, prefix, "rotational_" + str(runno).zfill(3) - ) - + "/" - + " --image_number 1" - ) - +# # Open index_html +# os.system("firefox /gpfs/current/processed/index.html") +# +# # Create diffraction snapshots +# os.system( +# "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " +# + self.latest_h5_filename +# + " --output " +# + os.path.join( +# basepath, prefix, "rotational_" + str(runno).zfill(3) +# ) +# + "/" +# + " --image_number 1" +# ) +# except RuntimeError: self.log.error(traceback.format_exc()) finally: @@ -535,7 +541,7 @@ def add_h5_info(self, h5file): del h5fd[node] h5fd.close() - except RuntimeError as err_msg: + except RuntimeWarning as err_msg: self.log.debug("Error while adding info to HDF5 file (%s)" % str(err_msg)) self.log.debug(traceback.format_exc()) diff --git a/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py b/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py index 7e0eb6c775..28f3399e25 100644 --- a/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py +++ b/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py @@ -47,6 +47,26 @@ def __init__(self, name): self.edna_default_file = None self.start_edna_command = None + def _run_edna(self, input_file, results_file, process_directory): + """Starts EDNA""" + msg = "Starting EDNA characterisation using xml file %s" % input_file + logging.getLogger("queue_exec").info(msg) + + args = (self.start_edna_command, input_file, results_file, process_directory) + # subprocess.call("%s %s %s %s" % args, shell=True) + + # Test run DESY + self.edna_maxwell(process_directory,input_file, results_file) + + + + self.result = None + if os.path.exists(results_file): + self.result = XSDataResultMXCuBE.parseFile(results_file) + + return self.result + + def edna_maxwell(self, process_directory, inputxml, outputxml): """ The function `edna_maxwell` is used to execute a command on a remote cluster using SSH and SBATCH. @@ -105,6 +125,8 @@ def edna_maxwell(self, process_directory, inputxml, outputxml): ) ) + print('{ssh:s} "{sbatch:s} --wrap \\"{cmd:s}"\\"'.format(ssh=ssh, sbatch=sbatch, cmd=cmd)) + os.system( '{ssh:s} "{sbatch:s} --wrap \\"{cmd:s}"\\"'.format( ssh=ssh, sbatch=sbatch, cmd=cmd @@ -235,16 +257,23 @@ def input_from_params(self, data_collection, char_params): data_set = XSDataMXCuBEDataSet() acquisition_parameters = data_collection.acquisitions[0].acquisition_parameters path_template = data_collection.acquisitions[0].path_template - + + #Make sure there is a proper path conversion between different mount points + print("======= Characterisation path template ====", path_template.directory) #/gpfs/current/raw + image_dir = path_template.directory.replace( "/gpfs/current", triggerUtils.get_beamtime_metadata()[2] ) - path_str = os.path.join(image_dir, path_template.get_image_file_name()) + print(image_dir) + path_str = os.path.join(image_dir, path_template.get_image_file_name()) + print(path_template.xds_dir) + characterisation_dir = path_template.xds_dir.replace( "/autoprocessing_", "/characterisation_" ) + os.makedirs(characterisation_dir, mode=0o755, exist_ok=True) for img_num in range(int(acquisition_parameters.num_images)): From e878dfb390941c74ba21b2b0d5f0d2247b4064ca Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Fri, 6 Oct 2023 22:57:55 +0200 Subject: [PATCH 023/151] Linting --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 142 +++++++++--------- .../HardwareObjects/DESY/P11DetectorCover.py | 17 ++- .../DESY/P11EDNACharacterisation.py | 27 ++-- mxcubecore/HardwareObjects/DESY/P11Flux.py | 2 +- mxcubecore/HardwareObjects/DESY/P11Session.py | 14 +- mxcubecore/HardwareObjects/DESY/P11Shutter.py | 20 +-- 6 files changed, 119 insertions(+), 103 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index 0912c90293..b13044b47e 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -56,23 +56,21 @@ class P11Collect(AbstractCollect): - def __init__(self, *args): super(P11Collect, self).__init__(*args) def init(self): - super(P11Collect,self).init() + super(P11Collect, self).init() # os.system("/opt/xray/bin/adxv -socket -colors Gray -rings &") # os.system("/bin/bash /gpfs/local/shared/MXCuBE/STRELA/start_viewer_zmq.sh") - self.default_speed = self.get_property("omega_default_speed", 130) self.turnback_time = self.get_property("turnback_time", 0.3) - self.filter_server_name = self.get_property('filterserver') - self.mono_server_name = self.get_property('monoserver') + self.filter_server_name = self.get_property("filterserver") + self.mono_server_name = self.get_property("monoserver") self.filter_server = DeviceProxy(self.filter_server_name) self.mono_server = DeviceProxy(self.mono_server_name) @@ -84,9 +82,14 @@ def init(self): self.acq_off_cmd = self.get_command_object("acq_off") self.acq_window_off_cmd = self.get_command_object("acq_window_off") - if None in [self.lower_bound_ch, self.upper_bound_ch, - self.acq_arm_cmd, self.acq_on_cmd, self.acq_off_cmd, - self.acq_window_off_cmd]: + if None in [ + self.lower_bound_ch, + self.upper_bound_ch, + self.acq_arm_cmd, + self.acq_on_cmd, + self.acq_off_cmd, + self.acq_window_off_cmd, + ]: self.init_ok = False self.log.debug("lower_bound_ch: %s" % self.lower_bound_ch) self.log.debug("upper_bound_ch: %s" % self.upper_bound_ch) @@ -96,6 +99,7 @@ def init(self): self.log.debug("acq_window_off_cmd: %s" % self.acq_window_off_cmd) else: self.init_ok = True + @task def move_motors(self, motor_position_dict): HWR.beamline.diffractometer.wait_omega() @@ -126,7 +130,6 @@ def data_collection_hook(self): self.diffr = HWR.beamline.diffractometer detector = HWR.beamline.detector - dc_pars = self.current_dc_parameters collection_type = dc_pars["experiment_type"] @@ -200,12 +203,13 @@ def data_collection_hook(self): ) # Filepath to the EDNA processing - #filepath = os.path.join(basepath,"%s_%d" % (prefix, runno)) + # filepath = os.path.join(basepath,"%s_%d" % (prefix, runno)) + + # setting up xds_dir for characterisation (used there internally to create dirs) + self.current_dc_parameters["xds_dir"] = os.path.join( + basepath, "%s_%d" % (prefix, runno) + ) - - #setting up xds_dir for characterisation (used there internally to create dirs) - self.current_dc_parameters["xds_dir"] = os.path.join(basepath,"%s_%d" % (prefix, runno)) - self.log.debug( "======= CURRENT FILEPATH: " + str(filepath) @@ -287,24 +291,24 @@ def data_collection_hook(self): # os.system("/opt/dectris/albula/4.0/bin/albula "+self.latest_h5_filename +" &") # os.system("adxv "+self.latest_h5_filename +" &") - #TODO: Remove for now creation of the snapshots and processing html. + # TODO: Remove for now creation of the snapshots and processing html. # Open index_html - #os.system("firefox /gpfs/current/processed/index.html") + # os.system("firefox /gpfs/current/processed/index.html") # Create diffraction snapshots -# for i in range(nframes): -# os.system( -# "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " -# + self.latest_h5_filename -# + " --output " -# + os.path.join( -# basepath, prefix, "screening_" + str(runno).zfill(3) -# ) -# + "/" -# + " --image_number " -# + str(i + 1) -# ) -# + # for i in range(nframes): + # os.system( + # "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " + # + self.latest_h5_filename + # + " --output " + # + os.path.join( + # basepath, prefix, "screening_" + str(runno).zfill(3) + # ) + # + "/" + # + " --image_number " + # + str(i + 1) + # ) + # else: self.collect_std_collection(start_angle, stop_angle) self.generate_xds_template() @@ -313,21 +317,21 @@ def data_collection_hook(self): # os.system("killall albula") # os.system("/opt/dectris/albula/4.0/bin/albula "+self.latest_h5_filename +" &") -# # Open index_html -# os.system("firefox /gpfs/current/processed/index.html") -# -# # Create diffraction snapshots -# os.system( -# "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " -# + self.latest_h5_filename -# + " --output " -# + os.path.join( -# basepath, prefix, "rotational_" + str(runno).zfill(3) -# ) -# + "/" -# + " --image_number 1" -# ) -# + # # Open index_html + # os.system("firefox /gpfs/current/processed/index.html") + # + # # Create diffraction snapshots + # os.system( + # "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " + # + self.latest_h5_filename + # + " --output " + # + os.path.join( + # basepath, prefix, "rotational_" + str(runno).zfill(3) + # ) + # + "/" + # + " --image_number 1" + # ) + # except RuntimeError: self.log.error(traceback.format_exc()) finally: @@ -347,20 +351,17 @@ def collect_std_collection(self, start_angle, stop_angle): """ HWR.beamline.diffractometer.wait_omega() - start_pos = start_angle - self.turnback_time*self.acq_speed - stop_pos = stop_angle + self.turnback_time*self.acq_speed - - - + start_pos = start_angle - self.turnback_time * self.acq_speed + stop_pos = stop_angle + self.turnback_time * self.acq_speed + self.log.debug("#COLLECT# Running OMEGA through the std acquisition") if start_angle <= stop_angle: - self.lower_bound_ch.set_value(start_angle) - self.upper_bound_ch.set_value(stop_angle) + self.lower_bound_ch.set_value(start_angle) + self.upper_bound_ch.set_value(stop_angle) else: - self.lower_bound_ch.set_value(stop_angle) - self.upper_bound_ch.set_value(start_angle) - + self.lower_bound_ch.set_value(stop_angle) + self.upper_bound_ch.set_value(start_angle) self.omega_mv(start_pos, self.default_speed) self.acq_arm_cmd() @@ -371,7 +372,6 @@ def collect_std_collection(self, start_angle, stop_angle): self.omega_mv(stop_angle, self.acq_speed) HWR.beamline.diffractometer.wait_omega() - def collect_characterisation( self, start_angle, img_range, nimages, angle_inc, exp_time ): @@ -391,7 +391,9 @@ def collect_characterisation( diffr = HWR.beamline.diffractometer - self.log.debug("#COLLECT# Running OMEGA through the characteristation acquisition") + self.log.debug( + "#COLLECT# Running OMEGA through the characteristation acquisition" + ) self.omega_mv(start_angle, self.default_speed) @@ -399,35 +401,37 @@ def collect_characterisation( print("collecting image %s" % img_no) start_at = start_angle + angle_inc * img_no stop_angle = start_at + img_range * 1.0 - #print("======= CHARACTERISATION Adding angle and range to the header...") - #Add start angle to the header - #detector = HWR.beamline.detector - #detector.set_eiger_start_angle(start_at) + # print("======= CHARACTERISATION Adding angle and range to the header...") + # Add start angle to the header + # detector = HWR.beamline.detector + # detector.set_eiger_start_angle(start_at) # Add angle increment to the header - #detector.set_eiger_angle_increment(angle_inc) + # detector.set_eiger_angle_increment(angle_inc) print("collecting image %s, angle %f" % (img_no, start_at)) if start_at >= stop_angle: - init_pos = start_at #- self.acq_speed * self.turnback_time + init_pos = start_at # - self.acq_speed * self.turnback_time # init_pos = start_at - 1.5 else: - init_pos = start_at #+ self.acq_speed * self.turnback_time + init_pos = start_at # + self.acq_speed * self.turnback_time # init_pos = start_at + 1.5 # self.omega_mv(init_pos, self.default_speed) self.collect_std_collection(start_at, stop_angle) - #This part goes to standard collection. Otherwise it produces phantom openings. + # This part goes to standard collection. Otherwise it produces phantom openings. # diffr.set_omega_velocity(self.default_speed) # self.acq_window_off_cmd() # self.acq_off_cmd() - self.log.debug("======= collect_characterisation Waiting =======================================") + self.log.debug( + "======= collect_characterisation Waiting =======================================" + ) - #Let adxv know whether it is + # Let adxv know whether it is # self.adxv_notify(self.latest_h5_filename,img_no+1) - + # time.sleep(1) def adxv_notify(self, image_filename, image_num=1): @@ -469,14 +473,14 @@ def acquisition_cleanup(self): detector.stop_acquisition() diffr.wait_omega() # ================= - #It is probably already finished in a standard collection. + # It is probably already finished in a standard collection. self.acq_off_cmd() self.acq_window_off_cmd() # ================== diffr.set_omega_velocity(self.default_speed) self.log.debug("#COLLECT# Closing detector cover") diffr.detector_cover_close(wait=True) - + except RuntimeError: self.log.error(traceback.format_exc()) diff --git a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py index 1f1e208f20..ec9c9e480e 100644 --- a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py +++ b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py @@ -44,13 +44,14 @@ class P11DetectorCover(AbstractShutter): @unique class BaseValueEnum(Enum): - """Defines only the compulsory values.""" - OPEN = "OPEN" - CLOSED = "CLOSED" - MOVING = "MOVING" - UNKNOWN = "UNKNOWN" - - VALUES=BaseValueEnum + """Defines only the compulsory values.""" + + OPEN = "OPEN" + CLOSED = "CLOSED" + MOVING = "MOVING" + UNKNOWN = "UNKNOWN" + + VALUES = BaseValueEnum def __init__(self, name): @@ -196,7 +197,7 @@ def simulated_update(self): self.update_value(value) return value - + @property def is_closed(self): """Check if the shutter is closed. diff --git a/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py b/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py index 28f3399e25..058ddc6784 100644 --- a/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py +++ b/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py @@ -56,17 +56,14 @@ def _run_edna(self, input_file, results_file, process_directory): # subprocess.call("%s %s %s %s" % args, shell=True) # Test run DESY - self.edna_maxwell(process_directory,input_file, results_file) - - + self.edna_maxwell(process_directory, input_file, results_file) self.result = None if os.path.exists(results_file): self.result = XSDataResultMXCuBE.parseFile(results_file) return self.result - - + def edna_maxwell(self, process_directory, inputxml, outputxml): """ The function `edna_maxwell` is used to execute a command on a remote cluster using SSH and SBATCH. @@ -125,7 +122,11 @@ def edna_maxwell(self, process_directory, inputxml, outputxml): ) ) - print('{ssh:s} "{sbatch:s} --wrap \\"{cmd:s}"\\"'.format(ssh=ssh, sbatch=sbatch, cmd=cmd)) + print( + '{ssh:s} "{sbatch:s} --wrap \\"{cmd:s}"\\"'.format( + ssh=ssh, sbatch=sbatch, cmd=cmd + ) + ) os.system( '{ssh:s} "{sbatch:s} --wrap \\"{cmd:s}"\\"'.format( @@ -257,10 +258,12 @@ def input_from_params(self, data_collection, char_params): data_set = XSDataMXCuBEDataSet() acquisition_parameters = data_collection.acquisitions[0].acquisition_parameters path_template = data_collection.acquisitions[0].path_template - - #Make sure there is a proper path conversion between different mount points - print("======= Characterisation path template ====", path_template.directory) #/gpfs/current/raw - + + # Make sure there is a proper path conversion between different mount points + print( + "======= Characterisation path template ====", path_template.directory + ) # /gpfs/current/raw + image_dir = path_template.directory.replace( "/gpfs/current", triggerUtils.get_beamtime_metadata()[2] ) @@ -269,11 +272,11 @@ def input_from_params(self, data_collection, char_params): path_str = os.path.join(image_dir, path_template.get_image_file_name()) print(path_template.xds_dir) - + characterisation_dir = path_template.xds_dir.replace( "/autoprocessing_", "/characterisation_" ) - + os.makedirs(characterisation_dir, mode=0o755, exist_ok=True) for img_num in range(int(acquisition_parameters.num_images)): diff --git a/mxcubecore/HardwareObjects/DESY/P11Flux.py b/mxcubecore/HardwareObjects/DESY/P11Flux.py index ae64c4ca83..d1475ab6f4 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Flux.py +++ b/mxcubecore/HardwareObjects/DESY/P11Flux.py @@ -44,7 +44,7 @@ def init(self): def get_value(self): """Get flux at current transmission in units of photons/s""" - + """ FLUX IS CHEETED HERE - NOWERE ELSE!""" return self.current_flux_dict["flux"] diff --git a/mxcubecore/HardwareObjects/DESY/P11Session.py b/mxcubecore/HardwareObjects/DESY/P11Session.py index f2fdfce8b0..05fecad4d8 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Session.py +++ b/mxcubecore/HardwareObjects/DESY/P11Session.py @@ -87,11 +87,17 @@ def info_set_defaults(self): def is_beamtime_open(self): self.log.debug("=========== CHECKING IF BEAMTIME ID IS OPEN... ============") if self.is_writable_dir(os.path.join(PATH_BEAMTIME, self.raw_data_folder_name)): - self.log.debug("=========== BEAMTIME IS OPEN (/gpfs/current exists) ============") + self.log.debug( + "=========== BEAMTIME IS OPEN (/gpfs/current exists) ============" + ) else: - self.log.debug("=========== NO BEMTIME ID IS OPEN (check /gpfs/current) ============") - - return self.is_writable_dir( os.path.join(PATH_BEAMTIME, self.raw_data_folder_name) ) + self.log.debug( + "=========== NO BEMTIME ID IS OPEN (check /gpfs/current) ============" + ) + + return self.is_writable_dir( + os.path.join(PATH_BEAMTIME, self.raw_data_folder_name) + ) def is_commissioning_open(self): return self.is_writable_dir( diff --git a/mxcubecore/HardwareObjects/DESY/P11Shutter.py b/mxcubecore/HardwareObjects/DESY/P11Shutter.py index 8202549f10..90e81aec28 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Shutter.py +++ b/mxcubecore/HardwareObjects/DESY/P11Shutter.py @@ -41,13 +41,14 @@ class P11Shutter(AbstractShutter): @unique class BaseValueEnum(Enum): - """Defines only the compulsory values.""" - OPEN = "OPEN" - CLOSED = "CLOSED" - MOVING = "MOVING" - UNKNOWN = "UNKNOWN" - - VALUES=BaseValueEnum + """Defines only the compulsory values.""" + + OPEN = "OPEN" + CLOSED = "CLOSED" + MOVING = "MOVING" + UNKNOWN = "UNKNOWN" + + VALUES = BaseValueEnum def __init__(self, name): @@ -109,8 +110,8 @@ def _set_value(self, value): self.simulated_opened = open_it self.simulated_moving = True self.t1 = gevent.spawn(self.simul_do) - self.t1.link(self.do_finish) - self.t1.link_exception(self.do_finish_exc) + self.t1.link(self.do_finish) + self.t1.link_exception(self.do_finish_exc) else: if open_it: self.do_open() @@ -139,6 +140,7 @@ def simul_do(self): def do_finish(self, t=None): self.log.debug("### simulated finished") + def do_finish_exc(self, exc=None): self.log.debug("### simulated finished with exception") From 7a1168441c05a6bf358fcb38bae1912718de8485 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Tue, 17 Oct 2023 16:25:29 +0200 Subject: [PATCH 024/151] Add empty store_robot_action for P11 (temp fix due to ISPyB tests). --- mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py b/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py index 3a6e24119e..3225c34dda 100644 --- a/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py +++ b/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py @@ -38,6 +38,10 @@ def store_image(self, image_dict): self.prepare_image_for_lims(image_dict) return ISPyBClient.store_image(self, image_dict) + def store_robot_action(self, robot_action_dict): + #TODO ISPyB is not ready for now. This prevents from error 500 from the server. + pass + def prepare_collect_for_lims(self, mx_collect_dict): # Attention! directory passed by reference. modified in place From 3fe9dffe5db5f15b135cb6deb40624c1a933ab9f Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 25 Oct 2023 14:34:51 +0200 Subject: [PATCH 025/151] Fix in AbstractSampleChanger that was causing sample not loaded error at P11 even if everything was ok (Bixente). --- mxcubecore/HardwareObjects/DESY/P11SampleChanger.py | 2 ++ .../HardwareObjects/abstract/AbstractSampleChanger.py | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11SampleChanger.py b/mxcubecore/HardwareObjects/DESY/P11SampleChanger.py index 2ec48d57ab..5afe2710f6 100644 --- a/mxcubecore/HardwareObjects/DESY/P11SampleChanger.py +++ b/mxcubecore/HardwareObjects/DESY/P11SampleChanger.py @@ -205,6 +205,7 @@ def load(self, sample=None, wait=True): "Sample changer: Sample loaded (total time: %s)" % (time.time() - self._start_load) ) + self.emit("progressStop", ()) return self.get_loaded_sample() @@ -476,6 +477,7 @@ def _update_selection(self): # find sample for s in self.get_sample_list(): + print(f"Sample coords = {s.get_coords()}") if s.get_coords() == (basket, sample): self.log.debug(" - sample found") self._set_loaded_sample(s) diff --git a/mxcubecore/HardwareObjects/abstract/AbstractSampleChanger.py b/mxcubecore/HardwareObjects/abstract/AbstractSampleChanger.py index 3d579431ea..b8c26edaf0 100644 --- a/mxcubecore/HardwareObjects/abstract/AbstractSampleChanger.py +++ b/mxcubecore/HardwareObjects/abstract/AbstractSampleChanger.py @@ -806,8 +806,10 @@ def _set_loaded_sample(self, sample): if smp != sample: smp._set_loaded(False) else: - if self.get_loaded_sample() == smp: - smp._set_loaded(True) + self.log.debug(f" Found sample {smp} is loaded") + self.log.debug(f" getting loaded {self.get_loaded_sample()}") + #if self.get_loaded_sample() == smp: + smp._set_loaded(True) if previous_loaded != self.get_loaded_sample(): self._trigger_loaded_sample_changed_event(sample) From 2d31d70407eb63613650a089693a82dbc5415694 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Mon, 18 Sep 2023 12:11:42 +0200 Subject: [PATCH 026/151] Fixing the ambiguity with Poller value and .any --- mxcubecore/Command/Tango.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mxcubecore/Command/Tango.py b/mxcubecore/Command/Tango.py index 96e998e14e..6f5c98f84f 100644 --- a/mxcubecore/Command/Tango.py +++ b/mxcubecore/Command/Tango.py @@ -21,6 +21,7 @@ import logging import gevent import gevent.event +import numpy as np try: import Queue as queue @@ -319,7 +320,7 @@ def get_info(self): self._device_initialized.wait(timeout=3) return self.device.get_attribute_config(self.attribute_name) - def update(self, value=Poller.NotInitializedValue): + # start with checking if we have a numpy array, as comparing # numpy.ndarray to Poller.NotInitializedValue raises a ValueError exception @@ -333,6 +334,7 @@ def update(self, value=Poller.NotInitializedValue): self.value = value self.emit("update", value) + def get_value(self): if self.read_as_str: value = self.device.read_attribute( From 8011a9c376a1f2d0d61f017f6c16adab79f6cfb7 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Mon, 18 Sep 2023 12:42:20 +0200 Subject: [PATCH 027/151] P11Collect additional debug after upgrade --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 124 +++++++++++------- 1 file changed, 75 insertions(+), 49 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index 3171a52753..c2f1b2e9d9 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -39,24 +39,42 @@ from mxcubecore.Command.Tango import DeviceProxy +import gevent +import time +import numpy as np +import logging +import os +import sys +import math +import h5py import triggerUtils +from tango import DeviceProxy, DevState FILE_TIMEOUT = 5 class P11Collect(AbstractCollect): + def __init__(self, *args): super(P11Collect, self).__init__(*args) + def init(self): + + super(P11Collect,self).init() + + # os.system("/opt/xray/bin/adxv -socket -colors Gray -rings &") + + # os.system("/bin/bash /gpfs/local/shared/MXCuBE/STRELA/start_viewer_zmq.sh") + + self.default_speed = self.get_property("omega_default_speed", 130) - self.turnback_time = self.get_property("turnback_time", 0.1) - self.filter_server_name = self.get_property("filterserver") - self.mono_server_name = self.get_property("monoserver") + self.turnback_time = self.get_property("turnback_time", 0.3) + self.filter_server_name = self.get_property('filterserver') + self.mono_server_name = self.get_property('monoserver') self.filter_server = DeviceProxy(self.filter_server_name) self.mono_server = DeviceProxy(self.mono_server_name) - self.diffr = HWR.beamline.diffractometer self.lower_bound_ch = self.get_channel_object("acq_lower_bound") self.upper_bound_ch = self.get_channel_object("acq_upper_bound") @@ -66,26 +84,9 @@ def __init__(self, *args): self.acq_off_cmd = self.get_command_object("acq_off") self.acq_window_off_cmd = self.get_command_object("acq_window_off") - self.latest_frames = 1 - self.acq_speed = 1.0 - self.init_ok = False - self.latest_h5_filename = "TEST_master.h5" - - def init(self): - super(P11Collect, self).init() - - # os.system("/opt/xray/bin/adxv -socket -colors Gray -rings &") - - # os.system("/bin/bash /gpfs/local/shared/MXCuBE/STRELA/start_viewer_zmq.sh") - - if None in [ - self.lower_bound_ch, - self.upper_bound_ch, - self.acq_arm_cmd, - self.acq_on_cmd, - self.acq_off_cmd, - self.acq_window_off_cmd, - ]: + if None in [self.lower_bound_ch, self.upper_bound_ch, + self.acq_arm_cmd, self.acq_on_cmd, self.acq_off_cmd, + self.acq_window_off_cmd]: self.init_ok = False self.log.debug("lower_bound_ch: %s" % self.lower_bound_ch) self.log.debug("upper_bound_ch: %s" % self.upper_bound_ch) @@ -95,7 +96,6 @@ def init(self): self.log.debug("acq_window_off_cmd: %s" % self.acq_window_off_cmd) else: self.init_ok = True - @task def move_motors(self, motor_position_dict): HWR.beamline.diffractometer.wait_omega() @@ -339,21 +339,32 @@ def collect_std_collection(self, start_angle, stop_angle): :param stop_angle: The stop_angle parameter is the final angle at which the collection should stop """ + HWR.beamline.diffractometer.wait_omega() - self.omega_mv(start_angle, self.default_speed) - + start_pos = start_angle - self.turnback_time*self.acq_speed + stop_pos = stop_angle + self.turnback_time*self.acq_speed + + + self.log.debug("#COLLECT# Running OMEGA through the std acquisition") if start_angle <= stop_angle: - self.lower_bound_ch.set_value(start_angle) - self.upper_bound_ch.set_value(stop_angle) + self.lower_bound_ch.set_value(start_angle) + self.upper_bound_ch.set_value(stop_angle) + else: - self.lower_bound_ch.set_value(stop_angle) - self.upper_bound_ch.set_value(start_angle) - self.acq_arm_cmd() + self.lower_bound_ch.set_value(stop_angle) + self.upper_bound_ch.set_value(start_angle) - final_pos = stop_angle + self.acq_speed * self.turnback_time - self.omega_mv(final_pos, self.acq_speed) + self.omega_mv(start_pos, self.default_speed) + self.acq_arm_cmd() + self.omega_mv(stop_pos, self.acq_speed) + time.sleep(0.5) + self.acq_off_cmd() + self.acq_window_off_cmd() + self.omega_mv(stop_angle, self.acq_speed) + HWR.beamline.diffractometer.wait_omega() + def collect_characterisation( self, start_angle, img_range, nimages, angle_inc, exp_time @@ -374,7 +385,7 @@ def collect_characterisation( diffr = HWR.beamline.diffractometer - self.log.debug("#COLLECT# Running OMEGA through the char acquisition") + self.log.debug("#COLLECT# Running OMEGA through the characteristation acquisition") self.omega_mv(start_angle, self.default_speed) @@ -382,26 +393,36 @@ def collect_characterisation( print("collecting image %s" % img_no) start_at = start_angle + angle_inc * img_no stop_angle = start_at + img_range * 1.0 + #print("======= CHARACTERISATION Adding angle and range to the header...") + #Add start angle to the header + #detector = HWR.beamline.detector + #detector.set_eiger_start_angle(start_at) + + # Add angle increment to the header + #detector.set_eiger_angle_increment(angle_inc) + print("collecting image %s, angle %f" % (img_no, start_at)) if start_at >= stop_angle: - init_pos = start_at - self.acq_speed * self.turnback_time + init_pos = start_at #- self.acq_speed * self.turnback_time # init_pos = start_at - 1.5 else: - init_pos = start_at + self.acq_speed * self.turnback_time + init_pos = start_at #+ self.acq_speed * self.turnback_time # init_pos = start_at + 1.5 - self.omega_mv(init_pos, self.default_speed) - self.collect_std_collection(start_angle, stop_angle) - diffr.set_omega_velocity(self.default_speed) - self.acq_window_off_cmd() - self.acq_off_cmd() - self.log.debug( - "======= collect_characterisation Waiting =======================================" - ) + # self.omega_mv(init_pos, self.default_speed) + self.collect_std_collection(start_at, stop_angle) + + #This part goes to standard collection. Otherwise it produces phantom openings. + # diffr.set_omega_velocity(self.default_speed) + # self.acq_window_off_cmd() + # self.acq_off_cmd() + self.log.debug("======= collect_characterisation Waiting =======================================") - # Let adxv know whether it is + #Let adxv know whether it is # self.adxv_notify(self.latest_h5_filename,img_no+1) + + # time.sleep(1) def adxv_notify(self, image_filename, image_num=1): """ @@ -439,12 +460,17 @@ def acquisition_cleanup(self): try: diffr = HWR.beamline.diffractometer detector = HWR.beamline.detector - diffr.set_omega_velocity(self.default_speed) - self.acq_window_off_cmd() + detector.stop_acquisition() + diffr.wait_omega() + # ================= + #It is probably already finished in a standard collection. self.acq_off_cmd() + self.acq_window_off_cmd() + # ================== + diffr.set_omega_velocity(self.default_speed) self.log.debug("#COLLECT# Closing detector cover") diffr.detector_cover_close(wait=True) - detector.stop_acquisition() + except RuntimeError: self.log.error(traceback.format_exc()) From 7def003ae0674ce5709b98013aa0cc599a51048b Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 09:53:30 +0200 Subject: [PATCH 028/151] Force upgrade from the develop to avoid merging conflict --- mxcubecore/Command/Tango.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mxcubecore/Command/Tango.py b/mxcubecore/Command/Tango.py index 6f5c98f84f..96e998e14e 100644 --- a/mxcubecore/Command/Tango.py +++ b/mxcubecore/Command/Tango.py @@ -21,7 +21,6 @@ import logging import gevent import gevent.event -import numpy as np try: import Queue as queue @@ -320,7 +319,7 @@ def get_info(self): self._device_initialized.wait(timeout=3) return self.device.get_attribute_config(self.attribute_name) - + def update(self, value=Poller.NotInitializedValue): # start with checking if we have a numpy array, as comparing # numpy.ndarray to Poller.NotInitializedValue raises a ValueError exception @@ -334,7 +333,6 @@ def get_info(self): self.value = value self.emit("update", value) - def get_value(self): if self.read_as_str: value = self.device.read_attribute( From 0451f4751e5447d73b7a533426484e9d40afc085 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 10:34:20 +0200 Subject: [PATCH 029/151] Added missing warnings module --- mxcubecore/HardwareObjects/ISPyBClient.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mxcubecore/HardwareObjects/ISPyBClient.py b/mxcubecore/HardwareObjects/ISPyBClient.py index 34797ad402..56475e92bb 100644 --- a/mxcubecore/HardwareObjects/ISPyBClient.py +++ b/mxcubecore/HardwareObjects/ISPyBClient.py @@ -8,6 +8,7 @@ from pprint import pformat from collections import namedtuple from datetime import datetime +import warnings try: from urlparse import urljoin From f4ea552816b157f359f806063f0b50dd6e3ea32d Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 11:20:37 +0200 Subject: [PATCH 030/151] Enabled back explicit check on if beamtimeid is open --- mxcubecore/HardwareObjects/DESY/P11Session.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Session.py b/mxcubecore/HardwareObjects/DESY/P11Session.py index fc959c288a..2e00a81615 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Session.py +++ b/mxcubecore/HardwareObjects/DESY/P11Session.py @@ -85,8 +85,7 @@ def info_set_defaults(self): self.beamtime_info["rootPath"] = PATH_FALLBACK def is_beamtime_open(self): - return True - # return self.is_writable_dir( os.path.join(PATH_BEAMTIME, self.raw_data_folder_name) ) + return self.is_writable_dir( os.path.join(PATH_BEAMTIME, self.raw_data_folder_name) ) def is_commissioning_open(self): return self.is_writable_dir( From 3f16e795ef658ebd0c2afe5526639c7471426ee5 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 11:29:10 +0200 Subject: [PATCH 031/151] Added debug info in case beamtime ID is not opened --- mxcubecore/HardwareObjects/DESY/P11Session.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mxcubecore/HardwareObjects/DESY/P11Session.py b/mxcubecore/HardwareObjects/DESY/P11Session.py index 2e00a81615..4e1abb1f16 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Session.py +++ b/mxcubecore/HardwareObjects/DESY/P11Session.py @@ -85,6 +85,12 @@ def info_set_defaults(self): self.beamtime_info["rootPath"] = PATH_FALLBACK def is_beamtime_open(self): + self.log.debug("=========== CHECKING IF BEAMTIME ID IS OPEN... ============") + if self.is_writable_dir(os.path.join(PATH_BEAMTIME, self.raw_data_folder_name)): + self.log.debug("=========== BEAMTIME IS OPEN (/gpfs/current exists) ============") + else: + self.log.debug("=========== NO BEMTIME ID IS OPEN (check /gpfs/current) ============") + return self.is_writable_dir( os.path.join(PATH_BEAMTIME, self.raw_data_folder_name) ) def is_commissioning_open(self): From 832f6e7a04811f56b6abf39c051804bca675639e Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 16:58:08 +0200 Subject: [PATCH 032/151] Added beamtime info as a property --- mxcubecore/HardwareObjects/DESY/P11Session.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mxcubecore/HardwareObjects/DESY/P11Session.py b/mxcubecore/HardwareObjects/DESY/P11Session.py index 4e1abb1f16..f2fdfce8b0 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Session.py +++ b/mxcubecore/HardwareObjects/DESY/P11Session.py @@ -116,6 +116,9 @@ def get_current_proposal_number(self): info = self.get_beamtime_info() return info["proposalId"] + def get_beamtime_info(self): + return self.beamtime_info + def read_beamtime_info(self): self.log.debug("=========== READING BEAMTIME INFO ============") if os.path.exists(PATH_BEAMTIME): From 0dc5d28ced7082d5783ee9edf6aac403115939f0 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 16:59:56 +0200 Subject: [PATCH 033/151] Added additional debug messages for shutter --- mxcubecore/HardwareObjects/DESY/P11Shutter.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mxcubecore/HardwareObjects/DESY/P11Shutter.py b/mxcubecore/HardwareObjects/DESY/P11Shutter.py index 3a147822dc..1fe79adaed 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Shutter.py +++ b/mxcubecore/HardwareObjects/DESY/P11Shutter.py @@ -133,9 +133,12 @@ def update_shutter_state(self, state=None): if state is None: state = self.chan_state.get_value() + self.log.debug(" SHUTTER state changed") if state[0] == 3: + self.log.debug(" P11SHUTTER IS OPEN") value = self.VALUES.OPEN else: + self.log.debug(" P11SHUTTER IS CLOSED") value = self.VALUES.CLOSED # else: @@ -146,6 +149,7 @@ def update_shutter_state(self, state=None): self.update_value(value) + self.log.debug(" update shutter state done") return value def simulated_update(self): From d62e6bf18923a7ae9894a4cef1f728659b6db8d2 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 17:01:42 +0200 Subject: [PATCH 034/151] Fixed get_properties naming (Bixente) --- mxcubecore/HardwareObjects/MotorsNPosition.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/MotorsNPosition.py b/mxcubecore/HardwareObjects/MotorsNPosition.py index c28ab9f24d..286826be3d 100644 --- a/mxcubecore/HardwareObjects/MotorsNPosition.py +++ b/mxcubecore/HardwareObjects/MotorsNPosition.py @@ -121,7 +121,7 @@ def load_positions(self): def get_position_list(self): return list(self._positions.keys()) - def get_properties_(self, position_index, property_name): + def get_properties(self, position_index, property_name): """ returns property with name property_name for position_index if position_index is None returns OrderedDict with property_name for all positions From 44491ab25a1fa708291bde1b4ed27ae173d54177 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 17:04:04 +0200 Subject: [PATCH 035/151] Removed faulty login_type=user fot P11 --- mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py b/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py index d1f259cb7a..3a6e24119e 100644 --- a/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py +++ b/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py @@ -26,8 +26,6 @@ def init(self): "PROPOSAL NUMBER is %s" % self.simulated_prop_number ) - self.loginType = "user" - def update_data_collection(self, mx_collection, wait=False): mx_collection["beamline_name"] = "P11" ISPyBClient.update_data_collection(self, mx_collection, wait) From d652b9c451394830400b8a94a466848af47ef5fb Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 17:06:43 +0200 Subject: [PATCH 036/151] Removed is_open() as a function and assigned is_closed() as a property for shutter-like objects inside P11 HO (Bixente) --- mxcubecore/HardwareObjects/DESY/P11DetectorCover.py | 8 +------- mxcubecore/HardwareObjects/DESY/P11FastShutter.py | 2 ++ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py index e246d7646b..1f1e208f20 100644 --- a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py +++ b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py @@ -197,13 +197,7 @@ def simulated_update(self): self.update_value(value) return value - def is_open(self): - """Check if the shutter is open. - Returns: - (bool): True if open, False otherwise. - """ - return self.get_value() == self.VALUES.OPEN - + @property def is_closed(self): """Check if the shutter is closed. Returns: diff --git a/mxcubecore/HardwareObjects/DESY/P11FastShutter.py b/mxcubecore/HardwareObjects/DESY/P11FastShutter.py index 4b4ae4c6e5..ebe924a395 100644 --- a/mxcubecore/HardwareObjects/DESY/P11FastShutter.py +++ b/mxcubecore/HardwareObjects/DESY/P11FastShutter.py @@ -67,9 +67,11 @@ def init(self): def get_value(self): return self.update_fast_shutter() + @property def is_open(self): return self.get_value() == self.VALUES.OPEN + @property def is_closed(self): return self.get_value() == self.VALUES.CLOSED From 8a03c769777bd9d377223db030b18aa93c871165 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 17:07:35 +0200 Subject: [PATCH 037/151] Added is_open as a property inside P11NanoDiff (Bixente) --- mxcubecore/HardwareObjects/DESY/P11NanoDiff.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py b/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py index e327c48faa..10fe34b321 100644 --- a/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py +++ b/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py @@ -737,9 +737,9 @@ def detector_cover_close(self, wait=True): def wait_detcover(self, state, timeout=60): start_time = time.time() while time.time() - start_time > timeout: - if state == "open" and self.detcover_hwobj.is_open(): + if state == "open" and self.detcover_hwobj.is_open: break - elif state == "close" and self.detcover_hwobj.is_closed(): + elif state == "close" and self.detcover_hwobj.is_closed: break gevent.sleep(0.5) @@ -802,8 +802,8 @@ def update_phase(self, value=None): omega_pos = self.get_omega_position() - cover_open = self.detcover_hwobj.is_open() - cover_closed = self.detcover_hwobj.is_closed() + cover_open = self.detcover_hwobj.is_open + cover_closed = self.detcover_hwobj.is_closed blight_in = self.backlight_hwobj.is_in() blight_out = self.backlight_hwobj.is_out() collim = self.collimator_hwobj.get_position() From 14e9de0d0f09b1450fb1f3cd18188f3853adc665 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 17:26:57 +0200 Subject: [PATCH 038/151] Fixed other get_properties typos which were preventing loading --- mxcubecore/HardwareObjects/MotorsNPosition.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/MotorsNPosition.py b/mxcubecore/HardwareObjects/MotorsNPosition.py index 286826be3d..ab28f896e8 100644 --- a/mxcubecore/HardwareObjects/MotorsNPosition.py +++ b/mxcubecore/HardwareObjects/MotorsNPosition.py @@ -161,7 +161,7 @@ def set_position(self, posname): posidx = -1 for name in self._positions: posidx += 1 - if posname == self.get_properties_(posidx, "posname"): + if posname == self.get_properties(posidx, "posname"): self._set_value(posidx) return From fb4f5345c0b63f068c0f74378e08e622987ac187 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Thu, 5 Oct 2023 15:35:55 +0200 Subject: [PATCH 039/151] Fixed shutter openning wainting forever (Bixente) --- mxcubecore/HardwareObjects/DESY/P11Shutter.py | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Shutter.py b/mxcubecore/HardwareObjects/DESY/P11Shutter.py index 1fe79adaed..8202549f10 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Shutter.py +++ b/mxcubecore/HardwareObjects/DESY/P11Shutter.py @@ -22,6 +22,7 @@ import gevent import urllib from mxcubecore.HardwareObjects.abstract.AbstractShutter import AbstractShutter +import mxcubecore.HardwareObjects.abstract.AbstractShutter as absshut from mxcubecore.BaseHardwareObjects import HardwareObjectState from enum import Enum, unique @@ -85,6 +86,8 @@ def init(self): else: self.simulated_update() + self.update_state(self.STATES.READY) + super(AbstractShutter, self).init() def get_value(self): @@ -105,25 +108,39 @@ def _set_value(self, value): if self.simulation: self.simulated_opened = open_it self.simulated_moving = True - gevent.spawn(self.simul_do) + self.t1 = gevent.spawn(self.simul_do) + self.t1.link(self.do_finish) + self.t1.link_exception(self.do_finish_exc) else: if open_it: self.do_open() else: self.do_close() self.cmd_started = time.time() + self.log.debug(" ### setting value value for shutter done") def do_open(self, timeout=3): + self.log.debug(" OPENING SHUTTER (web request)") result = urllib.request.urlopen(self.url_open, None, timeout).readlines() + self.log.debug(" OPENING SHUTTER (web request) retured") def do_close(self, timeout=3): + self.log.debug(" CLOSING SHUTTER (web request)") result = urllib.request.urlopen(self.url_close, None, timeout).readlines() + self.log.debug(" CLOSING SHUTTER (web request) retured") def simul_do(self): + self.log.debug("### starting simulated shutter move") gevent.sleep(1) self.simulated_moving = False self.log.debug("### updating simulated shutter") self.simulated_update() + self.log.debug("### ending simulated shutter move") + + def do_finish(self, t=None): + self.log.debug("### simulated finished") + def do_finish_exc(self, exc=None): + self.log.debug("### simulated finished with exception") def update_shutter_state(self, state=None): """Updates shutter state @@ -134,6 +151,7 @@ def update_shutter_state(self, state=None): state = self.chan_state.get_value() self.log.debug(" SHUTTER state changed") + if state[0] == 3: self.log.debug(" P11SHUTTER IS OPEN") value = self.VALUES.OPEN From d002f93431a06f3ae2541619e075386897763ff6 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Fri, 6 Oct 2023 17:32:07 +0200 Subject: [PATCH 040/151] Added preliminary flux HO for P11 --- mxcubecore/HardwareObjects/DESY/P11Flux.py | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 mxcubecore/HardwareObjects/DESY/P11Flux.py diff --git a/mxcubecore/HardwareObjects/DESY/P11Flux.py b/mxcubecore/HardwareObjects/DESY/P11Flux.py new file mode 100644 index 0000000000..ae64c4ca83 --- /dev/null +++ b/mxcubecore/HardwareObjects/DESY/P11Flux.py @@ -0,0 +1,72 @@ +# +# Project: MXCuBE +# https://github.com/mxcube +# +# This file is part of MXCuBE software. +# +# MXCuBE is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# MXCuBE is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with MXCuBE. If not, see . + +from random import random +from mxcubecore.HardwareObjects.abstract.AbstractFlux import AbstractFlux + +from mxcubecore import HardwareRepository as HWR + +__credits__ = ["MXCuBE collaboration"] +__category__ = "General" + + +class P11Flux(AbstractFlux): + + # default_flux - for initialising mockup + default_flux = 5e12 + + def __init__(self, name): + AbstractFlux.__init__(self, name) + + self.measured_flux_list = [] + self.measured_flux_dict = {} + self.current_flux_dict = {} + + def init(self): + + self.measure_flux() + + def get_value(self): + """Get flux at current transmission in units of photons/s""" + + """ FLUX IS CHEETED HERE - NOWERE ELSE!""" + return self.current_flux_dict["flux"] + + def measure_flux(self): + """Measures intesity""" + beam_size = HWR.beamline.beam.get_beam_size() + transmission = HWR.beamline.transmission.get_value() + flux = self.default_flux * (1 + random()) + + self.measured_flux_list = [ + { + "size_x": beam_size[0], + "size_y": beam_size[1], + "transmission": transmission, + "flux": flux, + } + ] + + self.measured_flux_dict = self.measured_flux_list[0] + self.current_flux_dict = self.measured_flux_list[0] + + self.emit( + "fluxInfoChanged", + {"measured": self.measured_flux_dict, "current": self.current_flux_dict}, + ) From 3575ae9ae52022094e509f78aad2cc2dd11b1053 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Fri, 6 Oct 2023 19:18:03 +0200 Subject: [PATCH 041/151] Upgraded the characterisation part for P11 using EDNA --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 68 ++++++++++--------- .../DESY/P11EDNACharacterisation.py | 33 ++++++++- 2 files changed, 68 insertions(+), 33 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index c2f1b2e9d9..0912c90293 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -126,6 +126,7 @@ def data_collection_hook(self): self.diffr = HWR.beamline.diffractometer detector = HWR.beamline.detector + dc_pars = self.current_dc_parameters collection_type = dc_pars["experiment_type"] @@ -199,8 +200,12 @@ def data_collection_hook(self): ) # Filepath to the EDNA processing - # filepath = os.path.join(basepath,"%s_%d" % (prefix, runno)) + #filepath = os.path.join(basepath,"%s_%d" % (prefix, runno)) + + #setting up xds_dir for characterisation (used there internally to create dirs) + self.current_dc_parameters["xds_dir"] = os.path.join(basepath,"%s_%d" % (prefix, runno)) + self.log.debug( "======= CURRENT FILEPATH: " + str(filepath) @@ -282,23 +287,24 @@ def data_collection_hook(self): # os.system("/opt/dectris/albula/4.0/bin/albula "+self.latest_h5_filename +" &") # os.system("adxv "+self.latest_h5_filename +" &") + #TODO: Remove for now creation of the snapshots and processing html. # Open index_html - os.system("firefox /gpfs/current/processed/index.html") + #os.system("firefox /gpfs/current/processed/index.html") # Create diffraction snapshots - for i in range(nframes): - os.system( - "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " - + self.latest_h5_filename - + " --output " - + os.path.join( - basepath, prefix, "screening_" + str(runno).zfill(3) - ) - + "/" - + " --image_number " - + str(i + 1) - ) - +# for i in range(nframes): +# os.system( +# "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " +# + self.latest_h5_filename +# + " --output " +# + os.path.join( +# basepath, prefix, "screening_" + str(runno).zfill(3) +# ) +# + "/" +# + " --image_number " +# + str(i + 1) +# ) +# else: self.collect_std_collection(start_angle, stop_angle) self.generate_xds_template() @@ -307,21 +313,21 @@ def data_collection_hook(self): # os.system("killall albula") # os.system("/opt/dectris/albula/4.0/bin/albula "+self.latest_h5_filename +" &") - # Open index_html - os.system("firefox /gpfs/current/processed/index.html") - - # Create diffraction snapshots - os.system( - "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " - + self.latest_h5_filename - + " --output " - + os.path.join( - basepath, prefix, "rotational_" + str(runno).zfill(3) - ) - + "/" - + " --image_number 1" - ) - +# # Open index_html +# os.system("firefox /gpfs/current/processed/index.html") +# +# # Create diffraction snapshots +# os.system( +# "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " +# + self.latest_h5_filename +# + " --output " +# + os.path.join( +# basepath, prefix, "rotational_" + str(runno).zfill(3) +# ) +# + "/" +# + " --image_number 1" +# ) +# except RuntimeError: self.log.error(traceback.format_exc()) finally: @@ -535,7 +541,7 @@ def add_h5_info(self, h5file): del h5fd[node] h5fd.close() - except RuntimeError as err_msg: + except RuntimeWarning as err_msg: self.log.debug("Error while adding info to HDF5 file (%s)" % str(err_msg)) self.log.debug(traceback.format_exc()) diff --git a/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py b/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py index 7e0eb6c775..28f3399e25 100644 --- a/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py +++ b/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py @@ -47,6 +47,26 @@ def __init__(self, name): self.edna_default_file = None self.start_edna_command = None + def _run_edna(self, input_file, results_file, process_directory): + """Starts EDNA""" + msg = "Starting EDNA characterisation using xml file %s" % input_file + logging.getLogger("queue_exec").info(msg) + + args = (self.start_edna_command, input_file, results_file, process_directory) + # subprocess.call("%s %s %s %s" % args, shell=True) + + # Test run DESY + self.edna_maxwell(process_directory,input_file, results_file) + + + + self.result = None + if os.path.exists(results_file): + self.result = XSDataResultMXCuBE.parseFile(results_file) + + return self.result + + def edna_maxwell(self, process_directory, inputxml, outputxml): """ The function `edna_maxwell` is used to execute a command on a remote cluster using SSH and SBATCH. @@ -105,6 +125,8 @@ def edna_maxwell(self, process_directory, inputxml, outputxml): ) ) + print('{ssh:s} "{sbatch:s} --wrap \\"{cmd:s}"\\"'.format(ssh=ssh, sbatch=sbatch, cmd=cmd)) + os.system( '{ssh:s} "{sbatch:s} --wrap \\"{cmd:s}"\\"'.format( ssh=ssh, sbatch=sbatch, cmd=cmd @@ -235,16 +257,23 @@ def input_from_params(self, data_collection, char_params): data_set = XSDataMXCuBEDataSet() acquisition_parameters = data_collection.acquisitions[0].acquisition_parameters path_template = data_collection.acquisitions[0].path_template - + + #Make sure there is a proper path conversion between different mount points + print("======= Characterisation path template ====", path_template.directory) #/gpfs/current/raw + image_dir = path_template.directory.replace( "/gpfs/current", triggerUtils.get_beamtime_metadata()[2] ) - path_str = os.path.join(image_dir, path_template.get_image_file_name()) + print(image_dir) + path_str = os.path.join(image_dir, path_template.get_image_file_name()) + print(path_template.xds_dir) + characterisation_dir = path_template.xds_dir.replace( "/autoprocessing_", "/characterisation_" ) + os.makedirs(characterisation_dir, mode=0o755, exist_ok=True) for img_num in range(int(acquisition_parameters.num_images)): From 4dafa5b9f792d8e30aa785f78fe9f9a50a995dbf Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Fri, 6 Oct 2023 22:57:55 +0200 Subject: [PATCH 042/151] Linting --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 142 +++++++++--------- .../HardwareObjects/DESY/P11DetectorCover.py | 17 ++- .../DESY/P11EDNACharacterisation.py | 27 ++-- mxcubecore/HardwareObjects/DESY/P11Flux.py | 2 +- mxcubecore/HardwareObjects/DESY/P11Session.py | 14 +- mxcubecore/HardwareObjects/DESY/P11Shutter.py | 20 +-- 6 files changed, 119 insertions(+), 103 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index 0912c90293..b13044b47e 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -56,23 +56,21 @@ class P11Collect(AbstractCollect): - def __init__(self, *args): super(P11Collect, self).__init__(*args) def init(self): - super(P11Collect,self).init() + super(P11Collect, self).init() # os.system("/opt/xray/bin/adxv -socket -colors Gray -rings &") # os.system("/bin/bash /gpfs/local/shared/MXCuBE/STRELA/start_viewer_zmq.sh") - self.default_speed = self.get_property("omega_default_speed", 130) self.turnback_time = self.get_property("turnback_time", 0.3) - self.filter_server_name = self.get_property('filterserver') - self.mono_server_name = self.get_property('monoserver') + self.filter_server_name = self.get_property("filterserver") + self.mono_server_name = self.get_property("monoserver") self.filter_server = DeviceProxy(self.filter_server_name) self.mono_server = DeviceProxy(self.mono_server_name) @@ -84,9 +82,14 @@ def init(self): self.acq_off_cmd = self.get_command_object("acq_off") self.acq_window_off_cmd = self.get_command_object("acq_window_off") - if None in [self.lower_bound_ch, self.upper_bound_ch, - self.acq_arm_cmd, self.acq_on_cmd, self.acq_off_cmd, - self.acq_window_off_cmd]: + if None in [ + self.lower_bound_ch, + self.upper_bound_ch, + self.acq_arm_cmd, + self.acq_on_cmd, + self.acq_off_cmd, + self.acq_window_off_cmd, + ]: self.init_ok = False self.log.debug("lower_bound_ch: %s" % self.lower_bound_ch) self.log.debug("upper_bound_ch: %s" % self.upper_bound_ch) @@ -96,6 +99,7 @@ def init(self): self.log.debug("acq_window_off_cmd: %s" % self.acq_window_off_cmd) else: self.init_ok = True + @task def move_motors(self, motor_position_dict): HWR.beamline.diffractometer.wait_omega() @@ -126,7 +130,6 @@ def data_collection_hook(self): self.diffr = HWR.beamline.diffractometer detector = HWR.beamline.detector - dc_pars = self.current_dc_parameters collection_type = dc_pars["experiment_type"] @@ -200,12 +203,13 @@ def data_collection_hook(self): ) # Filepath to the EDNA processing - #filepath = os.path.join(basepath,"%s_%d" % (prefix, runno)) + # filepath = os.path.join(basepath,"%s_%d" % (prefix, runno)) + + # setting up xds_dir for characterisation (used there internally to create dirs) + self.current_dc_parameters["xds_dir"] = os.path.join( + basepath, "%s_%d" % (prefix, runno) + ) - - #setting up xds_dir for characterisation (used there internally to create dirs) - self.current_dc_parameters["xds_dir"] = os.path.join(basepath,"%s_%d" % (prefix, runno)) - self.log.debug( "======= CURRENT FILEPATH: " + str(filepath) @@ -287,24 +291,24 @@ def data_collection_hook(self): # os.system("/opt/dectris/albula/4.0/bin/albula "+self.latest_h5_filename +" &") # os.system("adxv "+self.latest_h5_filename +" &") - #TODO: Remove for now creation of the snapshots and processing html. + # TODO: Remove for now creation of the snapshots and processing html. # Open index_html - #os.system("firefox /gpfs/current/processed/index.html") + # os.system("firefox /gpfs/current/processed/index.html") # Create diffraction snapshots -# for i in range(nframes): -# os.system( -# "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " -# + self.latest_h5_filename -# + " --output " -# + os.path.join( -# basepath, prefix, "screening_" + str(runno).zfill(3) -# ) -# + "/" -# + " --image_number " -# + str(i + 1) -# ) -# + # for i in range(nframes): + # os.system( + # "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " + # + self.latest_h5_filename + # + " --output " + # + os.path.join( + # basepath, prefix, "screening_" + str(runno).zfill(3) + # ) + # + "/" + # + " --image_number " + # + str(i + 1) + # ) + # else: self.collect_std_collection(start_angle, stop_angle) self.generate_xds_template() @@ -313,21 +317,21 @@ def data_collection_hook(self): # os.system("killall albula") # os.system("/opt/dectris/albula/4.0/bin/albula "+self.latest_h5_filename +" &") -# # Open index_html -# os.system("firefox /gpfs/current/processed/index.html") -# -# # Create diffraction snapshots -# os.system( -# "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " -# + self.latest_h5_filename -# + " --output " -# + os.path.join( -# basepath, prefix, "rotational_" + str(runno).zfill(3) -# ) -# + "/" -# + " --image_number 1" -# ) -# + # # Open index_html + # os.system("firefox /gpfs/current/processed/index.html") + # + # # Create diffraction snapshots + # os.system( + # "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " + # + self.latest_h5_filename + # + " --output " + # + os.path.join( + # basepath, prefix, "rotational_" + str(runno).zfill(3) + # ) + # + "/" + # + " --image_number 1" + # ) + # except RuntimeError: self.log.error(traceback.format_exc()) finally: @@ -347,20 +351,17 @@ def collect_std_collection(self, start_angle, stop_angle): """ HWR.beamline.diffractometer.wait_omega() - start_pos = start_angle - self.turnback_time*self.acq_speed - stop_pos = stop_angle + self.turnback_time*self.acq_speed - - - + start_pos = start_angle - self.turnback_time * self.acq_speed + stop_pos = stop_angle + self.turnback_time * self.acq_speed + self.log.debug("#COLLECT# Running OMEGA through the std acquisition") if start_angle <= stop_angle: - self.lower_bound_ch.set_value(start_angle) - self.upper_bound_ch.set_value(stop_angle) + self.lower_bound_ch.set_value(start_angle) + self.upper_bound_ch.set_value(stop_angle) else: - self.lower_bound_ch.set_value(stop_angle) - self.upper_bound_ch.set_value(start_angle) - + self.lower_bound_ch.set_value(stop_angle) + self.upper_bound_ch.set_value(start_angle) self.omega_mv(start_pos, self.default_speed) self.acq_arm_cmd() @@ -371,7 +372,6 @@ def collect_std_collection(self, start_angle, stop_angle): self.omega_mv(stop_angle, self.acq_speed) HWR.beamline.diffractometer.wait_omega() - def collect_characterisation( self, start_angle, img_range, nimages, angle_inc, exp_time ): @@ -391,7 +391,9 @@ def collect_characterisation( diffr = HWR.beamline.diffractometer - self.log.debug("#COLLECT# Running OMEGA through the characteristation acquisition") + self.log.debug( + "#COLLECT# Running OMEGA through the characteristation acquisition" + ) self.omega_mv(start_angle, self.default_speed) @@ -399,35 +401,37 @@ def collect_characterisation( print("collecting image %s" % img_no) start_at = start_angle + angle_inc * img_no stop_angle = start_at + img_range * 1.0 - #print("======= CHARACTERISATION Adding angle and range to the header...") - #Add start angle to the header - #detector = HWR.beamline.detector - #detector.set_eiger_start_angle(start_at) + # print("======= CHARACTERISATION Adding angle and range to the header...") + # Add start angle to the header + # detector = HWR.beamline.detector + # detector.set_eiger_start_angle(start_at) # Add angle increment to the header - #detector.set_eiger_angle_increment(angle_inc) + # detector.set_eiger_angle_increment(angle_inc) print("collecting image %s, angle %f" % (img_no, start_at)) if start_at >= stop_angle: - init_pos = start_at #- self.acq_speed * self.turnback_time + init_pos = start_at # - self.acq_speed * self.turnback_time # init_pos = start_at - 1.5 else: - init_pos = start_at #+ self.acq_speed * self.turnback_time + init_pos = start_at # + self.acq_speed * self.turnback_time # init_pos = start_at + 1.5 # self.omega_mv(init_pos, self.default_speed) self.collect_std_collection(start_at, stop_angle) - #This part goes to standard collection. Otherwise it produces phantom openings. + # This part goes to standard collection. Otherwise it produces phantom openings. # diffr.set_omega_velocity(self.default_speed) # self.acq_window_off_cmd() # self.acq_off_cmd() - self.log.debug("======= collect_characterisation Waiting =======================================") + self.log.debug( + "======= collect_characterisation Waiting =======================================" + ) - #Let adxv know whether it is + # Let adxv know whether it is # self.adxv_notify(self.latest_h5_filename,img_no+1) - + # time.sleep(1) def adxv_notify(self, image_filename, image_num=1): @@ -469,14 +473,14 @@ def acquisition_cleanup(self): detector.stop_acquisition() diffr.wait_omega() # ================= - #It is probably already finished in a standard collection. + # It is probably already finished in a standard collection. self.acq_off_cmd() self.acq_window_off_cmd() # ================== diffr.set_omega_velocity(self.default_speed) self.log.debug("#COLLECT# Closing detector cover") diffr.detector_cover_close(wait=True) - + except RuntimeError: self.log.error(traceback.format_exc()) diff --git a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py index 1f1e208f20..ec9c9e480e 100644 --- a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py +++ b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py @@ -44,13 +44,14 @@ class P11DetectorCover(AbstractShutter): @unique class BaseValueEnum(Enum): - """Defines only the compulsory values.""" - OPEN = "OPEN" - CLOSED = "CLOSED" - MOVING = "MOVING" - UNKNOWN = "UNKNOWN" - - VALUES=BaseValueEnum + """Defines only the compulsory values.""" + + OPEN = "OPEN" + CLOSED = "CLOSED" + MOVING = "MOVING" + UNKNOWN = "UNKNOWN" + + VALUES = BaseValueEnum def __init__(self, name): @@ -196,7 +197,7 @@ def simulated_update(self): self.update_value(value) return value - + @property def is_closed(self): """Check if the shutter is closed. diff --git a/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py b/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py index 28f3399e25..058ddc6784 100644 --- a/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py +++ b/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py @@ -56,17 +56,14 @@ def _run_edna(self, input_file, results_file, process_directory): # subprocess.call("%s %s %s %s" % args, shell=True) # Test run DESY - self.edna_maxwell(process_directory,input_file, results_file) - - + self.edna_maxwell(process_directory, input_file, results_file) self.result = None if os.path.exists(results_file): self.result = XSDataResultMXCuBE.parseFile(results_file) return self.result - - + def edna_maxwell(self, process_directory, inputxml, outputxml): """ The function `edna_maxwell` is used to execute a command on a remote cluster using SSH and SBATCH. @@ -125,7 +122,11 @@ def edna_maxwell(self, process_directory, inputxml, outputxml): ) ) - print('{ssh:s} "{sbatch:s} --wrap \\"{cmd:s}"\\"'.format(ssh=ssh, sbatch=sbatch, cmd=cmd)) + print( + '{ssh:s} "{sbatch:s} --wrap \\"{cmd:s}"\\"'.format( + ssh=ssh, sbatch=sbatch, cmd=cmd + ) + ) os.system( '{ssh:s} "{sbatch:s} --wrap \\"{cmd:s}"\\"'.format( @@ -257,10 +258,12 @@ def input_from_params(self, data_collection, char_params): data_set = XSDataMXCuBEDataSet() acquisition_parameters = data_collection.acquisitions[0].acquisition_parameters path_template = data_collection.acquisitions[0].path_template - - #Make sure there is a proper path conversion between different mount points - print("======= Characterisation path template ====", path_template.directory) #/gpfs/current/raw - + + # Make sure there is a proper path conversion between different mount points + print( + "======= Characterisation path template ====", path_template.directory + ) # /gpfs/current/raw + image_dir = path_template.directory.replace( "/gpfs/current", triggerUtils.get_beamtime_metadata()[2] ) @@ -269,11 +272,11 @@ def input_from_params(self, data_collection, char_params): path_str = os.path.join(image_dir, path_template.get_image_file_name()) print(path_template.xds_dir) - + characterisation_dir = path_template.xds_dir.replace( "/autoprocessing_", "/characterisation_" ) - + os.makedirs(characterisation_dir, mode=0o755, exist_ok=True) for img_num in range(int(acquisition_parameters.num_images)): diff --git a/mxcubecore/HardwareObjects/DESY/P11Flux.py b/mxcubecore/HardwareObjects/DESY/P11Flux.py index ae64c4ca83..d1475ab6f4 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Flux.py +++ b/mxcubecore/HardwareObjects/DESY/P11Flux.py @@ -44,7 +44,7 @@ def init(self): def get_value(self): """Get flux at current transmission in units of photons/s""" - + """ FLUX IS CHEETED HERE - NOWERE ELSE!""" return self.current_flux_dict["flux"] diff --git a/mxcubecore/HardwareObjects/DESY/P11Session.py b/mxcubecore/HardwareObjects/DESY/P11Session.py index f2fdfce8b0..05fecad4d8 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Session.py +++ b/mxcubecore/HardwareObjects/DESY/P11Session.py @@ -87,11 +87,17 @@ def info_set_defaults(self): def is_beamtime_open(self): self.log.debug("=========== CHECKING IF BEAMTIME ID IS OPEN... ============") if self.is_writable_dir(os.path.join(PATH_BEAMTIME, self.raw_data_folder_name)): - self.log.debug("=========== BEAMTIME IS OPEN (/gpfs/current exists) ============") + self.log.debug( + "=========== BEAMTIME IS OPEN (/gpfs/current exists) ============" + ) else: - self.log.debug("=========== NO BEMTIME ID IS OPEN (check /gpfs/current) ============") - - return self.is_writable_dir( os.path.join(PATH_BEAMTIME, self.raw_data_folder_name) ) + self.log.debug( + "=========== NO BEMTIME ID IS OPEN (check /gpfs/current) ============" + ) + + return self.is_writable_dir( + os.path.join(PATH_BEAMTIME, self.raw_data_folder_name) + ) def is_commissioning_open(self): return self.is_writable_dir( diff --git a/mxcubecore/HardwareObjects/DESY/P11Shutter.py b/mxcubecore/HardwareObjects/DESY/P11Shutter.py index 8202549f10..90e81aec28 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Shutter.py +++ b/mxcubecore/HardwareObjects/DESY/P11Shutter.py @@ -41,13 +41,14 @@ class P11Shutter(AbstractShutter): @unique class BaseValueEnum(Enum): - """Defines only the compulsory values.""" - OPEN = "OPEN" - CLOSED = "CLOSED" - MOVING = "MOVING" - UNKNOWN = "UNKNOWN" - - VALUES=BaseValueEnum + """Defines only the compulsory values.""" + + OPEN = "OPEN" + CLOSED = "CLOSED" + MOVING = "MOVING" + UNKNOWN = "UNKNOWN" + + VALUES = BaseValueEnum def __init__(self, name): @@ -109,8 +110,8 @@ def _set_value(self, value): self.simulated_opened = open_it self.simulated_moving = True self.t1 = gevent.spawn(self.simul_do) - self.t1.link(self.do_finish) - self.t1.link_exception(self.do_finish_exc) + self.t1.link(self.do_finish) + self.t1.link_exception(self.do_finish_exc) else: if open_it: self.do_open() @@ -139,6 +140,7 @@ def simul_do(self): def do_finish(self, t=None): self.log.debug("### simulated finished") + def do_finish_exc(self, exc=None): self.log.debug("### simulated finished with exception") From b8070784ab4d7fa0df58692621cea729c83c3fbf Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Tue, 17 Oct 2023 16:25:29 +0200 Subject: [PATCH 043/151] Add empty store_robot_action for P11 (temp fix due to ISPyB tests). --- mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py b/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py index 3a6e24119e..3225c34dda 100644 --- a/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py +++ b/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py @@ -38,6 +38,10 @@ def store_image(self, image_dict): self.prepare_image_for_lims(image_dict) return ISPyBClient.store_image(self, image_dict) + def store_robot_action(self, robot_action_dict): + #TODO ISPyB is not ready for now. This prevents from error 500 from the server. + pass + def prepare_collect_for_lims(self, mx_collect_dict): # Attention! directory passed by reference. modified in place From ae9588f8d5edc3e8def7aff3992ac99458d80fc9 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 25 Oct 2023 14:34:51 +0200 Subject: [PATCH 044/151] Fix in AbstractSampleChanger that was causing sample not loaded error at P11 even if everything was ok (Bixente). --- mxcubecore/HardwareObjects/DESY/P11SampleChanger.py | 2 ++ .../HardwareObjects/abstract/AbstractSampleChanger.py | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11SampleChanger.py b/mxcubecore/HardwareObjects/DESY/P11SampleChanger.py index 2ec48d57ab..5afe2710f6 100644 --- a/mxcubecore/HardwareObjects/DESY/P11SampleChanger.py +++ b/mxcubecore/HardwareObjects/DESY/P11SampleChanger.py @@ -205,6 +205,7 @@ def load(self, sample=None, wait=True): "Sample changer: Sample loaded (total time: %s)" % (time.time() - self._start_load) ) + self.emit("progressStop", ()) return self.get_loaded_sample() @@ -476,6 +477,7 @@ def _update_selection(self): # find sample for s in self.get_sample_list(): + print(f"Sample coords = {s.get_coords()}") if s.get_coords() == (basket, sample): self.log.debug(" - sample found") self._set_loaded_sample(s) diff --git a/mxcubecore/HardwareObjects/abstract/AbstractSampleChanger.py b/mxcubecore/HardwareObjects/abstract/AbstractSampleChanger.py index 3d579431ea..b8c26edaf0 100644 --- a/mxcubecore/HardwareObjects/abstract/AbstractSampleChanger.py +++ b/mxcubecore/HardwareObjects/abstract/AbstractSampleChanger.py @@ -806,8 +806,10 @@ def _set_loaded_sample(self, sample): if smp != sample: smp._set_loaded(False) else: - if self.get_loaded_sample() == smp: - smp._set_loaded(True) + self.log.debug(f" Found sample {smp} is loaded") + self.log.debug(f" getting loaded {self.get_loaded_sample()}") + #if self.get_loaded_sample() == smp: + smp._set_loaded(True) if previous_loaded != self.get_loaded_sample(): self._trigger_loaded_sample_changed_event(sample) From 5dabc0ff7cad74871d83552e47fc7fe9a5e84f73 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 25 Oct 2023 18:35:26 +0200 Subject: [PATCH 045/151] Added new HO for the beam representation for P11 (Bixente) --- mxcubecore/HardwareObjects/DESY/P11Beam.py | 114 +++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 mxcubecore/HardwareObjects/DESY/P11Beam.py diff --git a/mxcubecore/HardwareObjects/DESY/P11Beam.py b/mxcubecore/HardwareObjects/DESY/P11Beam.py new file mode 100644 index 0000000000..7088c2dfdb --- /dev/null +++ b/mxcubecore/HardwareObjects/DESY/P11Beam.py @@ -0,0 +1,114 @@ +# Project: MXCuBE +# https://github.com/mxcube +# +# This file is part of MXCuBE software. +# +# MXCuBE is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# MXCuBE is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with MXCuBE. If not, see . + +"""P11Beam""" + +import time +import sys +import urllib +from mxcubecore.HardwareObjects.abstract.AbstractBeam import AbstractBeam +from mxcubecore.BaseHardwareObjects import HardwareObjectState +from enum import Enum, unique + + +__credits__ = ["DESY P11"] +__license__ = "LGPLv3+" +__category__ = "General" + + +class P11Beam(AbstractBeam): + def __init__(self,*args): + super(P11Beam,self).__init__(*args) + + self._beam_size_dict = { + "aperture": [9999,9999], + "slits": [9999,9999], + } + + self._beam_position_on_screen = [340, 256] + + self.focus_sizes = { + -1: {'label': 'unknown', 'size': (0.2,0.2)}, + 0: {'label': 'flat', 'size': (0.2,0.2)}, + 1: {'label': '200x200', 'size': (0.2,0.2)}, + 2: {'label': '100x100', 'size': (0.1,0.1)}, + 3: {'label': '50x50', 'size': (0.05,0.05)}, + 4: {'label': '20x20', 'size': (0.02,0.02)}, + 5: {'label': '4x9', 'size': (0.009,0.004)}, + } + + + + def init(self): + self.mirror_idx_ch = self.get_channel_object("beamsize") + self.mirror_state_ch = self.get_channel_object("state") + + if self.mirror_idx_ch is not None: + self.mirror_idx_ch.connect_signal("update", self.mirror_idx_changed) + if self.mirror_state_ch is not None: + self.mirror_state_ch.connect_signal("update", self.mirror_state_changed) + + self.mirror_idx_changed() + self.mirror_state_changed() + + def get_beam_info_state(self): + if self.mirror_state_ch is not None: + tango_state = self.mirror_state_ch.get_value() + return self._convert_tango_state(tango_state) + + return self.STATES_READY + + def mirror_state_changed(self, state=None): + + if state is None: + state = self.get_beam_info_state() + + self.update_state( self._convert_tango_state(state) ) + + def _convert_tango_state(self, state): + str_state = str(state) + + if str_state == "ON": + _state = self.STATES.READY + elif str_state == "MOVING": + _state = self.STATES.BUSY + else: + _state = self.STATES.FAULT + return _state + + + def mirror_idx_changed(self, value=None): + + if value is None: + value = self.mirror_idx_ch.get_value() + + self.log.debug(f"P11Beam - mirror idx changed. now is {value}") + + if value not in self.focus_sizes: + value = -1 + self.log.debug(f" - UNKNOWN mirror index") + + curr_size_item = self.focus_sizes[value] + self.log.debug(f" current mirror focus is {curr_size_item['label']}: {curr_size_item['size']}") + + + self._beam_size_dict["aperture"] = curr_size_item['size'] + + self.evaluate_beam_info() + self.re_emit_values() + From 7e3188b70ddc8c13a6a5cca902c86c584fca54f9 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 8 Nov 2023 16:26:02 +0100 Subject: [PATCH 046/151] Fix beam position update in P11 Nanodiff --- mxcubecore/HardwareObjects/DESY/P11NanoDiff.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py b/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py index 10fe34b321..f4ce1efbc8 100644 --- a/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py +++ b/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py @@ -154,7 +154,8 @@ def init(self): self.update_phase() self.update_zoom_calibration() - self.beam_position = self.update_beam_position() + #self.beam_position = self.update_beam_position() + self.update_beam_position() def update_beam_position(self): zoom_hwobj = self.motor_hwobj_dict["zoom"] From 75ad89ccd111877d410748ad0c55717063fee071 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 8 Nov 2023 16:26:41 +0100 Subject: [PATCH 047/151] Minor changes --- mxcubecore/HardwareObjects/DESY/P11AlbulaView.py | 1 - 1 file changed, 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11AlbulaView.py b/mxcubecore/HardwareObjects/DESY/P11AlbulaView.py index 4062d1db26..95b2d76d3e 100644 --- a/mxcubecore/HardwareObjects/DESY/P11AlbulaView.py +++ b/mxcubecore/HardwareObjects/DESY/P11AlbulaView.py @@ -26,7 +26,6 @@ import time from PIL import Image - sys.path.append("/opt/dectris/albula/4.0/python/") from mxcubecore.BaseHardwareObjects import HardwareObject From b2f3c7c7ef5c3192301354511d5135fcfb859bdb Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 8 Nov 2023 16:28:18 +0100 Subject: [PATCH 048/151] Added slits gap None (no slits) for P11 (Bixente) --- mxcubecore/HardwareObjects/DESY/P11Beam.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mxcubecore/HardwareObjects/DESY/P11Beam.py b/mxcubecore/HardwareObjects/DESY/P11Beam.py index 7088c2dfdb..5b4da2fa14 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Beam.py +++ b/mxcubecore/HardwareObjects/DESY/P11Beam.py @@ -73,6 +73,9 @@ def get_beam_info_state(self): return self.STATES_READY + def get_slits_gap(self): + return None, None + def mirror_state_changed(self, state=None): if state is None: From 2fd8ad59458e8f12b802f34174846291b4abcec6 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 8 Nov 2023 16:29:40 +0100 Subject: [PATCH 049/151] Temp fix for P11 specific routine --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index b13044b47e..bc36df17d3 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -548,6 +548,9 @@ def add_h5_info(self, h5file): except RuntimeWarning as err_msg: self.log.debug("Error while adding info to HDF5 file (%s)" % str(err_msg)) self.log.debug(traceback.format_exc()) + except Exception as err_msg: + self.log.debug("Error while adding info to HDF5 file (%s)" % str(err_msg)) + self.log.debug(traceback.format_exc()) def get_filter_thickness(self): """ From 3d4f0d2c27fef61de7de8afa353f4050a07ea9e6 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Mon, 18 Sep 2023 12:11:42 +0200 Subject: [PATCH 050/151] Fixing the ambiguity with Poller value and .any --- mxcubecore/Command/Tango.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mxcubecore/Command/Tango.py b/mxcubecore/Command/Tango.py index 96e998e14e..6f5c98f84f 100644 --- a/mxcubecore/Command/Tango.py +++ b/mxcubecore/Command/Tango.py @@ -21,6 +21,7 @@ import logging import gevent import gevent.event +import numpy as np try: import Queue as queue @@ -319,7 +320,7 @@ def get_info(self): self._device_initialized.wait(timeout=3) return self.device.get_attribute_config(self.attribute_name) - def update(self, value=Poller.NotInitializedValue): + # start with checking if we have a numpy array, as comparing # numpy.ndarray to Poller.NotInitializedValue raises a ValueError exception @@ -333,6 +334,7 @@ def update(self, value=Poller.NotInitializedValue): self.value = value self.emit("update", value) + def get_value(self): if self.read_as_str: value = self.device.read_attribute( From 2b7e1fa650ed3b4c9d0b4c0f4a7c677e3b95b106 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Mon, 18 Sep 2023 12:42:20 +0200 Subject: [PATCH 051/151] P11Collect additional debug after upgrade --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 124 +++++++++++------- 1 file changed, 75 insertions(+), 49 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index 3171a52753..c2f1b2e9d9 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -39,24 +39,42 @@ from mxcubecore.Command.Tango import DeviceProxy +import gevent +import time +import numpy as np +import logging +import os +import sys +import math +import h5py import triggerUtils +from tango import DeviceProxy, DevState FILE_TIMEOUT = 5 class P11Collect(AbstractCollect): + def __init__(self, *args): super(P11Collect, self).__init__(*args) + def init(self): + + super(P11Collect,self).init() + + # os.system("/opt/xray/bin/adxv -socket -colors Gray -rings &") + + # os.system("/bin/bash /gpfs/local/shared/MXCuBE/STRELA/start_viewer_zmq.sh") + + self.default_speed = self.get_property("omega_default_speed", 130) - self.turnback_time = self.get_property("turnback_time", 0.1) - self.filter_server_name = self.get_property("filterserver") - self.mono_server_name = self.get_property("monoserver") + self.turnback_time = self.get_property("turnback_time", 0.3) + self.filter_server_name = self.get_property('filterserver') + self.mono_server_name = self.get_property('monoserver') self.filter_server = DeviceProxy(self.filter_server_name) self.mono_server = DeviceProxy(self.mono_server_name) - self.diffr = HWR.beamline.diffractometer self.lower_bound_ch = self.get_channel_object("acq_lower_bound") self.upper_bound_ch = self.get_channel_object("acq_upper_bound") @@ -66,26 +84,9 @@ def __init__(self, *args): self.acq_off_cmd = self.get_command_object("acq_off") self.acq_window_off_cmd = self.get_command_object("acq_window_off") - self.latest_frames = 1 - self.acq_speed = 1.0 - self.init_ok = False - self.latest_h5_filename = "TEST_master.h5" - - def init(self): - super(P11Collect, self).init() - - # os.system("/opt/xray/bin/adxv -socket -colors Gray -rings &") - - # os.system("/bin/bash /gpfs/local/shared/MXCuBE/STRELA/start_viewer_zmq.sh") - - if None in [ - self.lower_bound_ch, - self.upper_bound_ch, - self.acq_arm_cmd, - self.acq_on_cmd, - self.acq_off_cmd, - self.acq_window_off_cmd, - ]: + if None in [self.lower_bound_ch, self.upper_bound_ch, + self.acq_arm_cmd, self.acq_on_cmd, self.acq_off_cmd, + self.acq_window_off_cmd]: self.init_ok = False self.log.debug("lower_bound_ch: %s" % self.lower_bound_ch) self.log.debug("upper_bound_ch: %s" % self.upper_bound_ch) @@ -95,7 +96,6 @@ def init(self): self.log.debug("acq_window_off_cmd: %s" % self.acq_window_off_cmd) else: self.init_ok = True - @task def move_motors(self, motor_position_dict): HWR.beamline.diffractometer.wait_omega() @@ -339,21 +339,32 @@ def collect_std_collection(self, start_angle, stop_angle): :param stop_angle: The stop_angle parameter is the final angle at which the collection should stop """ + HWR.beamline.diffractometer.wait_omega() - self.omega_mv(start_angle, self.default_speed) - + start_pos = start_angle - self.turnback_time*self.acq_speed + stop_pos = stop_angle + self.turnback_time*self.acq_speed + + + self.log.debug("#COLLECT# Running OMEGA through the std acquisition") if start_angle <= stop_angle: - self.lower_bound_ch.set_value(start_angle) - self.upper_bound_ch.set_value(stop_angle) + self.lower_bound_ch.set_value(start_angle) + self.upper_bound_ch.set_value(stop_angle) + else: - self.lower_bound_ch.set_value(stop_angle) - self.upper_bound_ch.set_value(start_angle) - self.acq_arm_cmd() + self.lower_bound_ch.set_value(stop_angle) + self.upper_bound_ch.set_value(start_angle) - final_pos = stop_angle + self.acq_speed * self.turnback_time - self.omega_mv(final_pos, self.acq_speed) + self.omega_mv(start_pos, self.default_speed) + self.acq_arm_cmd() + self.omega_mv(stop_pos, self.acq_speed) + time.sleep(0.5) + self.acq_off_cmd() + self.acq_window_off_cmd() + self.omega_mv(stop_angle, self.acq_speed) + HWR.beamline.diffractometer.wait_omega() + def collect_characterisation( self, start_angle, img_range, nimages, angle_inc, exp_time @@ -374,7 +385,7 @@ def collect_characterisation( diffr = HWR.beamline.diffractometer - self.log.debug("#COLLECT# Running OMEGA through the char acquisition") + self.log.debug("#COLLECT# Running OMEGA through the characteristation acquisition") self.omega_mv(start_angle, self.default_speed) @@ -382,26 +393,36 @@ def collect_characterisation( print("collecting image %s" % img_no) start_at = start_angle + angle_inc * img_no stop_angle = start_at + img_range * 1.0 + #print("======= CHARACTERISATION Adding angle and range to the header...") + #Add start angle to the header + #detector = HWR.beamline.detector + #detector.set_eiger_start_angle(start_at) + + # Add angle increment to the header + #detector.set_eiger_angle_increment(angle_inc) + print("collecting image %s, angle %f" % (img_no, start_at)) if start_at >= stop_angle: - init_pos = start_at - self.acq_speed * self.turnback_time + init_pos = start_at #- self.acq_speed * self.turnback_time # init_pos = start_at - 1.5 else: - init_pos = start_at + self.acq_speed * self.turnback_time + init_pos = start_at #+ self.acq_speed * self.turnback_time # init_pos = start_at + 1.5 - self.omega_mv(init_pos, self.default_speed) - self.collect_std_collection(start_angle, stop_angle) - diffr.set_omega_velocity(self.default_speed) - self.acq_window_off_cmd() - self.acq_off_cmd() - self.log.debug( - "======= collect_characterisation Waiting =======================================" - ) + # self.omega_mv(init_pos, self.default_speed) + self.collect_std_collection(start_at, stop_angle) + + #This part goes to standard collection. Otherwise it produces phantom openings. + # diffr.set_omega_velocity(self.default_speed) + # self.acq_window_off_cmd() + # self.acq_off_cmd() + self.log.debug("======= collect_characterisation Waiting =======================================") - # Let adxv know whether it is + #Let adxv know whether it is # self.adxv_notify(self.latest_h5_filename,img_no+1) + + # time.sleep(1) def adxv_notify(self, image_filename, image_num=1): """ @@ -439,12 +460,17 @@ def acquisition_cleanup(self): try: diffr = HWR.beamline.diffractometer detector = HWR.beamline.detector - diffr.set_omega_velocity(self.default_speed) - self.acq_window_off_cmd() + detector.stop_acquisition() + diffr.wait_omega() + # ================= + #It is probably already finished in a standard collection. self.acq_off_cmd() + self.acq_window_off_cmd() + # ================== + diffr.set_omega_velocity(self.default_speed) self.log.debug("#COLLECT# Closing detector cover") diffr.detector_cover_close(wait=True) - detector.stop_acquisition() + except RuntimeError: self.log.error(traceback.format_exc()) From 94767660080189cb50c8066c6eac1f98f50fbb72 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 09:53:30 +0200 Subject: [PATCH 052/151] Force upgrade from the develop to avoid merging conflict --- mxcubecore/Command/Tango.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mxcubecore/Command/Tango.py b/mxcubecore/Command/Tango.py index 6f5c98f84f..96e998e14e 100644 --- a/mxcubecore/Command/Tango.py +++ b/mxcubecore/Command/Tango.py @@ -21,7 +21,6 @@ import logging import gevent import gevent.event -import numpy as np try: import Queue as queue @@ -320,7 +319,7 @@ def get_info(self): self._device_initialized.wait(timeout=3) return self.device.get_attribute_config(self.attribute_name) - + def update(self, value=Poller.NotInitializedValue): # start with checking if we have a numpy array, as comparing # numpy.ndarray to Poller.NotInitializedValue raises a ValueError exception @@ -334,7 +333,6 @@ def get_info(self): self.value = value self.emit("update", value) - def get_value(self): if self.read_as_str: value = self.device.read_attribute( From 77fe44730c9793c2dc8865d0a0dfd545ee383706 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 10:34:20 +0200 Subject: [PATCH 053/151] Added missing warnings module --- mxcubecore/HardwareObjects/ISPyBClient.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mxcubecore/HardwareObjects/ISPyBClient.py b/mxcubecore/HardwareObjects/ISPyBClient.py index 34797ad402..56475e92bb 100644 --- a/mxcubecore/HardwareObjects/ISPyBClient.py +++ b/mxcubecore/HardwareObjects/ISPyBClient.py @@ -8,6 +8,7 @@ from pprint import pformat from collections import namedtuple from datetime import datetime +import warnings try: from urlparse import urljoin From b7c2e645d34cf7a5bc88b7b720e710d2dfb7a3bf Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 11:20:37 +0200 Subject: [PATCH 054/151] Enabled back explicit check on if beamtimeid is open --- mxcubecore/HardwareObjects/DESY/P11Session.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Session.py b/mxcubecore/HardwareObjects/DESY/P11Session.py index fc959c288a..2e00a81615 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Session.py +++ b/mxcubecore/HardwareObjects/DESY/P11Session.py @@ -85,8 +85,7 @@ def info_set_defaults(self): self.beamtime_info["rootPath"] = PATH_FALLBACK def is_beamtime_open(self): - return True - # return self.is_writable_dir( os.path.join(PATH_BEAMTIME, self.raw_data_folder_name) ) + return self.is_writable_dir( os.path.join(PATH_BEAMTIME, self.raw_data_folder_name) ) def is_commissioning_open(self): return self.is_writable_dir( From 47c6c2c9d2743baa26620dc0341bf7c1b26e2e9d Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 11:29:10 +0200 Subject: [PATCH 055/151] Added debug info in case beamtime ID is not opened --- mxcubecore/HardwareObjects/DESY/P11Session.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mxcubecore/HardwareObjects/DESY/P11Session.py b/mxcubecore/HardwareObjects/DESY/P11Session.py index 2e00a81615..4e1abb1f16 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Session.py +++ b/mxcubecore/HardwareObjects/DESY/P11Session.py @@ -85,6 +85,12 @@ def info_set_defaults(self): self.beamtime_info["rootPath"] = PATH_FALLBACK def is_beamtime_open(self): + self.log.debug("=========== CHECKING IF BEAMTIME ID IS OPEN... ============") + if self.is_writable_dir(os.path.join(PATH_BEAMTIME, self.raw_data_folder_name)): + self.log.debug("=========== BEAMTIME IS OPEN (/gpfs/current exists) ============") + else: + self.log.debug("=========== NO BEMTIME ID IS OPEN (check /gpfs/current) ============") + return self.is_writable_dir( os.path.join(PATH_BEAMTIME, self.raw_data_folder_name) ) def is_commissioning_open(self): From 0177daf821f69e3fba1d244d7cb97c7bf66a7208 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 16:58:08 +0200 Subject: [PATCH 056/151] Added beamtime info as a property --- mxcubecore/HardwareObjects/DESY/P11Session.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mxcubecore/HardwareObjects/DESY/P11Session.py b/mxcubecore/HardwareObjects/DESY/P11Session.py index 4e1abb1f16..f2fdfce8b0 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Session.py +++ b/mxcubecore/HardwareObjects/DESY/P11Session.py @@ -116,6 +116,9 @@ def get_current_proposal_number(self): info = self.get_beamtime_info() return info["proposalId"] + def get_beamtime_info(self): + return self.beamtime_info + def read_beamtime_info(self): self.log.debug("=========== READING BEAMTIME INFO ============") if os.path.exists(PATH_BEAMTIME): From cf28f6c82695dd7b4af6af6a2e1a882ebe03606c Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 16:59:56 +0200 Subject: [PATCH 057/151] Added additional debug messages for shutter --- mxcubecore/HardwareObjects/DESY/P11Shutter.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mxcubecore/HardwareObjects/DESY/P11Shutter.py b/mxcubecore/HardwareObjects/DESY/P11Shutter.py index 3a147822dc..1fe79adaed 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Shutter.py +++ b/mxcubecore/HardwareObjects/DESY/P11Shutter.py @@ -133,9 +133,12 @@ def update_shutter_state(self, state=None): if state is None: state = self.chan_state.get_value() + self.log.debug(" SHUTTER state changed") if state[0] == 3: + self.log.debug(" P11SHUTTER IS OPEN") value = self.VALUES.OPEN else: + self.log.debug(" P11SHUTTER IS CLOSED") value = self.VALUES.CLOSED # else: @@ -146,6 +149,7 @@ def update_shutter_state(self, state=None): self.update_value(value) + self.log.debug(" update shutter state done") return value def simulated_update(self): From 1e6232099e7810d736df3d775039243313b319d7 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 17:01:42 +0200 Subject: [PATCH 058/151] Fixed get_properties naming (Bixente) --- mxcubecore/HardwareObjects/MotorsNPosition.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/MotorsNPosition.py b/mxcubecore/HardwareObjects/MotorsNPosition.py index c28ab9f24d..286826be3d 100644 --- a/mxcubecore/HardwareObjects/MotorsNPosition.py +++ b/mxcubecore/HardwareObjects/MotorsNPosition.py @@ -121,7 +121,7 @@ def load_positions(self): def get_position_list(self): return list(self._positions.keys()) - def get_properties_(self, position_index, property_name): + def get_properties(self, position_index, property_name): """ returns property with name property_name for position_index if position_index is None returns OrderedDict with property_name for all positions From dd41e292e160fa787f7f286d1312e227c2b622cc Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 17:04:04 +0200 Subject: [PATCH 059/151] Removed faulty login_type=user fot P11 --- mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py b/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py index d1f259cb7a..3a6e24119e 100644 --- a/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py +++ b/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py @@ -26,8 +26,6 @@ def init(self): "PROPOSAL NUMBER is %s" % self.simulated_prop_number ) - self.loginType = "user" - def update_data_collection(self, mx_collection, wait=False): mx_collection["beamline_name"] = "P11" ISPyBClient.update_data_collection(self, mx_collection, wait) From b7e7294c45c9cd47494a4453550d653930de20b6 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 17:06:43 +0200 Subject: [PATCH 060/151] Removed is_open() as a function and assigned is_closed() as a property for shutter-like objects inside P11 HO (Bixente) --- mxcubecore/HardwareObjects/DESY/P11DetectorCover.py | 8 +------- mxcubecore/HardwareObjects/DESY/P11FastShutter.py | 2 ++ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py index e246d7646b..1f1e208f20 100644 --- a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py +++ b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py @@ -197,13 +197,7 @@ def simulated_update(self): self.update_value(value) return value - def is_open(self): - """Check if the shutter is open. - Returns: - (bool): True if open, False otherwise. - """ - return self.get_value() == self.VALUES.OPEN - + @property def is_closed(self): """Check if the shutter is closed. Returns: diff --git a/mxcubecore/HardwareObjects/DESY/P11FastShutter.py b/mxcubecore/HardwareObjects/DESY/P11FastShutter.py index 4b4ae4c6e5..ebe924a395 100644 --- a/mxcubecore/HardwareObjects/DESY/P11FastShutter.py +++ b/mxcubecore/HardwareObjects/DESY/P11FastShutter.py @@ -67,9 +67,11 @@ def init(self): def get_value(self): return self.update_fast_shutter() + @property def is_open(self): return self.get_value() == self.VALUES.OPEN + @property def is_closed(self): return self.get_value() == self.VALUES.CLOSED From abb9df84cc2d8af4e2fe9182bafafd7fd4c1df8b Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 17:07:35 +0200 Subject: [PATCH 061/151] Added is_open as a property inside P11NanoDiff (Bixente) --- mxcubecore/HardwareObjects/DESY/P11NanoDiff.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py b/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py index e327c48faa..10fe34b321 100644 --- a/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py +++ b/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py @@ -737,9 +737,9 @@ def detector_cover_close(self, wait=True): def wait_detcover(self, state, timeout=60): start_time = time.time() while time.time() - start_time > timeout: - if state == "open" and self.detcover_hwobj.is_open(): + if state == "open" and self.detcover_hwobj.is_open: break - elif state == "close" and self.detcover_hwobj.is_closed(): + elif state == "close" and self.detcover_hwobj.is_closed: break gevent.sleep(0.5) @@ -802,8 +802,8 @@ def update_phase(self, value=None): omega_pos = self.get_omega_position() - cover_open = self.detcover_hwobj.is_open() - cover_closed = self.detcover_hwobj.is_closed() + cover_open = self.detcover_hwobj.is_open + cover_closed = self.detcover_hwobj.is_closed blight_in = self.backlight_hwobj.is_in() blight_out = self.backlight_hwobj.is_out() collim = self.collimator_hwobj.get_position() From b3c2ec3f246e707be21fdb32f780de8e0e4de7a1 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 17:26:57 +0200 Subject: [PATCH 062/151] Fixed other get_properties typos which were preventing loading --- mxcubecore/HardwareObjects/MotorsNPosition.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/MotorsNPosition.py b/mxcubecore/HardwareObjects/MotorsNPosition.py index 286826be3d..ab28f896e8 100644 --- a/mxcubecore/HardwareObjects/MotorsNPosition.py +++ b/mxcubecore/HardwareObjects/MotorsNPosition.py @@ -161,7 +161,7 @@ def set_position(self, posname): posidx = -1 for name in self._positions: posidx += 1 - if posname == self.get_properties_(posidx, "posname"): + if posname == self.get_properties(posidx, "posname"): self._set_value(posidx) return From 33b70bfad00b29fc7a5a0d27ab9af5c453c896e4 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Thu, 5 Oct 2023 15:35:55 +0200 Subject: [PATCH 063/151] Fixed shutter openning wainting forever (Bixente) --- mxcubecore/HardwareObjects/DESY/P11Shutter.py | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Shutter.py b/mxcubecore/HardwareObjects/DESY/P11Shutter.py index 1fe79adaed..8202549f10 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Shutter.py +++ b/mxcubecore/HardwareObjects/DESY/P11Shutter.py @@ -22,6 +22,7 @@ import gevent import urllib from mxcubecore.HardwareObjects.abstract.AbstractShutter import AbstractShutter +import mxcubecore.HardwareObjects.abstract.AbstractShutter as absshut from mxcubecore.BaseHardwareObjects import HardwareObjectState from enum import Enum, unique @@ -85,6 +86,8 @@ def init(self): else: self.simulated_update() + self.update_state(self.STATES.READY) + super(AbstractShutter, self).init() def get_value(self): @@ -105,25 +108,39 @@ def _set_value(self, value): if self.simulation: self.simulated_opened = open_it self.simulated_moving = True - gevent.spawn(self.simul_do) + self.t1 = gevent.spawn(self.simul_do) + self.t1.link(self.do_finish) + self.t1.link_exception(self.do_finish_exc) else: if open_it: self.do_open() else: self.do_close() self.cmd_started = time.time() + self.log.debug(" ### setting value value for shutter done") def do_open(self, timeout=3): + self.log.debug(" OPENING SHUTTER (web request)") result = urllib.request.urlopen(self.url_open, None, timeout).readlines() + self.log.debug(" OPENING SHUTTER (web request) retured") def do_close(self, timeout=3): + self.log.debug(" CLOSING SHUTTER (web request)") result = urllib.request.urlopen(self.url_close, None, timeout).readlines() + self.log.debug(" CLOSING SHUTTER (web request) retured") def simul_do(self): + self.log.debug("### starting simulated shutter move") gevent.sleep(1) self.simulated_moving = False self.log.debug("### updating simulated shutter") self.simulated_update() + self.log.debug("### ending simulated shutter move") + + def do_finish(self, t=None): + self.log.debug("### simulated finished") + def do_finish_exc(self, exc=None): + self.log.debug("### simulated finished with exception") def update_shutter_state(self, state=None): """Updates shutter state @@ -134,6 +151,7 @@ def update_shutter_state(self, state=None): state = self.chan_state.get_value() self.log.debug(" SHUTTER state changed") + if state[0] == 3: self.log.debug(" P11SHUTTER IS OPEN") value = self.VALUES.OPEN From 3b56eafa80061a2760d2052f861accb8569e9d05 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Fri, 6 Oct 2023 17:32:07 +0200 Subject: [PATCH 064/151] Added preliminary flux HO for P11 --- mxcubecore/HardwareObjects/DESY/P11Flux.py | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 mxcubecore/HardwareObjects/DESY/P11Flux.py diff --git a/mxcubecore/HardwareObjects/DESY/P11Flux.py b/mxcubecore/HardwareObjects/DESY/P11Flux.py new file mode 100644 index 0000000000..ae64c4ca83 --- /dev/null +++ b/mxcubecore/HardwareObjects/DESY/P11Flux.py @@ -0,0 +1,72 @@ +# +# Project: MXCuBE +# https://github.com/mxcube +# +# This file is part of MXCuBE software. +# +# MXCuBE is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# MXCuBE is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with MXCuBE. If not, see . + +from random import random +from mxcubecore.HardwareObjects.abstract.AbstractFlux import AbstractFlux + +from mxcubecore import HardwareRepository as HWR + +__credits__ = ["MXCuBE collaboration"] +__category__ = "General" + + +class P11Flux(AbstractFlux): + + # default_flux - for initialising mockup + default_flux = 5e12 + + def __init__(self, name): + AbstractFlux.__init__(self, name) + + self.measured_flux_list = [] + self.measured_flux_dict = {} + self.current_flux_dict = {} + + def init(self): + + self.measure_flux() + + def get_value(self): + """Get flux at current transmission in units of photons/s""" + + """ FLUX IS CHEETED HERE - NOWERE ELSE!""" + return self.current_flux_dict["flux"] + + def measure_flux(self): + """Measures intesity""" + beam_size = HWR.beamline.beam.get_beam_size() + transmission = HWR.beamline.transmission.get_value() + flux = self.default_flux * (1 + random()) + + self.measured_flux_list = [ + { + "size_x": beam_size[0], + "size_y": beam_size[1], + "transmission": transmission, + "flux": flux, + } + ] + + self.measured_flux_dict = self.measured_flux_list[0] + self.current_flux_dict = self.measured_flux_list[0] + + self.emit( + "fluxInfoChanged", + {"measured": self.measured_flux_dict, "current": self.current_flux_dict}, + ) From 07a6e6ac3b95123983ce1d38995f598087c1bbac Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Fri, 6 Oct 2023 19:18:03 +0200 Subject: [PATCH 065/151] Upgraded the characterisation part for P11 using EDNA --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 68 ++++++++++--------- .../DESY/P11EDNACharacterisation.py | 33 ++++++++- 2 files changed, 68 insertions(+), 33 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index c2f1b2e9d9..0912c90293 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -126,6 +126,7 @@ def data_collection_hook(self): self.diffr = HWR.beamline.diffractometer detector = HWR.beamline.detector + dc_pars = self.current_dc_parameters collection_type = dc_pars["experiment_type"] @@ -199,8 +200,12 @@ def data_collection_hook(self): ) # Filepath to the EDNA processing - # filepath = os.path.join(basepath,"%s_%d" % (prefix, runno)) + #filepath = os.path.join(basepath,"%s_%d" % (prefix, runno)) + + #setting up xds_dir for characterisation (used there internally to create dirs) + self.current_dc_parameters["xds_dir"] = os.path.join(basepath,"%s_%d" % (prefix, runno)) + self.log.debug( "======= CURRENT FILEPATH: " + str(filepath) @@ -282,23 +287,24 @@ def data_collection_hook(self): # os.system("/opt/dectris/albula/4.0/bin/albula "+self.latest_h5_filename +" &") # os.system("adxv "+self.latest_h5_filename +" &") + #TODO: Remove for now creation of the snapshots and processing html. # Open index_html - os.system("firefox /gpfs/current/processed/index.html") + #os.system("firefox /gpfs/current/processed/index.html") # Create diffraction snapshots - for i in range(nframes): - os.system( - "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " - + self.latest_h5_filename - + " --output " - + os.path.join( - basepath, prefix, "screening_" + str(runno).zfill(3) - ) - + "/" - + " --image_number " - + str(i + 1) - ) - +# for i in range(nframes): +# os.system( +# "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " +# + self.latest_h5_filename +# + " --output " +# + os.path.join( +# basepath, prefix, "screening_" + str(runno).zfill(3) +# ) +# + "/" +# + " --image_number " +# + str(i + 1) +# ) +# else: self.collect_std_collection(start_angle, stop_angle) self.generate_xds_template() @@ -307,21 +313,21 @@ def data_collection_hook(self): # os.system("killall albula") # os.system("/opt/dectris/albula/4.0/bin/albula "+self.latest_h5_filename +" &") - # Open index_html - os.system("firefox /gpfs/current/processed/index.html") - - # Create diffraction snapshots - os.system( - "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " - + self.latest_h5_filename - + " --output " - + os.path.join( - basepath, prefix, "rotational_" + str(runno).zfill(3) - ) - + "/" - + " --image_number 1" - ) - +# # Open index_html +# os.system("firefox /gpfs/current/processed/index.html") +# +# # Create diffraction snapshots +# os.system( +# "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " +# + self.latest_h5_filename +# + " --output " +# + os.path.join( +# basepath, prefix, "rotational_" + str(runno).zfill(3) +# ) +# + "/" +# + " --image_number 1" +# ) +# except RuntimeError: self.log.error(traceback.format_exc()) finally: @@ -535,7 +541,7 @@ def add_h5_info(self, h5file): del h5fd[node] h5fd.close() - except RuntimeError as err_msg: + except RuntimeWarning as err_msg: self.log.debug("Error while adding info to HDF5 file (%s)" % str(err_msg)) self.log.debug(traceback.format_exc()) diff --git a/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py b/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py index 7e0eb6c775..28f3399e25 100644 --- a/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py +++ b/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py @@ -47,6 +47,26 @@ def __init__(self, name): self.edna_default_file = None self.start_edna_command = None + def _run_edna(self, input_file, results_file, process_directory): + """Starts EDNA""" + msg = "Starting EDNA characterisation using xml file %s" % input_file + logging.getLogger("queue_exec").info(msg) + + args = (self.start_edna_command, input_file, results_file, process_directory) + # subprocess.call("%s %s %s %s" % args, shell=True) + + # Test run DESY + self.edna_maxwell(process_directory,input_file, results_file) + + + + self.result = None + if os.path.exists(results_file): + self.result = XSDataResultMXCuBE.parseFile(results_file) + + return self.result + + def edna_maxwell(self, process_directory, inputxml, outputxml): """ The function `edna_maxwell` is used to execute a command on a remote cluster using SSH and SBATCH. @@ -105,6 +125,8 @@ def edna_maxwell(self, process_directory, inputxml, outputxml): ) ) + print('{ssh:s} "{sbatch:s} --wrap \\"{cmd:s}"\\"'.format(ssh=ssh, sbatch=sbatch, cmd=cmd)) + os.system( '{ssh:s} "{sbatch:s} --wrap \\"{cmd:s}"\\"'.format( ssh=ssh, sbatch=sbatch, cmd=cmd @@ -235,16 +257,23 @@ def input_from_params(self, data_collection, char_params): data_set = XSDataMXCuBEDataSet() acquisition_parameters = data_collection.acquisitions[0].acquisition_parameters path_template = data_collection.acquisitions[0].path_template - + + #Make sure there is a proper path conversion between different mount points + print("======= Characterisation path template ====", path_template.directory) #/gpfs/current/raw + image_dir = path_template.directory.replace( "/gpfs/current", triggerUtils.get_beamtime_metadata()[2] ) - path_str = os.path.join(image_dir, path_template.get_image_file_name()) + print(image_dir) + path_str = os.path.join(image_dir, path_template.get_image_file_name()) + print(path_template.xds_dir) + characterisation_dir = path_template.xds_dir.replace( "/autoprocessing_", "/characterisation_" ) + os.makedirs(characterisation_dir, mode=0o755, exist_ok=True) for img_num in range(int(acquisition_parameters.num_images)): From 69f77348a5e71551564fd084223956e3df6f91b5 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Fri, 6 Oct 2023 22:57:55 +0200 Subject: [PATCH 066/151] Linting --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 142 +++++++++--------- .../HardwareObjects/DESY/P11DetectorCover.py | 17 ++- .../DESY/P11EDNACharacterisation.py | 27 ++-- mxcubecore/HardwareObjects/DESY/P11Flux.py | 2 +- mxcubecore/HardwareObjects/DESY/P11Session.py | 14 +- mxcubecore/HardwareObjects/DESY/P11Shutter.py | 20 +-- 6 files changed, 119 insertions(+), 103 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index 0912c90293..b13044b47e 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -56,23 +56,21 @@ class P11Collect(AbstractCollect): - def __init__(self, *args): super(P11Collect, self).__init__(*args) def init(self): - super(P11Collect,self).init() + super(P11Collect, self).init() # os.system("/opt/xray/bin/adxv -socket -colors Gray -rings &") # os.system("/bin/bash /gpfs/local/shared/MXCuBE/STRELA/start_viewer_zmq.sh") - self.default_speed = self.get_property("omega_default_speed", 130) self.turnback_time = self.get_property("turnback_time", 0.3) - self.filter_server_name = self.get_property('filterserver') - self.mono_server_name = self.get_property('monoserver') + self.filter_server_name = self.get_property("filterserver") + self.mono_server_name = self.get_property("monoserver") self.filter_server = DeviceProxy(self.filter_server_name) self.mono_server = DeviceProxy(self.mono_server_name) @@ -84,9 +82,14 @@ def init(self): self.acq_off_cmd = self.get_command_object("acq_off") self.acq_window_off_cmd = self.get_command_object("acq_window_off") - if None in [self.lower_bound_ch, self.upper_bound_ch, - self.acq_arm_cmd, self.acq_on_cmd, self.acq_off_cmd, - self.acq_window_off_cmd]: + if None in [ + self.lower_bound_ch, + self.upper_bound_ch, + self.acq_arm_cmd, + self.acq_on_cmd, + self.acq_off_cmd, + self.acq_window_off_cmd, + ]: self.init_ok = False self.log.debug("lower_bound_ch: %s" % self.lower_bound_ch) self.log.debug("upper_bound_ch: %s" % self.upper_bound_ch) @@ -96,6 +99,7 @@ def init(self): self.log.debug("acq_window_off_cmd: %s" % self.acq_window_off_cmd) else: self.init_ok = True + @task def move_motors(self, motor_position_dict): HWR.beamline.diffractometer.wait_omega() @@ -126,7 +130,6 @@ def data_collection_hook(self): self.diffr = HWR.beamline.diffractometer detector = HWR.beamline.detector - dc_pars = self.current_dc_parameters collection_type = dc_pars["experiment_type"] @@ -200,12 +203,13 @@ def data_collection_hook(self): ) # Filepath to the EDNA processing - #filepath = os.path.join(basepath,"%s_%d" % (prefix, runno)) + # filepath = os.path.join(basepath,"%s_%d" % (prefix, runno)) + + # setting up xds_dir for characterisation (used there internally to create dirs) + self.current_dc_parameters["xds_dir"] = os.path.join( + basepath, "%s_%d" % (prefix, runno) + ) - - #setting up xds_dir for characterisation (used there internally to create dirs) - self.current_dc_parameters["xds_dir"] = os.path.join(basepath,"%s_%d" % (prefix, runno)) - self.log.debug( "======= CURRENT FILEPATH: " + str(filepath) @@ -287,24 +291,24 @@ def data_collection_hook(self): # os.system("/opt/dectris/albula/4.0/bin/albula "+self.latest_h5_filename +" &") # os.system("adxv "+self.latest_h5_filename +" &") - #TODO: Remove for now creation of the snapshots and processing html. + # TODO: Remove for now creation of the snapshots and processing html. # Open index_html - #os.system("firefox /gpfs/current/processed/index.html") + # os.system("firefox /gpfs/current/processed/index.html") # Create diffraction snapshots -# for i in range(nframes): -# os.system( -# "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " -# + self.latest_h5_filename -# + " --output " -# + os.path.join( -# basepath, prefix, "screening_" + str(runno).zfill(3) -# ) -# + "/" -# + " --image_number " -# + str(i + 1) -# ) -# + # for i in range(nframes): + # os.system( + # "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " + # + self.latest_h5_filename + # + " --output " + # + os.path.join( + # basepath, prefix, "screening_" + str(runno).zfill(3) + # ) + # + "/" + # + " --image_number " + # + str(i + 1) + # ) + # else: self.collect_std_collection(start_angle, stop_angle) self.generate_xds_template() @@ -313,21 +317,21 @@ def data_collection_hook(self): # os.system("killall albula") # os.system("/opt/dectris/albula/4.0/bin/albula "+self.latest_h5_filename +" &") -# # Open index_html -# os.system("firefox /gpfs/current/processed/index.html") -# -# # Create diffraction snapshots -# os.system( -# "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " -# + self.latest_h5_filename -# + " --output " -# + os.path.join( -# basepath, prefix, "rotational_" + str(runno).zfill(3) -# ) -# + "/" -# + " --image_number 1" -# ) -# + # # Open index_html + # os.system("firefox /gpfs/current/processed/index.html") + # + # # Create diffraction snapshots + # os.system( + # "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " + # + self.latest_h5_filename + # + " --output " + # + os.path.join( + # basepath, prefix, "rotational_" + str(runno).zfill(3) + # ) + # + "/" + # + " --image_number 1" + # ) + # except RuntimeError: self.log.error(traceback.format_exc()) finally: @@ -347,20 +351,17 @@ def collect_std_collection(self, start_angle, stop_angle): """ HWR.beamline.diffractometer.wait_omega() - start_pos = start_angle - self.turnback_time*self.acq_speed - stop_pos = stop_angle + self.turnback_time*self.acq_speed - - - + start_pos = start_angle - self.turnback_time * self.acq_speed + stop_pos = stop_angle + self.turnback_time * self.acq_speed + self.log.debug("#COLLECT# Running OMEGA through the std acquisition") if start_angle <= stop_angle: - self.lower_bound_ch.set_value(start_angle) - self.upper_bound_ch.set_value(stop_angle) + self.lower_bound_ch.set_value(start_angle) + self.upper_bound_ch.set_value(stop_angle) else: - self.lower_bound_ch.set_value(stop_angle) - self.upper_bound_ch.set_value(start_angle) - + self.lower_bound_ch.set_value(stop_angle) + self.upper_bound_ch.set_value(start_angle) self.omega_mv(start_pos, self.default_speed) self.acq_arm_cmd() @@ -371,7 +372,6 @@ def collect_std_collection(self, start_angle, stop_angle): self.omega_mv(stop_angle, self.acq_speed) HWR.beamline.diffractometer.wait_omega() - def collect_characterisation( self, start_angle, img_range, nimages, angle_inc, exp_time ): @@ -391,7 +391,9 @@ def collect_characterisation( diffr = HWR.beamline.diffractometer - self.log.debug("#COLLECT# Running OMEGA through the characteristation acquisition") + self.log.debug( + "#COLLECT# Running OMEGA through the characteristation acquisition" + ) self.omega_mv(start_angle, self.default_speed) @@ -399,35 +401,37 @@ def collect_characterisation( print("collecting image %s" % img_no) start_at = start_angle + angle_inc * img_no stop_angle = start_at + img_range * 1.0 - #print("======= CHARACTERISATION Adding angle and range to the header...") - #Add start angle to the header - #detector = HWR.beamline.detector - #detector.set_eiger_start_angle(start_at) + # print("======= CHARACTERISATION Adding angle and range to the header...") + # Add start angle to the header + # detector = HWR.beamline.detector + # detector.set_eiger_start_angle(start_at) # Add angle increment to the header - #detector.set_eiger_angle_increment(angle_inc) + # detector.set_eiger_angle_increment(angle_inc) print("collecting image %s, angle %f" % (img_no, start_at)) if start_at >= stop_angle: - init_pos = start_at #- self.acq_speed * self.turnback_time + init_pos = start_at # - self.acq_speed * self.turnback_time # init_pos = start_at - 1.5 else: - init_pos = start_at #+ self.acq_speed * self.turnback_time + init_pos = start_at # + self.acq_speed * self.turnback_time # init_pos = start_at + 1.5 # self.omega_mv(init_pos, self.default_speed) self.collect_std_collection(start_at, stop_angle) - #This part goes to standard collection. Otherwise it produces phantom openings. + # This part goes to standard collection. Otherwise it produces phantom openings. # diffr.set_omega_velocity(self.default_speed) # self.acq_window_off_cmd() # self.acq_off_cmd() - self.log.debug("======= collect_characterisation Waiting =======================================") + self.log.debug( + "======= collect_characterisation Waiting =======================================" + ) - #Let adxv know whether it is + # Let adxv know whether it is # self.adxv_notify(self.latest_h5_filename,img_no+1) - + # time.sleep(1) def adxv_notify(self, image_filename, image_num=1): @@ -469,14 +473,14 @@ def acquisition_cleanup(self): detector.stop_acquisition() diffr.wait_omega() # ================= - #It is probably already finished in a standard collection. + # It is probably already finished in a standard collection. self.acq_off_cmd() self.acq_window_off_cmd() # ================== diffr.set_omega_velocity(self.default_speed) self.log.debug("#COLLECT# Closing detector cover") diffr.detector_cover_close(wait=True) - + except RuntimeError: self.log.error(traceback.format_exc()) diff --git a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py index 1f1e208f20..ec9c9e480e 100644 --- a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py +++ b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py @@ -44,13 +44,14 @@ class P11DetectorCover(AbstractShutter): @unique class BaseValueEnum(Enum): - """Defines only the compulsory values.""" - OPEN = "OPEN" - CLOSED = "CLOSED" - MOVING = "MOVING" - UNKNOWN = "UNKNOWN" - - VALUES=BaseValueEnum + """Defines only the compulsory values.""" + + OPEN = "OPEN" + CLOSED = "CLOSED" + MOVING = "MOVING" + UNKNOWN = "UNKNOWN" + + VALUES = BaseValueEnum def __init__(self, name): @@ -196,7 +197,7 @@ def simulated_update(self): self.update_value(value) return value - + @property def is_closed(self): """Check if the shutter is closed. diff --git a/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py b/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py index 28f3399e25..058ddc6784 100644 --- a/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py +++ b/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py @@ -56,17 +56,14 @@ def _run_edna(self, input_file, results_file, process_directory): # subprocess.call("%s %s %s %s" % args, shell=True) # Test run DESY - self.edna_maxwell(process_directory,input_file, results_file) - - + self.edna_maxwell(process_directory, input_file, results_file) self.result = None if os.path.exists(results_file): self.result = XSDataResultMXCuBE.parseFile(results_file) return self.result - - + def edna_maxwell(self, process_directory, inputxml, outputxml): """ The function `edna_maxwell` is used to execute a command on a remote cluster using SSH and SBATCH. @@ -125,7 +122,11 @@ def edna_maxwell(self, process_directory, inputxml, outputxml): ) ) - print('{ssh:s} "{sbatch:s} --wrap \\"{cmd:s}"\\"'.format(ssh=ssh, sbatch=sbatch, cmd=cmd)) + print( + '{ssh:s} "{sbatch:s} --wrap \\"{cmd:s}"\\"'.format( + ssh=ssh, sbatch=sbatch, cmd=cmd + ) + ) os.system( '{ssh:s} "{sbatch:s} --wrap \\"{cmd:s}"\\"'.format( @@ -257,10 +258,12 @@ def input_from_params(self, data_collection, char_params): data_set = XSDataMXCuBEDataSet() acquisition_parameters = data_collection.acquisitions[0].acquisition_parameters path_template = data_collection.acquisitions[0].path_template - - #Make sure there is a proper path conversion between different mount points - print("======= Characterisation path template ====", path_template.directory) #/gpfs/current/raw - + + # Make sure there is a proper path conversion between different mount points + print( + "======= Characterisation path template ====", path_template.directory + ) # /gpfs/current/raw + image_dir = path_template.directory.replace( "/gpfs/current", triggerUtils.get_beamtime_metadata()[2] ) @@ -269,11 +272,11 @@ def input_from_params(self, data_collection, char_params): path_str = os.path.join(image_dir, path_template.get_image_file_name()) print(path_template.xds_dir) - + characterisation_dir = path_template.xds_dir.replace( "/autoprocessing_", "/characterisation_" ) - + os.makedirs(characterisation_dir, mode=0o755, exist_ok=True) for img_num in range(int(acquisition_parameters.num_images)): diff --git a/mxcubecore/HardwareObjects/DESY/P11Flux.py b/mxcubecore/HardwareObjects/DESY/P11Flux.py index ae64c4ca83..d1475ab6f4 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Flux.py +++ b/mxcubecore/HardwareObjects/DESY/P11Flux.py @@ -44,7 +44,7 @@ def init(self): def get_value(self): """Get flux at current transmission in units of photons/s""" - + """ FLUX IS CHEETED HERE - NOWERE ELSE!""" return self.current_flux_dict["flux"] diff --git a/mxcubecore/HardwareObjects/DESY/P11Session.py b/mxcubecore/HardwareObjects/DESY/P11Session.py index f2fdfce8b0..05fecad4d8 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Session.py +++ b/mxcubecore/HardwareObjects/DESY/P11Session.py @@ -87,11 +87,17 @@ def info_set_defaults(self): def is_beamtime_open(self): self.log.debug("=========== CHECKING IF BEAMTIME ID IS OPEN... ============") if self.is_writable_dir(os.path.join(PATH_BEAMTIME, self.raw_data_folder_name)): - self.log.debug("=========== BEAMTIME IS OPEN (/gpfs/current exists) ============") + self.log.debug( + "=========== BEAMTIME IS OPEN (/gpfs/current exists) ============" + ) else: - self.log.debug("=========== NO BEMTIME ID IS OPEN (check /gpfs/current) ============") - - return self.is_writable_dir( os.path.join(PATH_BEAMTIME, self.raw_data_folder_name) ) + self.log.debug( + "=========== NO BEMTIME ID IS OPEN (check /gpfs/current) ============" + ) + + return self.is_writable_dir( + os.path.join(PATH_BEAMTIME, self.raw_data_folder_name) + ) def is_commissioning_open(self): return self.is_writable_dir( diff --git a/mxcubecore/HardwareObjects/DESY/P11Shutter.py b/mxcubecore/HardwareObjects/DESY/P11Shutter.py index 8202549f10..90e81aec28 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Shutter.py +++ b/mxcubecore/HardwareObjects/DESY/P11Shutter.py @@ -41,13 +41,14 @@ class P11Shutter(AbstractShutter): @unique class BaseValueEnum(Enum): - """Defines only the compulsory values.""" - OPEN = "OPEN" - CLOSED = "CLOSED" - MOVING = "MOVING" - UNKNOWN = "UNKNOWN" - - VALUES=BaseValueEnum + """Defines only the compulsory values.""" + + OPEN = "OPEN" + CLOSED = "CLOSED" + MOVING = "MOVING" + UNKNOWN = "UNKNOWN" + + VALUES = BaseValueEnum def __init__(self, name): @@ -109,8 +110,8 @@ def _set_value(self, value): self.simulated_opened = open_it self.simulated_moving = True self.t1 = gevent.spawn(self.simul_do) - self.t1.link(self.do_finish) - self.t1.link_exception(self.do_finish_exc) + self.t1.link(self.do_finish) + self.t1.link_exception(self.do_finish_exc) else: if open_it: self.do_open() @@ -139,6 +140,7 @@ def simul_do(self): def do_finish(self, t=None): self.log.debug("### simulated finished") + def do_finish_exc(self, exc=None): self.log.debug("### simulated finished with exception") From 72d19665231b45d8bb40d1d4a4cafdf0fcddbd44 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Tue, 17 Oct 2023 16:25:29 +0200 Subject: [PATCH 067/151] Add empty store_robot_action for P11 (temp fix due to ISPyB tests). --- mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py b/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py index 3a6e24119e..3225c34dda 100644 --- a/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py +++ b/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py @@ -38,6 +38,10 @@ def store_image(self, image_dict): self.prepare_image_for_lims(image_dict) return ISPyBClient.store_image(self, image_dict) + def store_robot_action(self, robot_action_dict): + #TODO ISPyB is not ready for now. This prevents from error 500 from the server. + pass + def prepare_collect_for_lims(self, mx_collect_dict): # Attention! directory passed by reference. modified in place From 518f517af4b5215e4fac0a39ecc3976b1439d154 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 25 Oct 2023 14:34:51 +0200 Subject: [PATCH 068/151] Fix in AbstractSampleChanger that was causing sample not loaded error at P11 even if everything was ok (Bixente). --- mxcubecore/HardwareObjects/DESY/P11SampleChanger.py | 2 ++ .../HardwareObjects/abstract/AbstractSampleChanger.py | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11SampleChanger.py b/mxcubecore/HardwareObjects/DESY/P11SampleChanger.py index 2ec48d57ab..5afe2710f6 100644 --- a/mxcubecore/HardwareObjects/DESY/P11SampleChanger.py +++ b/mxcubecore/HardwareObjects/DESY/P11SampleChanger.py @@ -205,6 +205,7 @@ def load(self, sample=None, wait=True): "Sample changer: Sample loaded (total time: %s)" % (time.time() - self._start_load) ) + self.emit("progressStop", ()) return self.get_loaded_sample() @@ -476,6 +477,7 @@ def _update_selection(self): # find sample for s in self.get_sample_list(): + print(f"Sample coords = {s.get_coords()}") if s.get_coords() == (basket, sample): self.log.debug(" - sample found") self._set_loaded_sample(s) diff --git a/mxcubecore/HardwareObjects/abstract/AbstractSampleChanger.py b/mxcubecore/HardwareObjects/abstract/AbstractSampleChanger.py index 3d579431ea..b8c26edaf0 100644 --- a/mxcubecore/HardwareObjects/abstract/AbstractSampleChanger.py +++ b/mxcubecore/HardwareObjects/abstract/AbstractSampleChanger.py @@ -806,8 +806,10 @@ def _set_loaded_sample(self, sample): if smp != sample: smp._set_loaded(False) else: - if self.get_loaded_sample() == smp: - smp._set_loaded(True) + self.log.debug(f" Found sample {smp} is loaded") + self.log.debug(f" getting loaded {self.get_loaded_sample()}") + #if self.get_loaded_sample() == smp: + smp._set_loaded(True) if previous_loaded != self.get_loaded_sample(): self._trigger_loaded_sample_changed_event(sample) From a3a645d844c730ce9d37b33698d389bbef639ab9 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Mon, 18 Sep 2023 12:11:42 +0200 Subject: [PATCH 069/151] Fixing the ambiguity with Poller value and .any --- mxcubecore/Command/Tango.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mxcubecore/Command/Tango.py b/mxcubecore/Command/Tango.py index 96e998e14e..6f5c98f84f 100644 --- a/mxcubecore/Command/Tango.py +++ b/mxcubecore/Command/Tango.py @@ -21,6 +21,7 @@ import logging import gevent import gevent.event +import numpy as np try: import Queue as queue @@ -319,7 +320,7 @@ def get_info(self): self._device_initialized.wait(timeout=3) return self.device.get_attribute_config(self.attribute_name) - def update(self, value=Poller.NotInitializedValue): + # start with checking if we have a numpy array, as comparing # numpy.ndarray to Poller.NotInitializedValue raises a ValueError exception @@ -333,6 +334,7 @@ def update(self, value=Poller.NotInitializedValue): self.value = value self.emit("update", value) + def get_value(self): if self.read_as_str: value = self.device.read_attribute( From 732d330aefd3889f9ff65924e38b32edbb693896 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Mon, 18 Sep 2023 12:42:20 +0200 Subject: [PATCH 070/151] P11Collect additional debug after upgrade --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index b13044b47e..694c891b61 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -56,6 +56,7 @@ class P11Collect(AbstractCollect): + def __init__(self, *args): super(P11Collect, self).__init__(*args) @@ -99,7 +100,6 @@ def init(self): self.log.debug("acq_window_off_cmd: %s" % self.acq_window_off_cmd) else: self.init_ok = True - @task def move_motors(self, motor_position_dict): HWR.beamline.diffractometer.wait_omega() @@ -429,8 +429,16 @@ def collect_characterisation( "======= collect_characterisation Waiting =======================================" ) - # Let adxv know whether it is + #This part goes to standard collection. Otherwise it produces phantom openings. + # diffr.set_omega_velocity(self.default_speed) + # self.acq_window_off_cmd() + # self.acq_off_cmd() + self.log.debug("======= collect_characterisation Waiting =======================================") + + #Let adxv know whether it is # self.adxv_notify(self.latest_h5_filename,img_no+1) + + # time.sleep(1) # time.sleep(1) From dbf92d17fb0c7aa6b7af0cefa6cce9870b43ed33 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 09:53:30 +0200 Subject: [PATCH 071/151] Force upgrade from the develop to avoid merging conflict --- mxcubecore/Command/Tango.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mxcubecore/Command/Tango.py b/mxcubecore/Command/Tango.py index 6f5c98f84f..96e998e14e 100644 --- a/mxcubecore/Command/Tango.py +++ b/mxcubecore/Command/Tango.py @@ -21,7 +21,6 @@ import logging import gevent import gevent.event -import numpy as np try: import Queue as queue @@ -320,7 +319,7 @@ def get_info(self): self._device_initialized.wait(timeout=3) return self.device.get_attribute_config(self.attribute_name) - + def update(self, value=Poller.NotInitializedValue): # start with checking if we have a numpy array, as comparing # numpy.ndarray to Poller.NotInitializedValue raises a ValueError exception @@ -334,7 +333,6 @@ def get_info(self): self.value = value self.emit("update", value) - def get_value(self): if self.read_as_str: value = self.device.read_attribute( From 2b0d5e98ca0e1a4761deb51633e75a0282220550 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 17:06:43 +0200 Subject: [PATCH 072/151] Removed is_open() as a function and assigned is_closed() as a property for shutter-like objects inside P11 HO (Bixente) --- mxcubecore/HardwareObjects/DESY/P11DetectorCover.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py index ec9c9e480e..5555ae015d 100644 --- a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py +++ b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py @@ -197,7 +197,7 @@ def simulated_update(self): self.update_value(value) return value - + @property def is_closed(self): """Check if the shutter is closed. From 2475e323e135d1f43467daa9b72a31d1b7817c8e Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Fri, 6 Oct 2023 19:18:03 +0200 Subject: [PATCH 073/151] Upgraded the characterisation part for P11 using EDNA --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index 694c891b61..b80d9fd8e1 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -130,6 +130,7 @@ def data_collection_hook(self): self.diffr = HWR.beamline.diffractometer detector = HWR.beamline.detector + dc_pars = self.current_dc_parameters collection_type = dc_pars["experiment_type"] @@ -203,7 +204,7 @@ def data_collection_hook(self): ) # Filepath to the EDNA processing - # filepath = os.path.join(basepath,"%s_%d" % (prefix, runno)) + #filepath = os.path.join(basepath,"%s_%d" % (prefix, runno)) # setting up xds_dir for characterisation (used there internally to create dirs) self.current_dc_parameters["xds_dir"] = os.path.join( From 738f981e71c6d9638c635683c907c19d0cbe81c4 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Fri, 6 Oct 2023 22:57:55 +0200 Subject: [PATCH 074/151] Linting --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 13 +++++++------ mxcubecore/HardwareObjects/DESY/P11DetectorCover.py | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index b80d9fd8e1..f22ae8f6d1 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -56,7 +56,6 @@ class P11Collect(AbstractCollect): - def __init__(self, *args): super(P11Collect, self).__init__(*args) @@ -100,6 +99,7 @@ def init(self): self.log.debug("acq_window_off_cmd: %s" % self.acq_window_off_cmd) else: self.init_ok = True + @task def move_motors(self, motor_position_dict): HWR.beamline.diffractometer.wait_omega() @@ -130,7 +130,6 @@ def data_collection_hook(self): self.diffr = HWR.beamline.diffractometer detector = HWR.beamline.detector - dc_pars = self.current_dc_parameters collection_type = dc_pars["experiment_type"] @@ -204,7 +203,7 @@ def data_collection_hook(self): ) # Filepath to the EDNA processing - #filepath = os.path.join(basepath,"%s_%d" % (prefix, runno)) + # filepath = os.path.join(basepath,"%s_%d" % (prefix, runno)) # setting up xds_dir for characterisation (used there internally to create dirs) self.current_dc_parameters["xds_dir"] = os.path.join( @@ -434,11 +433,13 @@ def collect_characterisation( # diffr.set_omega_velocity(self.default_speed) # self.acq_window_off_cmd() # self.acq_off_cmd() - self.log.debug("======= collect_characterisation Waiting =======================================") + self.log.debug( + "======= collect_characterisation Waiting =======================================" + ) - #Let adxv know whether it is + # Let adxv know whether it is # self.adxv_notify(self.latest_h5_filename,img_no+1) - + # time.sleep(1) # time.sleep(1) diff --git a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py index 5555ae015d..ec9c9e480e 100644 --- a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py +++ b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py @@ -197,7 +197,7 @@ def simulated_update(self): self.update_value(value) return value - + @property def is_closed(self): """Check if the shutter is closed. From d0bec06c9b94abecf3f3f8a11c7afe0f7646f005 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 25 Oct 2023 18:35:26 +0200 Subject: [PATCH 075/151] Added new HO for the beam representation for P11 (Bixente) --- mxcubecore/HardwareObjects/DESY/P11Beam.py | 114 +++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 mxcubecore/HardwareObjects/DESY/P11Beam.py diff --git a/mxcubecore/HardwareObjects/DESY/P11Beam.py b/mxcubecore/HardwareObjects/DESY/P11Beam.py new file mode 100644 index 0000000000..7088c2dfdb --- /dev/null +++ b/mxcubecore/HardwareObjects/DESY/P11Beam.py @@ -0,0 +1,114 @@ +# Project: MXCuBE +# https://github.com/mxcube +# +# This file is part of MXCuBE software. +# +# MXCuBE is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# MXCuBE is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with MXCuBE. If not, see . + +"""P11Beam""" + +import time +import sys +import urllib +from mxcubecore.HardwareObjects.abstract.AbstractBeam import AbstractBeam +from mxcubecore.BaseHardwareObjects import HardwareObjectState +from enum import Enum, unique + + +__credits__ = ["DESY P11"] +__license__ = "LGPLv3+" +__category__ = "General" + + +class P11Beam(AbstractBeam): + def __init__(self,*args): + super(P11Beam,self).__init__(*args) + + self._beam_size_dict = { + "aperture": [9999,9999], + "slits": [9999,9999], + } + + self._beam_position_on_screen = [340, 256] + + self.focus_sizes = { + -1: {'label': 'unknown', 'size': (0.2,0.2)}, + 0: {'label': 'flat', 'size': (0.2,0.2)}, + 1: {'label': '200x200', 'size': (0.2,0.2)}, + 2: {'label': '100x100', 'size': (0.1,0.1)}, + 3: {'label': '50x50', 'size': (0.05,0.05)}, + 4: {'label': '20x20', 'size': (0.02,0.02)}, + 5: {'label': '4x9', 'size': (0.009,0.004)}, + } + + + + def init(self): + self.mirror_idx_ch = self.get_channel_object("beamsize") + self.mirror_state_ch = self.get_channel_object("state") + + if self.mirror_idx_ch is not None: + self.mirror_idx_ch.connect_signal("update", self.mirror_idx_changed) + if self.mirror_state_ch is not None: + self.mirror_state_ch.connect_signal("update", self.mirror_state_changed) + + self.mirror_idx_changed() + self.mirror_state_changed() + + def get_beam_info_state(self): + if self.mirror_state_ch is not None: + tango_state = self.mirror_state_ch.get_value() + return self._convert_tango_state(tango_state) + + return self.STATES_READY + + def mirror_state_changed(self, state=None): + + if state is None: + state = self.get_beam_info_state() + + self.update_state( self._convert_tango_state(state) ) + + def _convert_tango_state(self, state): + str_state = str(state) + + if str_state == "ON": + _state = self.STATES.READY + elif str_state == "MOVING": + _state = self.STATES.BUSY + else: + _state = self.STATES.FAULT + return _state + + + def mirror_idx_changed(self, value=None): + + if value is None: + value = self.mirror_idx_ch.get_value() + + self.log.debug(f"P11Beam - mirror idx changed. now is {value}") + + if value not in self.focus_sizes: + value = -1 + self.log.debug(f" - UNKNOWN mirror index") + + curr_size_item = self.focus_sizes[value] + self.log.debug(f" current mirror focus is {curr_size_item['label']}: {curr_size_item['size']}") + + + self._beam_size_dict["aperture"] = curr_size_item['size'] + + self.evaluate_beam_info() + self.re_emit_values() + From 9a07a939a76cc3114687fa1faa94f13432f0bcb8 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 8 Nov 2023 16:26:02 +0100 Subject: [PATCH 076/151] Fix beam position update in P11 Nanodiff --- mxcubecore/HardwareObjects/DESY/P11NanoDiff.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py b/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py index 10fe34b321..f4ce1efbc8 100644 --- a/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py +++ b/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py @@ -154,7 +154,8 @@ def init(self): self.update_phase() self.update_zoom_calibration() - self.beam_position = self.update_beam_position() + #self.beam_position = self.update_beam_position() + self.update_beam_position() def update_beam_position(self): zoom_hwobj = self.motor_hwobj_dict["zoom"] From 411262913000ae5bc3cd2bf19903756c3ef95e4b Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 8 Nov 2023 16:26:41 +0100 Subject: [PATCH 077/151] Minor changes --- mxcubecore/HardwareObjects/DESY/P11AlbulaView.py | 1 - 1 file changed, 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11AlbulaView.py b/mxcubecore/HardwareObjects/DESY/P11AlbulaView.py index 4062d1db26..95b2d76d3e 100644 --- a/mxcubecore/HardwareObjects/DESY/P11AlbulaView.py +++ b/mxcubecore/HardwareObjects/DESY/P11AlbulaView.py @@ -26,7 +26,6 @@ import time from PIL import Image - sys.path.append("/opt/dectris/albula/4.0/python/") from mxcubecore.BaseHardwareObjects import HardwareObject From ab9ec246902dd14d6ed1b4c1cf8e8ca74d5a327c Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 8 Nov 2023 16:28:18 +0100 Subject: [PATCH 078/151] Added slits gap None (no slits) for P11 (Bixente) --- mxcubecore/HardwareObjects/DESY/P11Beam.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mxcubecore/HardwareObjects/DESY/P11Beam.py b/mxcubecore/HardwareObjects/DESY/P11Beam.py index 7088c2dfdb..5b4da2fa14 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Beam.py +++ b/mxcubecore/HardwareObjects/DESY/P11Beam.py @@ -73,6 +73,9 @@ def get_beam_info_state(self): return self.STATES_READY + def get_slits_gap(self): + return None, None + def mirror_state_changed(self, state=None): if state is None: From f86bc95831be64574ebcd44c2f16916fc32837a2 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 8 Nov 2023 16:29:40 +0100 Subject: [PATCH 079/151] Temp fix for P11 specific routine --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index f22ae8f6d1..8bce7ed4cc 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -558,6 +558,9 @@ def add_h5_info(self, h5file): except RuntimeWarning as err_msg: self.log.debug("Error while adding info to HDF5 file (%s)" % str(err_msg)) self.log.debug(traceback.format_exc()) + except Exception as err_msg: + self.log.debug("Error while adding info to HDF5 file (%s)" % str(err_msg)) + self.log.debug(traceback.format_exc()) def get_filter_thickness(self): """ From 349bda948b701fe6db7243ac2b7099b598340f42 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 8 Nov 2023 18:03:37 +0100 Subject: [PATCH 080/151] Renamed get_properties to get_properties_ as before and made appropriate changes in qt part-multi_state_brick.py (PR800) --- mxcubecore/HardwareObjects/MotorsNPosition.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mxcubecore/HardwareObjects/MotorsNPosition.py b/mxcubecore/HardwareObjects/MotorsNPosition.py index ab28f896e8..c28ab9f24d 100644 --- a/mxcubecore/HardwareObjects/MotorsNPosition.py +++ b/mxcubecore/HardwareObjects/MotorsNPosition.py @@ -121,7 +121,7 @@ def load_positions(self): def get_position_list(self): return list(self._positions.keys()) - def get_properties(self, position_index, property_name): + def get_properties_(self, position_index, property_name): """ returns property with name property_name for position_index if position_index is None returns OrderedDict with property_name for all positions @@ -161,7 +161,7 @@ def set_position(self, posname): posidx = -1 for name in self._positions: posidx += 1 - if posname == self.get_properties(posidx, "posname"): + if posname == self.get_properties_(posidx, "posname"): self._set_value(posidx) return From 8ee4cc424231ca02177b8332e440dffb50bdd21f Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 8 Nov 2023 18:39:43 +0100 Subject: [PATCH 081/151] Cleanup unused code (PR800) --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 42 +------------------ 1 file changed, 1 insertion(+), 41 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index 6820aa3087..2a00292b58 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -286,52 +286,12 @@ def data_collection_hook(self): self.collect_characterisation( start_angle, img_range, nframes, angle_inc, exp_time ) - # TODO: Add LiveView here - # os.system("killall albula") - # os.system("/opt/dectris/albula/4.0/bin/albula "+self.latest_h5_filename +" &") - # os.system("adxv "+self.latest_h5_filename +" &") - - # TODO: Remove for now creation of the snapshots and processing html. - # Open index_html - # os.system("firefox /gpfs/current/processed/index.html") - - # Create diffraction snapshots - # for i in range(nframes): - # os.system( - # "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " - # + self.latest_h5_filename - # + " --output " - # + os.path.join( - # basepath, prefix, "screening_" + str(runno).zfill(3) - # ) - # + "/" - # + " --image_number " - # + str(i + 1) - # ) - # else: self.collect_std_collection(start_angle, stop_angle) self.generate_xds_template() # self.adxv_notify(self.latest_h5_filename) # TODO: Add LiveView here - # os.system("killall albula") - # os.system("/opt/dectris/albula/4.0/bin/albula "+self.latest_h5_filename +" &") - - # # Open index_html - # os.system("firefox /gpfs/current/processed/index.html") - # - # # Create diffraction snapshots - # os.system( - # "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " - # + self.latest_h5_filename - # + " --output " - # + os.path.join( - # basepath, prefix, "rotational_" + str(runno).zfill(3) - # ) - # + "/" - # + " --image_number 1" - # ) - # + except RuntimeError: self.log.error(traceback.format_exc()) finally: From 50be287e9d86dbecef44a2d3c497f72b4fcc3ca2 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Mon, 18 Sep 2023 12:11:42 +0200 Subject: [PATCH 082/151] Fixing the ambiguity with Poller value and .any --- mxcubecore/Command/Tango.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/mxcubecore/Command/Tango.py b/mxcubecore/Command/Tango.py index 96e998e14e..51092486c4 100644 --- a/mxcubecore/Command/Tango.py +++ b/mxcubecore/Command/Tango.py @@ -21,6 +21,7 @@ import logging import gevent import gevent.event +import numpy as np try: import Queue as queue @@ -28,11 +29,7 @@ import queue -from mxcubecore.CommandContainer import ( - CommandObject, - ChannelObject, - ConnectionError, -) +from mxcubecore.CommandContainer import CommandObject, ChannelObject, ConnectionError from mxcubecore import Poller from mxcubecore.dispatcher import saferef import numpy @@ -171,13 +168,13 @@ def __init__( self.timeout = int(timeout) self.read_as_str = kwargs.get("read_as_str", False) self._device_initialized = gevent.event.Event() - #logging.getLogger("HWR").debug( + # logging.getLogger("HWR").debug( # "creating Tango attribute %s/%s, polling=%s, timeout=%d", # self.device_name, # self.attribute_name, # polling, # self.timeout, - #) + # ) self.init_device() self.continue_init(None) """ From 888ec974be8526629e5dbc15e9d86ee7d3c817d9 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Mon, 18 Sep 2023 12:42:20 +0200 Subject: [PATCH 083/151] P11Collect additional debug after upgrade --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 124 +++++++++++------- 1 file changed, 75 insertions(+), 49 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index 3171a52753..c2f1b2e9d9 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -39,24 +39,42 @@ from mxcubecore.Command.Tango import DeviceProxy +import gevent +import time +import numpy as np +import logging +import os +import sys +import math +import h5py import triggerUtils +from tango import DeviceProxy, DevState FILE_TIMEOUT = 5 class P11Collect(AbstractCollect): + def __init__(self, *args): super(P11Collect, self).__init__(*args) + def init(self): + + super(P11Collect,self).init() + + # os.system("/opt/xray/bin/adxv -socket -colors Gray -rings &") + + # os.system("/bin/bash /gpfs/local/shared/MXCuBE/STRELA/start_viewer_zmq.sh") + + self.default_speed = self.get_property("omega_default_speed", 130) - self.turnback_time = self.get_property("turnback_time", 0.1) - self.filter_server_name = self.get_property("filterserver") - self.mono_server_name = self.get_property("monoserver") + self.turnback_time = self.get_property("turnback_time", 0.3) + self.filter_server_name = self.get_property('filterserver') + self.mono_server_name = self.get_property('monoserver') self.filter_server = DeviceProxy(self.filter_server_name) self.mono_server = DeviceProxy(self.mono_server_name) - self.diffr = HWR.beamline.diffractometer self.lower_bound_ch = self.get_channel_object("acq_lower_bound") self.upper_bound_ch = self.get_channel_object("acq_upper_bound") @@ -66,26 +84,9 @@ def __init__(self, *args): self.acq_off_cmd = self.get_command_object("acq_off") self.acq_window_off_cmd = self.get_command_object("acq_window_off") - self.latest_frames = 1 - self.acq_speed = 1.0 - self.init_ok = False - self.latest_h5_filename = "TEST_master.h5" - - def init(self): - super(P11Collect, self).init() - - # os.system("/opt/xray/bin/adxv -socket -colors Gray -rings &") - - # os.system("/bin/bash /gpfs/local/shared/MXCuBE/STRELA/start_viewer_zmq.sh") - - if None in [ - self.lower_bound_ch, - self.upper_bound_ch, - self.acq_arm_cmd, - self.acq_on_cmd, - self.acq_off_cmd, - self.acq_window_off_cmd, - ]: + if None in [self.lower_bound_ch, self.upper_bound_ch, + self.acq_arm_cmd, self.acq_on_cmd, self.acq_off_cmd, + self.acq_window_off_cmd]: self.init_ok = False self.log.debug("lower_bound_ch: %s" % self.lower_bound_ch) self.log.debug("upper_bound_ch: %s" % self.upper_bound_ch) @@ -95,7 +96,6 @@ def init(self): self.log.debug("acq_window_off_cmd: %s" % self.acq_window_off_cmd) else: self.init_ok = True - @task def move_motors(self, motor_position_dict): HWR.beamline.diffractometer.wait_omega() @@ -339,21 +339,32 @@ def collect_std_collection(self, start_angle, stop_angle): :param stop_angle: The stop_angle parameter is the final angle at which the collection should stop """ + HWR.beamline.diffractometer.wait_omega() - self.omega_mv(start_angle, self.default_speed) - + start_pos = start_angle - self.turnback_time*self.acq_speed + stop_pos = stop_angle + self.turnback_time*self.acq_speed + + + self.log.debug("#COLLECT# Running OMEGA through the std acquisition") if start_angle <= stop_angle: - self.lower_bound_ch.set_value(start_angle) - self.upper_bound_ch.set_value(stop_angle) + self.lower_bound_ch.set_value(start_angle) + self.upper_bound_ch.set_value(stop_angle) + else: - self.lower_bound_ch.set_value(stop_angle) - self.upper_bound_ch.set_value(start_angle) - self.acq_arm_cmd() + self.lower_bound_ch.set_value(stop_angle) + self.upper_bound_ch.set_value(start_angle) - final_pos = stop_angle + self.acq_speed * self.turnback_time - self.omega_mv(final_pos, self.acq_speed) + self.omega_mv(start_pos, self.default_speed) + self.acq_arm_cmd() + self.omega_mv(stop_pos, self.acq_speed) + time.sleep(0.5) + self.acq_off_cmd() + self.acq_window_off_cmd() + self.omega_mv(stop_angle, self.acq_speed) + HWR.beamline.diffractometer.wait_omega() + def collect_characterisation( self, start_angle, img_range, nimages, angle_inc, exp_time @@ -374,7 +385,7 @@ def collect_characterisation( diffr = HWR.beamline.diffractometer - self.log.debug("#COLLECT# Running OMEGA through the char acquisition") + self.log.debug("#COLLECT# Running OMEGA through the characteristation acquisition") self.omega_mv(start_angle, self.default_speed) @@ -382,26 +393,36 @@ def collect_characterisation( print("collecting image %s" % img_no) start_at = start_angle + angle_inc * img_no stop_angle = start_at + img_range * 1.0 + #print("======= CHARACTERISATION Adding angle and range to the header...") + #Add start angle to the header + #detector = HWR.beamline.detector + #detector.set_eiger_start_angle(start_at) + + # Add angle increment to the header + #detector.set_eiger_angle_increment(angle_inc) + print("collecting image %s, angle %f" % (img_no, start_at)) if start_at >= stop_angle: - init_pos = start_at - self.acq_speed * self.turnback_time + init_pos = start_at #- self.acq_speed * self.turnback_time # init_pos = start_at - 1.5 else: - init_pos = start_at + self.acq_speed * self.turnback_time + init_pos = start_at #+ self.acq_speed * self.turnback_time # init_pos = start_at + 1.5 - self.omega_mv(init_pos, self.default_speed) - self.collect_std_collection(start_angle, stop_angle) - diffr.set_omega_velocity(self.default_speed) - self.acq_window_off_cmd() - self.acq_off_cmd() - self.log.debug( - "======= collect_characterisation Waiting =======================================" - ) + # self.omega_mv(init_pos, self.default_speed) + self.collect_std_collection(start_at, stop_angle) + + #This part goes to standard collection. Otherwise it produces phantom openings. + # diffr.set_omega_velocity(self.default_speed) + # self.acq_window_off_cmd() + # self.acq_off_cmd() + self.log.debug("======= collect_characterisation Waiting =======================================") - # Let adxv know whether it is + #Let adxv know whether it is # self.adxv_notify(self.latest_h5_filename,img_no+1) + + # time.sleep(1) def adxv_notify(self, image_filename, image_num=1): """ @@ -439,12 +460,17 @@ def acquisition_cleanup(self): try: diffr = HWR.beamline.diffractometer detector = HWR.beamline.detector - diffr.set_omega_velocity(self.default_speed) - self.acq_window_off_cmd() + detector.stop_acquisition() + diffr.wait_omega() + # ================= + #It is probably already finished in a standard collection. self.acq_off_cmd() + self.acq_window_off_cmd() + # ================== + diffr.set_omega_velocity(self.default_speed) self.log.debug("#COLLECT# Closing detector cover") diffr.detector_cover_close(wait=True) - detector.stop_acquisition() + except RuntimeError: self.log.error(traceback.format_exc()) From a091d6fe3a0ff0ddf92e5924c094df540d8e1150 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Mon, 18 Sep 2023 12:11:42 +0200 Subject: [PATCH 084/151] Fixing the ambiguity with Poller value and .any --- mxcubecore/Command/Tango.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mxcubecore/Command/Tango.py b/mxcubecore/Command/Tango.py index 51092486c4..0c23a3182d 100644 --- a/mxcubecore/Command/Tango.py +++ b/mxcubecore/Command/Tango.py @@ -316,7 +316,7 @@ def get_info(self): self._device_initialized.wait(timeout=3) return self.device.get_attribute_config(self.attribute_name) - def update(self, value=Poller.NotInitializedValue): + # start with checking if we have a numpy array, as comparing # numpy.ndarray to Poller.NotInitializedValue raises a ValueError exception @@ -330,6 +330,7 @@ def update(self, value=Poller.NotInitializedValue): self.value = value self.emit("update", value) + def get_value(self): if self.read_as_str: value = self.device.read_attribute( From a01d46e4a4f27b8afded28fd379551a12a3201c8 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 09:53:30 +0200 Subject: [PATCH 085/151] Force upgrade from the develop to avoid merging conflict --- mxcubecore/Command/Tango.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mxcubecore/Command/Tango.py b/mxcubecore/Command/Tango.py index 0c23a3182d..c164eb8017 100644 --- a/mxcubecore/Command/Tango.py +++ b/mxcubecore/Command/Tango.py @@ -21,7 +21,6 @@ import logging import gevent import gevent.event -import numpy as np try: import Queue as queue @@ -316,7 +315,7 @@ def get_info(self): self._device_initialized.wait(timeout=3) return self.device.get_attribute_config(self.attribute_name) - + def update(self, value=Poller.NotInitializedValue): # start with checking if we have a numpy array, as comparing # numpy.ndarray to Poller.NotInitializedValue raises a ValueError exception @@ -330,7 +329,6 @@ def get_info(self): self.value = value self.emit("update", value) - def get_value(self): if self.read_as_str: value = self.device.read_attribute( From 8414e3fd80f5fb2356ab3f4871bfb2021e34f632 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 10:34:20 +0200 Subject: [PATCH 086/151] Added missing warnings module --- mxcubecore/HardwareObjects/ISPyBClient.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mxcubecore/HardwareObjects/ISPyBClient.py b/mxcubecore/HardwareObjects/ISPyBClient.py index 34797ad402..56475e92bb 100644 --- a/mxcubecore/HardwareObjects/ISPyBClient.py +++ b/mxcubecore/HardwareObjects/ISPyBClient.py @@ -8,6 +8,7 @@ from pprint import pformat from collections import namedtuple from datetime import datetime +import warnings try: from urlparse import urljoin From 3d8eaa8f6112dad88aa3a24735bab6e79bb823b1 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 11:20:37 +0200 Subject: [PATCH 087/151] Enabled back explicit check on if beamtimeid is open --- mxcubecore/HardwareObjects/DESY/P11Session.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Session.py b/mxcubecore/HardwareObjects/DESY/P11Session.py index fc959c288a..2e00a81615 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Session.py +++ b/mxcubecore/HardwareObjects/DESY/P11Session.py @@ -85,8 +85,7 @@ def info_set_defaults(self): self.beamtime_info["rootPath"] = PATH_FALLBACK def is_beamtime_open(self): - return True - # return self.is_writable_dir( os.path.join(PATH_BEAMTIME, self.raw_data_folder_name) ) + return self.is_writable_dir( os.path.join(PATH_BEAMTIME, self.raw_data_folder_name) ) def is_commissioning_open(self): return self.is_writable_dir( From 2d02ae3ee32535854fd1a55773c0e902517efc69 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 11:29:10 +0200 Subject: [PATCH 088/151] Added debug info in case beamtime ID is not opened --- mxcubecore/HardwareObjects/DESY/P11Session.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mxcubecore/HardwareObjects/DESY/P11Session.py b/mxcubecore/HardwareObjects/DESY/P11Session.py index 2e00a81615..4e1abb1f16 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Session.py +++ b/mxcubecore/HardwareObjects/DESY/P11Session.py @@ -85,6 +85,12 @@ def info_set_defaults(self): self.beamtime_info["rootPath"] = PATH_FALLBACK def is_beamtime_open(self): + self.log.debug("=========== CHECKING IF BEAMTIME ID IS OPEN... ============") + if self.is_writable_dir(os.path.join(PATH_BEAMTIME, self.raw_data_folder_name)): + self.log.debug("=========== BEAMTIME IS OPEN (/gpfs/current exists) ============") + else: + self.log.debug("=========== NO BEMTIME ID IS OPEN (check /gpfs/current) ============") + return self.is_writable_dir( os.path.join(PATH_BEAMTIME, self.raw_data_folder_name) ) def is_commissioning_open(self): From 988c3c588ce1a92946c963e152de4b3fa16e8c8e Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 16:58:08 +0200 Subject: [PATCH 089/151] Added beamtime info as a property --- mxcubecore/HardwareObjects/DESY/P11Session.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mxcubecore/HardwareObjects/DESY/P11Session.py b/mxcubecore/HardwareObjects/DESY/P11Session.py index 4e1abb1f16..f2fdfce8b0 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Session.py +++ b/mxcubecore/HardwareObjects/DESY/P11Session.py @@ -116,6 +116,9 @@ def get_current_proposal_number(self): info = self.get_beamtime_info() return info["proposalId"] + def get_beamtime_info(self): + return self.beamtime_info + def read_beamtime_info(self): self.log.debug("=========== READING BEAMTIME INFO ============") if os.path.exists(PATH_BEAMTIME): From ead7953e464883deb42fb4b4d4cc2dd19c2e55c9 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 16:59:56 +0200 Subject: [PATCH 090/151] Added additional debug messages for shutter --- mxcubecore/HardwareObjects/DESY/P11Shutter.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mxcubecore/HardwareObjects/DESY/P11Shutter.py b/mxcubecore/HardwareObjects/DESY/P11Shutter.py index 3a147822dc..1fe79adaed 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Shutter.py +++ b/mxcubecore/HardwareObjects/DESY/P11Shutter.py @@ -133,9 +133,12 @@ def update_shutter_state(self, state=None): if state is None: state = self.chan_state.get_value() + self.log.debug(" SHUTTER state changed") if state[0] == 3: + self.log.debug(" P11SHUTTER IS OPEN") value = self.VALUES.OPEN else: + self.log.debug(" P11SHUTTER IS CLOSED") value = self.VALUES.CLOSED # else: @@ -146,6 +149,7 @@ def update_shutter_state(self, state=None): self.update_value(value) + self.log.debug(" update shutter state done") return value def simulated_update(self): From 40250bd587d0ddbdad5ac57dce1377331ea5d77e Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 17:01:42 +0200 Subject: [PATCH 091/151] Fixed get_properties naming (Bixente) --- mxcubecore/HardwareObjects/MotorsNPosition.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/MotorsNPosition.py b/mxcubecore/HardwareObjects/MotorsNPosition.py index c28ab9f24d..286826be3d 100644 --- a/mxcubecore/HardwareObjects/MotorsNPosition.py +++ b/mxcubecore/HardwareObjects/MotorsNPosition.py @@ -121,7 +121,7 @@ def load_positions(self): def get_position_list(self): return list(self._positions.keys()) - def get_properties_(self, position_index, property_name): + def get_properties(self, position_index, property_name): """ returns property with name property_name for position_index if position_index is None returns OrderedDict with property_name for all positions From ae8b878441e73d526ce24da6d9971efab769996a Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 17:04:04 +0200 Subject: [PATCH 092/151] Removed faulty login_type=user fot P11 --- mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py b/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py index d1f259cb7a..3a6e24119e 100644 --- a/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py +++ b/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py @@ -26,8 +26,6 @@ def init(self): "PROPOSAL NUMBER is %s" % self.simulated_prop_number ) - self.loginType = "user" - def update_data_collection(self, mx_collection, wait=False): mx_collection["beamline_name"] = "P11" ISPyBClient.update_data_collection(self, mx_collection, wait) From 13f14b870d3805051776d905675b3129e5443693 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 17:06:43 +0200 Subject: [PATCH 093/151] Removed is_open() as a function and assigned is_closed() as a property for shutter-like objects inside P11 HO (Bixente) --- mxcubecore/HardwareObjects/DESY/P11DetectorCover.py | 8 +------- mxcubecore/HardwareObjects/DESY/P11FastShutter.py | 2 ++ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py index e246d7646b..1f1e208f20 100644 --- a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py +++ b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py @@ -197,13 +197,7 @@ def simulated_update(self): self.update_value(value) return value - def is_open(self): - """Check if the shutter is open. - Returns: - (bool): True if open, False otherwise. - """ - return self.get_value() == self.VALUES.OPEN - + @property def is_closed(self): """Check if the shutter is closed. Returns: diff --git a/mxcubecore/HardwareObjects/DESY/P11FastShutter.py b/mxcubecore/HardwareObjects/DESY/P11FastShutter.py index 4b4ae4c6e5..ebe924a395 100644 --- a/mxcubecore/HardwareObjects/DESY/P11FastShutter.py +++ b/mxcubecore/HardwareObjects/DESY/P11FastShutter.py @@ -67,9 +67,11 @@ def init(self): def get_value(self): return self.update_fast_shutter() + @property def is_open(self): return self.get_value() == self.VALUES.OPEN + @property def is_closed(self): return self.get_value() == self.VALUES.CLOSED From b021661554eaf41dbe0053cff7ff93866c6d977b Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 17:07:35 +0200 Subject: [PATCH 094/151] Added is_open as a property inside P11NanoDiff (Bixente) --- mxcubecore/HardwareObjects/DESY/P11NanoDiff.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py b/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py index e327c48faa..10fe34b321 100644 --- a/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py +++ b/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py @@ -737,9 +737,9 @@ def detector_cover_close(self, wait=True): def wait_detcover(self, state, timeout=60): start_time = time.time() while time.time() - start_time > timeout: - if state == "open" and self.detcover_hwobj.is_open(): + if state == "open" and self.detcover_hwobj.is_open: break - elif state == "close" and self.detcover_hwobj.is_closed(): + elif state == "close" and self.detcover_hwobj.is_closed: break gevent.sleep(0.5) @@ -802,8 +802,8 @@ def update_phase(self, value=None): omega_pos = self.get_omega_position() - cover_open = self.detcover_hwobj.is_open() - cover_closed = self.detcover_hwobj.is_closed() + cover_open = self.detcover_hwobj.is_open + cover_closed = self.detcover_hwobj.is_closed blight_in = self.backlight_hwobj.is_in() blight_out = self.backlight_hwobj.is_out() collim = self.collimator_hwobj.get_position() From f31ed831becd1376f4106f1622c7cf1617683254 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 17:26:57 +0200 Subject: [PATCH 095/151] Fixed other get_properties typos which were preventing loading --- mxcubecore/HardwareObjects/MotorsNPosition.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/MotorsNPosition.py b/mxcubecore/HardwareObjects/MotorsNPosition.py index 286826be3d..ab28f896e8 100644 --- a/mxcubecore/HardwareObjects/MotorsNPosition.py +++ b/mxcubecore/HardwareObjects/MotorsNPosition.py @@ -161,7 +161,7 @@ def set_position(self, posname): posidx = -1 for name in self._positions: posidx += 1 - if posname == self.get_properties_(posidx, "posname"): + if posname == self.get_properties(posidx, "posname"): self._set_value(posidx) return From 9aa5e33a9757255e87d2710a3dc962011bc7d902 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Thu, 5 Oct 2023 15:35:55 +0200 Subject: [PATCH 096/151] Fixed shutter openning wainting forever (Bixente) --- mxcubecore/HardwareObjects/DESY/P11Shutter.py | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Shutter.py b/mxcubecore/HardwareObjects/DESY/P11Shutter.py index 1fe79adaed..8202549f10 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Shutter.py +++ b/mxcubecore/HardwareObjects/DESY/P11Shutter.py @@ -22,6 +22,7 @@ import gevent import urllib from mxcubecore.HardwareObjects.abstract.AbstractShutter import AbstractShutter +import mxcubecore.HardwareObjects.abstract.AbstractShutter as absshut from mxcubecore.BaseHardwareObjects import HardwareObjectState from enum import Enum, unique @@ -85,6 +86,8 @@ def init(self): else: self.simulated_update() + self.update_state(self.STATES.READY) + super(AbstractShutter, self).init() def get_value(self): @@ -105,25 +108,39 @@ def _set_value(self, value): if self.simulation: self.simulated_opened = open_it self.simulated_moving = True - gevent.spawn(self.simul_do) + self.t1 = gevent.spawn(self.simul_do) + self.t1.link(self.do_finish) + self.t1.link_exception(self.do_finish_exc) else: if open_it: self.do_open() else: self.do_close() self.cmd_started = time.time() + self.log.debug(" ### setting value value for shutter done") def do_open(self, timeout=3): + self.log.debug(" OPENING SHUTTER (web request)") result = urllib.request.urlopen(self.url_open, None, timeout).readlines() + self.log.debug(" OPENING SHUTTER (web request) retured") def do_close(self, timeout=3): + self.log.debug(" CLOSING SHUTTER (web request)") result = urllib.request.urlopen(self.url_close, None, timeout).readlines() + self.log.debug(" CLOSING SHUTTER (web request) retured") def simul_do(self): + self.log.debug("### starting simulated shutter move") gevent.sleep(1) self.simulated_moving = False self.log.debug("### updating simulated shutter") self.simulated_update() + self.log.debug("### ending simulated shutter move") + + def do_finish(self, t=None): + self.log.debug("### simulated finished") + def do_finish_exc(self, exc=None): + self.log.debug("### simulated finished with exception") def update_shutter_state(self, state=None): """Updates shutter state @@ -134,6 +151,7 @@ def update_shutter_state(self, state=None): state = self.chan_state.get_value() self.log.debug(" SHUTTER state changed") + if state[0] == 3: self.log.debug(" P11SHUTTER IS OPEN") value = self.VALUES.OPEN From 859bbf855903bc5a0795cbe50d755546bef647d4 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Fri, 6 Oct 2023 17:32:07 +0200 Subject: [PATCH 097/151] Added preliminary flux HO for P11 --- mxcubecore/HardwareObjects/DESY/P11Flux.py | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 mxcubecore/HardwareObjects/DESY/P11Flux.py diff --git a/mxcubecore/HardwareObjects/DESY/P11Flux.py b/mxcubecore/HardwareObjects/DESY/P11Flux.py new file mode 100644 index 0000000000..ae64c4ca83 --- /dev/null +++ b/mxcubecore/HardwareObjects/DESY/P11Flux.py @@ -0,0 +1,72 @@ +# +# Project: MXCuBE +# https://github.com/mxcube +# +# This file is part of MXCuBE software. +# +# MXCuBE is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# MXCuBE is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with MXCuBE. If not, see . + +from random import random +from mxcubecore.HardwareObjects.abstract.AbstractFlux import AbstractFlux + +from mxcubecore import HardwareRepository as HWR + +__credits__ = ["MXCuBE collaboration"] +__category__ = "General" + + +class P11Flux(AbstractFlux): + + # default_flux - for initialising mockup + default_flux = 5e12 + + def __init__(self, name): + AbstractFlux.__init__(self, name) + + self.measured_flux_list = [] + self.measured_flux_dict = {} + self.current_flux_dict = {} + + def init(self): + + self.measure_flux() + + def get_value(self): + """Get flux at current transmission in units of photons/s""" + + """ FLUX IS CHEETED HERE - NOWERE ELSE!""" + return self.current_flux_dict["flux"] + + def measure_flux(self): + """Measures intesity""" + beam_size = HWR.beamline.beam.get_beam_size() + transmission = HWR.beamline.transmission.get_value() + flux = self.default_flux * (1 + random()) + + self.measured_flux_list = [ + { + "size_x": beam_size[0], + "size_y": beam_size[1], + "transmission": transmission, + "flux": flux, + } + ] + + self.measured_flux_dict = self.measured_flux_list[0] + self.current_flux_dict = self.measured_flux_list[0] + + self.emit( + "fluxInfoChanged", + {"measured": self.measured_flux_dict, "current": self.current_flux_dict}, + ) From e095b64e0e8c7d03c0e9248586aa3ef84becc99e Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Fri, 6 Oct 2023 19:18:03 +0200 Subject: [PATCH 098/151] Upgraded the characterisation part for P11 using EDNA --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 68 ++++++++++--------- .../DESY/P11EDNACharacterisation.py | 33 ++++++++- 2 files changed, 68 insertions(+), 33 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index c2f1b2e9d9..0912c90293 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -126,6 +126,7 @@ def data_collection_hook(self): self.diffr = HWR.beamline.diffractometer detector = HWR.beamline.detector + dc_pars = self.current_dc_parameters collection_type = dc_pars["experiment_type"] @@ -199,8 +200,12 @@ def data_collection_hook(self): ) # Filepath to the EDNA processing - # filepath = os.path.join(basepath,"%s_%d" % (prefix, runno)) + #filepath = os.path.join(basepath,"%s_%d" % (prefix, runno)) + + #setting up xds_dir for characterisation (used there internally to create dirs) + self.current_dc_parameters["xds_dir"] = os.path.join(basepath,"%s_%d" % (prefix, runno)) + self.log.debug( "======= CURRENT FILEPATH: " + str(filepath) @@ -282,23 +287,24 @@ def data_collection_hook(self): # os.system("/opt/dectris/albula/4.0/bin/albula "+self.latest_h5_filename +" &") # os.system("adxv "+self.latest_h5_filename +" &") + #TODO: Remove for now creation of the snapshots and processing html. # Open index_html - os.system("firefox /gpfs/current/processed/index.html") + #os.system("firefox /gpfs/current/processed/index.html") # Create diffraction snapshots - for i in range(nframes): - os.system( - "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " - + self.latest_h5_filename - + " --output " - + os.path.join( - basepath, prefix, "screening_" + str(runno).zfill(3) - ) - + "/" - + " --image_number " - + str(i + 1) - ) - +# for i in range(nframes): +# os.system( +# "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " +# + self.latest_h5_filename +# + " --output " +# + os.path.join( +# basepath, prefix, "screening_" + str(runno).zfill(3) +# ) +# + "/" +# + " --image_number " +# + str(i + 1) +# ) +# else: self.collect_std_collection(start_angle, stop_angle) self.generate_xds_template() @@ -307,21 +313,21 @@ def data_collection_hook(self): # os.system("killall albula") # os.system("/opt/dectris/albula/4.0/bin/albula "+self.latest_h5_filename +" &") - # Open index_html - os.system("firefox /gpfs/current/processed/index.html") - - # Create diffraction snapshots - os.system( - "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " - + self.latest_h5_filename - + " --output " - + os.path.join( - basepath, prefix, "rotational_" + str(runno).zfill(3) - ) - + "/" - + " --image_number 1" - ) - +# # Open index_html +# os.system("firefox /gpfs/current/processed/index.html") +# +# # Create diffraction snapshots +# os.system( +# "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " +# + self.latest_h5_filename +# + " --output " +# + os.path.join( +# basepath, prefix, "rotational_" + str(runno).zfill(3) +# ) +# + "/" +# + " --image_number 1" +# ) +# except RuntimeError: self.log.error(traceback.format_exc()) finally: @@ -535,7 +541,7 @@ def add_h5_info(self, h5file): del h5fd[node] h5fd.close() - except RuntimeError as err_msg: + except RuntimeWarning as err_msg: self.log.debug("Error while adding info to HDF5 file (%s)" % str(err_msg)) self.log.debug(traceback.format_exc()) diff --git a/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py b/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py index 7e0eb6c775..28f3399e25 100644 --- a/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py +++ b/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py @@ -47,6 +47,26 @@ def __init__(self, name): self.edna_default_file = None self.start_edna_command = None + def _run_edna(self, input_file, results_file, process_directory): + """Starts EDNA""" + msg = "Starting EDNA characterisation using xml file %s" % input_file + logging.getLogger("queue_exec").info(msg) + + args = (self.start_edna_command, input_file, results_file, process_directory) + # subprocess.call("%s %s %s %s" % args, shell=True) + + # Test run DESY + self.edna_maxwell(process_directory,input_file, results_file) + + + + self.result = None + if os.path.exists(results_file): + self.result = XSDataResultMXCuBE.parseFile(results_file) + + return self.result + + def edna_maxwell(self, process_directory, inputxml, outputxml): """ The function `edna_maxwell` is used to execute a command on a remote cluster using SSH and SBATCH. @@ -105,6 +125,8 @@ def edna_maxwell(self, process_directory, inputxml, outputxml): ) ) + print('{ssh:s} "{sbatch:s} --wrap \\"{cmd:s}"\\"'.format(ssh=ssh, sbatch=sbatch, cmd=cmd)) + os.system( '{ssh:s} "{sbatch:s} --wrap \\"{cmd:s}"\\"'.format( ssh=ssh, sbatch=sbatch, cmd=cmd @@ -235,16 +257,23 @@ def input_from_params(self, data_collection, char_params): data_set = XSDataMXCuBEDataSet() acquisition_parameters = data_collection.acquisitions[0].acquisition_parameters path_template = data_collection.acquisitions[0].path_template - + + #Make sure there is a proper path conversion between different mount points + print("======= Characterisation path template ====", path_template.directory) #/gpfs/current/raw + image_dir = path_template.directory.replace( "/gpfs/current", triggerUtils.get_beamtime_metadata()[2] ) - path_str = os.path.join(image_dir, path_template.get_image_file_name()) + print(image_dir) + path_str = os.path.join(image_dir, path_template.get_image_file_name()) + print(path_template.xds_dir) + characterisation_dir = path_template.xds_dir.replace( "/autoprocessing_", "/characterisation_" ) + os.makedirs(characterisation_dir, mode=0o755, exist_ok=True) for img_num in range(int(acquisition_parameters.num_images)): From 39652576fd571cc30d0b635034806aea4b4bcbd0 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Fri, 6 Oct 2023 22:57:55 +0200 Subject: [PATCH 099/151] Linting --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 142 +++++++++--------- .../HardwareObjects/DESY/P11DetectorCover.py | 17 ++- .../DESY/P11EDNACharacterisation.py | 27 ++-- mxcubecore/HardwareObjects/DESY/P11Flux.py | 2 +- mxcubecore/HardwareObjects/DESY/P11Session.py | 14 +- mxcubecore/HardwareObjects/DESY/P11Shutter.py | 20 +-- 6 files changed, 119 insertions(+), 103 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index 0912c90293..b13044b47e 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -56,23 +56,21 @@ class P11Collect(AbstractCollect): - def __init__(self, *args): super(P11Collect, self).__init__(*args) def init(self): - super(P11Collect,self).init() + super(P11Collect, self).init() # os.system("/opt/xray/bin/adxv -socket -colors Gray -rings &") # os.system("/bin/bash /gpfs/local/shared/MXCuBE/STRELA/start_viewer_zmq.sh") - self.default_speed = self.get_property("omega_default_speed", 130) self.turnback_time = self.get_property("turnback_time", 0.3) - self.filter_server_name = self.get_property('filterserver') - self.mono_server_name = self.get_property('monoserver') + self.filter_server_name = self.get_property("filterserver") + self.mono_server_name = self.get_property("monoserver") self.filter_server = DeviceProxy(self.filter_server_name) self.mono_server = DeviceProxy(self.mono_server_name) @@ -84,9 +82,14 @@ def init(self): self.acq_off_cmd = self.get_command_object("acq_off") self.acq_window_off_cmd = self.get_command_object("acq_window_off") - if None in [self.lower_bound_ch, self.upper_bound_ch, - self.acq_arm_cmd, self.acq_on_cmd, self.acq_off_cmd, - self.acq_window_off_cmd]: + if None in [ + self.lower_bound_ch, + self.upper_bound_ch, + self.acq_arm_cmd, + self.acq_on_cmd, + self.acq_off_cmd, + self.acq_window_off_cmd, + ]: self.init_ok = False self.log.debug("lower_bound_ch: %s" % self.lower_bound_ch) self.log.debug("upper_bound_ch: %s" % self.upper_bound_ch) @@ -96,6 +99,7 @@ def init(self): self.log.debug("acq_window_off_cmd: %s" % self.acq_window_off_cmd) else: self.init_ok = True + @task def move_motors(self, motor_position_dict): HWR.beamline.diffractometer.wait_omega() @@ -126,7 +130,6 @@ def data_collection_hook(self): self.diffr = HWR.beamline.diffractometer detector = HWR.beamline.detector - dc_pars = self.current_dc_parameters collection_type = dc_pars["experiment_type"] @@ -200,12 +203,13 @@ def data_collection_hook(self): ) # Filepath to the EDNA processing - #filepath = os.path.join(basepath,"%s_%d" % (prefix, runno)) + # filepath = os.path.join(basepath,"%s_%d" % (prefix, runno)) + + # setting up xds_dir for characterisation (used there internally to create dirs) + self.current_dc_parameters["xds_dir"] = os.path.join( + basepath, "%s_%d" % (prefix, runno) + ) - - #setting up xds_dir for characterisation (used there internally to create dirs) - self.current_dc_parameters["xds_dir"] = os.path.join(basepath,"%s_%d" % (prefix, runno)) - self.log.debug( "======= CURRENT FILEPATH: " + str(filepath) @@ -287,24 +291,24 @@ def data_collection_hook(self): # os.system("/opt/dectris/albula/4.0/bin/albula "+self.latest_h5_filename +" &") # os.system("adxv "+self.latest_h5_filename +" &") - #TODO: Remove for now creation of the snapshots and processing html. + # TODO: Remove for now creation of the snapshots and processing html. # Open index_html - #os.system("firefox /gpfs/current/processed/index.html") + # os.system("firefox /gpfs/current/processed/index.html") # Create diffraction snapshots -# for i in range(nframes): -# os.system( -# "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " -# + self.latest_h5_filename -# + " --output " -# + os.path.join( -# basepath, prefix, "screening_" + str(runno).zfill(3) -# ) -# + "/" -# + " --image_number " -# + str(i + 1) -# ) -# + # for i in range(nframes): + # os.system( + # "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " + # + self.latest_h5_filename + # + " --output " + # + os.path.join( + # basepath, prefix, "screening_" + str(runno).zfill(3) + # ) + # + "/" + # + " --image_number " + # + str(i + 1) + # ) + # else: self.collect_std_collection(start_angle, stop_angle) self.generate_xds_template() @@ -313,21 +317,21 @@ def data_collection_hook(self): # os.system("killall albula") # os.system("/opt/dectris/albula/4.0/bin/albula "+self.latest_h5_filename +" &") -# # Open index_html -# os.system("firefox /gpfs/current/processed/index.html") -# -# # Create diffraction snapshots -# os.system( -# "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " -# + self.latest_h5_filename -# + " --output " -# + os.path.join( -# basepath, prefix, "rotational_" + str(runno).zfill(3) -# ) -# + "/" -# + " --image_number 1" -# ) -# + # # Open index_html + # os.system("firefox /gpfs/current/processed/index.html") + # + # # Create diffraction snapshots + # os.system( + # "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " + # + self.latest_h5_filename + # + " --output " + # + os.path.join( + # basepath, prefix, "rotational_" + str(runno).zfill(3) + # ) + # + "/" + # + " --image_number 1" + # ) + # except RuntimeError: self.log.error(traceback.format_exc()) finally: @@ -347,20 +351,17 @@ def collect_std_collection(self, start_angle, stop_angle): """ HWR.beamline.diffractometer.wait_omega() - start_pos = start_angle - self.turnback_time*self.acq_speed - stop_pos = stop_angle + self.turnback_time*self.acq_speed - - - + start_pos = start_angle - self.turnback_time * self.acq_speed + stop_pos = stop_angle + self.turnback_time * self.acq_speed + self.log.debug("#COLLECT# Running OMEGA through the std acquisition") if start_angle <= stop_angle: - self.lower_bound_ch.set_value(start_angle) - self.upper_bound_ch.set_value(stop_angle) + self.lower_bound_ch.set_value(start_angle) + self.upper_bound_ch.set_value(stop_angle) else: - self.lower_bound_ch.set_value(stop_angle) - self.upper_bound_ch.set_value(start_angle) - + self.lower_bound_ch.set_value(stop_angle) + self.upper_bound_ch.set_value(start_angle) self.omega_mv(start_pos, self.default_speed) self.acq_arm_cmd() @@ -371,7 +372,6 @@ def collect_std_collection(self, start_angle, stop_angle): self.omega_mv(stop_angle, self.acq_speed) HWR.beamline.diffractometer.wait_omega() - def collect_characterisation( self, start_angle, img_range, nimages, angle_inc, exp_time ): @@ -391,7 +391,9 @@ def collect_characterisation( diffr = HWR.beamline.diffractometer - self.log.debug("#COLLECT# Running OMEGA through the characteristation acquisition") + self.log.debug( + "#COLLECT# Running OMEGA through the characteristation acquisition" + ) self.omega_mv(start_angle, self.default_speed) @@ -399,35 +401,37 @@ def collect_characterisation( print("collecting image %s" % img_no) start_at = start_angle + angle_inc * img_no stop_angle = start_at + img_range * 1.0 - #print("======= CHARACTERISATION Adding angle and range to the header...") - #Add start angle to the header - #detector = HWR.beamline.detector - #detector.set_eiger_start_angle(start_at) + # print("======= CHARACTERISATION Adding angle and range to the header...") + # Add start angle to the header + # detector = HWR.beamline.detector + # detector.set_eiger_start_angle(start_at) # Add angle increment to the header - #detector.set_eiger_angle_increment(angle_inc) + # detector.set_eiger_angle_increment(angle_inc) print("collecting image %s, angle %f" % (img_no, start_at)) if start_at >= stop_angle: - init_pos = start_at #- self.acq_speed * self.turnback_time + init_pos = start_at # - self.acq_speed * self.turnback_time # init_pos = start_at - 1.5 else: - init_pos = start_at #+ self.acq_speed * self.turnback_time + init_pos = start_at # + self.acq_speed * self.turnback_time # init_pos = start_at + 1.5 # self.omega_mv(init_pos, self.default_speed) self.collect_std_collection(start_at, stop_angle) - #This part goes to standard collection. Otherwise it produces phantom openings. + # This part goes to standard collection. Otherwise it produces phantom openings. # diffr.set_omega_velocity(self.default_speed) # self.acq_window_off_cmd() # self.acq_off_cmd() - self.log.debug("======= collect_characterisation Waiting =======================================") + self.log.debug( + "======= collect_characterisation Waiting =======================================" + ) - #Let adxv know whether it is + # Let adxv know whether it is # self.adxv_notify(self.latest_h5_filename,img_no+1) - + # time.sleep(1) def adxv_notify(self, image_filename, image_num=1): @@ -469,14 +473,14 @@ def acquisition_cleanup(self): detector.stop_acquisition() diffr.wait_omega() # ================= - #It is probably already finished in a standard collection. + # It is probably already finished in a standard collection. self.acq_off_cmd() self.acq_window_off_cmd() # ================== diffr.set_omega_velocity(self.default_speed) self.log.debug("#COLLECT# Closing detector cover") diffr.detector_cover_close(wait=True) - + except RuntimeError: self.log.error(traceback.format_exc()) diff --git a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py index 1f1e208f20..ec9c9e480e 100644 --- a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py +++ b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py @@ -44,13 +44,14 @@ class P11DetectorCover(AbstractShutter): @unique class BaseValueEnum(Enum): - """Defines only the compulsory values.""" - OPEN = "OPEN" - CLOSED = "CLOSED" - MOVING = "MOVING" - UNKNOWN = "UNKNOWN" - - VALUES=BaseValueEnum + """Defines only the compulsory values.""" + + OPEN = "OPEN" + CLOSED = "CLOSED" + MOVING = "MOVING" + UNKNOWN = "UNKNOWN" + + VALUES = BaseValueEnum def __init__(self, name): @@ -196,7 +197,7 @@ def simulated_update(self): self.update_value(value) return value - + @property def is_closed(self): """Check if the shutter is closed. diff --git a/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py b/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py index 28f3399e25..058ddc6784 100644 --- a/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py +++ b/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py @@ -56,17 +56,14 @@ def _run_edna(self, input_file, results_file, process_directory): # subprocess.call("%s %s %s %s" % args, shell=True) # Test run DESY - self.edna_maxwell(process_directory,input_file, results_file) - - + self.edna_maxwell(process_directory, input_file, results_file) self.result = None if os.path.exists(results_file): self.result = XSDataResultMXCuBE.parseFile(results_file) return self.result - - + def edna_maxwell(self, process_directory, inputxml, outputxml): """ The function `edna_maxwell` is used to execute a command on a remote cluster using SSH and SBATCH. @@ -125,7 +122,11 @@ def edna_maxwell(self, process_directory, inputxml, outputxml): ) ) - print('{ssh:s} "{sbatch:s} --wrap \\"{cmd:s}"\\"'.format(ssh=ssh, sbatch=sbatch, cmd=cmd)) + print( + '{ssh:s} "{sbatch:s} --wrap \\"{cmd:s}"\\"'.format( + ssh=ssh, sbatch=sbatch, cmd=cmd + ) + ) os.system( '{ssh:s} "{sbatch:s} --wrap \\"{cmd:s}"\\"'.format( @@ -257,10 +258,12 @@ def input_from_params(self, data_collection, char_params): data_set = XSDataMXCuBEDataSet() acquisition_parameters = data_collection.acquisitions[0].acquisition_parameters path_template = data_collection.acquisitions[0].path_template - - #Make sure there is a proper path conversion between different mount points - print("======= Characterisation path template ====", path_template.directory) #/gpfs/current/raw - + + # Make sure there is a proper path conversion between different mount points + print( + "======= Characterisation path template ====", path_template.directory + ) # /gpfs/current/raw + image_dir = path_template.directory.replace( "/gpfs/current", triggerUtils.get_beamtime_metadata()[2] ) @@ -269,11 +272,11 @@ def input_from_params(self, data_collection, char_params): path_str = os.path.join(image_dir, path_template.get_image_file_name()) print(path_template.xds_dir) - + characterisation_dir = path_template.xds_dir.replace( "/autoprocessing_", "/characterisation_" ) - + os.makedirs(characterisation_dir, mode=0o755, exist_ok=True) for img_num in range(int(acquisition_parameters.num_images)): diff --git a/mxcubecore/HardwareObjects/DESY/P11Flux.py b/mxcubecore/HardwareObjects/DESY/P11Flux.py index ae64c4ca83..d1475ab6f4 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Flux.py +++ b/mxcubecore/HardwareObjects/DESY/P11Flux.py @@ -44,7 +44,7 @@ def init(self): def get_value(self): """Get flux at current transmission in units of photons/s""" - + """ FLUX IS CHEETED HERE - NOWERE ELSE!""" return self.current_flux_dict["flux"] diff --git a/mxcubecore/HardwareObjects/DESY/P11Session.py b/mxcubecore/HardwareObjects/DESY/P11Session.py index f2fdfce8b0..05fecad4d8 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Session.py +++ b/mxcubecore/HardwareObjects/DESY/P11Session.py @@ -87,11 +87,17 @@ def info_set_defaults(self): def is_beamtime_open(self): self.log.debug("=========== CHECKING IF BEAMTIME ID IS OPEN... ============") if self.is_writable_dir(os.path.join(PATH_BEAMTIME, self.raw_data_folder_name)): - self.log.debug("=========== BEAMTIME IS OPEN (/gpfs/current exists) ============") + self.log.debug( + "=========== BEAMTIME IS OPEN (/gpfs/current exists) ============" + ) else: - self.log.debug("=========== NO BEMTIME ID IS OPEN (check /gpfs/current) ============") - - return self.is_writable_dir( os.path.join(PATH_BEAMTIME, self.raw_data_folder_name) ) + self.log.debug( + "=========== NO BEMTIME ID IS OPEN (check /gpfs/current) ============" + ) + + return self.is_writable_dir( + os.path.join(PATH_BEAMTIME, self.raw_data_folder_name) + ) def is_commissioning_open(self): return self.is_writable_dir( diff --git a/mxcubecore/HardwareObjects/DESY/P11Shutter.py b/mxcubecore/HardwareObjects/DESY/P11Shutter.py index 8202549f10..90e81aec28 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Shutter.py +++ b/mxcubecore/HardwareObjects/DESY/P11Shutter.py @@ -41,13 +41,14 @@ class P11Shutter(AbstractShutter): @unique class BaseValueEnum(Enum): - """Defines only the compulsory values.""" - OPEN = "OPEN" - CLOSED = "CLOSED" - MOVING = "MOVING" - UNKNOWN = "UNKNOWN" - - VALUES=BaseValueEnum + """Defines only the compulsory values.""" + + OPEN = "OPEN" + CLOSED = "CLOSED" + MOVING = "MOVING" + UNKNOWN = "UNKNOWN" + + VALUES = BaseValueEnum def __init__(self, name): @@ -109,8 +110,8 @@ def _set_value(self, value): self.simulated_opened = open_it self.simulated_moving = True self.t1 = gevent.spawn(self.simul_do) - self.t1.link(self.do_finish) - self.t1.link_exception(self.do_finish_exc) + self.t1.link(self.do_finish) + self.t1.link_exception(self.do_finish_exc) else: if open_it: self.do_open() @@ -139,6 +140,7 @@ def simul_do(self): def do_finish(self, t=None): self.log.debug("### simulated finished") + def do_finish_exc(self, exc=None): self.log.debug("### simulated finished with exception") From 41adec37b151cf7bc5bd6ea982ece600220fbd52 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Tue, 17 Oct 2023 16:25:29 +0200 Subject: [PATCH 100/151] Add empty store_robot_action for P11 (temp fix due to ISPyB tests). --- mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py b/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py index 3a6e24119e..3225c34dda 100644 --- a/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py +++ b/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py @@ -38,6 +38,10 @@ def store_image(self, image_dict): self.prepare_image_for_lims(image_dict) return ISPyBClient.store_image(self, image_dict) + def store_robot_action(self, robot_action_dict): + #TODO ISPyB is not ready for now. This prevents from error 500 from the server. + pass + def prepare_collect_for_lims(self, mx_collect_dict): # Attention! directory passed by reference. modified in place From 3956097c239ba461c5c3bbf73d612ed8bdf99635 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 25 Oct 2023 14:34:51 +0200 Subject: [PATCH 101/151] Fix in AbstractSampleChanger that was causing sample not loaded error at P11 even if everything was ok (Bixente). --- mxcubecore/HardwareObjects/DESY/P11SampleChanger.py | 2 ++ .../HardwareObjects/abstract/AbstractSampleChanger.py | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11SampleChanger.py b/mxcubecore/HardwareObjects/DESY/P11SampleChanger.py index 2ec48d57ab..5afe2710f6 100644 --- a/mxcubecore/HardwareObjects/DESY/P11SampleChanger.py +++ b/mxcubecore/HardwareObjects/DESY/P11SampleChanger.py @@ -205,6 +205,7 @@ def load(self, sample=None, wait=True): "Sample changer: Sample loaded (total time: %s)" % (time.time() - self._start_load) ) + self.emit("progressStop", ()) return self.get_loaded_sample() @@ -476,6 +477,7 @@ def _update_selection(self): # find sample for s in self.get_sample_list(): + print(f"Sample coords = {s.get_coords()}") if s.get_coords() == (basket, sample): self.log.debug(" - sample found") self._set_loaded_sample(s) diff --git a/mxcubecore/HardwareObjects/abstract/AbstractSampleChanger.py b/mxcubecore/HardwareObjects/abstract/AbstractSampleChanger.py index 3d579431ea..b8c26edaf0 100644 --- a/mxcubecore/HardwareObjects/abstract/AbstractSampleChanger.py +++ b/mxcubecore/HardwareObjects/abstract/AbstractSampleChanger.py @@ -806,8 +806,10 @@ def _set_loaded_sample(self, sample): if smp != sample: smp._set_loaded(False) else: - if self.get_loaded_sample() == smp: - smp._set_loaded(True) + self.log.debug(f" Found sample {smp} is loaded") + self.log.debug(f" getting loaded {self.get_loaded_sample()}") + #if self.get_loaded_sample() == smp: + smp._set_loaded(True) if previous_loaded != self.get_loaded_sample(): self._trigger_loaded_sample_changed_event(sample) From c3b5452571feb1ab77917618ed0d9b7e975dee04 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Mon, 18 Sep 2023 12:11:42 +0200 Subject: [PATCH 102/151] Fixing the ambiguity with Poller value and .any --- mxcubecore/Command/Tango.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mxcubecore/Command/Tango.py b/mxcubecore/Command/Tango.py index c164eb8017..0c23a3182d 100644 --- a/mxcubecore/Command/Tango.py +++ b/mxcubecore/Command/Tango.py @@ -21,6 +21,7 @@ import logging import gevent import gevent.event +import numpy as np try: import Queue as queue @@ -315,7 +316,7 @@ def get_info(self): self._device_initialized.wait(timeout=3) return self.device.get_attribute_config(self.attribute_name) - def update(self, value=Poller.NotInitializedValue): + # start with checking if we have a numpy array, as comparing # numpy.ndarray to Poller.NotInitializedValue raises a ValueError exception @@ -329,6 +330,7 @@ def update(self, value=Poller.NotInitializedValue): self.value = value self.emit("update", value) + def get_value(self): if self.read_as_str: value = self.device.read_attribute( From 5d45193c39b2654322bc610e8175dcf855ebb154 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Mon, 18 Sep 2023 12:42:20 +0200 Subject: [PATCH 103/151] P11Collect additional debug after upgrade --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 83 ++++++++++++++++++- 1 file changed, 81 insertions(+), 2 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index b13044b47e..8ab92d48d4 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -56,21 +56,34 @@ class P11Collect(AbstractCollect): + def __init__(self, *args): super(P11Collect, self).__init__(*args) def init(self): +<<<<<<< HEAD super(P11Collect, self).init() +======= + super(P11Collect,self).init() +>>>>>>> P11Collect additional debug after upgrade # os.system("/opt/xray/bin/adxv -socket -colors Gray -rings &") # os.system("/bin/bash /gpfs/local/shared/MXCuBE/STRELA/start_viewer_zmq.sh") +<<<<<<< HEAD self.default_speed = self.get_property("omega_default_speed", 130) self.turnback_time = self.get_property("turnback_time", 0.3) self.filter_server_name = self.get_property("filterserver") self.mono_server_name = self.get_property("monoserver") +======= + + self.default_speed = self.get_property("omega_default_speed", 130) + self.turnback_time = self.get_property("turnback_time", 0.3) + self.filter_server_name = self.get_property('filterserver') + self.mono_server_name = self.get_property('monoserver') +>>>>>>> P11Collect additional debug after upgrade self.filter_server = DeviceProxy(self.filter_server_name) self.mono_server = DeviceProxy(self.mono_server_name) @@ -82,6 +95,7 @@ def init(self): self.acq_off_cmd = self.get_command_object("acq_off") self.acq_window_off_cmd = self.get_command_object("acq_window_off") +<<<<<<< HEAD if None in [ self.lower_bound_ch, self.upper_bound_ch, @@ -90,6 +104,11 @@ def init(self): self.acq_off_cmd, self.acq_window_off_cmd, ]: +======= + if None in [self.lower_bound_ch, self.upper_bound_ch, + self.acq_arm_cmd, self.acq_on_cmd, self.acq_off_cmd, + self.acq_window_off_cmd]: +>>>>>>> P11Collect additional debug after upgrade self.init_ok = False self.log.debug("lower_bound_ch: %s" % self.lower_bound_ch) self.log.debug("upper_bound_ch: %s" % self.upper_bound_ch) @@ -99,7 +118,6 @@ def init(self): self.log.debug("acq_window_off_cmd: %s" % self.acq_window_off_cmd) else: self.init_ok = True - @task def move_motors(self, motor_position_dict): HWR.beamline.diffractometer.wait_omega() @@ -351,6 +369,7 @@ def collect_std_collection(self, start_angle, stop_angle): """ HWR.beamline.diffractometer.wait_omega() +<<<<<<< HEAD start_pos = start_angle - self.turnback_time * self.acq_speed stop_pos = stop_angle + self.turnback_time * self.acq_speed @@ -363,6 +382,23 @@ def collect_std_collection(self, start_angle, stop_angle): self.lower_bound_ch.set_value(stop_angle) self.upper_bound_ch.set_value(start_angle) +======= + start_pos = start_angle - self.turnback_time*self.acq_speed + stop_pos = stop_angle + self.turnback_time*self.acq_speed + + + + self.log.debug("#COLLECT# Running OMEGA through the std acquisition") + if start_angle <= stop_angle: + self.lower_bound_ch.set_value(start_angle) + self.upper_bound_ch.set_value(stop_angle) + + else: + self.lower_bound_ch.set_value(stop_angle) + self.upper_bound_ch.set_value(start_angle) + + +>>>>>>> P11Collect additional debug after upgrade self.omega_mv(start_pos, self.default_speed) self.acq_arm_cmd() self.omega_mv(stop_pos, self.acq_speed) @@ -371,6 +407,10 @@ def collect_std_collection(self, start_angle, stop_angle): self.acq_window_off_cmd() self.omega_mv(stop_angle, self.acq_speed) HWR.beamline.diffractometer.wait_omega() +<<<<<<< HEAD +======= + +>>>>>>> P11Collect additional debug after upgrade def collect_characterisation( self, start_angle, img_range, nimages, angle_inc, exp_time @@ -391,9 +431,13 @@ def collect_characterisation( diffr = HWR.beamline.diffractometer +<<<<<<< HEAD self.log.debug( "#COLLECT# Running OMEGA through the characteristation acquisition" ) +======= + self.log.debug("#COLLECT# Running OMEGA through the characteristation acquisition") +>>>>>>> P11Collect additional debug after upgrade self.omega_mv(start_angle, self.default_speed) @@ -401,6 +445,7 @@ def collect_characterisation( print("collecting image %s" % img_no) start_at = start_angle + angle_inc * img_no stop_angle = start_at + img_range * 1.0 +<<<<<<< HEAD # print("======= CHARACTERISATION Adding angle and range to the header...") # Add start angle to the header # detector = HWR.beamline.detector @@ -408,19 +453,36 @@ def collect_characterisation( # Add angle increment to the header # detector.set_eiger_angle_increment(angle_inc) +======= + #print("======= CHARACTERISATION Adding angle and range to the header...") + #Add start angle to the header + #detector = HWR.beamline.detector + #detector.set_eiger_start_angle(start_at) + + # Add angle increment to the header + #detector.set_eiger_angle_increment(angle_inc) +>>>>>>> P11Collect additional debug after upgrade print("collecting image %s, angle %f" % (img_no, start_at)) if start_at >= stop_angle: +<<<<<<< HEAD init_pos = start_at # - self.acq_speed * self.turnback_time # init_pos = start_at - 1.5 else: init_pos = start_at # + self.acq_speed * self.turnback_time +======= + init_pos = start_at #- self.acq_speed * self.turnback_time + # init_pos = start_at - 1.5 + else: + init_pos = start_at #+ self.acq_speed * self.turnback_time +>>>>>>> P11Collect additional debug after upgrade # init_pos = start_at + 1.5 # self.omega_mv(init_pos, self.default_speed) self.collect_std_collection(start_at, stop_angle) +<<<<<<< HEAD # This part goes to standard collection. Otherwise it produces phantom openings. # diffr.set_omega_velocity(self.default_speed) # self.acq_window_off_cmd() @@ -428,9 +490,18 @@ def collect_characterisation( self.log.debug( "======= collect_characterisation Waiting =======================================" ) +======= + #This part goes to standard collection. Otherwise it produces phantom openings. + # diffr.set_omega_velocity(self.default_speed) + # self.acq_window_off_cmd() + # self.acq_off_cmd() + self.log.debug("======= collect_characterisation Waiting =======================================") +>>>>>>> P11Collect additional debug after upgrade - # Let adxv know whether it is + #Let adxv know whether it is # self.adxv_notify(self.latest_h5_filename,img_no+1) + + # time.sleep(1) # time.sleep(1) @@ -473,14 +544,22 @@ def acquisition_cleanup(self): detector.stop_acquisition() diffr.wait_omega() # ================= +<<<<<<< HEAD # It is probably already finished in a standard collection. +======= + #It is probably already finished in a standard collection. +>>>>>>> P11Collect additional debug after upgrade self.acq_off_cmd() self.acq_window_off_cmd() # ================== diffr.set_omega_velocity(self.default_speed) self.log.debug("#COLLECT# Closing detector cover") diffr.detector_cover_close(wait=True) +<<<<<<< HEAD +======= + +>>>>>>> P11Collect additional debug after upgrade except RuntimeError: self.log.error(traceback.format_exc()) From 81f2018721f5792eca54da628c7cd951349337f1 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 09:53:30 +0200 Subject: [PATCH 104/151] Force upgrade from the develop to avoid merging conflict --- mxcubecore/Command/Tango.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mxcubecore/Command/Tango.py b/mxcubecore/Command/Tango.py index 0c23a3182d..c164eb8017 100644 --- a/mxcubecore/Command/Tango.py +++ b/mxcubecore/Command/Tango.py @@ -21,7 +21,6 @@ import logging import gevent import gevent.event -import numpy as np try: import Queue as queue @@ -316,7 +315,7 @@ def get_info(self): self._device_initialized.wait(timeout=3) return self.device.get_attribute_config(self.attribute_name) - + def update(self, value=Poller.NotInitializedValue): # start with checking if we have a numpy array, as comparing # numpy.ndarray to Poller.NotInitializedValue raises a ValueError exception @@ -330,7 +329,6 @@ def get_info(self): self.value = value self.emit("update", value) - def get_value(self): if self.read_as_str: value = self.device.read_attribute( From dbbe6d470de5086f63da252c34fd8b3b9c6d3f38 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 11:20:37 +0200 Subject: [PATCH 105/151] Enabled back explicit check on if beamtimeid is open --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 75 ------------------- 1 file changed, 75 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index 8ab92d48d4..4103ca830a 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -62,28 +62,17 @@ def __init__(self, *args): def init(self): -<<<<<<< HEAD - super(P11Collect, self).init() -======= super(P11Collect,self).init() ->>>>>>> P11Collect additional debug after upgrade # os.system("/opt/xray/bin/adxv -socket -colors Gray -rings &") # os.system("/bin/bash /gpfs/local/shared/MXCuBE/STRELA/start_viewer_zmq.sh") -<<<<<<< HEAD - self.default_speed = self.get_property("omega_default_speed", 130) - self.turnback_time = self.get_property("turnback_time", 0.3) - self.filter_server_name = self.get_property("filterserver") - self.mono_server_name = self.get_property("monoserver") -======= self.default_speed = self.get_property("omega_default_speed", 130) self.turnback_time = self.get_property("turnback_time", 0.3) self.filter_server_name = self.get_property('filterserver') self.mono_server_name = self.get_property('monoserver') ->>>>>>> P11Collect additional debug after upgrade self.filter_server = DeviceProxy(self.filter_server_name) self.mono_server = DeviceProxy(self.mono_server_name) @@ -95,7 +84,6 @@ def init(self): self.acq_off_cmd = self.get_command_object("acq_off") self.acq_window_off_cmd = self.get_command_object("acq_window_off") -<<<<<<< HEAD if None in [ self.lower_bound_ch, self.upper_bound_ch, @@ -104,11 +92,6 @@ def init(self): self.acq_off_cmd, self.acq_window_off_cmd, ]: -======= - if None in [self.lower_bound_ch, self.upper_bound_ch, - self.acq_arm_cmd, self.acq_on_cmd, self.acq_off_cmd, - self.acq_window_off_cmd]: ->>>>>>> P11Collect additional debug after upgrade self.init_ok = False self.log.debug("lower_bound_ch: %s" % self.lower_bound_ch) self.log.debug("upper_bound_ch: %s" % self.upper_bound_ch) @@ -369,20 +352,6 @@ def collect_std_collection(self, start_angle, stop_angle): """ HWR.beamline.diffractometer.wait_omega() -<<<<<<< HEAD - start_pos = start_angle - self.turnback_time * self.acq_speed - stop_pos = stop_angle + self.turnback_time * self.acq_speed - - self.log.debug("#COLLECT# Running OMEGA through the std acquisition") - if start_angle <= stop_angle: - self.lower_bound_ch.set_value(start_angle) - self.upper_bound_ch.set_value(stop_angle) - - else: - self.lower_bound_ch.set_value(stop_angle) - self.upper_bound_ch.set_value(start_angle) - -======= start_pos = start_angle - self.turnback_time*self.acq_speed stop_pos = stop_angle + self.turnback_time*self.acq_speed @@ -398,7 +367,6 @@ def collect_std_collection(self, start_angle, stop_angle): self.upper_bound_ch.set_value(start_angle) ->>>>>>> P11Collect additional debug after upgrade self.omega_mv(start_pos, self.default_speed) self.acq_arm_cmd() self.omega_mv(stop_pos, self.acq_speed) @@ -407,10 +375,6 @@ def collect_std_collection(self, start_angle, stop_angle): self.acq_window_off_cmd() self.omega_mv(stop_angle, self.acq_speed) HWR.beamline.diffractometer.wait_omega() -<<<<<<< HEAD -======= - ->>>>>>> P11Collect additional debug after upgrade def collect_characterisation( self, start_angle, img_range, nimages, angle_inc, exp_time @@ -431,13 +395,9 @@ def collect_characterisation( diffr = HWR.beamline.diffractometer -<<<<<<< HEAD self.log.debug( "#COLLECT# Running OMEGA through the characteristation acquisition" ) -======= - self.log.debug("#COLLECT# Running OMEGA through the characteristation acquisition") ->>>>>>> P11Collect additional debug after upgrade self.omega_mv(start_angle, self.default_speed) @@ -445,15 +405,6 @@ def collect_characterisation( print("collecting image %s" % img_no) start_at = start_angle + angle_inc * img_no stop_angle = start_at + img_range * 1.0 -<<<<<<< HEAD - # print("======= CHARACTERISATION Adding angle and range to the header...") - # Add start angle to the header - # detector = HWR.beamline.detector - # detector.set_eiger_start_angle(start_at) - - # Add angle increment to the header - # detector.set_eiger_angle_increment(angle_inc) -======= #print("======= CHARACTERISATION Adding angle and range to the header...") #Add start angle to the header #detector = HWR.beamline.detector @@ -461,42 +412,24 @@ def collect_characterisation( # Add angle increment to the header #detector.set_eiger_angle_increment(angle_inc) ->>>>>>> P11Collect additional debug after upgrade print("collecting image %s, angle %f" % (img_no, start_at)) if start_at >= stop_angle: -<<<<<<< HEAD - init_pos = start_at # - self.acq_speed * self.turnback_time - # init_pos = start_at - 1.5 - else: - init_pos = start_at # + self.acq_speed * self.turnback_time -======= init_pos = start_at #- self.acq_speed * self.turnback_time # init_pos = start_at - 1.5 else: init_pos = start_at #+ self.acq_speed * self.turnback_time ->>>>>>> P11Collect additional debug after upgrade # init_pos = start_at + 1.5 # self.omega_mv(init_pos, self.default_speed) self.collect_std_collection(start_at, stop_angle) -<<<<<<< HEAD - # This part goes to standard collection. Otherwise it produces phantom openings. - # diffr.set_omega_velocity(self.default_speed) - # self.acq_window_off_cmd() - # self.acq_off_cmd() - self.log.debug( - "======= collect_characterisation Waiting =======================================" - ) -======= #This part goes to standard collection. Otherwise it produces phantom openings. # diffr.set_omega_velocity(self.default_speed) # self.acq_window_off_cmd() # self.acq_off_cmd() self.log.debug("======= collect_characterisation Waiting =======================================") ->>>>>>> P11Collect additional debug after upgrade #Let adxv know whether it is # self.adxv_notify(self.latest_h5_filename,img_no+1) @@ -544,22 +477,14 @@ def acquisition_cleanup(self): detector.stop_acquisition() diffr.wait_omega() # ================= -<<<<<<< HEAD - # It is probably already finished in a standard collection. -======= #It is probably already finished in a standard collection. ->>>>>>> P11Collect additional debug after upgrade self.acq_off_cmd() self.acq_window_off_cmd() # ================== diffr.set_omega_velocity(self.default_speed) self.log.debug("#COLLECT# Closing detector cover") diffr.detector_cover_close(wait=True) -<<<<<<< HEAD - -======= ->>>>>>> P11Collect additional debug after upgrade except RuntimeError: self.log.error(traceback.format_exc()) From a8017469a8da09508a8a728ec58cdd155b11960d Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 11:29:10 +0200 Subject: [PATCH 106/151] Added debug info in case beamtime ID is not opened --- mxcubecore/HardwareObjects/DESY/P11Session.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Session.py b/mxcubecore/HardwareObjects/DESY/P11Session.py index 05fecad4d8..f2fdfce8b0 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Session.py +++ b/mxcubecore/HardwareObjects/DESY/P11Session.py @@ -87,17 +87,11 @@ def info_set_defaults(self): def is_beamtime_open(self): self.log.debug("=========== CHECKING IF BEAMTIME ID IS OPEN... ============") if self.is_writable_dir(os.path.join(PATH_BEAMTIME, self.raw_data_folder_name)): - self.log.debug( - "=========== BEAMTIME IS OPEN (/gpfs/current exists) ============" - ) + self.log.debug("=========== BEAMTIME IS OPEN (/gpfs/current exists) ============") else: - self.log.debug( - "=========== NO BEMTIME ID IS OPEN (check /gpfs/current) ============" - ) - - return self.is_writable_dir( - os.path.join(PATH_BEAMTIME, self.raw_data_folder_name) - ) + self.log.debug("=========== NO BEMTIME ID IS OPEN (check /gpfs/current) ============") + + return self.is_writable_dir( os.path.join(PATH_BEAMTIME, self.raw_data_folder_name) ) def is_commissioning_open(self): return self.is_writable_dir( From 9f87b9d23292a835ce41fecd8e63743fc8c86b04 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 16:59:56 +0200 Subject: [PATCH 107/151] Added additional debug messages for shutter --- mxcubecore/HardwareObjects/DESY/P11Shutter.py | 1 - 1 file changed, 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Shutter.py b/mxcubecore/HardwareObjects/DESY/P11Shutter.py index 90e81aec28..b35ad5b689 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Shutter.py +++ b/mxcubecore/HardwareObjects/DESY/P11Shutter.py @@ -153,7 +153,6 @@ def update_shutter_state(self, state=None): state = self.chan_state.get_value() self.log.debug(" SHUTTER state changed") - if state[0] == 3: self.log.debug(" P11SHUTTER IS OPEN") value = self.VALUES.OPEN From d5230fc25b70f8011c869c708806eac95a850700 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 17:06:43 +0200 Subject: [PATCH 108/151] Removed is_open() as a function and assigned is_closed() as a property for shutter-like objects inside P11 HO (Bixente) --- mxcubecore/HardwareObjects/DESY/P11DetectorCover.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py index ec9c9e480e..5555ae015d 100644 --- a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py +++ b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py @@ -197,7 +197,7 @@ def simulated_update(self): self.update_value(value) return value - + @property def is_closed(self): """Check if the shutter is closed. From fa994b169149d6fafc0595d8ed896b483962234a Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Thu, 5 Oct 2023 15:35:55 +0200 Subject: [PATCH 109/151] Fixed shutter openning wainting forever (Bixente) --- mxcubecore/HardwareObjects/DESY/P11Shutter.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Shutter.py b/mxcubecore/HardwareObjects/DESY/P11Shutter.py index b35ad5b689..05ad9b7709 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Shutter.py +++ b/mxcubecore/HardwareObjects/DESY/P11Shutter.py @@ -110,8 +110,13 @@ def _set_value(self, value): self.simulated_opened = open_it self.simulated_moving = True self.t1 = gevent.spawn(self.simul_do) +<<<<<<< HEAD self.t1.link(self.do_finish) self.t1.link_exception(self.do_finish_exc) +======= + self.t1.link(self.do_finish) + self.t1.link_exception(self.do_finish_exc) +>>>>>>> Fixed shutter openning wainting forever (Bixente) else: if open_it: self.do_open() @@ -140,7 +145,6 @@ def simul_do(self): def do_finish(self, t=None): self.log.debug("### simulated finished") - def do_finish_exc(self, exc=None): self.log.debug("### simulated finished with exception") @@ -153,6 +157,7 @@ def update_shutter_state(self, state=None): state = self.chan_state.get_value() self.log.debug(" SHUTTER state changed") + if state[0] == 3: self.log.debug(" P11SHUTTER IS OPEN") value = self.VALUES.OPEN From deb07e950d4adf534e12346876fcd93ed8725894 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Fri, 6 Oct 2023 17:32:07 +0200 Subject: [PATCH 110/151] Added preliminary flux HO for P11 --- mxcubecore/HardwareObjects/DESY/P11Flux.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Flux.py b/mxcubecore/HardwareObjects/DESY/P11Flux.py index d1475ab6f4..ae64c4ca83 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Flux.py +++ b/mxcubecore/HardwareObjects/DESY/P11Flux.py @@ -44,7 +44,7 @@ def init(self): def get_value(self): """Get flux at current transmission in units of photons/s""" - + """ FLUX IS CHEETED HERE - NOWERE ELSE!""" return self.current_flux_dict["flux"] From 1aeb1f7a10267406af6f4d15d3c0045d416c31d7 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Fri, 6 Oct 2023 19:18:03 +0200 Subject: [PATCH 111/151] Upgraded the characterisation part for P11 using EDNA --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 3 +- .../DESY/P11EDNACharacterisation.py | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index 4103ca830a..1cb19e715a 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -131,6 +131,7 @@ def data_collection_hook(self): self.diffr = HWR.beamline.diffractometer detector = HWR.beamline.detector + dc_pars = self.current_dc_parameters collection_type = dc_pars["experiment_type"] @@ -204,7 +205,7 @@ def data_collection_hook(self): ) # Filepath to the EDNA processing - # filepath = os.path.join(basepath,"%s_%d" % (prefix, runno)) + #filepath = os.path.join(basepath,"%s_%d" % (prefix, runno)) # setting up xds_dir for characterisation (used there internally to create dirs) self.current_dc_parameters["xds_dir"] = os.path.join( diff --git a/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py b/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py index 058ddc6784..1804d5ddae 100644 --- a/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py +++ b/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py @@ -56,14 +56,25 @@ def _run_edna(self, input_file, results_file, process_directory): # subprocess.call("%s %s %s %s" % args, shell=True) # Test run DESY +<<<<<<< HEAD self.edna_maxwell(process_directory, input_file, results_file) +======= + self.edna_maxwell(process_directory,input_file, results_file) + + +>>>>>>> Upgraded the characterisation part for P11 using EDNA self.result = None if os.path.exists(results_file): self.result = XSDataResultMXCuBE.parseFile(results_file) return self.result +<<<<<<< HEAD +======= + + +>>>>>>> Upgraded the characterisation part for P11 using EDNA def edna_maxwell(self, process_directory, inputxml, outputxml): """ The function `edna_maxwell` is used to execute a command on a remote cluster using SSH and SBATCH. @@ -122,11 +133,15 @@ def edna_maxwell(self, process_directory, inputxml, outputxml): ) ) +<<<<<<< HEAD print( '{ssh:s} "{sbatch:s} --wrap \\"{cmd:s}"\\"'.format( ssh=ssh, sbatch=sbatch, cmd=cmd ) ) +======= + print('{ssh:s} "{sbatch:s} --wrap \\"{cmd:s}"\\"'.format(ssh=ssh, sbatch=sbatch, cmd=cmd)) +>>>>>>> Upgraded the characterisation part for P11 using EDNA os.system( '{ssh:s} "{sbatch:s} --wrap \\"{cmd:s}"\\"'.format( @@ -258,25 +273,42 @@ def input_from_params(self, data_collection, char_params): data_set = XSDataMXCuBEDataSet() acquisition_parameters = data_collection.acquisitions[0].acquisition_parameters path_template = data_collection.acquisitions[0].path_template +<<<<<<< HEAD # Make sure there is a proper path conversion between different mount points print( "======= Characterisation path template ====", path_template.directory ) # /gpfs/current/raw +======= + + #Make sure there is a proper path conversion between different mount points + print("======= Characterisation path template ====", path_template.directory) #/gpfs/current/raw + +>>>>>>> Upgraded the characterisation part for P11 using EDNA image_dir = path_template.directory.replace( "/gpfs/current", triggerUtils.get_beamtime_metadata()[2] ) print(image_dir) +<<<<<<< HEAD path_str = os.path.join(image_dir, path_template.get_image_file_name()) print(path_template.xds_dir) +======= +>>>>>>> Upgraded the characterisation part for P11 using EDNA + path_str = os.path.join(image_dir, path_template.get_image_file_name()) + print(path_template.xds_dir) + characterisation_dir = path_template.xds_dir.replace( "/autoprocessing_", "/characterisation_" ) +<<<<<<< HEAD +======= + +>>>>>>> Upgraded the characterisation part for P11 using EDNA os.makedirs(characterisation_dir, mode=0o755, exist_ok=True) for img_num in range(int(acquisition_parameters.num_images)): From 23922d284b529254f132ef25abc2791d3a6b98c6 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Fri, 6 Oct 2023 22:57:55 +0200 Subject: [PATCH 112/151] Linting --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 57 +++++++++---------- .../HardwareObjects/DESY/P11DetectorCover.py | 2 +- .../DESY/P11EDNACharacterisation.py | 32 ++--------- mxcubecore/HardwareObjects/DESY/P11Flux.py | 2 +- mxcubecore/HardwareObjects/DESY/P11Session.py | 14 +++-- mxcubecore/HardwareObjects/DESY/P11Shutter.py | 6 +- 6 files changed, 44 insertions(+), 69 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index 1cb19e715a..d27da914ba 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -56,23 +56,21 @@ class P11Collect(AbstractCollect): - def __init__(self, *args): super(P11Collect, self).__init__(*args) def init(self): - super(P11Collect,self).init() + super(P11Collect, self).init() # os.system("/opt/xray/bin/adxv -socket -colors Gray -rings &") # os.system("/bin/bash /gpfs/local/shared/MXCuBE/STRELA/start_viewer_zmq.sh") - self.default_speed = self.get_property("omega_default_speed", 130) self.turnback_time = self.get_property("turnback_time", 0.3) - self.filter_server_name = self.get_property('filterserver') - self.mono_server_name = self.get_property('monoserver') + self.filter_server_name = self.get_property("filterserver") + self.mono_server_name = self.get_property("monoserver") self.filter_server = DeviceProxy(self.filter_server_name) self.mono_server = DeviceProxy(self.mono_server_name) @@ -101,6 +99,7 @@ def init(self): self.log.debug("acq_window_off_cmd: %s" % self.acq_window_off_cmd) else: self.init_ok = True + @task def move_motors(self, motor_position_dict): HWR.beamline.diffractometer.wait_omega() @@ -131,7 +130,6 @@ def data_collection_hook(self): self.diffr = HWR.beamline.diffractometer detector = HWR.beamline.detector - dc_pars = self.current_dc_parameters collection_type = dc_pars["experiment_type"] @@ -205,7 +203,7 @@ def data_collection_hook(self): ) # Filepath to the EDNA processing - #filepath = os.path.join(basepath,"%s_%d" % (prefix, runno)) + # filepath = os.path.join(basepath,"%s_%d" % (prefix, runno)) # setting up xds_dir for characterisation (used there internally to create dirs) self.current_dc_parameters["xds_dir"] = os.path.join( @@ -353,20 +351,17 @@ def collect_std_collection(self, start_angle, stop_angle): """ HWR.beamline.diffractometer.wait_omega() - start_pos = start_angle - self.turnback_time*self.acq_speed - stop_pos = stop_angle + self.turnback_time*self.acq_speed - - - + start_pos = start_angle - self.turnback_time * self.acq_speed + stop_pos = stop_angle + self.turnback_time * self.acq_speed + self.log.debug("#COLLECT# Running OMEGA through the std acquisition") if start_angle <= stop_angle: - self.lower_bound_ch.set_value(start_angle) - self.upper_bound_ch.set_value(stop_angle) + self.lower_bound_ch.set_value(start_angle) + self.upper_bound_ch.set_value(stop_angle) else: - self.lower_bound_ch.set_value(stop_angle) - self.upper_bound_ch.set_value(start_angle) - + self.lower_bound_ch.set_value(stop_angle) + self.upper_bound_ch.set_value(start_angle) self.omega_mv(start_pos, self.default_speed) self.acq_arm_cmd() @@ -406,35 +401,37 @@ def collect_characterisation( print("collecting image %s" % img_no) start_at = start_angle + angle_inc * img_no stop_angle = start_at + img_range * 1.0 - #print("======= CHARACTERISATION Adding angle and range to the header...") - #Add start angle to the header - #detector = HWR.beamline.detector - #detector.set_eiger_start_angle(start_at) + # print("======= CHARACTERISATION Adding angle and range to the header...") + # Add start angle to the header + # detector = HWR.beamline.detector + # detector.set_eiger_start_angle(start_at) # Add angle increment to the header - #detector.set_eiger_angle_increment(angle_inc) + # detector.set_eiger_angle_increment(angle_inc) print("collecting image %s, angle %f" % (img_no, start_at)) if start_at >= stop_angle: - init_pos = start_at #- self.acq_speed * self.turnback_time + init_pos = start_at # - self.acq_speed * self.turnback_time # init_pos = start_at - 1.5 else: - init_pos = start_at #+ self.acq_speed * self.turnback_time + init_pos = start_at # + self.acq_speed * self.turnback_time # init_pos = start_at + 1.5 # self.omega_mv(init_pos, self.default_speed) self.collect_std_collection(start_at, stop_angle) - #This part goes to standard collection. Otherwise it produces phantom openings. + # This part goes to standard collection. Otherwise it produces phantom openings. # diffr.set_omega_velocity(self.default_speed) # self.acq_window_off_cmd() # self.acq_off_cmd() - self.log.debug("======= collect_characterisation Waiting =======================================") + self.log.debug( + "======= collect_characterisation Waiting =======================================" + ) - #Let adxv know whether it is + # Let adxv know whether it is # self.adxv_notify(self.latest_h5_filename,img_no+1) - + # time.sleep(1) # time.sleep(1) @@ -478,14 +475,14 @@ def acquisition_cleanup(self): detector.stop_acquisition() diffr.wait_omega() # ================= - #It is probably already finished in a standard collection. + # It is probably already finished in a standard collection. self.acq_off_cmd() self.acq_window_off_cmd() # ================== diffr.set_omega_velocity(self.default_speed) self.log.debug("#COLLECT# Closing detector cover") diffr.detector_cover_close(wait=True) - + except RuntimeError: self.log.error(traceback.format_exc()) diff --git a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py index 5555ae015d..ec9c9e480e 100644 --- a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py +++ b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py @@ -197,7 +197,7 @@ def simulated_update(self): self.update_value(value) return value - + @property def is_closed(self): """Check if the shutter is closed. diff --git a/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py b/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py index 1804d5ddae..d8290ac762 100644 --- a/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py +++ b/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py @@ -56,25 +56,15 @@ def _run_edna(self, input_file, results_file, process_directory): # subprocess.call("%s %s %s %s" % args, shell=True) # Test run DESY -<<<<<<< HEAD - self.edna_maxwell(process_directory, input_file, results_file) -======= - self.edna_maxwell(process_directory,input_file, results_file) - ->>>>>>> Upgraded the characterisation part for P11 using EDNA + self.edna_maxwell(process_directory, input_file, results_file) self.result = None if os.path.exists(results_file): self.result = XSDataResultMXCuBE.parseFile(results_file) return self.result -<<<<<<< HEAD -======= - - ->>>>>>> Upgraded the characterisation part for P11 using EDNA def edna_maxwell(self, process_directory, inputxml, outputxml): """ The function `edna_maxwell` is used to execute a command on a remote cluster using SSH and SBATCH. @@ -133,15 +123,14 @@ def edna_maxwell(self, process_directory, inputxml, outputxml): ) ) -<<<<<<< HEAD + print( '{ssh:s} "{sbatch:s} --wrap \\"{cmd:s}"\\"'.format( ssh=ssh, sbatch=sbatch, cmd=cmd ) ) -======= + print('{ssh:s} "{sbatch:s} --wrap \\"{cmd:s}"\\"'.format(ssh=ssh, sbatch=sbatch, cmd=cmd)) ->>>>>>> Upgraded the characterisation part for P11 using EDNA os.system( '{ssh:s} "{sbatch:s} --wrap \\"{cmd:s}"\\"'.format( @@ -273,42 +262,29 @@ def input_from_params(self, data_collection, char_params): data_set = XSDataMXCuBEDataSet() acquisition_parameters = data_collection.acquisitions[0].acquisition_parameters path_template = data_collection.acquisitions[0].path_template -<<<<<<< HEAD + # Make sure there is a proper path conversion between different mount points print( "======= Characterisation path template ====", path_template.directory ) # /gpfs/current/raw -======= - #Make sure there is a proper path conversion between different mount points print("======= Characterisation path template ====", path_template.directory) #/gpfs/current/raw ->>>>>>> Upgraded the characterisation part for P11 using EDNA image_dir = path_template.directory.replace( "/gpfs/current", triggerUtils.get_beamtime_metadata()[2] ) print(image_dir) -<<<<<<< HEAD path_str = os.path.join(image_dir, path_template.get_image_file_name()) print(path_template.xds_dir) -======= ->>>>>>> Upgraded the characterisation part for P11 using EDNA - path_str = os.path.join(image_dir, path_template.get_image_file_name()) - print(path_template.xds_dir) - characterisation_dir = path_template.xds_dir.replace( "/autoprocessing_", "/characterisation_" ) -<<<<<<< HEAD -======= - ->>>>>>> Upgraded the characterisation part for P11 using EDNA os.makedirs(characterisation_dir, mode=0o755, exist_ok=True) for img_num in range(int(acquisition_parameters.num_images)): diff --git a/mxcubecore/HardwareObjects/DESY/P11Flux.py b/mxcubecore/HardwareObjects/DESY/P11Flux.py index ae64c4ca83..d1475ab6f4 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Flux.py +++ b/mxcubecore/HardwareObjects/DESY/P11Flux.py @@ -44,7 +44,7 @@ def init(self): def get_value(self): """Get flux at current transmission in units of photons/s""" - + """ FLUX IS CHEETED HERE - NOWERE ELSE!""" return self.current_flux_dict["flux"] diff --git a/mxcubecore/HardwareObjects/DESY/P11Session.py b/mxcubecore/HardwareObjects/DESY/P11Session.py index f2fdfce8b0..05fecad4d8 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Session.py +++ b/mxcubecore/HardwareObjects/DESY/P11Session.py @@ -87,11 +87,17 @@ def info_set_defaults(self): def is_beamtime_open(self): self.log.debug("=========== CHECKING IF BEAMTIME ID IS OPEN... ============") if self.is_writable_dir(os.path.join(PATH_BEAMTIME, self.raw_data_folder_name)): - self.log.debug("=========== BEAMTIME IS OPEN (/gpfs/current exists) ============") + self.log.debug( + "=========== BEAMTIME IS OPEN (/gpfs/current exists) ============" + ) else: - self.log.debug("=========== NO BEMTIME ID IS OPEN (check /gpfs/current) ============") - - return self.is_writable_dir( os.path.join(PATH_BEAMTIME, self.raw_data_folder_name) ) + self.log.debug( + "=========== NO BEMTIME ID IS OPEN (check /gpfs/current) ============" + ) + + return self.is_writable_dir( + os.path.join(PATH_BEAMTIME, self.raw_data_folder_name) + ) def is_commissioning_open(self): return self.is_writable_dir( diff --git a/mxcubecore/HardwareObjects/DESY/P11Shutter.py b/mxcubecore/HardwareObjects/DESY/P11Shutter.py index 05ad9b7709..297cf2b24c 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Shutter.py +++ b/mxcubecore/HardwareObjects/DESY/P11Shutter.py @@ -110,13 +110,8 @@ def _set_value(self, value): self.simulated_opened = open_it self.simulated_moving = True self.t1 = gevent.spawn(self.simul_do) -<<<<<<< HEAD - self.t1.link(self.do_finish) - self.t1.link_exception(self.do_finish_exc) -======= self.t1.link(self.do_finish) self.t1.link_exception(self.do_finish_exc) ->>>>>>> Fixed shutter openning wainting forever (Bixente) else: if open_it: self.do_open() @@ -145,6 +140,7 @@ def simul_do(self): def do_finish(self, t=None): self.log.debug("### simulated finished") + def do_finish_exc(self, exc=None): self.log.debug("### simulated finished with exception") From 5fd5872626de7eb33024059909562c38500ef7c4 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 25 Oct 2023 18:35:26 +0200 Subject: [PATCH 113/151] Added new HO for the beam representation for P11 (Bixente) --- mxcubecore/HardwareObjects/DESY/P11Beam.py | 114 +++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 mxcubecore/HardwareObjects/DESY/P11Beam.py diff --git a/mxcubecore/HardwareObjects/DESY/P11Beam.py b/mxcubecore/HardwareObjects/DESY/P11Beam.py new file mode 100644 index 0000000000..7088c2dfdb --- /dev/null +++ b/mxcubecore/HardwareObjects/DESY/P11Beam.py @@ -0,0 +1,114 @@ +# Project: MXCuBE +# https://github.com/mxcube +# +# This file is part of MXCuBE software. +# +# MXCuBE is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# MXCuBE is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with MXCuBE. If not, see . + +"""P11Beam""" + +import time +import sys +import urllib +from mxcubecore.HardwareObjects.abstract.AbstractBeam import AbstractBeam +from mxcubecore.BaseHardwareObjects import HardwareObjectState +from enum import Enum, unique + + +__credits__ = ["DESY P11"] +__license__ = "LGPLv3+" +__category__ = "General" + + +class P11Beam(AbstractBeam): + def __init__(self,*args): + super(P11Beam,self).__init__(*args) + + self._beam_size_dict = { + "aperture": [9999,9999], + "slits": [9999,9999], + } + + self._beam_position_on_screen = [340, 256] + + self.focus_sizes = { + -1: {'label': 'unknown', 'size': (0.2,0.2)}, + 0: {'label': 'flat', 'size': (0.2,0.2)}, + 1: {'label': '200x200', 'size': (0.2,0.2)}, + 2: {'label': '100x100', 'size': (0.1,0.1)}, + 3: {'label': '50x50', 'size': (0.05,0.05)}, + 4: {'label': '20x20', 'size': (0.02,0.02)}, + 5: {'label': '4x9', 'size': (0.009,0.004)}, + } + + + + def init(self): + self.mirror_idx_ch = self.get_channel_object("beamsize") + self.mirror_state_ch = self.get_channel_object("state") + + if self.mirror_idx_ch is not None: + self.mirror_idx_ch.connect_signal("update", self.mirror_idx_changed) + if self.mirror_state_ch is not None: + self.mirror_state_ch.connect_signal("update", self.mirror_state_changed) + + self.mirror_idx_changed() + self.mirror_state_changed() + + def get_beam_info_state(self): + if self.mirror_state_ch is not None: + tango_state = self.mirror_state_ch.get_value() + return self._convert_tango_state(tango_state) + + return self.STATES_READY + + def mirror_state_changed(self, state=None): + + if state is None: + state = self.get_beam_info_state() + + self.update_state( self._convert_tango_state(state) ) + + def _convert_tango_state(self, state): + str_state = str(state) + + if str_state == "ON": + _state = self.STATES.READY + elif str_state == "MOVING": + _state = self.STATES.BUSY + else: + _state = self.STATES.FAULT + return _state + + + def mirror_idx_changed(self, value=None): + + if value is None: + value = self.mirror_idx_ch.get_value() + + self.log.debug(f"P11Beam - mirror idx changed. now is {value}") + + if value not in self.focus_sizes: + value = -1 + self.log.debug(f" - UNKNOWN mirror index") + + curr_size_item = self.focus_sizes[value] + self.log.debug(f" current mirror focus is {curr_size_item['label']}: {curr_size_item['size']}") + + + self._beam_size_dict["aperture"] = curr_size_item['size'] + + self.evaluate_beam_info() + self.re_emit_values() + From 55100bcaf56ddcaaf9a54d805f90ae9acf144a8d Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 8 Nov 2023 16:26:02 +0100 Subject: [PATCH 114/151] Fix beam position update in P11 Nanodiff --- mxcubecore/HardwareObjects/DESY/P11NanoDiff.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py b/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py index 10fe34b321..f4ce1efbc8 100644 --- a/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py +++ b/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py @@ -154,7 +154,8 @@ def init(self): self.update_phase() self.update_zoom_calibration() - self.beam_position = self.update_beam_position() + #self.beam_position = self.update_beam_position() + self.update_beam_position() def update_beam_position(self): zoom_hwobj = self.motor_hwobj_dict["zoom"] From 73c9a05adf98195445af12971638b2a3d55a8d9f Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 8 Nov 2023 16:26:41 +0100 Subject: [PATCH 115/151] Minor changes --- mxcubecore/HardwareObjects/DESY/P11AlbulaView.py | 1 - 1 file changed, 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11AlbulaView.py b/mxcubecore/HardwareObjects/DESY/P11AlbulaView.py index 4062d1db26..95b2d76d3e 100644 --- a/mxcubecore/HardwareObjects/DESY/P11AlbulaView.py +++ b/mxcubecore/HardwareObjects/DESY/P11AlbulaView.py @@ -26,7 +26,6 @@ import time from PIL import Image - sys.path.append("/opt/dectris/albula/4.0/python/") from mxcubecore.BaseHardwareObjects import HardwareObject From a8d8fdfd587a0b3efb4d918fc57a684a4953bd06 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 8 Nov 2023 16:28:18 +0100 Subject: [PATCH 116/151] Added slits gap None (no slits) for P11 (Bixente) --- mxcubecore/HardwareObjects/DESY/P11Beam.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mxcubecore/HardwareObjects/DESY/P11Beam.py b/mxcubecore/HardwareObjects/DESY/P11Beam.py index 7088c2dfdb..5b4da2fa14 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Beam.py +++ b/mxcubecore/HardwareObjects/DESY/P11Beam.py @@ -73,6 +73,9 @@ def get_beam_info_state(self): return self.STATES_READY + def get_slits_gap(self): + return None, None + def mirror_state_changed(self, state=None): if state is None: From 32c0666d7845f7e11318f8a1ecd8614e87b71c12 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 8 Nov 2023 16:29:40 +0100 Subject: [PATCH 117/151] Temp fix for P11 specific routine --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index d27da914ba..ba911d31c3 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -550,6 +550,9 @@ def add_h5_info(self, h5file): except RuntimeWarning as err_msg: self.log.debug("Error while adding info to HDF5 file (%s)" % str(err_msg)) self.log.debug(traceback.format_exc()) + except Exception as err_msg: + self.log.debug("Error while adding info to HDF5 file (%s)" % str(err_msg)) + self.log.debug(traceback.format_exc()) def get_filter_thickness(self): """ From 2e722cc039536360790c32b37b5417f1367daf8f Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Mon, 18 Sep 2023 12:11:42 +0200 Subject: [PATCH 118/151] Fixing the ambiguity with Poller value and .any --- mxcubecore/Command/Tango.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mxcubecore/Command/Tango.py b/mxcubecore/Command/Tango.py index c164eb8017..0c23a3182d 100644 --- a/mxcubecore/Command/Tango.py +++ b/mxcubecore/Command/Tango.py @@ -21,6 +21,7 @@ import logging import gevent import gevent.event +import numpy as np try: import Queue as queue @@ -315,7 +316,7 @@ def get_info(self): self._device_initialized.wait(timeout=3) return self.device.get_attribute_config(self.attribute_name) - def update(self, value=Poller.NotInitializedValue): + # start with checking if we have a numpy array, as comparing # numpy.ndarray to Poller.NotInitializedValue raises a ValueError exception @@ -329,6 +330,7 @@ def update(self, value=Poller.NotInitializedValue): self.value = value self.emit("update", value) + def get_value(self): if self.read_as_str: value = self.device.read_attribute( From 8f1755e471715142acbd0bd704a4372795071b66 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Mon, 18 Sep 2023 12:42:20 +0200 Subject: [PATCH 119/151] P11Collect additional debug after upgrade --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 69 +++++++++---------- 1 file changed, 33 insertions(+), 36 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index ba911d31c3..197a7c58f1 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -56,21 +56,23 @@ class P11Collect(AbstractCollect): + def __init__(self, *args): super(P11Collect, self).__init__(*args) def init(self): - super(P11Collect, self).init() + super(P11Collect,self).init() # os.system("/opt/xray/bin/adxv -socket -colors Gray -rings &") # os.system("/bin/bash /gpfs/local/shared/MXCuBE/STRELA/start_viewer_zmq.sh") + self.default_speed = self.get_property("omega_default_speed", 130) self.turnback_time = self.get_property("turnback_time", 0.3) - self.filter_server_name = self.get_property("filterserver") - self.mono_server_name = self.get_property("monoserver") + self.filter_server_name = self.get_property('filterserver') + self.mono_server_name = self.get_property('monoserver') self.filter_server = DeviceProxy(self.filter_server_name) self.mono_server = DeviceProxy(self.mono_server_name) @@ -82,14 +84,9 @@ def init(self): self.acq_off_cmd = self.get_command_object("acq_off") self.acq_window_off_cmd = self.get_command_object("acq_window_off") - if None in [ - self.lower_bound_ch, - self.upper_bound_ch, - self.acq_arm_cmd, - self.acq_on_cmd, - self.acq_off_cmd, - self.acq_window_off_cmd, - ]: + if None in [self.lower_bound_ch, self.upper_bound_ch, + self.acq_arm_cmd, self.acq_on_cmd, self.acq_off_cmd, + self.acq_window_off_cmd]: self.init_ok = False self.log.debug("lower_bound_ch: %s" % self.lower_bound_ch) self.log.debug("upper_bound_ch: %s" % self.upper_bound_ch) @@ -99,7 +96,6 @@ def init(self): self.log.debug("acq_window_off_cmd: %s" % self.acq_window_off_cmd) else: self.init_ok = True - @task def move_motors(self, motor_position_dict): HWR.beamline.diffractometer.wait_omega() @@ -351,17 +347,20 @@ def collect_std_collection(self, start_angle, stop_angle): """ HWR.beamline.diffractometer.wait_omega() - start_pos = start_angle - self.turnback_time * self.acq_speed - stop_pos = stop_angle + self.turnback_time * self.acq_speed - + start_pos = start_angle - self.turnback_time*self.acq_speed + stop_pos = stop_angle + self.turnback_time*self.acq_speed + + + self.log.debug("#COLLECT# Running OMEGA through the std acquisition") if start_angle <= stop_angle: - self.lower_bound_ch.set_value(start_angle) - self.upper_bound_ch.set_value(stop_angle) + self.lower_bound_ch.set_value(start_angle) + self.upper_bound_ch.set_value(stop_angle) else: - self.lower_bound_ch.set_value(stop_angle) - self.upper_bound_ch.set_value(start_angle) + self.lower_bound_ch.set_value(stop_angle) + self.upper_bound_ch.set_value(start_angle) + self.omega_mv(start_pos, self.default_speed) self.acq_arm_cmd() @@ -391,9 +390,7 @@ def collect_characterisation( diffr = HWR.beamline.diffractometer - self.log.debug( - "#COLLECT# Running OMEGA through the characteristation acquisition" - ) + self.log.debug("#COLLECT# Running OMEGA through the characteristation acquisition") self.omega_mv(start_angle, self.default_speed) @@ -401,36 +398,36 @@ def collect_characterisation( print("collecting image %s" % img_no) start_at = start_angle + angle_inc * img_no stop_angle = start_at + img_range * 1.0 - # print("======= CHARACTERISATION Adding angle and range to the header...") - # Add start angle to the header - # detector = HWR.beamline.detector - # detector.set_eiger_start_angle(start_at) + #print("======= CHARACTERISATION Adding angle and range to the header...") + #Add start angle to the header + #detector = HWR.beamline.detector + #detector.set_eiger_start_angle(start_at) # Add angle increment to the header - # detector.set_eiger_angle_increment(angle_inc) + #detector.set_eiger_angle_increment(angle_inc) print("collecting image %s, angle %f" % (img_no, start_at)) if start_at >= stop_angle: - init_pos = start_at # - self.acq_speed * self.turnback_time + init_pos = start_at #- self.acq_speed * self.turnback_time # init_pos = start_at - 1.5 else: - init_pos = start_at # + self.acq_speed * self.turnback_time + init_pos = start_at #+ self.acq_speed * self.turnback_time # init_pos = start_at + 1.5 # self.omega_mv(init_pos, self.default_speed) self.collect_std_collection(start_at, stop_angle) - # This part goes to standard collection. Otherwise it produces phantom openings. + #This part goes to standard collection. Otherwise it produces phantom openings. # diffr.set_omega_velocity(self.default_speed) # self.acq_window_off_cmd() # self.acq_off_cmd() - self.log.debug( - "======= collect_characterisation Waiting =======================================" - ) + self.log.debug("======= collect_characterisation Waiting =======================================") - # Let adxv know whether it is + #Let adxv know whether it is # self.adxv_notify(self.latest_h5_filename,img_no+1) + + # time.sleep(1) # time.sleep(1) @@ -475,14 +472,14 @@ def acquisition_cleanup(self): detector.stop_acquisition() diffr.wait_omega() # ================= - # It is probably already finished in a standard collection. + #It is probably already finished in a standard collection. self.acq_off_cmd() self.acq_window_off_cmd() # ================== diffr.set_omega_velocity(self.default_speed) self.log.debug("#COLLECT# Closing detector cover") diffr.detector_cover_close(wait=True) - + except RuntimeError: self.log.error(traceback.format_exc()) From 2a41443c5c37258f19c4fe47fefff8ffe882112d Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 09:53:30 +0200 Subject: [PATCH 120/151] Force upgrade from the develop to avoid merging conflict --- mxcubecore/Command/Tango.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mxcubecore/Command/Tango.py b/mxcubecore/Command/Tango.py index 0c23a3182d..c164eb8017 100644 --- a/mxcubecore/Command/Tango.py +++ b/mxcubecore/Command/Tango.py @@ -21,7 +21,6 @@ import logging import gevent import gevent.event -import numpy as np try: import Queue as queue @@ -316,7 +315,7 @@ def get_info(self): self._device_initialized.wait(timeout=3) return self.device.get_attribute_config(self.attribute_name) - + def update(self, value=Poller.NotInitializedValue): # start with checking if we have a numpy array, as comparing # numpy.ndarray to Poller.NotInitializedValue raises a ValueError exception @@ -330,7 +329,6 @@ def get_info(self): self.value = value self.emit("update", value) - def get_value(self): if self.read_as_str: value = self.device.read_attribute( From 198be997a9d27bcb1e7583b9639d97cb3c7ef290 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 11:29:10 +0200 Subject: [PATCH 121/151] Added debug info in case beamtime ID is not opened --- mxcubecore/HardwareObjects/DESY/P11Session.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Session.py b/mxcubecore/HardwareObjects/DESY/P11Session.py index 05fecad4d8..f2fdfce8b0 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Session.py +++ b/mxcubecore/HardwareObjects/DESY/P11Session.py @@ -87,17 +87,11 @@ def info_set_defaults(self): def is_beamtime_open(self): self.log.debug("=========== CHECKING IF BEAMTIME ID IS OPEN... ============") if self.is_writable_dir(os.path.join(PATH_BEAMTIME, self.raw_data_folder_name)): - self.log.debug( - "=========== BEAMTIME IS OPEN (/gpfs/current exists) ============" - ) + self.log.debug("=========== BEAMTIME IS OPEN (/gpfs/current exists) ============") else: - self.log.debug( - "=========== NO BEMTIME ID IS OPEN (check /gpfs/current) ============" - ) - - return self.is_writable_dir( - os.path.join(PATH_BEAMTIME, self.raw_data_folder_name) - ) + self.log.debug("=========== NO BEMTIME ID IS OPEN (check /gpfs/current) ============") + + return self.is_writable_dir( os.path.join(PATH_BEAMTIME, self.raw_data_folder_name) ) def is_commissioning_open(self): return self.is_writable_dir( From 554d003c461b20e174459ddabc945d9468f5d516 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 16:59:56 +0200 Subject: [PATCH 122/151] Added additional debug messages for shutter --- mxcubecore/HardwareObjects/DESY/P11Shutter.py | 1 - 1 file changed, 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Shutter.py b/mxcubecore/HardwareObjects/DESY/P11Shutter.py index 297cf2b24c..318802db0f 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Shutter.py +++ b/mxcubecore/HardwareObjects/DESY/P11Shutter.py @@ -153,7 +153,6 @@ def update_shutter_state(self, state=None): state = self.chan_state.get_value() self.log.debug(" SHUTTER state changed") - if state[0] == 3: self.log.debug(" P11SHUTTER IS OPEN") value = self.VALUES.OPEN From 4d320cc8b1be1cb226eb2dd676d524ea569e496f Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 17:06:43 +0200 Subject: [PATCH 123/151] Removed is_open() as a function and assigned is_closed() as a property for shutter-like objects inside P11 HO (Bixente) --- mxcubecore/HardwareObjects/DESY/P11DetectorCover.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py index ec9c9e480e..5555ae015d 100644 --- a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py +++ b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py @@ -197,7 +197,7 @@ def simulated_update(self): self.update_value(value) return value - + @property def is_closed(self): """Check if the shutter is closed. From 22f4a2a1c626cc88b578aecff2b69281679402da Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Thu, 5 Oct 2023 15:35:55 +0200 Subject: [PATCH 124/151] Fixed shutter openning wainting forever (Bixente) --- mxcubecore/HardwareObjects/DESY/P11Shutter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Shutter.py b/mxcubecore/HardwareObjects/DESY/P11Shutter.py index 318802db0f..91ce9b0b90 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Shutter.py +++ b/mxcubecore/HardwareObjects/DESY/P11Shutter.py @@ -140,7 +140,6 @@ def simul_do(self): def do_finish(self, t=None): self.log.debug("### simulated finished") - def do_finish_exc(self, exc=None): self.log.debug("### simulated finished with exception") @@ -153,6 +152,7 @@ def update_shutter_state(self, state=None): state = self.chan_state.get_value() self.log.debug(" SHUTTER state changed") + if state[0] == 3: self.log.debug(" P11SHUTTER IS OPEN") value = self.VALUES.OPEN From 007668162a45d4b360c9e5ef53f14c7dea2024c5 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Fri, 6 Oct 2023 17:32:07 +0200 Subject: [PATCH 125/151] Added preliminary flux HO for P11 --- mxcubecore/HardwareObjects/DESY/P11Flux.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Flux.py b/mxcubecore/HardwareObjects/DESY/P11Flux.py index d1475ab6f4..ae64c4ca83 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Flux.py +++ b/mxcubecore/HardwareObjects/DESY/P11Flux.py @@ -44,7 +44,7 @@ def init(self): def get_value(self): """Get flux at current transmission in units of photons/s""" - + """ FLUX IS CHEETED HERE - NOWERE ELSE!""" return self.current_flux_dict["flux"] From 4f0dc720e1d3c269d0b667067e8127bb6bb4f3df Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Fri, 6 Oct 2023 19:18:03 +0200 Subject: [PATCH 126/151] Upgraded the characterisation part for P11 using EDNA --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 9 ++++--- .../DESY/P11EDNACharacterisation.py | 25 ++++++------------- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index 197a7c58f1..7fc9a31104 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -126,6 +126,7 @@ def data_collection_hook(self): self.diffr = HWR.beamline.diffractometer detector = HWR.beamline.detector + dc_pars = self.current_dc_parameters collection_type = dc_pars["experiment_type"] @@ -199,7 +200,7 @@ def data_collection_hook(self): ) # Filepath to the EDNA processing - # filepath = os.path.join(basepath,"%s_%d" % (prefix, runno)) + #filepath = os.path.join(basepath,"%s_%d" % (prefix, runno)) # setting up xds_dir for characterisation (used there internally to create dirs) self.current_dc_parameters["xds_dir"] = os.path.join( @@ -544,9 +545,9 @@ def add_h5_info(self, h5file): del h5fd[node] h5fd.close() - except RuntimeWarning as err_msg: - self.log.debug("Error while adding info to HDF5 file (%s)" % str(err_msg)) - self.log.debug(traceback.format_exc()) + # except RuntimeWarning as err_msg: + # self.log.debug("Error while adding info to HDF5 file (%s)" % str(err_msg)) + # self.log.debug(traceback.format_exc()) except Exception as err_msg: self.log.debug("Error while adding info to HDF5 file (%s)" % str(err_msg)) self.log.debug(traceback.format_exc()) diff --git a/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py b/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py index d8290ac762..28f3399e25 100644 --- a/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py +++ b/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py @@ -56,15 +56,17 @@ def _run_edna(self, input_file, results_file, process_directory): # subprocess.call("%s %s %s %s" % args, shell=True) # Test run DESY + self.edna_maxwell(process_directory,input_file, results_file) + - self.edna_maxwell(process_directory, input_file, results_file) self.result = None if os.path.exists(results_file): self.result = XSDataResultMXCuBE.parseFile(results_file) return self.result - + + def edna_maxwell(self, process_directory, inputxml, outputxml): """ The function `edna_maxwell` is used to execute a command on a remote cluster using SSH and SBATCH. @@ -123,13 +125,6 @@ def edna_maxwell(self, process_directory, inputxml, outputxml): ) ) - - print( - '{ssh:s} "{sbatch:s} --wrap \\"{cmd:s}"\\"'.format( - ssh=ssh, sbatch=sbatch, cmd=cmd - ) - ) - print('{ssh:s} "{sbatch:s} --wrap \\"{cmd:s}"\\"'.format(ssh=ssh, sbatch=sbatch, cmd=cmd)) os.system( @@ -262,13 +257,7 @@ def input_from_params(self, data_collection, char_params): data_set = XSDataMXCuBEDataSet() acquisition_parameters = data_collection.acquisitions[0].acquisition_parameters path_template = data_collection.acquisitions[0].path_template - - - # Make sure there is a proper path conversion between different mount points - print( - "======= Characterisation path template ====", path_template.directory - ) # /gpfs/current/raw - + #Make sure there is a proper path conversion between different mount points print("======= Characterisation path template ====", path_template.directory) #/gpfs/current/raw @@ -280,11 +269,11 @@ def input_from_params(self, data_collection, char_params): path_str = os.path.join(image_dir, path_template.get_image_file_name()) print(path_template.xds_dir) - + characterisation_dir = path_template.xds_dir.replace( "/autoprocessing_", "/characterisation_" ) - + os.makedirs(characterisation_dir, mode=0o755, exist_ok=True) for img_num in range(int(acquisition_parameters.num_images)): From e9e7f7b377474e01ab7d923f8c9c11e4f8e67b6c Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Fri, 6 Oct 2023 22:57:55 +0200 Subject: [PATCH 127/151] Linting --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 72 ++++++++++--------- .../HardwareObjects/DESY/P11DetectorCover.py | 2 +- .../DESY/P11EDNACharacterisation.py | 27 +++---- mxcubecore/HardwareObjects/DESY/P11Flux.py | 2 +- mxcubecore/HardwareObjects/DESY/P11Session.py | 14 ++-- mxcubecore/HardwareObjects/DESY/P11Shutter.py | 5 +- 6 files changed, 68 insertions(+), 54 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index 7fc9a31104..eeaba9c986 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -56,23 +56,21 @@ class P11Collect(AbstractCollect): - def __init__(self, *args): super(P11Collect, self).__init__(*args) def init(self): - super(P11Collect,self).init() + super(P11Collect, self).init() # os.system("/opt/xray/bin/adxv -socket -colors Gray -rings &") # os.system("/bin/bash /gpfs/local/shared/MXCuBE/STRELA/start_viewer_zmq.sh") - self.default_speed = self.get_property("omega_default_speed", 130) self.turnback_time = self.get_property("turnback_time", 0.3) - self.filter_server_name = self.get_property('filterserver') - self.mono_server_name = self.get_property('monoserver') + self.filter_server_name = self.get_property("filterserver") + self.mono_server_name = self.get_property("monoserver") self.filter_server = DeviceProxy(self.filter_server_name) self.mono_server = DeviceProxy(self.mono_server_name) @@ -84,9 +82,14 @@ def init(self): self.acq_off_cmd = self.get_command_object("acq_off") self.acq_window_off_cmd = self.get_command_object("acq_window_off") - if None in [self.lower_bound_ch, self.upper_bound_ch, - self.acq_arm_cmd, self.acq_on_cmd, self.acq_off_cmd, - self.acq_window_off_cmd]: + if None in [ + self.lower_bound_ch, + self.upper_bound_ch, + self.acq_arm_cmd, + self.acq_on_cmd, + self.acq_off_cmd, + self.acq_window_off_cmd, + ]: self.init_ok = False self.log.debug("lower_bound_ch: %s" % self.lower_bound_ch) self.log.debug("upper_bound_ch: %s" % self.upper_bound_ch) @@ -96,6 +99,7 @@ def init(self): self.log.debug("acq_window_off_cmd: %s" % self.acq_window_off_cmd) else: self.init_ok = True + @task def move_motors(self, motor_position_dict): HWR.beamline.diffractometer.wait_omega() @@ -126,7 +130,6 @@ def data_collection_hook(self): self.diffr = HWR.beamline.diffractometer detector = HWR.beamline.detector - dc_pars = self.current_dc_parameters collection_type = dc_pars["experiment_type"] @@ -200,7 +203,7 @@ def data_collection_hook(self): ) # Filepath to the EDNA processing - #filepath = os.path.join(basepath,"%s_%d" % (prefix, runno)) + # filepath = os.path.join(basepath,"%s_%d" % (prefix, runno)) # setting up xds_dir for characterisation (used there internally to create dirs) self.current_dc_parameters["xds_dir"] = os.path.join( @@ -348,20 +351,17 @@ def collect_std_collection(self, start_angle, stop_angle): """ HWR.beamline.diffractometer.wait_omega() - start_pos = start_angle - self.turnback_time*self.acq_speed - stop_pos = stop_angle + self.turnback_time*self.acq_speed - - - + start_pos = start_angle - self.turnback_time * self.acq_speed + stop_pos = stop_angle + self.turnback_time * self.acq_speed + self.log.debug("#COLLECT# Running OMEGA through the std acquisition") if start_angle <= stop_angle: - self.lower_bound_ch.set_value(start_angle) - self.upper_bound_ch.set_value(stop_angle) + self.lower_bound_ch.set_value(start_angle) + self.upper_bound_ch.set_value(stop_angle) else: - self.lower_bound_ch.set_value(stop_angle) - self.upper_bound_ch.set_value(start_angle) - + self.lower_bound_ch.set_value(stop_angle) + self.upper_bound_ch.set_value(start_angle) self.omega_mv(start_pos, self.default_speed) self.acq_arm_cmd() @@ -391,7 +391,9 @@ def collect_characterisation( diffr = HWR.beamline.diffractometer - self.log.debug("#COLLECT# Running OMEGA through the characteristation acquisition") + self.log.debug( + "#COLLECT# Running OMEGA through the characteristation acquisition" + ) self.omega_mv(start_angle, self.default_speed) @@ -399,35 +401,37 @@ def collect_characterisation( print("collecting image %s" % img_no) start_at = start_angle + angle_inc * img_no stop_angle = start_at + img_range * 1.0 - #print("======= CHARACTERISATION Adding angle and range to the header...") - #Add start angle to the header - #detector = HWR.beamline.detector - #detector.set_eiger_start_angle(start_at) + # print("======= CHARACTERISATION Adding angle and range to the header...") + # Add start angle to the header + # detector = HWR.beamline.detector + # detector.set_eiger_start_angle(start_at) # Add angle increment to the header - #detector.set_eiger_angle_increment(angle_inc) + # detector.set_eiger_angle_increment(angle_inc) print("collecting image %s, angle %f" % (img_no, start_at)) if start_at >= stop_angle: - init_pos = start_at #- self.acq_speed * self.turnback_time + init_pos = start_at # - self.acq_speed * self.turnback_time # init_pos = start_at - 1.5 else: - init_pos = start_at #+ self.acq_speed * self.turnback_time + init_pos = start_at # + self.acq_speed * self.turnback_time # init_pos = start_at + 1.5 # self.omega_mv(init_pos, self.default_speed) self.collect_std_collection(start_at, stop_angle) - #This part goes to standard collection. Otherwise it produces phantom openings. + # This part goes to standard collection. Otherwise it produces phantom openings. # diffr.set_omega_velocity(self.default_speed) # self.acq_window_off_cmd() # self.acq_off_cmd() - self.log.debug("======= collect_characterisation Waiting =======================================") + self.log.debug( + "======= collect_characterisation Waiting =======================================" + ) - #Let adxv know whether it is + # Let adxv know whether it is # self.adxv_notify(self.latest_h5_filename,img_no+1) - + # time.sleep(1) # time.sleep(1) @@ -473,14 +477,14 @@ def acquisition_cleanup(self): detector.stop_acquisition() diffr.wait_omega() # ================= - #It is probably already finished in a standard collection. + # It is probably already finished in a standard collection. self.acq_off_cmd() self.acq_window_off_cmd() # ================== diffr.set_omega_velocity(self.default_speed) self.log.debug("#COLLECT# Closing detector cover") diffr.detector_cover_close(wait=True) - + except RuntimeError: self.log.error(traceback.format_exc()) diff --git a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py index 5555ae015d..ec9c9e480e 100644 --- a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py +++ b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py @@ -197,7 +197,7 @@ def simulated_update(self): self.update_value(value) return value - + @property def is_closed(self): """Check if the shutter is closed. diff --git a/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py b/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py index 28f3399e25..058ddc6784 100644 --- a/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py +++ b/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py @@ -56,17 +56,14 @@ def _run_edna(self, input_file, results_file, process_directory): # subprocess.call("%s %s %s %s" % args, shell=True) # Test run DESY - self.edna_maxwell(process_directory,input_file, results_file) - - + self.edna_maxwell(process_directory, input_file, results_file) self.result = None if os.path.exists(results_file): self.result = XSDataResultMXCuBE.parseFile(results_file) return self.result - - + def edna_maxwell(self, process_directory, inputxml, outputxml): """ The function `edna_maxwell` is used to execute a command on a remote cluster using SSH and SBATCH. @@ -125,7 +122,11 @@ def edna_maxwell(self, process_directory, inputxml, outputxml): ) ) - print('{ssh:s} "{sbatch:s} --wrap \\"{cmd:s}"\\"'.format(ssh=ssh, sbatch=sbatch, cmd=cmd)) + print( + '{ssh:s} "{sbatch:s} --wrap \\"{cmd:s}"\\"'.format( + ssh=ssh, sbatch=sbatch, cmd=cmd + ) + ) os.system( '{ssh:s} "{sbatch:s} --wrap \\"{cmd:s}"\\"'.format( @@ -257,10 +258,12 @@ def input_from_params(self, data_collection, char_params): data_set = XSDataMXCuBEDataSet() acquisition_parameters = data_collection.acquisitions[0].acquisition_parameters path_template = data_collection.acquisitions[0].path_template - - #Make sure there is a proper path conversion between different mount points - print("======= Characterisation path template ====", path_template.directory) #/gpfs/current/raw - + + # Make sure there is a proper path conversion between different mount points + print( + "======= Characterisation path template ====", path_template.directory + ) # /gpfs/current/raw + image_dir = path_template.directory.replace( "/gpfs/current", triggerUtils.get_beamtime_metadata()[2] ) @@ -269,11 +272,11 @@ def input_from_params(self, data_collection, char_params): path_str = os.path.join(image_dir, path_template.get_image_file_name()) print(path_template.xds_dir) - + characterisation_dir = path_template.xds_dir.replace( "/autoprocessing_", "/characterisation_" ) - + os.makedirs(characterisation_dir, mode=0o755, exist_ok=True) for img_num in range(int(acquisition_parameters.num_images)): diff --git a/mxcubecore/HardwareObjects/DESY/P11Flux.py b/mxcubecore/HardwareObjects/DESY/P11Flux.py index ae64c4ca83..d1475ab6f4 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Flux.py +++ b/mxcubecore/HardwareObjects/DESY/P11Flux.py @@ -44,7 +44,7 @@ def init(self): def get_value(self): """Get flux at current transmission in units of photons/s""" - + """ FLUX IS CHEETED HERE - NOWERE ELSE!""" return self.current_flux_dict["flux"] diff --git a/mxcubecore/HardwareObjects/DESY/P11Session.py b/mxcubecore/HardwareObjects/DESY/P11Session.py index f2fdfce8b0..05fecad4d8 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Session.py +++ b/mxcubecore/HardwareObjects/DESY/P11Session.py @@ -87,11 +87,17 @@ def info_set_defaults(self): def is_beamtime_open(self): self.log.debug("=========== CHECKING IF BEAMTIME ID IS OPEN... ============") if self.is_writable_dir(os.path.join(PATH_BEAMTIME, self.raw_data_folder_name)): - self.log.debug("=========== BEAMTIME IS OPEN (/gpfs/current exists) ============") + self.log.debug( + "=========== BEAMTIME IS OPEN (/gpfs/current exists) ============" + ) else: - self.log.debug("=========== NO BEMTIME ID IS OPEN (check /gpfs/current) ============") - - return self.is_writable_dir( os.path.join(PATH_BEAMTIME, self.raw_data_folder_name) ) + self.log.debug( + "=========== NO BEMTIME ID IS OPEN (check /gpfs/current) ============" + ) + + return self.is_writable_dir( + os.path.join(PATH_BEAMTIME, self.raw_data_folder_name) + ) def is_commissioning_open(self): return self.is_writable_dir( diff --git a/mxcubecore/HardwareObjects/DESY/P11Shutter.py b/mxcubecore/HardwareObjects/DESY/P11Shutter.py index 91ce9b0b90..90e81aec28 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Shutter.py +++ b/mxcubecore/HardwareObjects/DESY/P11Shutter.py @@ -110,8 +110,8 @@ def _set_value(self, value): self.simulated_opened = open_it self.simulated_moving = True self.t1 = gevent.spawn(self.simul_do) - self.t1.link(self.do_finish) - self.t1.link_exception(self.do_finish_exc) + self.t1.link(self.do_finish) + self.t1.link_exception(self.do_finish_exc) else: if open_it: self.do_open() @@ -140,6 +140,7 @@ def simul_do(self): def do_finish(self, t=None): self.log.debug("### simulated finished") + def do_finish_exc(self, exc=None): self.log.debug("### simulated finished with exception") From f6dc76d1cfcc1fec90c9dbb2b05f67f123d00354 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Mon, 18 Sep 2023 12:11:42 +0200 Subject: [PATCH 128/151] Fixing the ambiguity with Poller value and .any --- mxcubecore/Command/Tango.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mxcubecore/Command/Tango.py b/mxcubecore/Command/Tango.py index c164eb8017..0c23a3182d 100644 --- a/mxcubecore/Command/Tango.py +++ b/mxcubecore/Command/Tango.py @@ -21,6 +21,7 @@ import logging import gevent import gevent.event +import numpy as np try: import Queue as queue @@ -315,7 +316,7 @@ def get_info(self): self._device_initialized.wait(timeout=3) return self.device.get_attribute_config(self.attribute_name) - def update(self, value=Poller.NotInitializedValue): + # start with checking if we have a numpy array, as comparing # numpy.ndarray to Poller.NotInitializedValue raises a ValueError exception @@ -329,6 +330,7 @@ def update(self, value=Poller.NotInitializedValue): self.value = value self.emit("update", value) + def get_value(self): if self.read_as_str: value = self.device.read_attribute( From e7aa787dd24a5166e2d9dbae9ebabd2d558ec819 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Mon, 18 Sep 2023 12:42:20 +0200 Subject: [PATCH 129/151] P11Collect additional debug after upgrade --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index eeaba9c986..2975eedb76 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -56,6 +56,7 @@ class P11Collect(AbstractCollect): + def __init__(self, *args): super(P11Collect, self).__init__(*args) @@ -99,7 +100,6 @@ def init(self): self.log.debug("acq_window_off_cmd: %s" % self.acq_window_off_cmd) else: self.init_ok = True - @task def move_motors(self, motor_position_dict): HWR.beamline.diffractometer.wait_omega() @@ -429,8 +429,16 @@ def collect_characterisation( "======= collect_characterisation Waiting =======================================" ) - # Let adxv know whether it is + #This part goes to standard collection. Otherwise it produces phantom openings. + # diffr.set_omega_velocity(self.default_speed) + # self.acq_window_off_cmd() + # self.acq_off_cmd() + self.log.debug("======= collect_characterisation Waiting =======================================") + + #Let adxv know whether it is # self.adxv_notify(self.latest_h5_filename,img_no+1) + + # time.sleep(1) # time.sleep(1) From 01a26e9f3901d22ffaf35631c2bd162357f36f1b Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 09:53:30 +0200 Subject: [PATCH 130/151] Force upgrade from the develop to avoid merging conflict --- mxcubecore/Command/Tango.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mxcubecore/Command/Tango.py b/mxcubecore/Command/Tango.py index 0c23a3182d..c164eb8017 100644 --- a/mxcubecore/Command/Tango.py +++ b/mxcubecore/Command/Tango.py @@ -21,7 +21,6 @@ import logging import gevent import gevent.event -import numpy as np try: import Queue as queue @@ -316,7 +315,7 @@ def get_info(self): self._device_initialized.wait(timeout=3) return self.device.get_attribute_config(self.attribute_name) - + def update(self, value=Poller.NotInitializedValue): # start with checking if we have a numpy array, as comparing # numpy.ndarray to Poller.NotInitializedValue raises a ValueError exception @@ -330,7 +329,6 @@ def get_info(self): self.value = value self.emit("update", value) - def get_value(self): if self.read_as_str: value = self.device.read_attribute( From 1c72ab626316101b12b22a1f60180ead24848826 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 27 Sep 2023 17:06:43 +0200 Subject: [PATCH 131/151] Removed is_open() as a function and assigned is_closed() as a property for shutter-like objects inside P11 HO (Bixente) --- mxcubecore/HardwareObjects/DESY/P11DetectorCover.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py index ec9c9e480e..5555ae015d 100644 --- a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py +++ b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py @@ -197,7 +197,7 @@ def simulated_update(self): self.update_value(value) return value - + @property def is_closed(self): """Check if the shutter is closed. From bd966b356fc9d5b64b50b9fdc7d55c967f4d6a82 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Fri, 6 Oct 2023 19:18:03 +0200 Subject: [PATCH 132/151] Upgraded the characterisation part for P11 using EDNA --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index 2975eedb76..3ebbdacf3f 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -130,6 +130,7 @@ def data_collection_hook(self): self.diffr = HWR.beamline.diffractometer detector = HWR.beamline.detector + dc_pars = self.current_dc_parameters collection_type = dc_pars["experiment_type"] @@ -203,7 +204,7 @@ def data_collection_hook(self): ) # Filepath to the EDNA processing - # filepath = os.path.join(basepath,"%s_%d" % (prefix, runno)) + #filepath = os.path.join(basepath,"%s_%d" % (prefix, runno)) # setting up xds_dir for characterisation (used there internally to create dirs) self.current_dc_parameters["xds_dir"] = os.path.join( From a25eaf7e575b9246459dec94b3244c81c84afe73 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Fri, 6 Oct 2023 22:57:55 +0200 Subject: [PATCH 133/151] Linting --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 13 +++++++------ mxcubecore/HardwareObjects/DESY/P11DetectorCover.py | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index 3ebbdacf3f..11b244b997 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -56,7 +56,6 @@ class P11Collect(AbstractCollect): - def __init__(self, *args): super(P11Collect, self).__init__(*args) @@ -100,6 +99,7 @@ def init(self): self.log.debug("acq_window_off_cmd: %s" % self.acq_window_off_cmd) else: self.init_ok = True + @task def move_motors(self, motor_position_dict): HWR.beamline.diffractometer.wait_omega() @@ -130,7 +130,6 @@ def data_collection_hook(self): self.diffr = HWR.beamline.diffractometer detector = HWR.beamline.detector - dc_pars = self.current_dc_parameters collection_type = dc_pars["experiment_type"] @@ -204,7 +203,7 @@ def data_collection_hook(self): ) # Filepath to the EDNA processing - #filepath = os.path.join(basepath,"%s_%d" % (prefix, runno)) + # filepath = os.path.join(basepath,"%s_%d" % (prefix, runno)) # setting up xds_dir for characterisation (used there internally to create dirs) self.current_dc_parameters["xds_dir"] = os.path.join( @@ -434,11 +433,13 @@ def collect_characterisation( # diffr.set_omega_velocity(self.default_speed) # self.acq_window_off_cmd() # self.acq_off_cmd() - self.log.debug("======= collect_characterisation Waiting =======================================") + self.log.debug( + "======= collect_characterisation Waiting =======================================" + ) - #Let adxv know whether it is + # Let adxv know whether it is # self.adxv_notify(self.latest_h5_filename,img_no+1) - + # time.sleep(1) # time.sleep(1) diff --git a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py index 5555ae015d..ec9c9e480e 100644 --- a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py +++ b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py @@ -197,7 +197,7 @@ def simulated_update(self): self.update_value(value) return value - + @property def is_closed(self): """Check if the shutter is closed. From 0f434cba59dc80f077c3842c015a57a0251ab8cd Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 8 Nov 2023 16:29:40 +0100 Subject: [PATCH 134/151] Temp fix for P11 specific routine --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index 11b244b997..218626ff92 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -565,6 +565,9 @@ def add_h5_info(self, h5file): except Exception as err_msg: self.log.debug("Error while adding info to HDF5 file (%s)" % str(err_msg)) self.log.debug(traceback.format_exc()) + except Exception as err_msg: + self.log.debug("Error while adding info to HDF5 file (%s)" % str(err_msg)) + self.log.debug(traceback.format_exc()) def get_filter_thickness(self): """ From e3fe51320202118c1d5952cc193700ea52c8cabd Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 8 Nov 2023 18:03:37 +0100 Subject: [PATCH 135/151] Renamed get_properties to get_properties_ as before and made appropriate changes in qt part-multi_state_brick.py (PR800) --- mxcubecore/HardwareObjects/MotorsNPosition.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mxcubecore/HardwareObjects/MotorsNPosition.py b/mxcubecore/HardwareObjects/MotorsNPosition.py index ab28f896e8..c28ab9f24d 100644 --- a/mxcubecore/HardwareObjects/MotorsNPosition.py +++ b/mxcubecore/HardwareObjects/MotorsNPosition.py @@ -121,7 +121,7 @@ def load_positions(self): def get_position_list(self): return list(self._positions.keys()) - def get_properties(self, position_index, property_name): + def get_properties_(self, position_index, property_name): """ returns property with name property_name for position_index if position_index is None returns OrderedDict with property_name for all positions @@ -161,7 +161,7 @@ def set_position(self, posname): posidx = -1 for name in self._positions: posidx += 1 - if posname == self.get_properties(posidx, "posname"): + if posname == self.get_properties_(posidx, "posname"): self._set_value(posidx) return From 50c6b8392213b271c949696e2c271a3b0ef99a79 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 8 Nov 2023 18:39:43 +0100 Subject: [PATCH 136/151] Cleanup unused code (PR800) --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 42 +------------------ 1 file changed, 1 insertion(+), 41 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index 218626ff92..f8060fee35 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -286,52 +286,12 @@ def data_collection_hook(self): self.collect_characterisation( start_angle, img_range, nframes, angle_inc, exp_time ) - # TODO: Add LiveView here - # os.system("killall albula") - # os.system("/opt/dectris/albula/4.0/bin/albula "+self.latest_h5_filename +" &") - # os.system("adxv "+self.latest_h5_filename +" &") - - # TODO: Remove for now creation of the snapshots and processing html. - # Open index_html - # os.system("firefox /gpfs/current/processed/index.html") - - # Create diffraction snapshots - # for i in range(nframes): - # os.system( - # "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " - # + self.latest_h5_filename - # + " --output " - # + os.path.join( - # basepath, prefix, "screening_" + str(runno).zfill(3) - # ) - # + "/" - # + " --image_number " - # + str(i + 1) - # ) - # else: self.collect_std_collection(start_angle, stop_angle) self.generate_xds_template() # self.adxv_notify(self.latest_h5_filename) # TODO: Add LiveView here - # os.system("killall albula") - # os.system("/opt/dectris/albula/4.0/bin/albula "+self.latest_h5_filename +" &") - - # # Open index_html - # os.system("firefox /gpfs/current/processed/index.html") - # - # # Create diffraction snapshots - # os.system( - # "python3 /gpfs/local/shared/MXCuBE/hdf5tools/albula_api/generate_image.py --input " - # + self.latest_h5_filename - # + " --output " - # + os.path.join( - # basepath, prefix, "rotational_" + str(runno).zfill(3) - # ) - # + "/" - # + " --image_number 1" - # ) - # + except RuntimeError: self.log.error(traceback.format_exc()) finally: From 1c872e6d75d2fce4ba11c4869e896c22bdd217a4 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 15 Nov 2023 15:34:41 +0100 Subject: [PATCH 137/151] Linting --- mxcubecore/HardwareObjects/DESY/P11Beam.py | 44 ++++++++----------- mxcubecore/HardwareObjects/DESY/P11Collect.py | 6 +-- .../HardwareObjects/DESY/P11ISPyBClient.py | 2 +- .../HardwareObjects/DESY/P11NanoDiff.py | 10 ++--- mxcubecore/HardwareObjects/DESY/P11Pinhole.py | 2 +- .../HardwareObjects/DESY/P11SampleChanger.py | 2 +- 6 files changed, 30 insertions(+), 36 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Beam.py b/mxcubecore/HardwareObjects/DESY/P11Beam.py index 5b4da2fa14..b341c463fa 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Beam.py +++ b/mxcubecore/HardwareObjects/DESY/P11Beam.py @@ -32,36 +32,31 @@ class P11Beam(AbstractBeam): - def __init__(self,*args): - super(P11Beam,self).__init__(*args) + def __init__(self, *args): + super(P11Beam, self).__init__(*args) - self._beam_size_dict = { - "aperture": [9999,9999], - "slits": [9999,9999], - } + self._beam_size_dict = {"aperture": [9999, 9999], "slits": [9999, 9999]} - self._beam_position_on_screen = [340, 256] + self._beam_position_on_screen = [340, 256] self.focus_sizes = { - -1: {'label': 'unknown', 'size': (0.2,0.2)}, - 0: {'label': 'flat', 'size': (0.2,0.2)}, - 1: {'label': '200x200', 'size': (0.2,0.2)}, - 2: {'label': '100x100', 'size': (0.1,0.1)}, - 3: {'label': '50x50', 'size': (0.05,0.05)}, - 4: {'label': '20x20', 'size': (0.02,0.02)}, - 5: {'label': '4x9', 'size': (0.009,0.004)}, - } - - + -1: {"label": "unknown", "size": (0.2, 0.2)}, + 0: {"label": "flat", "size": (0.2, 0.2)}, + 1: {"label": "200x200", "size": (0.2, 0.2)}, + 2: {"label": "100x100", "size": (0.1, 0.1)}, + 3: {"label": "50x50", "size": (0.05, 0.05)}, + 4: {"label": "20x20", "size": (0.02, 0.02)}, + 5: {"label": "4x9", "size": (0.009, 0.004)}, + } def init(self): self.mirror_idx_ch = self.get_channel_object("beamsize") self.mirror_state_ch = self.get_channel_object("state") if self.mirror_idx_ch is not None: - self.mirror_idx_ch.connect_signal("update", self.mirror_idx_changed) + self.mirror_idx_ch.connect_signal("update", self.mirror_idx_changed) if self.mirror_state_ch is not None: - self.mirror_state_ch.connect_signal("update", self.mirror_state_changed) + self.mirror_state_ch.connect_signal("update", self.mirror_state_changed) self.mirror_idx_changed() self.mirror_state_changed() @@ -81,7 +76,7 @@ def mirror_state_changed(self, state=None): if state is None: state = self.get_beam_info_state() - self.update_state( self._convert_tango_state(state) ) + self.update_state(self._convert_tango_state(state)) def _convert_tango_state(self, state): str_state = str(state) @@ -94,7 +89,6 @@ def _convert_tango_state(self, state): _state = self.STATES.FAULT return _state - def mirror_idx_changed(self, value=None): if value is None: @@ -107,11 +101,11 @@ def mirror_idx_changed(self, value=None): self.log.debug(f" - UNKNOWN mirror index") curr_size_item = self.focus_sizes[value] - self.log.debug(f" current mirror focus is {curr_size_item['label']}: {curr_size_item['size']}") + self.log.debug( + f" current mirror focus is {curr_size_item['label']}: {curr_size_item['size']}" + ) - - self._beam_size_dict["aperture"] = curr_size_item['size'] + self._beam_size_dict["aperture"] = curr_size_item["size"] self.evaluate_beam_info() self.re_emit_values() - diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index 1acfef6b79..2478cd88d1 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -389,7 +389,7 @@ def collect_characterisation( "======= collect_characterisation Waiting =======================================" ) - #This part goes to standard collection. Otherwise it produces phantom openings. + # This part goes to standard collection. Otherwise it produces phantom openings. # diffr.set_omega_velocity(self.default_speed) # self.acq_window_off_cmd() # self.acq_off_cmd() @@ -536,7 +536,7 @@ def get_filter_thickness(self): thickness = int(thick1) + int(thick2) + int(thick3) - return float(thickness) / 1000000 + return float(thickness) / 1_000_000 else: return -1 @@ -1011,7 +1011,7 @@ def get_relative_path(self, path1, path2): if path_1[i] != v__: break - parts = ["..",] * (len(path_2) - i) + parts = [".."] * (len(path_2) - i) parts.extend(path_1[i:]) return os.path.join(*parts) diff --git a/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py b/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py index 3225c34dda..18aaa89172 100644 --- a/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py +++ b/mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py @@ -39,7 +39,7 @@ def store_image(self, image_dict): return ISPyBClient.store_image(self, image_dict) def store_robot_action(self, robot_action_dict): - #TODO ISPyB is not ready for now. This prevents from error 500 from the server. + # TODO ISPyB is not ready for now. This prevents from error 500 from the server. pass def prepare_collect_for_lims(self, mx_collect_dict): diff --git a/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py b/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py index f4ce1efbc8..4161f77e02 100644 --- a/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py +++ b/mxcubecore/HardwareObjects/DESY/P11NanoDiff.py @@ -118,20 +118,20 @@ def init(self): # using sample_centring module self.centring_sampx = sample_centring.CentringMotor( - self.motor_hwobj_dict["sampx"], units="microns", + self.motor_hwobj_dict["sampx"], units="microns" ) self.centring_sampy = sample_centring.CentringMotor( - self.motor_hwobj_dict["sampy"], units="microns", + self.motor_hwobj_dict["sampy"], units="microns" ) self.centring_phi = sample_centring.CentringMotor( - self.motor_hwobj_dict["phi"], direction=-1, + self.motor_hwobj_dict["phi"], direction=-1 ) self.centring_phiz = sample_centring.CentringMotor( self.motor_hwobj_dict["phiz"], direction=1, units="microns" ) self.centring_phiy = sample_centring.CentringMotor( - self.motor_hwobj_dict["phiy"], direction=1, units="microns", + self.motor_hwobj_dict["phiy"], direction=1, units="microns" ) self.detcover_hwobj = self.get_object_by_role("detector-cover") @@ -154,7 +154,7 @@ def init(self): self.update_phase() self.update_zoom_calibration() - #self.beam_position = self.update_beam_position() + # self.beam_position = self.update_beam_position() self.update_beam_position() def update_beam_position(self): diff --git a/mxcubecore/HardwareObjects/DESY/P11Pinhole.py b/mxcubecore/HardwareObjects/DESY/P11Pinhole.py index dd000b31d5..f3167d4f51 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Pinhole.py +++ b/mxcubecore/HardwareObjects/DESY/P11Pinhole.py @@ -57,7 +57,7 @@ def load_positions(self): names = config["Pinholes"]["pinholesizelist"].split(",") names[0] = "Down" - units = ["micron",] * len(names) + units = ["micron"] * len(names) units[0] = "" posnames = copy.copy(names) diff --git a/mxcubecore/HardwareObjects/DESY/P11SampleChanger.py b/mxcubecore/HardwareObjects/DESY/P11SampleChanger.py index 5afe2710f6..537359f4c3 100644 --- a/mxcubecore/HardwareObjects/DESY/P11SampleChanger.py +++ b/mxcubecore/HardwareObjects/DESY/P11SampleChanger.py @@ -205,7 +205,7 @@ def load(self, sample=None, wait=True): "Sample changer: Sample loaded (total time: %s)" % (time.time() - self._start_load) ) - + self.emit("progressStop", ()) return self.get_loaded_sample() From 46b4fe5d1021cd7482c899ab81bc53e85f844e5c Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 15 Nov 2023 15:48:45 +0100 Subject: [PATCH 138/151] Linting --- mxcubecore/HardwareObjects/abstract/AbstractSampleChanger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/abstract/AbstractSampleChanger.py b/mxcubecore/HardwareObjects/abstract/AbstractSampleChanger.py index b8c26edaf0..2c451ccf69 100644 --- a/mxcubecore/HardwareObjects/abstract/AbstractSampleChanger.py +++ b/mxcubecore/HardwareObjects/abstract/AbstractSampleChanger.py @@ -808,7 +808,7 @@ def _set_loaded_sample(self, sample): else: self.log.debug(f" Found sample {smp} is loaded") self.log.debug(f" getting loaded {self.get_loaded_sample()}") - #if self.get_loaded_sample() == smp: + # if self.get_loaded_sample() == smp: smp._set_loaded(True) if previous_loaded != self.get_loaded_sample(): From dfb0cb42f1800e898da3d1f611529d6c3cfcc47a Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 15 Nov 2023 15:59:48 +0100 Subject: [PATCH 139/151] Removed unused file --- .../HardwareObjects/DESY/MjpgStreamVideo.py | 974 ------------------ 1 file changed, 974 deletions(-) delete mode 100644 mxcubecore/HardwareObjects/DESY/MjpgStreamVideo.py diff --git a/mxcubecore/HardwareObjects/DESY/MjpgStreamVideo.py b/mxcubecore/HardwareObjects/DESY/MjpgStreamVideo.py deleted file mode 100644 index 310bb967a6..0000000000 --- a/mxcubecore/HardwareObjects/DESY/MjpgStreamVideo.py +++ /dev/null @@ -1,974 +0,0 @@ -# -# Project: MXCuBE -# https://github.com/mxcube -# -# This file is part of MXCuBE software. -# -# MXCuBE is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# MXCuBE is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with MXCuBE. If not, see . - -__author__ = "Jan Meyer" -__email__ = "jan.meyer@desy.de" -__copyright__ = "(c)2015 DESY, FS-PE, P11" -__license__ = "GPL" - - -import gevent - -try: - from httplib import HTTPConnection -except ImportError: - from http.client import HTTPConnection -import json - -from mxcubecore.utils.qt_import import QImage, QPixmap, QPoint -from mxcubecore.utils.conversion import string_types - -from mxcubecore.HardwareObjects.abstract.AbstractVideoDevice import AbstractVideoDevice - -from mxcubecore.BaseHardwareObjects import Device - - -class MjpgStreamVideo(AbstractVideoDevice, Device): - """ - Hardware object to capture images using mjpg-streamer - and it's input_avt.so plugin for AVT Prosilica cameras. - """ - - # command / control types supported by mjpg-streamer - CTRL_TYPE_INTEGER = 1 - CTRL_TYPE_BOOLEAN = 2 - CTRL_TYPE_MENU = 3 - CTRL_TYPE_BUTTON = 4 - - # command destinations - DEST_INPUT = 0 - DEST_OUTPUT = 1 - DEST_PROGRAM = 2 - - # command groups - IN_CMD_GROUP_GENERIC = 0 - IN_CMD_GROUP_RESOLUTION = 2 - IN_CMD_GROUP_JPEG_QUALITY = 3 - IN_CMD_GROUP_AVT_MISC = 32 - IN_CMD_GROUP_AVT_INFO = 33 - IN_CMD_GROUP_AVT_EXPOSURE = 34 - IN_CMD_GROUP_AVT_GAIN = 35 - IN_CMD_GROUP_AVT_LENS_DRIVE = 36 - IN_CMD_GROUP_AVT_IRIS = 37 - IN_CMD_GROUP_AVT_WHITE_BALANCE = 38 - IN_CMD_GROUP_AVT_DSP = 39 - IN_CMD_GROUP_AVT_IMAGE_FORMAT = 40 - IN_CMD_GROUP_AVT_IO = 41 - IN_CMD_GROUP_AVT_ACQUISITION = 42 - IN_CMD_GROUP_AVT_CONFIG_FILE = 43 - IN_CMD_GROUP_AVT_NETWORK = 44 - IN_CMD_GROUP_AVT_STATS = 45 - IN_CMD_GROUP_AVT_EVENTS = 46 - - # commands - # note: not every camera supports every command - # mjpg-streamer only supports integer values for commands - # float values are therefore submitted as an integer value * 1000 - # booleans will only accept 0 or 1 - # menus have an integer identifier for every item - # commands will ignore the given value - # strings and events are unsupported yet - # for more information see the "AVT Camera and Driver Attributes" manual - IN_CMD_UPDATE_CONTROLS = (1, IN_CMD_GROUP_GENERIC) - IN_CMD_JPEG_QUALITY = (1, IN_CMD_GROUP_JPEG_QUALITY) - IN_CMD_AVT_ACQ_END_TRIGGER_EVENT = (6, IN_CMD_GROUP_AVT_ACQUISITION) - IN_CMD_AVT_ACQ_END_TRIGGER_MODE = (7, IN_CMD_GROUP_AVT_ACQUISITION) - IN_CMD_AVT_ACQ_REC_TRIGGER_EVENT = (8, IN_CMD_GROUP_AVT_ACQUISITION) - IN_CMD_AVT_ACQ_REC_TRIGGER_MODE = (9, IN_CMD_GROUP_AVT_ACQUISITION) - IN_CMD_AVT_ACQ_START_TRIGGER_EVENT = (10, IN_CMD_GROUP_AVT_ACQUISITION) - IN_CMD_AVT_ACQ_START_TRIGGER_MODE = (11, IN_CMD_GROUP_AVT_ACQUISITION) - IN_CMD_AVT_ACQUISITION_ABORT = (5, IN_CMD_GROUP_AVT_ACQUISITION) - IN_CMD_AVT_ACQUISITION_FRAME_COUNT = (2, IN_CMD_GROUP_AVT_ACQUISITION) - IN_CMD_AVT_ACQUISITION_MODE = (1, IN_CMD_GROUP_AVT_ACQUISITION) - IN_CMD_AVT_ACQUISITION_START = (3, IN_CMD_GROUP_AVT_ACQUISITION) - IN_CMD_AVT_ACQUISITION_STOP = (4, IN_CMD_GROUP_AVT_ACQUISITION) - IN_CMD_AVT_BANDWIDTH_CTRL_MODE = (1, IN_CMD_GROUP_AVT_NETWORK) - IN_CMD_AVT_BINNING_X = (1, IN_CMD_GROUP_AVT_IMAGE_FORMAT) - IN_CMD_AVT_BINNING_Y = (2, IN_CMD_GROUP_AVT_IMAGE_FORMAT) - # String 2 IN_CMD_AVT_CAMERA_NAME = (0, IN_CMD_GROUP_AVT_INFO) - IN_CMD_AVT_CHUNK_MODE_ACTIVE = (2, IN_CMD_GROUP_AVT_NETWORK) - IN_CMD_AVT_CONFIG_FILE_INDEX = (1, IN_CMD_GROUP_AVT_CONFIG_FILE) - IN_CMD_AVT_CONFIG_FILE_LOAD = (3, IN_CMD_GROUP_AVT_CONFIG_FILE) - IN_CMD_AVT_CONFIG_FILE_POWER_UP = (2, IN_CMD_GROUP_AVT_CONFIG_FILE) - IN_CMD_AVT_CONFIG_FILE_SAVE = (4, IN_CMD_GROUP_AVT_CONFIG_FILE) - IN_CMD_AVT_DSP_SUBREGION_BOTTOM = (4, IN_CMD_GROUP_AVT_DSP) - IN_CMD_AVT_DSP_SUBREGION_LEFT = (1, IN_CMD_GROUP_AVT_DSP) - IN_CMD_AVT_DSP_SUBREGION_RIGHT = (3, IN_CMD_GROUP_AVT_DSP) - IN_CMD_AVT_DSP_SUBREGION_TOP = (2, IN_CMD_GROUP_AVT_DSP) - IN_CMD_AVT_DEFECT_MASK_COLUMN_ENABLE = (1, IN_CMD_GROUP_AVT_MISC) - # String 14 IN_CMD_AVT_DEVICE_ETH_ADDRESS = (0, IN_CMD_GROUP_AVT_NETWORK) - # String 3 IN_CMD_AVT_DEVICE_FIRMWARE_VERSION = (0, IN_CMD_GROUP_AVT_INFO) - # String 15 IN_CMD_AVT_DEVICE_IP_ADDRESS = (0, IN_CMD_GROUP_AVT_NETWORK) - # String 4 IN_CMD_AVT_DEVICE_MODEL_NAME = (0, IN_CMD_GROUP_AVT_INFO) - # String 5 IN_CMD_AVT_DEVICE_PART_NUMBER = (0, IN_CMD_GROUP_AVT_INFO) - # String 6 IN_CMD_AVT_DEVICE_SCAN_TYPE = (0, IN_CMD_GROUP_AVT_INFO) - # String 7 IN_CMD_AVT_DEVICE_SERIAL_NUMBER = (0, IN_CMD_GROUP_AVT_INFO) - # String 8 IN_CMD_AVT_DEVICE_VENDOR_NAME = (0, IN_CMD_GROUP_AVT_INFO) - # Event IN_CMD_AVT_EVENT_ACQUISITION_END = (0, IN_CMD_GROUP_AVT_EVENTS) - # Event IN_CMD_AVT_EVENT_ACQUISITION_RECORD_TRIGGER = (0, IN_CMD_GROUP_AVT_EVENTS) - # Event IN_CMD_AVT_EVENT_ACQUISITION_START = (0, IN_CMD_GROUP_AVT_EVENTS) - # Event IN_CMD_AVT_EVENT_ERROR = (0, IN_CMD_GROUP_AVT_EVENTS) - # Event IN_CMD_AVT_EVENT_EXPOSURE_END = (0, IN_CMD_GROUP_AVT_EVENTS) - # Event IN_CMD_AVT_EVENT_FRAME_TRIGGER = (0, IN_CMD_GROUP_AVT_EVENTS) - # Event IN_CMD_AVT_EVENT_NOTIFICATION = (0, IN_CMD_GROUP_AVT_EVENTS) - # Event IN_CMD_AVT_EVENT_OVERFLOW = (0, IN_CMD_GROUP_AVT_EVENTS) - # Event IN_CMD_AVT_EVENT_SELECTOR = (0, IN_CMD_GROUP_AVT_EVENTS) - # Event IN_CMD_AVT_EVENT_SYNC_IN1_FALL = (0, IN_CMD_GROUP_AVT_EVENTS) - # Event IN_CMD_AVT_EVENT_SYNC_IN1_RISE = (0, IN_CMD_GROUP_AVT_EVENTS) - # Event IN_CMD_AVT_EVENT_SYNC_IN2_FALL = (0, IN_CMD_GROUP_AVT_EVENTS) - # Event IN_CMD_AVT_EVENT_SYNC_IN2_RISE = (0, IN_CMD_GROUP_AVT_EVENTS) - # Event IN_CMD_AVT_EVENT_SYNC_IN3_FALL = (0, IN_CMD_GROUP_AVT_EVENTS) - # Event IN_CMD_AVT_EVENT_SYNC_IN3_RISE = (0, IN_CMD_GROUP_AVT_EVENTS) - # Event IN_CMD_AVT_EVENT_SYNC_IN4_FALL = (0, IN_CMD_GROUP_AVT_EVENTS) - # Event IN_CMD_AVT_EVENT_SYNC_IN4_RISE = (0, IN_CMD_GROUP_AVT_EVENTS) - # Event IN_CMD_AVT_EVENTS_ENABLE1 = (0, IN_CMD_GROUP_AVT_EVENTS) - IN_CMD_AVT_EXPOSURE_AUTO_ADJUST_TOL = (3, IN_CMD_GROUP_AVT_EXPOSURE) - IN_CMD_AVT_EXPOSURE_AUTO_ALG = (4, IN_CMD_GROUP_AVT_EXPOSURE) - IN_CMD_AVT_EXPOSURE_AUTO_MAX = (5, IN_CMD_GROUP_AVT_EXPOSURE) - IN_CMD_AVT_EXPOSURE_AUTO_MIN = (6, IN_CMD_GROUP_AVT_EXPOSURE) - IN_CMD_AVT_EXPOSURE_AUTO_OUTLIERS = (7, IN_CMD_GROUP_AVT_EXPOSURE) - IN_CMD_AVT_EXPOSURE_AUTO_RATE = (8, IN_CMD_GROUP_AVT_EXPOSURE) - IN_CMD_AVT_EXPOSURE_AUTO_TARGET = (9, IN_CMD_GROUP_AVT_EXPOSURE) - IN_CMD_AVT_EXPOSURE_MODE = (2, IN_CMD_GROUP_AVT_EXPOSURE) - IN_CMD_AVT_EXPOSURE_VALUE = (1, IN_CMD_GROUP_AVT_EXPOSURE) - IN_CMD_AVT_FIRMWARE_VER_BUILD = (9, IN_CMD_GROUP_AVT_INFO) - IN_CMD_AVT_FIRMWARE_VER_MAJOR = (10, IN_CMD_GROUP_AVT_INFO) - IN_CMD_AVT_FIRMWARE_VER_MINOR = (11, IN_CMD_GROUP_AVT_INFO) - IN_CMD_AVT_FRAMERATE = (12, IN_CMD_GROUP_AVT_ACQUISITION) - IN_CMD_AVT_FRAME_START_TRIGGER_DELAY = (14, IN_CMD_GROUP_AVT_ACQUISITION) - IN_CMD_AVT_FRAME_START_TRIGGER_EVENT = (15, IN_CMD_GROUP_AVT_ACQUISITION) - IN_CMD_AVT_FRAME_START_TRIGGER_MODE = (13, IN_CMD_GROUP_AVT_ACQUISITION) - IN_CMD_AVT_FRAME_START_TRIGGER_OVERLAP = (16, IN_CMD_GROUP_AVT_ACQUISITION) - IN_CMD_AVT_FRAME_START_TRIGGER_SOFTWARE = (17, IN_CMD_GROUP_AVT_ACQUISITION) - IN_CMD_AVT_GAIN_AUTO_ADJUST_TOL = (3, IN_CMD_GROUP_AVT_GAIN) - IN_CMD_AVT_GAIN_AUTO_MAX = (4, IN_CMD_GROUP_AVT_GAIN) - IN_CMD_AVT_GAIN_AUTO_MIN = (5, IN_CMD_GROUP_AVT_GAIN) - IN_CMD_AVT_GAIN_AUTO_OUTLIERS = (6, IN_CMD_GROUP_AVT_GAIN) - IN_CMD_AVT_GAIN_AUTO_RATE = (7, IN_CMD_GROUP_AVT_GAIN) - IN_CMD_AVT_GAIN_AUTO_TARGET = (8, IN_CMD_GROUP_AVT_GAIN) - IN_CMD_AVT_GAIN_MODE = (2, IN_CMD_GROUP_AVT_GAIN) - IN_CMD_AVT_GAIN_VALUE = (1, IN_CMD_GROUP_AVT_GAIN) - IN_CMD_AVT_GVSP_LOOKBACK_WINDOW = (18, IN_CMD_GROUP_AVT_NETWORK) - IN_CMD_AVT_GVSP_RESEND_PERCENT = (19, IN_CMD_GROUP_AVT_NETWORK) - IN_CMD_AVT_GVSP_RETRIES = (20, IN_CMD_GROUP_AVT_NETWORK) - IN_CMD_AVT_GVSP_SOCKET_BUFFERS_COUNT = (21, IN_CMD_GROUP_AVT_NETWORK) - IN_CMD_AVT_GVSP_TIMEOUT = (22, IN_CMD_GROUP_AVT_NETWORK) - IN_CMD_AVT_HEARTBEAT_INTERVAL = (23, IN_CMD_GROUP_AVT_NETWORK) - IN_CMD_AVT_HEARTBEAT_TIMEOUT = (24, IN_CMD_GROUP_AVT_NETWORK) - IN_CMD_AVT_HEIGHT = (6, IN_CMD_GROUP_AVT_IMAGE_FORMAT) - # String 16 IN_CMD_AVT_HOST_ETH_ADDRESS = (0, IN_CMD_GROUP_AVT_NETWORK) - # String 17 IN_CMD_AVT_HOST_IP_ADDRESS = (0, IN_CMD_GROUP_AVT_NETWORK) - IN_CMD_AVT_IRIS_AUTOTARGET = (1, IN_CMD_GROUP_AVT_IRIS) - IN_CMD_AVT_IRIS_MODE = (2, IN_CMD_GROUP_AVT_IRIS) - IN_CMD_AVT_IRIS_VIDEO_LEVEL = (3, IN_CMD_GROUP_AVT_IRIS) - IN_CMD_AVT_IRIS_VIDEO_LEVEL_MAX = (4, IN_CMD_GROUP_AVT_IRIS) - IN_CMD_AVT_IRIS_VIDEO_LEVEL_MIN = (5, IN_CMD_GROUP_AVT_IRIS) - IN_CMD_AVT_LENS_DRIVE_COMMAND = (1, IN_CMD_GROUP_AVT_LENS_DRIVE) - IN_CMD_AVT_LENS_DRIVE_DURATION = (2, IN_CMD_GROUP_AVT_LENS_DRIVE) - IN_CMD_AVT_LENS_VOLTAGE = (3, IN_CMD_GROUP_AVT_LENS_DRIVE) - IN_CMD_AVT_LENS_VOLTAGE_CONTROL = (4, IN_CMD_GROUP_AVT_LENS_DRIVE) - IN_CMD_AVT_MULTICAST_ENABLE = (25, IN_CMD_GROUP_AVT_NETWORK) - # String 26 IN_CMD_AVT_MULTICAST_IP_ADDRESS = (0, IN_CMD_GROUP_AVT_NETWORK) - IN_CMD_AVT_NON_IMAGE_PAYLOAD_SIZE = (3, IN_CMD_GROUP_AVT_NETWORK) - IN_CMD_AVT_PACKET_SIZE = (27, IN_CMD_GROUP_AVT_NETWORK) - IN_CMD_AVT_PART_CLASS = (12, IN_CMD_GROUP_AVT_INFO) - IN_CMD_AVT_PART_NUMBER = (13, IN_CMD_GROUP_AVT_INFO) - # String 14 IN_CMD_AVT_PART_REVISION = (0, IN_CMD_GROUP_AVT_INFO) - # String 15 IN_CMD_AVT_PART_VERSION = (0, IN_CMD_GROUP_AVT_INFO) - IN_CMD_AVT_PAYLOAD_SIZE = (4, IN_CMD_GROUP_AVT_NETWORK) - IN_CMD_AVT_PIXEL_FORMAT = (7, IN_CMD_GROUP_AVT_IMAGE_FORMAT) - IN_CMD_AVT_RECORDER_PRE_EVENT_COUNT = (18, IN_CMD_GROUP_AVT_ACQUISITION) - IN_CMD_AVT_REGION_X = (3, IN_CMD_GROUP_AVT_IMAGE_FORMAT) - IN_CMD_AVT_REGION_Y = (4, IN_CMD_GROUP_AVT_IMAGE_FORMAT) - IN_CMD_AVT_SENSOR_BITS = (20, IN_CMD_GROUP_AVT_INFO) - IN_CMD_AVT_SENSOR_HEIGHT = (18, IN_CMD_GROUP_AVT_INFO) - IN_CMD_AVT_SENSOR_TYPE = (19, IN_CMD_GROUP_AVT_INFO) - IN_CMD_AVT_SENSOR_WIDTH = (17, IN_CMD_GROUP_AVT_INFO) - # String 16 IN_CMD_AVT_SERIAL_NUMBER = (0, IN_CMD_GROUP_AVT_INFO) - IN_CMD_AVT_STAT_DRIVER_TYPE = (1, IN_CMD_GROUP_AVT_STATS) - # String 2 IN_CMD_AVT_STAT_FILTER_VERSION = (0, IN_CMD_GROUP_AVT_STATS) - IN_CMD_AVT_STAT_FRAME_RATE = (3, IN_CMD_GROUP_AVT_STATS) - IN_CMD_AVT_STAT_FRAMES_COMPLETED = (4, IN_CMD_GROUP_AVT_STATS) - IN_CMD_AVT_STAT_FRAMES_DROPPED = (5, IN_CMD_GROUP_AVT_STATS) - IN_CMD_AVT_STAT_PACKETS_ERRONEOUS = (6, IN_CMD_GROUP_AVT_STATS) - IN_CMD_AVT_STAT_PACKETS_MISSED = (7, IN_CMD_GROUP_AVT_STATS) - IN_CMD_AVT_STAT_PACKETS_RECEIVED = (8, IN_CMD_GROUP_AVT_STATS) - IN_CMD_AVT_STAT_PACKETS_REQUESTED = (9, IN_CMD_GROUP_AVT_STATS) - IN_CMD_AVT_STAT_PACKETS_RESENT = (10, IN_CMD_GROUP_AVT_STATS) - IN_CMD_AVT_STREAM_BYTES_PER_SECOND = (6, IN_CMD_GROUP_AVT_NETWORK) - IN_CMD_AVT_STREAM_FRAME_RATE_CONSTRAIN = (5, IN_CMD_GROUP_AVT_NETWORK) - IN_CMD_AVT_STREAM_HOLD_CAPACITY = (8, IN_CMD_GROUP_AVT_NETWORK) - IN_CMD_AVT_STREAM_HOLD_ENABLE = (7, IN_CMD_GROUP_AVT_NETWORK) - IN_CMD_AVT_STROBE1_CONTROLLED_DURATION = (1, IN_CMD_GROUP_AVT_IO) - IN_CMD_AVT_STROBE1_DELAY = (3, IN_CMD_GROUP_AVT_IO) - IN_CMD_AVT_STROBE1_DURATION = (4, IN_CMD_GROUP_AVT_IO) - IN_CMD_AVT_STROBE1_MODE = (2, IN_CMD_GROUP_AVT_IO) - IN_CMD_AVT_SYNC_IN1_GLITCH_FILTER = (5, IN_CMD_GROUP_AVT_IO) - IN_CMD_AVT_SYNC_IN2_GLITCH_FILTER = (6, IN_CMD_GROUP_AVT_IO) - IN_CMD_AVT_SYNC_IN_LEVELS = (7, IN_CMD_GROUP_AVT_IO) - IN_CMD_AVT_SYNC_OUT1_INVERT = (9, IN_CMD_GROUP_AVT_IO) - IN_CMD_AVT_SYNC_OUT1_MODE = (10, IN_CMD_GROUP_AVT_IO) - IN_CMD_AVT_SYNC_OUT2_INVERT = (11, IN_CMD_GROUP_AVT_IO) - IN_CMD_AVT_SYNC_OUT2_MODE = (12, IN_CMD_GROUP_AVT_IO) - IN_CMD_AVT_SYNC_OUT3_INVERT = (13, IN_CMD_GROUP_AVT_IO) - IN_CMD_AVT_SYNC_OUT3_MODE = (14, IN_CMD_GROUP_AVT_IO) - IN_CMD_AVT_SYNC_OUT4_INVERT = (15, IN_CMD_GROUP_AVT_IO) - IN_CMD_AVT_SYNC_OUT4_MODE = (16, IN_CMD_GROUP_AVT_IO) - IN_CMD_AVT_SYNC_OUT_GPO_LEVELS = (8, IN_CMD_GROUP_AVT_IO) - IN_CMD_AVT_TIME_STAMP_FREQUENCY = (9, IN_CMD_GROUP_AVT_NETWORK) - IN_CMD_AVT_TIME_STAMP_RESET = (13, IN_CMD_GROUP_AVT_NETWORK) - IN_CMD_AVT_TIME_STAMP_VALUE_HI = (11, IN_CMD_GROUP_AVT_NETWORK) - IN_CMD_AVT_TIME_STAMP_VALUE_LATCH = (12, IN_CMD_GROUP_AVT_NETWORK) - IN_CMD_AVT_TIME_STAMP_VALUE_LO = (10, IN_CMD_GROUP_AVT_NETWORK) - IN_CMD_AVT_TOTAL_BYTES_PER_FRAME = (8, IN_CMD_GROUP_AVT_IMAGE_FORMAT) - IN_CMD_AVT_UNIQUE_ID = (1, IN_CMD_GROUP_AVT_INFO) - IN_CMD_AVT_VSUB_VALUE = (2, IN_CMD_GROUP_AVT_MISC) - IN_CMD_AVT_WHITEBAL_AUTO_ADJUST_TOL = (4, IN_CMD_GROUP_AVT_WHITE_BALANCE) - IN_CMD_AVT_WHITEBAL_AUTO_RATE = (5, IN_CMD_GROUP_AVT_WHITE_BALANCE) - IN_CMD_AVT_WHITEBAL_MODE = (3, IN_CMD_GROUP_AVT_WHITE_BALANCE) - IN_CMD_AVT_WHITEBAL_VALUE_BLUE = (2, IN_CMD_GROUP_AVT_WHITE_BALANCE) - IN_CMD_AVT_WHITEBAL_VALUE_RED = (1, IN_CMD_GROUP_AVT_WHITE_BALANCE) - IN_CMD_AVT_WIDTH = (5, IN_CMD_GROUP_AVT_IMAGE_FORMAT) - - def __init__(self, name): - """ - Descript. : - """ - AbstractVideoDevice.__init__(self, name) - self.force_update = None - self.sensor_dimensions = None - self.image_dimensions = None - self.image_polling = None - self.image_type = None - self.image = None - self.sleep_time = 1 - self.host = None - self.port = None - self.path = "/" - self.plugin = 0 - self.update_controls = None - self.input_avt = None - - self.changing_pars = False - - def init(self): - """ - Descript. : - """ - self.sleep_time = self.get_property("interval") - - hw_width = self.get_property("width") - hw_height = self.get_property("height") - scale = self.get_property("scale", 1) - - self.display_width = hw_width * scale - self.display_height = hw_height * scale - - self.log.debug( - " MJPG video - width=%s,height=%s - scale=%s" % (hw_width, hw_height, scale) - ) - self.hw_dimensions = (hw_width, hw_height) - self.image_dimensions = (self.display_width, self.display_height) - self.scale = scale - - self.host = self.get_property("host") - self.port = int(self.get_property("port")) - - self.standard_fliph = bool(self.get_property("fliph")) - self.standard_flipv = bool(self.get_property("flipv")) - self.standard_offsetx = 0 - self.standard_offsety = 0 - - # parameters for overview camera - self.overview_host = self.get_property("overview_host") - self.overview_port = int(self.get_property("overview_port")) - self.overview_fliph = bool(self.get_property("overview_fliph")) - self.overview_flipv = bool(self.get_property("overview_flipv")) - self.overview_offsetx = bool(self.get_property("overview_offsetx")) - self.overview_offsety = bool(self.get_property("overview_offsety")) - - self.path = "/" - self.plugin = 0 - - self.using_overview = False - - self.update_controls = self.has_update_controls() - self.input_avt = self.is_input_avt() - - self.image = self.get_new_image() - - if self.input_avt: - sensor_info = self.get_cmd_info(self.IN_CMD_AVT_SENSOR_WIDTH) - if sensor_info: - sensor_width = int(sensor_info["value"]) - sensor_info = self.get_cmd_info(self.IN_CMD_AVT_SENSOR_HEIGHT) - if sensor_info: - sensor_height = int(sensor_info["value"]) - self.sensor_dimensions = (sensor_width, sensor_height) - - self.set_is_ready(True) - self.set_zoom(0) # overview camera - - def http_get(self, query, host=None, port=None, path=None): - """Sends HTTP GET requests and returns the answer. - - Keyword arguments: - query -- string appended to the end of the requested URL - host -- queried IP or hostname (default host of the MjpgStream instance) - port -- queried port number (default port of the MjpgStream instance) - path -- queried path (default path of the MjpgStream instance) - - Return value: - the HTTP answer content or None on error - - """ - if self.using_overview is True: - host = self.overview_host - port = self.overview_port - path = self.path - else: - host = self.host - port = self.port - path = self.path - - # send get request and return response - http = HTTPConnection(host, port, timeout=3) - # self.log.debug("MjpgStreamVideo: %s:%s - sending %s / %s " % (host,port,path,query)) - - try: - http.request("GET", path + query) - response = http.getresponse() - except Exception: - self.log.error( - "MjpgStreamVideo: Connection to http://{0}:{1}{2}{3} refused".format( - host, port, path, query - ) - ) - return None - if response.status != 200: - self.log.error( - "MjpgStreamVideo: Error {0}, {1}".format( - response.status, response.reason - ) - ) - return None - data = response.read() - http.close() - return data - - def send_cmd(self, value, cmd, group=None, plugin=None, dest=None): - """Sends a command to mjpg-streamer. - - Keyword arguments: - value -- command parameter as integer or item name as string if the command is of enumeration type - cmd -- command id number or tuple constant - group -- command group number, leave it at None if a tuple is given as cmd (default None) - plugin -- plugin number (default plugin of the MjpgStream instance) - dest -- command destination (default MjpgStream.DEST_INPUT) - - """ - if isinstance(cmd, tuple) and group is None: - group = cmd[1] - cmd = cmd[0] - elif isinstance(cmd, tuple): - cmd = cmd[0] - if group is None: - return None - cmd = str(int(cmd)) - group = str(int(group)) - try: - value = str(int(value)) - except Exception: - option = value - value = None - if isinstance(option, string_types): - info = self.get_cmd_info(cmd, group) - if info and "menu" in info and option in info["menu"].values(): - value = str( - [k for k, v in info["menu"].items() if (v == option)][0] - ) - if value is None: - return None - if plugin is None: - plugin = str(self.plugin) - else: - plugin = str(int(plugin)) - if dest is None: - dest = str(self.DEST_INPUT) - else: - dest = str(int(dest)) - # send request - self.http_get( - "?action=command&id=" - + cmd - + "&dest=" - + dest - + "&group=" - + group - + "&value=" - + value - + "&plugin=" - + plugin - ) - - def has_cmd(self, cmd, group=None, plugin=None, dest=None): - """Checks whether a command with the given id and group is known by the specified plugin. - - Keyword arguments: - cmd -- command id number or tuple constant - group -- command group number, leave it at None if a tuple is given as cmd (default None) - plugin -- plugin number (default plugin of the MjpgStream instance) - dest -- command destination (default MjpgStream.DEST_INPUT) - - Return value: - True if so, False if not or the connection was refused - - """ - data = self.get_cmd_info(cmd, group, plugin, dest) - if not data is None: - return True - return False - - def get_cmd_info(self, cmd, group=None, plugin=None, dest=None): - """Returns a dictionary with informations on the queried command. - - Keyword arguments: - cmd -- command id number or tuple constant - group -- command group number, leave it at None if a tuple is given as cmd (default None) - plugin -- plugin number (default plugin of the MjpgStream instance) - dest -- command destination (default MjpgStream.DEST_INPUT) - - Return value: - dictionary containing the following items ("menu" only for menu commands): - "name", "id", "type", "min", "max", "step", "default", "value", "dest", "flags", "group", "menu" - or None on error - - """ - if isinstance(cmd, tuple) and group is None: - group = cmd[1] - cmd = cmd[0] - elif isinstance(cmd, tuple): - cmd = cmd[0] - if group is None: - return None - if plugin is None: - plugin = self.plugin - else: - plugin = str(int(plugin)) - if dest is None or (dest != self.DEST_INPUT and dest != self.DEST_OUTPUT): - dest = self.DEST_INPUT - if self.update_controls: - self.send_cmd(group, self.IN_CMD_UPDATE_CONTROLS, plugin, dest) - # get list of controls and search for the matching one - data = self.get_controls(plugin, dest) - if data is not None: - for info in data: - if int(info["group"]) == int(group) and int(info["id"]) == int(cmd): - return info - return None - - def get_controls(self, plugin=None, dest=None): - """Returns a list with information on all commands supported by the - plugin. If DEST_PROGRAM is given for dest, a list with information on - all loaded plugins is returned. - - Keyword arguments: - plugin -- plugin number (default plugin of the MjpgStream instance) - dest -- command destination (default MjpgStream.DEST_INPUT) - - Return value: - depends on destination plugin. For input_avt.so a list with all commands - supported by the connected camera is returned - q.v. get_cmd_info(). - - """ - if plugin is None: - plugin = str(self.plugin) - else: - plugin = str(int(plugin)) - if dest is None: - dest = self.DEST_INPUT - else: - dest = int(dest) - query = None - if dest == self.DEST_INPUT: - query = "input_" + plugin + ".json" - elif dest == self.DEST_OUTPUT: - query = "output_" + plugin + ".json" - elif dest == self.DEST_PROGRAM: - query = "program.json" - # fetch json from server, decode it into a python object and return it - if query is not None: - data = self.http_get(query) - if data is not None: - data = json.loads(data.decode("utf-8")) - if dest != self.DEST_PROGRAM and "controls" in data: - data = data["controls"] - return data - return None - - def has_update_controls(self): - """Checks if the default plugin for this instance knows the UpdateControls command. - - Return value: - True if so, False if not and None if the connection was refused - - """ - data = self.get_cmd_info(self.IN_CMD_UPDATE_CONTROLS) - if data is None: - return None - if data["name"] == "UpdateControls": - return True - return False - - def is_input_avt(self): - """Checks if the default plugin for this instance is input_avt.so. - - Return value: - True if so, False if not and None if the connection was refused - - """ - data = self.get_controls(0, self.DEST_PROGRAM) - if data is None: - return None - if "inputs" in data: - for info in data["inputs"]: - if info["name"][-12:] == "input_avt.so": - return True - return False - - def start_camera(self): - if self.image_polling is None: - self.image_polling = gevent.spawn( - self._do_imagePolling, 1.0 / self.sleep_time - ) - - def get_image_dimensions(self): - return self.image_dimensions - - def get_scale(self): - return self.scale - - def imageType(self): - """ - Descript. : - """ - return - - def contrast_exists(self): - """ - Descript. : - """ - return - - def set_contrast(self, contrast): - """ - Descript. : - """ - return - - def get_contrast(self): - """ - Descript. : - """ - return - - def set_contrast_auto(self, state=True): - """ - Descript. : - """ - return - - def get_contrast_auto(self): - """ - Descript. : - """ - return - - def get_contrast_min_max(self): - """ - Descript. : - """ - return - - def brightnessExists(self): - """ - Descript. : - """ - return - - def set_brightness(self, brightness): - """ - Descript. : - """ - return - - def get_brightness(self): - """ - Descript. : - """ - return - - def set_brightness_auto(self, state=True): - """ - Descript. : - """ - return - - def get_brightness_auto(self): - """ - Descript. : - """ - return - - def get_brightness_min_max(self): - """ - Descript. : - """ - return - - def gain_exists(self): - """ - Descript. : - """ - return self.has_cmd(self.IN_CMD_AVT_GAIN_VALUE) - - def set_gain(self, gain): - """ - Descript. : - """ - # self.send_cmd("Manual", self.IN_CMD_AVT_GAIN_MODE) # gain mode manual - self.send_cmd(gain, self.IN_CMD_AVT_GAIN_VALUE) - - def get_gain(self): - """ - Descript. : - """ - info = self.get_cmd_info(self.IN_CMD_AVT_GAIN_VALUE) - if info is not None: - return float(info["value"]) - return - - def set_gain_auto(self, state=True): - """ - Descript. : - """ - if bool(state): - self.send_cmd("Auto", self.IN_CMD_AVT_GAIN_MODE) - else: - self.send_cmd("Manual", self.IN_CMD_AVT_GAIN_MODE) - - def get_gain_auto(self): - """ - Descript. : - """ - value = None - info = self.get_cmd_info(self.IN_CMD_AVT_GAIN_MODE) - if info is not None: - value = info["menu"][info["value"]] == "Auto" - return value - - def get_gain_min_max(self): - """ - Descript. : - """ - info = self.get_cmd_info(self.IN_CMD_AVT_GAIN_VALUE) - if info is not None: - return (float(info["min"]), float(info["max"])) - return - - def gamma_exists(self): - """ - Descript. : - """ - return - - def set_gamma(self, gamma): - """ - Descript. : - """ - return - - def get_gamma(self): - """ - Descript. : - """ - return - - def set_gamma_auto(self, state=True): - """ - Descript. : - """ - return - - def get_gamma_auto(self): - """ - Descript. : - """ - return - - def get_gamma_min_max(self): - """ - Descript. : - """ - return (0, 1) - - def exposure_time_exists(self): - """ - Descript. : - """ - return self.has_cmd(self.IN_CMD_AVT_EXPOSURE_VALUE) - - def set_exposure_time(self, gain): - """ - Descript. : - """ - # self.send_cmd("Manual", self.IN_CMD_AVT_EXPOSURE_MODE) # gain mode manual - self.send_cmd(gain, self.IN_CMD_AVT_EXPOSURE_VALUE) - - def get_exposure_time(self): - """ - Descript. : - """ - info = self.get_cmd_info(self.IN_CMD_AVT_EXPOSURE_VALUE) - if info is not None: - return float(info["value"]) - return - - def set_exposure_time_auto(self, state=True): - """ - Descript. : - """ - if bool(state): - self.send_cmd("Auto", self.IN_CMD_AVT_EXPOSURE_MODE) - else: - self.send_cmd("Manual", self.IN_CMD_AVT_EXPOSURE_MODE) - - def get_exposure_time_auto(self): - """ - Descript. : - """ - value = None - info = self.get_cmd_info(self.IN_CMD_AVT_EXPOSURE_MODE) - if info is not None: - value = info["menu"][info["value"]] == "Auto" - return value - - def get_exposure_time_min_max(self): - """ - Descript. : - """ - info = self.get_cmd_info(self.IN_CMD_AVT_EXPOSURE_VALUE) - if info is not None: - return (float(info["min"]), float(info["max"])) - return - - def zoom_exists(self): - """ - Descript. : True if the device supports digital zooming. - """ - return self.input_avt and self.sensor_dimensions is not None - - def set_zoom(self, zoom): - """ - Descript. : Sets digital zoom factor. - """ - self.changing_pars = True - - if zoom == 0: - self.using_overview = True - width = self.sensor_dimensions[0] - 200 - height = self.sensor_dimensions[1] - 200 - - offx, offy = self.overview_offsetx, self.overview_offsety - - pos_x = int(60) - pos_y = int(232) - else: - self.using_overview = False - - print("setting zoom to %s" % zoom) - - limits = self.get_zoom_min_max() - if zoom < limits[0] or zoom > limits[1]: - return - - display_dimensions = self.image_dimensions - width = display_dimensions[0] / zoom - height = display_dimensions[1] / zoom - - pos_x = (self.sensor_dimensions[0] - width) / 2 - pos_y = (self.sensor_dimensions[1] - height) / 2 - - pos_x = int(pos_x) - pos_y = int(pos_y) - - width = int(width) - height = int(height) - - self.send_cmd(1, self.IN_CMD_AVT_BINNING_X) - gevent.sleep(0.1) - self.send_cmd(1, self.IN_CMD_AVT_BINNING_Y) - gevent.sleep(0.1) - - for i in range(3): # try to program it three times - if pos_x == 0: - self.send_cmd(pos_x, self.IN_CMD_AVT_REGION_X) - gevent.sleep(0.01) - if pos_y == 0: - self.send_cmd(pos_y, self.IN_CMD_AVT_REGION_Y) - gevent.sleep(0.01) - - self.send_cmd(width, self.IN_CMD_AVT_WIDTH) - gevent.sleep(0.01) - self.send_cmd(height, self.IN_CMD_AVT_HEIGHT) - gevent.sleep(0.01) - - if pos_y > 0: - self.send_cmd(pos_y, self.IN_CMD_AVT_REGION_Y) - gevent.sleep(0.01) - if pos_x > 0: - self.send_cmd(pos_x, self.IN_CMD_AVT_REGION_X) - gevent.sleep(0.01) - - x_i = int(self.get_cmd_info(self.IN_CMD_AVT_REGION_X)["value"]) - y_i = int(self.get_cmd_info(self.IN_CMD_AVT_REGION_Y)["value"]) - w_i = int(self.get_cmd_info(self.IN_CMD_AVT_WIDTH)["value"]) - h_i = int(self.get_cmd_info(self.IN_CMD_AVT_HEIGHT)["value"]) - - print("zoom: %s" % zoom) - print("pos_x (%s, %s) - pos_y (%s,%s) " % (pos_x, x_i, pos_y, y_i)) - print("width (%s, %s) - height (%s,%s) " % (width, w_i, height, h_i)) - - if ( - abs(x_i - pos_x) > 3 - or abs(y_i - pos_y) > 3 - or abs(w_i - width) > 3 - or abs(h_i - height) > 3 - ): - self.log.debug(" - trying to program zoom again") - gevent.sleep(0.1) - continue - else: - break - - self.changing_pars = False - - self.emit("zoomChanged", self.get_zoom()) - - def get_zoom(self): - """ - Descript. : Returns the digital zoom factor. - """ - if self.using_overview: - return 0 - - info = self.get_cmd_info(self.IN_CMD_AVT_WIDTH) - if info is not None: - return self.image_dimensions[0] / float(info["value"]) - - return None - - def get_zoom_min_max(self): - """ - Descript. : Returns the limits for the digital zoom factor. - The upper limit is arbitrarily defined. - """ - return (self.image_dimensions[0] / float(self.sensor_dimensions[0]), 2) - - def set_live(self, mode): - """ - Descript. : - """ - return - - def get_width(self): - """ - Descript. : - """ - return self.image_dimensions[0] - - def get_height(self): - """ - Descript. : - """ - return self.image_dimensions[1] - - def get_new_image(self): - """ - Descript. : reads new image, flips it if necessary and returns the - result or None on error - """ - if self.using_overview: - fliph, flipv = self.overview_fliph, self.overview_flipv - offx, offy = self.overview_offsetx, self.overview_offsety - else: - fliph, flipv = self.standard_fliph, self.standard_flipv - offx, offy = self.standard_offsetx, self.standard_offsety - - image = self.http_get("?action=snapshot") - if image is not None: - return QImage.fromData(image).mirrored(fliph, flipv) - return None - - def refresh_video(self): - """ - Descript. : reads new image into member variable, scales it and emits - imageReceived event. Added for compatibility. - """ - image = self.get_new_image() - if image is not None: - image = image.scaled(self.display_width, self.display_height) - # image.setOffset(QPoint(300,300)) - self.image = QPixmap.fromImage( - image.scaled(self.display_width, self.display_height) - ) - self.emit("imageReceived", self.image) - - def take_snapshot(self, filename, bw=False): - """ - Descript. : calls get_new_image() and saves the result - """ - try: - qimage = self.get_new_image() - # TODO convert to grayscale - # if bw: - # qimage.setNumColors(0) - qimage.save(filename, "PNG") - except Exception: - self.log.error("MjpgStreamVideo: unable to save snapshot: %s" % filename) - - def _do_imagePolling(self, sleep_time): - """ - Descript. : worker method - """ - while True: - while self.changing_pars: - self.log.debug(" / not reading image. busy changing pars") - gevent.sleep(sleep_time) - continue - - image = self.get_new_image() - if image is not None: - # image.setOffset(QPoint(300,300)) - # self.image = QPixmap.fromImage(image) - self.image = QPixmap.fromImage( - image.scaled(self.display_width, self.display_height) - ) - self.emit("imageReceived", self.image) - # gevent.sleep(0.1) From 13bfad3db79c32844f712bddf69dabfe89eaa6c0 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 15 Nov 2023 16:02:00 +0100 Subject: [PATCH 140/151] Removed unused DigitalZoomMotor.py --- .../HardwareObjects/DESY/DigitalZoomMotor.py | 137 ------------------ 1 file changed, 137 deletions(-) delete mode 100644 mxcubecore/HardwareObjects/DESY/DigitalZoomMotor.py diff --git a/mxcubecore/HardwareObjects/DESY/DigitalZoomMotor.py b/mxcubecore/HardwareObjects/DESY/DigitalZoomMotor.py deleted file mode 100644 index 6ccd09999b..0000000000 --- a/mxcubecore/HardwareObjects/DESY/DigitalZoomMotor.py +++ /dev/null @@ -1,137 +0,0 @@ -# -# Project: MXCuBE -# https://github.com/mxcube -# -# This file is part of MXCuBE software. -# -# MXCuBE is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# MXCuBE is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with MXCuBE. If not, see . - - -__author__ = "Jan Meyer" -__email__ = "jan.meyer@desy.de" -__copyright__ = "(c)2016 DESY, FS-PE, P11" -__license__ = "GPL" - - -import logging -from mxcubecore.BaseHardwareObjects import Device -from mxcubecore.HardwareObjects.abstract.AbstractMotor import AbstractMotor -from mxcubecore.HardwareObjects.abstract.AbstractMotor import MotorStates - - -class DigitalZoomMotor(AbstractMotor, Device): - """ - Works with camera devices which provide - zoom_exists, set_zoom, get_zoom and get_zoom_min_max - - Zoom - Zoom - - - """ - - def __init__(self, name): - AbstractMotor.__init__(self, name) - Device.__init__(self, name) - self.camera = None - - def init(self): - self.set_limits((1.0, 1.0)) - try: - self.camera = self.get_object_by_role("camera") - except KeyError: - logging.getLogger("HWR").warning("DigitalZoomMotor: camera not defined") - return - try: - self.read_only = not (self.camera.zoom_exists()) - except AttributeError: - self.read_only = True - if not self.read_only: - limits = self.camera.get_zoom_min_max() - if limits[0] is None: - limits[0] = -1000 - if limits[1] is None: - limits[1] = 1000 - self.set_limits(limits) - self.set_position(self.camera.get_zoom()) - self.update_state(self.STATES.READY) - else: - self.update_state(self.STATES.OFF) - logging.getLogger("HWR").warning( - "DigitalZoomMotor: digital zoom is not supported " "by camera object" - ) - - self.set_is_ready(self.get_state() == MotorStates.READY) - - def update_state(self): - """ - Descript. : forces position update - """ - self.motor_position_changed() - - def motor_position_changed(self, position=None): - """ - Descript. : called by move and updateState. if the position has - changed valueChanged is fired if the position is at one - of the limits the state is set accordingly on state - changes, stateChanged is fired - """ - if position is None: - if self.read_only: - position = 1.0 - else: - position = self.camera.get_zoom() - - if position != self.get_value(): - current_motor_state = self.get_state() - if position <= self.get_limits()[0]: - self.update_state(MotorStates.LOWLIMIT) - elif position >= self.get_limits()[1]: - self.update_state(MotorStates.HIGHLIMIT) - else: - current_motor_state = MotorStates.READY - if (not self.read_only) and current_motor_state != self.get_state(): - self.update_state(current_motor_state) - self.emit("stateChanged", (current_motor_state,)) - self.set_position(position) - self.emit("valueChanged", (position,)) - - # def get_limits(self): - # """ - # Descript. : returns motor limits. If no limits channel defined then - # static_limits is returned - # """ - # return self.limits - - def get_value(self): - if self.read_only: - self.motor_position = 1.0 - else: - self.motor_position = self.camera.get_zoom() - return self.motor_position - - def _set_value(self, value): - """ - Descript. : move to the given position - """ - self.camera.set_zoom(value) - self.motor_position_changed(value) - - def stop(self): - """ - Descript. : does nothing, for position change is instantaneous - """ - - def is_moving(self): - return False From 85c48621669005f49d691b60b9f9e5f53ae705a9 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Wed, 15 Nov 2023 16:04:48 +0100 Subject: [PATCH 141/151] Removed unused Centring.py --- mxcubecore/HardwareObjects/DESY/Centring.py | 157 -------------------- 1 file changed, 157 deletions(-) delete mode 100644 mxcubecore/HardwareObjects/DESY/Centring.py diff --git a/mxcubecore/HardwareObjects/DESY/Centring.py b/mxcubecore/HardwareObjects/DESY/Centring.py deleted file mode 100644 index f195cc1e57..0000000000 --- a/mxcubecore/HardwareObjects/DESY/Centring.py +++ /dev/null @@ -1,157 +0,0 @@ -# encoding: utf-8 -# -# Project: MXCuBE -# https://github.com/mxcube -# -# This file is part of MXCuBE software. -# -# MXCuBE is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# MXCuBE is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with MXCuBE. If not, see . - -__copyright__ = """ Copyright © 2010 - 2020 by MXCuBE Collaboration """ -__license__ = "LGPLv3+" - - -import gevent - -from mxcubecore.BaseHardwareObjects import HardwareObject -from mxcubecore.BaseHardwareObjects import Device -from gevent import Timeout -import numpy - - -# import DeviceProxy function and DevState: -from PyTango import DevState -from PyTango import DeviceProxy - -last_centred_position = [200, 200] - - -class Centring(Device): - """ - Description: This class controls the operation of Tango Motor - """ - - def __init__(self, *args): - """ - Description: - """ - HardwareObject.__init__(self, *args) - self.proxyMotor = None # Hardware object to change motor attributes - self.motor_name = None # Tango name of DeviceServer controlling the motor - - def init(self): - self.gonioAxes = [] - - # self.gonioAxes = [] - # for axis in self['gonioAxes']: - # self.gonioAxes.append({'type':axis.type,'direction':eval(axis.direction),\ - # 'motor_name':axis.motorname,'motor_HO': - # HardwareRepository.get_hardware_repository().get_hardware_object(axis.motorHO) - # }) - - print("Centring Init") - print("-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+") - - def initCentringProcedure(self): - - print("initCentringProcedure(self)") - """ - Descript. : call before starting rotate-click sequence - """ - self.centringDataTensor = [] - self.centringDataMatrix = [] - self.motorConstraints = [] - - # self.centeingPoints = [Point(0.0,0.0), Point(0.0,0.0), Point(0.0,0.0)] # array of 3 points, initial values - zeroes - # print( "self.centeingPoints[0] = (", self.centeingPoints[0].x, ", ", self.centeingPoints[0].y, ")") - # print( "self.centeingPoints[1] = (", self.centeingPoints[1].x, ", ", self.centeingPoints[1].y, ")") - # print( "self.centeingPoints[2] = (", self.centeingPoints[2].x, ", ", self.centeingPoints[2].y, ")") - - print("Centring initCentringProcedure") - print("-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+") - - def appendCentringDataPoint(self, camera_coordinates): - """ - Descript. : call after each click and send click points - but relative in mm - """ - # self.centringDataTensor.append(self.factor_matrix()) - self.centringDataMatrix.append( - self.camera_coordinates_to_vector(camera_coordinates) - ) - - ll = len(self.centringDataMatrix) - print(("len(self.centringDataMatrix) = ", ll)) - - print(("self.centringDataMatrix = ", self.centringDataMatrix[ll - 1])) - - print("appendCentringDataPoint(self)") - print("-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+") - - # def setCentringDataPoint(self, i, camera_coordinates): - # print("camera_coordinates['X'] = ", camera_coordinates['X']) - # print("camera_coordinates['Y'] = ", camera_coordinates['Y']) - # #self.centeingPoints[i] = point(camera_coordinates['X'], camera_coordinates['Y']]) - # print("appendCentringDataPoint(self)") - # print( '-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+') - - def centeredPosition(self, return_by_name=False): - """ - Descript. : call after appending the last click. - Return : {motorHO:position} dictionary. - - M=numpy.zeros(shape=(self.translationAxesCount,self.translationAxesCount)) - V=numpy.zeros(shape=(self.translationAxesCount)) - - for l in range(0,self.translationAxesCount): - for i in range (0,len(self.centringDataMatrix)): - for k in range(0,len(self.cameraAxes)): - V[l] += self.centringDataTensor[i][l][k]*self.centringDataMatrix[i][k] - for m in range(0,self.translationAxesCount): - for i in range (0,len(self.centringDataMatrix)): - for k in range(0,len(self.cameraAxes)): - M[l][m] += self.centringDataTensor[i][l][k]*self.centringDataTensor[i][m][k] - tau_cntrd = numpy.dot(numpy.linalg.pinv(M,rcond=1e-6),V) - - tau_cntrd = self.apply_constraints(M,tau_cntrd) - """ - # return self.vector_to_centred_positions( - tau_cntrd + - # self.translation_datum(), return_by_name) - print("centeredPosition(self)") - print("-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+") - - return self.vector_to_centred_positions(123, 456) - - def vector_to_centred_positions(self, vector, return_by_name=False): - dic = {} - index = 0 - # for axis in self.gonioAxes: - # if axis['type'] == "translation": - # if return_by_name: - # dic[axis['motor_name']]=vector[index] - # else: - # dic[axis['motor_HO']]=vector[index] - # index += 1 - - print("vector_to_centred_positions(self)") - print("-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+") - - return dic - - def camera_coordinates_to_vector(self, camera_coordinates_dictionary): - vector = [] - - vector.append(camera_coordinates_dictionary["X"]) - vector.append(camera_coordinates_dictionary["Y"]) - - return vector From 85bc098537629dac3fa49aea6b8f7cee285a710c Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Mon, 27 Nov 2023 14:39:50 +0100 Subject: [PATCH 142/151] Put back deleted by mistake class --- .../HardwareObjects/DESY/MjpgStreamVideo.py | 974 ++++++++++++++++++ 1 file changed, 974 insertions(+) create mode 100644 mxcubecore/HardwareObjects/DESY/MjpgStreamVideo.py diff --git a/mxcubecore/HardwareObjects/DESY/MjpgStreamVideo.py b/mxcubecore/HardwareObjects/DESY/MjpgStreamVideo.py new file mode 100644 index 0000000000..310bb967a6 --- /dev/null +++ b/mxcubecore/HardwareObjects/DESY/MjpgStreamVideo.py @@ -0,0 +1,974 @@ +# +# Project: MXCuBE +# https://github.com/mxcube +# +# This file is part of MXCuBE software. +# +# MXCuBE is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# MXCuBE is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with MXCuBE. If not, see . + +__author__ = "Jan Meyer" +__email__ = "jan.meyer@desy.de" +__copyright__ = "(c)2015 DESY, FS-PE, P11" +__license__ = "GPL" + + +import gevent + +try: + from httplib import HTTPConnection +except ImportError: + from http.client import HTTPConnection +import json + +from mxcubecore.utils.qt_import import QImage, QPixmap, QPoint +from mxcubecore.utils.conversion import string_types + +from mxcubecore.HardwareObjects.abstract.AbstractVideoDevice import AbstractVideoDevice + +from mxcubecore.BaseHardwareObjects import Device + + +class MjpgStreamVideo(AbstractVideoDevice, Device): + """ + Hardware object to capture images using mjpg-streamer + and it's input_avt.so plugin for AVT Prosilica cameras. + """ + + # command / control types supported by mjpg-streamer + CTRL_TYPE_INTEGER = 1 + CTRL_TYPE_BOOLEAN = 2 + CTRL_TYPE_MENU = 3 + CTRL_TYPE_BUTTON = 4 + + # command destinations + DEST_INPUT = 0 + DEST_OUTPUT = 1 + DEST_PROGRAM = 2 + + # command groups + IN_CMD_GROUP_GENERIC = 0 + IN_CMD_GROUP_RESOLUTION = 2 + IN_CMD_GROUP_JPEG_QUALITY = 3 + IN_CMD_GROUP_AVT_MISC = 32 + IN_CMD_GROUP_AVT_INFO = 33 + IN_CMD_GROUP_AVT_EXPOSURE = 34 + IN_CMD_GROUP_AVT_GAIN = 35 + IN_CMD_GROUP_AVT_LENS_DRIVE = 36 + IN_CMD_GROUP_AVT_IRIS = 37 + IN_CMD_GROUP_AVT_WHITE_BALANCE = 38 + IN_CMD_GROUP_AVT_DSP = 39 + IN_CMD_GROUP_AVT_IMAGE_FORMAT = 40 + IN_CMD_GROUP_AVT_IO = 41 + IN_CMD_GROUP_AVT_ACQUISITION = 42 + IN_CMD_GROUP_AVT_CONFIG_FILE = 43 + IN_CMD_GROUP_AVT_NETWORK = 44 + IN_CMD_GROUP_AVT_STATS = 45 + IN_CMD_GROUP_AVT_EVENTS = 46 + + # commands + # note: not every camera supports every command + # mjpg-streamer only supports integer values for commands + # float values are therefore submitted as an integer value * 1000 + # booleans will only accept 0 or 1 + # menus have an integer identifier for every item + # commands will ignore the given value + # strings and events are unsupported yet + # for more information see the "AVT Camera and Driver Attributes" manual + IN_CMD_UPDATE_CONTROLS = (1, IN_CMD_GROUP_GENERIC) + IN_CMD_JPEG_QUALITY = (1, IN_CMD_GROUP_JPEG_QUALITY) + IN_CMD_AVT_ACQ_END_TRIGGER_EVENT = (6, IN_CMD_GROUP_AVT_ACQUISITION) + IN_CMD_AVT_ACQ_END_TRIGGER_MODE = (7, IN_CMD_GROUP_AVT_ACQUISITION) + IN_CMD_AVT_ACQ_REC_TRIGGER_EVENT = (8, IN_CMD_GROUP_AVT_ACQUISITION) + IN_CMD_AVT_ACQ_REC_TRIGGER_MODE = (9, IN_CMD_GROUP_AVT_ACQUISITION) + IN_CMD_AVT_ACQ_START_TRIGGER_EVENT = (10, IN_CMD_GROUP_AVT_ACQUISITION) + IN_CMD_AVT_ACQ_START_TRIGGER_MODE = (11, IN_CMD_GROUP_AVT_ACQUISITION) + IN_CMD_AVT_ACQUISITION_ABORT = (5, IN_CMD_GROUP_AVT_ACQUISITION) + IN_CMD_AVT_ACQUISITION_FRAME_COUNT = (2, IN_CMD_GROUP_AVT_ACQUISITION) + IN_CMD_AVT_ACQUISITION_MODE = (1, IN_CMD_GROUP_AVT_ACQUISITION) + IN_CMD_AVT_ACQUISITION_START = (3, IN_CMD_GROUP_AVT_ACQUISITION) + IN_CMD_AVT_ACQUISITION_STOP = (4, IN_CMD_GROUP_AVT_ACQUISITION) + IN_CMD_AVT_BANDWIDTH_CTRL_MODE = (1, IN_CMD_GROUP_AVT_NETWORK) + IN_CMD_AVT_BINNING_X = (1, IN_CMD_GROUP_AVT_IMAGE_FORMAT) + IN_CMD_AVT_BINNING_Y = (2, IN_CMD_GROUP_AVT_IMAGE_FORMAT) + # String 2 IN_CMD_AVT_CAMERA_NAME = (0, IN_CMD_GROUP_AVT_INFO) + IN_CMD_AVT_CHUNK_MODE_ACTIVE = (2, IN_CMD_GROUP_AVT_NETWORK) + IN_CMD_AVT_CONFIG_FILE_INDEX = (1, IN_CMD_GROUP_AVT_CONFIG_FILE) + IN_CMD_AVT_CONFIG_FILE_LOAD = (3, IN_CMD_GROUP_AVT_CONFIG_FILE) + IN_CMD_AVT_CONFIG_FILE_POWER_UP = (2, IN_CMD_GROUP_AVT_CONFIG_FILE) + IN_CMD_AVT_CONFIG_FILE_SAVE = (4, IN_CMD_GROUP_AVT_CONFIG_FILE) + IN_CMD_AVT_DSP_SUBREGION_BOTTOM = (4, IN_CMD_GROUP_AVT_DSP) + IN_CMD_AVT_DSP_SUBREGION_LEFT = (1, IN_CMD_GROUP_AVT_DSP) + IN_CMD_AVT_DSP_SUBREGION_RIGHT = (3, IN_CMD_GROUP_AVT_DSP) + IN_CMD_AVT_DSP_SUBREGION_TOP = (2, IN_CMD_GROUP_AVT_DSP) + IN_CMD_AVT_DEFECT_MASK_COLUMN_ENABLE = (1, IN_CMD_GROUP_AVT_MISC) + # String 14 IN_CMD_AVT_DEVICE_ETH_ADDRESS = (0, IN_CMD_GROUP_AVT_NETWORK) + # String 3 IN_CMD_AVT_DEVICE_FIRMWARE_VERSION = (0, IN_CMD_GROUP_AVT_INFO) + # String 15 IN_CMD_AVT_DEVICE_IP_ADDRESS = (0, IN_CMD_GROUP_AVT_NETWORK) + # String 4 IN_CMD_AVT_DEVICE_MODEL_NAME = (0, IN_CMD_GROUP_AVT_INFO) + # String 5 IN_CMD_AVT_DEVICE_PART_NUMBER = (0, IN_CMD_GROUP_AVT_INFO) + # String 6 IN_CMD_AVT_DEVICE_SCAN_TYPE = (0, IN_CMD_GROUP_AVT_INFO) + # String 7 IN_CMD_AVT_DEVICE_SERIAL_NUMBER = (0, IN_CMD_GROUP_AVT_INFO) + # String 8 IN_CMD_AVT_DEVICE_VENDOR_NAME = (0, IN_CMD_GROUP_AVT_INFO) + # Event IN_CMD_AVT_EVENT_ACQUISITION_END = (0, IN_CMD_GROUP_AVT_EVENTS) + # Event IN_CMD_AVT_EVENT_ACQUISITION_RECORD_TRIGGER = (0, IN_CMD_GROUP_AVT_EVENTS) + # Event IN_CMD_AVT_EVENT_ACQUISITION_START = (0, IN_CMD_GROUP_AVT_EVENTS) + # Event IN_CMD_AVT_EVENT_ERROR = (0, IN_CMD_GROUP_AVT_EVENTS) + # Event IN_CMD_AVT_EVENT_EXPOSURE_END = (0, IN_CMD_GROUP_AVT_EVENTS) + # Event IN_CMD_AVT_EVENT_FRAME_TRIGGER = (0, IN_CMD_GROUP_AVT_EVENTS) + # Event IN_CMD_AVT_EVENT_NOTIFICATION = (0, IN_CMD_GROUP_AVT_EVENTS) + # Event IN_CMD_AVT_EVENT_OVERFLOW = (0, IN_CMD_GROUP_AVT_EVENTS) + # Event IN_CMD_AVT_EVENT_SELECTOR = (0, IN_CMD_GROUP_AVT_EVENTS) + # Event IN_CMD_AVT_EVENT_SYNC_IN1_FALL = (0, IN_CMD_GROUP_AVT_EVENTS) + # Event IN_CMD_AVT_EVENT_SYNC_IN1_RISE = (0, IN_CMD_GROUP_AVT_EVENTS) + # Event IN_CMD_AVT_EVENT_SYNC_IN2_FALL = (0, IN_CMD_GROUP_AVT_EVENTS) + # Event IN_CMD_AVT_EVENT_SYNC_IN2_RISE = (0, IN_CMD_GROUP_AVT_EVENTS) + # Event IN_CMD_AVT_EVENT_SYNC_IN3_FALL = (0, IN_CMD_GROUP_AVT_EVENTS) + # Event IN_CMD_AVT_EVENT_SYNC_IN3_RISE = (0, IN_CMD_GROUP_AVT_EVENTS) + # Event IN_CMD_AVT_EVENT_SYNC_IN4_FALL = (0, IN_CMD_GROUP_AVT_EVENTS) + # Event IN_CMD_AVT_EVENT_SYNC_IN4_RISE = (0, IN_CMD_GROUP_AVT_EVENTS) + # Event IN_CMD_AVT_EVENTS_ENABLE1 = (0, IN_CMD_GROUP_AVT_EVENTS) + IN_CMD_AVT_EXPOSURE_AUTO_ADJUST_TOL = (3, IN_CMD_GROUP_AVT_EXPOSURE) + IN_CMD_AVT_EXPOSURE_AUTO_ALG = (4, IN_CMD_GROUP_AVT_EXPOSURE) + IN_CMD_AVT_EXPOSURE_AUTO_MAX = (5, IN_CMD_GROUP_AVT_EXPOSURE) + IN_CMD_AVT_EXPOSURE_AUTO_MIN = (6, IN_CMD_GROUP_AVT_EXPOSURE) + IN_CMD_AVT_EXPOSURE_AUTO_OUTLIERS = (7, IN_CMD_GROUP_AVT_EXPOSURE) + IN_CMD_AVT_EXPOSURE_AUTO_RATE = (8, IN_CMD_GROUP_AVT_EXPOSURE) + IN_CMD_AVT_EXPOSURE_AUTO_TARGET = (9, IN_CMD_GROUP_AVT_EXPOSURE) + IN_CMD_AVT_EXPOSURE_MODE = (2, IN_CMD_GROUP_AVT_EXPOSURE) + IN_CMD_AVT_EXPOSURE_VALUE = (1, IN_CMD_GROUP_AVT_EXPOSURE) + IN_CMD_AVT_FIRMWARE_VER_BUILD = (9, IN_CMD_GROUP_AVT_INFO) + IN_CMD_AVT_FIRMWARE_VER_MAJOR = (10, IN_CMD_GROUP_AVT_INFO) + IN_CMD_AVT_FIRMWARE_VER_MINOR = (11, IN_CMD_GROUP_AVT_INFO) + IN_CMD_AVT_FRAMERATE = (12, IN_CMD_GROUP_AVT_ACQUISITION) + IN_CMD_AVT_FRAME_START_TRIGGER_DELAY = (14, IN_CMD_GROUP_AVT_ACQUISITION) + IN_CMD_AVT_FRAME_START_TRIGGER_EVENT = (15, IN_CMD_GROUP_AVT_ACQUISITION) + IN_CMD_AVT_FRAME_START_TRIGGER_MODE = (13, IN_CMD_GROUP_AVT_ACQUISITION) + IN_CMD_AVT_FRAME_START_TRIGGER_OVERLAP = (16, IN_CMD_GROUP_AVT_ACQUISITION) + IN_CMD_AVT_FRAME_START_TRIGGER_SOFTWARE = (17, IN_CMD_GROUP_AVT_ACQUISITION) + IN_CMD_AVT_GAIN_AUTO_ADJUST_TOL = (3, IN_CMD_GROUP_AVT_GAIN) + IN_CMD_AVT_GAIN_AUTO_MAX = (4, IN_CMD_GROUP_AVT_GAIN) + IN_CMD_AVT_GAIN_AUTO_MIN = (5, IN_CMD_GROUP_AVT_GAIN) + IN_CMD_AVT_GAIN_AUTO_OUTLIERS = (6, IN_CMD_GROUP_AVT_GAIN) + IN_CMD_AVT_GAIN_AUTO_RATE = (7, IN_CMD_GROUP_AVT_GAIN) + IN_CMD_AVT_GAIN_AUTO_TARGET = (8, IN_CMD_GROUP_AVT_GAIN) + IN_CMD_AVT_GAIN_MODE = (2, IN_CMD_GROUP_AVT_GAIN) + IN_CMD_AVT_GAIN_VALUE = (1, IN_CMD_GROUP_AVT_GAIN) + IN_CMD_AVT_GVSP_LOOKBACK_WINDOW = (18, IN_CMD_GROUP_AVT_NETWORK) + IN_CMD_AVT_GVSP_RESEND_PERCENT = (19, IN_CMD_GROUP_AVT_NETWORK) + IN_CMD_AVT_GVSP_RETRIES = (20, IN_CMD_GROUP_AVT_NETWORK) + IN_CMD_AVT_GVSP_SOCKET_BUFFERS_COUNT = (21, IN_CMD_GROUP_AVT_NETWORK) + IN_CMD_AVT_GVSP_TIMEOUT = (22, IN_CMD_GROUP_AVT_NETWORK) + IN_CMD_AVT_HEARTBEAT_INTERVAL = (23, IN_CMD_GROUP_AVT_NETWORK) + IN_CMD_AVT_HEARTBEAT_TIMEOUT = (24, IN_CMD_GROUP_AVT_NETWORK) + IN_CMD_AVT_HEIGHT = (6, IN_CMD_GROUP_AVT_IMAGE_FORMAT) + # String 16 IN_CMD_AVT_HOST_ETH_ADDRESS = (0, IN_CMD_GROUP_AVT_NETWORK) + # String 17 IN_CMD_AVT_HOST_IP_ADDRESS = (0, IN_CMD_GROUP_AVT_NETWORK) + IN_CMD_AVT_IRIS_AUTOTARGET = (1, IN_CMD_GROUP_AVT_IRIS) + IN_CMD_AVT_IRIS_MODE = (2, IN_CMD_GROUP_AVT_IRIS) + IN_CMD_AVT_IRIS_VIDEO_LEVEL = (3, IN_CMD_GROUP_AVT_IRIS) + IN_CMD_AVT_IRIS_VIDEO_LEVEL_MAX = (4, IN_CMD_GROUP_AVT_IRIS) + IN_CMD_AVT_IRIS_VIDEO_LEVEL_MIN = (5, IN_CMD_GROUP_AVT_IRIS) + IN_CMD_AVT_LENS_DRIVE_COMMAND = (1, IN_CMD_GROUP_AVT_LENS_DRIVE) + IN_CMD_AVT_LENS_DRIVE_DURATION = (2, IN_CMD_GROUP_AVT_LENS_DRIVE) + IN_CMD_AVT_LENS_VOLTAGE = (3, IN_CMD_GROUP_AVT_LENS_DRIVE) + IN_CMD_AVT_LENS_VOLTAGE_CONTROL = (4, IN_CMD_GROUP_AVT_LENS_DRIVE) + IN_CMD_AVT_MULTICAST_ENABLE = (25, IN_CMD_GROUP_AVT_NETWORK) + # String 26 IN_CMD_AVT_MULTICAST_IP_ADDRESS = (0, IN_CMD_GROUP_AVT_NETWORK) + IN_CMD_AVT_NON_IMAGE_PAYLOAD_SIZE = (3, IN_CMD_GROUP_AVT_NETWORK) + IN_CMD_AVT_PACKET_SIZE = (27, IN_CMD_GROUP_AVT_NETWORK) + IN_CMD_AVT_PART_CLASS = (12, IN_CMD_GROUP_AVT_INFO) + IN_CMD_AVT_PART_NUMBER = (13, IN_CMD_GROUP_AVT_INFO) + # String 14 IN_CMD_AVT_PART_REVISION = (0, IN_CMD_GROUP_AVT_INFO) + # String 15 IN_CMD_AVT_PART_VERSION = (0, IN_CMD_GROUP_AVT_INFO) + IN_CMD_AVT_PAYLOAD_SIZE = (4, IN_CMD_GROUP_AVT_NETWORK) + IN_CMD_AVT_PIXEL_FORMAT = (7, IN_CMD_GROUP_AVT_IMAGE_FORMAT) + IN_CMD_AVT_RECORDER_PRE_EVENT_COUNT = (18, IN_CMD_GROUP_AVT_ACQUISITION) + IN_CMD_AVT_REGION_X = (3, IN_CMD_GROUP_AVT_IMAGE_FORMAT) + IN_CMD_AVT_REGION_Y = (4, IN_CMD_GROUP_AVT_IMAGE_FORMAT) + IN_CMD_AVT_SENSOR_BITS = (20, IN_CMD_GROUP_AVT_INFO) + IN_CMD_AVT_SENSOR_HEIGHT = (18, IN_CMD_GROUP_AVT_INFO) + IN_CMD_AVT_SENSOR_TYPE = (19, IN_CMD_GROUP_AVT_INFO) + IN_CMD_AVT_SENSOR_WIDTH = (17, IN_CMD_GROUP_AVT_INFO) + # String 16 IN_CMD_AVT_SERIAL_NUMBER = (0, IN_CMD_GROUP_AVT_INFO) + IN_CMD_AVT_STAT_DRIVER_TYPE = (1, IN_CMD_GROUP_AVT_STATS) + # String 2 IN_CMD_AVT_STAT_FILTER_VERSION = (0, IN_CMD_GROUP_AVT_STATS) + IN_CMD_AVT_STAT_FRAME_RATE = (3, IN_CMD_GROUP_AVT_STATS) + IN_CMD_AVT_STAT_FRAMES_COMPLETED = (4, IN_CMD_GROUP_AVT_STATS) + IN_CMD_AVT_STAT_FRAMES_DROPPED = (5, IN_CMD_GROUP_AVT_STATS) + IN_CMD_AVT_STAT_PACKETS_ERRONEOUS = (6, IN_CMD_GROUP_AVT_STATS) + IN_CMD_AVT_STAT_PACKETS_MISSED = (7, IN_CMD_GROUP_AVT_STATS) + IN_CMD_AVT_STAT_PACKETS_RECEIVED = (8, IN_CMD_GROUP_AVT_STATS) + IN_CMD_AVT_STAT_PACKETS_REQUESTED = (9, IN_CMD_GROUP_AVT_STATS) + IN_CMD_AVT_STAT_PACKETS_RESENT = (10, IN_CMD_GROUP_AVT_STATS) + IN_CMD_AVT_STREAM_BYTES_PER_SECOND = (6, IN_CMD_GROUP_AVT_NETWORK) + IN_CMD_AVT_STREAM_FRAME_RATE_CONSTRAIN = (5, IN_CMD_GROUP_AVT_NETWORK) + IN_CMD_AVT_STREAM_HOLD_CAPACITY = (8, IN_CMD_GROUP_AVT_NETWORK) + IN_CMD_AVT_STREAM_HOLD_ENABLE = (7, IN_CMD_GROUP_AVT_NETWORK) + IN_CMD_AVT_STROBE1_CONTROLLED_DURATION = (1, IN_CMD_GROUP_AVT_IO) + IN_CMD_AVT_STROBE1_DELAY = (3, IN_CMD_GROUP_AVT_IO) + IN_CMD_AVT_STROBE1_DURATION = (4, IN_CMD_GROUP_AVT_IO) + IN_CMD_AVT_STROBE1_MODE = (2, IN_CMD_GROUP_AVT_IO) + IN_CMD_AVT_SYNC_IN1_GLITCH_FILTER = (5, IN_CMD_GROUP_AVT_IO) + IN_CMD_AVT_SYNC_IN2_GLITCH_FILTER = (6, IN_CMD_GROUP_AVT_IO) + IN_CMD_AVT_SYNC_IN_LEVELS = (7, IN_CMD_GROUP_AVT_IO) + IN_CMD_AVT_SYNC_OUT1_INVERT = (9, IN_CMD_GROUP_AVT_IO) + IN_CMD_AVT_SYNC_OUT1_MODE = (10, IN_CMD_GROUP_AVT_IO) + IN_CMD_AVT_SYNC_OUT2_INVERT = (11, IN_CMD_GROUP_AVT_IO) + IN_CMD_AVT_SYNC_OUT2_MODE = (12, IN_CMD_GROUP_AVT_IO) + IN_CMD_AVT_SYNC_OUT3_INVERT = (13, IN_CMD_GROUP_AVT_IO) + IN_CMD_AVT_SYNC_OUT3_MODE = (14, IN_CMD_GROUP_AVT_IO) + IN_CMD_AVT_SYNC_OUT4_INVERT = (15, IN_CMD_GROUP_AVT_IO) + IN_CMD_AVT_SYNC_OUT4_MODE = (16, IN_CMD_GROUP_AVT_IO) + IN_CMD_AVT_SYNC_OUT_GPO_LEVELS = (8, IN_CMD_GROUP_AVT_IO) + IN_CMD_AVT_TIME_STAMP_FREQUENCY = (9, IN_CMD_GROUP_AVT_NETWORK) + IN_CMD_AVT_TIME_STAMP_RESET = (13, IN_CMD_GROUP_AVT_NETWORK) + IN_CMD_AVT_TIME_STAMP_VALUE_HI = (11, IN_CMD_GROUP_AVT_NETWORK) + IN_CMD_AVT_TIME_STAMP_VALUE_LATCH = (12, IN_CMD_GROUP_AVT_NETWORK) + IN_CMD_AVT_TIME_STAMP_VALUE_LO = (10, IN_CMD_GROUP_AVT_NETWORK) + IN_CMD_AVT_TOTAL_BYTES_PER_FRAME = (8, IN_CMD_GROUP_AVT_IMAGE_FORMAT) + IN_CMD_AVT_UNIQUE_ID = (1, IN_CMD_GROUP_AVT_INFO) + IN_CMD_AVT_VSUB_VALUE = (2, IN_CMD_GROUP_AVT_MISC) + IN_CMD_AVT_WHITEBAL_AUTO_ADJUST_TOL = (4, IN_CMD_GROUP_AVT_WHITE_BALANCE) + IN_CMD_AVT_WHITEBAL_AUTO_RATE = (5, IN_CMD_GROUP_AVT_WHITE_BALANCE) + IN_CMD_AVT_WHITEBAL_MODE = (3, IN_CMD_GROUP_AVT_WHITE_BALANCE) + IN_CMD_AVT_WHITEBAL_VALUE_BLUE = (2, IN_CMD_GROUP_AVT_WHITE_BALANCE) + IN_CMD_AVT_WHITEBAL_VALUE_RED = (1, IN_CMD_GROUP_AVT_WHITE_BALANCE) + IN_CMD_AVT_WIDTH = (5, IN_CMD_GROUP_AVT_IMAGE_FORMAT) + + def __init__(self, name): + """ + Descript. : + """ + AbstractVideoDevice.__init__(self, name) + self.force_update = None + self.sensor_dimensions = None + self.image_dimensions = None + self.image_polling = None + self.image_type = None + self.image = None + self.sleep_time = 1 + self.host = None + self.port = None + self.path = "/" + self.plugin = 0 + self.update_controls = None + self.input_avt = None + + self.changing_pars = False + + def init(self): + """ + Descript. : + """ + self.sleep_time = self.get_property("interval") + + hw_width = self.get_property("width") + hw_height = self.get_property("height") + scale = self.get_property("scale", 1) + + self.display_width = hw_width * scale + self.display_height = hw_height * scale + + self.log.debug( + " MJPG video - width=%s,height=%s - scale=%s" % (hw_width, hw_height, scale) + ) + self.hw_dimensions = (hw_width, hw_height) + self.image_dimensions = (self.display_width, self.display_height) + self.scale = scale + + self.host = self.get_property("host") + self.port = int(self.get_property("port")) + + self.standard_fliph = bool(self.get_property("fliph")) + self.standard_flipv = bool(self.get_property("flipv")) + self.standard_offsetx = 0 + self.standard_offsety = 0 + + # parameters for overview camera + self.overview_host = self.get_property("overview_host") + self.overview_port = int(self.get_property("overview_port")) + self.overview_fliph = bool(self.get_property("overview_fliph")) + self.overview_flipv = bool(self.get_property("overview_flipv")) + self.overview_offsetx = bool(self.get_property("overview_offsetx")) + self.overview_offsety = bool(self.get_property("overview_offsety")) + + self.path = "/" + self.plugin = 0 + + self.using_overview = False + + self.update_controls = self.has_update_controls() + self.input_avt = self.is_input_avt() + + self.image = self.get_new_image() + + if self.input_avt: + sensor_info = self.get_cmd_info(self.IN_CMD_AVT_SENSOR_WIDTH) + if sensor_info: + sensor_width = int(sensor_info["value"]) + sensor_info = self.get_cmd_info(self.IN_CMD_AVT_SENSOR_HEIGHT) + if sensor_info: + sensor_height = int(sensor_info["value"]) + self.sensor_dimensions = (sensor_width, sensor_height) + + self.set_is_ready(True) + self.set_zoom(0) # overview camera + + def http_get(self, query, host=None, port=None, path=None): + """Sends HTTP GET requests and returns the answer. + + Keyword arguments: + query -- string appended to the end of the requested URL + host -- queried IP or hostname (default host of the MjpgStream instance) + port -- queried port number (default port of the MjpgStream instance) + path -- queried path (default path of the MjpgStream instance) + + Return value: + the HTTP answer content or None on error + + """ + if self.using_overview is True: + host = self.overview_host + port = self.overview_port + path = self.path + else: + host = self.host + port = self.port + path = self.path + + # send get request and return response + http = HTTPConnection(host, port, timeout=3) + # self.log.debug("MjpgStreamVideo: %s:%s - sending %s / %s " % (host,port,path,query)) + + try: + http.request("GET", path + query) + response = http.getresponse() + except Exception: + self.log.error( + "MjpgStreamVideo: Connection to http://{0}:{1}{2}{3} refused".format( + host, port, path, query + ) + ) + return None + if response.status != 200: + self.log.error( + "MjpgStreamVideo: Error {0}, {1}".format( + response.status, response.reason + ) + ) + return None + data = response.read() + http.close() + return data + + def send_cmd(self, value, cmd, group=None, plugin=None, dest=None): + """Sends a command to mjpg-streamer. + + Keyword arguments: + value -- command parameter as integer or item name as string if the command is of enumeration type + cmd -- command id number or tuple constant + group -- command group number, leave it at None if a tuple is given as cmd (default None) + plugin -- plugin number (default plugin of the MjpgStream instance) + dest -- command destination (default MjpgStream.DEST_INPUT) + + """ + if isinstance(cmd, tuple) and group is None: + group = cmd[1] + cmd = cmd[0] + elif isinstance(cmd, tuple): + cmd = cmd[0] + if group is None: + return None + cmd = str(int(cmd)) + group = str(int(group)) + try: + value = str(int(value)) + except Exception: + option = value + value = None + if isinstance(option, string_types): + info = self.get_cmd_info(cmd, group) + if info and "menu" in info and option in info["menu"].values(): + value = str( + [k for k, v in info["menu"].items() if (v == option)][0] + ) + if value is None: + return None + if plugin is None: + plugin = str(self.plugin) + else: + plugin = str(int(plugin)) + if dest is None: + dest = str(self.DEST_INPUT) + else: + dest = str(int(dest)) + # send request + self.http_get( + "?action=command&id=" + + cmd + + "&dest=" + + dest + + "&group=" + + group + + "&value=" + + value + + "&plugin=" + + plugin + ) + + def has_cmd(self, cmd, group=None, plugin=None, dest=None): + """Checks whether a command with the given id and group is known by the specified plugin. + + Keyword arguments: + cmd -- command id number or tuple constant + group -- command group number, leave it at None if a tuple is given as cmd (default None) + plugin -- plugin number (default plugin of the MjpgStream instance) + dest -- command destination (default MjpgStream.DEST_INPUT) + + Return value: + True if so, False if not or the connection was refused + + """ + data = self.get_cmd_info(cmd, group, plugin, dest) + if not data is None: + return True + return False + + def get_cmd_info(self, cmd, group=None, plugin=None, dest=None): + """Returns a dictionary with informations on the queried command. + + Keyword arguments: + cmd -- command id number or tuple constant + group -- command group number, leave it at None if a tuple is given as cmd (default None) + plugin -- plugin number (default plugin of the MjpgStream instance) + dest -- command destination (default MjpgStream.DEST_INPUT) + + Return value: + dictionary containing the following items ("menu" only for menu commands): + "name", "id", "type", "min", "max", "step", "default", "value", "dest", "flags", "group", "menu" + or None on error + + """ + if isinstance(cmd, tuple) and group is None: + group = cmd[1] + cmd = cmd[0] + elif isinstance(cmd, tuple): + cmd = cmd[0] + if group is None: + return None + if plugin is None: + plugin = self.plugin + else: + plugin = str(int(plugin)) + if dest is None or (dest != self.DEST_INPUT and dest != self.DEST_OUTPUT): + dest = self.DEST_INPUT + if self.update_controls: + self.send_cmd(group, self.IN_CMD_UPDATE_CONTROLS, plugin, dest) + # get list of controls and search for the matching one + data = self.get_controls(plugin, dest) + if data is not None: + for info in data: + if int(info["group"]) == int(group) and int(info["id"]) == int(cmd): + return info + return None + + def get_controls(self, plugin=None, dest=None): + """Returns a list with information on all commands supported by the + plugin. If DEST_PROGRAM is given for dest, a list with information on + all loaded plugins is returned. + + Keyword arguments: + plugin -- plugin number (default plugin of the MjpgStream instance) + dest -- command destination (default MjpgStream.DEST_INPUT) + + Return value: + depends on destination plugin. For input_avt.so a list with all commands + supported by the connected camera is returned - q.v. get_cmd_info(). + + """ + if plugin is None: + plugin = str(self.plugin) + else: + plugin = str(int(plugin)) + if dest is None: + dest = self.DEST_INPUT + else: + dest = int(dest) + query = None + if dest == self.DEST_INPUT: + query = "input_" + plugin + ".json" + elif dest == self.DEST_OUTPUT: + query = "output_" + plugin + ".json" + elif dest == self.DEST_PROGRAM: + query = "program.json" + # fetch json from server, decode it into a python object and return it + if query is not None: + data = self.http_get(query) + if data is not None: + data = json.loads(data.decode("utf-8")) + if dest != self.DEST_PROGRAM and "controls" in data: + data = data["controls"] + return data + return None + + def has_update_controls(self): + """Checks if the default plugin for this instance knows the UpdateControls command. + + Return value: + True if so, False if not and None if the connection was refused + + """ + data = self.get_cmd_info(self.IN_CMD_UPDATE_CONTROLS) + if data is None: + return None + if data["name"] == "UpdateControls": + return True + return False + + def is_input_avt(self): + """Checks if the default plugin for this instance is input_avt.so. + + Return value: + True if so, False if not and None if the connection was refused + + """ + data = self.get_controls(0, self.DEST_PROGRAM) + if data is None: + return None + if "inputs" in data: + for info in data["inputs"]: + if info["name"][-12:] == "input_avt.so": + return True + return False + + def start_camera(self): + if self.image_polling is None: + self.image_polling = gevent.spawn( + self._do_imagePolling, 1.0 / self.sleep_time + ) + + def get_image_dimensions(self): + return self.image_dimensions + + def get_scale(self): + return self.scale + + def imageType(self): + """ + Descript. : + """ + return + + def contrast_exists(self): + """ + Descript. : + """ + return + + def set_contrast(self, contrast): + """ + Descript. : + """ + return + + def get_contrast(self): + """ + Descript. : + """ + return + + def set_contrast_auto(self, state=True): + """ + Descript. : + """ + return + + def get_contrast_auto(self): + """ + Descript. : + """ + return + + def get_contrast_min_max(self): + """ + Descript. : + """ + return + + def brightnessExists(self): + """ + Descript. : + """ + return + + def set_brightness(self, brightness): + """ + Descript. : + """ + return + + def get_brightness(self): + """ + Descript. : + """ + return + + def set_brightness_auto(self, state=True): + """ + Descript. : + """ + return + + def get_brightness_auto(self): + """ + Descript. : + """ + return + + def get_brightness_min_max(self): + """ + Descript. : + """ + return + + def gain_exists(self): + """ + Descript. : + """ + return self.has_cmd(self.IN_CMD_AVT_GAIN_VALUE) + + def set_gain(self, gain): + """ + Descript. : + """ + # self.send_cmd("Manual", self.IN_CMD_AVT_GAIN_MODE) # gain mode manual + self.send_cmd(gain, self.IN_CMD_AVT_GAIN_VALUE) + + def get_gain(self): + """ + Descript. : + """ + info = self.get_cmd_info(self.IN_CMD_AVT_GAIN_VALUE) + if info is not None: + return float(info["value"]) + return + + def set_gain_auto(self, state=True): + """ + Descript. : + """ + if bool(state): + self.send_cmd("Auto", self.IN_CMD_AVT_GAIN_MODE) + else: + self.send_cmd("Manual", self.IN_CMD_AVT_GAIN_MODE) + + def get_gain_auto(self): + """ + Descript. : + """ + value = None + info = self.get_cmd_info(self.IN_CMD_AVT_GAIN_MODE) + if info is not None: + value = info["menu"][info["value"]] == "Auto" + return value + + def get_gain_min_max(self): + """ + Descript. : + """ + info = self.get_cmd_info(self.IN_CMD_AVT_GAIN_VALUE) + if info is not None: + return (float(info["min"]), float(info["max"])) + return + + def gamma_exists(self): + """ + Descript. : + """ + return + + def set_gamma(self, gamma): + """ + Descript. : + """ + return + + def get_gamma(self): + """ + Descript. : + """ + return + + def set_gamma_auto(self, state=True): + """ + Descript. : + """ + return + + def get_gamma_auto(self): + """ + Descript. : + """ + return + + def get_gamma_min_max(self): + """ + Descript. : + """ + return (0, 1) + + def exposure_time_exists(self): + """ + Descript. : + """ + return self.has_cmd(self.IN_CMD_AVT_EXPOSURE_VALUE) + + def set_exposure_time(self, gain): + """ + Descript. : + """ + # self.send_cmd("Manual", self.IN_CMD_AVT_EXPOSURE_MODE) # gain mode manual + self.send_cmd(gain, self.IN_CMD_AVT_EXPOSURE_VALUE) + + def get_exposure_time(self): + """ + Descript. : + """ + info = self.get_cmd_info(self.IN_CMD_AVT_EXPOSURE_VALUE) + if info is not None: + return float(info["value"]) + return + + def set_exposure_time_auto(self, state=True): + """ + Descript. : + """ + if bool(state): + self.send_cmd("Auto", self.IN_CMD_AVT_EXPOSURE_MODE) + else: + self.send_cmd("Manual", self.IN_CMD_AVT_EXPOSURE_MODE) + + def get_exposure_time_auto(self): + """ + Descript. : + """ + value = None + info = self.get_cmd_info(self.IN_CMD_AVT_EXPOSURE_MODE) + if info is not None: + value = info["menu"][info["value"]] == "Auto" + return value + + def get_exposure_time_min_max(self): + """ + Descript. : + """ + info = self.get_cmd_info(self.IN_CMD_AVT_EXPOSURE_VALUE) + if info is not None: + return (float(info["min"]), float(info["max"])) + return + + def zoom_exists(self): + """ + Descript. : True if the device supports digital zooming. + """ + return self.input_avt and self.sensor_dimensions is not None + + def set_zoom(self, zoom): + """ + Descript. : Sets digital zoom factor. + """ + self.changing_pars = True + + if zoom == 0: + self.using_overview = True + width = self.sensor_dimensions[0] - 200 + height = self.sensor_dimensions[1] - 200 + + offx, offy = self.overview_offsetx, self.overview_offsety + + pos_x = int(60) + pos_y = int(232) + else: + self.using_overview = False + + print("setting zoom to %s" % zoom) + + limits = self.get_zoom_min_max() + if zoom < limits[0] or zoom > limits[1]: + return + + display_dimensions = self.image_dimensions + width = display_dimensions[0] / zoom + height = display_dimensions[1] / zoom + + pos_x = (self.sensor_dimensions[0] - width) / 2 + pos_y = (self.sensor_dimensions[1] - height) / 2 + + pos_x = int(pos_x) + pos_y = int(pos_y) + + width = int(width) + height = int(height) + + self.send_cmd(1, self.IN_CMD_AVT_BINNING_X) + gevent.sleep(0.1) + self.send_cmd(1, self.IN_CMD_AVT_BINNING_Y) + gevent.sleep(0.1) + + for i in range(3): # try to program it three times + if pos_x == 0: + self.send_cmd(pos_x, self.IN_CMD_AVT_REGION_X) + gevent.sleep(0.01) + if pos_y == 0: + self.send_cmd(pos_y, self.IN_CMD_AVT_REGION_Y) + gevent.sleep(0.01) + + self.send_cmd(width, self.IN_CMD_AVT_WIDTH) + gevent.sleep(0.01) + self.send_cmd(height, self.IN_CMD_AVT_HEIGHT) + gevent.sleep(0.01) + + if pos_y > 0: + self.send_cmd(pos_y, self.IN_CMD_AVT_REGION_Y) + gevent.sleep(0.01) + if pos_x > 0: + self.send_cmd(pos_x, self.IN_CMD_AVT_REGION_X) + gevent.sleep(0.01) + + x_i = int(self.get_cmd_info(self.IN_CMD_AVT_REGION_X)["value"]) + y_i = int(self.get_cmd_info(self.IN_CMD_AVT_REGION_Y)["value"]) + w_i = int(self.get_cmd_info(self.IN_CMD_AVT_WIDTH)["value"]) + h_i = int(self.get_cmd_info(self.IN_CMD_AVT_HEIGHT)["value"]) + + print("zoom: %s" % zoom) + print("pos_x (%s, %s) - pos_y (%s,%s) " % (pos_x, x_i, pos_y, y_i)) + print("width (%s, %s) - height (%s,%s) " % (width, w_i, height, h_i)) + + if ( + abs(x_i - pos_x) > 3 + or abs(y_i - pos_y) > 3 + or abs(w_i - width) > 3 + or abs(h_i - height) > 3 + ): + self.log.debug(" - trying to program zoom again") + gevent.sleep(0.1) + continue + else: + break + + self.changing_pars = False + + self.emit("zoomChanged", self.get_zoom()) + + def get_zoom(self): + """ + Descript. : Returns the digital zoom factor. + """ + if self.using_overview: + return 0 + + info = self.get_cmd_info(self.IN_CMD_AVT_WIDTH) + if info is not None: + return self.image_dimensions[0] / float(info["value"]) + + return None + + def get_zoom_min_max(self): + """ + Descript. : Returns the limits for the digital zoom factor. + The upper limit is arbitrarily defined. + """ + return (self.image_dimensions[0] / float(self.sensor_dimensions[0]), 2) + + def set_live(self, mode): + """ + Descript. : + """ + return + + def get_width(self): + """ + Descript. : + """ + return self.image_dimensions[0] + + def get_height(self): + """ + Descript. : + """ + return self.image_dimensions[1] + + def get_new_image(self): + """ + Descript. : reads new image, flips it if necessary and returns the + result or None on error + """ + if self.using_overview: + fliph, flipv = self.overview_fliph, self.overview_flipv + offx, offy = self.overview_offsetx, self.overview_offsety + else: + fliph, flipv = self.standard_fliph, self.standard_flipv + offx, offy = self.standard_offsetx, self.standard_offsety + + image = self.http_get("?action=snapshot") + if image is not None: + return QImage.fromData(image).mirrored(fliph, flipv) + return None + + def refresh_video(self): + """ + Descript. : reads new image into member variable, scales it and emits + imageReceived event. Added for compatibility. + """ + image = self.get_new_image() + if image is not None: + image = image.scaled(self.display_width, self.display_height) + # image.setOffset(QPoint(300,300)) + self.image = QPixmap.fromImage( + image.scaled(self.display_width, self.display_height) + ) + self.emit("imageReceived", self.image) + + def take_snapshot(self, filename, bw=False): + """ + Descript. : calls get_new_image() and saves the result + """ + try: + qimage = self.get_new_image() + # TODO convert to grayscale + # if bw: + # qimage.setNumColors(0) + qimage.save(filename, "PNG") + except Exception: + self.log.error("MjpgStreamVideo: unable to save snapshot: %s" % filename) + + def _do_imagePolling(self, sleep_time): + """ + Descript. : worker method + """ + while True: + while self.changing_pars: + self.log.debug(" / not reading image. busy changing pars") + gevent.sleep(sleep_time) + continue + + image = self.get_new_image() + if image is not None: + # image.setOffset(QPoint(300,300)) + # self.image = QPixmap.fromImage(image) + self.image = QPixmap.fromImage( + image.scaled(self.display_width, self.display_height) + ) + self.emit("imageReceived", self.image) + # gevent.sleep(0.1) From f03f7794ec0870da4f44c8d3287921ecb04a9c63 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Mon, 27 Nov 2023 15:22:22 +0100 Subject: [PATCH 143/151] Added guard variable to avoind recirsion error after sample loading in TangoMotor.py --- .../HardwareObjects/abstract/AbstractMotor.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/mxcubecore/HardwareObjects/abstract/AbstractMotor.py b/mxcubecore/HardwareObjects/abstract/AbstractMotor.py index 443fce394c..ce8888394e 100644 --- a/mxcubecore/HardwareObjects/abstract/AbstractMotor.py +++ b/mxcubecore/HardwareObjects/abstract/AbstractMotor.py @@ -28,9 +28,7 @@ from enum import Enum, unique from mxcubecore.BaseHardwareObjects import HardwareObjectState -from mxcubecore.HardwareObjects.abstract.AbstractActuator import ( - AbstractActuator, -) +from mxcubecore.HardwareObjects.abstract.AbstractActuator import AbstractActuator __copyright__ = """ Copyright © 2010-2020 by the MXCuBE collaboration """ __license__ = "LGPLv3+" @@ -59,6 +57,10 @@ def __init__(self, name): self._velocity = None self._tolerance = None + # Added additional guard variable to help with the recursion error in SampleChanger + # Probably related to the comments in Tango.py in def __call__ + self._updating_value = False + def init(self): """Initialise tolerance property""" super().init() @@ -101,6 +103,11 @@ def update_value(self, value=None): Args: value (float): value """ + if self._updating_value: + return # Already updating, avoid recursion + + self._updating_value = True + if value is None: value = self.get_value() @@ -114,3 +121,5 @@ def update_value(self, value=None): self._nominal_value = value self.emit("valueChanged", (value,)) + + self._updating_value = False From 37b69158ae59613c38b12676d8796e8c5d0d3b3e Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Sat, 2 Dec 2023 15:49:59 +0100 Subject: [PATCH 144/151] Bugfix for osc_start always initialised as None in case default params in the beamline_config.yml is set strictly to 0.0. This has also fixed the red None field for Characterisation tab. --- mxcubecore/HardwareObjects/Beamline.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/mxcubecore/HardwareObjects/Beamline.py b/mxcubecore/HardwareObjects/Beamline.py index a048c48968..f879d4f0f0 100644 --- a/mxcubecore/HardwareObjects/Beamline.py +++ b/mxcubecore/HardwareObjects/Beamline.py @@ -745,11 +745,9 @@ def get_default_acquisition_parameters(self, acquisition_type="default"): setattr(acq_parameters, tag, val) motor_positions = self.diffractometer.get_positions() - osc_start = ( - None - if not params["osc_start"] - else motor_positions.get("phi", params["osc_start"]) - ) + + osc_start = motor_positions.get("phi", params["osc_start"]) + acq_parameters.osc_start = osc_start kappa = motor_positions.get("kappa", False) kappa = kappa if kappa else None From b35f10f513e4eb7bc950c7bdf54409dae1145278 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Sat, 2 Dec 2023 16:37:42 +0100 Subject: [PATCH 145/151] Fixed add_h5_info function in case the file is already existing --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 151 +++++++++++------- 1 file changed, 94 insertions(+), 57 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index 2478cd88d1..79fdec4704 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -454,75 +454,112 @@ def acquisition_cleanup(self): def add_h5_info(self, h5file): """ - The function `add_h5_info` waits for a specified amount of time for a file to appear on disk and - raises an exception if the file does not appear within the timeout period. + Add information to an HDF5 file. - :param h5file: The `h5file` parameter is the name or path of the H5 file that you want to add - information to + :param h5file: The name or path of the HDF5 file. """ self.log.debug("========== Writing H5 info ==============") - h5file = self.latest_h5_filename - # wait up to 5 seconds to see the file appear - start_wait = time.time() + # Wait for the HDF5 file to appear with a timeout + start_time = time.time() while not os.path.exists(h5file): - if time.time() - start_wait > FILE_TIMEOUT: - raise RuntimeWarning( - "Cannot add info to H5 file. Timeout waiting for file on disk." + if time.time() - start_time > 5: + raise IOError( + "Cannot add info to HDF5 file. Timeout waiting for file on disk." ) time.sleep(0.5) try: - h5fd = h5py.File(h5file, "r+") - group = h5fd.create_group("entry/source") - group.attrs["NX_class"] = np.array("NXsource", dtype="S") - group.create_dataset("name", data=np.array("PETRA III, DESY", dtype="S")) - group = h5fd.get("entry/instrument") - group.create_dataset("name", data=np.array("P11", dtype="S")) - group = h5fd.create_group("entry/instrument/attenuator") - group.attrs["NX_class"] = np.array("NXattenuator", dtype="S") - - data_set = group.create_dataset( - "thickness", dtype="f8", data=self.get_filter_thickness() - ) - data_set.attrs["units"] = np.array("m", dtype="S") - data_set = group.create_dataset( - "type", data=np.array("Aluminum", dtype="S") - ) - data_set = group.create_dataset( - "attenuator_transmission", - dtype="f8", - data=self.get_filter_transmission(), - ) - # fix rotation axis and detector orientation - data_set = h5fd.get("entry/sample/transformations/omega") - data_set.attrs["vector"] = [1.0, 0.0, 0.0] - data_set = h5fd.get("entry/instrument/detector/module/fast_pixel_direction") - data_set.attrs["vector"] = [1.0, 0.0, 0.0] - data_set = h5fd.get("entry/instrument/detector/module/slow_pixel_direction") - data_set.attrs["vector"] = [0.0, 1.0, 0.0] - # delete phi angle info to avoid confusion - nodes = [ - "entry/sample/goniometer/phi", - "entry/sample/goniometer/phi_end", - "entry/sample/goniometer/phi_range_average", - "entry/sample/goniometer/phi_range_total", - ] - for node in nodes: - if node in h5fd: - del h5fd[node] - h5fd.close() - - # except RuntimeWarning as err_msg: - # self.log.debug("Error while adding info to HDF5 file (%s)" % str(err_msg)) - # self.log.debug(traceback.format_exc()) - except Exception as err_msg: - self.log.debug("Error while adding info to HDF5 file (%s)" % str(err_msg)) - self.log.debug(traceback.format_exc()) + with h5py.File(h5file, "r+") as h5fd: + # Create or get the 'entry/source' group + source_group = self.get_or_create_group(h5fd, "entry/source") + source_group.attrs["NX_class"] = np.array("NXsource", dtype="S") + + # Create or get datasets within the 'entry/source' group + self.create_or_get_dataset( + source_group, "name", np.array("PETRA III, DESY", dtype="S") + ) + + # Create or get the 'entry/instrument' group + instrument_group = self.get_or_create_group(h5fd, "entry/instrument") + + # Create or get datasets within the 'entry/instrument' group + self.create_or_get_dataset( + instrument_group, "name", np.array("P11", dtype="S") + ) + + # Create or get the 'entry/instrument/attenuator' group + attenuator_group = self.get_or_create_group( + instrument_group, "attenuator" + ) + attenuator_group.attrs["NX_class"] = np.array("NXattenuator", dtype="S") + + # Create or get datasets within the 'entry/instrument/attenuator' group + self.create_or_get_dataset( + attenuator_group, "thickness", self.get_filter_thickness() + ) + self.create_or_get_dataset( + attenuator_group, "type", np.array("Aluminum", dtype="S") + ) + self.create_or_get_dataset( + attenuator_group, + "attenuator_transmission", + self.get_filter_transmission(), + ) + + # Set attributes for certain nodes + h5fd["entry/sample/transformations/omega"].attrs["vector"] = [ + 1.0, + 0.0, + 0.0, + ] + h5fd["entry/instrument/detector/module/fast_pixel_direction"].attrs[ + "vector" + ] = [1.0, 0.0, 0.0] + h5fd["entry/instrument/detector/module/slow_pixel_direction"].attrs[ + "vector" + ] = [0.0, 1.0, 0.0] + + # Delete unwanted nodes + unwanted_nodes = [ + "entry/sample/goniometer/phi", + "entry/sample/goniometer/phi_end", + "entry/sample/goniometer/phi_range_average", + "entry/sample/goniometer/phi_range_total", + ] + for node in unwanted_nodes: + if node in h5fd: + del h5fd[node] except Exception as err_msg: - self.log.debug("Error while adding info to HDF5 file (%s)" % str(err_msg)) + self.log.debug(f"Error while adding info to HDF5 file: {str(err_msg)}") self.log.debug(traceback.format_exc()) + def get_or_create_group(self, parent_group, group_name): + """ + Get or create a group within a parent group. + + :param parent_group: The parent group where the new group will be created. + :param group_name: The name of the group to get or create. + :return: The group object. + """ + if group_name in parent_group: + return parent_group[group_name] + else: + return parent_group.create_group(group_name) + + def create_or_get_dataset(self, group, dataset_name, dataset_data): + """ + Create or get a dataset within a group. + + :param group: The group where the dataset will be created or retrieved. + :param dataset_name: The name of the dataset. + :param dataset_data: The data to be stored in the dataset. + """ + if dataset_name in group: + dataset = group[dataset_name] + else: + dataset = group.create_dataset(dataset_name, data=dataset_data) + def get_filter_thickness(self): """ The function `get_filter_thickness` calculates the total thickness of three filters. From 31cd0b8bd6f34997d23a92f654045c9bd23d009d Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Sat, 2 Dec 2023 20:06:15 +0100 Subject: [PATCH 146/151] Changed path conversion in P11Characterisation.py --- .../DESY/P11EDNACharacterisation.py | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py b/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py index 058ddc6784..570f466673 100644 --- a/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py +++ b/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py @@ -92,21 +92,15 @@ def edna_maxwell(self, process_directory, inputxml, outputxml): + "/edna.log", ) - cmd = ( - "/asap3/petra3/gpfs/common/p11/processing/edna_sbatch.sh " - + "{inxml:s} {outxml:s} {processpath:s}" - ).format( - inxml=inputxml.replace("/gpfs", "/beamline/p11"), - outxml=outputxml.replace("/gpfs", "/beamline/p11"), - processpath=process_directory.replace("/gpfs", "/beamline/p11") + "/edna", - ) - - self.mkdir_with_mode(process_directory + "/edna", mode=0o777) - + # Check path conversion inxml = inputxml.replace("/gpfs", "/beamline/p11") - outxml = outputxml.replace("/gpfs", "/beamline/p11") - processpath = process_directory.replace("/gpfs", "/beamline/p11") + "/edna" + outxml = outputxml.replace("/gpfs/current/raw", "/beamline/p11/current/processed") + processpath = process_directory.replace("/gpfs/current/raw", "/beamline/p11/current/processed") + "/edna" + self.mkdir_with_mode(process_directory.replace("/gpfs/current/raw","/gpfs/current/processed/") + "/edna", mode=0o777) + + + self.log.debug( '=======EDNA========== CLUSTER PROCESS DIRECTORY="%s"' % processpath ) @@ -115,6 +109,16 @@ def edna_maxwell(self, process_directory, inputxml, outputxml): self.log.debug('=======EDNA========== ssh="%s"' % ssh) self.log.debug('=======EDNA========== sbatch="%s"' % sbatch) + + cmd = ( + "/asap3/petra3/gpfs/common/p11/processing/edna_sbatch.sh " + + "{inxml:s} {outxml:s} {processpath:s}" + ).format( + inxml=inxml, + outxml=outxml, + processpath=processpath + ) + self.log.debug('=======EDNA========== executing process cmd="%s"' % cmd) self.log.debug( '=======EDNA========== {ssh:s} "{sbatch:s} --wrap \\"{cmd:s}\\""'.format( From 1bba3eda4f9c33601cd2c87c130c77f676f3b84a Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Sat, 2 Dec 2023 20:26:22 +0100 Subject: [PATCH 147/151] Modified the way additional shutter values are handeled (PR800) --- .../HardwareObjects/DESY/P11DetectorCover.py | 22 +++++++++---------- .../HardwareObjects/DESY/P11FastShutter.py | 18 ++++++++++----- mxcubecore/HardwareObjects/DESY/P11Shutter.py | 11 ++++++++++ 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py index ec9c9e480e..cdc65ede3e 100644 --- a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py +++ b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py @@ -42,17 +42,6 @@ class P11DetectorCover(AbstractShutter): default_timeout = 4 move_time_min = 1 - @unique - class BaseValueEnum(Enum): - """Defines only the compulsory values.""" - - OPEN = "OPEN" - CLOSED = "CLOSED" - MOVING = "MOVING" - UNKNOWN = "UNKNOWN" - - VALUES = BaseValueEnum - def __init__(self, name): super(AbstractShutter, self).__init__(name) @@ -74,6 +63,7 @@ def __init__(self, name): def init(self): """Initilise the predefined values""" + self._initialise_values() self.simulation = self.get_property("simulation") self.cmd_timeout = self.get_property("command_timeout", self.default_timeout) @@ -101,6 +91,16 @@ def init(self): self.simulated_update() super(AbstractShutter, self).init() + + def _initialise_values(self): + """Add additional, known in advance states to VALUES""" + values_dict = {item.name: item.value for item in self.VALUES} + values_dict.update( + { + "MOVING": "MOVING", + } + ) + self.VALUES = Enum("ValueEnum", values_dict) def get_value(self): if self.simulation: diff --git a/mxcubecore/HardwareObjects/DESY/P11FastShutter.py b/mxcubecore/HardwareObjects/DESY/P11FastShutter.py index ebe924a395..7a052f8a18 100644 --- a/mxcubecore/HardwareObjects/DESY/P11FastShutter.py +++ b/mxcubecore/HardwareObjects/DESY/P11FastShutter.py @@ -32,10 +32,6 @@ from mxcubecore.HardwareObjects.abstract.AbstractShutter import AbstractShutter -@unique -class FastShutterValues(Enum): - OPEN = "Open" - CLOSED = "Closed" class P11FastShutter(AbstractNState): @@ -43,8 +39,6 @@ class P11FastShutter(AbstractNState): P11 BakcLight define interface to Tango backlight at DESY P11 """ - VALUES = FastShutterValues - default_open_time = 8 default_close_time = 3 @@ -56,6 +50,7 @@ def __init__(self, name): def init(self): """Initilise the predefined values""" + self._initialise_values() self.chan_value = self.get_channel_object("value") if self.chan_value is not None: @@ -63,6 +58,17 @@ def init(self): self.update_fast_shutter(self.chan_value.get_value()) super(AbstractNState, self).init() + + def _initialise_values(self): + """Add additional, known in advance states to VALUES""" + values_dict = {item.name: item.value for item in self.VALUES} + values_dict.update( + { + "OPEN": "Open", + "CLOSED": "Closed", + } + ) + self.VALUES = Enum("ValueEnum", values_dict) def get_value(self): return self.update_fast_shutter() diff --git a/mxcubecore/HardwareObjects/DESY/P11Shutter.py b/mxcubecore/HardwareObjects/DESY/P11Shutter.py index 90e81aec28..83de6e6d3f 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Shutter.py +++ b/mxcubecore/HardwareObjects/DESY/P11Shutter.py @@ -70,6 +70,7 @@ def init(self): # if simulation is set - open and close will be mere software flags self.simulation = self.get_property("simulation") + self._initialise_values() if not self.simulation: url_base = self.get_property("base_url") @@ -90,6 +91,16 @@ def init(self): self.update_state(self.STATES.READY) super(AbstractShutter, self).init() + + def _initialise_values(self): + """Add additional, known in advance states to VALUES""" + values_dict = {item.name: item.value for item in self.VALUES} + values_dict.update( + { + "MOVING": "MOVING", + } + ) + self.VALUES = Enum("ValueEnum", values_dict) def get_value(self): if self.simulation: From 8686c657df9996f29064a8eb0585dab34b1b993f Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Sat, 2 Dec 2023 20:34:26 +0100 Subject: [PATCH 148/151] Run black --- .../HardwareObjects/DESY/P11DetectorCover.py | 8 ++---- .../DESY/P11EDNACharacterisation.py | 26 +++++++++++-------- .../HardwareObjects/DESY/P11FastShutter.py | 11 ++------ mxcubecore/HardwareObjects/DESY/P11Shutter.py | 8 ++---- 4 files changed, 21 insertions(+), 32 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py index cdc65ede3e..5b9ceaf853 100644 --- a/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py +++ b/mxcubecore/HardwareObjects/DESY/P11DetectorCover.py @@ -91,15 +91,11 @@ def init(self): self.simulated_update() super(AbstractShutter, self).init() - + def _initialise_values(self): """Add additional, known in advance states to VALUES""" values_dict = {item.name: item.value for item in self.VALUES} - values_dict.update( - { - "MOVING": "MOVING", - } - ) + values_dict.update({"MOVING": "MOVING"}) self.VALUES = Enum("ValueEnum", values_dict) def get_value(self): diff --git a/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py b/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py index 570f466673..d41e2cf1e2 100644 --- a/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py +++ b/mxcubecore/HardwareObjects/DESY/P11EDNACharacterisation.py @@ -92,14 +92,22 @@ def edna_maxwell(self, process_directory, inputxml, outputxml): + "/edna.log", ) - # Check path conversion inxml = inputxml.replace("/gpfs", "/beamline/p11") - outxml = outputxml.replace("/gpfs/current/raw", "/beamline/p11/current/processed") - processpath = process_directory.replace("/gpfs/current/raw", "/beamline/p11/current/processed") + "/edna" - self.mkdir_with_mode(process_directory.replace("/gpfs/current/raw","/gpfs/current/processed/") + "/edna", mode=0o777) - - + outxml = outputxml.replace( + "/gpfs/current/raw", "/beamline/p11/current/processed" + ) + processpath = ( + process_directory.replace( + "/gpfs/current/raw", "/beamline/p11/current/processed" + ) + + "/edna" + ) + self.mkdir_with_mode( + process_directory.replace("/gpfs/current/raw", "/gpfs/current/processed/") + + "/edna", + mode=0o777, + ) self.log.debug( '=======EDNA========== CLUSTER PROCESS DIRECTORY="%s"' % processpath @@ -113,11 +121,7 @@ def edna_maxwell(self, process_directory, inputxml, outputxml): cmd = ( "/asap3/petra3/gpfs/common/p11/processing/edna_sbatch.sh " + "{inxml:s} {outxml:s} {processpath:s}" - ).format( - inxml=inxml, - outxml=outxml, - processpath=processpath - ) + ).format(inxml=inxml, outxml=outxml, processpath=processpath) self.log.debug('=======EDNA========== executing process cmd="%s"' % cmd) self.log.debug( diff --git a/mxcubecore/HardwareObjects/DESY/P11FastShutter.py b/mxcubecore/HardwareObjects/DESY/P11FastShutter.py index 7a052f8a18..1847f3558f 100644 --- a/mxcubecore/HardwareObjects/DESY/P11FastShutter.py +++ b/mxcubecore/HardwareObjects/DESY/P11FastShutter.py @@ -32,8 +32,6 @@ from mxcubecore.HardwareObjects.abstract.AbstractShutter import AbstractShutter - - class P11FastShutter(AbstractNState): """ P11 BakcLight define interface to Tango backlight at DESY P11 @@ -58,16 +56,11 @@ def init(self): self.update_fast_shutter(self.chan_value.get_value()) super(AbstractNState, self).init() - + def _initialise_values(self): """Add additional, known in advance states to VALUES""" values_dict = {item.name: item.value for item in self.VALUES} - values_dict.update( - { - "OPEN": "Open", - "CLOSED": "Closed", - } - ) + values_dict.update({"OPEN": "Open", "CLOSED": "Closed"}) self.VALUES = Enum("ValueEnum", values_dict) def get_value(self): diff --git a/mxcubecore/HardwareObjects/DESY/P11Shutter.py b/mxcubecore/HardwareObjects/DESY/P11Shutter.py index 83de6e6d3f..72dd2eb6e4 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Shutter.py +++ b/mxcubecore/HardwareObjects/DESY/P11Shutter.py @@ -91,15 +91,11 @@ def init(self): self.update_state(self.STATES.READY) super(AbstractShutter, self).init() - + def _initialise_values(self): """Add additional, known in advance states to VALUES""" values_dict = {item.name: item.value for item in self.VALUES} - values_dict.update( - { - "MOVING": "MOVING", - } - ) + values_dict.update({"MOVING": "MOVING"}) self.VALUES = Enum("ValueEnum", values_dict) def get_value(self): From c3a2a0365b22c0ca4e30608dbf2958d6f4afe63b Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Sat, 2 Dec 2023 21:57:28 +0100 Subject: [PATCH 149/151] Disabled additional logging --- mxcubecore/HardwareObjects/DESY/P11SampleChanger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11SampleChanger.py b/mxcubecore/HardwareObjects/DESY/P11SampleChanger.py index 537359f4c3..4925f42c69 100644 --- a/mxcubecore/HardwareObjects/DESY/P11SampleChanger.py +++ b/mxcubecore/HardwareObjects/DESY/P11SampleChanger.py @@ -477,7 +477,7 @@ def _update_selection(self): # find sample for s in self.get_sample_list(): - print(f"Sample coords = {s.get_coords()}") + #print(f"Sample coords = {s.get_coords()}") if s.get_coords() == (basket, sample): self.log.debug(" - sample found") self._set_loaded_sample(s) From 3f6338124fdeceb90d4d572df3781d72e825137c Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Tue, 12 Dec 2023 15:38:40 +0100 Subject: [PATCH 150/151] Remove unnessesary triggerring of autoprocessing. It is triggered automatically after data collection. --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 99 +------------------ 1 file changed, 1 insertion(+), 98 deletions(-) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index 79fdec4704..f8a621028b 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -298,7 +298,6 @@ def data_collection_hook(self): self.acquisition_cleanup() # self.add_h5_info(self.latest_h5_filename) - self.trigger_auto_processing() def collect_std_collection(self, start_angle, stop_angle): """ @@ -855,103 +854,7 @@ def trigger_auto_processing(self, process_event=None, frame_number=None): ) ) - # imagepath = self.path.get_path( - # "/central/beamtime/raw/user/sample/rotational_number/" + - # "sample_rotational_number_master.h5") - # processpath = "/beamline/p11/current" + self.path.get_path( - # "/processed/user/sample/rotational_number/xdsapp") - # - # - # - # - # #create processing folder with 0o777 - # self.path.get_path("/beamline/beamtime/processed/user/sample/" + - # "rotational_number/xdsapp", force=True) - # #add to datasets.txt for presenterd - # try: - # f = open(self.path.get_path( - # "/beamline/beamtime/processed/datasets.txt"), "a") - # f.write(self.path.get_path( - # "user/sample/rotational_number/xdsapp\n").lstrip("/")) - # f.close() - # except: - # print(sys.exc_info()) - # - # #create call - # ssh = btHelper.get_ssh_command() - # sbatch = btHelper.get_sbatch_command( - # jobname_prefix = "xdsapp", - # job_dependency = "", - # logfile_path = processpath + "/xdsapp.log" - # ) - # cmd = ("/asap3/petra3/gpfs/common/p11/processing/xdsapp_sbatch.sh " + \ - # "{imagepath:s} {processpath:s} {res:f}").format( - # imagepath = imagepath, - # processpath = processpath, - # res = res - # ) - # print(cmd) - # os.system("{ssh:s} \"{sbatch:s} --wrap \\\"{cmd:s}\\\"\"".format( - # ssh = ssh, - # sbatch = sbatch, - # cmd = cmd - # )) - - # Test of the autoprocessing as in CC (AG) - # def trigger_auto_processing(self, process_event=None, frame_number=None): - # self.log.debug("Triggering auto processing. NOT IMPLEMENTED YET. Direct test from CC.") - # - # #creation will fail if beamtime folder, slurm reservation or - # #bl-fs mount on the compute nodes can not be found - # try: - # btHelper = triggerUtils.Trigger() - # except: - # print(sys.exc_info()) - # return - # - # energy = self.petraThread.currentMonoEnergy / 1000. - # wavelength = 12.3984 / energy #in Angstrom - # res = wavelength / (2. * math.sin(0.5 * math.atan( - # (311. / 2.) / self.parameters["detectordistance"]))) - # frames = self.parameters["frames"] - # imagepath = self.path.get_path( - # "/central/beamtime/raw/user/sample/rotational_number/" + - # "sample_rotational_number_master.h5") - # processpath = "/beamline/p11/current" + self.path.get_path( - # "/processed/user/sample/rotational_number/xdsapp") - # - # #create processing folder with 0o777 - # self.path.get_path("/beamline/beamtime/processed/user/sample/" + - # "rotational_number/xdsapp", force=True) - # #add to datasets.txt for presenterd - # try: - # f = open(self.path.get_path( - # "/beamline/beamtime/processed/datasets.txt"), "a") - # f.write(self.path.get_path( - # "user/sample/rotational_number/xdsapp\n").lstrip("/")) - # f.close() - # except: - # print(sys.exc_info()) - # - # #create call - # ssh = btHelper.get_ssh_command() - # sbatch = btHelper.get_sbatch_command( - # jobname_prefix = "xdsapp", - # job_dependency = "", - # logfile_path = processpath + "/xdsapp.log" - # ) - # cmd = ("/asap3/petra3/gpfs/common/p11/processing/xdsapp_sbatch.sh " + \ - # "{imagepath:s} {processpath:s} {res:f}").format( - # imagepath = imagepath, - # processpath = processpath, - # res = res - # ) - # print(cmd) - # os.system("{ssh:s} \"{sbatch:s} --wrap \\\"{cmd:s}\\\"\"".format( - # ssh = ssh, - # sbatch = sbatch, - # cmd = cmd - # )) + def diffractometer_prepare_collection(self): diffr = HWR.beamline.diffractometer From 1a0b15e10a68759e90291f2c439e356501efd179 Mon Sep 17 00:00:00 2001 From: Andrey Gruzinov Date: Tue, 12 Dec 2023 15:51:26 +0100 Subject: [PATCH 151/151] Set omega to 0 at the end explicitly --- mxcubecore/HardwareObjects/DESY/P11Collect.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mxcubecore/HardwareObjects/DESY/P11Collect.py b/mxcubecore/HardwareObjects/DESY/P11Collect.py index f8a621028b..a0816eab32 100644 --- a/mxcubecore/HardwareObjects/DESY/P11Collect.py +++ b/mxcubecore/HardwareObjects/DESY/P11Collect.py @@ -448,6 +448,10 @@ def acquisition_cleanup(self): self.log.debug("#COLLECT# Closing detector cover") diffr.detector_cover_close(wait=True) + # Move omega to 0 at the end + self.omega_mv(0, self.default_speed) + self.wait_omega() + except RuntimeError: self.log.error(traceback.format_exc())