Skip to content

Commit

Permalink
naming reframing
Browse files Browse the repository at this point in the history
  • Loading branch information
stan-dot committed Aug 16, 2024
1 parent 679dca2 commit 0eea568
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
17 changes: 10 additions & 7 deletions src/dodal/devices/undulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def __init__(
@AsyncStatus.wrap
async def set(self, value: float):
"""
set the undulator gap to a given ENERGY
Set the undulator gap to a given energy in keV
Args:
value: energy in keV
Expand All @@ -113,22 +113,22 @@ async def _set_undulator_gap(self, energy_kev: float) -> None:
if access_level is UndulatorGapAccess.DISABLED and not TEST_MODE:
raise AccessError("Undulator gap access is disabled. Contact Control Room")
LOGGER.info(f"Setting undulator gap to {energy_kev:.2f} kev")
gap_to_match_dcm_energy = await self._gap_to_match_dcm_energy(energy_kev)
target_gap = await self._get_gap_to_match_energy(energy_kev)

# Check if undulator gap is close enough to the value from the DCM
current_gap = await self.current_gap.get_value()
tolerance = await self.gap_discrepancy_tolerance_mm.get_value()
difference = abs(gap_to_match_dcm_energy - current_gap)
difference = abs(target_gap - current_gap)
if difference > tolerance:
LOGGER.info(
f"Undulator gap mismatch. {difference:.3f}mm is outside tolerance.\
Moving gap to nominal value, {gap_to_match_dcm_energy:.3f}mm"
Moving gap to nominal value, {target_gap:.3f}mm"
)
if not TEST_MODE:
# Only move if the gap is sufficiently different to the value from the
# DCM lookup table AND we're not in TEST_MODE
await self.gap_motor.set(
gap_to_match_dcm_energy,
target_gap,
timeout=STATUS_TIMEOUT_S,
)
else:
Expand All @@ -139,8 +139,11 @@ async def _set_undulator_gap(self, energy_kev: float) -> None:
f"{energy_kev}, no need to ask it to move"
)

async def _gap_to_match_dcm_energy(self, energy_kev: float) -> float:
# from lookup table a get a 2d np.array converting energies to undulator gap distance
async def _get_gap_to_match_energy(self, energy_kev: float) -> float:
"""
get a 2d np.array from lookup table that
converts energies to undulator gap distance
"""
energy_to_distance_table: np.ndarray = await energy_distance_table(
self.id_gap_lookup_table_path
)
Expand Down
8 changes: 3 additions & 5 deletions tests/devices/unit_tests/test_undulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,12 @@ async def test_length_not_propagated_if_not_supplied():


@pytest.mark.parametrize(
"dcm_energy, expected_output", [(5730, 5.4606), (7200, 6.045), (9000, 6.404)]
"energy, expected_output", [(5730, 5.4606), (7200, 6.045), (9000, 6.404)]
)
def test_correct_closest_distance_to_energy_from_table(dcm_energy, expected_output):
def test_correct_closest_distance_to_energy_from_table(energy, expected_output):
energy_to_distance_table = np.array([[5700, 5.4606], [7000, 6.045], [9700, 6.404]])
assert (
_get_closest_gap_for_energy(dcm_energy, energy_to_distance_table)
== expected_output
_get_closest_gap_for_energy(energy, energy_to_distance_table) == expected_output
)


Expand All @@ -130,5 +129,4 @@ async def test_when_gap_access_is_disabled_set_energy_then_error_is_raised(
):
set_mock_value(undulator.gap_access, UndulatorGapAccess.DISABLED)
with pytest.raises(AccessError):
# AccessError("Undulator gap access is disabled. Contact Control Room")
await undulator.set(5)

0 comments on commit 0eea568

Please sign in to comment.