COMPASS  5.4.4
End-to-end AO simulation tool using GPU acceleration
dmCompass.py
1 
37 from shesha.init.dm_init import dm_init
38 import numpy as np
39 from typing import Tuple
40 
41 class DmCompass(object):
42  """ DM handler for compass simulation
43 
44  Attributes:
45  _dms : (sutraWrap.Dms) : Sutra dms instance
46 
47  _context : (carmaContext) : CarmaContext instance
48 
49  _config : (config module) : Parameters configuration structure module
50  """
51  def __init__(self, context, config):
52  """ Initialize a DmCompass component for DM related supervision
53 
54  Args:
55  context : (carmaContext) : CarmaContext instance
56 
57  config : (config module) : Parameters configuration structure module
58  """
59  self._context_context = context
60  self._config_config = config # Parameters configuration coming from supervisor init
61  print("->dms init")
62  self._dms_dms = dm_init(self._context_context, self._config_config.p_dms, self._config_config.p_tel,
63  self._config_config.p_geom, self._config_config.p_wfss)
64 
65  def set_command(self, commands: np.ndarray, *, dm_index : int=None, shape_dm : bool=True) -> None:
66  """ Immediately sets provided command to DMs - does not affect integrator
67 
68  Args:
69  commands : (np.ndarray) : commands vector to apply
70 
71  Kwargs:
72  dm_index : (int) : Index of the DM to set. If None (default), set all the DMs.
73  In that case, provided commands vector must have a size equal
74  to the sum of all the DMs actuators.
75  If index_dm is set, size must be equal to the number of actuator
76  of the specified DM.
77 
78  shape_dm : (bool) : If True (default), immediately apply the given commands on the DMs
79  """
80  if dm_index is None:
81  self._dms_dms.set_full_com(commands, shape_dm)
82  else:
83  self._dms_dms.d_dms[dm_index].set_com(commands, shape_dm)
84 
85  def set_one_actu(self, dm_index: int, nactu: int, *, ampli: float = 1) -> None:
86  """ Push the selected actuator
87 
88  Args:
89  dm_index : (int) : DM index
90 
91  nactu : (int) : actuator index to push
92 
93  Kwargs:
94  ampli : (float) : amplitude to apply. Default is 1 volt
95  """
96  self._dms_dms.d_dms[dm_index].comp_oneactu(nactu, ampli)
97 
98  def get_influ_function(self, dm_index : int) -> np.ndarray:
99  """ Returns the influence function cube for the given dm
100 
101  Args:
102  dm_index : (int) : index of the DM
103 
104  Returns:
105  influ : (np.ndarray) : Influence functions of the DM dm_index
106  """
107  return self._config_config.p_dms[dm_index]._influ
108 
109  def get_influ_function_ipupil_coords(self, dm_index : int) -> Tuple[np.ndarray, np.ndarray]:
110  """ Returns the lower left coordinates of the influ function support in the ipupil coord system
111 
112  Args:
113  dm_index : (int) : index of the DM
114 
115  Returns:
116  coords : (tuple) : (i, j)
117  """
118  i1 = self._config_config.p_dms[dm_index]._i1 # i1 is in the dmshape support coords
119  j1 = self._config_config.p_dms[dm_index]._j1 # j1 is in the dmshape support coords
120  ii1 = i1 + self._config_config.p_dms[dm_index]._n1 # in ipupil coords
121  jj1 = j1 + self._config_config.p_dms[dm_index]._n1 # in ipupil coords
122  return ii1, jj1
123 
124  def reset_dm(self, dm_index: int = -1) -> None:
125  """ Reset the specified DM or all DMs if dm_index is -1
126 
127  Kwargs:
128  dm_index : (int) : Index of the DM to reset
129  Default is -1, i.e. all DMs are reset
130  """
131  if (dm_index == -1): # All Dms reset
132  for dm in self._dms_dms.d_dms:
133  dm.reset_shape()
134  else:
135  self._dms_dms.d_dms[dm_index].reset_shape()
136 
137  def get_dm_shape(self, indx : int) -> np.ndarray:
138  """ Return the current phase shape of the selected DM
139 
140  Args:
141  indx : (int) : Index of the DM
142 
143  Returns:
144  dm_shape : (np.ndarray) : DM phase screen
145 
146  """
147  return np.array(self._dms_dms.d_dms[indx].d_shape)
148 
149  def set_dm_registration(self, dm_index : int, *, dx : float=None, dy : float=None,
150  theta : float=None, G : float=None) -> None:
151  """Set the registration parameters for DM #dm_index
152 
153  Args:
154  dm_index : (int) : DM index
155 
156  Kwargs:
157  dx : (float) : X axis registration parameter [meters]. If None, re-use the last one
158 
159  dy : (float) : Y axis registration parameter [meters]. If None, re-use the last one
160 
161  theta : (float) : Rotation angle parameter [rad]. If None, re-use the last one
162 
163  G : (float) : Magnification factor. If None, re-use the last one
164  """
165  if dx is not None:
166  self._config_config.p_dms[dm_index].set_dx(dx)
167  if dy is not None:
168  self._config_config.p_dms[dm_index].set_dy(dy)
169  if theta is not None:
170  self._config_config.p_dms[dm_index].set_theta(theta)
171  if G is not None:
172  self._config_config.p_dms[dm_index].set_G(G)
173 
174  self._dms_dms.d_dms[dm_index].set_registration(
175  self._config_config.p_dms[dm_index].dx / self._config_config.p_geom._pixsize,
176  self._config_config.p_dms[dm_index].dy / self._config_config.p_geom._pixsize,
177  self._config_config.p_dms[dm_index].theta, self._config_config.p_dms[dm_index].G)
DM handler for compass simulation.
Definition: dmCompass.py:45
None reset_dm(self, int dm_index=-1)
Reset the specified DM or all DMs if dm_index is -1.
Definition: dmCompass.py:138
None set_dm_registration(self, int dm_index, *float dx=None, float dy=None, float theta=None, float G=None)
Set the registration parameters for DM #dm_index.
Definition: dmCompass.py:172
None set_one_actu(self, int dm_index, int nactu, *float ampli=1)
Push the selected actuator.
Definition: dmCompass.py:103
np.ndarray get_influ_function(self, int dm_index)
Returns the influence function cube for the given dm.
Definition: dmCompass.py:114
Tuple[np.ndarray, np.ndarray] get_influ_function_ipupil_coords(self, int dm_index)
Returns the lower left coordinates of the influ function support in the ipupil coord system.
Definition: dmCompass.py:125
None set_command(self, np.ndarray commands, *int dm_index=None, bool shape_dm=True)
Immediately sets provided command to DMs - does not affect integrator.
Definition: dmCompass.py:87
np.ndarray get_dm_shape(self, int indx)
Return the current phase shape of the selected DM.
Definition: dmCompass.py:154
Initialization of a Dms object.
Definition: dm_init.py:1