Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Clarify which transmission is which #1271

Merged
merged 8 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ install_requires =
xarray
doct
databroker
dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git
dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@7ab82c46eaefd5fd84650c5247405fe67ad8c504
pydantic<2.0 # See https://github.com/DiamondLightSource/hyperion/issues/774
scipy
pyzmq<25 # See https://github.com/DiamondLightSource/hyperion/issues/1103
Expand Down
4 changes: 2 additions & 2 deletions src/hyperion/experiment_plans/experiment_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from dodal.devices.fast_grid_scan import GridScanParams
from dodal.devices.panda_fast_grid_scan import PandAGridScanParams
from dodal.parameters.experiment_parameter_base import AbstractExperimentParameterBase
from dodal.parameters.experiment_parameter_base import AbstractExperimentWithBeamParams

import hyperion.experiment_plans.flyscan_xray_centre_plan as flyscan_xray_centre_plan
import hyperion.experiment_plans.panda_flyscan_xray_centre_plan as panda_flyscan_xray_centre_plan
Expand Down Expand Up @@ -65,7 +65,7 @@ class ExperimentRegistryEntry(TypedDict):
| WaitForRobotLoadThenCentreInternalParameters
| PandAGridscanInternalParameters
]
experiment_param_type: type[AbstractExperimentParameterBase]
experiment_param_type: type[AbstractExperimentWithBeamParams]
callback_collection_type: type[AbstractPlanCallbackCollection]


Expand Down
35 changes: 2 additions & 33 deletions src/hyperion/experiment_plans/flyscan_xray_centre_plan.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
from __future__ import annotations

import argparse
import dataclasses
from typing import TYPE_CHECKING, Any, List

import bluesky.plan_stubs as bps
import bluesky.preprocessors as bpp
import numpy as np
from blueapi.core import BlueskyContext, MsgGenerator
from bluesky.run_engine import RunEngine
from bluesky.utils import ProgressBarManager
from dodal.devices.aperturescatterguard import (
ApertureScatterguard,
SingleAperturePosition,
Expand Down Expand Up @@ -52,17 +49,13 @@
transmission_and_xbpm_feedback_for_collection_decorator,
)
from hyperion.exceptions import WarningException
from hyperion.external_interaction.callbacks.xray_centre.callback_collection import (
XrayCentreCallbackCollection,
)
from hyperion.log import LOGGER
from hyperion.parameters import external_parameters
from hyperion.parameters.constants import CONST
from hyperion.tracing import TRACER
from hyperion.utils.aperturescatterguard import (
load_default_aperture_scatterguard_positions_if_unset,
)
from hyperion.utils.context import device_composite_from_context, setup_context
from hyperion.utils.context import device_composite_from_context

if TYPE_CHECKING:
from hyperion.parameters.plan_specific.gridscan_internal_params import (
Expand Down Expand Up @@ -363,33 +356,9 @@ def flyscan_xray_centre(
@transmission_and_xbpm_feedback_for_collection_decorator(
composite.xbpm_feedback,
composite.attenuator,
parameters.hyperion_params.ispyb_params.transmission_fraction,
parameters.experiment_params.transmission_fraction,
)
def run_gridscan_and_move_and_tidy(fgs_composite, params):
yield from run_gridscan_and_move(fgs_composite, params)

return run_gridscan_and_move_and_tidy(composite, parameters)


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--beamline",
help="The beamline prefix this is being run on",
default=CONST.SIM.BEAMLINE,
)
args = parser.parse_args()

RE = RunEngine({})
RE.waiting_hook = ProgressBarManager() # type: ignore
from hyperion.parameters.plan_specific.gridscan_internal_params import (
GridscanInternalParameters,
)

parameters = GridscanInternalParameters(**external_parameters.conftest.from_file())
subscriptions = XrayCentreCallbackCollection()

context = setup_context(wait_for_connection=True)
composite = create_devices(context)

RE(flyscan_xray_centre(composite, parameters))
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def panda_flyscan_xray_centre(
@transmission_and_xbpm_feedback_for_collection_decorator(
composite.xbpm_feedback,
composite.attenuator,
parameters.hyperion_params.ispyb_params.transmission_fraction,
parameters.experiment_params.transmission_fraction,
)
def run_gridscan_and_move_and_tidy(fgs_composite, params):
yield from run_gridscan_and_move(fgs_composite, params)
Expand Down
2 changes: 1 addition & 1 deletion src/hyperion/experiment_plans/rotation_scan_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def rotation_with_cleanup_and_stage(params: RotationInternalParameters):
composite.detector_motion,
composite.backlight,
composite.attenuator,
params.hyperion_params.ispyb_params.transmission_fraction,
params.experiment_params.transmission_fraction,
params.hyperion_params.detector_params.detector_distance,
)
LOGGER.info("moving to position (if specified)")
Expand Down
2 changes: 1 addition & 1 deletion src/hyperion/experiment_plans/set_energy_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import dataclasses
from typing import Any, Generator

from bluesky import Msg
from bluesky import plan_stubs as bps
from bluesky.utils import Msg
from dodal.devices.attenuator import Attenuator
from dodal.devices.DCM import DCM
from dodal.devices.focusing_mirror import FocusingMirror, VFMMirrorVoltages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def event(self, doc: Event):

def get_grid_parameters(self) -> GridScanParams:
return GridScanParams(
transmission_fraction=0.01,
dwell_time_ms=self.exposure_time * 1000,
x_start=self.start_positions[0][0],
y1_start=self.start_positions[0][1],
Expand All @@ -80,6 +81,7 @@ def get_grid_parameters(self) -> GridScanParams:

def get_panda_grid_parameters(self) -> PandAGridScanParams:
return PandAGridScanParams(
transmission_fraction=0.01,
run_up_distance_mm=self.run_up_distance_mm,
x_start=self.start_positions[0][0],
y1_start=self.start_positions[0][1],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def activity_gated_event(self, doc: Event) -> Event:
return self._tag_doc(doc)

@abstractmethod
def update_deposition(self, params):
def update_deposition(self, params) -> IspybIds:
pass

def activity_gated_stop(self, doc: RunStop) -> Optional[RunStop]:
Expand Down
9 changes: 3 additions & 6 deletions src/hyperion/parameters/internal_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Any

from dodal.devices.eiger import DetectorParams
from dodal.parameters.experiment_parameter_base import AbstractExperimentParameterBase
from dodal.parameters.experiment_parameter_base import AbstractExperimentWithBeamParams
from pydantic import BaseModel, root_validator
from semver import Version

Expand Down Expand Up @@ -73,10 +73,7 @@ def extract_experiment_params_from_flat_dict(
experiment_param_class, flat_params: dict[str, Any]
):
# Use __fields__ to get inherited attributes from BaseModels
if issubclass(experiment_param_class, BaseModel):
experiment_field_keys = list(experiment_param_class.__fields__.keys())
else:
experiment_field_keys = list(experiment_param_class.__annotations__.keys())
experiment_field_keys = list(experiment_param_class.__fields__.keys())

experiment_params_args = fetch_subdict_from_bucket(
experiment_field_keys, flat_params
Expand Down Expand Up @@ -159,7 +156,7 @@ def _hyperion_param_key_definitions():
def _preprocess_experiment_params(
cls,
experiment_params: dict[str, Any],
) -> AbstractExperimentParameterBase: ...
) -> AbstractExperimentWithBeamParams: ...

@abstractmethod
def _preprocess_hyperion_params(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

import numpy as np
from dodal.devices.detector import TriggerMode
from dodal.parameters.experiment_parameter_base import AbstractExperimentParameterBase
from dodal.parameters.experiment_parameter_base import AbstractExperimentWithBeamParams
from pydantic import validator
from pydantic.dataclasses import dataclass

from hyperion.external_interaction.ispyb.ispyb_dataclass import GridscanIspybParams
from hyperion.parameters.internal_parameters import (
Expand All @@ -20,8 +19,7 @@
)


@dataclass
class GridScanWithEdgeDetectParams(AbstractExperimentParameterBase):
class GridScanWithEdgeDetectParams(AbstractExperimentWithBeamParams):
"""
Holder class for the parameters of a grid scan that uses edge detection to detect the grid.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

import numpy as np
from dodal.devices.detector import TriggerMode
from dodal.parameters.experiment_parameter_base import AbstractExperimentParameterBase
from dodal.parameters.experiment_parameter_base import AbstractExperimentWithBeamParams
from pydantic import validator
from pydantic.dataclasses import dataclass

from hyperion.external_interaction.ispyb.ispyb_dataclass import GridscanIspybParams
from hyperion.parameters.internal_parameters import (
Expand All @@ -20,8 +19,7 @@
)


@dataclass
class PinCentreThenXrayCentreParams(AbstractExperimentParameterBase):
class PinCentreThenXrayCentreParams(AbstractExperimentWithBeamParams):
"""
Holder class for the parameters of a plan that does a pin centre then xray centre
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from dodal.devices.detector import DetectorParams
from dodal.devices.motors import XYZLimitBundle
from dodal.devices.zebra import RotationDirection
from dodal.parameters.experiment_parameter_base import AbstractExperimentParameterBase
from pydantic import BaseModel, validator
from dodal.parameters.experiment_parameter_base import AbstractExperimentWithBeamParams
from pydantic import validator
from scanspec.core import Path as ScanPath
from scanspec.specs import Line

Expand Down Expand Up @@ -36,7 +36,7 @@ class Config:
}


class RotationScanParams(BaseModel, AbstractExperimentParameterBase):
class RotationScanParams(AbstractExperimentWithBeamParams):
"""
Holder class for the parameters of a rotation data collection.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

import numpy as np
from dodal.devices.detector import DetectorParams, TriggerMode
from dodal.parameters.experiment_parameter_base import AbstractExperimentParameterBase
from dodal.parameters.experiment_parameter_base import AbstractExperimentWithBeamParams
from pydantic import validator
from pydantic.dataclasses import dataclass

from hyperion.external_interaction.ispyb.ispyb_dataclass import (
GRIDSCAN_ISPYB_PARAM_DEFAULTS,
Expand All @@ -33,8 +32,7 @@ class Config:
}


@dataclass
class WaitForRobotLoadThenCentreParams(AbstractExperimentParameterBase):
class WaitForRobotLoadThenCentreParams(AbstractExperimentWithBeamParams):
"""
Holder class for the parameters of a plan that waits for robot load then does a
centre.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
"omega_start": {
"type": "number"
},
"transmission_fraction": {
"type": "number"
},
"set_stub_offsets": {
"type": "boolean"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
},
"use_panda": {
"type": "boolean"
},
"transmission_fraction": {
"type": "number"
}

},
"required": [
"exposure_time",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@
"set_stub_offsets": {
"type": "boolean"
},
"transmission_fraction": {
"type": "number"
},
"run_up_distance_mm": {
"type": "number"
}

},
"minProperties": 12,
"additionalProperties": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
},
"shutter_opening_time_s": {
"type": "number"
},
"transmission_fraction": {
"type": "number"
}
},
"required": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@
"type": "boolean"
},
"requested_energy_kev": {
"type": ["number", "null"]
"type": [
"number",
"null"
]
},
"use_panda": {
"type": "boolean"
},
"transmission_fraction": {
"type": "number"
}

},
"required": [
"exposure_time",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "object",
"properties": {
"params_version": {
"const": "4.0.4"
"const": "5.0.0"
},
"hyperion_params": {
"type": "object",
Expand Down
9 changes: 4 additions & 5 deletions src/hyperion/parameters/schemas/ispyb_parameters_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@
"type": "string"
}
},
"transmission_fraction": {
"type": "number"
},
"flux": {
"type": "number"
},
Expand Down Expand Up @@ -76,15 +73,17 @@
"type": "number"
},
"ispyb_experiment_type": {
"type": ["string", "null"]
"type": [
"string",
"null"
]
}
},
"required": [
"visit_path",
"microns_per_pixel_x",
"microns_per_pixel_y",
"position",
"transmission_fraction",
"flux",
"beam_size_x",
"beam_size_y",
Expand Down
2 changes: 1 addition & 1 deletion tests/system_tests/experiment_plans/test_fgs_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def test_xbpm_feedback_decorator(
@transmission_and_xbpm_feedback_for_collection_decorator(
fxc_composite.xbpm_feedback,
fxc_composite.attenuator,
params.hyperion_params.ispyb_params.transmission_fraction,
params.experiment_params.transmission_fraction,
)
def decorated_plan():
yield from bps.sleep(0.1)
Expand Down
Loading
Loading