Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace calls to deprecated inject() with direct factory calls #587

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/mx_bluesky/beamlines/i04/thawing_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import bluesky.preprocessors as bpp
from bluesky.preprocessors import run_decorator, subs_decorator
from dls_bluesky_core.core import MsgGenerator
from dodal.beamlines import i04
from dodal.beamlines.i04 import MURKO_REDIS_DB, REDIS_HOST, REDIS_PASSWORD
from dodal.common import inject
from dodal.devices.oav.oav_detector import OAV
from dodal.devices.oav.oav_to_redis_forwarder import OAVToRedisForwarder, Source
from dodal.devices.robot import BartRobot
Expand All @@ -18,11 +18,13 @@
def thaw_and_stream_to_redis(
time_to_thaw: float,
rotation: float = 360,
robot: BartRobot = inject("robot"),
thawer: Thawer = inject("thawer"),
smargon: Smargon = inject("smargon"),
oav: OAV = inject("oav"),
oav_to_redis_forwarder: OAVToRedisForwarder = inject("oav_to_redis_forwarder"),
robot: BartRobot = i04.robot(wait_for_connection=False),
thawer: Thawer = i04.thawer(wait_for_connection=False),
smargon: Smargon = i04.smargon(wait_for_connection=False),
oav: OAV = i04.oav(wait_for_connection=False),
oav_to_redis_forwarder: OAVToRedisForwarder = i04.oav_to_redis_forwarder(
wait_for_connection=False
),
) -> MsgGenerator:
zoom_percentage = yield from bps.rd(oav.zoom_controller.percentage) # type: ignore # See: https://github.com/bluesky/bluesky/issues/1809
sample_id = yield from bps.rd(robot.sample_id)
Expand Down Expand Up @@ -75,8 +77,8 @@ def cleanup():
def thaw(
time_to_thaw: float,
rotation: float = 360,
thawer: Thawer = inject("thawer"),
smargon: Smargon = inject("smargon"),
thawer: Thawer = i04.thawer(wait_for_connection=False),
smargon: Smargon = i04.smargon(wait_for_connection=False),
plan_between_rotations: Callable[[], MsgGenerator] | None = None,
) -> MsgGenerator:
"""Rotates the sample and thaws it at the same time.
Expand All @@ -85,9 +87,9 @@ def thaw(
time_to_thaw (float): Time to thaw for, in seconds.
rotation (float, optional): How much to rotate by whilst thawing, in degrees.
Defaults to 360.
thawer (Thawer, optional): The thawing device. Defaults to inject("thawer").
thawer (Thawer, optional): The thawing device. Defaults to i04.thawer(wait_for_connection=False).
smargon (Smargon, optional): The smargon used to rotate.
Defaults to inject("smargon")
Defaults to i04.smargon(wait_for_connection=False)
plan_between_rotations (MsgGenerator, optional): A plan to run between rotations
of the smargon. Defaults to no plan.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import bluesky.plan_stubs as bps
import bluesky.preprocessors as bpp
from blueapi.core import MsgGenerator
from dodal.common import inject
from dodal.beamlines import i24
from dodal.devices.hutch_shutter import HutchShutter, ShutterDemand
from dodal.devices.i24.aperture import Aperture
from dodal.devices.i24.beamstop import Beamstop
Expand Down Expand Up @@ -72,7 +72,7 @@ def flush_print(text):

@log.log_on_entry
def initialise_extruder(
detector_stage: DetectorMotion = inject("detector_motion"),
detector_stage: DetectorMotion = i24.detector_motion(wait_for_connection=False),
) -> MsgGenerator:
setup_logging()
logger.info("Initialise Parameters for extruder data collection on I24.")
Expand Down Expand Up @@ -100,8 +100,8 @@ def initialise_extruder(
@log.log_on_entry
def laser_check(
mode: str,
zebra: Zebra = inject("zebra"),
detector_stage: DetectorMotion = inject("detector_motion"),
zebra: Zebra = i24.zebra(wait_for_connection=False),
detector_stage: DetectorMotion = i24.detector_motion(wait_for_connection=False),
) -> MsgGenerator:
"""Plan to open the shutter and check the laser beam from the viewer by pressing \
'Laser On' and 'Laser Off' buttons on the edm.
Expand Down Expand Up @@ -133,7 +133,7 @@ def laser_check(

@log.log_on_entry
def enter_hutch(
detector_stage: DetectorMotion = inject("detector_motion"),
detector_stage: DetectorMotion = i24.detector_motion(wait_for_connection=False),
) -> MsgGenerator:
"""Move the detector stage before entering hutch."""
setup_logging()
Expand Down Expand Up @@ -466,13 +466,13 @@ def collection_complete_plan(


def run_extruder_plan(
zebra: Zebra = inject("zebra"),
aperture: Aperture = inject("aperture"),
backlight: DualBacklight = inject("backlight"),
beamstop: Beamstop = inject("beamstop"),
detector_stage: DetectorMotion = inject("detector_motion"),
shutter: HutchShutter = inject("shutter"),
dcm: DCM = inject("dcm"),
zebra: Zebra = i24.zebra(wait_for_connection=False),
aperture: Aperture = i24.aperture(wait_for_connection=False),
backlight: DualBacklight = i24.backlight(wait_for_connection=False),
beamstop: Beamstop = i24.beamstop(wait_for_connection=False),
detector_stage: DetectorMotion = i24.detector_motion(wait_for_connection=False),
shutter: HutchShutter = i24.shutter(wait_for_connection=False),
dcm: DCM = i24.dcm(wait_for_connection=False),
) -> MsgGenerator:
setup_logging()
start_time = datetime.now()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import bluesky.preprocessors as bpp
import numpy as np
from blueapi.core import MsgGenerator
from dodal.common import inject
from dodal.beamlines import i24
from dodal.devices.hutch_shutter import HutchShutter, ShutterDemand
from dodal.devices.i24.aperture import Aperture
from dodal.devices.i24.beamstop import Beamstop
Expand Down Expand Up @@ -743,14 +743,14 @@ def tidy_up_after_collection_plan(


def run_fixed_target_plan(
zebra: Zebra = inject("zebra"),
pmac: PMAC = inject("pmac"),
aperture: Aperture = inject("aperture"),
backlight: DualBacklight = inject("backlight"),
beamstop: Beamstop = inject("beamstop"),
detector_stage: DetectorMotion = inject("detector_motion"),
shutter: HutchShutter = inject("shutter"),
dcm: DCM = inject("dcm"),
zebra: Zebra = i24.zebra(wait_for_connection=False),
pmac: PMAC = i24.pmac(wait_for_connection=False),
aperture: Aperture = i24.aperture(wait_for_connection=False),
backlight: DualBacklight = i24.backlight(wait_for_connection=False),
beamstop: Beamstop = i24.beamstop(wait_for_connection=False),
detector_stage: DetectorMotion = i24.detector_motion(wait_for_connection=False),
shutter: HutchShutter = i24.shutter(wait_for_connection=False),
dcm: DCM = i24.dcm(wait_for_connection=False),
) -> MsgGenerator:
setup_logging()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import numpy as np
from blueapi.core import MsgGenerator
from dodal.beamlines import i24
from dodal.common import inject
from dodal.devices.i24.beamstop import Beamstop, BeamstopPositions
from dodal.devices.i24.dual_backlight import BacklightPositions, DualBacklight
from dodal.devices.i24.i24_detector_motion import DetectorMotion
Expand Down Expand Up @@ -73,7 +72,7 @@ def setup_logging():

@log.log_on_entry
def initialise_stages(
pmac: PMAC = inject("pmac"),
pmac: PMAC = i24.pmac(wait_for_connection=False),
) -> MsgGenerator:
"""Initialise the portable stages PVs, usually used only once right after setting \
up the stages either after use at different facility.
Expand Down Expand Up @@ -210,7 +209,7 @@ def scrape_pvar_file(fid: str, pvar_dir: Path = PVAR_FILE_PATH):
@log.log_on_entry
def define_current_chip(
chipid: str = "oxford",
pmac: PMAC = inject("pmac"),
pmac: PMAC = i24.pmac(wait_for_connection=False),
) -> MsgGenerator:
setup_logging()
logger.debug("Run load stock map for just the first block")
Expand Down Expand Up @@ -255,7 +254,7 @@ def save_screen_map() -> MsgGenerator:


@log.log_on_entry
def upload_parameters(pmac: PMAC = inject("pmac")) -> MsgGenerator:
def upload_parameters(pmac: PMAC = i24.pmac(wait_for_connection=False)) -> MsgGenerator:
setup_logging()
logger.info("Uploading Parameters for Oxford Chip to the GeoBrick")
caput(CHIPTYPE_PV, 0)
Expand Down Expand Up @@ -606,7 +605,9 @@ def load_full_map() -> MsgGenerator:


@log.log_on_entry
def moveto(place: str = "origin", pmac: PMAC = inject("pmac")) -> MsgGenerator:
def moveto(
place: str = "origin", pmac: PMAC = i24.pmac(wait_for_connection=False)
) -> MsgGenerator:
setup_logging()
logger.info(f"Move to: {place}")
if place == Fiducials.zero:
Expand Down Expand Up @@ -634,10 +635,10 @@ def moveto(place: str = "origin", pmac: PMAC = inject("pmac")) -> MsgGenerator:
@log.log_on_entry
def moveto_preset(
place: str,
pmac: PMAC = inject("pmac"),
beamstop: Beamstop = inject("beamstop"),
backlight: DualBacklight = inject("backlight"),
det_stage: DetectorMotion = inject("detector_motion"),
pmac: PMAC = i24.pmac(wait_for_connection=False),
beamstop: Beamstop = i24.beamstop(wait_for_connection=False),
backlight: DualBacklight = i24.backlight(wait_for_connection=False),
det_stage: DetectorMotion = i24.detector_motion(wait_for_connection=False),
) -> MsgGenerator:
setup_logging()

Expand Down Expand Up @@ -671,7 +672,9 @@ def moveto_preset(


@log.log_on_entry
def laser_control(laser_setting: str, pmac: PMAC = inject("pmac")) -> MsgGenerator:
def laser_control(
laser_setting: str, pmac: PMAC = i24.pmac(wait_for_connection=False)
) -> MsgGenerator:
setup_logging()
logger.info(f"Move to: {laser_setting}")
if laser_setting == "laser1on": # these are in laser edm
Expand Down Expand Up @@ -731,7 +734,9 @@ def scrape_mtr_directions(motor_file_path: Path = CS_FILES_PATH):


@log.log_on_entry
def fiducial(point: int = 1, pmac: PMAC = inject("pmac")) -> MsgGenerator:
def fiducial(
point: int = 1, pmac: PMAC = i24.pmac(wait_for_connection=False)
) -> MsgGenerator:
setup_logging()
scale = 10000.0 # noqa: F841

Expand Down Expand Up @@ -770,7 +775,7 @@ def scrape_mtr_fiducials(


@log.log_on_entry
def cs_maker(pmac: PMAC = inject("pmac")) -> MsgGenerator:
def cs_maker(pmac: PMAC = i24.pmac(wait_for_connection=False)) -> MsgGenerator:
"""
Coordinate system.

Expand Down Expand Up @@ -930,7 +935,7 @@ def check_dir(val):
yield from bps.null()


def cs_reset(pmac: PMAC = inject("pmac")) -> MsgGenerator:
def cs_reset(pmac: PMAC = i24.pmac(wait_for_connection=False)) -> MsgGenerator:
"""Used to clear CS when using Custom Chip"""
setup_logging()
cs1 = "#1->10000X+0Y+0Z"
Expand Down Expand Up @@ -994,7 +999,7 @@ def pumpprobe_calc() -> MsgGenerator:


@log.log_on_entry
def block_check(pmac: PMAC = inject("pmac")) -> MsgGenerator:
def block_check(pmac: PMAC = i24.pmac(wait_for_connection=False)) -> MsgGenerator:
setup_logging()
# TODO See https://github.com/DiamondLightSource/mx_bluesky/issues/117
caput(pv.me14e_gp9, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import bluesky.plan_stubs as bps
from blueapi.core import MsgGenerator
from bluesky.utils import Msg
from dodal.common import inject
from dodal.beamlines import i24
from dodal.devices.i24.i24_detector_motion import DetectorMotion

from mx_bluesky.beamlines.i24.serial import log
Expand Down Expand Up @@ -92,7 +92,8 @@ def _get_requested_detector(det_type_pv: str) -> str:


def setup_detector_stage(
expt_type: SSXType, detector_stage: DetectorMotion = inject("detector_motion")
expt_type: SSXType,
detector_stage: DetectorMotion = i24.detector_motion(wait_for_connection=False),
) -> MsgGenerator:
setup_logging()
# Grab the correct PV depending on experiment
Expand Down
Loading