From 8217dfca5db33c4f99678a5c0614c06e8c1935f1 Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Thu, 2 Nov 2023 17:04:18 +0000 Subject: [PATCH 01/13] FIrst make some order --- .../extruder/i24ssx_Extruder_Collect_py3v2.py | 3 +- .../fixed_target/i24ssx_Chip_Manager_py3v1.py | 4 +-- .../I24/serial/setup_beamline/pv.py | 2 +- .../serial/setup_beamline/setup_beamline.py | 18 ---------- .../serial/setup_beamline/setup_detector.py | 34 +++++++++++++++++++ .../serial/extruder/test_extruder_collect.py | 4 +-- .../setup_beamline/test_setup_beamline.py | 12 ------- .../setup_beamline/test_setup_detector.py | 15 ++++++++ 8 files changed, 55 insertions(+), 37 deletions(-) create mode 100644 src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py create mode 100644 tests/I24/serial/setup_beamline/test_setup_detector.py 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..2f6f3efe5 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 @@ -19,6 +19,7 @@ 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 +50,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/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/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..a5b2d2207 --- /dev/null +++ b/src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py @@ -0,0 +1,34 @@ +import logging + +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_det") + + +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 move_detector_stage(expt_type: str): + print(expt_type) + # detector_pv = pv.me14e_gp101 + pass + + +if __name__ == "__main__": + move_detector_stage("fixed_target") 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..9c1108272 --- /dev/null +++ b/tests/I24/serial/setup_beamline/test_setup_detector.py @@ -0,0 +1,15 @@ +from unittest.mock import patch + +from mx_bluesky.I24.serial.setup_beamline.setup_detector import get_detector_type + + +@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" From 33e14e73f4ef4af3a99ee2c5072d8104ab4fbd45 Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Thu, 2 Nov 2023 17:16:55 +0000 Subject: [PATCH 02/13] Set up PV abstract for experiments to easily find common PVs --- src/mx_bluesky/I24/serial/dcid.py | 7 +-- .../extruder/i24ssx_Extruder_Collect_py3v2.py | 3 +- .../fixed_target/i24ssx_Chip_Collect_py3v1.py | 3 +- .../I24/serial/parameters/__init__.py | 5 ++ .../I24/serial/parameters/constants.py | 7 +++ .../I24/serial/setup_beamline/pv_abstract.py | 46 +++++++++++++++++++ 6 files changed, 63 insertions(+), 8 deletions(-) create mode 100644 src/mx_bluesky/I24/serial/parameters/__init__.py diff --git a/src/mx_bluesky/I24/serial/dcid.py b/src/mx_bluesky/I24/serial/dcid.py index 4c0e1d549..a203ab0d9 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/i24ssx_Extruder_Collect_py3v2.py b/src/mx_bluesky/I24/serial/extruder/i24ssx_Extruder_Collect_py3v2.py index 2f6f3efe5..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,7 +15,8 @@ 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 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/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 446c4507e..e6d2fd8dd 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" + + PARAM_FILE_PATH = Path("src/mx_bluesky/I24/serial/parameters").expanduser().resolve() PARAM_FILE_PATH_FT = ( Path("src/mx_bluesky/I24/serial/parameters/fixed_target").expanduser().resolve() diff --git a/src/mx_bluesky/I24/serial/setup_beamline/pv_abstract.py b/src/mx_bluesky/I24/serial/setup_beamline/pv_abstract.py index 2d9c437f2..24ad6d13d 100644 --- a/src/mx_bluesky/I24/serial/setup_beamline/pv_abstract.py +++ b/src/mx_bluesky/I24/serial/setup_beamline/pv_abstract.py @@ -8,6 +8,7 @@ from typing import Union +from mx_bluesky.I24.serial.parameters import SSXType from mx_bluesky.I24.serial.setup_beamline import pv @@ -64,3 +65,48 @@ class pv: Detector = Union[Pilatus, Eiger] + + +# Experiment types + + +class Extruder: + expt_type = SSXType.EXTRUDER + + class pv: + visit = pv.ioc12_gp1 + directory = pv.ioc12_gp2 + filename = pv.ioc12_gp3 + exp_time = pv.ioc12_gp5 + det_dist = pv.ioc12_gp7 + det_type = pv.ioc12_gp15 + pump_exp = pv.ioc12_gp9 + pump_delay = pv.ioc12_gp10 + + class spec_pv: + num_imgs = pv.ioc12_gp4 + pump_status = pv.ioc12_gp6 + + +class FixedTarget: + expt_type = SSXType.FIXED + + class pv: + visit = pv.me14e_gp100 + directory = pv.me14e_filepath + filename = pv.me14e_chip_name + exp_time = pv.me14e_exptime + det_dist = pv.me14e_dcdetdist + det_type = pv.me14e_gp101 + pump_exp = pv.me14e_gp103 + pump_delay = pv.me14e_gp110 + + class spec_pv: + chip_type = pv.me14e_gp1 + map_type = pv.me14e_gp2 + n_exposures = pv.me14e_gp3 + pump_repeat = pv.me14e_gp4 + prepump_exp = pv.me14e_gp109 + + +ExperimentType = Union[Extruder, FixedTarget] From fe5a622f0344760a56200fa822f003b3ed3b1e84 Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Thu, 2 Nov 2023 17:40:47 +0000 Subject: [PATCH 03/13] Save all files from previous change --- src/mx_bluesky/I24/serial/setup_beamline/__init__.py | 5 ++++- tests/I24/serial/setup_beamline/test_pv_abstract.py | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/mx_bluesky/I24/serial/setup_beamline/__init__.py b/src/mx_bluesky/I24/serial/setup_beamline/__init__.py index f4dcfd8ec..f147d78e1 100644 --- a/src/mx_bluesky/I24/serial/setup_beamline/__init__.py +++ b/src/mx_bluesky/I24/serial/setup_beamline/__init__.py @@ -1,6 +1,6 @@ from . import pv, setup_beamline from .ca import caget, cagetstring, caput -from .pv_abstract import Detector, Eiger, Pilatus +from .pv_abstract import Detector, Eiger, ExperimentType, Extruder, FixedTarget, Pilatus __all__ = [ "caget", @@ -11,4 +11,7 @@ "Pilatus", "pv", "setup_beamline", + "Extruder", + "FixedTarget", + "ExperimentType", ] diff --git a/tests/I24/serial/setup_beamline/test_pv_abstract.py b/tests/I24/serial/setup_beamline/test_pv_abstract.py index 3a816b97e..dffe8cf3a 100644 --- a/tests/I24/serial/setup_beamline/test_pv_abstract.py +++ b/tests/I24/serial/setup_beamline/test_pv_abstract.py @@ -1,4 +1,4 @@ -from mx_bluesky.I24.serial.setup_beamline import Eiger, Pilatus +from mx_bluesky.I24.serial.setup_beamline import Eiger, Extruder, FixedTarget, Pilatus def test_eiger(): @@ -9,3 +9,8 @@ def test_eiger(): def test_pilatus(): pil = Pilatus() assert pil.image_size_mm == (423.636, 434.644) + + +def test_experiment_types(): + assert Extruder().expt_type.value == "Serial Jet" + assert FixedTarget().expt_type.value == "Serial Fixed" From 727ed1953b35e712c9d874bc2a65369bb59dfb42 Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Thu, 2 Nov 2023 18:03:02 +0000 Subject: [PATCH 04/13] Bare bones of an idea --- .../serial/setup_beamline/setup_detector.py | 56 +++++++++++++++++-- 1 file changed, 51 insertions(+), 5 deletions(-) diff --git a/src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py b/src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py index a5b2d2207..14e6ddfdf 100644 --- a/src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py +++ b/src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py @@ -1,12 +1,31 @@ +""" +Utilities for defining the detector in use, and moving the stage. +""" +import argparse import logging +import time +from mx_bluesky.I24.serial import log 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 +from mx_bluesky.I24.serial.setup_beamline.pv_abstract import ( + Detector, + Eiger, + ExperimentType, + Extruder, + FixedTarget, + Pilatus, +) logger = logging.getLogger("I24ssx.sup_det") +def setup_logging(): + # Log should now change name daily. + logfile = time.strftime("SSXdetectorOps_%d%B%y.log").lower() + log.config(logfile) + + class UnknownDetectorType(Exception): pass @@ -24,11 +43,38 @@ def get_detector_type() -> Detector: raise UnknownDetectorType("Detector not found.") -def move_detector_stage(expt_type: str): - print(expt_type) - # detector_pv = pv.me14e_gp101 +def move_detector_stage(): + "Plan goes here" pass +def setup_detector_stage(expt_type: str): + expt: ExperimentType + expt = FixedTarget() if expt_type == "fixed-target" else Extruder() + print(expt.expt_type) + current_detector = get_detector_type().name + logger.info( + f"Detector type PV for {expt_type} currently set to: {current_detector}." + ) + requested_detector = caget(expt.pv.det_type) + logger.info(f"Requested detector: {requested_detector}.") + if current_detector == requested_detector: + print("do nothing") + else: + print("call plan to move") + logger.info("Detector setup done.") + + if __name__ == "__main__": - move_detector_stage("fixed_target") + setup_logging() + + parser = argparse.ArgumentParser() + parser.add_argument( + "expt", + type=str, + choices=["extruder", "fixed-target"], + help="Type of serial experiment being run.", + ) + + args = parser.parse_args() + setup_detector_stage(args.expt) From d86f0e620b1058e8ffb2a4431c9c1df6f22eab75 Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Tue, 7 Nov 2023 19:27:52 +0000 Subject: [PATCH 05/13] A stub --- .../serial/setup_beamline/setup_detector.py | 41 ++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py b/src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py index 14e6ddfdf..98926adbf 100644 --- a/src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py +++ b/src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py @@ -5,6 +5,11 @@ 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.setup_beamline import pv from mx_bluesky.I24.serial.setup_beamline.ca import caget # , caput @@ -21,7 +26,6 @@ def setup_logging(): - # Log should now change name daily. logfile = time.strftime("SSXdetectorOps_%d%B%y.log").lower() log.config(logfile) @@ -30,8 +34,14 @@ class UnknownDetectorType(Exception): pass +def _read_detector_stage_position(det_stage: DetectorMotion): + yield from bps.rd(det_stage.y) + yield from bps.rd(det_stage.z) + + def get_detector_type() -> Detector: det_y = caget(pv.det_y) + # Note to self, I should also be able to use detmotion for this too! if float(det_y) < Eiger.det_y_threshold: logger.info("Eiger detector in use.") return Eiger() @@ -43,24 +53,43 @@ def get_detector_type() -> Detector: raise UnknownDetectorType("Detector not found.") -def move_detector_stage(): +def check_detector_position(det_stage: DetectorMotion, tolerance: int = 10): + """Check that detector is in the right position (ie if pilatus not in place \ + for eiger) and/or that it's within allowed range (see tolerance) + """ + det_y = yield from bps.rd(det_stage.y) + print(det_y) + + +def move_detector_stage(det_stage: DetectorMotion, target: float): + yield from bps.abs_set( + det_stage.y, + target, + ) "Plan goes here" - pass def setup_detector_stage(expt_type: str): expt: ExperimentType expt = FixedTarget() if expt_type == "fixed-target" else Extruder() - print(expt.expt_type) + detector_stage = i24.detector_motion() current_detector = get_detector_type().name logger.info( f"Detector type PV for {expt_type} currently set to: {current_detector}." ) - requested_detector = caget(expt.pv.det_type) + requested_detector = caget(expt.pv.det_type) # Set with MUX on edm screen logger.info(f"Requested detector: {requested_detector}.") + RE = RunEngine() if current_detector == requested_detector: - print("do nothing") + # check that the position is actually correct, if not move + logger.info("Detector already in place") else: + det_y_target = ( + Eiger.det_y_target + if "eiger" in requested_detector + else Pilatus.det_y_target + ) + RE(move_detector_stage(detector_stage, det_y_target)) print("call plan to move") logger.info("Detector setup done.") From c0e83edb578da611d16732a25262c9bb40821ba2 Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Thu, 9 Nov 2023 17:26:32 +0000 Subject: [PATCH 06/13] Simplify things a bit --- .../I24/serial/setup_beamline/__init__.py | 5 +- .../I24/serial/setup_beamline/pv_abstract.py | 46 ---------------- .../serial/setup_beamline/setup_detector.py | 52 +++++-------------- .../serial/setup_beamline/test_pv_abstract.py | 7 +-- 4 files changed, 16 insertions(+), 94 deletions(-) diff --git a/src/mx_bluesky/I24/serial/setup_beamline/__init__.py b/src/mx_bluesky/I24/serial/setup_beamline/__init__.py index f147d78e1..f4dcfd8ec 100644 --- a/src/mx_bluesky/I24/serial/setup_beamline/__init__.py +++ b/src/mx_bluesky/I24/serial/setup_beamline/__init__.py @@ -1,6 +1,6 @@ from . import pv, setup_beamline from .ca import caget, cagetstring, caput -from .pv_abstract import Detector, Eiger, ExperimentType, Extruder, FixedTarget, Pilatus +from .pv_abstract import Detector, Eiger, Pilatus __all__ = [ "caget", @@ -11,7 +11,4 @@ "Pilatus", "pv", "setup_beamline", - "Extruder", - "FixedTarget", - "ExperimentType", ] diff --git a/src/mx_bluesky/I24/serial/setup_beamline/pv_abstract.py b/src/mx_bluesky/I24/serial/setup_beamline/pv_abstract.py index 24ad6d13d..2d9c437f2 100644 --- a/src/mx_bluesky/I24/serial/setup_beamline/pv_abstract.py +++ b/src/mx_bluesky/I24/serial/setup_beamline/pv_abstract.py @@ -8,7 +8,6 @@ from typing import Union -from mx_bluesky.I24.serial.parameters import SSXType from mx_bluesky.I24.serial.setup_beamline import pv @@ -65,48 +64,3 @@ class pv: Detector = Union[Pilatus, Eiger] - - -# Experiment types - - -class Extruder: - expt_type = SSXType.EXTRUDER - - class pv: - visit = pv.ioc12_gp1 - directory = pv.ioc12_gp2 - filename = pv.ioc12_gp3 - exp_time = pv.ioc12_gp5 - det_dist = pv.ioc12_gp7 - det_type = pv.ioc12_gp15 - pump_exp = pv.ioc12_gp9 - pump_delay = pv.ioc12_gp10 - - class spec_pv: - num_imgs = pv.ioc12_gp4 - pump_status = pv.ioc12_gp6 - - -class FixedTarget: - expt_type = SSXType.FIXED - - class pv: - visit = pv.me14e_gp100 - directory = pv.me14e_filepath - filename = pv.me14e_chip_name - exp_time = pv.me14e_exptime - det_dist = pv.me14e_dcdetdist - det_type = pv.me14e_gp101 - pump_exp = pv.me14e_gp103 - pump_delay = pv.me14e_gp110 - - class spec_pv: - chip_type = pv.me14e_gp1 - map_type = pv.me14e_gp2 - n_exposures = pv.me14e_gp3 - pump_repeat = pv.me14e_gp4 - prepump_exp = pv.me14e_gp109 - - -ExperimentType = Union[Extruder, FixedTarget] diff --git a/src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py b/src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py index 98926adbf..69c85289e 100644 --- a/src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py +++ b/src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py @@ -16,9 +16,6 @@ from mx_bluesky.I24.serial.setup_beamline.pv_abstract import ( Detector, Eiger, - ExperimentType, - Extruder, - FixedTarget, Pilatus, ) @@ -34,11 +31,6 @@ class UnknownDetectorType(Exception): pass -def _read_detector_stage_position(det_stage: DetectorMotion): - yield from bps.rd(det_stage.y) - yield from bps.rd(det_stage.z) - - def get_detector_type() -> Detector: det_y = caget(pv.det_y) # Note to self, I should also be able to use detmotion for this too! @@ -53,44 +45,28 @@ def get_detector_type() -> Detector: raise UnknownDetectorType("Detector not found.") -def check_detector_position(det_stage: DetectorMotion, tolerance: int = 10): - """Check that detector is in the right position (ie if pilatus not in place \ - for eiger) and/or that it's within allowed range (see tolerance) - """ - det_y = yield from bps.rd(det_stage.y) - print(det_y) - - -def move_detector_stage(det_stage: DetectorMotion, target: float): +def _move_detector_stage(det_stage: DetectorMotion, target: float): + logger.info(f"Moving detector stage to target position: {target}.") yield from bps.abs_set( det_stage.y, target, + wait=True, ) - "Plan goes here" def setup_detector_stage(expt_type: str): - expt: ExperimentType - expt = FixedTarget() if expt_type == "fixed-target" else Extruder() - detector_stage = i24.detector_motion() - current_detector = get_detector_type().name - logger.info( - f"Detector type PV for {expt_type} currently set to: {current_detector}." - ) - requested_detector = caget(expt.pv.det_type) # Set with MUX on edm screen - logger.info(f"Requested detector: {requested_detector}.") RE = RunEngine() - if current_detector == requested_detector: - # check that the position is actually correct, if not move - logger.info("Detector already in place") - else: - det_y_target = ( - Eiger.det_y_target - if "eiger" in requested_detector - else Pilatus.det_y_target - ) - RE(move_detector_stage(detector_stage, det_y_target)) - print("call plan to move") + # Grab the correct PV depending on experiment + # Its value is set with MUX on edm screen + det_type = pv.me14e_gp101 if expt_type == "fixed-target" else pv.ioc12_gp15 + 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 + ) + # Use dodal device for move + detector_stage = i24.detector_motion() + RE(_move_detector_stage(detector_stage, det_y_target)) logger.info("Detector setup done.") diff --git a/tests/I24/serial/setup_beamline/test_pv_abstract.py b/tests/I24/serial/setup_beamline/test_pv_abstract.py index dffe8cf3a..3a816b97e 100644 --- a/tests/I24/serial/setup_beamline/test_pv_abstract.py +++ b/tests/I24/serial/setup_beamline/test_pv_abstract.py @@ -1,4 +1,4 @@ -from mx_bluesky.I24.serial.setup_beamline import Eiger, Extruder, FixedTarget, Pilatus +from mx_bluesky.I24.serial.setup_beamline import Eiger, Pilatus def test_eiger(): @@ -9,8 +9,3 @@ def test_eiger(): def test_pilatus(): pil = Pilatus() assert pil.image_size_mm == (423.636, 434.644) - - -def test_experiment_types(): - assert Extruder().expt_type.value == "Serial Jet" - assert FixedTarget().expt_type.value == "Serial Fixed" From 697ae5b8290ed03b9ce3dce8a103af032e25d22c Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Fri, 10 Nov 2023 13:10:45 +0000 Subject: [PATCH 07/13] Add a test --- .../serial/setup_beamline/setup_detector.py | 16 ++++---- .../setup_beamline/test_setup_detector.py | 39 ++++++++++++++++++- 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py b/src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py index 69c85289e..f20333072 100644 --- a/src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py +++ b/src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py @@ -45,17 +45,16 @@ def get_detector_type() -> Detector: raise UnknownDetectorType("Detector not found.") -def _move_detector_stage(det_stage: DetectorMotion, target: float): +def _move_detector_stage(detector_stage: DetectorMotion, target: float): logger.info(f"Moving detector stage to target position: {target}.") yield from bps.abs_set( - det_stage.y, + detector_stage.y, target, wait=True, ) -def setup_detector_stage(expt_type: str): - RE = RunEngine() +def setup_detector_stage(detector_stage: DetectorMotion, expt_type: str): # Grab the correct PV depending on experiment # Its value is set with MUX on edm screen det_type = pv.me14e_gp101 if expt_type == "fixed-target" else pv.ioc12_gp15 @@ -64,14 +63,15 @@ def setup_detector_stage(expt_type: str): det_y_target = ( Eiger.det_y_target if "eiger" in requested_detector else Pilatus.det_y_target ) - # Use dodal device for move - detector_stage = i24.detector_motion() - RE(_move_detector_stage(detector_stage, det_y_target)) + yield from _move_detector_stage(detector_stage, det_y_target) logger.info("Detector setup done.") if __name__ == "__main__": setup_logging() + RE = RunEngine() + # Use dodal device for move + detector_stage = i24.detector_motion() parser = argparse.ArgumentParser() parser.add_argument( @@ -82,4 +82,4 @@ def setup_detector_stage(expt_type: str): ) args = parser.parse_args() - setup_detector_stage(args.expt) + RE(setup_detector_stage(detector_stage, args.expt)) diff --git a/tests/I24/serial/setup_beamline/test_setup_detector.py b/tests/I24/serial/setup_beamline/test_setup_detector.py index 9c1108272..aad60b050 100644 --- a/tests/I24/serial/setup_beamline/test_setup_detector.py +++ b/tests/I24/serial/setup_beamline/test_setup_detector.py @@ -1,6 +1,34 @@ +from functools import partial from unittest.mock import patch -from mx_bluesky.I24.serial.setup_beamline.setup_detector import get_detector_type +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.setup_beamline import Eiger +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") @@ -13,3 +41,12 @@ def test_get_detector_type(fake_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, "fixed-target")) + assert fake_detector_motion.y.user_readback.get() == Eiger.det_y_target From dba50a6cfe9a41ff5395b48c7d7142737d275232 Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Fri, 10 Nov 2023 13:24:56 +0000 Subject: [PATCH 08/13] Add edm screen for detector dtage --- .../fixed_target/FT-gui-edm/DetStage.edl | 139 ++++++++++++++++++ .../FT-gui-edm/DiamondChipI24-py3v1.edl | 38 ++++- 2 files changed, 170 insertions(+), 7 deletions(-) create mode 100644 src/mx_bluesky/I24/serial/fixed_target/FT-gui-edm/DetStage.edl 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..5cdc79f8e --- /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 2848 +y 651 +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 "P300K" +} +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 0 +botShadowColor index 14 +font "arial-medium-r-18.0" +buttonLabel "Move Stage" +numCmds 1 +command { + 0 "python SCRIPTS_LOCATION/setup_beamline/setup_detector.py fixed-target" +} +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..3a9589cf0 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 150 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 0 +botShadowColor index 14 +font "arial-medium-r-16.0" +buttonLabel "Detector" +numPvs 4 +numDsps 1 +displayFileName { + 0 "EDM_LOCATION/DetStage.edl" +} +endObjectProperties + From deb9733d1485c633e34f46c525f52cfdd530ea8b Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Fri, 10 Nov 2023 13:39:55 +0000 Subject: [PATCH 09/13] Add edm for extruder and tidy it up --- .../serial/extruder/EX-gui-edm/DetStage.edl | 139 ++++++++++++++++++ .../EX-gui-edm/DiamondExtruder-I24-py3v1.edl | 63 +++++--- .../fixed_target/FT-gui-edm/DetStage.edl | 4 +- .../FT-gui-edm/DiamondChipI24-py3v1.edl | 6 +- 4 files changed, 187 insertions(+), 25 deletions(-) create mode 100644 src/mx_bluesky/I24/serial/extruder/EX-gui-edm/DetStage.edl 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..21adb747b --- /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 498 +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 0 +botShadowColor index 14 +font "arial-medium-r-18.0" +buttonLabel "Move Stage" +numCmds 1 +command { + 0 "python SCRIPTS_LOCATION/setup_beamline/setup_detector.py extruder" +} +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/fixed_target/FT-gui-edm/DetStage.edl b/src/mx_bluesky/I24/serial/fixed_target/FT-gui-edm/DetStage.edl index 5cdc79f8e..ca39feda9 100644 --- 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 @@ -4,7 +4,7 @@ major 4 minor 0 release 1 x 2848 -y 651 +y 688 w 450 h 180 font "arial-medium-r-18.0" @@ -87,7 +87,7 @@ symbolTag { } symbol0 { 0 "E9M" - 1 "P300K" + 1 "P6M" } PV0 { 0 "eiger" 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 3a9589cf0..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 150 +y 187 w 1030 h 950 font "arial-medium-r-18.0" @@ -4076,8 +4076,8 @@ w 105 h 30 fgColor index 14 bgColor index 49 -topShadowColor index 0 -botShadowColor index 14 +topShadowColor index 1 +botShadowColor index 11 font "arial-medium-r-16.0" buttonLabel "Detector" numPvs 4 From b8c7d6c10da14c4f0b882c103919dbe5d6d669ab Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Fri, 10 Nov 2023 16:42:47 +0000 Subject: [PATCH 10/13] Add issue link --- src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py b/src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py index f20333072..262cd946c 100644 --- a/src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py +++ b/src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py @@ -33,7 +33,8 @@ class UnknownDetectorType(Exception): def get_detector_type() -> Detector: det_y = caget(pv.det_y) - # Note to self, I should also be able to use detmotion for this too! + # 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() From 284e9ac17585f8477d97e611c55f3b3a3c30f71b Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Fri, 10 Nov 2023 17:00:16 +0000 Subject: [PATCH 11/13] Use SSXType for expt --- .../I24/serial/extruder/EX-gui-edm/DetStage.edl | 8 ++++---- .../I24/serial/fixed_target/FT-gui-edm/DetStage.edl | 10 +++++----- .../I24/serial/setup_beamline/setup_detector.py | 5 +++-- tests/I24/serial/setup_beamline/test_setup_detector.py | 3 ++- 4 files changed, 14 insertions(+), 12 deletions(-) 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 index 21adb747b..e066864ff 100644 --- a/src/mx_bluesky/I24/serial/extruder/EX-gui-edm/DetStage.edl +++ b/src/mx_bluesky/I24/serial/extruder/EX-gui-edm/DetStage.edl @@ -4,7 +4,7 @@ major 4 minor 0 release 1 x 3338 -y 498 +y 572 w 450 h 180 font "arial-medium-r-18.0" @@ -107,13 +107,13 @@ w 160 h 42 fgColor index 14 bgColor index 49 -topShadowColor index 0 -botShadowColor index 14 +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 extruder" + 0 "python SCRIPTS_LOCATION/setup_beamline/setup_detector.py \"Serial Jet\"" } endObjectProperties 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 index ca39feda9..0f81b680a 100644 --- 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 @@ -3,8 +3,8 @@ beginScreenProperties major 4 minor 0 release 1 -x 2848 -y 688 +x 3172 +y 731 w 450 h 180 font "arial-medium-r-18.0" @@ -107,13 +107,13 @@ w 160 h 42 fgColor index 14 bgColor index 49 -topShadowColor index 0 -botShadowColor index 14 +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 fixed-target" + 0 "python SCRIPTS_LOCATION/setup_beamline/setup_detector.py \"Serial Fixed\"" } endObjectProperties diff --git a/src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py b/src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py index 262cd946c..d21796d62 100644 --- a/src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py +++ b/src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py @@ -11,6 +11,7 @@ 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 # , caput from mx_bluesky.I24.serial.setup_beamline.pv_abstract import ( @@ -58,7 +59,7 @@ def _move_detector_stage(detector_stage: DetectorMotion, target: float): def setup_detector_stage(detector_stage: DetectorMotion, expt_type: str): # Grab the correct PV depending on experiment # Its value is set with MUX on edm screen - det_type = pv.me14e_gp101 if expt_type == "fixed-target" else pv.ioc12_gp15 + det_type = pv.me14e_gp101 if expt_type == SSXType.FIXED.value else pv.ioc12_gp15 requested_detector = caget(det_type) logger.info(f"Requested detector: {requested_detector}.") det_y_target = ( @@ -78,7 +79,7 @@ def setup_detector_stage(detector_stage: DetectorMotion, expt_type: str): parser.add_argument( "expt", type=str, - choices=["extruder", "fixed-target"], + choices=["Serial Jet", "Serial Fixed"], help="Type of serial experiment being run.", ) diff --git a/tests/I24/serial/setup_beamline/test_setup_detector.py b/tests/I24/serial/setup_beamline/test_setup_detector.py index aad60b050..9cb699e03 100644 --- a/tests/I24/serial/setup_beamline/test_setup_detector.py +++ b/tests/I24/serial/setup_beamline/test_setup_detector.py @@ -7,6 +7,7 @@ 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 from mx_bluesky.I24.serial.setup_beamline.setup_detector import ( get_detector_type, @@ -48,5 +49,5 @@ 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, "fixed-target")) + RE(setup_detector_stage(fake_detector_motion, SSXType.FIXED.value)) assert fake_detector_motion.y.user_readback.get() == Eiger.det_y_target From 0586ac1e9e0c44c196e732e0b14fe103da5ee745 Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Fri, 10 Nov 2023 17:02:25 +0000 Subject: [PATCH 12/13] Change test to reflect parser --- tests/I24/serial/setup_beamline/test_setup_detector.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/I24/serial/setup_beamline/test_setup_detector.py b/tests/I24/serial/setup_beamline/test_setup_detector.py index 9cb699e03..b048f8864 100644 --- a/tests/I24/serial/setup_beamline/test_setup_detector.py +++ b/tests/I24/serial/setup_beamline/test_setup_detector.py @@ -7,7 +7,6 @@ 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 from mx_bluesky.I24.serial.setup_beamline.setup_detector import ( get_detector_type, @@ -49,5 +48,5 @@ 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.value)) + RE(setup_detector_stage(fake_detector_motion, "Serial Fixed")) assert fake_detector_motion.y.user_readback.get() == Eiger.det_y_target From 8994d57a2953e9c62ad9021775d88d9ea685c8c0 Mon Sep 17 00:00:00 2001 From: David Perl Date: Fri, 10 Nov 2023 18:00:34 +0000 Subject: [PATCH 13/13] use enum type as soon as args are parsed --- .../serial/setup_beamline/setup_detector.py | 24 +++++++++++-------- .../setup_beamline/test_setup_detector.py | 11 ++++++--- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py b/src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py index d21796d62..3717fd341 100644 --- a/src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py +++ b/src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py @@ -13,7 +13,7 @@ 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 # , caput +from mx_bluesky.I24.serial.setup_beamline.ca import caget from mx_bluesky.I24.serial.setup_beamline.pv_abstract import ( Detector, Eiger, @@ -22,6 +22,11 @@ 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() @@ -56,10 +61,10 @@ def _move_detector_stage(detector_stage: DetectorMotion, target: float): ) -def setup_detector_stage(detector_stage: DetectorMotion, expt_type: str): +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 = pv.me14e_gp101 if expt_type == SSXType.FIXED.value else pv.ioc12_gp15 + det_type = EXPT_TYPE_DETECTOR_PVS[expt_type] requested_detector = caget(det_type) logger.info(f"Requested detector: {requested_detector}.") det_y_target = ( @@ -71,17 +76,16 @@ def setup_detector_stage(detector_stage: DetectorMotion, expt_type: str): if __name__ == "__main__": setup_logging() - RE = RunEngine() - # Use dodal device for move - detector_stage = i24.detector_motion() - parser = argparse.ArgumentParser() parser.add_argument( "expt", type=str, - choices=["Serial Jet", "Serial Fixed"], + choices=[expt.value for expt in SSXType], help="Type of serial experiment being run.", ) - args = parser.parse_args() - RE(setup_detector_stage(detector_stage, args.expt)) + 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/setup_beamline/test_setup_detector.py b/tests/I24/serial/setup_beamline/test_setup_detector.py index b048f8864..a41f87386 100644 --- a/tests/I24/serial/setup_beamline/test_setup_detector.py +++ b/tests/I24/serial/setup_beamline/test_setup_detector.py @@ -7,7 +7,8 @@ from dodal.devices.i24.I24_detector_motion import DetectorMotion from ophyd.status import Status -from mx_bluesky.I24.serial.setup_beamline import Eiger +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, @@ -46,7 +47,11 @@ def test_get_detector_type_finds_pilatus(fake_caget): @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, "Serial Fixed")) + 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