COMPASS  5.4.4
End-to-end AO simulation tool using GPU acceleration
rtcAbstract.py
1 
37 
38 from shesha.sutra_wrap import carmaWrap_context
39 
40 from shesha.supervisor.components.sourceCompass import SourceCompass
41 import shesha.constants as scons
42 import numpy as np
43 from typing import Union
44 
45 from abc import ABC, abstractmethod
46 
47 
48 class RtcAbstract(ABC):
49  """ RTC handler for compass simulation
50 
51  Attributes:
52  _rtc : (sutraWrap.Rtc) : Sutra rtc instance
53 
54  _context : (carmaContext) : CarmaContext instance
55 
56  _config : (config module) : Parameters configuration structure module
57 
58  brahma : (bool) : BRAHMA features enabled in the RTC
59 
60  fp16 : (bool) : FP16 features enabled in the RTC
61 
62  cacao : (bool) : CACAO features enabled in the RTC
63  """
64 
65  def __init__(self, context: carmaWrap_context, config, *, brahma: bool = False,
66  fp16: bool = False, cacao: bool = False):
67  """ Initialize a RtcCompass component for rtc related supervision
68 
69  Args:
70  context : (carmaContext) : CarmaContext instance
71 
72  config : (config module) : Parameters configuration structure module
73 
74  Kwargs:
75  brahma : (bool, optional) : If True, enables BRAHMA features in RTC (Default is False)
76  Requires BRAHMA to be installed
77 
78  fp16 : (bool, optional) : If True, enables FP16 features in RTC (Default is False)
79  Requires CUDA_SM>60 to be installed
80 
81  cacao : (bool) : If True, enables CACAO features in RTC (Default is False)
82  Requires OCTOPUS to be installed
83  """
84  self.brahmabrahma = brahma
85  self.fp16fp16 = fp16
86  self.cacaocacao = cacao
87  self._context_context = context
88  self._config_config = config # Parameters configuration coming from supervisor init
89  self._rtc_rtc = None
90 
91  @abstractmethod
92  def rtc_init(self):
93  pass
94 
95  def set_perturbation_voltage(self, controller_index: int, name: str,
96  command: np.ndarray) -> None:
97  """ Add circular buffer of offset values to integrator (will be applied at the end of next iteration)
98 
99  Args:
100  controller_index : (int) : Controller index
101 
102  name : (str) : Buffer name
103 
104  command : (np.ndarray) : perturbation voltage circular buffer
105  """
106  if len(command.shape) == 1:
107  self._rtc_rtc.d_control[controller_index].set_perturb_voltage(name, command, 1)
108  elif len(command.shape) == 2:
109  self._rtc_rtc.d_control[controller_index].set_perturb_voltage(
110  name, command, command.shape[0])
111  else:
112  raise AttributeError("command should be a 1D or 2D array")
113 
114  def get_slopes(self, controller_index: int) -> np.ndarray:
115  """ Return the current slopes vector of the controller_index controller
116 
117  Args:
118  controller_index : (int) : controller index handling the slopes
119 
120  Returns:
121  slopes : (np.ndarray) : Current slopes vector containing slopes of all
122  the WFS handled by the specified controller
123  """
124  return np.array(self._rtc_rtc.d_control[controller_index].d_centroids)
125 
126  def close_loop(self, controller_index: int = None) -> None:
127  """ DM receives controller output + pertuVoltage
128 
129  Kwargs:
130  controller_index: (int): controller index.
131  If None (default), apply on all controllers
132  """
133  if controller_index is None:
134  for controller in self._rtc_rtc.d_control:
135  controller.set_open_loop(0)
136  else:
137  self._rtc_rtc.d_control[controller_index].set_open_loop(0) # close_loop
138 
139  def open_loop(self, controller_index: int = None, reset=True) -> None:
140  """ Integrator computation goes to /dev/null but pertuVoltage still applied
141 
142  Kwargs:
143  controller_index: (int): controller index.
144  If None (default), apply on all controllers
145 
146  reset : (bool) : If True (default), integrator is reset
147  """
148  if controller_index is None:
149  for controller in self._rtc_rtc.d_control:
150  controller.set_open_loop(1, reset)
151  else:
152  self._rtc_rtc.d_control[controller_index].set_open_loop(1, reset) # open_loop
153 
154  def set_ref_slopes(self, ref_slopes: np.ndarray, *,
155  centro_index: int = None) -> None:
156  """ Set given ref slopes in centroider
157 
158  Args:
159  ref_slopes : (ndarray) : Reference slopes vectoronly set the reference slop
160 
161  Kwargs:
162  centro_index : (int) : If given, only set the reference slopes vector
163  used by the specified centroider. If None, the reference
164  slopes vector must be a concatenation of all the reference
165  slopes to use for each centroiders handled by the controller
166  """
167  if (centro_index is None):
168  self._rtc_rtc.set_centroids_ref(ref_slopes)
169  else:
170  self._rtc_rtc.d_centro[centro_index].set_centroids_ref(ref_slopes)
171 
172  def get_ref_slopes(self, centro_index=None) -> np.ndarray:
173  """ Get the currently used reference slopes
174 
175  Kwargs:
176  centro_index : (int) : If given, only get the reference slopes vector
177  used by the specified centroider. If None, the reference
178  slopes vector returned is a concatenation of all the reference
179  slopes used for by centroiders in the RTC
180 
181  Returns:
182  ref_slopes : (np.ndarray) : Reference slopes vector
183  """
184  ref_slopes = np.empty(0)
185  if (centro_index is None):
186  for centro in self._rtc_rtc.d_centro:
187  ref_slopes = np.append(ref_slopes, np.array(centro.d_centroids_ref))
188  return ref_slopes
189  else:
190  return np.array(self._rtc_rtc.d_centro[centro_index].d_centroids_ref)
191 
192  def set_gain(self, controller_index: int, gain: float) -> None:
193  """ Set the scalar gain
194 
195  Args:
196  controller_index : (int) : Index of the controller to modify
197 
198  gain : (float) : scalar gain of modal gain to set
199  """
200  self._rtc_rtc.d_control[controller_index].set_gain(gain)
201 
202  def get_interaction_matrix(self, controller_index: int):
203  """ Return the interaction matrix of the controller
204 
205  Args:
206  controller_index: (int): controller index
207 
208  Returns:
209  imat : (np.ndarray) : Interaction matrix currently set in the controller
210  """
211  return np.array(self._rtc_rtc.d_control[controller_index].d_imat)
212 
213  def get_command_matrix(self, controller_index: int):
214  """ Return the command matrix of the controller
215 
216  Args:
217  controller_index: (int): controller index
218 
219  Returns:
220  cmat : (np.ndarray) : Command matrix currently used by the controller
221  """
222  return np.array(self._rtc_rtc.d_control[controller_index].d_cmat)
223 
224  def set_command_matrix(self, controller_index: int, cmat: np.ndarray) -> None:
225  """ Set the command matrix for the controller to use
226 
227  Args:
228  controller_index : (int) : Controller index to modify
229 
230  cmat : (np.ndarray) : command matrix to set
231  """
232  self._rtc_rtc.d_control[controller_index].set_cmat(cmat)
233 
234  def get_intensities(self) -> np.ndarray:
235  """ Return sum of intensities in subaps. Size nSubaps, same order as slopes
236  """
237  raise NotImplementedError("Not implemented")
238 
239  def set_flat(
240  self,
241  centro_index: int,
242  flat: np.ndarray,
243  ):
244  """ Load flat field for the given wfs
245 
246  Args:
247  centro_index : (int) : index of the centroider handling the WFS
248 
249  flat : (np.ndarray) : New WFS flat to use
250  """
251  self._rtc_rtc.d_centro[centro_index].set_flat(flat, flat.shape[0])
252 
253  def set_dark(self, centro_index: int, dark: np.ndarray):
254  """ Load dark for the given wfs
255 
256  Args:
257  centro_index : (int) : index of the centroider handling the WFS
258 
259  dark : (np.ndarray) : New WFS dark to use
260  """
261  self._rtc_rtc.d_centro[centro_index].set_dark(dark, dark.shape[0])
262 
263  def compute_slopes(self, controller_index: int):
264  """ Compute the slopes handled by a controller, and returns it
265 
266  Args:
267  controller_index : (int) : Controller index that will compute its slopes
268 
269  Returns:
270  slopes : (np.ndarray) : Slopes vector
271  """
272  self._rtc_rtc.do_centroids(controller_index)
273  return self.get_slopesget_slopes(controller_index)
274 
275  def reset_perturbation_voltage(self, controller_index: int) -> None:
276  """ Reset the perturbation voltage of the controller_index controller
277  (i.e. will remove ALL perturbation voltages.)
278  If you want to reset just one, see the function remove_perturbation_voltage()
279 
280  Args:
281  controller_index : (int) : controller index from where to remove the buffer
282  """
283  self._rtc_rtc.d_control[controller_index].reset_perturb_voltage()
284 
285  def remove_perturbation_voltage(self, controller_index: int, name: str) -> None:
286  """ Remove the perturbation voltage called <name>, from the controller number <controller_index>.
287  If you want to remove all of them, see function reset_perturbation_voltage()
288 
289  Args:
290  controller_index : (int) : controller index from where to remove the buffer
291 
292  name : (str) : Name of the buffer to remove
293  """
294  self._rtc_rtc.d_control[controller_index].remove_perturb_voltage(name)
295 
296  def get_perturbation_voltage(self, controller_index: int, *,
297  name: str = None) -> Union[dict, tuple]:
298  """ Get a perturbation voltage buffer
299 
300  Args:
301  controller_index : (int) : controller index from where to get the buffer
302 
303  Kwargs:
304  name : (str) : Name of the buffer to get. If None, returns all the buffers
305 
306  Returns:
307  pertu : (dict or tuple) : If name is None, returns a dictionnary with the buffers names as keys
308  and a tuple (buffer, circular_counter, is_enabled)
309  """
310  pertu_map = self._rtc_rtc.d_control[controller_index].d_perturb_map
311  if name is None:
312  for key in pertu_map.keys():
313  pertu_map[key] = (np.array(pertu_map[key][0]), pertu_map[key][1],
314  pertu_map[key][2])
315  return pertu_map
316  else:
317  pertu = pertu_map[name]
318  pertu = (np.array(pertu[0]), pertu[1], pertu[2])
319  return pertu
320 
321  def get_err(self, controller_index: int) -> np.ndarray:
322  """ Get integrator increment from controller_index controller
323 
324  Args:
325  controller_index : (int) : controller index
326  """
327  return np.array(self._rtc_rtc.d_control[controller_index].d_err)
328 
329  def get_voltages(self, controller_index: int) -> np.ndarray:
330  """ Get voltages vector (i.e. vector sent to the DM) from controller_index controller
331 
332  Args:
333  controller_index : (int) : controller index
334 
335  Returns:
336  voltages : (np.ndarray) : current voltages vector
337 
338  """
339  return np.array(self._rtc_rtc.d_control[controller_index].d_voltage)
340 
341  def set_integrator_law(self, controller_index: int) -> None:
342  """ Set the command law to integrator (controller generic only)
343  v[k] = v[k-1] + g.R.s[k]
344 
345  Args:
346  controller_index: (int): controller index
347  """
348  self._rtc_rtc.d_control[controller_index].set_commandlaw("integrator")
349 
350  def set_2matrices_law(self, controller_index: int) -> None:
351  """ Set the command law to 2matrices (controller generic only)
352  v[k] = decayFactor.E.v[k-1] + g.R.s[k]
353 
354  Args:
355  controller_index: (int): controller index
356  """
357  self._rtc_rtc.d_control[controller_index].set_commandlaw("2matrices")
358 
359  def set_modal_integrator_law(self, controller_index: int) -> None:
360  """ Set the command law to 2matrices (controller generic only)
361  v[k] = v[k-1] + E.g.R.s[k]
362 
363  Args:
364  controller_index: (int): controller index
365  """
366  self._rtc_rtc.d_control[controller_index].set_commandlaw("modal_integrator")
367 
368  def set_decay_factor(self, controller_index: int, decay: np.ndarray) -> None:
369  """ Set the decay factor used in 2matrices command law (controller generic only)
370 
371  Args:
372  controller_index: (int): controller index
373 
374  decay : (np.ndarray) : decay factor vector
375  """
376  self._rtc_rtc.d_control[controller_index].set_decayFactor(decay)
377 
378  def set_E_matrix(self, controller_index: int, e_matrix: np.ndarray) -> None:
379  """ Set the E matrix used in 2matrices or modal command law (controller generic only)
380 
381  Args:
382  e_matrix : (np.ndarray) : E matrix to set
383 
384  controller_index: (int): controller index
385  """
386  self._rtc_rtc.d_control[controller_index].set_matE(e_matrix)
387 
388  def _get_x_buffer(self, controller_index: int) -> list:
389  """ Get the buffer of state vectors (controller generic linear only)
390 
391  Args:
392  controller_index: (int): controller index
393  """
394  return [np.array(x) for x in self._rtc_rtc.d_control[controller_index].d_circular_x]
395 
396  def _get_s_buffer(self, controller_index: int) -> list:
397  """ Get the buffer of slope vectors (controller generic linear only)
398 
399  Args:
400  controller_index: (int): controller index
401  """
402  return [np.array(x) for x in self._rtc_rtc.d_control[controller_index].d_circular_s]
403 
404  def _get_u_in_buffer(self, controller_index: int) -> list:
405  """ Get the buffer of iir input vectors (controller generic linear only)
406 
407  Args:
408  controller_index: (int): controller index
409  """
410  return [np.array(x) for x in self._rtc_rtc.d_control[controller_index].d_circular_u_in]
411 
412  def _get_u_out_buffer(self, controller_index: int) -> list:
413  """ Get the buffer of iir output vectors (controller generic linear only)
414 
415  Args:
416  controller_index: (int): controller index
417  """
418  return [np.array(x) for x in self._rtc_rtc.d_control[controller_index].d_circular_u_out]
419 
420  def _get_A_matrix(self, controller_index: int, matrix_index: int) -> np.ndarray:
421  """ Get a particular A matrix from the list of A matrices (controller generic linear only)
422 
423  Args:
424  controller_index: (int): controller index
425 
426  matrix_index: (int): matrix index
427  """
428  return np.array(self._rtc_rtc.d_control[controller_index].d_matA[matrix_index])
429 
430  def _get_L_matrix(self, controller_index: int, matrix_index: int) -> np.ndarray:
431  """ Get a particular L matrix from the list of L matrices (controller generic linear only)
432 
433  Args:
434  controller_index: (int): controller index
435 
436  matrix_index: (int): matrix index
437  """
438  return np.array(self._rtc_rtc.d_control[controller_index].d_matL[matrix_index])
439 
440  def _get_K_matrix(self, controller_index: int) -> np.ndarray:
441  """ Get the K matrix (controller generic linear only)
442 
443  Args:
444  controller_index: (int): controller index
445  """
446  return np.array(self._rtc_rtc.d_control[controller_index].d_matK)
447 
448  def _get_D_matrix(self, controller_index: int) -> np.ndarray:
449  """ Get the D matrix (controller generic linear only)
450 
451  Args:
452  controller_index: (int): controller index
453  """
454  return np.array(self._rtc_rtc.d_control[controller_index].d_matD)
455 
456  def _get_F_matrix(self, controller_index: int) -> np.ndarray:
457  """ Get the F matrix (controller generic linear only)
458 
459  Args:
460  controller_index: (int): controller index
461  """
462  return np.array(self._rtc_rtc.d_control[controller_index].d_matF)
463 
464  def _get_iir_a_vector(self, controller_index: int, vector_index: int) -> np.ndarray:
465  """ Get a particular iir "a" vector (outputs) (controller generic linear only)
466 
467  Args:
468  controller_index: (int): controller index
469 
470  vector_index: (int): vector index
471  """
472  return np.array(self._rtc_rtc.d_control[controller_index].d_iir_a[vector_index])
473 
474  def _get_iir_b_vector(self, controller_index: int, vector_index: int) -> np.ndarray:
475  """ Get a particular iir "b" vector (inputs) (controller generic linear only)
476 
477  Args:
478  controller_index: (int): controller index
479 
480  vector_index: (int): vector index
481  """
482  return np.array(self._rtc_rtc.d_control[controller_index].d_iir_b[vector_index])
483 
484  def set_A_matrix(self, controller_index: int, matrix_index: int,
485  a_matrix: np.ndarray) -> None:
486  """ Set a particular A matrix (controller generic linear only)
487 
488  Args:
489  controller_index: (int): controller index
490 
491  matrix_index : (int) : matrix index
492 
493  a_matrix : (np.ndarray) : A matrix to set
494  """
495  self._rtc_rtc.d_control[controller_index].set_matA(a_matrix, matrix_index)
496 
497  def set_L_matrix(self, controller_index: int, matrix_index: int,
498  l_matrix: np.ndarray) -> None:
499  """ Set a particular L matrix (controller generic linear only)
500 
501  Args:
502  controller_index: (int): controller index
503 
504  matrix_index : (int) : matrix index
505 
506  l_matrix : (np.ndarray) : L matrix to set
507  """
508  self._rtc_rtc.d_control[controller_index].set_matL(l_matrix, matrix_index)
509 
510  def set_K_matrix(self, controller_index: int, k_matrix: np.ndarray) -> None:
511  """ Set the K matrix (controller generic linear only)
512 
513  Args:
514  controller_index: (int): controller index
515 
516  k_matrix : (np.ndarray) : K matrix to set
517  """
518  self._rtc_rtc.d_control[controller_index].set_matK(k_matrix)
519 
520  def set_D_matrix(self, controller_index: int, d_matrix: np.ndarray) -> None:
521  """ Set the D matrix (controller generic linear only)
522 
523  Args:
524  controller_index: (int): controller index
525 
526  d_matrix : (np.ndarray) : D matrix to set
527  """
528  self._rtc_rtc.d_control[controller_index].set_matD(d_matrix)
529 
530  def set_F_matrix(self, controller_index: int, f_matrix: np.ndarray) -> None:
531  """ Set the K matrix (controller generic linear only)
532 
533  Args:
534  controller_index: (int): controller index
535 
536  f_matrix : (np.ndarray) : F matrix to set
537  """
538  self._rtc_rtc.d_control[controller_index].set_matF(f_matrix)
539 
540  def set_iir_a_vector(self, controller_index: int, vector_index: int,
541  iir_a_vector: np.ndarray) -> None:
542  """ Set a particular iir "a" vector (outputs) (controller generic linear only)
543 
544  Args:
545  controller_index: (int): controller index
546 
547  vector_index: (int): vector index
548 
549  iir_a_vector : (np.ndarray) : iir "a" vector to set
550  """
551  self._rtc_rtc.d_control[controller_index].set_iir_a(iir_a_vector, vector_index)
552 
553  def set_iir_b_vector(self, controller_index: int, vector_index: int,
554  iir_b_vector: np.ndarray) -> None:
555  """ Set a particular iir "b" vector (outputs) (controller generic linear only)
556 
557  Args:
558  controller_index: (int): controller index
559 
560  vector_index: (int): vector index
561 
562  iir_b_vector : (np.ndarray) : iir "b" vector to set
563  """
564  self._rtc_rtc.d_control[controller_index].set_iir_b(iir_b_vector, vector_index)
565 
566  def reset_ref_slopes(self, controller_index: int) -> None:
567  """ Reset the reference slopes of each WFS handled by the specified controller
568 
569  Args:
570  controller_index: (int): controller index
571  """
572  for centro in self._rtc_rtc.d_centro:
573  centro.d_centroids_ref.reset()
574 
575  def set_centroider_threshold(self, centro_index: int, thresh: float) -> None:
576  """ Set the threshold value of a thresholded COG
577 
578  Args:
579  centro_index: (int): centroider index
580 
581  thresh: (float): new threshold value
582  """
583  self._rtc_rtc.d_centro[centro_index].set_threshold(thresh)
584 
585  def get_pyr_method(self, centro_index: int) -> str:
586  """ Get pyramid compute method currently used
587 
588  Args:
589  centro_index: (int): centroider index
590 
591  Returns:
592  method : (str) : Pyramid compute method currently used
593  """
594  return self._rtc_rtc.d_centro[centro_index].pyr_method
595 
596  def set_pyr_method(self, centro_index: int, pyr_method: int) -> None:
597  """ Set the pyramid method for slopes computation
598 
599  Args:
600  centro_index : (int) : centroider index
601 
602  pyr_method : (int) : new centroiding method (0: nosinus global
603  1: sinus global
604  2: nosinus local
605  3: sinus local)
606  """
607  self._rtc_rtc.d_centro[centro_index].set_pyr_method(
608  pyr_method) # Sets the pyr method
609  self._rtc_rtc.do_centroids(0) # To be ready for the next get_slopess
610  print("PYR method set to " + self._rtc_rtc.d_centro[centro_index].pyr_method)
611 
612  def set_modal_gains(self, controller_index: int, mgain: np.ndarray) -> None:
613  """ Sets the modal gain (when using modal integrator command law)
614 
615  Args:
616  controller_index : (int) : Controller index to modify
617 
618  mgain : (np.ndarray) : Modal gains to set
619  """
620  self._rtc_rtc.d_control[controller_index].set_modal_gains(mgain)
621 
622  def get_modal_gains(self, controller_index: int) -> np.ndarray:
623  """ Returns the modal gains (when using modal integrator command law)
624 
625  Args:
626  controller_index : (int) : Controller index to modify
627 
628  Returns:
629  mgain : (np.ndarray) : Modal gains vector currently used
630  """
631  return np.array(self._rtc_rtc.d_control[controller_index].d_gain)
632 
633  def get_masked_pix(self, centro_index: int) -> np.ndarray:
634  """ Return the mask of valid pixels used by a maskedpix centroider
635 
636  Args:
637  centro_index : (int): Centroider index. Must be a maskedpix centroider
638 
639  Returns:
640  mask : (np.ndarray) : Mask used
641  """
642  if (self._rtc_rtc.d_centro[centro_index].type != scons.CentroiderType.MASKEDPIX):
643  raise TypeError("Centroider must be a maskedpix one")
644  self._rtc_rtc.d_centro[centro_index].fill_mask()
645  return np.array(self._rtc_rtc.d_centro[centro_index].d_mask)
646 
647  def get_command(self, controller_index: int) -> np.ndarray:
648  """ Returns the last computed command before conversion to voltages
649 
650  Args:
651  controller_index : (int) : Controller index
652 
653  Returns:
654  com : (np.ndarray) : Command vector
655  """
656  return np.array(self._rtc_rtc.d_control[controller_index].d_com)
657 
658  def set_command(self, controller_index: int, com: np.ndarray) -> np.ndarray:
659  """ Returns the last computed command before conversion to voltages
660 
661  Args:
662  controller_index : (int) : Controller index
663 
664  com : (np.ndarray) : Command vector to set
665  """
666  if (com.size != self._config_config.p_controllers[controller_index].nactu):
667  raise ValueError("Dimension mismatch")
668  self._rtc_rtc.d_control[controller_index].set_com(com, com.size)
669 
670  def reset_command(self, controller_index: int = None) -> None:
671  """ Reset the controller_index Controller command buffer, reset all controllers if controller_index is None
672 
673  Kwargs:
674  controller_index : (int) : Controller index
675  Default is None, i.e. all controllers are reset
676  """
677  if (controller_index is None): # All Dms reset
678  for control in self._rtc_rtc.d_control:
679  control.d_com.reset()
680  else:
681  self._rtc_rtc.d_control[controller_index].d_com.reset()
682 
683  def get_slopes_geom(self, controller_index: int, geom_type: int = 0) -> np.ndarray:
684  """ Computes and return the slopes geom from the specified controller
685 
686  Args:
687  controller_index : (int) : controller index
688 
689  geom_type : (int) : geom centroiding method, default = 0, others (1,2) are experimental
690  Returns:
691  slopes_geom : (np.ndarray) : geometrically computed slopes
692  """
693  self.do_centroids_geomdo_centroids_geom(controller_index, geom_type=geom_type)
694  slopes_geom = np.array(self._rtc_rtc.d_control[controller_index].d_centroids)
695  self._rtc_rtc.do_centroids(controller_index) # To return in non-geo state
696  return slopes_geom
697 
698  def get_selected_pix(self) -> np.ndarray:
699  """ Return the pyramid image with only the selected pixels used by the full pixels centroider
700 
701  Returns:
702  selected_pix : (np.ndarray) : PWFS image with only selected pixels
703  """
704  if (self._config_config.p_centroiders[0].type != scons.CentroiderType.MASKEDPIX):
705  raise TypeError("Centroider must be maskedPix")
706 
707  carma_centroids = self._rtc_rtc.d_control[0].d_centroids
708  self._rtc_rtc.d_centro[0].fill_selected_pix(carma_centroids)
709 
710  return np.array(self._rtc_rtc.d_centro[0].d_selected_pix)
711 
712  def do_ref_slopes(self, controller_index: int) -> None:
713  """ Computes and set a new reference slopes for each WFS handled by
714  the specified controller
715 
716  Args:
717  controller_index: (int): controller index
718  """
719  print("Doing reference slopes...")
720  self._rtc_rtc.do_centroids_ref(controller_index)
721  print("Reference slopes done")
722 
723  def do_control(self, controller_index: int, *, sources: SourceCompass = None,
724  source_index: int = 0, is_wfs_phase: bool = False) -> None:
725  """Computes the command from the Wfs slopes
726 
727  Args:
728  controller_index: (int): controller index
729 
730  Kwargs:
731  sources : (SourceCompass) : List of phase screens of a wfs or target sutra object
732  If the controller is a GEO one, specify a SourceCompass instance
733  from WfsCompass or TargetCompass to project the corresponding phase
734 
735  source_index : (int) : Index of the phase screen to consider inside <sources>. Default is 0
736 
737  is_wfs_phase : (bool) : If True, sources[source_index] is a WFS phase screen.
738  Else, it is a Target phase screen (Default)
739  """
740  if (self._rtc_rtc.d_control[controller_index].type == scons.ControllerType.GEO):
741  if (sources is not None):
742  self._rtc_rtc.d_control[controller_index].comp_dphi(
743  sources[source_index], is_wfs_phase)
744  self._rtc_rtc.do_control(controller_index)
745 
746  def do_calibrate_img(self, controller_index: int) -> None:
747  """ Computes the calibrated image from the Wfs image
748 
749  Args:
750  controller_index: (int): controller index
751  """
752  self._rtc_rtc.do_calibrate_img(controller_index)
753 
754  def do_centroids(self, controller_index: int) -> None:
755  """ Computes the centroids from the Wfs image
756 
757  Args:
758  controller_index: (int): controller index
759  """
760  self._rtc_rtc.do_centroids(controller_index)
761 
762  def do_centroids_geom(self, controller_index: int, *, geom_type: int = 0) -> None:
763  """ Computes the centroids geom from the Wfs image
764 
765  Args:
766  controller_index: (int): controller index
767 
768  geom_type : (int) : geom centroiding method, default = 0, others (1,2) are experimental
769  """
770  self._rtc_rtc.do_centroids_geom(controller_index, geom_type)
771 
772  def apply_control(self, controller_index: int, *, comp_voltage: bool = True) -> None:
773  """ Computes the final voltage vector to apply on the DM by taking into account delay and perturbation voltages, and shape the DMs
774 
775  Args:
776  controller_index: (int): controller index
777 
778  Kwargs:
779  comp_voltage: (bool): If True (default), computes the voltage vector from the command one (delay + perturb). Else, directly applies the current voltage vector
780  """
781  self._rtc_rtc.apply_control(controller_index, comp_voltage)
782 
783  def do_clipping(self, controller_index: int) -> None:
784  """ Clip the commands between vmin and vmax values set in the RTC
785 
786  Args:
787  controller_index: (int): controller index
788  """
789  self._rtc_rtc.do_clipping(controller_index)
790 
791  def set_scale(self, centroider_index: int, scale: float) -> None:
792  """ Update the scale factor of the centroider
793 
794  Args:
795  centroider_index : (int) : Index of the centroider to update
796 
797  scale : (float) : scale factor to apply on slopes
798  """
799  self._rtc_rtc.d_centro[centroider_index].set_scale(scale)
800 
801  def publish(self) -> None:
802  """ Publish loop data on DDS topics
803 
804  only with cacao enabled, requires OCTOPUS
805  """
806  if self.cacaocacao:
807  self._rtc_rtc.publish()
808  else:
809  raise AttributeError("CACAO must be enabled")
810 
811  def get_image_raw(self, centroider_index: int) -> np.ndarray:
812  """ Return the raw image currently loaded on the specified centroider
813 
814  Args:
815  centroider_index : (int) : Index of the centroider
816 
817  Returns:
818  image_raw : (np.ndarray) : Raw WFS image loaded in the centroider
819  """
820  return np.array(self._rtc_rtc.d_centro[centroider_index].d_img_raw)
821 
822  def get_image_calibrated(self, centroider_index: int) -> np.ndarray:
823  """ Return the last image calibrated by the specified centroider
824 
825  Args:
826  centroider_index : (int) : Index of the centroider
827 
828  Returns:
829  image_cal : (np.ndarray) : Calibrated WFS image loaded in the centroider
830  """
831  img = np.array(self._rtc_rtc.d_centro[centroider_index].d_img)
832  if self._config_config.p_centroiders[
833  centroider_index].type == scons.CentroiderType.MASKEDPIX: # Full pixel case
834  img *= self.get_masked_pixget_masked_pix(centroider_index)
835  return img
None set_command_matrix(self, int controller_index, np.ndarray cmat)
Set the command matrix for the controller to use.
Definition: rtcAbstract.py:248
brahma
(bool) : BRAHMA features enabled in the RTC
Definition: rtcAbstract.py:101
np.ndarray get_err(self, int controller_index)
Get integrator increment from controller_index controller.
Definition: rtcAbstract.py:343
None do_ref_slopes(self, int controller_index)
Computes and set a new reference slopes for each WFS handled by the specified controller.
Definition: rtcAbstract.py:763
None set_E_matrix(self, int controller_index, np.ndarray e_matrix)
Set the E matrix used in 2matrices or modal command law (controller generic only)
Definition: rtcAbstract.py:408
None set_D_matrix(self, int controller_index, np.ndarray d_matrix)
Set the D matrix (controller generic linear only)
Definition: rtcAbstract.py:572
None do_clipping(self, int controller_index)
Clip the commands between vmin and vmax values set in the RTC.
Definition: rtcAbstract.py:833
None do_centroids_geom(self, int controller_index, *int geom_type=0)
Computes the centroids geom from the Wfs image.
Definition: rtcAbstract.py:814
def set_dark(self, int centro_index, np.ndarray dark)
Load dark for the given wfs.
Definition: rtcAbstract.py:277
None set_integrator_law(self, int controller_index)
Set the command law to integrator (controller generic only)
Definition: rtcAbstract.py:366
None remove_perturbation_voltage(self, int controller_index, str name)
Remove the perturbation voltage called <name>, from the controller number <controller_index>.
Definition: rtcAbstract.py:310
def set_flat(self, int centro_index, np.ndarray flat)
Load flat field for the given wfs.
Definition: rtcAbstract.py:267
None reset_ref_slopes(self, int controller_index)
Reset the reference slopes of each WFS handled by the specified controller.
Definition: rtcAbstract.py:616
None set_2matrices_law(self, int controller_index)
Set the command law to 2matrices (controller generic only)
Definition: rtcAbstract.py:377
np.ndarray get_voltages(self, int controller_index)
Get voltages vector (i.e.
Definition: rtcAbstract.py:355
def get_interaction_matrix(self, int controller_index)
Return the interaction matrix of the controller.
Definition: rtcAbstract.py:227
None close_loop(self, int controller_index=None)
DM receives controller output + pertuVoltage.
Definition: rtcAbstract.py:149
None publish(self)
Publish loop data on DDS topics.
Definition: rtcAbstract.py:850
None set_ref_slopes(self, np.ndarray ref_slopes, *int centro_index=None)
Set given ref slopes in centroider.
Definition: rtcAbstract.py:183
None do_control(self, int controller_index, *SourceCompass sources=None, int source_index=0, bool is_wfs_phase=False)
Computes the command from the Wfs slopes.
Definition: rtcAbstract.py:784
None set_gain(self, int controller_index, float gain)
Set the scalar gain.
Definition: rtcAbstract.py:216
def compute_slopes(self, int controller_index)
Compute the slopes handled by a controller, and returns it.
Definition: rtcAbstract.py:288
cacao
(bool) : CACAO features enabled in the RTC
Definition: rtcAbstract.py:103
None do_calibrate_img(self, int controller_index)
Computes the calibrated image from the Wfs image.
Definition: rtcAbstract.py:796
None set_F_matrix(self, int controller_index, np.ndarray f_matrix)
Set the K matrix (controller generic linear only)
Definition: rtcAbstract.py:582
None set_iir_b_vector(self, int controller_index, int vector_index, np.ndarray iir_b_vector)
Set a particular iir "b" vector (outputs) (controller generic linear only)
Definition: rtcAbstract.py:608
np.ndarray get_slopes_geom(self, int controller_index, int geom_type=0)
Computes and return the slopes geom from the specified controller.
Definition: rtcAbstract.py:737
str get_pyr_method(self, int centro_index)
Get pyramid compute method currently used.
Definition: rtcAbstract.py:638
None set_centroider_threshold(self, int centro_index, float thresh)
Set the threshold value of a thresholded COG.
Definition: rtcAbstract.py:627
None open_loop(self, int controller_index=None, reset=True)
Integrator computation goes to /dev/null but pertuVoltage still applied.
Definition: rtcAbstract.py:164
None set_iir_a_vector(self, int controller_index, int vector_index, np.ndarray iir_a_vector)
Set a particular iir "a" vector (outputs) (controller generic linear only)
Definition: rtcAbstract.py:595
np.ndarray get_modal_gains(self, int controller_index)
Returns the modal gains (when using modal integrator command law)
Definition: rtcAbstract.py:675
np.ndarray get_ref_slopes(self, centro_index=None)
Get the currently used reference slopes.
Definition: rtcAbstract.py:200
np.ndarray get_image_raw(self, int centroider_index)
Return the raw image currently loaded on the specified centroider.
Definition: rtcAbstract.py:864
np.ndarray get_image_calibrated(self, int centroider_index)
Return the last image calibrated by the specified centroider.
Definition: rtcAbstract.py:875
np.ndarray get_masked_pix(self, int centro_index)
Return the mask of valid pixels used by a maskedpix centroider.
Definition: rtcAbstract.py:686
None set_modal_integrator_law(self, int controller_index)
Set the command law to 2matrices (controller generic only)
Definition: rtcAbstract.py:388
np.ndarray get_intensities(self)
Return sum of intensities in subaps.
Definition: rtcAbstract.py:253
None set_modal_gains(self, int controller_index, np.ndarray mgain)
Sets the modal gain (when using modal integrator command law)
Definition: rtcAbstract.py:664
Union[dict, tuple] get_perturbation_voltage(self, int controller_index, *str name=None)
Get a perturbation voltage buffer.
Definition: rtcAbstract.py:326
np.ndarray get_slopes(self, int controller_index)
Return the current slopes vector of the controller_index controller.
Definition: rtcAbstract.py:140
np.ndarray set_command(self, int controller_index, np.ndarray com)
Returns the last computed command before conversion to voltages.
Definition: rtcAbstract.py:710
None set_L_matrix(self, int controller_index, int matrix_index, np.ndarray l_matrix)
Set a particular L matrix (controller generic linear only)
Definition: rtcAbstract.py:552
None set_pyr_method(self, int centro_index, int pyr_method)
Set the pyramid method for slopes computation.
Definition: rtcAbstract.py:651
None do_centroids(self, int controller_index)
Computes the centroids from the Wfs image.
Definition: rtcAbstract.py:804
np.ndarray get_command(self, int controller_index)
Returns the last computed command before conversion to voltages.
Definition: rtcAbstract.py:700
np.ndarray get_selected_pix(self)
Return the pyramid image with only the selected pixels used by the full pixels centroider.
Definition: rtcAbstract.py:748
None set_K_matrix(self, int controller_index, np.ndarray k_matrix)
Set the K matrix (controller generic linear only)
Definition: rtcAbstract.py:562
None apply_control(self, int controller_index, *bool comp_voltage=True)
Computes the final voltage vector to apply on the DM by taking into account delay and perturbation vo...
Definition: rtcAbstract.py:825
def get_command_matrix(self, int controller_index)
Return the command matrix of the controller.
Definition: rtcAbstract.py:238
None reset_command(self, int controller_index=None)
Reset the controller_index Controller command buffer, reset all controllers if controller_index is No...
Definition: rtcAbstract.py:721
None reset_perturbation_voltage(self, int controller_index)
Reset the perturbation voltage of the controller_index controller (i.e.
Definition: rtcAbstract.py:299
None set_perturbation_voltage(self, int controller_index, str name, np.ndarray command)
Add circular buffer of offset values to integrator (will be applied at the end of next iteration)
Definition: rtcAbstract.py:122
None set_scale(self, int centroider_index, float scale)
Update the scale factor of the centroider.
Definition: rtcAbstract.py:843
None set_A_matrix(self, int controller_index, int matrix_index, np.ndarray a_matrix)
Set a particular A matrix (controller generic linear only)
Definition: rtcAbstract.py:539
None set_decay_factor(self, int controller_index, np.ndarray decay)
Set the decay factor used in 2matrices command law (controller generic only)
Definition: rtcAbstract.py:398
fp16
(bool) : FP16 features enabled in the RTC
Definition: rtcAbstract.py:102
def __init__(self, carmaWrap_context context, config, *bool brahma=False, bool fp16=False, bool cacao=False)
Initialize a RtcCompass component for rtc related supervision.
Definition: rtcAbstract.py:100
Numerical constants for shesha and config enumerations for safe-typing.
Definition: constants.py:1
int fill_mask(float *d_odata, float *d_idata, int N, int norm, CarmaDevice *device)