38 Widget to simulate a closed loop using CANAPASS
41 widget_canapass.py [<parameters_filename>]
43 with 'parameters_filename' the path to the parameters file
46 -h --help Show this help message and exit
47 -i, --interactive keep the script interactive
54 import pyqtgraph
as pg
56 from tqdm
import trange
57 import astropy.io.fits
as pfits
58 from PyQt5
import QtWidgets
61 from typing
import Any, Dict, Tuple, Callable, List
62 from docopt
import docopt
72 def __init__(self, config_file: Any =
None, cacao: bool =
False,
73 expert: bool =
False) ->
None:
74 widgetAOWindow.__init__(self, config_file, cacao, hide_histograms=
True)
92 self.
uiAO.wao_deviceNumber.setDisabled(
True)
96 widgetAOWindow.init_config(self)
100 def load_config(self, *args, config_file=None, supervisor=None) -> None:
102 Callback when 'LOAD' button is hit
104 if supervisor
is None:
107 widgetAOWindow.load_config(self, args, config_file=config_file,
108 supervisor=supervisor)
111 widgetAOWindow.loop_once(self)
112 if (self.
uiAO.actionShow_Pyramid_Tools.isChecked()):
114 if (self.
wpyr.CBNumber == 1):
115 self.
ai = self.compute_modal_residuals()
119 aiVect = self.compute_modal_residuals()
120 self.
ai = aiVect[np.newaxis, :]
124 aiVect = self.compute_modal_residuals()
125 self.
ai = np.concatenate((self.
ai, aiVect[np.newaxis, :]))
132 def next(self, nbIters):
133 ''' Move atmos -> get_slopes -> applyControl ; One integrator step '''
134 for i
in trange(nbIters):
138 ADOPTPATH = os.getenv(
"ADOPTPATH")
139 sys.path.append(ADOPTPATH +
"/widgets")
140 from pyrStats
import widget_pyrStats
141 print(
"OK Pyramid Tools Widget initialized")
142 self.
wpyr = widget_pyrStats()
148 self.
wpyr.phase = self.
supervisor.target.get_tar_phase(0, pupil=
True)
149 self.
wpyr.updateResiduals(ai)
151 print(
'computing phase 2 Modes basis')
156 if (self.
wpyr is None):
158 print(
"Lauching pyramid widget...")
162 raise ValueError(
"ERROR: ADOPT not found. Cannot launch Pyramid tools")
164 if (self.
uiAO.actionShow_Pyramid_Tools.isChecked()):
174 from subprocess
import Popen, PIPE
175 from hraa.server.pyroServer
import PyroServer
181 p = Popen(
"whoami", shell=
True, stdout=PIPE, stderr=PIPE)
182 out, err = p.communicate()
185 raise Exception(
"ERROR CANNOT RECOGNIZE USER")
187 user = out.split(b
"\n")[0].decode(
"utf-8")
188 print(
"User is " + user)
190 server = PyroServer()
191 server.add_device(self.
supervisor,
"waoconfig_" + user)
192 server.add_device(wao_loop,
"waoloop_" + user)
195 raise Exception(
"Error could not connect to Pyro server.\n It can be:\n - Missing dependencies? (check if Pyro4 is installed)\n - pyro server not running")
206 self.
wao.aoLoopClicked(
True)
207 self.
wao.uiAO.wao_run.setChecked(
True)
210 self.
wao.aoLoopClicked(
False)
211 self.
wao.uiAO.wao_run.setChecked(
False)
217 if __name__ ==
'__main__':
218 arguments = docopt(__doc__)
219 app = QtWidgets.QApplication(sys.argv)
220 app.setStyle(
'cleanlooks')