pymodaq_scripting 5.3.7__tar.gz → 5.3.9__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.
- {pymodaq_scripting-5.3.7 → pymodaq_scripting-5.3.9}/PKG-INFO +1 -1
- pymodaq_scripting-5.3.9/src/pymodaq_scripting/devices.py +297 -0
- pymodaq_scripting-5.3.9/src/pymodaq_scripting/py.typed +0 -0
- {pymodaq_scripting-5.3.7 → pymodaq_scripting-5.3.9}/src/pymodaq_scripting/utils.py +1 -1
- pymodaq_scripting-5.3.7/src/pymodaq_scripting/devices.py +0 -107
- {pymodaq_scripting-5.3.7 → pymodaq_scripting-5.3.9}/.gitignore +0 -0
- {pymodaq_scripting-5.3.7 → pymodaq_scripting-5.3.9}/LICENSE +0 -0
- {pymodaq_scripting-5.3.7 → pymodaq_scripting-5.3.9}/README.rst +0 -0
- {pymodaq_scripting-5.3.7 → pymodaq_scripting-5.3.9}/pyproject.toml +0 -0
- {pymodaq_scripting-5.3.7 → pymodaq_scripting-5.3.9}/src/pymodaq_scripting/__init__.py +0 -0
- {pymodaq_scripting-5.3.7 → pymodaq_scripting-5.3.9}/src/pymodaq_scripting/examples/__init__.py +0 -0
- {pymodaq_scripting-5.3.7 → pymodaq_scripting-5.3.9}/src/pymodaq_scripting/examples/dashboard_script.py +0 -0
- {pymodaq_scripting-5.3.7 → pymodaq_scripting-5.3.9}/src/pymodaq_scripting/examples/simple_script.py +0 -0
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
from concurrent.futures import Future
|
|
2
|
+
from typing import Optional, TYPE_CHECKING, Union
|
|
3
|
+
from xml.etree.ElementTree import Element
|
|
4
|
+
from pymodaq_data.data import DataToExport
|
|
5
|
+
from pymodaq_scripting.utils import (
|
|
6
|
+
Device,
|
|
7
|
+
LECOActuatorWrapper,
|
|
8
|
+
LECODetectorWrapper,
|
|
9
|
+
LECODashboardWrapper,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
if TYPE_CHECKING:
|
|
13
|
+
from pymodaq.utils.data import DataActuator
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class Actuator(Device[LECOActuatorWrapper]):
|
|
17
|
+
"""
|
|
18
|
+
Public interface to control an Actuator of a running Dashboard
|
|
19
|
+
|
|
20
|
+
All the commands return at once with a :class:`concurrent.futures.Future`, filled when the Dashboard
|
|
21
|
+
answers: call ``result()`` on it to wait for the answer. A new command of the same kind replaces the
|
|
22
|
+
previous one, whose future then never completes (the four moves share the same future).
|
|
23
|
+
|
|
24
|
+
Parameters
|
|
25
|
+
----------
|
|
26
|
+
device: str
|
|
27
|
+
Name of the actuator in the Dashboard (its title in the experiment)
|
|
28
|
+
**kwargs
|
|
29
|
+
Passed to the LECO ``Director`` (for example the ``host`` of the coordinator)
|
|
30
|
+
|
|
31
|
+
Examples
|
|
32
|
+
--------
|
|
33
|
+
>>> actuator = Actuator('Xaxis')
|
|
34
|
+
>>> actuator.move_abs('1.5 mm').result() # position reached, as a DataActuator
|
|
35
|
+
>>> actuator.get_actuator_value().result()
|
|
36
|
+
"""
|
|
37
|
+
def __init__(self, device: str, **kwargs) -> None:
|
|
38
|
+
super().__init__(LECOActuatorWrapper(device, **kwargs))
|
|
39
|
+
|
|
40
|
+
def get_actuator_value(self) -> Future['DataActuator']:
|
|
41
|
+
""" Ask for the current position of the actuator
|
|
42
|
+
|
|
43
|
+
Returns
|
|
44
|
+
-------
|
|
45
|
+
Future: its result is the position, as a ``DataActuator``
|
|
46
|
+
"""
|
|
47
|
+
return self._wrapper.get_actuator_value()
|
|
48
|
+
|
|
49
|
+
def move_home(self) -> Future['DataActuator']:
|
|
50
|
+
""" Move the actuator to its home position
|
|
51
|
+
|
|
52
|
+
Returns
|
|
53
|
+
-------
|
|
54
|
+
Future: its result is the position once the move is over
|
|
55
|
+
"""
|
|
56
|
+
return self._wrapper.move_home()
|
|
57
|
+
|
|
58
|
+
def move_abs(self, value: Union['DataActuator', int, float, str]) -> Future['DataActuator']:
|
|
59
|
+
""" Move the actuator to an absolute position
|
|
60
|
+
|
|
61
|
+
Parameters
|
|
62
|
+
----------
|
|
63
|
+
value: DataActuator, int, float or str
|
|
64
|
+
The target. A number is sent without units, a string is read with its units (``'1.5 mm'``,
|
|
65
|
+
see :func:`pymodaq_scripting.utils.value_to_data_actuator`).
|
|
66
|
+
|
|
67
|
+
Returns
|
|
68
|
+
-------
|
|
69
|
+
Future: its result is the position once the move is over
|
|
70
|
+
"""
|
|
71
|
+
return self._wrapper.move_abs(value)
|
|
72
|
+
|
|
73
|
+
def move_rel(self, value: Union['DataActuator', int, float, str]) -> Future['DataActuator']:
|
|
74
|
+
""" Move the actuator by a displacement relative to its current position
|
|
75
|
+
|
|
76
|
+
Parameters
|
|
77
|
+
----------
|
|
78
|
+
value: DataActuator, int, float or str
|
|
79
|
+
The displacement, same conversions as in :meth:`move_abs`
|
|
80
|
+
|
|
81
|
+
Returns
|
|
82
|
+
-------
|
|
83
|
+
Future: its result is the position once the move is over
|
|
84
|
+
"""
|
|
85
|
+
return self._wrapper.move_rel(value)
|
|
86
|
+
|
|
87
|
+
def stop_move(self) -> Future['DataActuator']:
|
|
88
|
+
""" Stop the movement of the actuator
|
|
89
|
+
|
|
90
|
+
Returns
|
|
91
|
+
-------
|
|
92
|
+
Future: its result is the position once the actuator is stopped
|
|
93
|
+
"""
|
|
94
|
+
return self._wrapper.stop_move()
|
|
95
|
+
|
|
96
|
+
def get_settings(self) -> Future[Element]:
|
|
97
|
+
""" Ask for the settings of the actuator
|
|
98
|
+
|
|
99
|
+
Returns
|
|
100
|
+
-------
|
|
101
|
+
Future: its result is the settings tree, as an XML ``Element``. It is also kept as the reference
|
|
102
|
+
against which :meth:`set_settings` detects what changed.
|
|
103
|
+
"""
|
|
104
|
+
return self._wrapper.get_settings()
|
|
105
|
+
|
|
106
|
+
def set_settings(self, settings: Element) -> None:
|
|
107
|
+
""" Send the settings that differ from those obtained by the last :meth:`get_settings`
|
|
108
|
+
|
|
109
|
+
Only the parameters whose value or attributes changed are sent. Nothing is sent as long as the answer
|
|
110
|
+
to :meth:`get_settings` has not been received.
|
|
111
|
+
|
|
112
|
+
Parameters
|
|
113
|
+
----------
|
|
114
|
+
settings: Element
|
|
115
|
+
The settings tree returned by :meth:`get_settings`, with some values modified
|
|
116
|
+
"""
|
|
117
|
+
self._wrapper.set_settings(settings)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
class Detector(Device[LECODetectorWrapper]):
|
|
121
|
+
"""
|
|
122
|
+
Public interface to control a Detector of a running Dashboard
|
|
123
|
+
|
|
124
|
+
Parameters
|
|
125
|
+
----------
|
|
126
|
+
device: str
|
|
127
|
+
Name of the detector in the Dashboard (its title in the experiment)
|
|
128
|
+
**kwargs
|
|
129
|
+
Passed to the LECO ``Director`` (for example the ``host`` of the coordinator)
|
|
130
|
+
|
|
131
|
+
Examples
|
|
132
|
+
--------
|
|
133
|
+
>>> detector = Detector('Camera')
|
|
134
|
+
>>> data = detector.snap().result() # a DataToExport
|
|
135
|
+
"""
|
|
136
|
+
def __init__(self, device: str, **kwargs) -> None:
|
|
137
|
+
super().__init__(LECODetectorWrapper(device, **kwargs))
|
|
138
|
+
|
|
139
|
+
def snap(self) -> Optional[Future[DataToExport]]:
|
|
140
|
+
""" Acquire one data set
|
|
141
|
+
|
|
142
|
+
Returns
|
|
143
|
+
-------
|
|
144
|
+
Future or None: its result is the acquired ``DataToExport``. None, and nothing is asked, while a
|
|
145
|
+
continuous grab started by :meth:`grab` is running.
|
|
146
|
+
"""
|
|
147
|
+
return self._wrapper.snap()
|
|
148
|
+
|
|
149
|
+
def grab(self, keep: bool = False) -> Optional[list[DataToExport]]:
|
|
150
|
+
""" Start a continuous acquisition, or stop it when one is running (each call toggles)
|
|
151
|
+
|
|
152
|
+
Parameters
|
|
153
|
+
----------
|
|
154
|
+
keep: bool
|
|
155
|
+
If True, the data sets received while grabbing are appended to the returned list. Only used by
|
|
156
|
+
the call starting the grab.
|
|
157
|
+
|
|
158
|
+
Returns
|
|
159
|
+
-------
|
|
160
|
+
list or None: when starting with ``keep=True``, the list filling up with the acquired ``DataToExport``;
|
|
161
|
+
None otherwise (``keep=False``, or the call stopping the grab).
|
|
162
|
+
"""
|
|
163
|
+
return self._wrapper.grab(keep=keep)
|
|
164
|
+
|
|
165
|
+
def stop_grab(self) -> None:
|
|
166
|
+
""" Stop the continuous acquisition """
|
|
167
|
+
return self._wrapper.stop_grab()
|
|
168
|
+
|
|
169
|
+
def get_settings(self) -> Future[Element]:
|
|
170
|
+
""" Ask for the settings of the detector
|
|
171
|
+
|
|
172
|
+
Returns
|
|
173
|
+
-------
|
|
174
|
+
Future: its result is the settings tree, as an XML ``Element``. It is also kept as the reference
|
|
175
|
+
against which :meth:`set_settings` detects what changed.
|
|
176
|
+
"""
|
|
177
|
+
return self._wrapper.get_settings()
|
|
178
|
+
|
|
179
|
+
def set_settings(self, settings: Element) -> None:
|
|
180
|
+
""" Send the settings that differ from those obtained by the last :meth:`get_settings`
|
|
181
|
+
|
|
182
|
+
Only the parameters whose value or attributes changed are sent. Nothing is sent as long as the answer
|
|
183
|
+
to :meth:`get_settings` has not been received.
|
|
184
|
+
|
|
185
|
+
Parameters
|
|
186
|
+
----------
|
|
187
|
+
settings: Element
|
|
188
|
+
The settings tree returned by :meth:`get_settings`, with some values modified
|
|
189
|
+
"""
|
|
190
|
+
self._wrapper.set_settings(settings)
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
class Dashboard(Device[LECODashboardWrapper]):
|
|
194
|
+
"""
|
|
195
|
+
Public interface to control a Dashboard
|
|
196
|
+
|
|
197
|
+
Parameters
|
|
198
|
+
----------
|
|
199
|
+
**kwargs
|
|
200
|
+
Passed to the LECO ``Director`` (for example the ``host`` of the coordinator)
|
|
201
|
+
|
|
202
|
+
Examples
|
|
203
|
+
--------
|
|
204
|
+
>>> dashboard = Dashboard()
|
|
205
|
+
>>> dashboard.apply_experiment('my_experiment').result() # True once applied
|
|
206
|
+
>>> devices = dashboard.get_scripting_devices()
|
|
207
|
+
>>> devices['actuators']['Xaxis'].move_abs('1 mm').result()
|
|
208
|
+
"""
|
|
209
|
+
|
|
210
|
+
def __init__(self, **kwargs) -> None:
|
|
211
|
+
super().__init__(LECODashboardWrapper(**kwargs))
|
|
212
|
+
|
|
213
|
+
@property
|
|
214
|
+
def leco_name(self) -> str:
|
|
215
|
+
""" Name under which this script is known on the LECO network"""
|
|
216
|
+
return self._wrapper.leco_name
|
|
217
|
+
|
|
218
|
+
@property
|
|
219
|
+
def name(self) -> str:
|
|
220
|
+
""" Name of the Dashboard on the LECO network"""
|
|
221
|
+
return self._wrapper.name
|
|
222
|
+
|
|
223
|
+
def sign_out(self) -> None:
|
|
224
|
+
""" Sign this script out of the LECO coordinator (done automatically when Python exits)"""
|
|
225
|
+
self._wrapper.sign_out()
|
|
226
|
+
|
|
227
|
+
def get_devices(self) -> Future[dict[str, list[str]]]:
|
|
228
|
+
""" Ask for the names of the instruments of the applied experiment
|
|
229
|
+
|
|
230
|
+
Returns
|
|
231
|
+
-------
|
|
232
|
+
Future: its result is a dict with the keys ``'actuators'`` and ``'detectors'``, each holding the list
|
|
233
|
+
of the names
|
|
234
|
+
"""
|
|
235
|
+
return self._wrapper.get_devices()
|
|
236
|
+
|
|
237
|
+
def get_scripting_devices(self) -> dict[str, dict[str, Actuator | Detector]]:
|
|
238
|
+
""" Get an :class:`Actuator` or :class:`Detector` object for each instrument of the experiment
|
|
239
|
+
|
|
240
|
+
Waits for the answer of the Dashboard (see :meth:`get_devices`).
|
|
241
|
+
|
|
242
|
+
Returns
|
|
243
|
+
-------
|
|
244
|
+
dict: ``{'actuators': {name: Actuator}, 'detectors': {name: Detector}}``
|
|
245
|
+
"""
|
|
246
|
+
devices = self._wrapper.get_devices().result()
|
|
247
|
+
|
|
248
|
+
return {
|
|
249
|
+
'actuators': {name: Actuator(name) for name in devices['actuators']},
|
|
250
|
+
'detectors': {name: Detector(name) for name in devices['detectors']},
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
def get_states(self) -> Future[list[str]]:
|
|
254
|
+
""" Ask for the names of the available states
|
|
255
|
+
|
|
256
|
+
Returns
|
|
257
|
+
-------
|
|
258
|
+
Future: its result is the list of names
|
|
259
|
+
"""
|
|
260
|
+
return self._wrapper.get_states()
|
|
261
|
+
|
|
262
|
+
def apply_state(self, state: str) -> Future[bool]:
|
|
263
|
+
""" Apply a state (instrument settings and actuator values)
|
|
264
|
+
|
|
265
|
+
Parameters
|
|
266
|
+
----------
|
|
267
|
+
state: str
|
|
268
|
+
Name of the state, as returned by :meth:`get_states`
|
|
269
|
+
|
|
270
|
+
Returns
|
|
271
|
+
-------
|
|
272
|
+
Future: its result is the success of the operation, set when the state has been applied
|
|
273
|
+
"""
|
|
274
|
+
return self._wrapper.apply_state(state)
|
|
275
|
+
|
|
276
|
+
def get_experiments(self) -> Future[list[str]]:
|
|
277
|
+
""" Ask for the names of the available experiments
|
|
278
|
+
|
|
279
|
+
Returns
|
|
280
|
+
-------
|
|
281
|
+
Future: its result is the list of names
|
|
282
|
+
"""
|
|
283
|
+
return self._wrapper.get_experiments()
|
|
284
|
+
|
|
285
|
+
def apply_experiment(self, experiment: str) -> Future[bool]:
|
|
286
|
+
""" Load an experiment (the list of instruments the Dashboard manages)
|
|
287
|
+
|
|
288
|
+
Parameters
|
|
289
|
+
----------
|
|
290
|
+
experiment: str
|
|
291
|
+
Name of the experiment, as returned by :meth:`get_experiments`
|
|
292
|
+
|
|
293
|
+
Returns
|
|
294
|
+
-------
|
|
295
|
+
Future: its result is the success of the operation, set when the experiment has been applied
|
|
296
|
+
"""
|
|
297
|
+
return self._wrapper.apply_experiment(experiment)
|
|
File without changes
|
|
@@ -212,7 +212,7 @@ class LECOActuatorWrapper(LECODeviceWrapper):
|
|
|
212
212
|
|
|
213
213
|
return future
|
|
214
214
|
|
|
215
|
-
def move_rel(self, value: 'DataActuator') -> Future['DataActuator']:
|
|
215
|
+
def move_rel(self, value: Union['DataActuator', int, float, str]) -> Future['DataActuator']:
|
|
216
216
|
future = Future()
|
|
217
217
|
self._move_done_future = future
|
|
218
218
|
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
from concurrent.futures import Future
|
|
2
|
-
from typing import Optional, TYPE_CHECKING, Union
|
|
3
|
-
from xml.etree.ElementTree import Element
|
|
4
|
-
from pymodaq_data.data import DataToExport
|
|
5
|
-
from pymodaq_scripting.utils import (
|
|
6
|
-
Device,
|
|
7
|
-
LECOActuatorWrapper,
|
|
8
|
-
LECODetectorWrapper,
|
|
9
|
-
LECODashboardWrapper,
|
|
10
|
-
)
|
|
11
|
-
|
|
12
|
-
if TYPE_CHECKING:
|
|
13
|
-
from pymodaq.utils.data import DataActuator
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class Actuator(Device[LECOActuatorWrapper]):
|
|
17
|
-
"""
|
|
18
|
-
Public interface to control an Actuator
|
|
19
|
-
"""
|
|
20
|
-
def __init__(self, device: str, **kwargs) -> None:
|
|
21
|
-
super().__init__(LECOActuatorWrapper(device, **kwargs))
|
|
22
|
-
|
|
23
|
-
def get_actuator_value(self) -> Future['DataActuator']:
|
|
24
|
-
return self._wrapper.get_actuator_value()
|
|
25
|
-
|
|
26
|
-
def move_home(self) -> Future['DataActuator']:
|
|
27
|
-
return self._wrapper.move_home()
|
|
28
|
-
|
|
29
|
-
def move_abs(self, value: Union['DataActuator', int, float, str]) -> Future['DataActuator']:
|
|
30
|
-
return self._wrapper.move_abs(value)
|
|
31
|
-
|
|
32
|
-
def move_rel(self, value: Union['DataActuator', int, float, str]) -> Future['DataActuator']:
|
|
33
|
-
return self._wrapper.move_rel(value)
|
|
34
|
-
|
|
35
|
-
def stop_move(self) -> Future['DataActuator']:
|
|
36
|
-
return self._wrapper.stop_move()
|
|
37
|
-
|
|
38
|
-
def get_settings(self) -> Future[Element]:
|
|
39
|
-
return self._wrapper.get_settings()
|
|
40
|
-
|
|
41
|
-
def set_settings(self, settings: Element) -> None:
|
|
42
|
-
self._wrapper.set_settings(settings)
|
|
43
|
-
|
|
44
|
-
class Detector(Device[LECODetectorWrapper]):
|
|
45
|
-
"""
|
|
46
|
-
Public interface to control a Detector
|
|
47
|
-
"""
|
|
48
|
-
def __init__(self, device: str, **kwargs) -> None:
|
|
49
|
-
super().__init__(LECODetectorWrapper(device, **kwargs))
|
|
50
|
-
|
|
51
|
-
def snap(self) -> Optional[Future[DataToExport]]:
|
|
52
|
-
return self._wrapper.snap()
|
|
53
|
-
|
|
54
|
-
def grab(self, keep=False) -> Optional[list[DataToExport]]:
|
|
55
|
-
return self._wrapper.grab(keep=keep)
|
|
56
|
-
|
|
57
|
-
def stop_grab(self) -> None:
|
|
58
|
-
return self._wrapper.stop_grab()
|
|
59
|
-
|
|
60
|
-
def get_settings(self) -> Future[Element]:
|
|
61
|
-
return self._wrapper.get_settings()
|
|
62
|
-
|
|
63
|
-
def set_settings(self, settings: Element) -> None:
|
|
64
|
-
self._wrapper.set_settings(settings)
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
class Dashboard(Device[LECODashboardWrapper]):
|
|
68
|
-
"""
|
|
69
|
-
Public interface to control a Dashboard
|
|
70
|
-
"""
|
|
71
|
-
|
|
72
|
-
def __init__(self, **kwargs) -> None:
|
|
73
|
-
super().__init__(LECODashboardWrapper(**kwargs))
|
|
74
|
-
|
|
75
|
-
@property
|
|
76
|
-
def leco_name(self):
|
|
77
|
-
return self._wrapper.leco_name
|
|
78
|
-
|
|
79
|
-
@property
|
|
80
|
-
def name(self) -> str:
|
|
81
|
-
return self._wrapper.name
|
|
82
|
-
|
|
83
|
-
def sign_out(self) -> None:
|
|
84
|
-
self._wrapper.sign_out()
|
|
85
|
-
|
|
86
|
-
def get_devices(self) -> Future[dict[str, list[str]]]:
|
|
87
|
-
return self._wrapper.get_devices()
|
|
88
|
-
|
|
89
|
-
def get_scripting_devices(self) -> dict[str, dict[str, Actuator | Detector]]:
|
|
90
|
-
devices = self._wrapper.get_devices().result()
|
|
91
|
-
|
|
92
|
-
return {
|
|
93
|
-
'actuators': {name: Actuator(name) for name in devices['actuators']},
|
|
94
|
-
'detectors': {name: Detector(name) for name in devices['detectors']},
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
def get_states(self) -> Future[list[str]]:
|
|
98
|
-
return self._wrapper.get_states()
|
|
99
|
-
|
|
100
|
-
def apply_state(self, state: str) -> Future[bool]:
|
|
101
|
-
return self._wrapper.apply_state(state)
|
|
102
|
-
|
|
103
|
-
def get_experiments(self) -> Future[list[str]]:
|
|
104
|
-
return self._wrapper.get_experiments()
|
|
105
|
-
|
|
106
|
-
def apply_experiment(self, experiment: str) -> Future[bool]:
|
|
107
|
-
return self._wrapper.apply_experiment(experiment)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pymodaq_scripting-5.3.7 → pymodaq_scripting-5.3.9}/src/pymodaq_scripting/examples/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{pymodaq_scripting-5.3.7 → pymodaq_scripting-5.3.9}/src/pymodaq_scripting/examples/simple_script.py
RENAMED
|
File without changes
|