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 cbb57a342..215073cd6 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 @@ -40,10 +40,8 @@ def initialise_extruderi24(): visit = "/dls/i24/data/2023/cm33852-2/" lg.info("%s Visit defined %s" % (name, visit)) - # define detector using the below line - # Oct 2021. beta. Do not change from pilatus unless your name is Robin - det_type = "pilatus" - # det_type = "eiger" + # Define detector in use + det_type = sup.get_detector_type() caput(pv.ioc12_gp1, str(visit)) caput(pv.ioc12_gp2, "test") @@ -54,7 +52,7 @@ def initialise_extruderi24(): caput(pv.ioc12_gp8, 0) # status PV do not reuse gp8 for something else caput(pv.ioc12_gp9, 0) caput(pv.ioc12_gp10, 0) - caput(pv.ioc12_gp15, str(det_type)) + caput(pv.ioc12_gp15, det_type.name) caput(pv.pilat_cbftemplate, 0) print("Done Done Done") lg.info("%s Initialsation complete" % name) 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 9539b0926..3b8ed1e6f 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 @@ -15,6 +15,7 @@ from mx_bluesky.I24.serial.fixed_target import i24ssx_Chip_Mapping_py3v1 as mapping from mx_bluesky.I24.serial.fixed_target import i24ssx_Chip_StartUp_py3v1 as startup from mx_bluesky.I24.serial.setup_beamline import caget, caput, pv +from mx_bluesky.I24.serial.setup_beamline import setup_beamline as sup # Log should now change name daily. lg.basicConfig( @@ -89,10 +90,10 @@ def initialise(): caput(pv.me14e_pmac_str, "m708=100 m709=150") caput(pv.me14e_pmac_str, "m808=100 m809=150") - # define detector using the below line - # det_type = "pilatus" + # Define detector in use + det_type = sup.get_detector_type() + caput(pv.pilat_cbftemplate, 0) - det_type = "eiger" sleep(0.1) print("Clearing") @@ -105,7 +106,7 @@ def initialise(): sys.stdout.flush() caput(pv.me14e_gp100, "press set params to read visit") - caput(pv.me14e_gp101, str(det_type)) + caput(pv.me14e_gp101, det_type.name) print("\n", "Initialisation Complete") lg.info("%s Complete" % name) 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 8f5269b8f..a6dfc4ee7 100644 --- a/src/mx_bluesky/I24/serial/setup_beamline/pv_abstract.py +++ b/src/mx_bluesky/I24/serial/setup_beamline/pv_abstract.py @@ -13,6 +13,7 @@ class Pilatus: id = 58 + name = "pilatus" # fast, slow / width, height image_size_pixels = (2463, 2527) @@ -21,6 +22,9 @@ class Pilatus: round(a * b, 3) for a, b in zip(image_size_pixels, pixel_size_mm) ) + det_y_threshold = 50.0 + det_y_target = 0.0 + class pv: detector_distance = pv.pilat_detdist wavelength = pv.pilat_wavelength @@ -35,6 +39,7 @@ class pv: class Eiger: id = 94 + name = "eiger" pixel_size_mm = (0.075, 0.075) image_size_pixels = (3108, 3262) @@ -43,6 +48,9 @@ class Eiger: round(a * b, 3) for a, b in zip(image_size_pixels, pixel_size_mm) ) + det_y_threshold = 200.0 + det_y_target = 220.0 + class pv: detector_distance = pv.eiger_detdist wavelength = pv.eiger_wavelength 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 2bea87444..e72dc748c 100644 --- a/src/mx_bluesky/I24/serial/setup_beamline/setup_beamline.py +++ b/src/mx_bluesky/I24/serial/setup_beamline/setup_beamline.py @@ -2,6 +2,21 @@ 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 + + +class UnknownDetectorType(Exception): + pass + + +def get_detector_type() -> Detector: + det_y = caget(pv.det_y) + if float(det_y) > Eiger.det_y_threshold: + return Eiger() + elif float(det_y) > Pilatus.det_y_threshold: + return Pilatus() + else: + raise UnknownDetectorType("Detector not found.") def modechange(action): diff --git a/tests/I24/serial/extruder/test_extruder_collect.py b/tests/I24/serial/extruder/test_extruder_collect.py index 5afc8da55..bb5ec828c 100644 --- a/tests/I24/serial/extruder/test_extruder_collect.py +++ b/tests/I24/serial/extruder/test_extruder_collect.py @@ -6,6 +6,7 @@ run_extruderi24, scrape_parameter_file, ) +from mx_bluesky.I24.serial.setup_beamline import Eiger params_file_str = """visit foo directory bar @@ -30,7 +31,11 @@ def test_scrape_parameter_file(): @patch("mx_bluesky.I24.serial.extruder.i24ssx_Extruder_Collect_py3v2.caput") -def test_initialise_extruder(fake_caput): +@patch( + "mx_bluesky.I24.serial.extruder.i24ssx_Extruder_Collect_py3v2.sup.get_detector_type" +) +def test_initialise_extruder(fake_det, fake_caput): + fake_det.return_value = Eiger() initialise_extruderi24() assert fake_caput.call_count == 11 diff --git a/tests/I24/serial/setup_beamline/test_setup_beamline.py b/tests/I24/serial/setup_beamline/test_setup_beamline.py index 5d356d137..2bff645df 100644 --- a/tests/I24/serial/setup_beamline/test_setup_beamline.py +++ b/tests/I24/serial/setup_beamline/test_setup_beamline.py @@ -5,6 +5,12 @@ 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 = 205 + assert setup_beamline.get_detector_type().name == "eiger" + + @patch("mx_bluesky.I24.serial.setup_beamline.setup_beamline.caput") def test_beamline_collect(fake_caput): setup_beamline.beamline("collect")