38 from rich.progress
import track
41 """ This optimizer class handles all the modal basis and DM Influence functions
45 _config : (config) : Configuration parameters module
47 _tel : (TelescopeCompass) : TelescopeCompass instance
49 _atmos : (AtmosScompass) : AtmosCompass instance
51 _dms : (DmCompass) : DmCompass instance
53 _target : (TargetCompass) : TargetCompass instance
55 _rtc : (RtcCompass) : RtcCompass instance
57 _wfs : (WfsCompass) : WfsCompass instance
59 def __init__(self, config, tel, atmos, dms, target, rtc, wfs):
60 """ Instantiate a ModalBasis object
63 config : (config) : Configuration parameters module
65 tel : (TelescopeCompass) : TelescopeCompass instance
67 atmos : (AtmosScompass) : AtmosCompass instance
69 dms : (DmCompass) : DmCompass instance
71 target : (TargetCompass) : TargetCompass instance
73 rtc : (RtcCompass) : RtcCompass instance
75 wfs : (WfsCompass) : WfsCompass instance
86 turbu: bool =
False, reset: bool =
True):
87 """ Apply voltages, raytrace, compute WFS image, compute slopes and returns it
90 controller_index : (int) : Controller index
93 noise : (bool) : Flag to enable noise for WFS image computation. Default is False
95 turbu : (bool) : Flag to enable atmosphere for WFS phase screen raytracing.
98 reset : (bool) : Flag to reset previous phase screen before raytracing.
101 self.
_rtc_rtc.apply_control(controller_index)
102 for w
in range(len(self.
_config_config.p_wfss)):
104 self.
_wfs_wfs.raytrace(w, tel=self.
_tel_tel, atm=self.
_atmos_atmos, dms=self.
_dms_dms)
106 self.
_wfs_wfs.raytrace(w, dms=self.
_dms_dms, reset=reset)
107 self.
_wfs_wfs.compute_wfs_image(w, noise=noise)
108 return self.
_rtc_rtc.compute_slopes(controller_index)
110 def do_imat_modal(self, controller_index : int, ampli : np.ndarray, modal_basis : np.ndarray,
111 *, noise : bool=
False, nmodes_max : int=0, with_turbu : bool=
False, push_pull : bool=
False) -> np.ndarray:
112 """ Computes an interaction matrix from provided modal basis
115 controller_index : (int) : Controller index
117 ampli : (np.ndarray) : amplitude to apply on each mode
119 modal_basis : (np.ndarray) : modal basis matrix
122 noise : (bool) : Flag to enable noise for WFS image compuation. Default is False
124 nmodes_max : (int) : Default is 0. TODO : description
126 with_turbu : (bool) : Flag to enable atmosphere for WFS phase screen raytracing.
129 push_pull : (bool) : If True, imat is computed as an average of push and pull ampli
133 modal_imat : (np.ndarray) : Modal interaction matrix
135 modal_imat = np.zeros((self.
_config_config.p_controllers[controller_index].nslope, modal_basis.shape[1]))
136 print(
"Starting Modal imat...")
137 if (nmodes_max == 0):
138 nmodes_max = modal_basis.shape[1]
139 v_old = self.
_rtc_rtc.get_command(controller_index)
140 self.
_rtc_rtc.open_loop(controller_index, reset=
False)
141 for m
in track(range(nmodes_max)):
142 v = ampli[m] * modal_basis[:, m]
143 if ((push_pull
is True)
or
144 (with_turbu
is True)):
145 self.
_rtc_rtc.set_perturbation_voltage(
146 controller_index,
"imat_modal",
149 turbu=with_turbu, noise=noise)
150 self.
_rtc_rtc.set_perturbation_voltage(controller_index,
"imat_modal", v_old - v)
152 turbu=with_turbu, noise=noise)
153 modal_imat[:, m] = (devpos - devmin) / (2. * ampli[m])
155 self.
_rtc_rtc.open_loop(controller_index)
156 self.
_rtc_rtc.set_perturbation_voltage(controller_index,
"imat_modal", v)
158 self.
_rtc_rtc.remove_perturbation_voltage(controller_index,
"imat_modal")
159 if ((push_pull
is True)
or (with_turbu
is True)):
160 self.
_rtc_rtc.close_loop(controller_index)
163 def do_imat_phase(self, controller_index: int, cube_phase: np.ndarray, *, noise : bool=
False,
164 nmodes_max : int=0, with_turbu : bool=
False, push_pull : bool=
False, wfs_index : int=0) -> np.ndarray:
165 """ Computes an interaction matrix with the provided cube phase
168 controller_index : (int) : Controller index
170 cube_phase : (np.ndarray) : Cube of phase to insert as NCPA
173 noise : (bool) : Flag to enable noise for WFS image compuation. Default is False
175 nmodes_max : (int) : Default is 0. TODO : description
177 with_turbu : (bool) : Flag to enable atmosphere for WFS phase screen raytracing.
180 push_pull : (bool) : If True, imat is computed as an average of push and pull ampli
183 wfs_index : (int) : WFS index. Default is 0
186 phase_imat : (np.ndarray) : Phase interaction matrix
188 imat_phase = np.zeros((cube_phase.shape[0], self.
_config_config.p_controllers[controller_index].nslope))
189 for nphase
in range(cube_phase.shape[0]):
190 if ((push_pull
is True)
or (with_turbu
is True)
192 self.
_wfs_wfs.set_ncpa_wfs(wfs_index, cube_phase[nphase, :, :])
194 turbu=with_turbu, noise=noise)
195 self.
_wfs_wfs.set_ncpa_wfs(wfs_index, -cube_phase[nphase, :, :])
197 turbu=with_turbu, noise=noise)
198 imat_phase[nphase, :] = (devpos - devmin) / 2
200 self.
_rtc_rtc.open_loop(controller_index)
201 self.
_wfs_wfs.set_ncpa_wfs(wfs_index, cube_phase[nphase, :, :])
203 controller_index, noise=noise)
204 self.
_wfs_wfs.set_ncpa_wfs(wfs_index,
205 cube_phase[nphase, :, :] * 0.)
212 *, selected_actus : np.ndarray=
None) -> np.ndarray:
213 """ Computes the modal residual coefficients of the residual phase.
215 It supposed that roket is enabled, and the associated GEO controller is index 1.
217 Uses the projection matrix computed from compute_modes_to_volts_basis (modalBasis module)
220 projection_matrix : (np.ndarray) : Modal projection matrix
223 selected_actus : (np.ndarray) : TODO : description
226 ai : (np.ndarray) : Modal coefficients
229 self.
_rtc_rtc.do_control(1, sources=self.
_target_target.sources)
232 v = self.
_rtc_rtc.get_command(1)
233 if (selected_actus
is None):
234 ai = projection_matrix.dot(v) * 1000.
239 ai = projection_matrix.dot(np.concatenate((v2, v3))) * 1000.
This optimizer class handles all the modal basis and DM Influence functions related operations.
np.ndarray compute_modal_residuals(self, np.ndarray projection_matrix, *np.ndarray selected_actus=None)
Computes the modal residual coefficients of the residual phase.
def __init__(self, config, tel, atmos, dms, target, rtc, wfs)
np.ndarray do_imat_phase(self, int controller_index, np.ndarray cube_phase, *bool noise=False, int nmodes_max=0, bool with_turbu=False, bool push_pull=False, int wfs_index=0)
Computes an interaction matrix with the provided cube phase.
def apply_volts_and_get_slopes(self, int controller_index, *bool noise=False, bool turbu=False, bool reset=True)
Apply voltages, raytrace, compute WFS image, compute slopes and returns it.
np.ndarray do_imat_modal(self, int controller_index, np.ndarray ampli, np.ndarray modal_basis, *bool noise=False, int nmodes_max=0, bool with_turbu=False, bool push_pull=False)
Computes an interaction matrix from provided modal basis.