Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
119 commits
Select commit Hold shift + click to select a range
d9c49f3
add i09 look up table praiser
Relm-Arrowny Oct 27, 2025
5143eb5
move get_poly to lookuptable
Relm-Arrowny Oct 27, 2025
2f63d81
extracted EnergyMotorLookup base class from i10EnergyMotorLookup
Relm-Arrowny Oct 28, 2025
035f619
added new make_phase_tables function
Relm-Arrowny Oct 29, 2025
42beac5
add test for correct table output
Relm-Arrowny Oct 29, 2025
2802e7e
Merge branch 'main' into 1663-i09-energy
Relm-Arrowny Oct 29, 2025
30af852
remove_i09
Relm-Arrowny Oct 29, 2025
ea13a6f
Merge branch 'main' into create_apple2_energy_motor_lookUP
Relm-Arrowny Oct 29, 2025
b206d04
add docstring
Relm-Arrowny Oct 29, 2025
9ea6715
Merge branch 'create_apple2_energy_motor_lookUP' of github.com:Diamon…
Relm-Arrowny Oct 29, 2025
6f593de
add test for helper functions
Relm-Arrowny Oct 29, 2025
6fee510
add test for skipping
Relm-Arrowny Oct 29, 2025
2cc7b93
Merge branch 'create_apple2_energy_motor_lookUP' into 1663-i09-energy
Relm-Arrowny Oct 30, 2025
9f70022
group and reuse fixture, add J09 controller and tests
Relm-Arrowny Oct 30, 2025
a8ebdc8
there is no reason to set mock value to zero
Relm-Arrowny Oct 30, 2025
348bf70
Merge branch 'main' into create_apple2_energy_motor_lookUP
Relm-Arrowny Oct 30, 2025
47cd4de
spacing fix
Relm-Arrowny Oct 30, 2025
cbc2a65
Merge remote-tracking branch 'origin/create_apple2_energy_motor_lookU…
Relm-Arrowny Oct 30, 2025
8d05913
remove print
Relm-Arrowny Oct 30, 2025
f0e6dfd
add gap tests
Relm-Arrowny Oct 30, 2025
4b61dc9
add controller, energy and polarisation to i09_2 configuration
Relm-Arrowny Oct 30, 2025
782de6b
move path to top
Relm-Arrowny Oct 30, 2025
071f3e4
add model_validation
Relm-Arrowny Oct 30, 2025
8b3f1a7
remove debug
Relm-Arrowny Oct 30, 2025
03db439
Update docstring for energy_jid function
Relm-Arrowny Oct 31, 2025
b13e35b
Update nc parameter and phase calculation logic
Relm-Arrowny Oct 31, 2025
f584f7a
Refactor Lookuptable class documentation
Relm-Arrowny Oct 31, 2025
9d94308
Merge branch 'create_apple2_energy_motor_lookUP' into 1663-i09-energy
Relm-Arrowny Oct 31, 2025
38649cf
update expected lookup table after sign change
Relm-Arrowny Oct 31, 2025
a0af379
Merge branch 'main' into create_apple2_energy_motor_lookUP
oliwenmandiamond Nov 6, 2025
b22a1c2
Merge branch 'create_apple2_energy_motor_lookUP' into 1663-i09-energy
Relm-Arrowny Nov 6, 2025
883aa15
change lookup table schema to snake case
Relm-Arrowny Nov 6, 2025
dc3afed
Merge remote-tracking branch 'origin/create_apple2_energy_motor_lookU…
Relm-Arrowny Nov 6, 2025
4a3977e
Merge branch 'main' into create_apple2_energy_motor_lookUP
Relm-Arrowny Nov 7, 2025
435be47
replace dictionary with basemodel
Relm-Arrowny Nov 12, 2025
3f5c041
add tying
Relm-Arrowny Nov 12, 2025
8bf42a7
Merge branch 'main' into create_apple2_energy_motor_lookUP
Relm-Arrowny Nov 12, 2025
0e2edac
add gap and phase
Relm-Arrowny Nov 12, 2025
1f8d8a0
Merge branch 'create_apple2_energy_motor_lookUP' of github.com:Diamon…
Relm-Arrowny Nov 12, 2025
d8e998d
fat finger correction
Relm-Arrowny Nov 12, 2025
3233149
Update ID lookup logic to use type checking
oliwenmandiamond Nov 13, 2025
927a681
Fix some tests
oliwenmandiamond Nov 13, 2025
330a69e
Improve models to not use shared defaults
oliwenmandiamond Nov 13, 2025
8b2b109
undo syntax error
oliwenmandiamond Nov 13, 2025
f87f63e
Merge branch 'main' into id_lookup_with_type_checking
oliwenmandiamond Nov 13, 2025
3537d0d
Fixed test to check for success on loading i10 lut
oliwenmandiamond Nov 13, 2025
1d1a775
Simplified lut logic
oliwenmandiamond Nov 13, 2025
c2529b9
Added back generate_lookup_table function
oliwenmandiamond Nov 14, 2025
290c3cf
Fixed all tests but polarisation
oliwenmandiamond Nov 14, 2025
45888cf
Updated doc strings
oliwenmandiamond Nov 14, 2025
60931d0
Moved generic test from i10 to test_lookup_table_apple2
oliwenmandiamond Nov 14, 2025
b60e3b3
Renamed lut_column_config to lut_config
oliwenmandiamond Nov 14, 2025
7ef1dad
Updated more doc strings
oliwenmandiamond Nov 14, 2025
963f6ab
Fix default phase_file name and thus tests
oliwenmandiamond Nov 14, 2025
5d23897
Merge branch 'main' into id_lookup_with_type_checking
oliwenmandiamond Nov 14, 2025
1713dc3
Use Pol in LookupTable rather than string
oliwenmandiamond Nov 14, 2025
9801415
Updated test_convert_csv_to_lookup_overwrite_name_convert_default to …
oliwenmandiamond Nov 14, 2025
09ae94d
Update tests to use Pol rather str value
oliwenmandiamond Nov 14, 2025
e6b3f3e
fix tests
Relm-Arrowny Nov 14, 2025
018130f
Merge remote-tracking branch 'origin/main' into 1663-i09-energy
Relm-Arrowny Nov 14, 2025
684ac41
Merge branch 'id_lookup_with_type_checking' of ssh://github.com/Diamo…
oliwenmandiamond Nov 14, 2025
25c6756
fix i09 controller and test
Relm-Arrowny Nov 14, 2025
bcc1815
reuse fixture
Relm-Arrowny Nov 14, 2025
c5d0dc1
Improve EnergyCoverageEntry to have a poly serializer and EnergyCover…
oliwenmandiamond Nov 14, 2025
fdb12ea
Add type checking to i10Apple2 phase
oliwenmandiamond Nov 17, 2025
38843c0
Removed commente out code
oliwenmandiamond Nov 17, 2025
7f21ea9
Update i10 id tests to use json files rather than pickle files so the…
oliwenmandiamond Nov 17, 2025
4b52060
Remove comments
oliwenmandiamond Nov 17, 2025
f9ee203
Fixed poly test
oliwenmandiamond Nov 17, 2025
a56bdad
Merge branch 'main' into replace_id_pickle_files_with_json
oliwenmandiamond Nov 17, 2025
e8978d4
Merge branch 'id_lookup_with_type_checking' into replace_id_pickle_fi…
oliwenmandiamond Nov 17, 2025
0f40b01
Fixed test_make_phase_tables_multiple_entries
oliwenmandiamond Nov 17, 2025
18c85bf
Added test_lookup_table_is_serialisable
oliwenmandiamond Nov 17, 2025
ffb160b
Update src/dodal/devices/util/lookup_tables_apple2.py
oliwenmandiamond Nov 17, 2025
ab4d790
Merge branch 'main' into id_lookup_with_type_checking
oliwenmandiamond Nov 17, 2025
8c28b4b
Merge branch 'id_lookup_with_type_checking' into replace_id_pickle_fi…
oliwenmandiamond Nov 17, 2025
a390b96
Merge branch 'main' into replace_id_pickle_files_with_json
oliwenmandiamond Nov 17, 2025
313dc33
Fixed formatting
oliwenmandiamond Nov 17, 2025
e92ce85
Merge remote-tracking branch 'origin/main' into 1663-i09-energy
Relm-Arrowny Nov 17, 2025
975766a
Improved code coverage
oliwenmandiamond Nov 17, 2025
363a64a
Simplified ID lookup table logic
oliwenmandiamond Nov 17, 2025
176de56
Merge branch 'main' into id_lookup_config_improvements
oliwenmandiamond Nov 17, 2025
c302503
Updated doc strings, tidy tests and variable names
oliwenmandiamond Nov 17, 2025
558fa33
Merge branch 'main' into id_lookup_config_improvements
oliwenmandiamond Nov 17, 2025
aeb3e62
Made default files a constant
oliwenmandiamond Nov 17, 2025
40ffa4c
Merge branch 'id_lookup_config_improvements' of ssh://github.com/Diam…
oliwenmandiamond Nov 17, 2025
14c8886
added gap and phase lookup
Relm-Arrowny Nov 17, 2025
700ac53
Update logging messages
oliwenmandiamond Nov 17, 2025
b39657b
Merge branch 'main' into id_lookup_config_improvements
oliwenmandiamond Nov 17, 2025
34c9b93
Merge branch 'id_lookup_config_improvements' of ssh://github.com/Diam…
oliwenmandiamond Nov 17, 2025
0df749c
Removed duplicate test logic
oliwenmandiamond Nov 17, 2025
f2a6061
Decoupled path from LookupTableConfig, updated convert_csv_to_lookup …
oliwenmandiamond Nov 17, 2025
a1d4085
Updated doc strings
oliwenmandiamond Nov 17, 2025
c06b0d1
Clean up imports
oliwenmandiamond Nov 17, 2025
87c16f1
Merge branch 'id_lookup_config_improvements', remote-tracking branch …
Relm-Arrowny Nov 18, 2025
a4cf9fe
fixed test
Relm-Arrowny Nov 18, 2025
2615167
update and reuse fixture
Relm-Arrowny Nov 18, 2025
bdb5b05
Merge branch 'id_lookup_config_improvements' into 1663-i09-energy
Relm-Arrowny Nov 18, 2025
52c4389
change I09 to use json data
Relm-Arrowny Nov 18, 2025
5725020
Merge remote-tracking branch 'origin/main' into 1663-i09-energy
Relm-Arrowny Nov 18, 2025
88d70e6
fix controller
Relm-Arrowny Nov 18, 2025
6c61291
add test for Path not given
Relm-Arrowny Nov 18, 2025
e9e8bc3
correct test
Relm-Arrowny Nov 18, 2025
c5fdbe8
typing
Relm-Arrowny Nov 19, 2025
0cf964f
modify _setpol to go to lh first for i09 id
Relm-Arrowny Nov 19, 2025
ec3365f
Merge branch 'main' into 1663-i09-energy
Relm-Arrowny Nov 19, 2025
b2c426c
Rename class and update comments for clarity
Relm-Arrowny Nov 20, 2025
e194ab3
Remove POLY_DEG list from test_i09_apple2.py
Relm-Arrowny Nov 20, 2025
599eb68
fix lint
Relm-Arrowny Nov 20, 2025
47518f9
add grading to lookup table
Relm-Arrowny Nov 21, 2025
8436a1f
add i21_apple2
Relm-Arrowny Nov 21, 2025
e3ab510
remove I09EnergyMotorLookup and move phase generation into EnergyMoto…
Relm-Arrowny Nov 21, 2025
7c1e552
move lookup table path into lut_config
Relm-Arrowny Nov 21, 2025
6a66d59
Merge branch '1663-i09-energy' into 1725-i21-energy-devices
Relm-Arrowny Nov 21, 2025
187c504
Merge branch '1725-i21-energy-devices' of github.com:DiamondLightSour…
Relm-Arrowny Nov 21, 2025
62c1000
Merge branch 'main' into 1663-i09-energy
Relm-Arrowny Nov 21, 2025
83247ba
Merge branch '1663-i09-energy' into 1725-i21-energy-devices
Relm-Arrowny Nov 21, 2025
3e85e9b
fix i21 test
Relm-Arrowny Nov 21, 2025
18f2bdf
created fullMotionApple2Controller
Relm-Arrowny Nov 24, 2025
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
46 changes: 46 additions & 0 deletions src/dodal/beamlines/i09_2.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
from pathlib import Path

from daq_config_server.client import ConfigServer

from dodal.common.beamlines.beamline_utils import (
device_factory,
)
from dodal.common.beamlines.beamline_utils import set_beamline as set_utils_beamline
from dodal.devices.apple2_undulator import (
Apple2,
BeamEnergy,
FullMotionApple2Controller,
InsertionDeviceEnergy,
InsertionDevicePolarisation,
UndulatorGap,
UndulatorPhaseAxes,
)
from dodal.devices.i09.enums import Grating
from dodal.devices.i09_2_shared.i09_apple2 import (
J09DefaultLookupTableConfig,
)
from dodal.devices.pgm import PlaneGratingMonochromator
from dodal.devices.synchrotron import Synchrotron
from dodal.devices.util.lookup_tables_apple2 import EnergyMotorLookup
from dodal.log import set_beamline as set_log_beamline
from dodal.utils import BeamlinePrefix, get_beamline_name

J09_CONF_CLIENT = ConfigServer(url="https://daq-config.diamond.ac.uk")
LOOK_UPTABLE_DIR = "/dls_sw/i09-2/software/gda/workspace_git/gda-diamond.git/configurations/i09-2-shared/lookupTables/"
GAP_LOOKUP_FILE_NAME = "JIDEnergy2GapCalibrations.csv"

BL = get_beamline_name("i09-2")
PREFIX = BeamlinePrefix(BL, suffix="J")
set_log_beamline(BL)
Expand Down Expand Up @@ -55,3 +71,33 @@ def jid() -> Apple2:
id_gap=jid_gap(),
id_phase=jid_phase(),
)


@device_factory()
def jid_controller() -> FullMotionApple2Controller:
"""J09 insertion device controller."""
J09DefaultLookupTableConfig.gap_path = Path(LOOK_UPTABLE_DIR, GAP_LOOKUP_FILE_NAME)
return FullMotionApple2Controller(
apple2=jid(),
energy_motor_lut=EnergyMotorLookup(
lut_config=J09DefaultLookupTableConfig,
config_client=J09_CONF_CLIENT,
),
units="keV",
)


@device_factory()
def jid_energy() -> InsertionDeviceEnergy:
return InsertionDeviceEnergy(id_controller=jid_controller())


@device_factory()
def jid_polarisation() -> InsertionDevicePolarisation:
return InsertionDevicePolarisation(id_controller=jid_controller())


@device_factory()
def energy_jid() -> BeamEnergy:
"""Beam energy."""
return BeamEnergy(id_energy=jid_energy(), mono=pgm().energy)
18 changes: 10 additions & 8 deletions src/dodal/beamlines/i10_optics.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@
set_utils_beamline(BL)
PREFIX = BeamlinePrefix(BL)

LOOK_UPTABLE_DIR = "/dls_sw/i10/software/blueapi/scratch/i10-config/lookupTables/"


@device_factory()
def synchrotron() -> Synchrotron:
Expand Down Expand Up @@ -125,9 +123,11 @@ def idd_controller() -> I10Apple2Controller:
"""I10 downstream insertion device controller."""
idd_energy_motor_lut = EnergyMotorLookup(
config_client=I10_CONF_CLIENT,
lut_config=LookupTableConfig(source=("Source", "idd")),
gap_path=Path(LOOK_UPTABLE_DIR, DEFAULT_GAP_FILE),
phase_path=Path(LOOK_UPTABLE_DIR, DEFAULT_PHASE_FILE),
lut_config=LookupTableConfig(
source=("Source", "idd"),
gap_path=Path(LOOK_UPTABLE_DIR, DEFAULT_GAP_FILE),
phase_path=Path(LOOK_UPTABLE_DIR, DEFAULT_PHASE_FILE),
),
)
return I10Apple2Controller(apple2=idd(), energy_motor_lut=idd_energy_motor_lut)

Expand Down Expand Up @@ -190,9 +190,11 @@ def idu_controller() -> I10Apple2Controller:
"""I10 upstream insertion device controller."""
idu_energy_motor_lut = EnergyMotorLookup(
config_client=I10_CONF_CLIENT,
lut_config=LookupTableConfig(source=("Source", "idu")),
gap_path=Path(LOOK_UPTABLE_DIR, DEFAULT_GAP_FILE),
phase_path=Path(LOOK_UPTABLE_DIR, DEFAULT_PHASE_FILE),
lut_config=LookupTableConfig(
source=("Source", "idu"),
gap_path=Path(LOOK_UPTABLE_DIR, DEFAULT_GAP_FILE),
phase_path=Path(LOOK_UPTABLE_DIR, DEFAULT_PHASE_FILE),
),
)
return I10Apple2Controller(apple2=idd(), energy_motor_lut=idu_energy_motor_lut)

Expand Down
45 changes: 44 additions & 1 deletion src/dodal/beamlines/i21.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
from pathlib import Path

from daq_config_server.client import ConfigServer

from dodal.common.beamlines.beamline_utils import (
device_factory,
)
from dodal.common.beamlines.beamline_utils import set_beamline as set_utils_beamline
from dodal.devices.apple2_undulator import (
Apple2,
BeamEnergy,
FullMotionApple2Controller,
InsertionDeviceEnergy,
InsertionDevicePolarisation,
UndulatorGap,
UndulatorPhaseAxes,
)
from dodal.devices.i21 import Grating
from dodal.devices.i21 import Grating, I21EnergyMotorLookup
from dodal.devices.pgm import PlaneGratingMonochromator
from dodal.devices.synchrotron import Synchrotron
from dodal.devices.util.lookup_tables_apple2 import LookupTableConfig
from dodal.log import set_beamline as set_log_beamline
from dodal.utils import BeamlinePrefix, get_beamline_name

I21_CONF_CLIENT = ConfigServer(url="https://daq-config.diamond.ac.uk")
LOOK_UPTABLE_DIR = "/dls_sw/i21/software/gda/workspace_git/gda-diamond.git/configurations/i21-config/lookupTables/"
GAP_LOOKUP_FILE_NAME = "IDEnergy2GapCalibrations.csv"
BL = get_beamline_name("i21")
PREFIX = BeamlinePrefix(BL)
set_log_beamline(BL)
Expand Down Expand Up @@ -55,3 +67,34 @@ def id() -> Apple2:
id_gap=id_gap(),
id_phase=id_phase(),
)


@device_factory()
def id_controller() -> FullMotionApple2Controller:
"""i21 insertion device controller."""
return FullMotionApple2Controller(
apple2=id(),
energy_motor_lut=I21EnergyMotorLookup(
lut_config=LookupTableConfig(
grading="Grating", gap_path=Path(LOOK_UPTABLE_DIR, GAP_LOOKUP_FILE_NAME)
),
config_client=I21_CONF_CLIENT,
),
units="eV",
)


@device_factory()
def id_energy() -> InsertionDeviceEnergy:
return InsertionDeviceEnergy(id_controller=id_controller())


@device_factory()
def id_polarisation() -> InsertionDevicePolarisation:
return InsertionDevicePolarisation(id_controller=id_controller())


@device_factory()
def energy_jid() -> BeamEnergy:
"""Beam energy."""
return BeamEnergy(id_energy=id_energy(), mono=pgm().energy)
77 changes: 65 additions & 12 deletions src/dodal/devices/apple2_undulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from ophyd_async.epics.motor import Motor

from dodal.common.enums import EnabledDisabledUpper
from dodal.devices.util.lookup_tables_apple2 import EnergyMotorLookup, Pol
from dodal.log import LOGGER

T = TypeVar("T")
Expand Down Expand Up @@ -58,16 +59,6 @@ def extract_phase_val(self):
return self.phase


class Pol(StrictEnum):
NONE = "None"
LH = "lh"
LV = "lv"
PC = "pc"
NC = "nc"
LA = "la"
LH3 = "lh3"


ROW_PHASE_MOTOR_TOLERANCE = 0.004
MAXIMUM_ROW_PHASE_MOTOR_POSITION = 24.0
MAXIMUM_GAP_MOTOR_POSITION = 100
Expand Down Expand Up @@ -449,6 +440,7 @@ def __init__(
self,
apple2: Apple2Type,
energy_to_motor_converter: EnergyMotorConvertor,
units: str = "eV",
name: str = "",
) -> None:
"""
Expand All @@ -465,14 +457,14 @@ def __init__(

# Store the set energy for readback.
self._energy, self._energy_set = soft_signal_r_and_setter(
float, initial_value=None, units="eV"
float, initial_value=None, units=units
)
with self.add_children_as_readables(StandardReadableFormat.HINTED_SIGNAL):
self.energy = derived_signal_rw(
raw_to_derived=self._read_energy,
set_derived=self._set_energy,
energy=self._energy,
derived_units="eV",
derived_units=units,
)

# Store the polarisation for setpoint. And provide readback for LH3.
Expand Down Expand Up @@ -653,6 +645,67 @@ def determine_phase_from_hardware(
return Pol.NONE, 0.0


class FullMotionApple2Controller(Apple2Controller[Apple2]):
"""The latest Apple2 version allows unrestricted motor movement.
However, because of the high forces involved in polarization changes,
all movements must be performed using the Linear Horizontal (LH) mode.
A look-up table must also be used to determine the highest energy that can
be reached in LH mode."""

def __init__(
self,
apple2: Apple2,
energy_motor_lut: EnergyMotorLookup,
units: str = "eV",
name: str = "",
) -> None:
self.lookup_table_client = energy_motor_lut
super().__init__(
apple2=apple2,
energy_to_motor_converter=self.lookup_table_client.get_motor_from_energy,
units=units,
name=name,
)

async def _set_motors_from_energy(self, value: float) -> None:
"""
Set the undulator motors for a given energy and polarisation.
"""

pol = await self._check_and_get_pol_setpoint()
gap, phase = self.energy_to_motor(energy=value, pol=pol)
id_set_val = Apple2Val(
gap=f"{gap:.6f}",
phase=Apple2PhasesVal(
top_outer=f"{phase:.6f}",
top_inner=f"{0.0:.6f}",
btm_inner=f"{phase:.6f}",
btm_outer=f"{0.0:.6f}",
),
)

LOGGER.info(f"Setting polarisation to {pol}, with values: {id_set_val}")
await self.apple2().set(id_motor_values=id_set_val)

async def _set_pol(
self,
value: Pol,
) -> None:
# I09 require all palarisation change to go via LH.
target_energy = await self.energy.get_value()
if value is not Pol.LH:
self._polarisation_setpoint_set(Pol.LH)
max_lh_energy = float(
self.lookup_table_client.lookup_tables.gap.root[Pol("lh")].limit.maximum
)
lh_setpoint = (
max_lh_energy if target_energy > max_lh_energy else target_energy
)
await self.energy.set(lh_setpoint, timeout=MAXIMUM_MOVE_TIME)
self._polarisation_setpoint_set(value)
await self.energy.set(target_energy, timeout=MAXIMUM_MOVE_TIME)


class InsertionDeviceEnergyBase(abc.ABC, StandardReadable, Movable):
"""Base class for ID energy movable device."""

Expand Down
Empty file.
22 changes: 22 additions & 0 deletions src/dodal/devices/i09_2_shared/i09_apple2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from dodal.devices.util.lookup_tables_apple2 import (
LookupTableConfig,
)

J09DefaultLookupTableConfig = LookupTableConfig(
mode="Mode",
min_energy="MinEnergy",
max_energy="MaxEnergy",
poly_deg=[
"9th-order",
"8th-order",
"7th-order",
"6th-order",
"5th-order",
"4th-order",
"3rd-order",
"2nd-order",
"1st-order",
"0th-order",
],
mode_name_convert={"cr": "pc", "cl": "nc"},
)
3 changes: 2 additions & 1 deletion src/dodal/devices/i21/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from dodal.devices.i21.enums import Grating
from dodal.devices.i21.i21_apple2 import I21EnergyMotorLookup

__all__ = ["Grating"]
__all__ = ["Grating", "I21EnergyMotorLookup"]
26 changes: 26 additions & 0 deletions src/dodal/devices/i21/i21_apple2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from dodal.devices.i21.enums import Grating
from dodal.devices.util.lookup_tables_apple2 import (
EnergyMotorLookup,
Pol,
)


class I21EnergyMotorLookup(EnergyMotorLookup):
"""Add an helper function to get the correct grading from lookup table"""

def get_grating_from_energy(self, energy: float, pol: Pol) -> Grating:
if (
energy < self.lookup_tables.gap.root[pol].limit.minimum
or energy > self.lookup_tables.gap.root[pol].limit.maximum
):
raise ValueError(
"Demanding energy must lie between"
+ f" {self.lookup_tables.gap.root[pol].limit.minimum}"
+ f" and {self.lookup_tables.gap.root[pol].limit.maximum} eV!"
)
else:
for energy_range in self.lookup_tables.gap.root[pol].energies.root.values():
if energy >= energy_range.low and energy < energy_range.high:
if energy_range.grading is not None:
return Grating[energy_range.grading]
raise ValueError("Grading undefine in lookup table")
Loading