diff --git a/src/mx_bluesky/I24/serial/dcid.py b/src/mx_bluesky/I24/serial/dcid.py index f3c0e5961..9fa36d445 100644 --- a/src/mx_bluesky/I24/serial/dcid.py +++ b/src/mx_bluesky/I24/serial/dcid.py @@ -8,11 +8,11 @@ import re import subprocess import warnings -from enum import Enum from functools import lru_cache import requests +from mx_bluesky.I24.serial.parameters import SSXType from mx_bluesky.I24.serial.setup_beamline import ( Detector, Eiger, @@ -53,11 +53,6 @@ def get_auth_header() -> dict: return {"Authorization": "Bearer " + token} -class SSXType(Enum): - FIXED = "Serial Fixed" - EXTRUDER = "Serial Jet" - - class DCID: """ Interfaces with ISPyB to allow ssx DCID/synchweb interaction. diff --git a/src/mx_bluesky/I24/serial/extruder/EX-gui-edm/DetStage.edl b/src/mx_bluesky/I24/serial/extruder/EX-gui-edm/DetStage.edl new file mode 100644 index 000000000..e066864ff --- /dev/null +++ b/src/mx_bluesky/I24/serial/extruder/EX-gui-edm/DetStage.edl @@ -0,0 +1,139 @@ +4 0 1 +beginScreenProperties +major 4 +minor 0 +release 1 +x 3338 +y 572 +w 450 +h 180 +font "arial-medium-r-18.0" +ctlFont "arial-medium-r-18.0" +btnFont "arial-medium-r-18.0" +fgColor index 14 +bgColor index 3 +textColor index 14 +ctlFgColor1 index 14 +ctlFgColor2 index 0 +ctlBgColor1 index 0 +ctlBgColor2 index 14 +topShadowColor index 0 +botShadowColor index 14 +title "Detector stage " +endScreenProperties + +# (Text Monitor) +object activeXTextDspClass:noedit +beginObjectProperties +major 4 +minor 6 +release 0 +x 251 +y 139 +w 160 +h 21 +controlPv "BL24I-EA-DET-01:Y" +font "arial-medium-r-18.0" +fgColor index 16 +bgColor index 10 +autoHeight +limitsFromDb +nullColor index 0 +useHexPrefix +newPos +objType "monitors" +endObjectProperties + +# (Static Text) +object activeXTextClass +beginObjectProperties +major 4 +minor 1 +release 1 +x 28 +y 139 +w 193 +h 21 +font "arial-medium-r-18.0" +fgColor index 14 +bgColor index 0 +useDisplayBg +value { + "Detector stage position" +} +autoSize +endObjectProperties + +# (Menu Mux PV) +object menuMuxPVClass +beginObjectProperties +major 4 +minor 0 +release 0 +x 35 +y 59 +w 160 +h 42 +fgColour index 14 +bgColour index 4 +topShadowColour index 1 +botShadowColour index 8 +controlPv "BL24I-EA-IOC-12:GP15" +font "arial-medium-r-18.0" +numItems 2 +symbolTag { + 0 "Eiger" + 1 "Pilatus" +} +symbol0 { + 0 "E9M" + 1 "P6M" +} +PV0 { + 0 "eiger" + 1 "pilatus" +} +endObjectProperties + +# (Shell Command) +object shellCmdClass +beginObjectProperties +major 4 +minor 3 +release 0 +x 251 +y 59 +w 160 +h 42 +fgColor index 14 +bgColor index 49 +topShadowColor index 1 +botShadowColor index 11 +font "arial-medium-r-18.0" +buttonLabel "Move Stage" +numCmds 1 +command { + 0 "python SCRIPTS_LOCATION/setup_beamline/setup_detector.py \"Serial Jet\"" +} +endObjectProperties + +# (Static Text) +object activeXTextClass +beginObjectProperties +major 4 +minor 1 +release 1 +x 150 +y 10 +w 135 +h 21 +font "arial-bold-r-18.0" +fgColor index 14 +bgColor index 0 +useDisplayBg +value { + "Detector Stage" +} +autoSize +endObjectProperties + diff --git a/src/mx_bluesky/I24/serial/extruder/EX-gui-edm/DiamondExtruder-I24-py3v1.edl b/src/mx_bluesky/I24/serial/extruder/EX-gui-edm/DiamondExtruder-I24-py3v1.edl index 78dfae6e2..90e4347d8 100644 --- a/src/mx_bluesky/I24/serial/extruder/EX-gui-edm/DiamondExtruder-I24-py3v1.edl +++ b/src/mx_bluesky/I24/serial/extruder/EX-gui-edm/DiamondExtruder-I24-py3v1.edl @@ -3,8 +3,8 @@ beginScreenProperties major 4 minor 0 release 1 -x 4241 -y 52 +x 3046 +y 314 w 700 h 900 font "arial-medium-r-18.0" @@ -1014,8 +1014,8 @@ beginObjectProperties major 4 minor 0 release 0 -x 11 -y 610 +x 10 +y 611 w 680 h 252 lineColor index 9 @@ -1355,7 +1355,7 @@ beginObjectProperties major 4 minor 1 release 1 -x 307 +x 304 y 689 w 35 h 18 @@ -1679,8 +1679,8 @@ beginObjectProperties major 4 minor 1 release 0 -x 499 -y 818 +x 466 +y 819 w 43 h 25 fgColor index 25 @@ -1704,8 +1704,8 @@ beginObjectProperties major 10 minor 0 release 0 -x 405 -y 784 +x 375 +y 785 w 83 h 30 controlPv "BL24I-EA-DET-01:Z.VAL" @@ -1724,8 +1724,8 @@ beginObjectProperties major 4 minor 1 release 0 -x 547 -y 818 +x 513 +y 819 w 43 h 25 fgColor index 25 @@ -1749,8 +1749,8 @@ beginObjectProperties major 4 minor 1 release 1 -x 340 -y 763 +x 304 +y 758 w 149 h 18 font "arial-medium-r-16.0" @@ -1769,8 +1769,8 @@ beginObjectProperties major 4 minor 1 release 1 -x 338 -y 795 +x 304 +y 792 w 53 h 16 font "arial-medium-r-14.0" @@ -1789,8 +1789,8 @@ beginObjectProperties major 4 minor 1 release 1 -x 348 -y 822 +x 304 +y 823 w 42 h 16 font "arial-medium-r-14.0" @@ -1809,7 +1809,7 @@ beginObjectProperties major 4 minor 6 release 0 -x 501 +x 466 y 791 w 86 h 18 @@ -1832,7 +1832,7 @@ beginObjectProperties major 10 minor 0 release 0 -x 405 +x 375 y 816 w 83 h 30 @@ -1852,7 +1852,7 @@ beginObjectProperties major 4 minor 1 release 1 -x 307 +x 304 y 716 w 35 h 18 @@ -2252,3 +2252,26 @@ command { } endObjectProperties +# (Related Display) +object relatedDisplayClass +beginObjectProperties +major 4 +minor 4 +release 0 +x 571 +y 800 +w 96 +h 31 +fgColor index 14 +bgColor index 49 +topShadowColor index 1 +botShadowColor index 11 +font "arial-medium-r-18.0" +buttonLabel "Detector" +numPvs 4 +numDsps 1 +displayFileName { + 0 "EDM_LOCATION/DetStage.edl" +} +endObjectProperties + diff --git a/src/mx_bluesky/I24/serial/extruder/i24ssx_Extruder_Collect_py3v2.py b/src/mx_bluesky/I24/serial/extruder/i24ssx_Extruder_Collect_py3v2.py index db7a8e90b..eca37cba5 100755 --- a/src/mx_bluesky/I24/serial/extruder/i24ssx_Extruder_Collect_py3v2.py +++ b/src/mx_bluesky/I24/serial/extruder/i24ssx_Extruder_Collect_py3v2.py @@ -15,10 +15,12 @@ from time import sleep from mx_bluesky.I24.serial import log -from mx_bluesky.I24.serial.dcid import DCID, SSXType +from mx_bluesky.I24.serial.dcid import DCID +from mx_bluesky.I24.serial.parameters import SSXType from mx_bluesky.I24.serial.parameters.constants import PARAM_FILE_PATH from mx_bluesky.I24.serial.setup_beamline import caget, caput, pv from mx_bluesky.I24.serial.setup_beamline import setup_beamline as sup +from mx_bluesky.I24.serial.setup_beamline.setup_detector import get_detector_type from mx_bluesky.I24.serial.write_nexus import call_nexgen usage = "%(prog)s command [options]" @@ -49,7 +51,7 @@ def initialise_extruderi24(args=None): logger.info("Visit defined %s" % visit) # Define detector in use - det_type = sup.get_detector_type() + det_type = get_detector_type() caput(pv.ioc12_gp2, "test") caput(pv.ioc12_gp3, "testrun") diff --git a/src/mx_bluesky/I24/serial/fixed_target/FT-gui-edm/DetStage.edl b/src/mx_bluesky/I24/serial/fixed_target/FT-gui-edm/DetStage.edl new file mode 100644 index 000000000..0f81b680a --- /dev/null +++ b/src/mx_bluesky/I24/serial/fixed_target/FT-gui-edm/DetStage.edl @@ -0,0 +1,139 @@ +4 0 1 +beginScreenProperties +major 4 +minor 0 +release 1 +x 3172 +y 731 +w 450 +h 180 +font "arial-medium-r-18.0" +ctlFont "arial-medium-r-18.0" +btnFont "arial-medium-r-18.0" +fgColor index 14 +bgColor index 3 +textColor index 14 +ctlFgColor1 index 14 +ctlFgColor2 index 0 +ctlBgColor1 index 0 +ctlBgColor2 index 14 +topShadowColor index 0 +botShadowColor index 14 +title "Detector stage " +endScreenProperties + +# (Text Monitor) +object activeXTextDspClass:noedit +beginObjectProperties +major 4 +minor 6 +release 0 +x 251 +y 139 +w 160 +h 21 +controlPv "BL24I-EA-DET-01:Y" +font "arial-medium-r-18.0" +fgColor index 16 +bgColor index 10 +autoHeight +limitsFromDb +nullColor index 0 +useHexPrefix +newPos +objType "monitors" +endObjectProperties + +# (Static Text) +object activeXTextClass +beginObjectProperties +major 4 +minor 1 +release 1 +x 28 +y 139 +w 193 +h 21 +font "arial-medium-r-18.0" +fgColor index 14 +bgColor index 0 +useDisplayBg +value { + "Detector stage position" +} +autoSize +endObjectProperties + +# (Menu Mux PV) +object menuMuxPVClass +beginObjectProperties +major 4 +minor 0 +release 0 +x 35 +y 59 +w 160 +h 42 +fgColour index 14 +bgColour index 4 +topShadowColour index 1 +botShadowColour index 8 +controlPv "ME-14E-MO-IOC-01:GP101" +font "arial-medium-r-18.0" +numItems 2 +symbolTag { + 0 "Eiger" + 1 "Pilatus" +} +symbol0 { + 0 "E9M" + 1 "P6M" +} +PV0 { + 0 "eiger" + 1 "pilatus" +} +endObjectProperties + +# (Shell Command) +object shellCmdClass +beginObjectProperties +major 4 +minor 3 +release 0 +x 251 +y 59 +w 160 +h 42 +fgColor index 14 +bgColor index 49 +topShadowColor index 1 +botShadowColor index 11 +font "arial-medium-r-18.0" +buttonLabel "Move Stage" +numCmds 1 +command { + 0 "python SCRIPTS_LOCATION/setup_beamline/setup_detector.py \"Serial Fixed\"" +} +endObjectProperties + +# (Static Text) +object activeXTextClass +beginObjectProperties +major 4 +minor 1 +release 1 +x 150 +y 10 +w 135 +h 21 +font "arial-bold-r-18.0" +fgColor index 14 +bgColor index 0 +useDisplayBg +value { + "Detector Stage" +} +autoSize +endObjectProperties + diff --git a/src/mx_bluesky/I24/serial/fixed_target/FT-gui-edm/DiamondChipI24-py3v1.edl b/src/mx_bluesky/I24/serial/fixed_target/FT-gui-edm/DiamondChipI24-py3v1.edl index d3a3473a9..a2604d133 100644 --- a/src/mx_bluesky/I24/serial/fixed_target/FT-gui-edm/DiamondChipI24-py3v1.edl +++ b/src/mx_bluesky/I24/serial/fixed_target/FT-gui-edm/DiamondChipI24-py3v1.edl @@ -4,7 +4,7 @@ major 4 minor 0 release 1 x 2685 -y 76 +y 187 w 1030 h 950 font "arial-medium-r-18.0" @@ -1699,7 +1699,7 @@ beginObjectProperties major 4 minor 1 release 1 -x 495 +x 496 y 860 w 66 h 21 @@ -3263,7 +3263,7 @@ beginObjectProperties major 4 minor 1 release 1 -x 710 +x 700 y 830 w 195 h 18 @@ -3340,7 +3340,7 @@ beginObjectProperties major 4 minor 1 release 1 -x 740 +x 762 y 860 w 133 h 18 @@ -3360,7 +3360,7 @@ beginObjectProperties major 4 minor 1 release 1 -x 785 +x 804 y 890 w 91 h 18 @@ -3993,7 +3993,7 @@ beginObjectProperties major 4 minor 1 release 1 -x 442 +x 465 y 883 w 97 h 18 @@ -4062,4 +4062,28 @@ onLabel "Reset" offLabel "Reset" 3d font "arial-medium-r-14.0" -endObjectProperties \ No newline at end of file +endObjectProperties + +# (Related Display) +object relatedDisplayClass +beginObjectProperties +major 4 +minor 4 +release 0 +x 695 +y 905 +w 105 +h 30 +fgColor index 14 +bgColor index 49 +topShadowColor index 1 +botShadowColor index 11 +font "arial-medium-r-16.0" +buttonLabel "Detector" +numPvs 4 +numDsps 1 +displayFileName { + 0 "EDM_LOCATION/DetStage.edl" +} +endObjectProperties + diff --git a/src/mx_bluesky/I24/serial/fixed_target/i24ssx_Chip_Collect_py3v1.py b/src/mx_bluesky/I24/serial/fixed_target/i24ssx_Chip_Collect_py3v1.py index 15ef63d5b..8119e9e7c 100755 --- a/src/mx_bluesky/I24/serial/fixed_target/i24ssx_Chip_Collect_py3v1.py +++ b/src/mx_bluesky/I24/serial/fixed_target/i24ssx_Chip_Collect_py3v1.py @@ -15,11 +15,12 @@ import numpy as np from mx_bluesky.I24.serial import log -from mx_bluesky.I24.serial.dcid import DCID, SSXType +from mx_bluesky.I24.serial.dcid import DCID from mx_bluesky.I24.serial.fixed_target.i24ssx_Chip_StartUp_py3v1 import ( get_format, scrape_parameter_file, ) +from mx_bluesky.I24.serial.parameters import SSXType from mx_bluesky.I24.serial.parameters.constants import LITEMAP_PATH, PARAM_FILE_PATH_FT from mx_bluesky.I24.serial.setup_beamline import caget, cagetstring, caput, pv from mx_bluesky.I24.serial.setup_beamline import setup_beamline as sup diff --git a/src/mx_bluesky/I24/serial/fixed_target/i24ssx_Chip_Manager_py3v1.py b/src/mx_bluesky/I24/serial/fixed_target/i24ssx_Chip_Manager_py3v1.py index 94fb35d4e..9fa978c85 100755 --- a/src/mx_bluesky/I24/serial/fixed_target/i24ssx_Chip_Manager_py3v1.py +++ b/src/mx_bluesky/I24/serial/fixed_target/i24ssx_Chip_Manager_py3v1.py @@ -27,7 +27,7 @@ PVAR_FILE_PATH, ) from mx_bluesky.I24.serial.setup_beamline import caget, caput, pv -from mx_bluesky.I24.serial.setup_beamline import setup_beamline as sup +from mx_bluesky.I24.serial.setup_beamline.setup_detector import get_detector_type logger = logging.getLogger("I24ssx.chip_manager") @@ -85,7 +85,7 @@ def initialise(): # Define detector in use logger.debug("Define detector in use.") - det_type = sup.get_detector_type() + det_type = get_detector_type() caput(pv.pilat_cbftemplate, 0) diff --git a/src/mx_bluesky/I24/serial/parameters/__init__.py b/src/mx_bluesky/I24/serial/parameters/__init__.py new file mode 100644 index 000000000..0a110c8bc --- /dev/null +++ b/src/mx_bluesky/I24/serial/parameters/__init__.py @@ -0,0 +1,5 @@ +from __future__ import annotations + +from mx_bluesky.I24.serial.parameters.constants import SSXType + +__all__ = ["SSXType"] diff --git a/src/mx_bluesky/I24/serial/parameters/constants.py b/src/mx_bluesky/I24/serial/parameters/constants.py index be437f5e0..49c38e286 100644 --- a/src/mx_bluesky/I24/serial/parameters/constants.py +++ b/src/mx_bluesky/I24/serial/parameters/constants.py @@ -1,5 +1,12 @@ +from enum import Enum from pathlib import Path + +class SSXType(Enum): + FIXED = "Serial Fixed" + EXTRUDER = "Serial Jet" + + OAV_CONFIG_FILES = { "zoom_params_file": "/dls_sw/i24/software/gda/config/xml/jCameraManZoomLevels.xml", "oav_config_json": "/dls_sw/i24/software/daq_configuration/json/OAVCentring.json", diff --git a/src/mx_bluesky/I24/serial/setup_beamline/pv.py b/src/mx_bluesky/I24/serial/setup_beamline/pv.py index 4eb1c113f..a40454342 100644 --- a/src/mx_bluesky/I24/serial/setup_beamline/pv.py +++ b/src/mx_bluesky/I24/serial/setup_beamline/pv.py @@ -448,7 +448,7 @@ def __which__(): me14e_gp98 = "ME14E-MO-IOC-01:GP98" me14e_gp99 = "ME14E-MO-IOC-01:GP99" me14e_gp100 = "ME14E-MO-IOC-01:GP100" -me14e_gp101 = "ME14E-MO-IOC-01:GP101" +me14e_gp101 = "ME14E-MO-IOC-01:GP101" # Detector in use me14e_gp102 = "ME14E-MO-IOC-01:GP102" me14e_gp103 = "ME14E-MO-IOC-01:GP103" me14e_gp104 = "ME14E-MO-IOC-01:GP104" diff --git a/src/mx_bluesky/I24/serial/setup_beamline/setup_beamline.py b/src/mx_bluesky/I24/serial/setup_beamline/setup_beamline.py index d306823a7..a5aa35dcd 100644 --- a/src/mx_bluesky/I24/serial/setup_beamline/setup_beamline.py +++ b/src/mx_bluesky/I24/serial/setup_beamline/setup_beamline.py @@ -3,28 +3,10 @@ from mx_bluesky.I24.serial.setup_beamline import pv from mx_bluesky.I24.serial.setup_beamline.ca import caget, caput -from mx_bluesky.I24.serial.setup_beamline.pv_abstract import Detector, Eiger, Pilatus logger = logging.getLogger("I24ssx.sup") -class UnknownDetectorType(Exception): - pass - - -def get_detector_type() -> Detector: - det_y = caget(pv.det_y) - if float(det_y) < Eiger.det_y_threshold: - logger.info("Eiger detector in use.") - return Eiger() - elif float(det_y) > Pilatus.det_y_threshold: - logger.info("Pilatus detector in use.") - return Pilatus() - else: - logger.error("Detector not found.") - raise UnknownDetectorType("Detector not found.") - - def modechange(action): """Mode Change""" # Pin Hand Mount diff --git a/src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py b/src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py new file mode 100644 index 000000000..3717fd341 --- /dev/null +++ b/src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py @@ -0,0 +1,91 @@ +""" +Utilities for defining the detector in use, and moving the stage. +""" +import argparse +import logging +import time + +import bluesky.plan_stubs as bps +from bluesky.run_engine import RunEngine +from dodal.beamlines import i24 +from dodal.devices.i24.I24_detector_motion import DetectorMotion + +from mx_bluesky.I24.serial import log +from mx_bluesky.I24.serial.parameters.constants import SSXType +from mx_bluesky.I24.serial.setup_beamline import pv +from mx_bluesky.I24.serial.setup_beamline.ca import caget +from mx_bluesky.I24.serial.setup_beamline.pv_abstract import ( + Detector, + Eiger, + Pilatus, +) + +logger = logging.getLogger("I24ssx.sup_det") + +EXPT_TYPE_DETECTOR_PVS = { + SSXType.FIXED: pv.me14e_gp101, + SSXType.EXTRUDER: pv.ioc12_gp15, +} + + +def setup_logging(): + logfile = time.strftime("SSXdetectorOps_%d%B%y.log").lower() + log.config(logfile) + + +class UnknownDetectorType(Exception): + pass + + +def get_detector_type() -> Detector: + det_y = caget(pv.det_y) + # DetectorMotion should also be used for this. + # This should be part of https://github.com/DiamondLightSource/mx_bluesky/issues/51 + if float(det_y) < Eiger.det_y_threshold: + logger.info("Eiger detector in use.") + return Eiger() + elif float(det_y) > Pilatus.det_y_threshold: + logger.info("Pilatus detector in use.") + return Pilatus() + else: + logger.error("Detector not found.") + raise UnknownDetectorType("Detector not found.") + + +def _move_detector_stage(detector_stage: DetectorMotion, target: float): + logger.info(f"Moving detector stage to target position: {target}.") + yield from bps.abs_set( + detector_stage.y, + target, + wait=True, + ) + + +def setup_detector_stage(detector_stage: DetectorMotion, expt_type: SSXType): + # Grab the correct PV depending on experiment + # Its value is set with MUX on edm screen + det_type = EXPT_TYPE_DETECTOR_PVS[expt_type] + requested_detector = caget(det_type) + logger.info(f"Requested detector: {requested_detector}.") + det_y_target = ( + Eiger.det_y_target if "eiger" in requested_detector else Pilatus.det_y_target + ) + yield from _move_detector_stage(detector_stage, det_y_target) + logger.info("Detector setup done.") + + +if __name__ == "__main__": + setup_logging() + parser = argparse.ArgumentParser() + parser.add_argument( + "expt", + type=str, + choices=[expt.value for expt in SSXType], + help="Type of serial experiment being run.", + ) + args = parser.parse_args() + expt_type = SSXType(args.expt) + RE = RunEngine() + # Use dodal device for move + detector_stage = i24.detector_motion() + RE(setup_detector_stage(detector_stage, expt_type)) diff --git a/tests/I24/serial/extruder/test_extruder_collect.py b/tests/I24/serial/extruder/test_extruder_collect.py index e5d04eee7..7e0bbbc11 100644 --- a/tests/I24/serial/extruder/test_extruder_collect.py +++ b/tests/I24/serial/extruder/test_extruder_collect.py @@ -47,9 +47,7 @@ def test_scrape_parameter_file(): @patch("mx_bluesky.I24.serial.extruder.i24ssx_Extruder_Collect_py3v2.caget") @patch("mx_bluesky.I24.serial.extruder.i24ssx_Extruder_Collect_py3v2.caput") -@patch( - "mx_bluesky.I24.serial.extruder.i24ssx_Extruder_Collect_py3v2.sup.get_detector_type" -) +@patch("mx_bluesky.I24.serial.extruder.i24ssx_Extruder_Collect_py3v2.get_detector_type") @patch("mx_bluesky.I24.serial.extruder.i24ssx_Extruder_Collect_py3v2.logger") def test_initialise_extruder(fake_log, fake_det, fake_caput, fake_caget): fake_caget.return_value = "/path/to/visit" diff --git a/tests/I24/serial/setup_beamline/test_setup_beamline.py b/tests/I24/serial/setup_beamline/test_setup_beamline.py index 64a21117a..10277633a 100644 --- a/tests/I24/serial/setup_beamline/test_setup_beamline.py +++ b/tests/I24/serial/setup_beamline/test_setup_beamline.py @@ -5,18 +5,6 @@ from mx_bluesky.I24.serial.setup_beamline import setup_beamline -@patch("mx_bluesky.I24.serial.setup_beamline.setup_beamline.caget") -def test_get_detector_type(fake_caget): - fake_caget.return_value = -22 - assert setup_beamline.get_detector_type().name == "eiger" - - -@patch("mx_bluesky.I24.serial.setup_beamline.setup_beamline.caget") -def test_get_detector_type_finds_pilatus(fake_caget): - fake_caget.return_value = 566 - assert setup_beamline.get_detector_type().name == "pilatus" - - @patch("mx_bluesky.I24.serial.setup_beamline.setup_beamline.caput") def test_beamline_collect(fake_caput): setup_beamline.beamline("collect") diff --git a/tests/I24/serial/setup_beamline/test_setup_detector.py b/tests/I24/serial/setup_beamline/test_setup_detector.py new file mode 100644 index 000000000..a41f87386 --- /dev/null +++ b/tests/I24/serial/setup_beamline/test_setup_detector.py @@ -0,0 +1,57 @@ +from functools import partial +from unittest.mock import patch + +import pytest +from bluesky.run_engine import RunEngine +from dodal.beamlines import i24 +from dodal.devices.i24.I24_detector_motion import DetectorMotion +from ophyd.status import Status + +from mx_bluesky.I24.serial.parameters.constants import SSXType +from mx_bluesky.I24.serial.setup_beamline import Eiger, Pilatus +from mx_bluesky.I24.serial.setup_beamline.setup_detector import ( + get_detector_type, + setup_detector_stage, +) + + +@pytest.fixture +def fake_detector_motion() -> DetectorMotion: + detector_motion = i24.detector_motion(fake_with_ophyd_sim=True) + detector_motion.y.user_setpoint._use_limits = False + detector_motion.z.user_setpoint._use_limits = False + + def mock_set(motor, val): + motor.user_readback.sim_put(val) + return Status(done=True, success=True) + + def patch_motor(motor): + return patch.object(motor, "set", partial(mock_set, motor)) + + with patch_motor(detector_motion.y), patch_motor(detector_motion.z): + yield detector_motion + + +@patch("mx_bluesky.I24.serial.setup_beamline.setup_detector.caget") +def test_get_detector_type(fake_caget): + fake_caget.return_value = -22 + assert get_detector_type().name == "eiger" + + +@patch("mx_bluesky.I24.serial.setup_beamline.setup_detector.caget") +def test_get_detector_type_finds_pilatus(fake_caget): + fake_caget.return_value = 566 + assert get_detector_type().name == "pilatus" + + +@patch("mx_bluesky.I24.serial.setup_beamline.setup_detector.caget") +def test_setup_detector_stage_for_eiger(fake_caget, fake_detector_motion): + RE = RunEngine() + + fake_caget.return_value = "eiger" + RE(setup_detector_stage(fake_detector_motion, SSXType.FIXED)) + assert fake_detector_motion.y.user_readback.get() == Eiger.det_y_target + + fake_caget.return_value = "pilatus" + RE(setup_detector_stage(fake_detector_motion, SSXType.EXTRUDER)) + assert fake_detector_motion.y.user_readback.get() == Pilatus.det_y_target