38 Widget to use on a bench
41 widget_bench.py [<parameters_filename>] [options]
43 with 'parameters_filename' the path to the parameters file
46 -h --help Show this help message and exit
47 --brahma Distribute data with brahma
48 -d, --devices devices Specify the devices
49 -i, --interactive keep the script interactive
56 import pyqtgraph
as pg
57 from pyqtgraph.dockarea
import Dock, DockArea
62 from PyQt5
import QtGui, QtWidgets
63 from PyQt5.uic
import loadUiType
64 from PyQt5.QtCore
import QThread, QTimer, Qt
66 from subprocess
import Popen, PIPE
68 from typing
import Any, Dict, Tuple, Callable, List
70 from docopt
import docopt
71 from collections
import deque
74 BenchWindowTemplate, BenchClassTemplate = uiLoader(
'widget_bench')
76 import matplotlib.pyplot
as plt
88 def __init__(self, config_file: Any =
None, brahma: bool =
False,
89 devices: str =
None) ->
None:
90 WidgetBase.__init__(self)
91 BenchClassTemplate.__init__(self)
121 self.
uiBench.wao_run.setCheckable(
True)
123 self.
uiBench.wao_open_loop.setCheckable(
True)
131 self.
uiBench.wao_run.setDisabled(
True)
132 self.
uiBench.wao_next.setDisabled(
True)
133 self.
uiBench.wao_unzoom.setDisabled(
True)
135 self.addDockWidget(Qt.DockWidgetArea(1), self.
uiBase.wao_ConfigDock)
136 self.addDockWidget(Qt.DockWidgetArea(1), self.
uiBase.wao_DisplayDock)
137 self.
uiBase.wao_ConfigDock.setFloating(
False)
138 self.
uiBase.wao_DisplayDock.setFloating(
False)
142 if config_file
is not None:
143 self.
uiBase.wao_selectConfig.clear()
144 self.
uiBase.wao_selectConfig.addItem(config_file)
156 self.
uiBench.wao_nbiters.setDisabled(state)
158 def add_dispDock(self, name: str, parent, type: str =
"pg_image") ->
None:
159 d = WidgetBase.add_dispDock(self, name, parent, type)
161 d.addWidget(self.
uiBench.wao_Strehl)
165 Callback when 'LOAD' button is hit
167 WidgetBase.load_config(self)
168 config_file = str(self.
uiBase.wao_selectConfig.currentText())
189 for wfs
in range(self.
nwfs):
190 name =
'slpComp_%d' % wfs
192 name =
'wfs_%d' % wfs
195 self.
uiBench.wao_run.setDisabled(
True)
196 self.
uiBench.wao_next.setDisabled(
True)
197 self.
uiBench.wao_unzoom.setDisabled(
True)
199 self.
uiBase.wao_init.setDisabled(
False)
201 if (hasattr(self.
config,
"layout")):
203 self.
loadArea(filename=area_filename)
213 if self.
uiBench.wao_forever.isChecked():
214 print(
"LOOP STARTED")
216 print(
"LOOP STARTED FOR %d iterations" % self.
nbiter)
224 self.uiAO.wao_open_loop.setText(
"Close Loop")
227 self.uiAO.wao_open_loop.setText(
"Open Loop")
230 WidgetBase.init_config(self)
246 print(
'Warning: could not call supervisor.force_context().')
248 for i
in range(self.
nwfs):
249 if self.
config.p_wfss[i].type == WFSType.SH:
252 self.
config.p_wfss[i].get_validsub(),
257 self.
uiBench.wao_run.setDisabled(
False)
258 self.
uiBench.wao_next.setDisabled(
False)
259 self.
uiBench.wao_open_loop.setDisabled(
False)
260 self.
uiBench.wao_unzoom.setDisabled(
False)
262 WidgetBase.init_configFinished(self)
266 not self.
uiBase.wao_Display.isChecked()):
269 if not self.
loopLock.acquire(
False):
273 for key, dock
in self.
docks.items():
276 elif dock.isVisible():
277 index = int(key.split(
"_")[-1])
280 data = self.
supervisor.wfs.get_wfs_image(index)
281 if (data
is not None):
286 self.
imgs[key].setImage(data, autoLevels=autoscale)
290 if (self.
config.p_wfss[index].type == WFSType.PYRHR
or
291 self.
config.p_wfss[index].type == WFSType.PYRLR):
292 raise RuntimeError(
"PYRHR not usable")
293 self.
imgs[key].canvas.axes.clear()
294 x, y = self.
supervisor.config.p_wfss[index].get_validsub()
298 vx = centroids[:nssp]
299 vy = centroids[nssp:]
301 offset = (self.
supervisor.config.p_wfss[index].npix - 1) / 2
302 self.
imgs[key].canvas.axes.quiver(
303 x + offset, y + offset, vy, vx, angles=
'xy',
306 self.
imgs[key].canvas.draw()
312 if not self.
loopLock.acquire(
False):
313 print(
"Display locked")
319 loopTime = time.time() - start
320 refreshDisplayTime = 1. / self.
uiBase.wao_frameRate.value()
322 if (time.time() - self.
refreshTime > refreshDisplayTime):
323 currentFreq = 1 / loopTime
324 self.
uiBench.wao_currentFreq.setValue(currentFreq)
333 if not self.
uiBench.wao_forever.isChecked():
338 self.
uiBench.wao_run.setChecked(
False)
341 if __name__ ==
'__main__':
342 arguments = docopt(__doc__)
343 app = QtWidgets.QApplication(sys.argv)
344 app.setStyle(
'cleanlooks')
346 brahma=arguments[
"--brahma"], devices=arguments[
"--devices"])
348 if arguments[
"--interactive"]:
350 from os.path
import basename
351 embed(basename(__file__), locals())