COMPASS  5.4.4
End-to-end AO simulation tool using GPU acceleration
canapassSupervisor.py
1 
37 """
38 Initialization and execution of a CANAPASS supervisor
39 
40 Usage:
41  canapassSupervisor.py <parameters_filename> [options]
42 
43 with 'parameters_filename' the path to the parameters file
44 
45 Options:
46  -h, --help Show this help message and exit
47  -f, --freq freq change the frequency of the loop
48  -d, --delay delay change the delay of the loop
49  -s, --spiders spiders change the spiders size
50  -n, --nxsub nxsub change the number of pixels in subap
51  -p, --pupsep pupsep change the distance between subap center and frame center
52  -g, --gsmag gsmag change guide star magnitude
53  -r, --rmod rmod change modulation radius
54  -x, --offaxis offaxis change all targets position along x axis
55  -r0,--setr0 setr0 change the global r0
56 """
57 
58 import numpy as np
59 
60 from subprocess import Popen, PIPE
61 
62 import shesha.ao as ao
63 import shesha.constants as scons
64 
65 from shesha.supervisor.compassSupervisor import CompassSupervisor
66 
67 # from carmaWrap.obj import obj_Double2D
68 # from carmaWrap.magma import syevd_Double, svd_host_Double
69 # from carmaWrap.context import context as carmaWrap_context
70 
71 # from carmaWrap.host_obj import host_obj_Double1D, host_obj_Double2D
72 
73 
75 
76  def __init__(self, config, cacao: bool = True) -> None:
77  print("switching to a generic controller")
78  config.p_controllers[0].type = scons.ControllerType.GENERIC
79  CompassSupervisor.__init__(self, config, cacao=cacao)
80 
81 
82 
83 
84 # def initModalGain(self, gain, cmatModal, modal_basis, control=0, reset_gain=True):
85 # """
86 # Given a gain, cmat and btt2v initialise the modal gain mode
87 # """
88 # print("TODO: A RECODER !!!!")
89 # nmode_total = modal_basis.shape[1]
90 # nactu_total = modal_basis.shape[0]
91 # nfilt = nmode_total - cmatModal.shape[0]
92 # ctrl = self._sim.rtc.d_control[control]
93 # ctrl.set_commandlaw('modal_integrator')
94 # cmat = np.zeros((nactu_total, cmatModal.shape[1]))
95 # dec = cmat.shape[0] - cmatModal.shape[0]
96 # cmat[:-dec, :] += cmatModal # Fill the full Modal with all non-filtered modes
97 # modes2V = np.zeros((nactu_total, nactu_total))
98 # dec2 = modes2V.shape[1] - modal_basis.shape[1]
99 # modes2V[:, :-dec2] += modal_basis
100 # mgain = np.ones(len(modes2V)) * gain # Initialize the gain
101 # ctrl.set_matE(modes2V)
102 # ctrl.set_cmat(cmat)
103 # if reset_gain:
104 # ctrl.set_modal_gains(mgain)
105 
106 # def leaveModalGain(self, control=0):
107 # ctrl = self._sim.rtc.d_control[control]
108 # ctrl.set_commandlaw('integrator')
109 
110 class loopHandler:
111 
112  def __init__(self):
113  pass
114 
115  def start(self):
116  pass
117 
118  def stop(self):
119  pass
120 
121  def alive(self):
122  return "alive"
123 
124 if __name__ == '__main__':
125  from docopt import docopt
126  from shesha.config import ParamConfig
127  arguments = docopt(__doc__)
128  config = ParamConfig(arguments["<parameters_filename>"])
129  if (arguments["--freq"]):
130  print("Warning changed frequency loop to: ", arguments["--freq"])
131  config.p_loop.set_ittime(1 / float(arguments["--freq"]))
132  if (arguments["--delay"]):
133  print("Warning changed delay loop to: ", arguments["--delay"])
134  config.p_controllers[0].set_delay(float(arguments["--delay"]))
135  if (arguments["--spiders"]):
136  print("Warning changed spiders size to: ", arguments["--spiders"])
137  config.p_tel.set_t_spiders(float(arguments["--spiders"]))
138  if (arguments["--nxsub"]):
139  print("Warning changed number of pixels per subaperture to: ", arguments["--nxsub"])
140  config.p_wfss[0].set_nxsub(int(arguments["--nxsub"]))
141  if (arguments["--pupsep"]):
142  print("Warning changed distance between subaperture center and frame center to: ", arguments["--pupsep"])
143  config.p_wfss[0].set_pyr_pup_sep(int(arguments["--pupsep"]))
144  if (arguments["--gsmag"]):
145  print("Warning changed guide star magnitude to: ", arguments["--gsmag"])
146  config.p_wfss[0].set_gsmag(float(arguments["--gsmag"]))
147  if (arguments["--setr0"]):
148  print("Warning changed r0 to: ", arguments["--setr0"])
149  config.p_atmos.set_r0(float(arguments["--setr0"]))
150  if (arguments["--rmod"]):
151  print("Warning changed modulation radius to: ", arguments["--rmod"])
152  rMod = int(arguments["--rmod"])
153  nbPtMod = int(np.ceil(int(rMod * 2 * 3.141592653589793) / 4.) * 4)
154  config.p_wfss[0].set_pyr_npts(nbPtMod)
155  config.p_wfss[0].set_pyr_ampl(rMod)
156  if (arguments["--offaxis"]):
157  print("Warning changed target x position: ", arguments["--offaxis"])
158  config.p_targets[0].set_xpos(float(arguments["--offaxis"]))
159  config.p_targets[1].set_xpos(float(arguments["--offaxis"]))
160  config.p_targets[2].set_xpos(float(arguments["--offaxis"]))
161 
162  supervisor = CanapassSupervisor(config, cacao=True)
163 
164  try:
165  from subprocess import Popen, PIPE
166  from hraa.server.pyroServer import PyroServer
167  import Pyro4
168  Pyro4.config.REQUIRE_EXPOSE = False
169  p = Popen("whoami", shell=True, stdout=PIPE, stderr=PIPE)
170  out, err = p.communicate()
171  if (err != b''):
172  print(err)
173  raise Exception("ERROR CANNOT RECOGNIZE USER")
174  else:
175  user = out.split(b"\n")[0].decode("utf-8")
176  print("User is " + user)
177  if (supervisor.corono == None):
178  from shesha.util.pyroEmptyClass import PyroEmptyClass
179  coro2pyro = PyroEmptyClass()
180  else:
181  coro2pyro = supervisor.corono
182  devices = [
183  supervisor, supervisor.rtc, supervisor.wfs, supervisor.target,
184  supervisor.tel, supervisor.basis, supervisor.calibration,
185  supervisor.atmos, supervisor.dms, supervisor.config, supervisor.modalgains, coro2pyro
186  ]
187  names = [
188  "supervisor", "supervisor_rtc", "supervisor_wfs", "supervisor_target",
189  "supervisor_tel", "supervisor_basis", "supervisor_calibration",
190  "supervisor_atmos", "supervisor_dms", "supervisor_config", "supervisor_modalgains", "supervisor_corono",
191  ]
192  nname = []
193  for name in names:
194  nname.append(name + "_" + user)
195  server = PyroServer(listDevices=devices, listNames=nname)
196  #server.add_device(supervisor, "waoconfig_" + user)
197  server.start()
198  except:
199  raise EnvironmentError(
200  "Missing dependencies (code HRAA or Pyro4 or Dill Serializer)")
Shesha parameters configuration class.
Definition: pconfig.py:51
This class implements generic supervisor to handle compass simulation.
This file is here only to avoid pyro server crash when a coronograph class is not in the pramam file.
Python package for AO operations on COMPASS simulation.
Definition: ao/__init__.py:1
Parameter classes for COMPASS.
Numerical constants for shesha and config enumerations for safe-typing.
Definition: constants.py:1
Initialization and execution of a COMPASS supervisor.