Skip to content

Commit

Permalink
Merge branch 'main' into 117_use-blueapi-abort
Browse files Browse the repository at this point in the history
  • Loading branch information
noemifrisina committed Jul 19, 2024
2 parents 8317a53 + 333a3ba commit 5bf69f5
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from dodal.devices.hutch_shutter import HutchShutter, ShutterDemand
from dodal.devices.i24.aperture import Aperture
from dodal.devices.i24.beamstop import Beamstop
from dodal.devices.i24.dcm import DCM
from dodal.devices.i24.dual_backlight import DualBacklight
from dodal.devices.i24.I24_detector_motion import DetectorMotion
from dodal.devices.zebra import DISCONNECT, SOFT_IN3, Zebra
Expand Down Expand Up @@ -192,6 +193,7 @@ def main_extruder_plan(
beamstop: Beamstop,
detector_stage: DetectorMotion,
shutter: HutchShutter,
dcm: DCM,
parameters: ExtruderParameters,
dcid: DCID,
start_time: datetime,
Expand Down Expand Up @@ -359,8 +361,9 @@ def main_extruder_plan(
dcid.notify_start()

if parameters.detector_name == "eiger":
wavelength = yield from bps.rd(dcm.wavelength_in_a)
logger.debug("Call nexgen server for nexus writing.")
call_nexgen(None, start_time, parameters, "extruder")
call_nexgen(None, start_time, parameters, wavelength, "extruder")

timeout_time = time.time() + parameters.num_images * parameters.exposure_time_s + 10

Expand Down Expand Up @@ -456,6 +459,7 @@ def run_extruder_plan(
beamstop: Beamstop = inject("beamstop"),
detector_stage: DetectorMotion = inject("detector_motion"),
shutter: HutchShutter = inject("shutter"),
dcm: DCM = inject("dcm"),
) -> MsgGenerator:
setup_logging()
start_time = datetime.now()
Expand All @@ -480,6 +484,7 @@ def run_extruder_plan(
detector_stage,
shutter,
parameters,
dcm,
dcid,
start_time,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from dodal.devices.hutch_shutter import HutchShutter, ShutterDemand
from dodal.devices.i24.aperture import Aperture
from dodal.devices.i24.beamstop import Beamstop
from dodal.devices.i24.dcm import DCM
from dodal.devices.i24.dual_backlight import DualBacklight
from dodal.devices.i24.I24_detector_motion import DetectorMotion
from dodal.devices.i24.pmac import PMAC
Expand Down Expand Up @@ -534,13 +535,14 @@ def finish_i24(
zebra: Zebra,
pmac: PMAC,
shutter: HutchShutter,
dcm: DCM,
parameters: FixedTargetParameters,
):
logger.info(f"Finish I24 data collection with {parameters.detector_name} detector.")

complete_filename: str
transmission = float(caget(pv.pilat_filtertrasm))
wavelength = float(caget(pv.dcm_lambda))
wavelength = yield from bps.rd(dcm.wavelength_in_a)

if parameters.detector_name == "pilatus":
logger.debug("Finish I24 Pilatus")
Expand Down Expand Up @@ -592,6 +594,7 @@ def main_fixed_target_plan(
beamstop: Beamstop,
detector_stage: DetectorMotion,
shutter: HutchShutter,
dcm: DCM,
parameters: FixedTargetParameters,
dcid: DCID,
) -> MsgGenerator:
Expand Down Expand Up @@ -642,6 +645,7 @@ def main_fixed_target_plan(
logger.debug("Notify DCID of the start of the collection.")
dcid.notify_start() # NOTE This can bo before run_program

wavelength = yield from bps.rd(dcm.wavelength_in_a)
if parameters.detector_name == "eiger":
# TODO can be moved before prog_num once
# https://github.com/DiamondLightSource/nexgen/issues/266 is done
Expand All @@ -650,6 +654,7 @@ def main_fixed_target_plan(
chip_prog_dict,
start_time,
parameters,
wavelength,
)

logger.info(f"Run PMAC with program number {prog_num}")
Expand Down Expand Up @@ -696,6 +701,7 @@ def tidy_up_after_collection_plan(
zebra: Zebra,
pmac: PMAC,
shutter: HutchShutter,
dcm: DCM,
parameters: FixedTargetParameters,
dcid: DCID,
) -> MsgGenerator:
Expand All @@ -716,7 +722,7 @@ def tidy_up_after_collection_plan(
caput(pv.eiger_acquire, 0)
caput(pv.eiger_ODcapture, "Done")

end_time = yield from finish_i24(zebra, pmac, shutter, parameters)
end_time = yield from finish_i24(zebra, pmac, shutter, dcm, parameters)

dcid.collection_complete(end_time, aborted=ABORTED)
logger.debug("Notify DCID of end of collection.")
Expand All @@ -734,6 +740,7 @@ def run_fixed_target_plan(
beamstop: Beamstop = inject("beamstop"),
detector_stage: DetectorMotion = inject("detector_motion"),
shutter: HutchShutter = inject("shutter"),
dcm: DCM = inject("dcm"),
) -> MsgGenerator:
setup_logging()

Expand Down Expand Up @@ -774,13 +781,14 @@ def run_fixed_target_plan(
beamstop,
detector_stage,
shutter,
dcm,
parameters,
dcid,
),
except_plan=lambda e: (yield from run_aborted_plan(pmac)),
final_plan=lambda: (
yield from tidy_up_after_collection_plan(
zebra, pmac, shutter, parameters, dcid
zebra, pmac, shutter, dcm, parameters, dcid
)
),
auto_raise=False,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
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
from dodal.devices.i24.pmac import PMAC, EncReset, LaserSettings

Expand Down Expand Up @@ -626,7 +628,13 @@ def moveto(place: str = "origin", pmac: PMAC = inject("pmac")) -> MsgGenerator:


@log.log_on_entry
def moveto_preset(place: str, pmac: PMAC = inject("pmac")) -> MsgGenerator:
def moveto_preset(
place: str,
pmac: PMAC = inject("pmac"),
beamstop: Beamstop = inject("beamstop"),
backlight: DualBacklight = inject("backlight"),
det_stage: DetectorMotion = inject("detector_motion"),
) -> MsgGenerator:
setup_logging()

# Non Chip Specific Move
Expand All @@ -636,16 +644,22 @@ def moveto_preset(place: str, pmac: PMAC = inject("pmac")) -> MsgGenerator:

elif place == "load_position":
logger.info("load position")
caput(pv.bs_mp_select, "Robot")
caput(pv.bl_mp_select, "Out")
caput(pv.det_z, 1300)
yield from bps.abs_set(
beamstop.pos_select, BeamstopPositions.ROBOT, group=place
)
yield from bps.abs_set(backlight, BacklightPositions.OUT, group=place)
yield from bps.abs_set(det_stage.z, 1300, group=place)
yield from bps.wait(group=place)

elif place == "collect_position":
logger.info("collect position")
caput(pv.me14e_filter, 20)
yield from bps.mv(pmac.x, 0.0, pmac.y, 0.0, pmac.z, 0.0)
caput(pv.bs_mp_select, "Data Collection")
caput(pv.bl_mp_select, "In")
yield from bps.abs_set(
beamstop.pos_select, BeamstopPositions.DATA_COLLECTION, group=place
)
yield from bps.abs_set(backlight, BacklightPositions.IN, group=place)
yield from bps.wait(group=place)

elif place == "microdrop_position":
logger.info("microdrop align position")
Expand Down
7 changes: 0 additions & 7 deletions src/mx_bluesky/I24/serial/setup_beamline/pv.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,6 @@ def __which__():
dcm_lambda = "BL24I-MO-DCM-01:LAMBDA"
dcm_energy = "BL24I-MO-DCM-01:ENERGY"

# OLD Mono. Left for short term reference only 10Nov21
# dcm_bragg = 'BL24I-OP-DCM-01:BRAGG'
# dcm_t2 = 'BL24I-OP-DCM-01:T2'
# dcm_roll1 = 'BL24I-OP-DCM-01:ROLL1'
# dcm_pitch2 = 'BL24I-OP-DCM-01:PITCH2'
# dcm_lambda = 'BL24I-OP-DCM-01:LAMBDA'
# dcm_energy = 'BL24I-OP-DCM-01:ENERGY'
# S2
s2_x_plus = "BL24I-AL-SLITS-02:X:PLUS"
s2_x_minus = "BL24I-AL-SLITS-02:X:MINUS"
Expand Down
3 changes: 3 additions & 0 deletions src/mx_bluesky/I24/serial/setup_beamline/pv_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Takes the PV tables from I24's setup_beamline and wraps a slightly more
abstract wrapper around them.
"""

from typing import Union

from mx_bluesky.I24.serial.setup_beamline import pv
Expand Down Expand Up @@ -56,12 +57,14 @@ class pv:
detector_distance = pv.eiger_detdist
wavelength = pv.eiger_wavelength
transmission = "BL24I-EA-PILAT-01:cam1:FilterTransm"
filenameRBV = pv.eiger_ODfilenameRBV
file_name = pv.eiger_ODfilename
file_path = pv.eiger_ODfilepath
file_template = None
sequence_id = pv.eiger_seqID
beamx = pv.eiger_beamx
beamy = pv.eiger_beamy
bit_depth = pv.eiger_bitdepthrbv

def __str__(self) -> str:
return self.name
Expand Down
16 changes: 8 additions & 8 deletions src/mx_bluesky/I24/serial/write_nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@

from mx_bluesky.I24.serial.fixed_target.ft_utils import ChipType, MappingType
from mx_bluesky.I24.serial.parameters import ExtruderParameters, FixedTargetParameters
from mx_bluesky.I24.serial.setup_beamline import Eiger, caget, cagetstring, pv
from mx_bluesky.I24.serial.setup_beamline import Eiger, caget, cagetstring

logger = logging.getLogger("I24ssx.nexus_writer")


def call_nexgen(
chip_prog_dict: Dict,
chip_prog_dict: Dict | None,
start_time: datetime,
parameters: ExtruderParameters | FixedTargetParameters,
wavelength: float,
expt_type: Literal["fixed-target", "extruder"] = "fixed-target",
):
det_type = parameters.detector_name
Expand All @@ -42,7 +43,7 @@ def call_nexgen(
currentchipmap = None
pump_status = parameters.pump_status

filename_prefix = cagetstring(pv.eiger_ODfilenameRBV)
filename_prefix = cagetstring(Eiger.pv.filenameRBV)
meta_h5 = (
pathlib.Path(parameters.visit)
/ parameters.directory
Expand All @@ -62,11 +63,10 @@ def call_nexgen(
logger.warning(f"Giving up waiting for {meta_h5} after {max_wait} seconds")
return False

transmission = (float(caget(pv.pilat_filtertrasm)),)
wavelength = float(caget(pv.dcm_lambda))
transmission = (float(caget(Eiger.pv.transmission)),)

if det_type == Eiger.name:
bit_depth = int(caget(pv.eiger_bitdepthrbv))
bit_depth = int(caget(Eiger.pv.bit_depth))
logger.debug(
f"Call to nexgen server with the following chip definition: \n{chip_prog_dict}"
)
Expand All @@ -77,7 +77,7 @@ def call_nexgen(

payload = {
"beamline": "i24",
"beam_center": [caget(pv.eiger_beamx), caget(pv.eiger_beamy)],
"beam_center": [caget(Eiger.pv.beamx), caget(Eiger.pv.beamy)],
"chipmap": currentchipmap,
"chip_info": chip_prog_dict,
"det_dist": parameters.detector_distance_mm,
Expand All @@ -91,7 +91,7 @@ def call_nexgen(
"transmission": transmission[0],
"visitpath": os.fspath(meta_h5.parent),
"wavelength": wavelength,
"bit_depth": bit_depth, # NOTE requires nexgen-server to use nexgen>=0.9.4
"bit_depth": bit_depth,
}
logger.info(f"Sending POST request to {url} with payload:")
logger.info(pprint.pformat(payload))
Expand Down
7 changes: 7 additions & 0 deletions tests/I24/serial/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
)
from dodal.devices.i24.aperture import Aperture
from dodal.devices.i24.beamstop import Beamstop
from dodal.devices.i24.dcm import DCM
from dodal.devices.i24.dual_backlight import DualBacklight
from dodal.devices.i24.pmac import PMAC
from dodal.devices.zebra import Zebra
Expand Down Expand Up @@ -118,3 +119,9 @@ def pmac(RE):
patch_motor(pmac.z),
):
yield pmac


@pytest.fixture
def dcm(RE) -> DCM:
dcm = i24.dcm(fake_with_ophyd_sim=True)
return dcm
8 changes: 6 additions & 2 deletions tests/I24/serial/extruder/test_extruder_collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,12 @@ def test_run_extruder_quickshot_with_eiger(
backlight,
beamstop,
detector_stage,
dcm,
dummy_params,
):
fake_start_time = MagicMock()
# Mock end of data collection (zebra disarmed)
fake_read.side_effect = [fake_generator(0)]
fake_read.side_effect = [fake_generator(0.6), fake_generator(0)]
RE(
main_extruder_plan(
zebra,
Expand All @@ -154,12 +155,13 @@ def test_run_extruder_quickshot_with_eiger(
beamstop,
detector_stage,
shutter,
dcm,
dummy_params,
fake_dcid,
fake_start_time,
)
)
assert fake_nexgen.call_count == 1
fake_nexgen.assert_called_once_with(None, ANY, dummy_params, 0.6, "extruder")
assert fake_dcid.generate_dcid.call_count == 1
assert fake_dcid.notify_start.call_count == 1
assert fake_sup.setup_beamline_for_collection_plan.call_count == 1
Expand Down Expand Up @@ -194,6 +196,7 @@ def test_run_extruder_pump_probe_with_pilatus(
backlight,
beamstop,
detector_stage,
dcm,
dummy_params_pp,
):
fake_start_time = MagicMock()
Expand All @@ -207,6 +210,7 @@ def test_run_extruder_pump_probe_with_pilatus(
beamstop,
detector_stage,
shutter,
dcm,
dummy_params_pp,
fake_dcid,
fake_start_time,
Expand Down
Loading

0 comments on commit 5bf69f5

Please sign in to comment.