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 from PyQt5
import QtWidgets
57 from PyQt5.QtCore
import QThread, Qt
58 except ModuleNotFoundError
as e:
60 from PySide2
import QtWidgets
61 from PySide2.QtCore
import QThread, Qt
62 except ModuleNotFoundError
as e:
63 raise ModuleNotFoundError(
"No module named 'PyQt5' or PySide2', please install one of them\nException raised: "+e.msg)
65 from typing
import Any
67 from docopt
import docopt
70 BenchWindowTemplate, BenchClassTemplate = uiLoader(
'widget_bench')
72 import matplotlib.pyplot
as plt
84 def __init__(self, config_file: Any =
None, brahma: bool =
False,
85 devices: str =
None) ->
None:
86 WidgetBase.__init__(self)
87 BenchClassTemplate.__init__(self)
93 self.
uiBenchuiBench.setupUi(self)
103 self.
uiBenchuiBench.wao_nbiters.setValue(1000)
117 self.
uiBenchuiBench.wao_run.setCheckable(
True)
119 self.
uiBenchuiBench.wao_open_loop.setCheckable(
True)
120 self.
uiBenchuiBench.wao_open_loop.clicked[bool].connect(self.
aoLoopOpenaoLoopOpen)
127 self.
uiBenchuiBench.wao_run.setDisabled(
True)
128 self.
uiBenchuiBench.wao_next.setDisabled(
True)
129 self.
uiBenchuiBench.wao_unzoom.setDisabled(
True)
131 self.addDockWidget(Qt.DockWidgetArea(1), self.
uiBaseuiBase.wao_ConfigDock)
132 self.addDockWidget(Qt.DockWidgetArea(1), self.
uiBaseuiBase.wao_DisplayDock)
133 self.
uiBaseuiBase.wao_ConfigDock.setFloating(
False)
134 self.
uiBaseuiBase.wao_DisplayDock.setFloating(
False)
138 if config_file
is not None:
139 self.
uiBaseuiBase.wao_selectConfig.clear()
140 self.
uiBaseuiBase.wao_selectConfig.addItem(config_file)
152 self.
uiBenchuiBench.wao_nbiters.setDisabled(state)
154 def add_dispDock(self, name: str, parent, type: str =
"pg_image") ->
None:
155 d = WidgetBase.add_dispDock(self, name, parent, type)
157 d.addWidget(self.
uiBenchuiBench.wao_Strehl)
161 Callback when 'LOAD' button is hit
163 WidgetBase.load_config(self)
164 config_file = str(self.
uiBaseuiBase.wao_selectConfig.currentText())
185 for wfs
in range(self.
nwfsnwfs):
186 name =
'slpComp_%d' % wfs
188 name =
'wfs_%d' % wfs
191 self.
uiBenchuiBench.wao_run.setDisabled(
True)
192 self.
uiBenchuiBench.wao_next.setDisabled(
True)
193 self.
uiBenchuiBench.wao_unzoom.setDisabled(
True)
195 self.
uiBaseuiBase.wao_init.setDisabled(
False)
197 if (hasattr(self.
configconfig,
"layout")):
199 self.
loadArealoadArea(filename=area_filename)
205 self.
stopstop =
False
209 if self.
uiBenchuiBench.wao_forever.isChecked():
210 print(
"LOOP STARTED")
212 print(
"LOOP STARTED FOR %d iterations" % self.
nbiternbiter)
220 self.uiAO.wao_open_loop.setText(
"Close Loop")
223 self.uiAO.wao_open_loop.setText(
"Open Loop")
226 WidgetBase.init_config(self)
242 print(
'Warning: could not call supervisor.force_context().')
244 for i
in range(self.
nwfsnwfs):
245 if self.
configconfig.p_wfss[i].type == WFSType.SH:
248 self.
configconfig.p_wfss[i].get_validsub(),
249 self.
configconfig.p_wfss[i].npix, self.
configconfig.p_wfss[i].npix)
253 self.
uiBenchuiBench.wao_run.setDisabled(
False)
254 self.
uiBenchuiBench.wao_next.setDisabled(
False)
255 self.
uiBenchuiBench.wao_open_loop.setDisabled(
False)
256 self.
uiBenchuiBench.wao_unzoom.setDisabled(
False)
258 WidgetBase.init_configFinished(self)
262 not self.
uiBaseuiBase.wao_Display.isChecked()):
265 if not self.
loopLockloopLock.acquire(
False):
269 for key, dock
in self.
docksdocks.items():
272 elif dock.isVisible():
273 index = int(key.split(
"_")[-1])
276 data = self.
supervisorsupervisor.wfs.get_wfs_image(index)
277 if (data
is not None):
282 self.
imgsimgs[key].setImage(data, autoLevels=autoscale)
286 if (self.
configconfig.p_wfss[index].type == WFSType.PYRHR
or
287 self.
configconfig.p_wfss[index].type == WFSType.PYRLR):
288 raise RuntimeError(
"PYRHR not usable")
289 self.
imgsimgs[key].canvas.axes.clear()
290 x, y = self.
supervisorsupervisor.config.p_wfss[index].get_validsub()
293 centroids = self.
supervisorsupervisor.rtc.get_slopes()
294 vx = centroids[:nssp]
295 vy = centroids[nssp:]
297 offset = (self.
supervisorsupervisor.config.p_wfss[index].npix - 1) / 2
298 self.
imgsimgs[key].canvas.axes.quiver(
299 x + offset, y + offset, vy, vx, angles=
'xy',
302 self.
imgsimgs[key].canvas.draw()
308 if not self.
loopLockloopLock.acquire(
False):
309 print(
"Display locked")
315 loopTime = time.time() - start
316 refreshDisplayTime = 1. / self.
uiBaseuiBase.wao_frameRate.value()
318 if (time.time() - self.
refreshTimerefreshTime > refreshDisplayTime):
319 currentFreq = 1 / loopTime
320 self.
uiBenchuiBench.wao_currentFreq.setValue(currentFreq)
329 if not self.
uiBenchuiBench.wao_forever.isChecked():
332 if self.
nbiternbiter <= 0:
334 self.
uiBenchuiBench.wao_run.setChecked(
False)
337 if __name__ ==
'__main__':
338 arguments = docopt(__doc__)
339 app = QtWidgets.QApplication(sys.argv)
340 app.setStyle(
'cleanlooks')
342 brahma=arguments[
"--brahma"], devices=arguments[
"--devices"])
344 if arguments[
"--interactive"]:
346 from os.path
import basename
347 embed(basename(__file__), locals())
Initialization and execution of a Bench supervisor.