Skip to content

Commit

Permalink
Merge branch 'main' into 618_aperture_selection_based_on_real_box_size
Browse files Browse the repository at this point in the history
  • Loading branch information
shihab-dls authored Jan 8, 2025
2 parents 9466d59 + fc9a053 commit 50b0ff6
Show file tree
Hide file tree
Showing 46 changed files with 649 additions and 298 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,6 @@ edm_serial/
**/parameters/fixed_target/*/*.map
# idea project files
.idea/

# Generated PlantUML diagrams
docs/developer/hyperion/reference/param_hierarchy.puml
7 changes: 1 addition & 6 deletions docs/developer/hyperion/reference/param-hierarchy.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
Hyperion Parameter class hierarchy
==================================

TODO: automate including the param hierarchy here

How Gridscan Parameters are Obtained
------------------------------------

.. uml:: gridscan.puml
.. uml:: param_hierarchy.puml
86 changes: 0 additions & 86 deletions docs/developer/hyperion/reference/param_hierarchy.puml

This file was deleted.

6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dependencies = [
"ophyd == 1.9.0",
"ophyd-async >= 0.8a5",
"bluesky >= 1.13.0a4",
"dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@00858ea059bb147c04fdc51a478bd2674ca4ea00",
"dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@e6ad77ee5aa489d0035918e45a28a0d6f72b19ed",
]


Expand Down Expand Up @@ -79,7 +79,6 @@ dev = [
"ruff",
"sphinx-autobuild",
"sphinx-copybutton",
"sphinxcontrib-plantuml",
"sphinx-design",
"tox-direct",
"tox",
Expand Down Expand Up @@ -181,6 +180,9 @@ commands =
type-checking: pyright src tests {posargs}
tests: pytest --cov=mx_bluesky --cov-report term --cov-report xml:cov.xml {posargs}
docs: sphinx-{posargs:build -EW --keep-going} -T docs build/html
commands_pre =
docs: /usr/bin/bash -c "{toxinidir}/utility_scripts/generate_plantuml.py > \
docs/developer/hyperion/reference/param_hierarchy.puml"
"""

[tool.ruff]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import bluesky.preprocessors as bpp
from bluesky.utils import MsgGenerator
from dodal.common import inject
from dodal.devices.attenuator import ReadOnlyAttenuator
from dodal.devices.attenuator.attenuator import ReadOnlyAttenuator
from dodal.devices.hutch_shutter import HutchShutter, ShutterDemand
from dodal.devices.i24.aperture import Aperture
from dodal.devices.i24.beam_center import DetectorBeamCenter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import bluesky.preprocessors as bpp
from bluesky.utils import MsgGenerator
from dodal.common import inject
from dodal.devices.attenuator import ReadOnlyAttenuator
from dodal.devices.attenuator.attenuator import ReadOnlyAttenuator
from dodal.devices.hutch_shutter import HutchShutter, ShutterDemand
from dodal.devices.i24.aperture import Aperture
from dodal.devices.i24.beam_center import DetectorBeamCenter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import numpy as np
from bluesky.utils import MsgGenerator
from dodal.common import inject
from dodal.devices.attenuator import ReadOnlyAttenuator
from dodal.devices.attenuator.attenuator import ReadOnlyAttenuator
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
27 changes: 27 additions & 0 deletions src/mx_bluesky/hyperion/device_setup_plans/check_beamstop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import bluesky.plan_stubs as bps
from dodal.devices.i03.beamstop import Beamstop, BeamstopPositions

from mx_bluesky.common.utils.log import LOGGER


class BeamstopException(Exception):
pass


def check_beamstop(beamstop: Beamstop):
"""
Check the current position of the beamstop to ensure it is in position for data collection
Args:
beamstop: The beamstop device
Raises:
BeamstopException: If the beamstop is in any other position than DATA_COLLECTION
"""
current_pos = yield from bps.rd(beamstop.selected_pos)
if current_pos != BeamstopPositions.DATA_COLLECTION:
LOGGER.info(f"Beamstop check failed: position {current_pos}")
raise BeamstopException(
f"Beamstop is not DATA_COLLECTION, current state is {current_pos}"
)

LOGGER.info("Beamstop check ok")
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import bluesky.plan_stubs as bps
from dodal.devices.aperturescatterguard import ApertureScatterguard
from dodal.devices.attenuator import Attenuator
from dodal.devices.attenuator.attenuator import BinaryFilterAttenuator
from dodal.devices.dcm import DCM
from dodal.devices.eiger import EigerDetector
from dodal.devices.flux import Flux
Expand Down Expand Up @@ -39,7 +39,7 @@ def read_hardware_pre_collection(

def read_hardware_during_collection(
aperture_scatterguard: ApertureScatterguard,
attenuator: Attenuator,
attenuator: BinaryFilterAttenuator,
flux: Flux,
dcm: DCM,
detector: EigerDetector,
Expand Down
4 changes: 4 additions & 0 deletions src/mx_bluesky/hyperion/device_setup_plans/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
)
from dodal.devices.detector.detector_motion import DetectorMotion, ShutterState
from dodal.devices.eiger import EigerDetector
from dodal.devices.i03.beamstop import Beamstop

from mx_bluesky.hyperion.device_setup_plans.check_beamstop import check_beamstop
from mx_bluesky.hyperion.device_setup_plans.position_detector import (
set_detector_z_position,
set_shutter,
Expand All @@ -24,6 +26,7 @@ def fill_in_energy_if_not_supplied(dcm: DCM, detector_params: DetectorParams):


def start_preparing_data_collection_then_do_plan(
beamstop: Beamstop,
eiger: EigerDetector,
detector_motion: DetectorMotion,
detector_distance_mm: float | None,
Expand All @@ -49,6 +52,7 @@ def wrapped_plan():
yield from set_shutter(detector_motion, ShutterState.OPEN, group)
yield from plan_to_run

yield from check_beamstop(beamstop)
yield from bpp.contingency_wrapper(
wrapped_plan(),
except_plan=lambda e: (yield from bps.stop(eiger)), # type: ignore # See: https://github.com/bluesky/bluesky/issues/1809
Expand Down
14 changes: 7 additions & 7 deletions src/mx_bluesky/hyperion/device_setup_plans/xbpm_feedback.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from bluesky import plan_stubs as bps
from bluesky.preprocessors import finalize_wrapper
from bluesky.utils import make_decorator
from dodal.devices.attenuator import Attenuator
from dodal.devices.attenuator.attenuator import BinaryFilterAttenuator
from dodal.devices.xbpm_feedback import Pause, XBPMFeedback

from mx_bluesky.common.utils.log import LOGGER


def _check_and_pause_feedback(
xbpm_feedback: XBPMFeedback,
attenuator: Attenuator,
attenuator: BinaryFilterAttenuator,
desired_transmission_fraction: float,
):
"""Checks that the xbpm is in position before then turning it off and setting a new
Expand All @@ -18,7 +18,7 @@ def _check_and_pause_feedback(
Args:
xbpm_feedback (XBPMFeedback): The XBPM device that is responsible for keeping
the beam in position
attenuator (Attenuator): The attenuator used to set transmission
attenuator (BinaryFilterAttenuator): The attenuator used to set transmission
desired_transmission_fraction (float): The desired transmission to set after
turning XBPM feedback off.
Expand All @@ -34,23 +34,23 @@ def _check_and_pause_feedback(


def _unpause_xbpm_feedback_and_set_transmission_to_1(
xbpm_feedback: XBPMFeedback, attenuator: Attenuator
xbpm_feedback: XBPMFeedback, attenuator: BinaryFilterAttenuator
):
"""Turns the XBPM feedback back on and sets transmission to 1 so that it keeps the
beam aligned whilst not collecting.
Args:
xbpm_feedback (XBPMFeedback): The XBPM device that is responsible for keeping
the beam in position
attenuator (Attenuator): The attenuator used to set transmission
attenuator (BinaryFilterAttenuator): The attenuator used to set transmission
"""
yield from bps.mv(xbpm_feedback.pause_feedback, Pause.RUN, attenuator, 1.0) # type: ignore # See: https://github.com/bluesky/bluesky/issues/1809


def transmission_and_xbpm_feedback_for_collection_wrapper(
plan,
xbpm_feedback: XBPMFeedback,
attenuator: Attenuator,
attenuator: BinaryFilterAttenuator,
desired_transmission_fraction: float,
):
"""Sets the transmission for the data collection, ensuring the xbpm feedback is valid
Expand All @@ -70,7 +70,7 @@ def transmission_and_xbpm_feedback_for_collection_wrapper(
plan: The plan performing the data collection
xbpm_feedback (XBPMFeedback): The XBPM device that is responsible for keeping
the beam in position
attenuator (Attenuator): The attenuator used to set transmission
attenuator (BinaryFilterAttenuator): The attenuator used to set transmission
desired_transmission_fraction (float): The desired transmission for the collection
"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from dodal.devices.aperturescatterguard import (
ApertureScatterguard,
)
from dodal.devices.attenuator import Attenuator
from dodal.devices.attenuator.attenuator import BinaryFilterAttenuator
from dodal.devices.backlight import Backlight
from dodal.devices.dcm import DCM
from dodal.devices.eiger import EigerDetector
Expand Down Expand Up @@ -94,7 +94,7 @@ class FlyScanXRayCentreComposite:
"""All devices which are directly or indirectly required by this plan"""

aperture_scatterguard: ApertureScatterguard
attenuator: Attenuator
attenuator: BinaryFilterAttenuator
backlight: Backlight
dcm: DCM
eiger: EigerDetector
Expand All @@ -112,11 +112,6 @@ class FlyScanXRayCentreComposite:
robot: BartRobot
sample_shutter: ZebraShutter

@property
def sample_motors(self) -> Smargon:
"""Convenience alias with a more user-friendly name"""
return self.smargon


class XRayCentreEventHandler(CallbackBase):
def __init__(self):
Expand Down Expand Up @@ -225,16 +220,7 @@ def run_gridscan_and_fetch_results(
"""A multi-run plan which runs a gridscan, gets the results from zocalo
and fires an event with the centres of mass determined by zocalo"""

# We get the initial motor positions so we can return to them on zocalo failure
initial_xyz = np.array(
[
(yield from bps.rd(fgs_composite.sample_motors.x)),
(yield from bps.rd(fgs_composite.sample_motors.y)),
(yield from bps.rd(fgs_composite.sample_motors.z)),
]
)

yield from feature_controlled.setup_trigger(fgs_composite, parameters, initial_xyz)
yield from feature_controlled.setup_trigger(fgs_composite, parameters)

LOGGER.info("Starting grid scan")
yield from bps.stage(
Expand Down Expand Up @@ -331,11 +317,9 @@ def run_gridscan(
"plan_name": CONST.PLAN.GRIDSCAN_MAIN,
},
):
sample_motors = fgs_composite.sample_motors

# Currently gridscan only works for omega 0, see #
with TRACER.start_span("moving_omega_to_0"):
yield from bps.abs_set(sample_motors.omega, 0)
yield from bps.abs_set(fgs_composite.smargon.omega, 0)

# We only subscribe to the communicator callback for run_gridscan, so this is where
# we should generate an event reading the values which need to be included in the
Expand Down Expand Up @@ -408,7 +392,6 @@ def __call__(
self,
fgs_composite: FlyScanXRayCentreComposite,
parameters: HyperionThreeDGridScan,
initial_xyz: np.ndarray,
) -> MsgGenerator: ...

setup_trigger: _ExtraSetup
Expand Down Expand Up @@ -469,7 +452,6 @@ def _panda_tidy(fgs_composite: FlyScanXRayCentreComposite):
def _zebra_triggering_setup(
fgs_composite: FlyScanXRayCentreComposite,
parameters: HyperionThreeDGridScan,
initial_xyz: np.ndarray,
):
yield from setup_zebra_for_gridscan(
fgs_composite.zebra, fgs_composite.sample_shutter, wait=True
Expand All @@ -479,7 +461,6 @@ def _zebra_triggering_setup(
def _panda_triggering_setup(
fgs_composite: FlyScanXRayCentreComposite,
parameters: HyperionThreeDGridScan,
initial_xyz: np.ndarray,
):
LOGGER.info("Setting up Panda for flyscan")

Expand All @@ -492,6 +473,8 @@ def _panda_triggering_setup(

time_between_x_steps_ms = (DEADTIME_S + parameters.exposure_time_s) * 1e3

current_x = yield from bps.rd(fgs_composite.smargon.x.user_readback)

smargon_speed_limit_mm_per_s = yield from bps.rd(
fgs_composite.smargon.x.max_velocity
)
Expand Down Expand Up @@ -524,7 +507,7 @@ def _panda_triggering_setup(
yield from setup_panda_for_flyscan(
fgs_composite.panda,
parameters.panda_FGS_params,
initial_xyz[0],
current_x,
parameters.exposure_time_s,
time_between_x_steps_ms,
sample_velocity_mm_per_s,
Expand Down
Loading

0 comments on commit 50b0ff6

Please sign in to comment.