From 8b679457bee1064bf76ea4c96ade50f0c0a9fe30 Mon Sep 17 00:00:00 2001 From: Dominic Oram Date: Tue, 18 Jul 2023 17:32:35 +0100 Subject: [PATCH 1/3] (#810) Fix use of class variables --- src/artemis/__main__.py | 6 ++- .../callbacks/aperture_change_callback.py | 4 +- .../callbacks/fgs/ispyb_callback.py | 4 +- .../callbacks/oav_snapshot_callback.py | 7 +-- .../external_interaction/nexus/write_nexus.py | 51 ++++++++----------- .../zocalo/zocalo_interaction.py | 4 +- 6 files changed, 33 insertions(+), 43 deletions(-) diff --git a/src/artemis/__main__.py b/src/artemis/__main__.py index 47fa7338e..d0e978c55 100755 --- a/src/artemis/__main__.py +++ b/src/artemis/__main__.py @@ -60,6 +60,8 @@ class BlueskyRunner: current_status: StatusAndMessage = StatusAndMessage(Status.IDLE) last_run_aborted: bool = False aperture_change_callback = ApertureChangeCallback() + RE: RunEngine + skip_startup_connection: bool def __init__(self, RE: RunEngine, skip_startup_connection=False) -> None: self.RE = RE @@ -147,7 +149,7 @@ def wait_on_queue(self): class RunExperiment(Resource): def __init__(self, runner: BlueskyRunner) -> None: super().__init__() - self.runner = runner + self.runner: BlueskyRunner = runner def put(self, plan_name: str, action: Actions): status_and_message = StatusAndMessage(Status.FAILED, f"{action} not understood") @@ -195,7 +197,7 @@ def put(self, plan_name: str, action: Actions): class StopOrStatus(Resource): def __init__(self, runner: BlueskyRunner) -> None: super().__init__() - self.runner = runner + self.runner: BlueskyRunner = runner def put(self, action): status_and_message = StatusAndMessage(Status.FAILED, f"{action} not understood") diff --git a/src/artemis/external_interaction/callbacks/aperture_change_callback.py b/src/artemis/external_interaction/callbacks/aperture_change_callback.py index ab265a538..4c6be229d 100644 --- a/src/artemis/external_interaction/callbacks/aperture_change_callback.py +++ b/src/artemis/external_interaction/callbacks/aperture_change_callback.py @@ -4,7 +4,9 @@ class ApertureChangeCallback(CallbackBase): - last_selected_aperture: str = "NONE" + def __init__(self, *args, **kwargs) -> None: + super().__init__(*args, **kwargs) + self.last_selected_aperture: str = "NONE" def start(self, doc: dict): if doc.get("subplan_name") == "change_aperture": diff --git a/src/artemis/external_interaction/callbacks/fgs/ispyb_callback.py b/src/artemis/external_interaction/callbacks/fgs/ispyb_callback.py index c612ec3c3..9c3de9bd8 100644 --- a/src/artemis/external_interaction/callbacks/fgs/ispyb_callback.py +++ b/src/artemis/external_interaction/callbacks/fgs/ispyb_callback.py @@ -1,7 +1,7 @@ from __future__ import annotations import os -from typing import Dict +from typing import Dict, Optional from bluesky.callbacks import CallbackBase @@ -48,7 +48,7 @@ def __init__(self, parameters: FGSInternalParameters): else StoreInIspyb2D(ispyb_config, self.params) ) self.ispyb_ids: tuple = (None, None, None) - self.uid_to_finalize_on = None + self.uid_to_finalize_on: Optional[str] = None def append_to_comment(self, comment: str): try: diff --git a/src/artemis/external_interaction/callbacks/oav_snapshot_callback.py b/src/artemis/external_interaction/callbacks/oav_snapshot_callback.py index 51354b8eb..7c4bce247 100644 --- a/src/artemis/external_interaction/callbacks/oav_snapshot_callback.py +++ b/src/artemis/external_interaction/callbacks/oav_snapshot_callback.py @@ -2,13 +2,10 @@ class OavSnapshotCallback(CallbackBase): - snapshot_filenames: list - out_upper_left: list - def __init__(self, *args) -> None: super().__init__(*args) - self.snapshot_filenames = [] - self.out_upper_left = [] + self.snapshot_filenames: list = [] + self.out_upper_left: list = [] def event(self, doc): data = doc.get("data") diff --git a/src/artemis/external_interaction/nexus/write_nexus.py b/src/artemis/external_interaction/nexus/write_nexus.py index f9ffbecc1..be9692e80 100644 --- a/src/artemis/external_interaction/nexus/write_nexus.py +++ b/src/artemis/external_interaction/nexus/write_nexus.py @@ -10,7 +10,7 @@ import h5py import numpy as np -from nexgen.nxs_utils import Attenuator, Beam, Detector, Goniometer, Source +from nexgen.nxs_utils import Detector, Goniometer, Source from nexgen.nxs_write.NXmxWriter import NXmxFileWriter from artemis.external_interaction.nexus.nexus_utils import ( @@ -23,21 +23,6 @@ class NexusWriter: - detector: Detector - source: Source - beam: Beam - attenuator: Attenuator - goniometer: Goniometer - directory: Path - start_index: int - full_num_of_images: int - nexus_file: Path - master_file: Path - scan_points: dict - data_shape: tuple[int, int, int] - omega_start: float - run_number: int - def __init__( self, parameters: InternalParameters, @@ -47,38 +32,44 @@ def __init__( run_number: int | None = None, vds_start_index: int = 0, ) -> None: - self.scan_points = scan_points - self.data_shape = data_shape - self.omega_start = ( + self.scan_points: dict = scan_points + self.data_shape: tuple[int, int, int] = data_shape + self.omega_start: float = ( omega_start if omega_start else parameters.artemis_params.detector_params.omega_start ) - self.run_number = ( + self.run_number: int = ( run_number if run_number else parameters.artemis_params.detector_params.run_number ) - self.detector = create_detector_parameters( + self.detector: Detector = create_detector_parameters( parameters.artemis_params.detector_params ) self.beam, self.attenuator = create_beam_and_attenuator_parameters( parameters.artemis_params.ispyb_params ) - self.source = Source(parameters.artemis_params.beamline) - self.directory = Path(parameters.artemis_params.detector_params.directory) - self.filename = parameters.artemis_params.detector_params.prefix - self.start_index = vds_start_index - self.full_num_of_images = ( + self.source: Source = Source(parameters.artemis_params.beamline) + self.directory: Path = Path(parameters.artemis_params.detector_params.directory) + self.filename: str = parameters.artemis_params.detector_params.prefix + self.start_index: int = vds_start_index + self.full_num_of_images: int = ( parameters.artemis_params.detector_params.num_triggers * parameters.artemis_params.detector_params.num_images_per_trigger ) - self.full_filename = parameters.artemis_params.detector_params.full_filename - self.nexus_file = self.directory / f"{self.filename}_{self.run_number}.nxs" - self.master_file = ( + self.full_filename: str = ( + parameters.artemis_params.detector_params.full_filename + ) + self.nexus_file: Path = ( + self.directory / f"{self.filename}_{self.run_number}.nxs" + ) + self.master_file: Path = ( self.directory / f"{self.filename}_{self.run_number}_master.h5" ) - self.goniometer = create_goniometer_axes(self.omega_start, self.scan_points) + self.goniometer: Goniometer = create_goniometer_axes( + self.omega_start, self.scan_points + ) def create_nexus_file(self): """ diff --git a/src/artemis/external_interaction/zocalo/zocalo_interaction.py b/src/artemis/external_interaction/zocalo/zocalo_interaction.py index ad2be249b..6e9888176 100644 --- a/src/artemis/external_interaction/zocalo/zocalo_interaction.py +++ b/src/artemis/external_interaction/zocalo/zocalo_interaction.py @@ -22,10 +22,8 @@ class NoDiffractionFound(WarningException): class ZocaloInteractor: - zocalo_environment: str = "artemis" - def __init__(self, environment: str = "artemis"): - self.zocalo_environment = environment + self.zocalo_environment: str = environment def _get_zocalo_connection(self): zc = zocalo.configuration.from_file() From c79644cf0eb3698ab7f5b3069c06e18e2024c43e Mon Sep 17 00:00:00 2001 From: Dominic Oram Date: Tue, 18 Jul 2023 17:33:25 +0100 Subject: [PATCH 2/3] Update dodal --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 9d00cf070..1d6a6d5c3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -36,7 +36,7 @@ install_requires = xarray doct databroker - dodal @ git+https://github.com/DiamondLightSource/python-dodal.git@b625b9e3abadc26b095e72701a008795f0c680c0 + dodal @ git+https://github.com/DiamondLightSource/python-dodal.git@36e0efe08f7a741796654bb07119595f9bab3411 pydantic<2.0 # See https://github.com/DiamondLightSource/python-artemis/issues/774 From 84fc1a8eea9c04e8797d262e2cd7974bc5c83c74 Mon Sep 17 00:00:00 2001 From: Dominic Oram Date: Thu, 3 Aug 2023 08:48:05 +0100 Subject: [PATCH 3/3] (#810) Remove class variables from FGSComposite --- .../experiment_plans/fast_grid_scan_plan.py | 36 +++++++------------ 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/src/artemis/experiment_plans/fast_grid_scan_plan.py b/src/artemis/experiment_plans/fast_grid_scan_plan.py index 0a04a5c88..21bde8625 100755 --- a/src/artemis/experiment_plans/fast_grid_scan_plan.py +++ b/src/artemis/experiment_plans/fast_grid_scan_plan.py @@ -53,37 +53,27 @@ class FGSComposite: """A container for all the Devices required for a fast gridscan.""" - aperture_scatterguard: ApertureScatterguard - backlight: Backlight - eiger: EigerDetector - fast_grid_scan: FastGridScan - flux: Flux - s4_slit_gaps: S4SlitGaps - sample_motors: Smargon - synchrotron: Synchrotron - undulator: Undulator - zebra: Zebra - attenuator: Attenuator - def __init__( self, aperture_positions: AperturePositions = None, detector_params: DetectorParams = None, fake: bool = False, ): - self.aperture_scatterguard = i03.aperture_scatterguard( + self.aperture_scatterguard: ApertureScatterguard = i03.aperture_scatterguard( fake_with_ophyd_sim=fake, aperture_positions=aperture_positions ) - self.backlight = i03.backlight(fake_with_ophyd_sim=fake) - self.eiger = i03.eiger(fake_with_ophyd_sim=fake, params=detector_params) - self.fast_grid_scan = i03.fast_grid_scan(fake_with_ophyd_sim=fake) - self.flux = i03.flux(fake_with_ophyd_sim=fake) - self.s4_slit_gaps = i03.s4_slit_gaps(fake_with_ophyd_sim=fake) - self.sample_motors = i03.smargon(fake_with_ophyd_sim=fake) - self.undulator = i03.undulator(fake_with_ophyd_sim=fake) - self.synchrotron = i03.synchrotron(fake_with_ophyd_sim=fake) - self.zebra = i03.zebra(fake_with_ophyd_sim=fake) - self.attenuator = i03.attenuator(fake_with_ophyd_sim=fake) + self.backlight: Backlight = i03.backlight(fake_with_ophyd_sim=fake) + self.eiger: EigerDetector = i03.eiger( + fake_with_ophyd_sim=fake, params=detector_params + ) + self.fast_grid_scan: FastGridScan = i03.fast_grid_scan(fake_with_ophyd_sim=fake) + self.flux: Flux = i03.flux(fake_with_ophyd_sim=fake) + self.s4_slit_gaps: S4SlitGaps = i03.s4_slit_gaps(fake_with_ophyd_sim=fake) + self.sample_motors: Smargon = i03.smargon(fake_with_ophyd_sim=fake) + self.undulator: Synchrotron = i03.undulator(fake_with_ophyd_sim=fake) + self.synchrotron: Undulator = i03.synchrotron(fake_with_ophyd_sim=fake) + self.zebra: Zebra = i03.zebra(fake_with_ophyd_sim=fake) + self.attenuator: Attenuator = i03.attenuator(fake_with_ophyd_sim=fake) fast_grid_scan_composite: FGSComposite | None = None