-
Notifications
You must be signed in to change notification settings - Fork 5
Bugfix linearsource scanspecv2 #213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v2-dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| from typing import Any | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| def approx( | ||
| expected: Any, | ||
| rel: float | None = None, | ||
| abs: float | None = None, | ||
| nan_ok: bool = False, | ||
| ) -> Any: | ||
| """ | ||
| Temporary loosely typed wrapper around approx. | ||
| To be removed pending: | ||
| https://github.com/pytest-dev/pytest/issues/7469 | ||
|
|
||
| Args: | ||
| expected: Expected value | ||
| rel: Relative tolerance. Defaults to None. | ||
| abs: Absolute tolerance. Defaults to None. | ||
| nan_ok: Permit nan. Defaults to False. | ||
|
|
||
| Returns: | ||
| Any: Approximate comparator | ||
| """ | ||
|
|
||
| return pytest.approx(expected, rel=rel, abs=abs, nan_ok=nan_ok) # type: ignore |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1012,3 +1012,84 @@ def test_zip_rejects_monitors(): | |
| ) | ||
| with pytest.raises(ValueError, match="Zip does not accept.*monitors"): | ||
| Linspace("y", 0, 1, 5).zip(a).compile() # type: ignore[reportArgumentType] | ||
|
|
||
|
|
||
| def test_acquire_fly_scan_window_positions(): | ||
| # Detector with total acquisition time of 1s | ||
| det = DetectorGroup(1, 10, 0.9, 0.1, ["spec_det1"]) | ||
| spec: Acquire[str, str, Never] = Acquire( | ||
| spec=Linspace("x", 11, 20, 10), fly=True, detectors=[det], stream_name="spec" | ||
| ) | ||
| scan = spec.compile() | ||
| ws = windows(scan) | ||
| assert len(ws) == 1 | ||
| for w in ws: | ||
| # Return positions spaced 1s apart | ||
| for p in w.positions(1, None): | ||
| assert len(p["x"]) == 12 | ||
| assert p["x"] == pytest.approx( # type: ignore[reportUnknownMemberType] | ||
| [ | ||
| 10.55, | ||
| 11.45, | ||
| 12.35, | ||
| 13.25, | ||
| 14.15, | ||
| 15.05, | ||
| 15.95, | ||
| 16.85, | ||
| 17.75, | ||
| 18.65, | ||
| 19.55, | ||
| 20.45, | ||
| ] | ||
| ) | ||
|
Comment on lines
+1028
to
+1045
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then I would expect this to have size 11, and be [0.5, ... 10.5] as we are returning bounds rather than midpoints
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why this would be the expected behaviour. Currently all the method does is shift the first point to be the equivalent to the first
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the intended behaviour. The
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I'll push the changes that implement this logic. |
||
| det = DetectorGroup(1, 10, 1, 1, ["spec_det1"]) | ||
| spec: Acquire[str, str, Never] = Acquire( | ||
| spec=Linspace("x", 11, 20, 10), fly=True, detectors=[det], stream_name="spec" | ||
| ) | ||
| scan = spec.compile() | ||
| ws = windows(scan) | ||
| assert len(ws) == 1 | ||
| for w in ws: | ||
| # Return positions spaced 1s apart | ||
| for p in w.positions(1, None): | ||
| assert len(p["x"]) == 22 | ||
| assert p["x"] == pytest.approx( # type: ignore[reportUnknownMemberType] | ||
| [ | ||
| 10.775, | ||
| 11.225, | ||
| 11.675, | ||
| 12.125, | ||
| 12.575, | ||
| 13.025, | ||
| 13.475, | ||
| 13.925, | ||
| 14.375, | ||
| 14.825, | ||
| 15.275, | ||
| 15.725, | ||
| 16.175, | ||
| 16.625, | ||
| 17.075, | ||
| 17.525, | ||
| 17.975, | ||
| 18.425, | ||
| 18.875, | ||
| 19.325, | ||
| 19.775, | ||
| 20.225, | ||
| ] | ||
| ) | ||
|
|
||
|
|
||
| def test_acquire_step_scan_window_positions(): | ||
| det = DetectorGroup(1, 10, 1, 1, ["spec_det1"]) | ||
| spec: Acquire[str, str, Never] = Acquire( | ||
| spec=Linspace("x", 0, 10, 10), fly=False, detectors=[det], stream_name="spec" | ||
| ) | ||
| scan = spec.compile() | ||
| ws = windows(scan) | ||
| pos = np.linspace(0, 10, 10, endpoint=False) | ||
| assert len(ws) == 10 | ||
| for w, p in zip(ws, pos, strict=True): | ||
| assert w.static_axes == {"x": p} | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sure we've got this helper somewhere else in tests/scanspec2 already...