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

1302 do not put position into ispyb for gridscans #1401

Merged
merged 5 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

from hyperion.external_interaction.callbacks.common.ispyb_mapping import (
populate_data_collection_group,
populate_data_collection_position_info,
populate_remaining_data_collection_info,
)
from hyperion.external_interaction.callbacks.ispyb_callback_base import (
Expand Down Expand Up @@ -176,9 +175,6 @@ def populate_info_for_update(
), "Expect at least one valid data collection to record scan data"
xy_scan_data_info = ScanDataInfo(
data_collection_info=event_sourced_data_collection_info,
data_collection_position_info=populate_data_collection_position_info(
params.ispyb_params
),
data_collection_id=self.ispyb_ids.data_collection_ids[0],
)
scan_data_infos = [xy_scan_data_info]
Expand All @@ -190,9 +186,6 @@ def populate_info_for_update(
)
xz_scan_data_info = ScanDataInfo(
data_collection_info=event_sourced_data_collection_info,
data_collection_position_info=populate_data_collection_position_info(
params.ispyb_params
),
data_collection_id=data_collection_id,
)
scan_data_infos.append(xz_scan_data_info)
Expand Down
14 changes: 9 additions & 5 deletions src/hyperion/external_interaction/ispyb/ispyb_dataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
GRIDSCAN_ISPYB_PARAM_DEFAULTS = {
"sample_id": None,
"visit_path": "",
"position": [0, 0, 0],
"position": None,
"xtal_snapshots_omega_start": ["test_1_y", "test_2_y", "test_3_y"],
"xtal_snapshots_omega_end": ["test_1_z", "test_2_z", "test_3_z"],
"comment": "Descriptive comment.",
Expand All @@ -16,7 +16,7 @@

class IspybParams(BaseModel):
visit_path: str
position: np.ndarray
position: Optional[np.ndarray]
comment: str
sample_id: Optional[int] = None

Expand All @@ -31,13 +31,17 @@ class Config:

def dict(self, **kwargs):
as_dict = super().dict(**kwargs)
as_dict["position"] = as_dict["position"].tolist()
as_dict["position"] = (
as_dict["position"].tolist() if as_dict["position"] is not None else None
)
return as_dict

@validator("position", pre=True)
def _parse_position(
cls, position: list[int | float] | np.ndarray, values: Dict[str, Any]
) -> np.ndarray:
cls, position: list[int | float] | np.ndarray | None, values: Dict[str, Any]
) -> np.ndarray | None:
if position is None:
return None
assert len(position) == 3
if isinstance(position, np.ndarray):
return position
Expand Down
11 changes: 5 additions & 6 deletions src/hyperion/parameters/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from pathlib import Path
from typing import Sequence, SupportsInt, TypeVar

import numpy as np
from dodal.devices.detector import (
DetectorParams,
TriggerMode,
Expand Down Expand Up @@ -120,11 +119,11 @@ def __hash__(self) -> int:

@validator("parameter_model_version")
def _validate_version(cls, version: ParameterVersion):
assert version >= ParameterVersion(
major=PARAMETER_VERSION.major
assert (
version >= ParameterVersion(major=PARAMETER_VERSION.major)
), f"Parameter version too old! This version of hyperion uses {PARAMETER_VERSION}"
assert version <= ParameterVersion(
major=PARAMETER_VERSION.major + 1
assert (
version <= ParameterVersion(major=PARAMETER_VERSION.major + 1)
), f"Parameter version too new! This version of hyperion uses {PARAMETER_VERSION}"
return version

Expand Down Expand Up @@ -248,7 +247,7 @@ class Config:
arbitrary_types_allowed = True
extra = Extra.forbid

position: list[float] | NDArray = Field(default=np.array([0, 0, 0]))
position: list[float] = None
xtal_snapshots_omega_start: list[str] | None = None
xtal_snapshots_omega_end: list[str] | None = None
xtal_snapshots: list[str] | None = None
2 changes: 0 additions & 2 deletions src/hyperion/parameters/gridscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import os

import numpy as np
from dodal.devices.detector import (
DetectorDistanceToBeamXYConverter,
DetectorParams,
Expand Down Expand Up @@ -51,7 +50,6 @@ class GridCommon(
def ispyb_params(self):
return GridscanIspybParams(
visit_path=str(self.visit_directory),
position=np.array(self.ispyb_extras.position),
comment=self.comment,
sample_id=self.sample_id,
xtal_snapshots_omega_start=self.ispyb_extras.xtal_snapshots_omega_start
Expand Down
2 changes: 2 additions & 0 deletions tests/system_tests/external_interaction/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ def get_current_position_attribute(
with Session() as session:
query = session.query(Position).filter(Position.positionId == position_id)
first_result = query.first()
if first_result is None:
return None
return getattr(first_result, attr)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
)
from hyperion.external_interaction.callbacks.common.ispyb_mapping import (
populate_data_collection_group,
populate_data_collection_position_info,
populate_remaining_data_collection_info,
)
from hyperion.external_interaction.callbacks.rotation.ispyb_callback import (
Expand Down Expand Up @@ -397,9 +396,6 @@ def scan_xy_data_info_for_update(
scan_data_info_for_update.data_collection_grid_info,
)
)
scan_data_info_for_update.data_collection_position_info = (
populate_data_collection_position_info(dummy_params.ispyb_params)
)
return scan_data_info_for_update


Expand Down Expand Up @@ -436,9 +432,6 @@ def scan_data_infos_for_update_3d(
scan_xz_data_info_for_update = ScanDataInfo(
data_collection_info=xz_data_collection_info,
data_collection_grid_info=(data_collection_grid_info),
data_collection_position_info=(
populate_data_collection_position_info(dummy_params.ispyb_params)
),
)
return [scan_xy_data_info_for_update, scan_xz_data_info_for_update]

Expand Down Expand Up @@ -677,10 +670,7 @@ def test_ispyb_deposition_in_gridscan(
position_id = fetch_datacollection_attribute(
ispyb_ids.data_collection_ids[0], DATA_COLLECTION_COLUMN_MAP["positionid"]
)
expected_values = {"posX": 10.0, "posY": 20.0, "posZ": 30.0}
compare_actual_and_expected(
position_id, expected_values, fetch_datacollection_position_attribute
)
assert position_id is None
DC_EXPECTED_VALUES.update(
{
"axisstart": 90.0,
Expand All @@ -707,10 +697,7 @@ def test_ispyb_deposition_in_gridscan(
position_id = fetch_datacollection_attribute(
ispyb_ids.data_collection_ids[1], DATA_COLLECTION_COLUMN_MAP["positionid"]
)
expected_values = {"posX": 10.0, "posY": 20.0, "posZ": 30.0}
compare_actual_and_expected(
position_id, expected_values, fetch_datacollection_position_attribute
)
assert position_id is None
GRIDINFO_EXPECTED_VALUES.update(
{
"gridInfoId": ispyb_ids.grid_ids[1],
Expand Down Expand Up @@ -767,6 +754,7 @@ def test_ispyb_deposition_in_rotation_plan(
fetch_comment: Callable[..., Any],
fetch_datacollection_attribute: Callable[..., Any],
fetch_datacollectiongroup_attribute: Callable[..., Any],
fetch_datacollection_position_attribute: Callable[..., Any],
undulator: Undulator,
attenuator: Attenuator,
synchrotron: Synchrotron,
Expand Down Expand Up @@ -855,3 +843,11 @@ def test_ispyb_deposition_in_rotation_plan(
}

compare_actual_and_expected(dcid, EXPECTED_VALUES, fetch_datacollection_attribute)

position_id = fetch_datacollection_attribute(
dcid, DATA_COLLECTION_COLUMN_MAP["positionid"]
)
expected_values = {"posX": 10.0, "posY": 20.0, "posZ": 30.0}
compare_actual_and_expected(
position_id, expected_values, fetch_datacollection_position_attribute
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
"transmission_frac": 1.0,
"visit": "cm31105-4",
"ispyb_extras": {
"position": [
10.0,
20.0,
30.0
],
"xtal_snapshots_omega_start": [
"c",
"b",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
"z2_start_um": 0.0,
"storage_directory": "/tmp/dls/i03/data/2024/cm31105-4/xraycentring/123456/",
"ispyb_extras": {
"position": [
10.0,
20.0,
30.0
],
"xtal_snapshots_omega_start": [
"test_1_y",
"test_2_y",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,5 @@
"transmission_frac": 1.0,
"visit": "cm31105-4",
"ispyb_extras": {
"position": [
10.0,
20.0,
30.0
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,5 @@
"sample_pin": 3,
"comment": "Descriptive comment.",
"ispyb_extras": {
"position": [
0,
0,
0
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@
"visit": "cm31105-4",
"demand_energy_ev": 12700,
"ispyb_extras": {
"position": [
10.0,
20.0,
30.0
],
"xtal_snapshots_omega_start": [
"test_1_y",
"test_2_y",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@
"exposure_time_s": 0.1,
"set_stub_offsets": true,
"ispyb_extras": {
"position": [
0,
0,
0
],
"xtal_snapshots_omega_start": [
"test_1_y",
"test_2_y",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,26 +175,7 @@ def test_flux_read_events_3d(self, mock_ispyb_conn):
"resolution": 1.1830593328548429,
},
)
assert_upsert_call_with(
mx_acq.update_dc_position.mock_calls[0],
mx_acq.get_dc_position_params(),
{
"id": TEST_DATA_COLLECTION_IDS[0],
"pos_x": 0,
"pos_y": 0,
"pos_z": 0,
},
)
assert_upsert_call_with(
mx_acq.update_dc_position.mock_calls[1],
mx_acq.get_dc_position_params(),
{
"id": TEST_DATA_COLLECTION_IDS[1],
"pos_x": 0,
"pos_y": 0,
"pos_z": 0,
},
)
mx_acq.update_dc_position.assert_not_called()
mx_acq.upsert_dc_grid.assert_not_called()

def test_activity_gated_event_oav_snapshot_triggered(self, mock_ispyb_conn):
Expand Down
Loading