38 Widget built to simulate a 2 stage AO loop (1st stage = SH; second stage = pyramid)
41 widget_twoStages.py <parameters_filename1> <parameters_filename2> <freqratio> [options]
43 with 'parameters_filename1' the path to the parameters file for first stage
44 with 'parameters_filename2' the path to the parameters file for second stage
45 with 'freqratio' the ratio of the frequencies of the two stages
48 -a, --adopt used to connect ADOPT (via pyro + shm cacao)
51 ipython -i widget_twoStages.py ../../data/par/SPHERE+/sphere.py ../../data/par/SPHERE+/sphere+.py
52 ipython -i widget_twoStages.py ../../data/par/SPHERE+/sphere.py ../../data/par/SPHERE+/sphere+.py -- --adopt
59 import pyqtgraph
as pg
61 from rich.progress
import track
62 import astropy.io.fits
as pfits
63 from PyQt5
import QtWidgets
66 from typing
import Any, Dict, Tuple, Callable, List
67 from docopt
import docopt
78 def __init__(self, config_file1: Any =
None, config_file2: Any =
None, freqratio : int =
None,
79 cacao: bool =
False, expert: bool =
False) ->
None:
81 self.
config2config2 = config_file2
87 self.
wao2wao2=
widgetAOWindow(config_file2, cacao=cacao, hide_histograms=
True, twoStages=
True)
88 self.
wao1wao1=
widgetAOWindow(config_file1, cacao=cacao, hide_histograms=
True, twoStages=
True)
89 pupdiam_first_stage = self.
wao1wao1.supervisor.config.p_geom.pupdiam
90 pupdiam_second_stage = self.
wao2wao2.supervisor.config.p_geom.pupdiam
91 if(pupdiam_first_stage != pupdiam_second_stage):
92 print(
"---------------ERROR---------------")
93 print(
"SECOND STAGE PUPDIAM IS SET TO %d" % pupdiam_second_stage)
94 print(
"FIRST STAGE PUPDIAM IS SET TO %d" % pupdiam_first_stage)
95 raise Exception(
'ERROR!!!! FIRST STAGE PUPDIAM MUST BE SET TO %d' % pupdiam_second_stage)
109 self.
wao1wao1.uiAO.actionShow_Pyramid_Tools.toggled.connect(self.
show_pyr_toolsshow_pyr_tools)
110 self.
wao2wao2.uiAO.actionShow_Pyramid_Tools.toggled.connect(self.
show_pyr_toolsshow_pyr_tools)
124 for wao
in [self.
wao1wao1, self.
wao2wao2]:
126 for t
in range(len(wao.supervisor.config.p_targets)):
127 wao.supervisor.target.comp_tar_image(t)
128 loopTime = time.time() - start
130 refreshDisplayTime = 1. / wao.uiBase.wao_frameRate.value()
132 if (time.time() - wao.refreshTime > refreshDisplayTime):
135 for t
in range(len(wao.config.p_targets)):
136 SR = wao.supervisor.target.get_strehl(t)
138 if (t == wao.uiAO.wao_dispSR_tar.value()
140 wao.updateSRDisplay(SR[1], SR[0],
141 wao.supervisor.get_frame_counter())
142 signal_se +=
"%1.2f " % SR[0]
143 signal_le +=
"%1.2f " % SR[1]
145 currentFreq = 1 / loopTime
146 refreshFreq = 1 / (time.time() - wao.refreshTime)
148 wao.updateSRSE(signal_se)
149 wao.updateSRLE(signal_le)
150 wao.updateCurrentLoopFrequency(currentFreq)
152 if (wao.dispStatsInTerminal):
154 "iter #%d SR: (L.E, S.E.)= (%s, %s) running at %4.1fHz (real %4.1fHz)"
155 % (wao.supervisor.get_frame_counter(), signal_le,
156 signal_se, refreshFreq, currentFreq))
157 if (self.
wao2wao2.uiAO.actionShow_Pyramid_Tools.isChecked()):
158 self.
wpyrwpyr.Fe = 1 / self.config.p_loop.ittime
159 if (self.
wpyrwpyr.CBNumber == 1):
160 self.
aiai = self.compute_modal_residuals()
164 aiVect = self.compute_modal_residuals()
165 self.
aiai = aiVect[np.newaxis, :]
169 aiVect = self.compute_modal_residuals()
170 self.
aiai = np.concatenate((self.
aiai, aiVect[np.newaxis, :]))
177 def next(self, nbIters):
178 ''' Move atmos -> get_slopes -> applyControl ; One integrator step '''
179 for i
in track(range(nbIters)):
183 ADOPTPATH = os.getenv(
"ADOPTPATH")
184 sys.path.append(ADOPTPATH +
"/widgets")
185 from pyrStats
import widget_pyrStats
186 print(
"OK Pyramid Tools Widget initialized")
187 self.
wpyrwpyr = widget_pyrStats()
192 self.
wpyrwpyr.pup = self.
managermanager.second_stage.config.p_geom._spupil
193 self.
wpyrwpyr.phase = self.supervisor.target.get_tar_phase(0, pupil=
True)
194 self.
wpyrwpyr.updateResiduals(ai)
196 print(
'computing phase 2 Modes basis')
197 self.
phase_to_modesphase_to_modes = self.
managermanager.second_stage.basis.compute_phase_to_modes(self.modal_basis)
201 if (self.
wpyrwpyr
is None):
203 print(
"Lauching pyramid widget...")
207 raise ValueError(
"ERROR: ADOPT not found. Cannot launch Pyramid tools")
209 if (self.
wao2wao2.uiAO.actionShow_Pyramid_Tools.isChecked()):
215 return self.
wpyrwpyr.ai
221 from subprocess
import Popen, PIPE
222 from hraa.server.pyroServer
import PyroServer
224 Pyro4.config.REQUIRE_EXPOSE =
False
225 p = Popen(
"whoami", shell=
True, stdout=PIPE, stderr=PIPE)
226 out, err = p.communicate()
229 raise Exception(
"ERROR CANNOT RECOGNIZE USER")
231 user = out.split(b
"\n")[0].decode(
"utf-8")
232 print(
"User is " + user)
233 supervisor = self.
managermanager
234 supervisor1 = self.
managermanager.first_stage
235 supervisor2 = self.
managermanager.second_stage
237 if(supervisor1.corono ==
None):
239 coro2pyro1 = PyroEmptyClass()
241 coro2pyro1 = supervisor1.corono
243 if(supervisor2.corono ==
None):
245 coro2pyro2 = PyroEmptyClass()
247 coro2pyro2 = supervisor2.corono
250 supervisor1, supervisor1.rtc, supervisor1.wfs, supervisor1.target,
251 supervisor1.tel, supervisor1.basis, supervisor1.calibration,
252 supervisor1.atmos, supervisor1.dms, supervisor1.config, supervisor1.modalgains,
256 supervisor2, supervisor2.rtc, supervisor2.wfs, supervisor2.target,
257 supervisor2.tel, supervisor2.basis, supervisor2.calibration,
258 supervisor2.atmos, supervisor2.dms, supervisor2.config, supervisor2.modalgains,
262 "supervisor",
"supervisor_rtc",
"supervisor_wfs",
"supervisor_target",
263 "supervisor_tel",
"supervisor_basis",
"supervisor_calibration",
264 "supervisor_atmos",
"supervisor_dms",
"supervisor_config",
"supervisor_modalgains",
271 nname.append(name +
"_" + user +
"_" +label)
273 label =
"secondStage"
275 nname.append(name +
"_" + user +
"_" +label)
277 nname.append(
'twoStagesManager'+
"_" + user )
278 nname.append(
"wao_loop"+
"_" + user)
279 devices = devices1 + devices2 + [supervisor, wao_loop]
280 server = PyroServer(listDevices=devices, listNames=nname)
286 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")
296 self.
waowao.aoLoopClicked(
True)
297 self.
waowao.uiAO.wao_run.setChecked(
True)
300 self.
waowao.aoLoopClicked(
False)
301 self.
waowao.uiAO.wao_run.setChecked(
False)
307 if __name__ ==
'__main__':
308 arguments = docopt(__doc__)
309 adopt = arguments[
"--adopt"]
310 app = QtWidgets.QApplication(sys.argv)
311 app.setStyle(
'cleanlooks')
313 arguments[
"<parameters_filename2>"],
314 arguments[
"<freqratio>"], cacao=adopt)
318 wao.wao2.uiAO.wao_run.hide()
319 wao.wao2.uiAO.wao_next.hide()
320 wao.wao2.uiAO.wao_atmosphere.hide()
321 wao.wao1.loop_once = wao.loop_once
322 wao.wao2.loop_once = wao.loop_once
Class handling both supervisors of first stage and second stage.
Parameter classes for COMPASS.
Initialization and execution of a CANAPASS supervisor.