Skip to content

Commit

Permalink
Flake/ Black reformatted
Browse files Browse the repository at this point in the history
Add default timeout 0
  • Loading branch information
FLorial Jean Baptiste committed Jan 4, 2024
1 parent 5a24596 commit 47edb43
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 61 deletions.
6 changes: 3 additions & 3 deletions mxcubecore/HardwareObjects/Beamline.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,9 @@ def harvester_maintenance(self):
def plate_manipulator(self):
"""**DEPRECATED**
Plate Manuipulator Hardware object
NBNB TODO REMOVE THIS From qt version usage and
and call HWR.beamline.sample_changer instead as plate_manipulator being
treated as an alternative sample changer .
NBNB TODO REMOVE THIS From qt version usage and
and call HWR.beamline.sample_changer instead as plate_manipulator being
treated as an alternative sample changer.
Returns:
Optional[AbstractSampleChanger]:
Expand Down
4 changes: 2 additions & 2 deletions mxcubecore/HardwareObjects/Harvester.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def _execute_cmd_exporter(self, cmd, *args, **kwargs):
return : respond
"""
ret = None
timeout = kwargs.pop("timeout", 900)
timeout = kwargs.pop("timeout", 0)
if args:
args_str = "%s" % "\t".join(map(str, args))
if kwargs.pop("command", None):
Expand Down Expand Up @@ -164,7 +164,7 @@ def _execute_cmd_exporter(self, cmd, *args, **kwargs):
if cmd.startswith("set"):
ret = exp_attr.set_value(args_str)

# self._wait_ready(timeout=timeout)
self._wait_ready(timeout=timeout)
return ret

# ---------------------- State --------------------------------
Expand Down
104 changes: 48 additions & 56 deletions mxcubecore/HardwareObjects/mockup/HarvesterMockup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@
- getSampleList : Get list of available sample from Harvester
- Harvest : load sample from Harvester
-----------------------------------------------------------------------
"""
import gevent
import logging

from mxcubecore.BaseHardwareObjects import HardwareObject


class HarvesterMockup(HardwareObject):
"""Harvester functionality
The Harvester Class consists of methods executing exporter commands
to communicate with the Crystal Direct Harvester Machine
The Harvester Class consists of methods executing exporter commands
to communicate with the Crystal Direct Harvester Machine
"""

Expand All @@ -38,10 +39,9 @@ def __init__(self, name):
self.room_temperature_mode = False

def init(self):
""" Init """
"""Init"""
self.exporter_addr = self.get_property("exporter_address")


def set_calibrate_state(self, state):
"""Set Calibration state
Expand All @@ -65,9 +65,11 @@ def _wait_ready(self, timeout=None):

with gevent.Timeout(timeout, RuntimeError(err_msg)):
while not self._ready():
logging.getLogger("user_level_log").info("Waiting Harvester to be Ready")
logging.getLogger("user_level_log").info(
"Waiting Harvester to be Ready"
)
gevent.sleep(3)

def _wait_sample_transfer_ready(self, timeout=None):
"""Wait Harvester to be ready to transfer a sample
Expand All @@ -82,7 +84,9 @@ def _wait_sample_transfer_ready(self, timeout=None):

with gevent.Timeout(timeout, RuntimeError(err_msg)):
while not self._ready_to_transfer():
logging.getLogger("user_level_log").info("Waiting Harvester to be ready to transfer")
logging.getLogger("user_level_log").info(
"Waiting Harvester to be ready to transfer"
)
gevent.sleep(3)

def _execute_cmd_exporter(self, cmd, *args, **kwargs):
Expand All @@ -91,11 +95,10 @@ def _execute_cmd_exporter(self, cmd, *args, **kwargs):
Args:
cmd (string) : command type
args, kwargs (string): commands arguments, and command or attribute
return : respond
"""
ret = None
timeout = kwargs.pop("timeout", 900)
if args:
args_str = "%s" % "\t".join(map(str, args))
if kwargs.pop("command", None):
Expand Down Expand Up @@ -126,16 +129,16 @@ def _execute_cmd_exporter(self, cmd, *args, **kwargs):
ret = exp_attr.set_value(args_str)

return ret

# ---------------------- State --------------------------------

def get_state(self):
"""Get the Harvester State
Return (str): state "Ready, Running etc.."
"""
"""
return "Ready"

def get_status(self):
"""Get the Harvester Status
Expand All @@ -157,7 +160,7 @@ def _busy(self):
Return (bool): True if Harvester is not Ready otherwise False
"""
return not self._ready()

def _ready_to_transfer(self):
"""Same as Get Harvester Status
Expand All @@ -166,24 +169,22 @@ def _ready_to_transfer(self):
# return self._execute_cmd_exporter("getStatus", attribute=True) == "Waiting Sample Transfer"
return "Waiting Sample Transfer"


def get_samples_state(self):
"""Get the Harvester Sample State
Return (List): list of crystal state "waiting_for_transfer, Running etc.."
"""
"""
# return self._execute_cmd_exporter("getSampleStates", command=True)
return "Ready"

def get_current_crystal(self):
"""Get the Harvester current harvested crystal
Return (str): crystal uuid
"""
"""
# return self._execute_cmd_exporter("getCurrentSampleID", attribute=True)
return None



def is_crystal_harvested(self, crystal_uuid):
"""Same as Get Harvester Status
Expand All @@ -198,7 +199,7 @@ def is_crystal_harvested(self, crystal_uuid):
if crystal_uuid == Current_SampleID:
res = True
return res

def current_crystal_state(self, crystal_uuid):
"""Wait Harvester to be ready to transfer a sample
Expand All @@ -214,9 +215,8 @@ def current_crystal_state(self, crystal_uuid):
if crystal_uuid == x_tal:
return sample_states[index]


return None

def check_crystal_state(self, crystal_uuid):
"""Check wether if a Crystal is in pending_and_current or not
Expand All @@ -228,19 +228,20 @@ def check_crystal_state(self, crystal_uuid):
crystal_uuids = self.get_crystal_uuids()

for index, x_tal in enumerate(crystal_uuids):
if crystal_uuid == x_tal and sample_states[index] == 'waiting_for_transfer':
return 'pending_and_current'
elif crystal_uuid != x_tal and sample_states[index] == 'waiting_for_transfer':
return 'pending_not_current'
if crystal_uuid == x_tal and sample_states[index] == "waiting_for_transfer":
return "pending_and_current"
elif (
crystal_uuid != x_tal and sample_states[index] == "waiting_for_transfer"
):
return "pending_not_current"
else:
return None


def get_crystal_uuids(self):
"""Get the Harvester Sample List uuid
Return (List): list of crystal by uuid from the current processing plan"
"""
"""
# harvester_crystal_list = self._execute_cmd_exporter("getSampleList", attribute=True)
return []

Expand All @@ -251,7 +252,7 @@ def get_sample_names(self):
"""
# harvester_sample_names = self._execute_cmd_exporter("getSampleNames", attribute=True)
return []

def get_crystal_images_urls(self, crystal_uuid):
"""Get the Harvester Sample List Images
Expand All @@ -262,15 +263,14 @@ def get_crystal_images_urls(self, crystal_uuid):
# crystal_images_url = self._execute_cmd_exporter("getImageURL", crystal_uuid, command=True)
return []


def get_sample_acronyms(self):
"""Get the Harvester Sample List by Acronyms
Return (List): list of crystal by Acronyms from the current processing plan"
"""
# harvester_sample_acronyms = self._execute_cmd_exporter("getSampleAcronyms", attribute=True)
return []

# ------------------------------------------------------------------------------------

def abort(self):
Expand All @@ -279,7 +279,7 @@ def abort(self):
"""
# return self._execute_cmd_exporter("abort", command=True)
return None

def harvest_crystal(self, crystal_uuid):
"""Harvester crystal
Expand All @@ -288,20 +288,16 @@ def harvest_crystal(self, crystal_uuid):
# return self._execute_cmd_exporter("harvestCrystal", crystal_uuid, command=True)
return False


def transfer_sample(self):
"""Transfer the current Harvested Crystal
"""
"""Transfer the current Harvested Crystal"""
# return self._execute_cmd_exporter("startTransfer", command=True)
return False

def trash_sample(self):
""" Trash the current Harvested Crystal
"""
"""Trash the current Harvested Crystal"""
# return self._execute_cmd_exporter("trashSample", command=True)
return False


# -----------------------------------------------------------------------------

def load_plate(self, plate_id):
Expand Down Expand Up @@ -330,8 +326,7 @@ def get_image_target_x(self, crystal_uuid):
"""
# return self._execute_cmd_exporter("getImageTargetX", crystal_uuid, command=True)
return ""



def get_image_target_y(self, crystal_uuid):
"""Wait Harvester to be ready to transfer a sample
Expand All @@ -341,7 +336,7 @@ def get_image_target_y(self, crystal_uuid):
"""
# return self._execute_cmd_exporter("getImageTargetY", crystal_uuid, command=True)
return ""

def get_room_temperature_mode(self):
# return self._execute_cmd_exporter("getRoomTemperatureMode", attribute=True)
return True
Expand All @@ -352,7 +347,7 @@ def set_room_temperature_mode(self, value):
Args: (bool) set room temperature when true
"""
# self._execute_cmd_exporter("setRoomTemperatureMode", value, command=True)
print("setting HA Room temperature to: %s" %value)
print("setting HA Room temperature to: %s" % value)
return self.get_room_temperature_mode()

# -------------------- Calibrate Drift Shape offset ----------------------------
Expand Down Expand Up @@ -386,24 +381,23 @@ def get_last_pin_cut_shape_offset_x(self):
"""
# pin_last_cut_shape_offset_x = self._execute_cmd_exporter("getLastSampleCutShapeOffsetX", attribute=True)
pass

def get_last_pin_cut_shape_offset_y(self):
"""Pin shape Offset Y position when
Return (float): last pin cut shape offset y
Return (float): last pin cut shape offset y
"""
# pin_last_cut_shape_offset_y = self._execute_cmd_exporter("getLastSampleCutShapeOffsetY", attribute=True)
pass

# =============== Pin / Calibration -----------------------------

def load_calibrated_pin(self):
"""Start Pin Calibration Procedure
"""
"""Start Pin Calibration Procedure"""
# return self._execute_cmd_exporter("loadCalibratedPin", command=True)
pass

def store_calibrated_pin(self, x, y, z):
""" Store x , y , z offsets position after calibration procedure
"""Store x , y , z offsets position after calibration procedure
Args: (float) x, y, z offsets
"""
Expand All @@ -425,10 +419,8 @@ def get_number_of_available_pin(self):
"""
# return self._execute_cmd_exporter("getNbRemainingPins", command=True)
return 1


def get_offsets_for_sample_centering(self):

def get_offsets_for_sample_centering(self):
pin_to_beam = tuple(self.get_calibrated_pin_offset())

sample_drift_x = float(self.get_last_sample_drift_offset_x())
Expand All @@ -438,10 +430,10 @@ def get_offsets_for_sample_centering(self):
pin_cut_shape_x = float(self.get_last_pin_cut_shape_offset_x())
pin_cut_shape_y = float(self.get_last_pin_cut_shape_offset_y())

phiy_offset = sample_drift_x - pin_cut_shape_x + float(pin_to_beam[1])
phiy_offset = sample_drift_x - pin_cut_shape_x + float(pin_to_beam[1])

centringFocus = sample_drift_z + float(pin_to_beam[0])
centringFocus = sample_drift_z + float(pin_to_beam[0])

centringTableVertical = sample_drift_y - pin_cut_shape_y + float(pin_to_beam[2])
centringTableVertical = sample_drift_y - pin_cut_shape_y + float(pin_to_beam[2])

return (phiy_offset, centringFocus, centringTableVertical)
return (phiy_offset, centringFocus, centringTableVertical)

0 comments on commit 47edb43

Please sign in to comment.