Skip to content

Commit

Permalink
use enum type as soon as args are parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
d-perl committed Nov 10, 2023
1 parent 0586ac1 commit 8994d57
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
24 changes: 14 additions & 10 deletions src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand Down Expand Up @@ -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 = (
Expand All @@ -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(

Check warning on line 80 in src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py

View check run for this annotation

Codecov / codecov/patch

src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py#L78-L80

Added lines #L78 - L80 were not covered by tests
"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()

Check warning on line 88 in src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py

View check run for this annotation

Codecov / codecov/patch

src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py#L86-L88

Added lines #L86 - L88 were not covered by tests
# Use dodal device for move
detector_stage = i24.detector_motion()
RE(setup_detector_stage(detector_stage, expt_type))

Check warning on line 91 in src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py

View check run for this annotation

Codecov / codecov/patch

src/mx_bluesky/I24/serial/setup_beamline/setup_detector.py#L90-L91

Added lines #L90 - L91 were not covered by tests
11 changes: 8 additions & 3 deletions tests/I24/serial/setup_beamline/test_setup_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

0 comments on commit 8994d57

Please sign in to comment.