mapping-scanhelper 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mapping_scanhelper-0.1.0/.gitignore +4 -0
- mapping_scanhelper-0.1.0/.gitlab-ci.yml +38 -0
- mapping_scanhelper-0.1.0/PKG-INFO +50 -0
- mapping_scanhelper-0.1.0/README.md +40 -0
- mapping_scanhelper-0.1.0/pyproject.toml +24 -0
- mapping_scanhelper-0.1.0/setup.cfg +4 -0
- mapping_scanhelper-0.1.0/src/mapping_scanhelper/__init__.py +4 -0
- mapping_scanhelper-0.1.0/src/mapping_scanhelper/base.py +393 -0
- mapping_scanhelper-0.1.0/src/mapping_scanhelper/logbook.py +283 -0
- mapping_scanhelper-0.1.0/src/mapping_scanhelper.egg-info/PKG-INFO +50 -0
- mapping_scanhelper-0.1.0/src/mapping_scanhelper.egg-info/SOURCES.txt +14 -0
- mapping_scanhelper-0.1.0/src/mapping_scanhelper.egg-info/dependency_links.txt +1 -0
- mapping_scanhelper-0.1.0/src/mapping_scanhelper.egg-info/requires.txt +4 -0
- mapping_scanhelper-0.1.0/src/mapping_scanhelper.egg-info/scm_file_list.json +11 -0
- mapping_scanhelper-0.1.0/src/mapping_scanhelper.egg-info/scm_version.json +8 -0
- mapping_scanhelper-0.1.0/src/mapping_scanhelper.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
image: condaforge/miniforge3
|
|
2
|
+
|
|
3
|
+
stages:
|
|
4
|
+
- style
|
|
5
|
+
- package
|
|
6
|
+
- publish
|
|
7
|
+
|
|
8
|
+
before_script:
|
|
9
|
+
- mamba create -y -q -n ci python=3.12
|
|
10
|
+
- . /opt/conda/bin/activate ci
|
|
11
|
+
|
|
12
|
+
check_style:
|
|
13
|
+
stage: style
|
|
14
|
+
script:
|
|
15
|
+
- pip install black
|
|
16
|
+
- black --check --diff .
|
|
17
|
+
|
|
18
|
+
package:
|
|
19
|
+
stage: package
|
|
20
|
+
variables:
|
|
21
|
+
GIT_DEPTH: 0 # setuptools-scm needs the tags to derive the version
|
|
22
|
+
script:
|
|
23
|
+
- pip install build
|
|
24
|
+
- python -m build
|
|
25
|
+
artifacts:
|
|
26
|
+
paths:
|
|
27
|
+
- dist
|
|
28
|
+
expire_in: 7 days
|
|
29
|
+
interruptible: true
|
|
30
|
+
|
|
31
|
+
pypi:
|
|
32
|
+
stage: publish
|
|
33
|
+
script:
|
|
34
|
+
- pip install twine
|
|
35
|
+
- twine upload dist/*
|
|
36
|
+
rules:
|
|
37
|
+
- if: $CI_COMMIT_TAG =~ /^v?\d+\.\d+\.\d+$/
|
|
38
|
+
interruptible: true
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mapping-scanhelper
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Base for the BLISS scan_helper called by the daiquiri imageviewer actors
|
|
5
|
+
Requires-Python: >=3.9
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Provides-Extra: dev
|
|
8
|
+
Requires-Dist: black; extra == "dev"
|
|
9
|
+
Requires-Dist: flake8-pyproject; extra == "dev"
|
|
10
|
+
|
|
11
|
+
# mapping-scanhelper
|
|
12
|
+
|
|
13
|
+
Base class for a beamline's BLISS `scan_helper`, the env object the bundled daiquiri imageviewer actors call through `session.call`.
|
|
14
|
+
|
|
15
|
+
Install it in the BLISS session environment, subclass `ScanHelperBase` in the beamline package, and register the subclass as a BLISS config object named `scan_helper`:
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from typing import Any
|
|
19
|
+
|
|
20
|
+
from mapping_scanhelper import MeshAxis, ScanHelperBase
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class ScanHelper(ScanHelperBase):
|
|
24
|
+
def get_energy(self):
|
|
25
|
+
...
|
|
26
|
+
|
|
27
|
+
def start_map(
|
|
28
|
+
self,
|
|
29
|
+
*,
|
|
30
|
+
fast: MeshAxis,
|
|
31
|
+
slow: MeshAxis,
|
|
32
|
+
dwell: float,
|
|
33
|
+
detectors: list[Any],
|
|
34
|
+
datacollectionid: int,
|
|
35
|
+
continuous: bool = True,
|
|
36
|
+
fast_motor_mode: str = "REWIND",
|
|
37
|
+
**extra,
|
|
38
|
+
):
|
|
39
|
+
...
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```yaml
|
|
43
|
+
- name: scan_helper
|
|
44
|
+
plugin: bliss
|
|
45
|
+
class: ScanHelper
|
|
46
|
+
package: id21.daiquiri.scan_helper
|
|
47
|
+
config: {}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
The base provides `move_sample_stage` / `move_sample_stage_3d` (`umv`), a no-op `sample_light`, `logbook_message` / `logbook_image`, and `logbook_scan_message`, which calls `logbook_<command>` (`logbook_map`, `logbook_map_patch`, `logbook_map_stack`) from the logbook mixin or the beamline. `get_energy` and the `start_*` functions a beamline's actors use must be overridden; the others raise "not supported". The argument conventions are in the `ScanHelperBase` docstrings and in daiquiri's `BUNDLED_ACTORS_PLAN.md` (section 1b).
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# mapping-scanhelper
|
|
2
|
+
|
|
3
|
+
Base class for a beamline's BLISS `scan_helper`, the env object the bundled daiquiri imageviewer actors call through `session.call`.
|
|
4
|
+
|
|
5
|
+
Install it in the BLISS session environment, subclass `ScanHelperBase` in the beamline package, and register the subclass as a BLISS config object named `scan_helper`:
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
from mapping_scanhelper import MeshAxis, ScanHelperBase
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class ScanHelper(ScanHelperBase):
|
|
14
|
+
def get_energy(self):
|
|
15
|
+
...
|
|
16
|
+
|
|
17
|
+
def start_map(
|
|
18
|
+
self,
|
|
19
|
+
*,
|
|
20
|
+
fast: MeshAxis,
|
|
21
|
+
slow: MeshAxis,
|
|
22
|
+
dwell: float,
|
|
23
|
+
detectors: list[Any],
|
|
24
|
+
datacollectionid: int,
|
|
25
|
+
continuous: bool = True,
|
|
26
|
+
fast_motor_mode: str = "REWIND",
|
|
27
|
+
**extra,
|
|
28
|
+
):
|
|
29
|
+
...
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```yaml
|
|
33
|
+
- name: scan_helper
|
|
34
|
+
plugin: bliss
|
|
35
|
+
class: ScanHelper
|
|
36
|
+
package: id21.daiquiri.scan_helper
|
|
37
|
+
config: {}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The base provides `move_sample_stage` / `move_sample_stage_3d` (`umv`), a no-op `sample_light`, `logbook_message` / `logbook_image`, and `logbook_scan_message`, which calls `logbook_<command>` (`logbook_map`, `logbook_map_patch`, `logbook_map_stack`) from the logbook mixin or the beamline. `get_energy` and the `start_*` functions a beamline's actors use must be overridden; the others raise "not supported". The argument conventions are in the `ScanHelperBase` docstrings and in daiquiri's `BUNDLED_ACTORS_PLAN.md` (section 1b).
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=64", "setuptools-scm>=8"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "mapping-scanhelper"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Base for the BLISS scan_helper called by the daiquiri imageviewer actors"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
# bliss is provided by the BLISS session environment
|
|
12
|
+
dependencies = []
|
|
13
|
+
|
|
14
|
+
[project.optional-dependencies]
|
|
15
|
+
dev = ["black", "flake8-pyproject"]
|
|
16
|
+
|
|
17
|
+
[tool.setuptools_scm]
|
|
18
|
+
|
|
19
|
+
[tool.setuptools.packages.find]
|
|
20
|
+
where = ["src"]
|
|
21
|
+
|
|
22
|
+
[tool.flake8]
|
|
23
|
+
# let black handle formatting
|
|
24
|
+
extend-ignore = ["E501", "W503", "E203"]
|
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
import base64
|
|
2
|
+
from typing import Any, Optional, TypedDict, Union
|
|
3
|
+
|
|
4
|
+
from bliss import current_session
|
|
5
|
+
from bliss.common.axis import Axis
|
|
6
|
+
from bliss.shell.standard import umv
|
|
7
|
+
|
|
8
|
+
# BLISS counters / controllers to acquire with
|
|
9
|
+
Detectors = list[Any]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class MeshAxis(TypedDict):
|
|
13
|
+
"""One axis of a map, the `fast` or `slow` argument"""
|
|
14
|
+
|
|
15
|
+
axis: Axis
|
|
16
|
+
"""Motor to scan"""
|
|
17
|
+
start: float
|
|
18
|
+
"""Object edge"""
|
|
19
|
+
end: float
|
|
20
|
+
"""Object far edge"""
|
|
21
|
+
step_size: float
|
|
22
|
+
"""Step size"""
|
|
23
|
+
steps: int
|
|
24
|
+
"""Number of points (not intervals)"""
|
|
25
|
+
offset: float
|
|
26
|
+
"""Half step, applied as the scan type needs"""
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class ScanHelperBase:
|
|
30
|
+
"""Base for a beamline's BLISS `scan_helper`, the env object the bundled
|
|
31
|
+
daiquiri imageviewer actors call through `session.call`
|
|
32
|
+
|
|
33
|
+
A beamline subclasses it, overrides the `start_*` functions its actors use
|
|
34
|
+
and `get_energy`, and registers it as a BLISS config object named
|
|
35
|
+
`scan_helper`. `start_*` functions it doesn't override raise, so an actor
|
|
36
|
+
configured for a scan the beamline can't run fails with a clear message.
|
|
37
|
+
|
|
38
|
+
Arguments come from daiquiri as keyword arguments. Each map axis is a
|
|
39
|
+
`MeshAxis`. Unless a function says otherwise, positions, step sizes and
|
|
40
|
+
offsets are in the motor's units. Arguments a beamline doesn't use arrive
|
|
41
|
+
in `**extra`.
|
|
42
|
+
|
|
43
|
+
`start_*` functions return the scan without running it.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
def __init__(self, name: str, config_tree: dict):
|
|
47
|
+
"""
|
|
48
|
+
Args:
|
|
49
|
+
name: BLISS object name, `scan_helper`
|
|
50
|
+
config_tree: the object's BLISS config; its `config` key is kept
|
|
51
|
+
as `self._config`
|
|
52
|
+
"""
|
|
53
|
+
self.name = name
|
|
54
|
+
self._config = config_tree.get("config") or {}
|
|
55
|
+
|
|
56
|
+
def __info__(self) -> str:
|
|
57
|
+
return f"Scan Helper ({type(self).__name__})\n"
|
|
58
|
+
|
|
59
|
+
def _not_supported(self, function: str):
|
|
60
|
+
raise NotImplementedError(f"`{self.name}` does not provide `{function}`")
|
|
61
|
+
|
|
62
|
+
# -----------------------------------------------------------------------------------
|
|
63
|
+
# Sample stage
|
|
64
|
+
|
|
65
|
+
def move_sample_stage(self, *motor_positions: Union[Axis, float]):
|
|
66
|
+
"""Move to an object
|
|
67
|
+
|
|
68
|
+
Args:
|
|
69
|
+
motor_positions: motor1, pos1, motor2, pos2, ...
|
|
70
|
+
"""
|
|
71
|
+
umv(*motor_positions)
|
|
72
|
+
|
|
73
|
+
def move_sample_stage_3d(self, *motor_positions: Union[Axis, float]):
|
|
74
|
+
"""Move to an object on a 3D (rotation) stage
|
|
75
|
+
|
|
76
|
+
Args:
|
|
77
|
+
motor_positions: motor1, pos1, motor2, pos2, ...
|
|
78
|
+
"""
|
|
79
|
+
self.move_sample_stage(*motor_positions)
|
|
80
|
+
|
|
81
|
+
def sample_light(self, on: bool):
|
|
82
|
+
"""Switch the sample illumination around the live snapshot
|
|
83
|
+
|
|
84
|
+
Does nothing by default, for beamlines without sample illumination.
|
|
85
|
+
|
|
86
|
+
Args:
|
|
87
|
+
on: `True` before the snapshot, `False` after it
|
|
88
|
+
"""
|
|
89
|
+
|
|
90
|
+
# -----------------------------------------------------------------------------------
|
|
91
|
+
# Info
|
|
92
|
+
|
|
93
|
+
def get_energy(self) -> float:
|
|
94
|
+
"""Current beam energy in keV"""
|
|
95
|
+
self._not_supported("get_energy")
|
|
96
|
+
|
|
97
|
+
# -----------------------------------------------------------------------------------
|
|
98
|
+
# Logbook
|
|
99
|
+
|
|
100
|
+
def logbook_scan_message(self, command: str, parameters: list):
|
|
101
|
+
"""Call the logbook method for a scan
|
|
102
|
+
|
|
103
|
+
Args:
|
|
104
|
+
command: `map`, `map_patch`, `map_stack` or `map3d`; calls `logbook_<command>`,
|
|
105
|
+
which the logbook mixin or the beamline provides
|
|
106
|
+
parameters: passed positionally to `logbook_<command>`
|
|
107
|
+
"""
|
|
108
|
+
function = getattr(self, f"logbook_{command}", None)
|
|
109
|
+
if function is None:
|
|
110
|
+
self._not_supported(f"logbook_{command}")
|
|
111
|
+
return function(*parameters)
|
|
112
|
+
|
|
113
|
+
def logbook_message(self, message: str, msg_type: str):
|
|
114
|
+
"""Send a message to the elogbook
|
|
115
|
+
|
|
116
|
+
Args:
|
|
117
|
+
message: message text
|
|
118
|
+
msg_type: elogbook message type, e.g. `info`, `error`
|
|
119
|
+
"""
|
|
120
|
+
elogbook = current_session.scan_saving.elogbook
|
|
121
|
+
elogbook.send_message(message, msg_type=msg_type)
|
|
122
|
+
|
|
123
|
+
def logbook_image(self, sample_name: str, image_b64: str):
|
|
124
|
+
"""Send an image to the elogbook
|
|
125
|
+
|
|
126
|
+
Args:
|
|
127
|
+
sample_name: sample the image belongs to, used in the message
|
|
128
|
+
image_b64: PNG as a base64 data URL
|
|
129
|
+
"""
|
|
130
|
+
blob = image_b64[image_b64.find("base64") + 7 :]
|
|
131
|
+
blob = base64.b64decode(blob)
|
|
132
|
+
|
|
133
|
+
elogbook = current_session.scan_saving.elogbook
|
|
134
|
+
elogbook.send_binary_data(blob, mimetype="image/png")
|
|
135
|
+
elogbook.send_message(
|
|
136
|
+
f"Saved current acquisition image for sample {sample_name}"
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
# -----------------------------------------------------------------------------------
|
|
140
|
+
# Maps
|
|
141
|
+
|
|
142
|
+
def start_map(
|
|
143
|
+
self,
|
|
144
|
+
*,
|
|
145
|
+
fast: MeshAxis,
|
|
146
|
+
slow: MeshAxis,
|
|
147
|
+
dwell: float,
|
|
148
|
+
detectors: Detectors,
|
|
149
|
+
datacollectionid: int,
|
|
150
|
+
continuous: bool = True,
|
|
151
|
+
fast_motor_mode: str = "REWIND",
|
|
152
|
+
**extra,
|
|
153
|
+
):
|
|
154
|
+
"""2D map
|
|
155
|
+
|
|
156
|
+
Args:
|
|
157
|
+
fast: fast axis
|
|
158
|
+
slow: slow axis
|
|
159
|
+
dwell: count time per point in s
|
|
160
|
+
detectors: counters / controllers to acquire with
|
|
161
|
+
datacollectionid: daiquiri datacollection id, for the scan's `scan_info`
|
|
162
|
+
continuous: continuous scan, otherwise step scan
|
|
163
|
+
fast_motor_mode: `REWIND` or `ZIGZAG`; raise for a combination the
|
|
164
|
+
beamline can't run
|
|
165
|
+
"""
|
|
166
|
+
self._not_supported("start_map")
|
|
167
|
+
|
|
168
|
+
def start_map_patch(
|
|
169
|
+
self,
|
|
170
|
+
*,
|
|
171
|
+
fast: MeshAxis,
|
|
172
|
+
slow: MeshAxis,
|
|
173
|
+
fast_fine: Axis,
|
|
174
|
+
slow_fine: Axis,
|
|
175
|
+
patches: list[int],
|
|
176
|
+
patch_size: list[float],
|
|
177
|
+
dwell: float,
|
|
178
|
+
detectors: Detectors,
|
|
179
|
+
datacollectionid: int,
|
|
180
|
+
fast_motor_mode: str = "REWIND",
|
|
181
|
+
**extra,
|
|
182
|
+
):
|
|
183
|
+
"""Map split into patches: the coarse motors move between patches and
|
|
184
|
+
the fine motors scan inside a patch
|
|
185
|
+
|
|
186
|
+
Args:
|
|
187
|
+
fast: fast axis on the coarse motor; `start`, `end` and `offset`
|
|
188
|
+
in coarse motor units, `step_size` in µm for the fine motor,
|
|
189
|
+
`steps` per patch
|
|
190
|
+
slow: slow axis, as `fast`
|
|
191
|
+
fast_fine: fast axis fine motor
|
|
192
|
+
slow_fine: slow axis fine motor
|
|
193
|
+
patches: number of patches, fast then slow
|
|
194
|
+
patch_size: patch size, fast then slow, coarse motor units
|
|
195
|
+
dwell: count time per point in s
|
|
196
|
+
detectors: counters / controllers to acquire with
|
|
197
|
+
datacollectionid: daiquiri datacollection id, for the scan's `scan_info`
|
|
198
|
+
fast_motor_mode: `REWIND` or `ZIGZAG`
|
|
199
|
+
"""
|
|
200
|
+
self._not_supported("start_map_patch")
|
|
201
|
+
|
|
202
|
+
def start_map_stack(
|
|
203
|
+
self,
|
|
204
|
+
*,
|
|
205
|
+
fast: MeshAxis,
|
|
206
|
+
slow: MeshAxis,
|
|
207
|
+
reference: float,
|
|
208
|
+
min_e: float,
|
|
209
|
+
intervals: list[dict[str, float]],
|
|
210
|
+
detectors: Detectors,
|
|
211
|
+
datacollectionid: int,
|
|
212
|
+
continuous: bool = True,
|
|
213
|
+
fast_motor_mode: str = "REWIND",
|
|
214
|
+
**extra,
|
|
215
|
+
):
|
|
216
|
+
"""One 2D map per energy point
|
|
217
|
+
|
|
218
|
+
Args:
|
|
219
|
+
fast: fast axis
|
|
220
|
+
slow: slow axis
|
|
221
|
+
reference: edge energy in keV
|
|
222
|
+
min_e: lowest region start in eV, relative to `reference`
|
|
223
|
+
intervals: energy points as `{"energy": eV, "dwell": s}`
|
|
224
|
+
detectors: counters / controllers to acquire with
|
|
225
|
+
datacollectionid: daiquiri datacollection id, for the scan's `scan_info`
|
|
226
|
+
continuous: continuous maps, otherwise step maps
|
|
227
|
+
fast_motor_mode: `REWIND` or `ZIGZAG`
|
|
228
|
+
"""
|
|
229
|
+
self._not_supported("start_map_stack")
|
|
230
|
+
|
|
231
|
+
def start_map3d(
|
|
232
|
+
self,
|
|
233
|
+
*,
|
|
234
|
+
fast: MeshAxis,
|
|
235
|
+
slow: MeshAxis,
|
|
236
|
+
rotation_start: float,
|
|
237
|
+
rotation_range: float,
|
|
238
|
+
rotation_n: int,
|
|
239
|
+
dwell: float,
|
|
240
|
+
detectors: Detectors,
|
|
241
|
+
datacollectionid: int,
|
|
242
|
+
continuous: bool = True,
|
|
243
|
+
fast_motor_mode: str = "REWIND",
|
|
244
|
+
fast_axis: str = "Horizontal",
|
|
245
|
+
**extra,
|
|
246
|
+
):
|
|
247
|
+
"""2D map at each rotation angle
|
|
248
|
+
|
|
249
|
+
Args:
|
|
250
|
+
fast: fast linear axis
|
|
251
|
+
slow: slow linear axis
|
|
252
|
+
rotation_start: first angle in degrees
|
|
253
|
+
rotation_range: angular range in degrees
|
|
254
|
+
rotation_n: number of projections
|
|
255
|
+
dwell: count time per point in s
|
|
256
|
+
detectors: counters / controllers to acquire with
|
|
257
|
+
datacollectionid: daiquiri datacollection id, for the scan's `scan_info`
|
|
258
|
+
continuous: continuous scan, otherwise step scan
|
|
259
|
+
fast_motor_mode: `REWIND` or `ZIGZAG`
|
|
260
|
+
fast_axis: `Horizontal`, `Vertical` or `Rotation`. With `Rotation`
|
|
261
|
+
the linear axes come horizontal first; raise if the
|
|
262
|
+
beamline can't scan with rotation fast
|
|
263
|
+
"""
|
|
264
|
+
self._not_supported("start_map3d")
|
|
265
|
+
|
|
266
|
+
# -----------------------------------------------------------------------------------
|
|
267
|
+
# Points
|
|
268
|
+
|
|
269
|
+
def start_point(
|
|
270
|
+
self,
|
|
271
|
+
*,
|
|
272
|
+
detectors: Detectors,
|
|
273
|
+
datacollectionid: int,
|
|
274
|
+
**extra,
|
|
275
|
+
):
|
|
276
|
+
"""Acquire at a point
|
|
277
|
+
|
|
278
|
+
Args:
|
|
279
|
+
detectors: counters / controllers to acquire with
|
|
280
|
+
datacollectionid: daiquiri datacollection id, for the scan's `scan_info`
|
|
281
|
+
"""
|
|
282
|
+
self._not_supported("start_point")
|
|
283
|
+
|
|
284
|
+
# -----------------------------------------------------------------------------------
|
|
285
|
+
# Spectroscopy
|
|
286
|
+
#
|
|
287
|
+
# The scan runs from `reference + start_e` to `reference + end_e`, all in
|
|
288
|
+
# keV, in `intervals` intervals.
|
|
289
|
+
|
|
290
|
+
def start_xanes(
|
|
291
|
+
self,
|
|
292
|
+
*,
|
|
293
|
+
reference: float,
|
|
294
|
+
start_e: float,
|
|
295
|
+
end_e: float,
|
|
296
|
+
intervals: int,
|
|
297
|
+
dwell: float,
|
|
298
|
+
detectors: Detectors,
|
|
299
|
+
repeats: int,
|
|
300
|
+
repeat_continue: bool,
|
|
301
|
+
datacollectionid: int,
|
|
302
|
+
**extra,
|
|
303
|
+
):
|
|
304
|
+
"""Energy scan at a point
|
|
305
|
+
|
|
306
|
+
Args:
|
|
307
|
+
reference: edge energy in keV
|
|
308
|
+
start_e: region start in keV, relative to `reference`
|
|
309
|
+
end_e: region end in keV, relative to `reference`
|
|
310
|
+
intervals: number of energy intervals
|
|
311
|
+
dwell: count time per point in s
|
|
312
|
+
detectors: counters / controllers to acquire with
|
|
313
|
+
repeats: number of times to run the scan
|
|
314
|
+
repeat_continue: keep repeating after a failed scan
|
|
315
|
+
datacollectionid: daiquiri datacollection id, for the scan's `scan_info`
|
|
316
|
+
"""
|
|
317
|
+
self._not_supported("start_xanes")
|
|
318
|
+
|
|
319
|
+
def start_axanes(
|
|
320
|
+
self,
|
|
321
|
+
*,
|
|
322
|
+
reference: float,
|
|
323
|
+
start_e: float,
|
|
324
|
+
end_e: float,
|
|
325
|
+
intervals: int,
|
|
326
|
+
fast: MeshAxis,
|
|
327
|
+
slow: MeshAxis,
|
|
328
|
+
dwell: float,
|
|
329
|
+
detectors: Detectors,
|
|
330
|
+
point_continue: bool,
|
|
331
|
+
datacollectionid: int,
|
|
332
|
+
**extra,
|
|
333
|
+
):
|
|
334
|
+
"""Energy scan at each point of a 2D grid, point by point
|
|
335
|
+
|
|
336
|
+
Args:
|
|
337
|
+
reference: edge energy in keV
|
|
338
|
+
start_e: region start in keV, relative to `reference`
|
|
339
|
+
end_e: region end in keV, relative to `reference`
|
|
340
|
+
intervals: number of energy intervals
|
|
341
|
+
fast: horizontal axis
|
|
342
|
+
slow: vertical axis
|
|
343
|
+
dwell: count time per point in s
|
|
344
|
+
detectors: counters / controllers to acquire with
|
|
345
|
+
point_continue: continue with the next point after a failed scan
|
|
346
|
+
datacollectionid: daiquiri datacollection id, for the scan's `scan_info`
|
|
347
|
+
"""
|
|
348
|
+
self._not_supported("start_axanes")
|
|
349
|
+
|
|
350
|
+
def start_lxanes(
|
|
351
|
+
self,
|
|
352
|
+
*,
|
|
353
|
+
reference: float,
|
|
354
|
+
start_e: float,
|
|
355
|
+
end_e: float,
|
|
356
|
+
intervals: int,
|
|
357
|
+
has_x: bool,
|
|
358
|
+
x_motor: Optional[Axis],
|
|
359
|
+
x_start: Optional[float],
|
|
360
|
+
x_step_size: float,
|
|
361
|
+
has_y: bool,
|
|
362
|
+
y_motor: Optional[Axis],
|
|
363
|
+
y_start: Optional[float],
|
|
364
|
+
y_step_size: float,
|
|
365
|
+
steps: int,
|
|
366
|
+
dwell: float,
|
|
367
|
+
detectors: Detectors,
|
|
368
|
+
point_continue: bool,
|
|
369
|
+
datacollectionid: int,
|
|
370
|
+
**extra,
|
|
371
|
+
):
|
|
372
|
+
"""Energy scan at each point along a line
|
|
373
|
+
|
|
374
|
+
Args:
|
|
375
|
+
reference: edge energy in keV
|
|
376
|
+
start_e: region start in keV, relative to `reference`
|
|
377
|
+
end_e: region end in keV, relative to `reference`
|
|
378
|
+
intervals: number of energy intervals
|
|
379
|
+
has_x: the line moves horizontally
|
|
380
|
+
x_motor: horizontal motor, `None` if unused
|
|
381
|
+
x_start: horizontal line start, `None` if unused
|
|
382
|
+
x_step_size: horizontal step between points
|
|
383
|
+
has_y: the line moves vertically
|
|
384
|
+
y_motor: vertical motor, `None` if unused
|
|
385
|
+
y_start: vertical line start, `None` if unused
|
|
386
|
+
y_step_size: vertical step between points
|
|
387
|
+
steps: number of points along the line
|
|
388
|
+
dwell: count time per point in s
|
|
389
|
+
detectors: counters / controllers to acquire with
|
|
390
|
+
point_continue: continue with the next point after a failed scan
|
|
391
|
+
datacollectionid: daiquiri datacollection id, for the scan's `scan_info`
|
|
392
|
+
"""
|
|
393
|
+
self._not_supported("start_lxanes")
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import pprint
|
|
3
|
+
from typing import Any, Optional
|
|
4
|
+
|
|
5
|
+
from bliss import current_session
|
|
6
|
+
|
|
7
|
+
logger = logging.getLogger(__name__)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class LogbookMixin:
|
|
11
|
+
"""Logbook messages for the scans started by the daiquiri imageviewer actors
|
|
12
|
+
|
|
13
|
+
`ScanHelperBase.logbook_scan_message` calls `logbook_<command>` with the
|
|
14
|
+
parameters daiquiri sends. Each message method lists its own lines and
|
|
15
|
+
`logbook_scan` adds the parts every message shares. A beamline mixes this
|
|
16
|
+
into its `scan_helper` and overrides a message method to change or skip
|
|
17
|
+
one message, or a shared part: `logbook_extra_info` (beamline lines, empty
|
|
18
|
+
by default), `logbook_dataset`, `logbook_energy` or `logbook_parameters`:
|
|
19
|
+
|
|
20
|
+
class ScanHelper(LogbookMixin, ScanHelperBase):
|
|
21
|
+
def logbook_extra_info(self) -> str:
|
|
22
|
+
return f"iodet gain: {setup_globals.iodet.gain}\\n"
|
|
23
|
+
|
|
24
|
+
`steps_x` / `steps_y` are the requested number of points per axis, which
|
|
25
|
+
can differ from what the scan command takes (points or intervals).
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
def logbook_send(self, message: str):
|
|
29
|
+
"""Send a message to the elogbook, logging rather than raising on failure"""
|
|
30
|
+
try:
|
|
31
|
+
current_session.scan_saving.elogbook.send_message(message)
|
|
32
|
+
except Exception as e:
|
|
33
|
+
logger.error(f"Could not save parameters to elogbook: {str(e)}")
|
|
34
|
+
|
|
35
|
+
def logbook_extra_info(self) -> str:
|
|
36
|
+
"""Beamline lines added to every scan message, one per line"""
|
|
37
|
+
return ""
|
|
38
|
+
|
|
39
|
+
def logbook_dataset(self) -> str:
|
|
40
|
+
"""The current scan saving file"""
|
|
41
|
+
return current_session.scan_saving.filename
|
|
42
|
+
|
|
43
|
+
def logbook_energy(self) -> str:
|
|
44
|
+
"""The energy in keV, from `get_energy`"""
|
|
45
|
+
try:
|
|
46
|
+
return f"{self.get_energy()}"
|
|
47
|
+
except Exception as e:
|
|
48
|
+
logger.warning(f"Could not read energy for the logbook: {str(e)}")
|
|
49
|
+
return "unknown"
|
|
50
|
+
|
|
51
|
+
def logbook_parameters(self, parameters: Optional[dict]) -> str:
|
|
52
|
+
"""Beamline parameters block, one parameter per line"""
|
|
53
|
+
if not parameters:
|
|
54
|
+
return ""
|
|
55
|
+
lines = "".join(f" {name}: {value}\n" for name, value in parameters.items())
|
|
56
|
+
return f"parameters:\n{lines}"
|
|
57
|
+
|
|
58
|
+
def _logbook_extra_info(self) -> str:
|
|
59
|
+
try:
|
|
60
|
+
return self.logbook_extra_info()
|
|
61
|
+
except Exception as e:
|
|
62
|
+
logger.warning(f"Could not get logbook extra info: {str(e)}")
|
|
63
|
+
return ""
|
|
64
|
+
|
|
65
|
+
def logbook_scan(
|
|
66
|
+
self,
|
|
67
|
+
title: str,
|
|
68
|
+
motor_positions: str,
|
|
69
|
+
fields: dict[str, Any],
|
|
70
|
+
parameters: Optional[dict] = None,
|
|
71
|
+
):
|
|
72
|
+
"""Send a scan message: the title, motors and dataset, the scan's own
|
|
73
|
+
lines, then the extra info and beamline parameters
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
title: scan description, after "Starting"
|
|
77
|
+
motor_positions: object position as text, one motor per line
|
|
78
|
+
fields: the scan's own lines as `label: value`, in order
|
|
79
|
+
parameters: chosen beamline parameters
|
|
80
|
+
"""
|
|
81
|
+
parts = [
|
|
82
|
+
f"Starting {title}",
|
|
83
|
+
"motors:",
|
|
84
|
+
motor_positions,
|
|
85
|
+
f"dataset: {self.logbook_dataset()}",
|
|
86
|
+
*(self._logbook_field(label, value) for label, value in fields.items()),
|
|
87
|
+
self._logbook_extra_info(),
|
|
88
|
+
self.logbook_parameters(parameters),
|
|
89
|
+
]
|
|
90
|
+
# One part per line, skipping empty parts so there are no blank lines
|
|
91
|
+
self.logbook_send(
|
|
92
|
+
"\n".join(p.strip("\n") for p in parts if p and p.strip()) + "\n"
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
@staticmethod
|
|
96
|
+
def _logbook_field(label: str, value: Any) -> str:
|
|
97
|
+
# Multi-line values start on the line after the label
|
|
98
|
+
text = str(value)
|
|
99
|
+
if text.startswith("\n"):
|
|
100
|
+
return f"{label}:{text}"
|
|
101
|
+
return f"{label}: {text}"
|
|
102
|
+
|
|
103
|
+
def _map_fields(
|
|
104
|
+
self,
|
|
105
|
+
detectors: Optional[list[str]],
|
|
106
|
+
steps_x: int,
|
|
107
|
+
steps_y: int,
|
|
108
|
+
step_size_x: float,
|
|
109
|
+
step_size_y: float,
|
|
110
|
+
) -> dict[str, Any]:
|
|
111
|
+
fields = {}
|
|
112
|
+
if detectors is not None:
|
|
113
|
+
fields["detectors"] = ",".join(detectors)
|
|
114
|
+
fields.update(
|
|
115
|
+
{
|
|
116
|
+
"steps_x": steps_x,
|
|
117
|
+
"steps_y": steps_y,
|
|
118
|
+
"step_size_x in um": step_size_x,
|
|
119
|
+
"step_size_y in um": step_size_y,
|
|
120
|
+
}
|
|
121
|
+
)
|
|
122
|
+
return fields
|
|
123
|
+
|
|
124
|
+
def logbook_map(
|
|
125
|
+
self,
|
|
126
|
+
steps_x: int,
|
|
127
|
+
steps_y: int,
|
|
128
|
+
step_size_x: float,
|
|
129
|
+
step_size_y: float,
|
|
130
|
+
dwell: float,
|
|
131
|
+
detectors: list[str],
|
|
132
|
+
motor_positions: str,
|
|
133
|
+
parameters: Optional[dict] = None,
|
|
134
|
+
):
|
|
135
|
+
"""Message for a 2D map
|
|
136
|
+
|
|
137
|
+
Args:
|
|
138
|
+
steps_x: requested number of points, horizontal
|
|
139
|
+
steps_y: requested number of points, vertical
|
|
140
|
+
step_size_x: horizontal step size in µm
|
|
141
|
+
step_size_y: vertical step size in µm
|
|
142
|
+
dwell: count time per point in s
|
|
143
|
+
detectors: detector names
|
|
144
|
+
motor_positions: object position as text, one motor per line
|
|
145
|
+
parameters: chosen beamline parameters
|
|
146
|
+
"""
|
|
147
|
+
self.logbook_scan(
|
|
148
|
+
"XRF_2Dmap",
|
|
149
|
+
motor_positions,
|
|
150
|
+
{
|
|
151
|
+
**self._map_fields(
|
|
152
|
+
detectors, steps_x, steps_y, step_size_x, step_size_y
|
|
153
|
+
),
|
|
154
|
+
"dwell time in sec": dwell,
|
|
155
|
+
"energy in keV": self.logbook_energy(),
|
|
156
|
+
},
|
|
157
|
+
parameters,
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
def logbook_map_patch(
|
|
161
|
+
self,
|
|
162
|
+
patches_x: int,
|
|
163
|
+
patches_y: int,
|
|
164
|
+
patch_size_x: float,
|
|
165
|
+
patch_size_y: float,
|
|
166
|
+
steps_x: int,
|
|
167
|
+
steps_y: int,
|
|
168
|
+
step_size_x: float,
|
|
169
|
+
step_size_y: float,
|
|
170
|
+
dwell: float,
|
|
171
|
+
motor_positions: str,
|
|
172
|
+
parameters: Optional[dict] = None,
|
|
173
|
+
):
|
|
174
|
+
"""Message for a map split into patches
|
|
175
|
+
|
|
176
|
+
Args:
|
|
177
|
+
patches_x: number of patches, horizontal
|
|
178
|
+
patches_y: number of patches, vertical
|
|
179
|
+
patch_size_x: patch size in µm, horizontal
|
|
180
|
+
patch_size_y: patch size in µm, vertical
|
|
181
|
+
steps_x: number of points per patch, horizontal
|
|
182
|
+
steps_y: number of points per patch, vertical
|
|
183
|
+
step_size_x: horizontal step size in µm
|
|
184
|
+
step_size_y: vertical step size in µm
|
|
185
|
+
dwell: count time per point in s
|
|
186
|
+
motor_positions: object position as text, one motor per line
|
|
187
|
+
parameters: chosen beamline parameters
|
|
188
|
+
"""
|
|
189
|
+
self.logbook_scan(
|
|
190
|
+
"patched XRF_2Dmap",
|
|
191
|
+
motor_positions,
|
|
192
|
+
{
|
|
193
|
+
"patches_x": patches_x,
|
|
194
|
+
"patches_y": patches_y,
|
|
195
|
+
"patch_size_x in um": patch_size_x,
|
|
196
|
+
"patch_size_y in um": patch_size_y,
|
|
197
|
+
**self._map_fields(None, steps_x, steps_y, step_size_x, step_size_y),
|
|
198
|
+
"dwell time in sec": dwell,
|
|
199
|
+
"energy in keV": self.logbook_energy(),
|
|
200
|
+
},
|
|
201
|
+
parameters,
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
def logbook_map_stack(
|
|
205
|
+
self,
|
|
206
|
+
steps_x: int,
|
|
207
|
+
steps_y: int,
|
|
208
|
+
step_size_x: float,
|
|
209
|
+
step_size_y: float,
|
|
210
|
+
intervals: list[dict],
|
|
211
|
+
detectors: list[str],
|
|
212
|
+
motor_positions: str,
|
|
213
|
+
parameters: Optional[dict] = None,
|
|
214
|
+
):
|
|
215
|
+
"""Message for a stack of 2D maps, one per energy
|
|
216
|
+
|
|
217
|
+
Args:
|
|
218
|
+
steps_x: requested number of points, horizontal
|
|
219
|
+
steps_y: requested number of points, vertical
|
|
220
|
+
step_size_x: horizontal step size in µm
|
|
221
|
+
step_size_y: vertical step size in µm
|
|
222
|
+
intervals: energy points as `{"energy": eV, "dwell": s}`
|
|
223
|
+
detectors: detector names
|
|
224
|
+
motor_positions: object position as text, one motor per line
|
|
225
|
+
parameters: chosen beamline parameters
|
|
226
|
+
"""
|
|
227
|
+
intervals_text = "".join(f"\n {pprint.pformat(i)}" for i in intervals)
|
|
228
|
+
self.logbook_scan(
|
|
229
|
+
"multi energy XRF_2Dmap",
|
|
230
|
+
motor_positions,
|
|
231
|
+
{
|
|
232
|
+
**self._map_fields(
|
|
233
|
+
detectors, steps_x, steps_y, step_size_x, step_size_y
|
|
234
|
+
),
|
|
235
|
+
"intervals": intervals_text,
|
|
236
|
+
},
|
|
237
|
+
parameters,
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
def logbook_map3d(
|
|
241
|
+
self,
|
|
242
|
+
steps_x: int,
|
|
243
|
+
steps_y: int,
|
|
244
|
+
step_size_x: float,
|
|
245
|
+
step_size_y: float,
|
|
246
|
+
dwell: float,
|
|
247
|
+
detectors: list[str],
|
|
248
|
+
motor_positions: str,
|
|
249
|
+
rotation_start: float,
|
|
250
|
+
rotation_range: float,
|
|
251
|
+
rotation_n: int,
|
|
252
|
+
parameters: Optional[dict] = None,
|
|
253
|
+
):
|
|
254
|
+
"""Message for a 2D map at each rotation angle
|
|
255
|
+
|
|
256
|
+
Args:
|
|
257
|
+
steps_x: requested number of points, horizontal
|
|
258
|
+
steps_y: requested number of points, vertical
|
|
259
|
+
step_size_x: horizontal step size in µm
|
|
260
|
+
step_size_y: vertical step size in µm
|
|
261
|
+
dwell: count time per point in s
|
|
262
|
+
detectors: detector names
|
|
263
|
+
motor_positions: object position as text, one motor per line
|
|
264
|
+
rotation_start: first angle in degrees
|
|
265
|
+
rotation_range: angular range in degrees
|
|
266
|
+
rotation_n: number of projections
|
|
267
|
+
parameters: chosen beamline parameters
|
|
268
|
+
"""
|
|
269
|
+
self.logbook_scan(
|
|
270
|
+
"XRF_3Dmap",
|
|
271
|
+
motor_positions,
|
|
272
|
+
{
|
|
273
|
+
**self._map_fields(
|
|
274
|
+
detectors, steps_x, steps_y, step_size_x, step_size_y
|
|
275
|
+
),
|
|
276
|
+
"rotation_start in deg": rotation_start,
|
|
277
|
+
"rotation_range in deg": rotation_range,
|
|
278
|
+
"rotation_n": rotation_n,
|
|
279
|
+
"dwell time in sec": dwell,
|
|
280
|
+
"energy in keV": self.logbook_energy(),
|
|
281
|
+
},
|
|
282
|
+
parameters,
|
|
283
|
+
)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mapping-scanhelper
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Base for the BLISS scan_helper called by the daiquiri imageviewer actors
|
|
5
|
+
Requires-Python: >=3.9
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Provides-Extra: dev
|
|
8
|
+
Requires-Dist: black; extra == "dev"
|
|
9
|
+
Requires-Dist: flake8-pyproject; extra == "dev"
|
|
10
|
+
|
|
11
|
+
# mapping-scanhelper
|
|
12
|
+
|
|
13
|
+
Base class for a beamline's BLISS `scan_helper`, the env object the bundled daiquiri imageviewer actors call through `session.call`.
|
|
14
|
+
|
|
15
|
+
Install it in the BLISS session environment, subclass `ScanHelperBase` in the beamline package, and register the subclass as a BLISS config object named `scan_helper`:
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from typing import Any
|
|
19
|
+
|
|
20
|
+
from mapping_scanhelper import MeshAxis, ScanHelperBase
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class ScanHelper(ScanHelperBase):
|
|
24
|
+
def get_energy(self):
|
|
25
|
+
...
|
|
26
|
+
|
|
27
|
+
def start_map(
|
|
28
|
+
self,
|
|
29
|
+
*,
|
|
30
|
+
fast: MeshAxis,
|
|
31
|
+
slow: MeshAxis,
|
|
32
|
+
dwell: float,
|
|
33
|
+
detectors: list[Any],
|
|
34
|
+
datacollectionid: int,
|
|
35
|
+
continuous: bool = True,
|
|
36
|
+
fast_motor_mode: str = "REWIND",
|
|
37
|
+
**extra,
|
|
38
|
+
):
|
|
39
|
+
...
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```yaml
|
|
43
|
+
- name: scan_helper
|
|
44
|
+
plugin: bliss
|
|
45
|
+
class: ScanHelper
|
|
46
|
+
package: id21.daiquiri.scan_helper
|
|
47
|
+
config: {}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
The base provides `move_sample_stage` / `move_sample_stage_3d` (`umv`), a no-op `sample_light`, `logbook_message` / `logbook_image`, and `logbook_scan_message`, which calls `logbook_<command>` (`logbook_map`, `logbook_map_patch`, `logbook_map_stack`) from the logbook mixin or the beamline. `get_energy` and the `start_*` functions a beamline's actors use must be overridden; the others raise "not supported". The argument conventions are in the `ScanHelperBase` docstrings and in daiquiri's `BUNDLED_ACTORS_PLAN.md` (section 1b).
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
.gitignore
|
|
2
|
+
.gitlab-ci.yml
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
src/mapping_scanhelper/__init__.py
|
|
6
|
+
src/mapping_scanhelper/base.py
|
|
7
|
+
src/mapping_scanhelper/logbook.py
|
|
8
|
+
src/mapping_scanhelper.egg-info/PKG-INFO
|
|
9
|
+
src/mapping_scanhelper.egg-info/SOURCES.txt
|
|
10
|
+
src/mapping_scanhelper.egg-info/dependency_links.txt
|
|
11
|
+
src/mapping_scanhelper.egg-info/requires.txt
|
|
12
|
+
src/mapping_scanhelper.egg-info/scm_file_list.json
|
|
13
|
+
src/mapping_scanhelper.egg-info/scm_version.json
|
|
14
|
+
src/mapping_scanhelper.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
mapping_scanhelper
|