Skip to content

Commit

Permalink
Merge pull request #87 from DiamondLightSource/artemis_370_implement_…
Browse files Browse the repository at this point in the history
…rotation_nexus

update current_energy with units
  • Loading branch information
DominicOram authored Jun 26, 2023
2 parents a726a7d + 5cb5579 commit b02e01d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/dodal/devices/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DetectorParams(BaseModel):
"""Holds parameters for the detector. Provides access to a list of Dectris detector
sizes and a converter for distance to beam centre."""

current_energy: float
current_energy_ev: float
exposure_time: float
directory: str
prefix: str
Expand Down
5 changes: 2 additions & 3 deletions src/dodal/devices/eiger.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ def async_stage(self):
status_ok, error_message = self.odin.check_odin_initialised()
if not status_ok:
raise Exception(f"Odin not initialised: {error_message}")

return self.do_arming_chain()

def unstage(self) -> bool:
Expand Down Expand Up @@ -159,6 +158,7 @@ def set_odin_number_of_frame_chunks(self) -> Status:
return status

def set_odin_pvs(self) -> Status:
assert self.detector_params is not None
file_prefix = self.detector_params.full_filename
status = self.odin.file_writer.file_path.set(
self.detector_params.directory, timeout=self.GENERAL_STATUS_TIMEOUT
Expand Down Expand Up @@ -206,7 +206,6 @@ def set_detector_threshold(self, energy: float, tolerance: float = 0.1) -> Statu
"""

current_energy = self.cam.photon_energy.get()

if abs(current_energy - energy) > tolerance:
return self.cam.photon_energy.set(
energy, timeout=self.GENERAL_STATUS_TIMEOUT
Expand Down Expand Up @@ -283,7 +282,7 @@ def do_arming_chain(self) -> Status:
functions_to_do_arm.extend(
[
lambda: self.set_detector_threshold(
energy=detector_params.current_energy
energy=detector_params.current_energy_ev
),
self.set_cam_pvs,
self.set_odin_number_of_frame_chunks,
Expand Down
2 changes: 1 addition & 1 deletion tests/devices/system_tests/test_eiger_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@pytest.fixture()
def eiger():
detector_params: DetectorParams = DetectorParams(
current_energy=100,
current_energy_ev=100,
exposure_time=0.1,
directory="/tmp",
prefix="file_name",
Expand Down
4 changes: 2 additions & 2 deletions tests/devices/unit_tests/test_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

def create_detector_params_with_directory(directory):
return DetectorParams(
current_energy=100,
current_energy_ev=100,
exposure_time=1.0,
directory=directory,
prefix="test",
Expand Down Expand Up @@ -36,7 +36,7 @@ def test_if_trailing_slash_provided_then_not_appended():
)
def test_correct_det_dist_to_beam_converter_path_passed_in(mocked_parse_table):
params = DetectorParams(
current_energy=100,
current_energy_ev=100,
exposure_time=1.0,
directory="directory",
prefix="test",
Expand Down
14 changes: 7 additions & 7 deletions tests/devices/unit_tests/test_eiger.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

def create_new_params() -> DetectorParams:
return DetectorParams(
current_energy=TEST_CURRENT_ENERGY,
current_energy_ev=TEST_CURRENT_ENERGY,
exposure_time=TEST_EXPOSURE_TIME,
directory=TEST_DIR,
prefix=TEST_PREFIX,
Expand Down Expand Up @@ -80,7 +80,7 @@ def do_set(val: str):


@pytest.mark.parametrize(
"current_energy, request_energy, is_energy_change",
"current_energy_ev, request_energy, is_energy_change",
[
(100.0, 100.0, False),
(100.0, 200.0, True),
Expand All @@ -91,12 +91,12 @@ def do_set(val: str):
)
def test_detector_threshold(
fake_eiger: EigerDetector,
current_energy: float,
current_energy_ev: float,
request_energy: float,
is_energy_change: bool,
):
status_obj = MagicMock()
when(fake_eiger.cam.photon_energy).get().thenReturn(current_energy)
when(fake_eiger.cam.photon_energy).get().thenReturn(current_energy_ev)
when(fake_eiger.cam.photon_energy).set(ANY, timeout=ANY).thenReturn(status_obj)

returned_status = fake_eiger.set_detector_threshold(request_energy)
Expand Down Expand Up @@ -274,7 +274,7 @@ def test_unsuccessful_true_roi_mode_change_results_in_callback_error(
unwrapped_funcs = [
lambda: fake_eiger.change_roi_mode(enable=True),
lambda: fake_eiger.set_detector_threshold(
energy=fake_eiger.detector_params.current_energy
energy=fake_eiger.detector_params.current_energy_ev
),
]
with pytest.raises(Exception):
Expand All @@ -294,7 +294,7 @@ def test_unsuccessful_false_roi_mode_change_results_in_callback_error(
unwrapped_funcs = [
lambda: fake_eiger.change_roi_mode(enable=False),
lambda: fake_eiger.set_detector_threshold(
energy=fake_eiger.detector_params.current_energy
energy=fake_eiger.detector_params.current_energy_ev
),
]
with pytest.raises(Exception):
Expand Down Expand Up @@ -451,7 +451,7 @@ def get_bad_status():
unwrapped_funcs = [
(
lambda: fake_eiger.set_detector_threshold(
energy=fake_eiger.detector_params.current_energy
energy=fake_eiger.detector_params.current_energy_ev
)
),
(fake_eiger.set_cam_pvs),
Expand Down

0 comments on commit b02e01d

Please sign in to comment.