COMPASS  5.0.0
End-to-end AO simulation tool using GPU acceleration
shesha.ao.imats Namespace Reference

Computation implementations of interaction matrix. More...

Functions

np.ndarray imat_geom (Sensors wfs, Dms dms, List[conf.Param_wfs] p_wfss, List[conf.Param_dm] p_dms, conf.Param_controller p_controller, int meth=0)
 Compute the interaction matrix with a geometric method. More...
 
None imat_init (int ncontrol, Rtc rtc, Dms dms, list p_dms, Sensors wfs, list p_wfss, conf.Param_tel p_tel, conf.Param_controller p_controller, M2V=None, dict dataBase={}, bool use_DB=False)
 Initialize and compute the interaction matrix on the GPU. More...
 
np.ndarray imat_geom_ts_multiple_direction (Sensors wfs, Dms dms, List[conf.Param_wfs] p_wfss, List[conf.Param_dm] p_dms, conf.Param_geom p_geom, int ind_TS, List ind_dmseen, conf.Param_tel p_tel, x, y, int meth=0)
 Compute the interaction matrix with a geometric method for multiple truth sensors (with different direction) More...
 
np.ndarray imat_geom_ts (Sensors wfs, Dms dms, conf.Param_wfs p_wfss, int ind_TS, List[conf.Param_dm] p_dms, List[int] ind_DMs, int meth=0)
 Compute the interaction matrix with a geometric method for a single truth sensor. More...
 
def get_metaD (sup, TS_xpos=None, TS_ypos=None, ind_TS=-1, save_metaD=False, nControl=0)
 Create an interaction matrix for the current simulation given TS position :parameters: sim current COMPASS simulation TS_xpos np.ndarray : TS position (x axis) TS_ypos np.ndarray : TS position (y axis) More...
 

Detailed Description

Computation implementations of interaction matrix.

Author
COMPASS Team https://github.com/ANR-COMPASS
Version
5.0.0
Date
2020/05/18

This file is part of COMPASS https://anr-compass.github.io/compass/

Copyright (C) 2011-2019 COMPASS Team https://github.com/ANR-COMPASS All rights reserved. Distributed under GNU - LGPL

COMPASS is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.

COMPASS: End-to-end AO simulation tool using GPU acceleration The COMPASS platform was designed to meet the need of high-performance for the simulation of AO systems.

The final product includes a software package for simulating all the critical subcomponents of AO, particularly in the context of the ELT and a real-time core based on several control approaches, with performances consistent with its integration into an instrument. Taking advantage of the specific hardware architecture of the GPU, the COMPASS tool allows to achieve adequate execution speeds to conduct large simulation campaigns called to the ELT.

The COMPASS platform can be used to carry a wide variety of simulations to both testspecific components of AO of the E-ELT (such as wavefront analysis device with a pyramid or elongated Laser star), and various systems configurations such as multi-conjugate AO.

COMPASS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with COMPASS. If not, see https://www.gnu.org/licenses/lgpl-3.0.txt.

Function Documentation

◆ get_metaD()

def shesha.ao.imats.get_metaD (   sup,
  TS_xpos = None,
  TS_ypos = None,
  ind_TS = -1,
  save_metaD = False,
  nControl = 0 
)

Create an interaction matrix for the current simulation given TS position :parameters: sim current COMPASS simulation TS_xpos np.ndarray : TS position (x axis) TS_ypos np.ndarray : TS position (y axis)

:return: metaD np.ndarray :interaction matrix

Definition at line 315 of file imats.py.

315  """
316  if (TS_xpos is None):
317  TS_xpos = np.array([t.xpos for t in sup.config.p_wfs_ts])
318  elif (isinstance(TS_xpos, list)):
319  TS_xpos = np.array(TS_xpos)
320  elif (isinstance(TS_xpos, int) or isinstance(TS_xpos, float)):
321  TS_xpos = np.array([TS_xpos]).astype(np.float32)
322  if (TS_xpos.size < 1):
323  TS_xpos = np.zeros((1))
324 
325  if (TS_ypos is None):
326  TS_ypos = np.array([t.ypos for t in sup.config.p_wfs_ts])
327  elif (isinstance(TS_ypos, list)):
328  TS_ypos = np.array(TS_ypos)
329  elif (isinstance(TS_ypos, int) or isinstance(TS_ypos, float)):
330  TS_ypos = np.array([TS_ypos]).astype(np.float32)
331  if (TS_ypos.size < 1):
332  TS_ypos = np.zeros((1))
333 
334  return imat_geom_ts_multiple_direction(sup._sim.wfs, sup._sim.dms, sup.config.p_wfss,
335  sup.config.p_dms, sup.config.p_geom, ind_TS,
336  sup.config.p_controllers[nControl].ndm,
337  sup.config.p_tel, TS_xpos, TS_ypos)
Here is the call graph for this function:

◆ imat_geom()

np.ndarray shesha.ao.imats.imat_geom ( Sensors  wfs,
Dms  dms,
List[conf.Param_wfs]  p_wfss,
List[conf.Param_dm]  p_dms,
conf.Param_controller  p_controller,
int   meth = 0 
)

Compute the interaction matrix with a geometric method.

:parameters:

wfs (Sensors) : Sensors object

dms (Dms) : Dms object

p_wfss (list of Param_wfs) : wfs settings

p_dms (list of Param_dm) : dms settings

p_controller (Param_controller) : controller settings

meth (int) : (optional) method type (0 or 1)

Definition at line 70 of file imats.py.

70 
71  meth: (int) : (optional) method type (0 or 1)
72  """
73 
74  nwfs = p_controller.nwfs.size
75  ndm = p_controller.ndm.size
76  imat_size1 = 0
77  imat_size2 = 0
78 
79  for dm in dms.d_dms:
80  dm.reset_shape()
81 
82  for nw in range(nwfs):
83  nm = p_controller.nwfs[nw]
84  imat_size1 += p_wfss[nm]._nvalid * 2
85 
86  for nmc in range(ndm):
87  nm = p_controller.ndm[nmc]
88  imat_size2 += p_dms[nm]._ntotact
89 
90  imat_cpu = np.zeros((imat_size1, imat_size2), dtype=np.float32)
91  ind = 0
92  cc = 0
93  print("Doing imat geom...")
94  for nmc in range(ndm):
95  nm = p_controller.ndm[nmc]
96  dms.d_dms[nm].reset_shape()
97  for i in tqdm(range(p_dms[nm]._ntotact), desc="DM%d" % nmc):
98  dms.d_dms[nm].comp_oneactu(i, p_dms[nm].push4imat)
99  nslps = 0
100  for nw in range(nwfs):
101  n = p_controller.nwfs[nw]
102  wfs.d_wfs[n].d_gs.raytrace(dms, rst=1)
103  wfs.d_wfs[n].slopes_geom(meth)
104  imat_cpu[nslps:nslps + p_wfss[n]._nvalid * 2, ind] = np.array(
105  wfs.d_wfs[n].d_slopes)
106  nslps += p_wfss[n]._nvalid * 2
107  imat_cpu[:, ind] = imat_cpu[:, ind] / p_dms[nm].push4imat
108  ind = ind + 1
109  cc = cc + 1
110  dms.d_dms[nm].reset_shape()
111 
112  return imat_cpu
113 
114 

◆ imat_geom_ts()

np.ndarray shesha.ao.imats.imat_geom_ts ( Sensors  wfs,
Dms  dms,
conf.Param_wfs  p_wfss,
int  ind_TS,
List[conf.Param_dm]  p_dms,
List[int]  ind_DMs,
int   meth = 0 
)

Compute the interaction matrix with a geometric method for a single truth sensor.

:parameters:

wfs (Sensors) : Sensors object

dms (Dms) : Dms object

p_wfss (list of Param_wfs) : wfs settings

ind_TS (int) : index of the truth sensor in the wfs settings list

p_dms (list of Param_dm) : dms settings

ind_DMs (list of int) : indices of used DMs

p_controller (Param_controller) : controller settings

meth (int) : (optional) method type (0 or 1)

Definition at line 268 of file imats.py.

268 
269  meth: (int) : (optional) method type (0 or 1)
270  """
271 
272  #nwfs = 1 #p_controller.nwfs.size # as parameter list of indices for wfs if several ts (only 1 ts for now)
273  ndm = len(ind_DMs) #p_controller.ndm.size # as parameter list of indices of used dms
274  imat_size1 = p_wfss[ind_TS]._nvalid * 2 # as parameter (nvalid)
275  imat_size2 = 0
276 
277  # for nw in range(nwfs):
278  # nm = p_controller.nwfs[nw]
279  # imat_size1 += p_wfss[nm]._nvalid * 2
280 
281  for dm in dms.d_dms:
282  dm.reset_shape()
283 
284  imat_size2 = 0
285  for nm in ind_DMs:
286  imat_size2 += p_dms[nm]._ntotact
287 
288  imat_cpu = np.zeros((imat_size1, imat_size2), dtype=np.float64)
289  ind = 0
290  cc = 0
291  for nm in tqdm(ind_DMs, desc="imat geom DM"):
292  dms.d_dms[nm].reset_shape()
293  for i in trange(p_dms[nm]._ntotact, desc="imat geom actu"):
294  dms.d_dms[nm].comp_oneactu(i, p_dms[nm].push4imat)
295  wfs.d_wfs[ind_TS].d_gs.raytrace(dms, rst=1)
296  wfs.d_wfs[ind_TS].slopes_geom(meth)
297  imat_cpu[:, ind] = np.array(wfs.d_wfs[ind_TS].d_slopes)
298  imat_cpu[:, ind] = imat_cpu[:, ind] / p_dms[nm].push4imat
299  ind = ind + 1
300  cc = cc + 1
301  dms.d_dms[nm].reset_shape()
302 
303  return imat_cpu
304 
305 
Here is the caller graph for this function:

◆ imat_geom_ts_multiple_direction()

np.ndarray shesha.ao.imats.imat_geom_ts_multiple_direction ( Sensors  wfs,
Dms  dms,
List[conf.Param_wfs]  p_wfss,
List[conf.Param_dm]  p_dms,
conf.Param_geom  p_geom,
int  ind_TS,
List  ind_dmseen,
conf.Param_tel  p_tel,
  x,
  y,
int   meth = 0 
)

Compute the interaction matrix with a geometric method for multiple truth sensors (with different direction)

:parameters:

wfs (Sensors) : Sensors object

dms (Dms) : Dms object

p_wfss (list of Param_wfs) : wfs settings

ind_TS (int) : index of the truth sensor in the wfs settings list

p_dms (list of Param_dm) : dms settings

ind_DMs (list of int) : indices of used DMs

p_controller (Param_controller) : controller settings

meth (int) : (optional) method type (0 or 1)

Definition at line 202 of file imats.py.

202  p_controller: (Param_controller) : controller settings
203 
204  meth: (int) : (optional) method type (0 or 1)
205  """
206  p_wfs = p_wfss[ind_TS]
207  imat_size2 = 0
208  print("DMS_SEEN: ", ind_dmseen)
209  for nm in ind_dmseen:
210  imat_size2 += p_dms[nm]._ntotact
211  imat_cpu = np.ndarray((0, imat_size2))
212 
213  for i in trange(x.size, desc="TS pos"):
214  xpos = x[i]
215  ypos = y[i]
216  for k in ind_dmseen:
217  dims = p_dms[k]._n2 - p_dms[k]._n1 + 1
218  dim = p_geom._mpupil.shape[0]
219  if (dim < dims):
220  dim = dims
221  xoff = xpos * CONST.ARCSEC2RAD * \
222  p_dms[k].alt / p_tel.diam * p_geom.pupdiam
223  yoff = ypos * CONST.ARCSEC2RAD * \
224  p_dms[k].alt / p_tel.diam * p_geom.pupdiam
225  xoff = xoff + (dim - p_geom._n) / 2
226  yoff = yoff + (dim - p_geom._n) / 2
227  wfs.d_wfs[ind_TS].d_gs.add_layer(p_dms[k].type, k, xoff, yoff)
228  imat_cpu = np.concatenate(
229  (imat_cpu, imat_geom_ts(wfs, dms, p_wfss, ind_TS, p_dms, ind_dmseen,
230  meth)), axis=0)
231 
232  for k in ind_dmseen:
233  dims = p_dms[k]._n2 - p_dms[k]._n1 + 1
234  dim = p_geom._mpupil.shape[0]
235  if (dim < dims):
236  dim = dims
237  xoff = p_wfs.xpos * CONST.ARCSEC2RAD * \
238  p_dms[k].alt / p_tel.diam * p_geom.pupdiam
239  yoff = p_wfs.ypos * CONST.ARCSEC2RAD * \
240  p_dms[k].alt / p_tel.diam * p_geom.pupdiam
241  xoff = xoff + (dim - p_geom._n) / 2
242  yoff = yoff + (dim - p_geom._n) / 2
243  wfs.d_wfs[ind_TS].d_gs.add_layer(p_dms[k].type, k, xoff, yoff)
244 
245  return imat_cpu
246 
247 
Here is the call graph for this function:
Here is the caller graph for this function:

◆ imat_init()

None shesha.ao.imats.imat_init ( int  ncontrol,
Rtc  rtc,
Dms  dms,
list  p_dms,
Sensors  wfs,
list  p_wfss,
conf.Param_tel  p_tel,
conf.Param_controller  p_controller,
  M2V = None,
dict   dataBase = {},
bool   use_DB = False 
)

Initialize and compute the interaction matrix on the GPU.

:parameters:

ncontrol (int) : controller's index

rtc (Rtc) : Rtc object

dms (Dms) : Dms object

p_dms (Param_dms) : dms settings

wfs (Sensors) : Sensors object

p_wfss (list of Param_wfs) : wfs settings

p_tel (Param_tel) : telescope settings

p_controller (Param_controller) : controller settings

M2V KL_matrix

dataBase (optional) dict containing paths to files to load

use_DB (optional) use dataBase flag

Definition at line 141 of file imats.py.

141 
142  use_DB:(bool) : (optional) use dataBase flag
143  """
144  # first check if wfs is using lgs
145  # if so, load new lgs spot, just for imat
146  for i in range(len(p_wfss)):
147  if (p_wfss[i].gsalt > 0):
148  # TODO: check that
149  save_profile = p_wfss[i].proftype
150  p_wfss[i].proftype = scons.ProfType.GAUSS1
151  lgs.prep_lgs_prof(p_wfss[i], i, p_tel, wfs, imat=1)
152 
153  if "imat" in dataBase:
154  imat = h5u.load_imat_from_dataBase(dataBase)
155  rtc.d_control[ncontrol].set_imat(imat)
156  else:
157  t0 = time.time()
158  if M2V is not None:
159  p_controller._M2V = M2V.copy()
160  rtc.do_imat_basis(ncontrol, dms, M2V.shape[1], M2V, p_controller.klpush)
161  else:
162  rtc.do_imat(ncontrol, dms)
163  print("done in %f s" % (time.time() - t0))
164  imat = np.array(rtc.d_control[ncontrol].d_imat)
165  if use_DB:
166  h5u.save_imat_in_dataBase(imat)
167  p_controller.set_imat(imat)
168 
169  # Restore original profile in lgs spots
170  for i in range(len(p_wfss)):
171  if (p_wfss[i].gsalt > 0):
172  p_wfss[i].proftype = save_profile
173  lgs.prep_lgs_prof(p_wfss[i], i, p_tel, wfs)
174 
175 
176 #write imat_ts:
177 # loop over ts directions
178 # change WFS offset to direction
179 # do imat geom
180 
181