Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into 455_remove_precommit_…
Browse files Browse the repository at this point in the history
…no_commit_to_main
  • Loading branch information
olliesilvester committed Sep 20, 2024
2 parents 9f2e31b + ece1903 commit 08cda16
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 64 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ dependencies = [
"ophyd == 1.9.0",
"ophyd-async >= 0.3a5",
"bluesky >= 1.13.0a4",
"dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@040a72885deaca1055a930f09eccef4acca812f5",
"dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@3f59ce090dd5c5f94f761b4b80a61cbd34d90564",
]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def adjust_dcm_pitch_roll_vfm_from_lut(
bragg_deg = yield from bps.rd(dcm.bragg_in_degrees.user_readback)
LOGGER.info(f"Read Bragg angle = {bragg_deg} degrees")
dcm_pitch_adjuster = lookup_table_adjuster(
linear_interpolation_lut(undulator_dcm.dcm_pitch_converter_lookup_table_path),
linear_interpolation_lut(undulator_dcm.pitch_energy_table_path),
dcm.pitch_in_mrad,
bragg_deg,
)
Expand All @@ -97,7 +97,7 @@ def adjust_dcm_pitch_roll_vfm_from_lut(

# DCM Roll
dcm_roll_adjuster = lookup_table_adjuster(
linear_interpolation_lut(undulator_dcm.dcm_roll_converter_lookup_table_path),
linear_interpolation_lut(undulator_dcm.roll_energy_table_path),
dcm.roll_in_mrad,
bragg_deg,
)
Expand Down
21 changes: 7 additions & 14 deletions src/mx_bluesky/hyperion/device_setup_plans/setup_panda.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
from ophyd_async.fastcs.panda import (
HDFPanda,
SeqTable,
SeqTableRow,
SeqTrigger,
seq_table_from_rows,
)

import mx_bluesky.hyperion.resources.panda as panda_resource
Expand Down Expand Up @@ -85,10 +83,10 @@ def _get_seq_table(
# BITA_1 trigger wired from TTLIN1, this is the trigger input

# +ve direction scan
rows = [SeqTableRow(trigger=SeqTrigger.BITA_1, time2=1)]

rows.append(
SeqTableRow(
table = (
SeqTable.row(trigger=SeqTrigger.BITA_1, time2=1)
+ SeqTable.row(
repeats=num_pulses,
trigger=SeqTrigger.POSA_GT,
position=start_of_grid_x_counts,
Expand All @@ -97,13 +95,10 @@ def _get_seq_table(
time2=delay_between_pulses - PULSE_WIDTH_US,
outa2=False,
)
)

# -ve direction scan
rows.append(SeqTableRow(trigger=SeqTrigger.BITA_1, time2=1))

rows.append(
SeqTableRow(
+
# -ve direction scan
SeqTable.row(trigger=SeqTrigger.BITA_1, time2=1)
+ SeqTable.row(
repeats=num_pulses,
trigger=SeqTrigger.POSA_LT,
position=end_of_grid_x_counts + exposure_distance_x_counts,
Expand All @@ -114,8 +109,6 @@ def _get_seq_table(
)
)

table = seq_table_from_rows(*rows)

return table


Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,10 @@ def vfm_mirror_voltages():
def undulator_dcm(RE, dcm):
undulator_dcm = i03.undulator_dcm(fake_with_ophyd_sim=True)
undulator_dcm.dcm = dcm
undulator_dcm.dcm_roll_converter_lookup_table_path = (
undulator_dcm.roll_energy_table_path = (
"tests/test_data/test_beamline_dcm_roll_converter.txt"
)
undulator_dcm.dcm_pitch_converter_lookup_table_path = (
undulator_dcm.pitch_energy_table_path = (
"tests/test_data/test_beamline_dcm_pitch_converter.txt"
)
yield undulator_dcm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
async def test_getting_data_for_ispyb():
params = GDABeamlineParameters.from_file(BEAMLINE_PARAMETER_PATHS["i03"])
undulator = Undulator(
f"{CONST.SIM.INSERTION_PREFIX}-MO-SERVC-01:", name="undulator"
f"{CONST.SIM.INSERTION_PREFIX}-MO-SERVC-01:",
name="undulator",
id_gap_lookup_table_path="/dls_sw/i03/software/daq_configuration/lookup/BeamLine_Undulator_toGap.txt",
)
synchrotron = i03.synchrotron(fake_with_ophyd_sim=True)
slit_gaps = S4SlitGaps(f"{CONST.SIM.BEAMLINE}-AL-SLITS-04:", name="slits")
Expand Down
87 changes: 43 additions & 44 deletions tests/unit_tests/hyperion/device_setup_plans/test_setup_panda.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from datetime import datetime
from typing import NamedTuple
from unittest.mock import MagicMock, patch

import numpy as np
Expand All @@ -9,7 +8,7 @@
from bluesky.simulators import RunEngineSimulator, assert_message_and_return_remaining
from dodal.common.types import UpdatingPathProvider
from dodal.devices.fast_grid_scan import PandAGridScanParams
from ophyd_async.fastcs.panda import SeqTrigger
from ophyd_async.fastcs.panda import SeqTable, SeqTrigger

from mx_bluesky.hyperion.device_setup_plans.setup_panda import (
MM_TO_ENCODER_COUNTS,
Expand Down Expand Up @@ -69,16 +68,6 @@ def test_setup_panda_performs_correct_plans(mock_load_device, sim_run_engine):
assert num_of_waits == 3


class SeqRow(NamedTuple):
repeats: int
trigger: SeqTrigger
position: int
time1: int
outa1: int
time2: int
outa2: int


@pytest.mark.parametrize(
"x_steps, x_step_size, x_start, run_up_distance_mm, time_between_x_steps_ms, exposure_time_s",
[
Expand Down Expand Up @@ -142,44 +131,54 @@ def test_setup_panda_correctly_configures_table(

PULSE_WIDTH_US = 1
SPACE_WIDTH_US = int(time_between_x_steps_ms * 1000 - PULSE_WIDTH_US)
expected_seq_rows: list[SeqRow] = [
SeqRow(1, SeqTrigger.BITA_1, 0, 0, 0, 1, 0),
SeqRow(
x_steps,
SeqTrigger.POSA_GT,
int(params.x_start * MM_TO_ENCODER_COUNTS),
PULSE_WIDTH_US,
1,
SPACE_WIDTH_US,
0,
),
]

exposure_distance_counts = exposure_distance_mm * MM_TO_ENCODER_COUNTS
expected_seq_rows.extend(
[
SeqRow(1, SeqTrigger.BITA_1, 0, 0, 0, 1, 0),
SeqRow(
x_steps,
SeqTrigger.POSA_LT,
int(
(params.x_start + (params.x_steps - 1) * params.x_step_size)
* MM_TO_ENCODER_COUNTS
+ exposure_distance_counts
),
PULSE_WIDTH_US,
1,
SPACE_WIDTH_US,
0,
expected_seq_table: SeqTable = (
SeqTable.row(
repeats=1,
trigger=SeqTrigger.BITA_1,
position=0,
time1=False,
outa1=False,
time2=True,
outa2=False,
)
+ SeqTable.row(
repeats=x_steps,
trigger=SeqTrigger.POSA_GT,
position=int(params.x_start * MM_TO_ENCODER_COUNTS),
time1=PULSE_WIDTH_US,
outa1=True,
time2=SPACE_WIDTH_US,
outa2=False,
)
+ SeqTable.row(
repeats=1,
trigger=SeqTrigger.BITA_1,
position=0,
time1=False,
outa1=False,
time2=True,
outa2=False,
)
+ SeqTable.row(
repeats=x_steps,
trigger=SeqTrigger.POSA_LT,
position=int(
(params.x_start + (params.x_steps - 1) * params.x_step_size)
* MM_TO_ENCODER_COUNTS
+ exposure_distance_counts
),
]
time1=PULSE_WIDTH_US,
outa1=True,
time2=SPACE_WIDTH_US,
outa2=False,
)
)

for key in SeqRow._fields:
for attr_name in table.__annotations__.keys():
np.testing.assert_array_equal(
table.get(key),
[getattr(row, key) for row in expected_seq_rows],
f"Sequence table for field {key} does not match",
getattr(table, attr_name), getattr(expected_seq_table, attr_name)
)


Expand Down

0 comments on commit 08cda16

Please sign in to comment.