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

Computation implementations of command matrix. More...

Functions

np.ndarray generic_imat_inversion (np.ndarray M2V, np.ndarray modalIMat, np.ndarray modeSelect=None, np.ndarray modeGains=None)
 Generic numpy modal interaction matrix inversion function. More...
 
None cmat_init (int ncontrol, Rtc rtc, conf.Param_controller p_controller, List[conf.Param_wfs] p_wfss, conf.Param_atmos p_atmos, conf.Param_tel p_tel, List[conf.Param_dm] p_dms, int nmodes=0)
 Compute the command matrix on the GPU. More...
 
def svd_for_cmat (D)
 
def Btt_for_cmat (rtc, dms, p_dms, p_geom)
 Compute a command matrix in Btt modal basis (see error breakdown) and set it on the sutra_rtc. More...
 
def get_cmat (D, nfilt, Btt=None, rtc=None, svd=None)
 Compute a command matrix from an interaction matrix 'D'. More...
 

Detailed Description

Computation implementations of command 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

◆ Btt_for_cmat()

def shesha.ao.cmats.Btt_for_cmat (   rtc,
  dms,
  p_dms,
  p_geom 
)

Compute a command matrix in Btt modal basis (see error breakdown) and set it on the sutra_rtc.

It computes by itself the volts to Btt matrix.

:parameters:

rtc (Rtc) : rtc object

dms (Dms): dms object

p_dms (list of Param_dm): dms settings

p_geom (Param_geom): geometry settings

Definition at line 178 of file cmats.py.

178  """
179 
180  IFs = basis.compute_IFsparse(dms, p_dms, p_geom).T
181  n = IFs.shape[1]
182  IFtt = IFs[:, -2:].toarray()
183  IFpzt = IFs[:, :n - 2]
184 
185  Btt, P = basis.compute_btt(IFpzt, IFtt)
186  return Btt, P
187 
188 

◆ cmat_init()

None shesha.ao.cmats.cmat_init ( int  ncontrol,
Rtc  rtc,
conf.Param_controller  p_controller,
List[conf.Param_wfs]  p_wfss,
conf.Param_atmos  p_atmos,
conf.Param_tel  p_tel,
List[conf.Param_dm]  p_dms,
int   nmodes = 0 
)

Compute the command matrix on the GPU.

:parameters:

ncontrol (int) :

rtc (Rtc) :

p_controller (Param_controller) : controller settings

p_wfss (list of Param_wfs) : wfs settings

p_atmos (Param_atmos) : atmos settings

p_tel (Param_tel) : telescope settings

p_dms (list of Param_dm) : dms settings

M2V (np.ndarray[ndim=2, dtype=np.float32]): (optional) KL to volts matrix (for KL cmat)

nmodes (int) : (optional) number of kl modes

Definition at line 104 of file cmats.py.

104  M2V : (np.ndarray[ndim=2, dtype=np.float32]): (optional) KL to volts matrix (for KL cmat)
105 
106  nmodes: (int) : (optional) number of kl modes
107  """
108  if (p_controller.type == scons.ControllerType.LS):
109  print("Doing imat svd...")
110  t0 = time.time()
111  rtc.d_control[ncontrol].svdec_imat()
112  print("svd done in %f s" % (time.time() - t0))
113  eigenv = np.array(rtc.d_control[ncontrol].d_eigenvals)
114  imat = np.array(rtc.d_control[ncontrol].d_imat)
115  maxcond = p_controller.maxcond
116  if (eigenv[0] < eigenv[eigenv.shape[0] - 1]):
117  mfilt = np.where((eigenv / eigenv[eigenv.shape[0] - 3]) < 1. / maxcond)[0]
118  else:
119  mfilt = np.where((1. / (eigenv / eigenv[2])) > maxcond)[0]
120  nfilt = mfilt.shape[0]
121 
122  print("Building cmat...")
123  t0 = time.time()
124  if not p_controller.do_kl_imat:
125  print("Filtering ", nfilt, " modes")
126  rtc.d_control[ncontrol].build_cmat(nfilt)
127  else:
128  # filter imat
129  D_filt = imat.copy()
130  # Direct inversion
131  Dp_filt = np.linalg.inv(D_filt.T.dot(D_filt)).dot(D_filt.T)
132  if (p_controller.klgain is not None):
133  Dp_filt *= p_controller.klgain[None, :]
134  cmat_filt = p_controller._M2V.dot(Dp_filt)
135  rtc.d_control[ncontrol].set_cmat(cmat_filt)
136 
137  print("cmat done in %f s" % (time.time() - t0))
138 
139  if (p_controller.type == scons.ControllerType.MV):
140  Cn = np.zeros(p_controller._imat.shape[0], dtype=np.float32)
141  ind = 0
142  for k in p_controller.nwfs:
143  Cn[ind:ind + 2 * p_wfss[k]._nvalid] = noise_cov(k, p_wfss[k], p_atmos, p_tel)
144  ind += 2 * p_wfss[k]._nvalid
145 
146  rtc.d_control[ncontrol].load_noisemat(Cn)
147  print("Building cmat...")
148  rtc.d_control[ncontrol].build_cmat(p_controller.maxcond)
149 
150  if (p_controller.TTcond == None):
151  p_controller.set_TTcond(p_controller.maxcond)
152 
153  if ("tt" in [dm.type for dm in p_dms]):
154  rtc.d_control[ncontrol].filter_cmat(p_controller.TTcond)
155  print("Done")
156  p_controller.set_cmat(np.array(rtc.d_control[ncontrol].d_cmat))
157 
158 

◆ generic_imat_inversion()

np.ndarray shesha.ao.cmats.generic_imat_inversion ( np.ndarray  M2V,
np.ndarray  modalIMat,
np.ndarray   modeSelect = None,
np.ndarray   modeGains = None 
)

Generic numpy modal interaction matrix inversion function.

   :parameters:

M2V (nActu x nModes) : modal basis matrix

modalIMat (nSlopes x nModes) : modal interaction matrix

modeSelect (nModes, dtype=bool): (Optional): mode selection, mode at False is filtered

modeGains (nModes, dtype=bool): (Optional): modal gains to apply. These are gain in the reconstruction sens, ie they are applied multiplicatively on the command matrix

Definition at line 67 of file cmats.py.

67  mode selection, mode at False is filtered
68 
69  modeGains: (nModes, dtype=bool): (Optional):
70  modal gains to apply. These are gain in the reconstruction sens, ie
71  they are applied multiplicatively on the command matrix
72  """
73  if modeSelect is None:
74  modeSelect = np.ones(modalIMat.shape[1], dtype=bool)
75  if modeGains is None:
76  modeGains = np.ones(modalIMat.shape[1], dtype=np.float32)
77 
78  return M2V.dot(modeGains[:, None] * np.linalg.inv(modalIMat[:, modeSelect].T.dot(
79  modalIMat[:, modeSelect])).dot(modalIMat[:, modeSelect].T))
80 
81 

◆ get_cmat()

def shesha.ao.cmats.get_cmat (   D,
  nfilt,
  Btt = None,
  rtc = None,
  svd = None 
)

Compute a command matrix from an interaction matrix 'D'.

usage: get_cmat(D,nfilt) get_cmat(D,nfilt,Btt=BTT,rtc=RTC) get_cmat(D,nfilt,svd=SVD)

:parameters: D (np.ndarray[ndim=2, dtype=np.float32]): interaction matrix

nfilt (int): number of element to filter

Btt (np.ndarray[ndim=2, dtype=np.float32]): Btt modal basis

rtc (Rtc) :

svd (tuple of np.ndarray[ndim=1, dtype=np.float32): svd of D.T*D (obtained from np.linalg.svd)

Definition at line 207 of file cmats.py.

207  """
208  nfilt = max(nfilt, 0) #nfilt is positive
209  if (Btt is not None):
210  if (svd is not None):
211  raise ValueError("Btt and SVD cannt be used together")
212  if (rtc is None):
213  raise ValueError("Btt cannot be used without rtc")
214  n = Btt.shape[1]
215  index = np.concatenate((np.arange(n - nfilt - 2), np.array([n - 2,
216  n - 1]))).astype(int)
217  Btt_filt = Btt[:, index]
218  # Modal interaction basis
219  Dm = D.dot(Btt_filt)
220  # Direct inversion
221  Dmp = np.linalg.inv(Dm.T.dot(Dm)).dot(Dm.T)
222  # Command matrix
223  cmat = Btt_filt.dot(Dmp)
224  else:
225  if (svd is not None):
226  u = svd[0]
227  s = svd[1]
228  v = svd[2]
229  else:
230  u, s, v = svd_for_cmat(D)
231  s_filt = 1 / s
232  if (nfilt > 0):
233  s_filt[-nfilt:] = 0
234  DtDx = v.T.dot(np.diag(s_filt)).dot(u.T)
235  cmat = DtDx.dot(D.T)
236 
237  return cmat.astype(np.float32)
Here is the call graph for this function:

◆ svd_for_cmat()

def shesha.ao.cmats.svd_for_cmat (   D)

Definition at line 159 of file cmats.py.

159 def svd_for_cmat(D):
160  DtD = D.T.dot(D)
161  return np.linalg.svd(DtD)
162 
163 
Here is the caller graph for this function: