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