pymodaq_plugins_utils 5.0.2__py3-none-any.whl
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_plugins_utils/__init__.py +13 -0
- pymodaq_plugins_utils/app/__init__.py +0 -0
- pymodaq_plugins_utils/exporters/__init__.py +6 -0
- pymodaq_plugins_utils/extensions/__init__.py +6 -0
- pymodaq_plugins_utils/extensions/custom_extension_template.py +140 -0
- pymodaq_plugins_utils/hardware/__init__.py +0 -0
- pymodaq_plugins_utils/hardware/camera_base_pylablib.py +398 -0
- pymodaq_plugins_utils/models/__init__.py +6 -0
- pymodaq_plugins_utils/resources/__init__.py +0 -0
- pymodaq_plugins_utils/resources/config_template.toml +2 -0
- pymodaq_plugins_utils/scanners/__init__.py +6 -0
- pymodaq_plugins_utils/utils.py +15 -0
- pymodaq_plugins_utils-5.0.2.dist-info/METADATA +97 -0
- pymodaq_plugins_utils-5.0.2.dist-info/RECORD +17 -0
- pymodaq_plugins_utils-5.0.2.dist-info/WHEEL +4 -0
- pymodaq_plugins_utils-5.0.2.dist-info/entry_points.txt +2 -0
- pymodaq_plugins_utils-5.0.2.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from .utils import Config
|
|
3
|
+
from pymodaq_utils.utils import get_version, PackageNotFoundError
|
|
4
|
+
from pymodaq_utils.logger import set_logger, get_module_name
|
|
5
|
+
|
|
6
|
+
config = Config()
|
|
7
|
+
try:
|
|
8
|
+
__version__ = get_version(__package__)
|
|
9
|
+
except PackageNotFoundError:
|
|
10
|
+
__version__ = '0.0.0dev'
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
File without changes
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
from qtpy import QtWidgets
|
|
2
|
+
|
|
3
|
+
from pymodaq_gui import utils as gutils
|
|
4
|
+
from pymodaq_utils.config import Config, ConfigError
|
|
5
|
+
from pymodaq_utils.logger import set_logger, get_module_name
|
|
6
|
+
|
|
7
|
+
from pymodaq.utils.config import get_set_preset_path
|
|
8
|
+
from pymodaq.extensions.utils import CustomExt
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
# todo: replace here *pymodaq_plugins_utils* by your plugin package name
|
|
12
|
+
from pymodaq_plugins_template.utils import Config as PluginConfig
|
|
13
|
+
|
|
14
|
+
logger = set_logger(get_module_name(__file__))
|
|
15
|
+
|
|
16
|
+
main_config = Config()
|
|
17
|
+
plugin_config = PluginConfig()
|
|
18
|
+
|
|
19
|
+
# todo: modify this as you wish
|
|
20
|
+
EXTENSION_NAME = 'MY_EXTENSION_NAME' # the name that will be displayed in the extension list in the
|
|
21
|
+
# dashboard
|
|
22
|
+
CLASS_NAME = 'CustomExtensionTemplate' # this should be the name of your class defined below
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# todo: modify the name of this class to reflect its application and change the name in the main
|
|
26
|
+
# method at the end of the script
|
|
27
|
+
class CustomExtensionTemplate(CustomExt):
|
|
28
|
+
|
|
29
|
+
# todo: if you wish to create custom Parameter and corresponding widgets. These will be
|
|
30
|
+
# automatically added as children of self.settings. Morevover, the self.settings_tree will
|
|
31
|
+
# render the widgets in a Qtree. If you wish to see it in your app, add is into a Dock
|
|
32
|
+
params = []
|
|
33
|
+
|
|
34
|
+
def __init__(self, parent: gutils.DockArea, dashboard):
|
|
35
|
+
super().__init__(parent, dashboard)
|
|
36
|
+
|
|
37
|
+
# info: in an extension, if you want to interact with ControlModules you have to use the
|
|
38
|
+
# object: self.modules_manager which is a ModulesManager instance from the dashboard
|
|
39
|
+
|
|
40
|
+
self.setup_ui()
|
|
41
|
+
|
|
42
|
+
def setup_docks(self):
|
|
43
|
+
"""Mandatory method to be subclassed to setup the docks layout
|
|
44
|
+
|
|
45
|
+
Examples
|
|
46
|
+
--------
|
|
47
|
+
>>>self.docks['ADock'] = gutils.Dock('ADock name')
|
|
48
|
+
>>>self.dockarea.addDock(self.docks['ADock'])
|
|
49
|
+
>>>self.docks['AnotherDock'] = gutils.Dock('AnotherDock name')
|
|
50
|
+
>>>self.dockarea.addDock(self.docks['AnotherDock'''], 'bottom', self.docks['ADock'])
|
|
51
|
+
|
|
52
|
+
See Also
|
|
53
|
+
--------
|
|
54
|
+
pyqtgraph.dockarea.Dock
|
|
55
|
+
"""
|
|
56
|
+
# todo: create docks and add them here to hold your widgets
|
|
57
|
+
# reminder, the attribute self.settings_tree will render the widgets in a Qtree.
|
|
58
|
+
# If you wish to see it in your app, add is into a Dock
|
|
59
|
+
raise NotImplementedError
|
|
60
|
+
|
|
61
|
+
def setup_actions(self):
|
|
62
|
+
"""Method where to create actions to be subclassed. Mandatory
|
|
63
|
+
|
|
64
|
+
Examples
|
|
65
|
+
--------
|
|
66
|
+
>>> self.add_action('quit', 'Quit', 'close2', "Quit program")
|
|
67
|
+
>>> self.add_action('grab', 'Grab', 'camera', "Grab from camera", checkable=True)
|
|
68
|
+
>>> self.add_action('load', 'Load', 'Open', "Load target file (.h5, .png, .jpg) or data from camera"
|
|
69
|
+
, checkable=False)
|
|
70
|
+
>>> self.add_action('save', 'Save', 'SaveAs', "Save current data", checkable=False)
|
|
71
|
+
|
|
72
|
+
See Also
|
|
73
|
+
--------
|
|
74
|
+
ActionManager.add_action
|
|
75
|
+
"""
|
|
76
|
+
raise NotImplementedError(f'You have to define actions here')
|
|
77
|
+
|
|
78
|
+
def connect_things(self):
|
|
79
|
+
"""Connect actions and/or other widgets signal to methods"""
|
|
80
|
+
raise NotImplementedError
|
|
81
|
+
|
|
82
|
+
def setup_menu(self, menubar: QtWidgets.QMenuBar = None):
|
|
83
|
+
"""Non mandatory method to be subclassed in order to create a menubar
|
|
84
|
+
|
|
85
|
+
create menu for actions contained into the self._actions, for instance:
|
|
86
|
+
|
|
87
|
+
Examples
|
|
88
|
+
--------
|
|
89
|
+
>>>file_menu = menubar.addMenu('File')
|
|
90
|
+
>>>self.affect_to('load', file_menu)
|
|
91
|
+
>>>self.affect_to('save', file_menu)
|
|
92
|
+
|
|
93
|
+
>>>file_menu.addSeparator()
|
|
94
|
+
>>>self.affect_to('quit', file_menu)
|
|
95
|
+
|
|
96
|
+
See Also
|
|
97
|
+
--------
|
|
98
|
+
pymodaq.utils.managers.action_manager.ActionManager
|
|
99
|
+
"""
|
|
100
|
+
# todo create and populate menu using actions defined above in self.setup_actions
|
|
101
|
+
pass
|
|
102
|
+
|
|
103
|
+
def value_changed(self, param):
|
|
104
|
+
""" Actions to perform when one of the param's value in self.settings is changed from the
|
|
105
|
+
user interface
|
|
106
|
+
|
|
107
|
+
For instance:
|
|
108
|
+
if param.name() == 'do_something':
|
|
109
|
+
if param.value():
|
|
110
|
+
print('Do something')
|
|
111
|
+
self.settings.child('main_settings', 'something_done').setValue(False)
|
|
112
|
+
|
|
113
|
+
Parameters
|
|
114
|
+
----------
|
|
115
|
+
param: (Parameter) the parameter whose value just changed
|
|
116
|
+
"""
|
|
117
|
+
pass
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def main():
|
|
121
|
+
from pymodaq.utils.gui_utils.utils import mkQApp
|
|
122
|
+
from pymodaq.utils.gui_utils.loader_utils import load_dashboard_with_preset
|
|
123
|
+
from pymodaq.utils.messenger import messagebox
|
|
124
|
+
|
|
125
|
+
app = mkQApp(EXTENSION_NAME)
|
|
126
|
+
try:
|
|
127
|
+
preset_file_name = plugin_config('presets', f'preset_for_{CLASS_NAME.lower()}')
|
|
128
|
+
load_dashboard_with_preset(preset_file_name, EXTENSION_NAME)
|
|
129
|
+
app.exec()
|
|
130
|
+
|
|
131
|
+
except ConfigError as e:
|
|
132
|
+
messagebox(f'No entry with name f"preset_for_{CLASS_NAME.lower()}" has been configured'
|
|
133
|
+
f'in the plugin config file. The toml entry should be:\n'
|
|
134
|
+
f'[presets]'
|
|
135
|
+
f"preset_for_{CLASS_NAME.lower()} = {'a name for an existing preset'}"
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
if __name__ == '__main__':
|
|
140
|
+
main()
|
|
File without changes
|
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
import cv2
|
|
2
|
+
from pymodaq_utils.logger import set_logger, get_module_name
|
|
3
|
+
from pymodaq_utils.utils import ThreadCommand
|
|
4
|
+
from pymodaq_gui.parameter import Parameter
|
|
5
|
+
try:
|
|
6
|
+
from pymodaq_gui.plotting.items.roi import RoiInfo # pymodaq > 5.1.x
|
|
7
|
+
except ImportError:
|
|
8
|
+
from pymodaq_gui.plotting.utils.plot_utils import RoiInfo
|
|
9
|
+
|
|
10
|
+
from pymodaq.utils.data import DataFromPlugins, Axis
|
|
11
|
+
from pymodaq.control_modules.viewer_utility_classes import DAQ_Viewer_base, comon_parameters, main
|
|
12
|
+
|
|
13
|
+
from qtpy import QtWidgets, QtCore
|
|
14
|
+
import numpy as np
|
|
15
|
+
from time import perf_counter
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
cam_params = [
|
|
19
|
+
{'title': 'Camera name:', 'name': 'camera_name', 'type': 'str', 'value': '', 'readonly': True},
|
|
20
|
+
{'title': 'Sensor type:', 'name': 'sensor', 'type': 'list', 'limits': ['Monochrome', 'Bayer']},
|
|
21
|
+
{'title': 'Ouput Color:', 'name': 'output_color', 'type': 'list', 'limits': ['RGB', 'MonoChrome']},
|
|
22
|
+
{'title': 'ROI', 'name': 'roi', 'type': 'group', 'children': [
|
|
23
|
+
{'title': 'Update ROI from Viewer', 'name': 'update_roi', 'type': 'led', 'value': False},
|
|
24
|
+
{'title': 'Apply ROI', 'name': 'apply_roi', 'type': 'led', 'value': False},
|
|
25
|
+
{'title': 'Clear ROI+Bin', 'name': 'clear_roi', 'type': 'bool_push', 'value': False},
|
|
26
|
+
{'title': 'ROI:', 'name': 'roi_slices', 'type': 'str', 'value': ''},
|
|
27
|
+
{'title': 'X binning', 'name': 'x_binning', 'type': 'int', 'value': 1},
|
|
28
|
+
{'title': 'Y binning', 'name': 'y_binning', 'type': 'int', 'value': 1},
|
|
29
|
+
], },
|
|
30
|
+
{'title': 'Image width', 'name': 'hdet', 'type': 'int', 'value': 1, 'readonly': True},
|
|
31
|
+
{'title': 'Image height', 'name': 'vdet', 'type': 'int', 'value': 1, 'readonly': True},
|
|
32
|
+
{'title': 'Timing', 'name': 'timing_opts', 'type': 'group', 'children':
|
|
33
|
+
[{'title': 'Exposure Time (ms)', 'name': 'exposure_time', 'type': 'int', 'value': 1},
|
|
34
|
+
{'title': 'Compute FPS', 'name': 'fps_on', 'type': 'bool', 'value': True},
|
|
35
|
+
{'title': 'FPS', 'name': 'fps', 'type': 'float', 'value': 0.0, 'readonly': True}]
|
|
36
|
+
},
|
|
37
|
+
{'title': 'Buffer', 'name': 'buffer', 'type': 'group', 'children': [
|
|
38
|
+
{'title': 'Size:', 'name': 'size', 'type': 'int', 'value': 10},
|
|
39
|
+
{'title': 'mode:', 'name': 'mode', 'type': 'list', 'value': 'now',
|
|
40
|
+
'limits': ['now', 'lastread', 'lastwait', 'start']},
|
|
41
|
+
]},
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class CameraBasePyLabLib(DAQ_Viewer_base):
|
|
46
|
+
"""
|
|
47
|
+
Base implementation for Camera using pylablib framework. Works for TSI and uc480 thorlabs camera and rpobaly others
|
|
48
|
+
"""
|
|
49
|
+
serial_numbers = []
|
|
50
|
+
|
|
51
|
+
serial_params = [{'title': 'Serial number:', 'name': 'serial_number', 'type': 'list', 'limits': serial_numbers}]
|
|
52
|
+
|
|
53
|
+
params = comon_parameters + serial_params + cam_params
|
|
54
|
+
|
|
55
|
+
callback_signal = QtCore.Signal(bool)
|
|
56
|
+
live_mode_available = True
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def ini_attributes(self):
|
|
60
|
+
self.controller = None
|
|
61
|
+
self.callback_thread: QtCore.QThread = None
|
|
62
|
+
|
|
63
|
+
self.x_axis: Axis = None
|
|
64
|
+
self.y_axis: Axis = None
|
|
65
|
+
|
|
66
|
+
self.roi_select_info: RoiInfo = None
|
|
67
|
+
|
|
68
|
+
self.last_tick = 0.0 # time counter used to compute FPS
|
|
69
|
+
self.fps = 0.0
|
|
70
|
+
|
|
71
|
+
self.data_shape: str = ''
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def roi_select(self, roi_info: RoiInfo, ind_viewer: int = 0):
|
|
75
|
+
""" Automatically called when a user use the RoiSelect ROi from a 2D viewer"""
|
|
76
|
+
self.roi_select_info = roi_info
|
|
77
|
+
self.roi_select_viewer_index = ind_viewer
|
|
78
|
+
|
|
79
|
+
if self.settings['roi', 'update_roi']:
|
|
80
|
+
self.settings['roi', 'roi_slices'] = str(roi_info.to_slices())
|
|
81
|
+
if self.settings['roi', 'apply_roi']:
|
|
82
|
+
self.apply_roi()
|
|
83
|
+
|
|
84
|
+
def apply_roi(self):
|
|
85
|
+
roi_info = RoiInfo.from_slices(eval(self.settings['roi', 'roi_slices']))
|
|
86
|
+
new_roi = (roi_info.origin[1], roi_info.size[1], self.settings['roi', 'x_binning'],
|
|
87
|
+
roi_info.origin[0], roi_info.size[0], self.settings['roi', 'y_binning'])
|
|
88
|
+
self.update_rois(new_roi)
|
|
89
|
+
|
|
90
|
+
def compute_axes(self):
|
|
91
|
+
(hstart, hend, vstart, vend, hbin, vbin) = self.controller.get_roi()
|
|
92
|
+
slices = [slice(vstart, vend, vbin), slice(hstart, hend, hbin)]
|
|
93
|
+
self.settings.child('roi', 'roi_slices').setValue(str(slices))
|
|
94
|
+
roi_info = RoiInfo.from_slices(slices)
|
|
95
|
+
|
|
96
|
+
self.x_axis = Axis('x_axis', offset=roi_info.origin[1],
|
|
97
|
+
scaling=self.settings['roi', 'x_binning'],
|
|
98
|
+
size=int(roi_info.size[1]),
|
|
99
|
+
index=1)
|
|
100
|
+
self.y_axis = Axis('y_axis', offset=roi_info.origin[0],
|
|
101
|
+
scaling=self.settings['roi', 'y_binning'],
|
|
102
|
+
size=int(roi_info.size[0]),
|
|
103
|
+
index=0)
|
|
104
|
+
|
|
105
|
+
def clear_roi(self):
|
|
106
|
+
wdet, hdet = self.controller.get_detector_size()
|
|
107
|
+
self.settings.child('roi', 'x_binning').setValue(1)
|
|
108
|
+
self.settings.child('roi', 'y_binning').setValue(1)
|
|
109
|
+
|
|
110
|
+
new_roi = (0, wdet, 1, 0, hdet, 1)
|
|
111
|
+
self.update_rois(new_roi)
|
|
112
|
+
|
|
113
|
+
def update_rois(self, new_roi):
|
|
114
|
+
# In pylablib, ROIs compare as tuples
|
|
115
|
+
(new_x, new_width, new_xbinning, new_y, new_height, new_ybinning) = new_roi
|
|
116
|
+
if new_roi != self.controller.get_roi():
|
|
117
|
+
# self.controller.set_attribute_value("ROIs",[new_roi])
|
|
118
|
+
self.controller.set_roi(hstart=new_x, hend=new_x + new_width, vstart=new_y, vend=new_y + new_height,
|
|
119
|
+
hbin=new_xbinning, vbin=new_ybinning)
|
|
120
|
+
self.emit_status(ThreadCommand('Update_Status', [f'Changed ROI: {new_roi}']))
|
|
121
|
+
self.controller.clear_acquisition()
|
|
122
|
+
self.controller.setup_acquisition()
|
|
123
|
+
# Finally, prepare view for displaying the new data
|
|
124
|
+
self._prepare_view()
|
|
125
|
+
self.compute_axes()
|
|
126
|
+
|
|
127
|
+
def commit_settings(self, param: Parameter):
|
|
128
|
+
"""Apply the consequences of a change of value in the detector settings
|
|
129
|
+
|
|
130
|
+
Parameters
|
|
131
|
+
----------
|
|
132
|
+
param: Parameter
|
|
133
|
+
A given parameter (within detector_settings) whose value has been changed by the user
|
|
134
|
+
"""
|
|
135
|
+
if param.name() == "exposure_time":
|
|
136
|
+
self.controller.set_exposure(param.value()/1000)
|
|
137
|
+
|
|
138
|
+
if param.name() == "fps_on":
|
|
139
|
+
self.settings.child('timing_opts', 'fps').setOpts(visible=param.value())
|
|
140
|
+
|
|
141
|
+
if param.name() == "apply_roi":
|
|
142
|
+
if param.value(): # Switching on ROI
|
|
143
|
+
self.apply_roi()
|
|
144
|
+
else:
|
|
145
|
+
self.clear_roi()
|
|
146
|
+
|
|
147
|
+
if param.name() in ['x_binning', 'y_binning']:
|
|
148
|
+
# We handle ROI and binning separately for clarity
|
|
149
|
+
(x0, w, y0, h, *_) = self.controller.get_roi() # Get current ROI
|
|
150
|
+
xbin = self.settings['roi', 'x_binning']
|
|
151
|
+
ybin = self.settings['roi', 'y_binning']
|
|
152
|
+
new_roi = (x0, w, xbin, y0, h, ybin)
|
|
153
|
+
self.update_rois(new_roi)
|
|
154
|
+
|
|
155
|
+
if param.name() == "clear_roi":
|
|
156
|
+
if param.value(): # Switching on ROI
|
|
157
|
+
self.clear_roi()
|
|
158
|
+
param.setValue(False)
|
|
159
|
+
|
|
160
|
+
def ini_detector_custom(self, controller=None):
|
|
161
|
+
raise NotImplementedError
|
|
162
|
+
|
|
163
|
+
def ini_detector(self, controller=None):
|
|
164
|
+
"""Detector communication initialization
|
|
165
|
+
|
|
166
|
+
Parameters
|
|
167
|
+
----------
|
|
168
|
+
controller: (object)
|
|
169
|
+
custom object of a PyMoDAQ plugin (Slave case). None if only one actuator/detector by controller
|
|
170
|
+
(Master case)
|
|
171
|
+
|
|
172
|
+
Returns
|
|
173
|
+
-------
|
|
174
|
+
info: str
|
|
175
|
+
initialized: bool
|
|
176
|
+
False if initialization failed otherwise True
|
|
177
|
+
"""
|
|
178
|
+
self.ini_detector_custom(controller)
|
|
179
|
+
|
|
180
|
+
self.get_device_info()
|
|
181
|
+
self.get_set_color()
|
|
182
|
+
self.get_set_main_parameters()
|
|
183
|
+
self.setup_callback_thread()
|
|
184
|
+
|
|
185
|
+
info = "Initialized camera"
|
|
186
|
+
initialized = True
|
|
187
|
+
return info, initialized
|
|
188
|
+
|
|
189
|
+
def get_device_info(self):
|
|
190
|
+
|
|
191
|
+
device_info = self.controller.get_device_info()
|
|
192
|
+
|
|
193
|
+
# Get camera name/model
|
|
194
|
+
if hasattr(device_info, 'name'):
|
|
195
|
+
self.settings.child('camera_name').setValue(device_info.name)
|
|
196
|
+
elif hasattr(device_info, 'model'):
|
|
197
|
+
self.settings.child('camera_name').setValue(device_info.model)
|
|
198
|
+
|
|
199
|
+
def get_set_color(self):
|
|
200
|
+
if 'monochrome' in self.settings['sensor'].lower():
|
|
201
|
+
self.settings.child('output_color').setValue('MonoChrome')
|
|
202
|
+
self.settings.child('output_color').setOpts(visible=False)
|
|
203
|
+
|
|
204
|
+
def get_set_main_parameters(self):
|
|
205
|
+
# Set exposure time
|
|
206
|
+
self.controller.set_exposure(self.settings['timing_opts', 'exposure_time']/1000)
|
|
207
|
+
|
|
208
|
+
# FPS visibility
|
|
209
|
+
self.settings.child('timing_opts', 'fps').setOpts(visible=self.settings['timing_opts', 'fps_on'])
|
|
210
|
+
|
|
211
|
+
# get roi limits
|
|
212
|
+
self.controller.get_roi_limits()
|
|
213
|
+
|
|
214
|
+
# Update image parameters
|
|
215
|
+
(hstart, hend, vstart, vend, hbin, vbin) = self.controller.get_roi()
|
|
216
|
+
height, width = self.controller.get_data_dimensions()
|
|
217
|
+
self.settings.child('roi', 'x_binning').setValue(hbin)
|
|
218
|
+
self.settings.child('roi', 'y_binning').setValue(vbin)
|
|
219
|
+
self.settings.child('hdet').setValue(width)
|
|
220
|
+
self.settings.child('vdet').setValue(height)
|
|
221
|
+
slices = [slice(vstart, vend, vbin), slice(hstart, hend, hbin)]
|
|
222
|
+
self.settings.child('roi', 'roi_slices').setValue(str(slices))
|
|
223
|
+
self.compute_axes()
|
|
224
|
+
|
|
225
|
+
def setup_callback_thread(self):
|
|
226
|
+
# Way to define a wait function with arguments
|
|
227
|
+
wait_func = lambda: self.controller.wait_for_frame(since=self.settings['buffer', 'mode'],
|
|
228
|
+
nframes=1, timeout=20.0)
|
|
229
|
+
callback = CameraCallback(wait_func)
|
|
230
|
+
self.settings.child('buffer', 'mode').setReadonly(True)
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
self.callback_thread = QtCore.QThread() # creation of a Qt5 thread
|
|
234
|
+
callback.moveToThread(self.callback_thread) # callback object will live within this thread
|
|
235
|
+
callback.data_sig.connect(
|
|
236
|
+
self.emit_data) # when the wait for acquisition returns (with data taken), emit_data will be fired
|
|
237
|
+
|
|
238
|
+
self.callback_signal.connect(callback.set_do_grab)
|
|
239
|
+
self.callback_thread.callback = callback
|
|
240
|
+
self.callback_thread.start()
|
|
241
|
+
|
|
242
|
+
self._prepare_view()
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
def _prepare_view(self):
|
|
246
|
+
"""Preparing a data viewer by emitting temporary data. Typically, needs to be called whenever the
|
|
247
|
+
ROIs are changed"""
|
|
248
|
+
|
|
249
|
+
height, width = self.controller.get_data_dimensions()
|
|
250
|
+
|
|
251
|
+
self.settings.child('hdet').setValue(width)
|
|
252
|
+
self.settings.child('vdet').setValue(height)
|
|
253
|
+
mock_data = np.zeros((height, width))
|
|
254
|
+
|
|
255
|
+
if width != 1 and height != 1:
|
|
256
|
+
data_shape = 'Data2D'
|
|
257
|
+
else:
|
|
258
|
+
data_shape = 'Data1D'
|
|
259
|
+
|
|
260
|
+
if data_shape != self.data_shape:
|
|
261
|
+
self.data_shape = data_shape
|
|
262
|
+
# init the viewers
|
|
263
|
+
self.data_grabed_signal_temp.emit([DataFromPlugins(name='Thorlabs Camera',
|
|
264
|
+
data=[np.squeeze(mock_data)],
|
|
265
|
+
dim=self.data_shape,
|
|
266
|
+
labels=[f'ThorCam_{self.data_shape}'])])
|
|
267
|
+
QtWidgets.QApplication.processEvents()
|
|
268
|
+
|
|
269
|
+
def grab_data(self, Naverage=1, **kwargs):
|
|
270
|
+
"""
|
|
271
|
+
Grabs the data. ASynchronous method (kinda).
|
|
272
|
+
----------
|
|
273
|
+
Naverage: (int) Number of averaging
|
|
274
|
+
kwargs: (dict) of others optionals arguments
|
|
275
|
+
"""
|
|
276
|
+
try:
|
|
277
|
+
# Warning, acquisition_in_progress returns 1,0 and not a real bool
|
|
278
|
+
if not kwargs.get('live', False):
|
|
279
|
+
self.emit_data(self.controller.snap())
|
|
280
|
+
else:
|
|
281
|
+
if not self.controller.acquisition_in_progress():
|
|
282
|
+
self.controller.clear_acquisition()
|
|
283
|
+
self.controller.start_acquisition(nframes=self.settings['buffer', 'size'])
|
|
284
|
+
#Then start the acquisition
|
|
285
|
+
self.callback_signal.emit(True) # will trigger the wait for acquisition
|
|
286
|
+
|
|
287
|
+
except Exception as e:
|
|
288
|
+
self.emit_status(ThreadCommand('Update_Status', [str(e), "log"]))
|
|
289
|
+
|
|
290
|
+
def emit_data(self, frame: np.ndarray=None):
|
|
291
|
+
""" Function used to emit data obtained by callback.
|
|
292
|
+
|
|
293
|
+
Parameter
|
|
294
|
+
---------
|
|
295
|
+
status: bool
|
|
296
|
+
If True a frame is available, If False, a Timeout occurred while waiting for the frame
|
|
297
|
+
|
|
298
|
+
See Also
|
|
299
|
+
--------
|
|
300
|
+
daq_utils.ThreadCommand
|
|
301
|
+
"""
|
|
302
|
+
try:
|
|
303
|
+
# Get data from buffer
|
|
304
|
+
if frame is None:
|
|
305
|
+
frame = self.controller.read_newest_image()
|
|
306
|
+
# Emit the frame.
|
|
307
|
+
if frame is not None: # happens for last frame when stopping camera
|
|
308
|
+
if self.settings['output_color'] == 'RGB':
|
|
309
|
+
rgb_image = cv2.cvtColor(frame, cv2.COLOR_BAYER_BG2RGB)
|
|
310
|
+
data_arrays = [np.atleast_1d(rgb_image[..., ind]) for ind in range(3)]
|
|
311
|
+
else:
|
|
312
|
+
if 'monochrome' in self.settings['sensor'].lower():
|
|
313
|
+
data_arrays = [np.atleast_1d(frame)]
|
|
314
|
+
else:
|
|
315
|
+
data_arrays = [np.atleast_1d(cv2.cvtColor(frame, cv2.COLOR_BAYER_BG2GRAY))]
|
|
316
|
+
|
|
317
|
+
self.data_grabed_signal.emit([DataFromPlugins(name='Thorlabs Camera',
|
|
318
|
+
data=data_arrays,
|
|
319
|
+
dim=self.data_shape,
|
|
320
|
+
labels=[f'ThorCam_{self.data_shape}'],
|
|
321
|
+
axes=[self.x_axis, self.y_axis])])
|
|
322
|
+
if self.settings.child('timing_opts', 'fps_on').value():
|
|
323
|
+
self.update_fps()
|
|
324
|
+
|
|
325
|
+
# To make sure that timed events are executed in continuous grab mode
|
|
326
|
+
QtWidgets.QApplication.processEvents()
|
|
327
|
+
|
|
328
|
+
except Exception as e:
|
|
329
|
+
self.emit_status(ThreadCommand('Update_Status', [str(e), 'log']))
|
|
330
|
+
|
|
331
|
+
def update_fps(self):
|
|
332
|
+
current_tick = perf_counter()
|
|
333
|
+
frame_time = current_tick-self.last_tick
|
|
334
|
+
|
|
335
|
+
if self.last_tick != 0.0 and frame_time != 0.0:
|
|
336
|
+
# We don't update FPS for the first frame, and we also avoid divisions by zero
|
|
337
|
+
|
|
338
|
+
if self.fps == 0.0:
|
|
339
|
+
self.fps = 1 / frame_time
|
|
340
|
+
else:
|
|
341
|
+
# If we already have an FPS calculated, we smooth its evolution
|
|
342
|
+
self.fps = 0.9 * self.fps + 0.1 / frame_time
|
|
343
|
+
|
|
344
|
+
self.last_tick = current_tick
|
|
345
|
+
|
|
346
|
+
# Update reading
|
|
347
|
+
self.settings.child('timing_opts', 'fps').setValue(round(self.fps, 1))
|
|
348
|
+
|
|
349
|
+
def close(self):
|
|
350
|
+
"""
|
|
351
|
+
Terminate the communication protocol
|
|
352
|
+
"""
|
|
353
|
+
# Terminate the communication
|
|
354
|
+
|
|
355
|
+
self.stop()
|
|
356
|
+
if self.callback_thread is not None:
|
|
357
|
+
self.callback_thread.quit()
|
|
358
|
+
self.callback_thread.wait()
|
|
359
|
+
|
|
360
|
+
self.controller.close()
|
|
361
|
+
self.settings.child('buffer', 'mode').setReadonly(False)
|
|
362
|
+
|
|
363
|
+
def stop(self):
|
|
364
|
+
"""Stop the acquisition."""
|
|
365
|
+
self.callback_signal.emit(False)
|
|
366
|
+
QtWidgets.QApplication.processEvents()
|
|
367
|
+
|
|
368
|
+
self.controller.clear_acquisition()
|
|
369
|
+
return ''
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
class CameraCallback(QtCore.QObject):
|
|
373
|
+
"""Callback object """
|
|
374
|
+
data_sig = QtCore.Signal()
|
|
375
|
+
|
|
376
|
+
def __init__(self, wait_fn):
|
|
377
|
+
super().__init__()
|
|
378
|
+
# Set the wait function
|
|
379
|
+
self.wait_fn = wait_fn
|
|
380
|
+
self.do_grab = True
|
|
381
|
+
|
|
382
|
+
def set_do_grab(self, do_grab=True):
|
|
383
|
+
self.do_grab = do_grab
|
|
384
|
+
if do_grab:
|
|
385
|
+
self.wait_for_acquisition()
|
|
386
|
+
|
|
387
|
+
def wait_for_acquisition(self):
|
|
388
|
+
while self.do_grab:
|
|
389
|
+
try:
|
|
390
|
+
new_data = self.wait_fn()
|
|
391
|
+
if new_data is not False: # will be returned if the main thread called CancelWait
|
|
392
|
+
self.data_sig.emit()
|
|
393
|
+
except Exception as e:
|
|
394
|
+
pass
|
|
395
|
+
QtWidgets.QApplication.processEvents()
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
Created the 31/08/2023
|
|
4
|
+
|
|
5
|
+
@author: Sebastien Weber
|
|
6
|
+
"""
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
from pymodaq_utils.config import BaseConfig, USER
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Config(BaseConfig):
|
|
13
|
+
"""Main class to deal with configuration values for this plugin"""
|
|
14
|
+
config_template_path = Path(__file__).parent.joinpath('resources/config_template.toml')
|
|
15
|
+
config_name = f"config_{__package__.split('pymodaq_plugins_')[1]}"
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pymodaq_plugins_utils
|
|
3
|
+
Version: 5.0.2
|
|
4
|
+
Summary: Set of utility methods and classes to interact with instruments
|
|
5
|
+
Project-URL: Homepage, https://pymodaq.cnrs.fr
|
|
6
|
+
Project-URL: Documentation , https://pymodaq.cnrs.fr
|
|
7
|
+
Project-URL: Repository , https://github.com/PyMoDAQ/pymodaq_plugins_utils
|
|
8
|
+
Author-email: Weber Sebastien <sebastien.weber@cemes.fr>
|
|
9
|
+
Maintainer-email: Weber Sebastien <sebastien.weber@cemes.fr>
|
|
10
|
+
License: The MIT License (MIT)
|
|
11
|
+
|
|
12
|
+
Copyright (c) 2021 Sebastien Weber <sebastien.weber@cemes.fr>
|
|
13
|
+
|
|
14
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
15
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
16
|
+
in the Software without restriction, including without limitation the rights
|
|
17
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
18
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
19
|
+
furnished to do so, subject to the following conditions:
|
|
20
|
+
|
|
21
|
+
The above copyright notice and this permission notice shall be included in
|
|
22
|
+
all copies or substantial portions of the Software.
|
|
23
|
+
|
|
24
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
25
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
26
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
27
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
28
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
29
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
30
|
+
THE SOFTWARE.
|
|
31
|
+
License-File: LICENSE
|
|
32
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
33
|
+
Classifier: Intended Audience :: Science/Research
|
|
34
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
35
|
+
Classifier: Natural Language :: English
|
|
36
|
+
Classifier: Operating System :: OS Independent
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
41
|
+
Classifier: Topic :: Scientific/Engineering :: Human Machine Interfaces
|
|
42
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
43
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
44
|
+
Classifier: Topic :: Software Development :: User Interfaces
|
|
45
|
+
Requires-Python: >=3.8
|
|
46
|
+
Requires-Dist: pymodaq>=5.0.0
|
|
47
|
+
Provides-Extra: serial
|
|
48
|
+
Requires-Dist: pyvisa; extra == 'serial'
|
|
49
|
+
Description-Content-Type: text/x-rst
|
|
50
|
+
|
|
51
|
+
pymodaq_plugins_utils
|
|
52
|
+
#####################
|
|
53
|
+
|
|
54
|
+
.. the following must be adapted to your developed package, links to pypi, github description...
|
|
55
|
+
|
|
56
|
+
.. image:: https://img.shields.io/pypi/v/pymodaq_plugins_utils.svg
|
|
57
|
+
:target: https://pypi.org/project/pymodaq_plugins_utils/
|
|
58
|
+
:alt: Latest Version
|
|
59
|
+
|
|
60
|
+
.. image:: https://readthedocs.org/projects/pymodaq/badge/?version=latest
|
|
61
|
+
:target: https://pymodaq.readthedocs.io/en/stable/?badge=latest
|
|
62
|
+
:alt: Documentation Status
|
|
63
|
+
|
|
64
|
+
.. image:: https://github.com/PyMoDAQ/pymodaq_plugins_utils/workflows/Upload%20Python%20Package/badge.svg
|
|
65
|
+
:target: https://github.com/PyMoDAQ/pymodaq_plugins_utils
|
|
66
|
+
:alt: Publication Status
|
|
67
|
+
|
|
68
|
+
.. image:: https://github.com/PyMoDAQ/pymodaq_plugins_utils/actions/workflows/Test.yml/badge.svg
|
|
69
|
+
:target: https://github.com/PyMoDAQ/pymodaq_plugins_utils/actions/workflows/Test.yml
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
Authors
|
|
74
|
+
=======
|
|
75
|
+
|
|
76
|
+
* Sebastien J. Weber (sebastien.weber@cemes.fr)
|
|
77
|
+
* Other author (myotheremail@xxx.org)
|
|
78
|
+
|
|
79
|
+
.. if needed use this field
|
|
80
|
+
|
|
81
|
+
Contributors
|
|
82
|
+
============
|
|
83
|
+
|
|
84
|
+
* First Contributor
|
|
85
|
+
* Other Contributors
|
|
86
|
+
|
|
87
|
+
.. if needed use this field
|
|
88
|
+
|
|
89
|
+
Depending on the plugin type, delete/complete the fields below
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
Utilities
|
|
93
|
+
=========
|
|
94
|
+
|
|
95
|
+
* pysvisa stuff
|
|
96
|
+
* CameraBasePyLabLib: Base plugin class inheriting from DAQ_Viewer_base but implementing ROI management, binning,
|
|
97
|
+
the use of buffers through the pylablib package implementation. Mostly for (S)CMOS camera
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
pymodaq_plugins_utils/__init__.py,sha256=kHISHcIGvr98_YfphdBAs1wThG_WCeoh_Vt0mftOxck,306
|
|
2
|
+
pymodaq_plugins_utils/utils.py,sha256=saBKehqiq5myeh7GCW1vYf5wq4QVYhSVLTxFK6KkdP4,419
|
|
3
|
+
pymodaq_plugins_utils/app/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
pymodaq_plugins_utils/exporters/__init__.py,sha256=vqgY3SHF6EhPcfeS8lzb7QvAiTIXWmyObIaCYeJNb6Y,81
|
|
5
|
+
pymodaq_plugins_utils/extensions/__init__.py,sha256=vqgY3SHF6EhPcfeS8lzb7QvAiTIXWmyObIaCYeJNb6Y,81
|
|
6
|
+
pymodaq_plugins_utils/extensions/custom_extension_template.py,sha256=s4myQuS-_m8m7ZwDydm9kMikqAV7hEfTLx56vVt8Bk8,5113
|
|
7
|
+
pymodaq_plugins_utils/hardware/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
pymodaq_plugins_utils/hardware/camera_base_pylablib.py,sha256=O7rF-wxAE5DKq4360IQ8Ks4Gct8xUQMsZ3c79JT8Cko,16006
|
|
9
|
+
pymodaq_plugins_utils/models/__init__.py,sha256=vqgY3SHF6EhPcfeS8lzb7QvAiTIXWmyObIaCYeJNb6Y,81
|
|
10
|
+
pymodaq_plugins_utils/resources/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
+
pymodaq_plugins_utils/resources/config_template.toml,sha256=TmG-xPcxkpmXcZSg0z7nG2vsVKF6TNPdQxbe7Mb4tXY,60
|
|
12
|
+
pymodaq_plugins_utils/scanners/__init__.py,sha256=vqgY3SHF6EhPcfeS8lzb7QvAiTIXWmyObIaCYeJNb6Y,81
|
|
13
|
+
pymodaq_plugins_utils-5.0.2.dist-info/METADATA,sha256=5yyIBzoBF2tb-Qzu3hkU2SaeEFtEv-HuV-UT2loL50o,4009
|
|
14
|
+
pymodaq_plugins_utils-5.0.2.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
15
|
+
pymodaq_plugins_utils-5.0.2.dist-info/entry_points.txt,sha256=TiGCih60OSBHysqCYygRyzBnVAGBivgJUJ6lRXFoj9A,48
|
|
16
|
+
pymodaq_plugins_utils-5.0.2.dist-info/licenses/LICENSE,sha256=VKOejxexXAe3XwfhAhcFGqeXQ12irxVHdeAojZwFEI8,1108
|
|
17
|
+
pymodaq_plugins_utils-5.0.2.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Sebastien Weber <sebastien.weber@cemes.fr>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|