-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8da4bf1
commit e51299a
Showing
9 changed files
with
209 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from .alignments import PeakPosition, fast_scan_and_move_cen, scan_and_move_cen | ||
from .alignments import PeakPosition, fast_scan_and_move_cen, step_scan_and_move_cen | ||
|
||
__all__ = ["fast_scan_and_move_cen", "scan_and_move_cen", "PeakPosition"] | ||
__all__ = ["fast_scan_and_move_cen", "step_scan_and_move_cen", "PeakPosition"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
from collections import defaultdict | ||
from unittest.mock import Mock | ||
|
||
import numpy as np | ||
import pytest | ||
from bluesky.run_engine import RunEngine | ||
from ophyd_async.testing import callback_on_mock_put, set_mock_value | ||
from p99_bluesky.devices.stages import ThreeAxisStage | ||
|
||
from i10_bluesky.plans.utils import ( | ||
PeakPosition, | ||
step_scan_and_move_cen, | ||
) | ||
from sim_devices import sim_detector | ||
|
||
docs = defaultdict(list) | ||
|
||
|
||
def capture_emitted(name, doc): | ||
docs[name].append(doc) | ||
|
||
|
||
def gaussian(x, mu, sig): | ||
return ( | ||
1.0 | ||
/ (np.sqrt(2.0 * np.pi) * sig) | ||
* np.exp(-np.power((x - mu) / sig, 2.0) / 2.0) | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"test_input, expected_centre", | ||
[ | ||
( | ||
[5, -5, 21, 0.1], | ||
-1, | ||
), | ||
( | ||
[50, -55, 151, 1], | ||
21.1, | ||
), | ||
( | ||
[-1, -2.51241, 31, 0.05], | ||
-1.2, | ||
), | ||
], | ||
) | ||
async def test_scan_and_move_cen_success_peak( | ||
RE: RunEngine, | ||
sim_motor_step: ThreeAxisStage, | ||
fake_detector: sim_detector, | ||
test_input, | ||
expected_centre, | ||
): | ||
start = test_input[0] | ||
end = test_input[1] | ||
num = test_input[2] | ||
peak_width = test_input[3] | ||
cen = expected_centre | ||
# Generate gaussian | ||
x_data = np.linspace(start, end, num, endpoint=True) | ||
y_data = gaussian(x_data, cen, peak_width) | ||
|
||
rbv_mocks = Mock() | ||
y_data = np.append(y_data, [0] * 2) | ||
y_data = np.array(y_data, dtype=np.float64) | ||
rbv_mocks.get.side_effect = y_data | ||
callback_on_mock_put( | ||
sim_motor_step.x.user_setpoint, | ||
lambda *_, **__: set_mock_value(fake_detector.value, value=rbv_mocks.get()), | ||
) | ||
|
||
RE( | ||
step_scan_and_move_cen( | ||
det=fake_detector, | ||
motor=sim_motor_step.x, | ||
start=start, | ||
end=end, | ||
num=num, | ||
motor_name="-user_readback", | ||
det_name="-value", | ||
loc=PeakPosition.CEN, | ||
), | ||
capture_emitted, | ||
) | ||
y_data1 = np.array([]) | ||
x_data1 = np.array([]) | ||
for i in docs["event"]: | ||
y_data1 = np.append(y_data1, i["data"]["fake_detector-value"]) | ||
x_data1 = np.append(x_data1, i["data"]["sim_motor_step-x-user_readback"]) | ||
assert await sim_motor_step.x.user_setpoint.get_value() == pytest.approx( | ||
expected_centre, 0.05 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from .sim_detectors import sim_detector | ||
from .soft_motor import SoftThreeAxisStage | ||
|
||
__all__ = ["SoftThreeAxisStage", "sim_detector"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from ophyd_async.core import ( | ||
StandardReadable, | ||
) | ||
from ophyd_async.core import StandardReadableFormat as Format | ||
from ophyd_async.epics.core import epics_signal_rw | ||
|
||
|
||
class sim_detector(StandardReadable): | ||
def __init__(self, prefix: str, name: str): | ||
with self.add_children_as_readables(Format.HINTED_SIGNAL): | ||
self.value = epics_signal_rw(float, read_pv=prefix) | ||
super().__init__(name=name) |