Skip to content

Commit

Permalink
respond to feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
stan-dot committed Aug 16, 2024
1 parent 7120b94 commit 945fe77
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 15 deletions.
38 changes: 38 additions & 0 deletions src/i18_bluesky/devices/LookupTable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import asyncio

from bluesky.protocols import Movable
from dodal.log import LOGGER
from ophyd_async.core import (
AsyncStatus,
StandardReadable,
wait_for_value,
)


class LookupTable(StandardReadable, Movable):
def __init__(self, prefix: str, name: str = ""):
with self.add_children_as_readables():
# self.actual_transmission = epics_signal_r(float, prefix + "MATCH")
print("test")

super().__init__(name)

@AsyncStatus.wrap
async def set(self, transmission: float):
LOGGER.debug("Updating the lookup table ")
await self._use_current_energy.trigger()
LOGGER.info(f"Setting desired transmission to {transmission}")
await self._desired_transmission.set(transmission)
LOGGER.debug("Sending change filter command")
await self._change.trigger()

await asyncio.gather(
*[
wait_for_value(
self._filters_in_position[i],
await self._calculated_filter_states[i].get_value(),
None,
)
for i in range(16)
]
)
17 changes: 4 additions & 13 deletions src/i18_bluesky/plans/align_lookup_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Optional

import bluesky.plan_stubs as bps
from i18_bluesky.plans.align_lookup_2 import calculate_derivative_maxima
import numpy as np
import sympy as sp
from dodal.common import MsgGenerator, inject
Expand All @@ -20,22 +21,12 @@

# get the gaussian shape IT transmission detector we get the shape


def derivative_max(data):
x, y = sp.symbols("x y")
y = sp.Function("y")(x)
derivative = sp.diff(y, x)
argmax = sp.solve(sp.Eq(derivative, 0), x)
return argmax


@dataclass
class BeamlineAlignmentParams:
target_energy: Optional[float] = 12.0
tolerance: Optional[float] = 0.1
target_energy: float = 12.0
tolerance: float = 0.1


@inject
def align_beamline(KBMirror, tolerance: float) -> MsgGenerator:
# first, we lookup table - calibratre the DCM -
# measure foil, etc Fe, Mg, then absorption spectrum
Expand All @@ -48,7 +39,7 @@ def align_beamline(KBMirror, tolerance: float) -> MsgGenerator:

yield from bps.mv(monochromator, "measure_absorption_spectrum")
absorption_spectrum = yield from bps.rd(monochromator.absorption_spectrum)
energy_positions = derivative_max(absorption_spectrum)
energy_positions = calculate_derivative_maxima(absorption_spectrum)

for position in energy_positions:
yield from bps.mv(monochromator.bragg_offset, position)
Expand Down
13 changes: 11 additions & 2 deletions src/i18_bluesky/plans/align_lookup_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@


def calculate_derivative_maxima(data: np.ndarray) -> List[float]:
"""
data is array[tuple(float, float)]
x = motor position
y = transmission strength
todo need to pass an x argument to the function
"""
x = sp.Symbol("x")
y = sp.interpolating_spline(3, sp.lambdify(x, data))
derivative = y.diff(x)
Expand All @@ -39,8 +46,9 @@ def adjust_bragg_offset_using_absorption_spectrum(
absorption_spectrum: np.ndarray,
) -> MsgGenerator:
energy_positions = calculate_derivative_maxima(absorption_spectrum)
for position in energy_positions:
yield from bps.mv(monochromator.bragg_in_degrees, position)
# todo return the max
max_energy_position = max(energy_positions)
yield from bps.mv(monochromator.bragg_in_degrees, max_energy_position)


def scan_undulator_gap_within_energy_range(
Expand Down Expand Up @@ -101,6 +109,7 @@ def focus_kb_mirror_until_tolerance(
yield from bps.mv(pinhole, "final_position")


# todo multiple types of alignment were mixed in this plan and the plans above
def align_beamline(
undulator, monochromator, params: BeamlineAlignmentParams
) -> MsgGenerator:
Expand Down

0 comments on commit 945fe77

Please sign in to comment.