This repository was archived by the owner on Sep 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Add plan to do pin tip centring then xray centring #852
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
fa7a00f
(#499) Add an externally visible plan to pin tip centre then xray centre
DominicOram 4b0dd46
(#499) Move prepare data collection out of full_grid_scan_plan
DominicOram ddd8e44
(#499) Add parallel arming to pin tip then xray
DominicOram 11c7468
(#499) Set detector parameters before starting arming
DominicOram 328a365
(#499) Use a different OAVCentring file for full centring, which uses…
DominicOram 37e2ba0
(#499) Add fixes found in beamline testing
DominicOram 4d682e9
Merge branch 'main' into 499_full_centring_continued
DominicOram 0503e59
(#499) Add grid width to pin centre then xray centre
DominicOram 545709c
(#499) Use test OAV config files
DominicOram c78ba4b
(#499) Use test OAV config files again
DominicOram 327d5ce
(#499) Add type hint
DominicOram 080e6c1
(#499) Fixes after review
DominicOram 314e595
Merge branch 'main' into 499_full_centring_continued
DominicOram 10694ed
(#499) Fix merge issue
DominicOram File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| from unittest.mock import MagicMock | ||
|
|
||
| import pytest | ||
| from bluesky import RunEngine | ||
| from bluesky import plan_stubs as bps | ||
| from bluesky.run_engine import RunEngine | ||
| from dodal.beamlines import i03 | ||
|
|
||
| from artemis.device_setup_plans.utils import ( | ||
| start_preparing_data_collection_then_do_plan, | ||
| ) | ||
|
|
||
|
|
||
| def test_given_plan_raises_when_exception_raised_then_eiger_disarmed_and_correct_exception_returned(): | ||
| class TestException(Exception): | ||
| pass | ||
|
|
||
| def my_plan(): | ||
| yield from bps.null() | ||
| raise TestException() | ||
|
|
||
| eiger = i03.eiger(fake_with_ophyd_sim=True) | ||
| eiger.detector_params = MagicMock() | ||
| eiger.async_stage = MagicMock() | ||
| eiger.disarm_detector = MagicMock() | ||
|
|
||
| RE = RunEngine() | ||
|
|
||
| with pytest.raises(TestException): | ||
| RE( | ||
| start_preparing_data_collection_then_do_plan( | ||
| eiger, MagicMock(), 0.2, my_plan() | ||
| ) | ||
| ) | ||
|
|
||
| # Check detector was armed | ||
| eiger.async_stage.assert_called_once() | ||
|
|
||
| eiger.disarm_detector.assert_called_once() | ||
|
|
||
|
|
||
| def test_when_preparing_data_collection_then_transmission_set(): | ||
| def my_plan(): | ||
| yield from bps.null() | ||
|
|
||
| attenuator = MagicMock() | ||
| RE = RunEngine() | ||
|
|
||
| RE( | ||
| start_preparing_data_collection_then_do_plan( | ||
| MagicMock(), attenuator, 0.2, my_plan() | ||
| ) | ||
| ) | ||
|
|
||
| # Check transmission set | ||
| attenuator.set.assert_called_once_with(0.2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| from typing import Generator | ||
|
|
||
| from bluesky import plan_stubs as bps | ||
| from bluesky import preprocessors as bpp | ||
| from bluesky.utils import Msg | ||
| from dodal.devices.attenuator import Attenuator | ||
| from dodal.devices.eiger import EigerDetector | ||
|
|
||
|
|
||
| def start_preparing_data_collection_then_do_plan( | ||
| eiger: EigerDetector, | ||
| attenuator: Attenuator, | ||
| transmission_fraction: float, | ||
| plan_to_run: Generator[Msg, None, None], | ||
| group="ready_for_data_collection", | ||
| ) -> Generator[Msg, None, None]: | ||
| """Starts preparing for the next data collection by arming the eiger and setting the | ||
| transmission. Then runs the given plan. If the plan fails it will stop disarm the eiger. | ||
| """ | ||
| yield from bps.abs_set(eiger.do_arm, 1, group=group) | ||
| yield from bps.abs_set( | ||
| attenuator, | ||
| transmission_fraction, | ||
| group=group, | ||
| ) | ||
|
|
||
| yield from bpp.contingency_wrapper( | ||
| plan_to_run, | ||
| except_plan=lambda e: (yield from bps.stop(eiger)), | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
src/artemis/experiment_plans/pin_centre_then_xray_centre_plan.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import json | ||
|
|
||
| from blueapi.core import MsgGenerator | ||
| from dodal.beamlines import i03 | ||
| from dodal.devices.attenuator import Attenuator | ||
| from dodal.devices.eiger import EigerDetector | ||
| from dodal.devices.oav.oav_parameters import OAV_CONFIG_FILE_DEFAULTS, OAVParameters | ||
|
|
||
| from artemis.device_setup_plans.utils import ( | ||
| start_preparing_data_collection_then_do_plan, | ||
| ) | ||
| from artemis.experiment_plans.full_grid_scan_plan import ( | ||
| create_devices as full_grid_create_devices, | ||
| ) | ||
| from artemis.experiment_plans.full_grid_scan_plan import detect_grid_and_do_gridscan | ||
| from artemis.experiment_plans.pin_tip_centring_plan import ( | ||
| create_devices as pin_tip_create_devices, | ||
| ) | ||
| from artemis.experiment_plans.pin_tip_centring_plan import pin_tip_centre_plan | ||
| from artemis.log import LOGGER | ||
| from artemis.parameters.plan_specific.grid_scan_with_edge_detect_params import ( | ||
| GridScanWithEdgeDetectInternalParameters, | ||
| ) | ||
| from artemis.parameters.plan_specific.pin_centre_then_xray_centre_params import ( | ||
| PinCentreThenXrayCentreInternalParameters, | ||
| ) | ||
|
|
||
|
|
||
| def create_devices(): | ||
| full_grid_create_devices() | ||
| pin_tip_create_devices() | ||
|
|
||
|
|
||
| def create_parameters_for_grid_detection( | ||
| pin_centre_parameters: PinCentreThenXrayCentreInternalParameters, | ||
| ) -> GridScanWithEdgeDetectInternalParameters: | ||
| params_json = json.loads(pin_centre_parameters.json()) | ||
| grid_detect_and_xray_centre = GridScanWithEdgeDetectInternalParameters( | ||
| **params_json | ||
| ) | ||
| LOGGER.info( | ||
| f"Parameters for grid detect and xray centre: {grid_detect_and_xray_centre}" | ||
| ) | ||
| return grid_detect_and_xray_centre | ||
|
|
||
|
|
||
| def pin_centre_then_xray_centre_plan( | ||
| parameters: PinCentreThenXrayCentreInternalParameters, | ||
| oav_config_files=OAV_CONFIG_FILE_DEFAULTS, | ||
| ): | ||
| """Plan that perfoms a pin tip centre followed by an xray centre to completely | ||
| centre the sample""" | ||
| oav_config_files["oav_config_json"] = parameters.experiment_params.oav_centring_file | ||
|
|
||
| yield from pin_tip_centre_plan( | ||
| parameters.experiment_params.tip_offset_microns, oav_config_files | ||
| ) | ||
| grid_detect_params = create_parameters_for_grid_detection(parameters) | ||
|
|
||
| backlight = i03.backlight() | ||
| aperture_scattergaurd = i03.aperture_scatterguard() | ||
| detector_motion = i03.detector_motion() | ||
|
DominicOram marked this conversation as resolved.
|
||
| oav_params = OAVParameters("xrayCentring", **oav_config_files) | ||
|
|
||
| yield from detect_grid_and_do_gridscan( | ||
| grid_detect_params, | ||
| backlight, | ||
| aperture_scattergaurd, | ||
| detector_motion, | ||
| oav_params, | ||
| ) | ||
|
|
||
|
|
||
| def pin_tip_centre_then_xray_centre( | ||
| parameters: PinCentreThenXrayCentreInternalParameters, | ||
| ) -> MsgGenerator: | ||
| """Starts preparing for collection then performs the pin tip centre and xray centre""" | ||
|
|
||
| eiger: EigerDetector = i03.eiger() | ||
| attenuator: Attenuator = i03.attenuator() | ||
|
|
||
| eiger.set_detector_parameters(parameters.artemis_params.detector_params) | ||
|
|
||
| return start_preparing_data_collection_then_do_plan( | ||
| eiger, | ||
| attenuator, | ||
| parameters.artemis_params.ispyb_params.transmission_fraction, | ||
| pin_centre_then_xray_centre_plan(parameters), | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.