COMPASS  5.0.0
End-to-end AO simulation tool using GPU acceleration
test_rtcFFF Namespace Reference

Functions

def relative_array_error (array1, array2)
 
def test_initCentro_nvalid ()
 
def test_initCentro_offset ()
 
def test_initCentro_scale ()
 
def test_initCentro_type ()
 
def test_initControl_nslope ()
 
def test_initControl_nactu ()
 
def test_initControl_type ()
 
def test_initControl_delay ()
 
def test_set_npix ()
 
def test_load_validposX ()
 
def test_load_validposY ()
 
def test_set_cmat ()
 
def test_set_gain ()
 
def test_load_img ()
 
def test_set_dark ()
 
def test_set_flat ()
 
def test_calibrate_img ()
 
def test_doCentroids_cog ()
 
def test_do_control_generic ()
 
def test_set_comRange ()
 
def test_clipping ()
 
def test_add_perturb_voltage ()
 
def test_remove_perturb_voltage ()
 
def test_add_perturb ()
 
def test_disable_perturb_voltage ()
 
def test_enable_perturb_voltage ()
 
def test_reset_perturb_voltage ()
 
def test_comp_voltage ()
 
def test_remove_centroider ()
 
def test_doCentroids_tcog ()
 
def test_doCentroids_bpcog ()
 

Variables

int precision = 1e-2
 
 config
 
 sup = Supervisor(config)
 
 rtc = Rtc()
 
 idx_centro
 
 ncentro
 
 centro = rtc.d_centro[0]
 
 control = rtc.d_control[0]
 
 xvalid = np.array(sup.rtc.rtc.d_centro[0].d_validx)
 
 yvalid = np.array(sup.rtc.rtc.d_centro[0].d_validy)
 
 cmat = sup.rtc.get_command_matrix(0)
 
 frame = sup.wfs.get_wfs_image(0)
 
 slp = ng.array(rtc.d_control[0].d_centroids)
 
 com = ng.array(rtc.d_control[0].d_com)
 
 dark = np.random.random(frame.shape)
 
 flat = np.random.random(frame.shape)
 

Function Documentation

◆ relative_array_error()

def test_rtcFFF.relative_array_error (   array1,
  array2 
)

Definition at line 51 of file test_rtcFFF.py.

51 def relative_array_error(array1, array2):
52  return np.abs((array1 - array2) / array2.max()).max()
53 
54 
Here is the caller graph for this function:

◆ test_add_perturb()

def test_rtcFFF.test_add_perturb ( )

Definition at line 174 of file test_rtcFFF.py.

174 def test_add_perturb():
175  C = np.random.random(sup.config.p_controller0.nactu)
176  control.add_perturb_voltage("test", C, 1)
177  com = ng.array(control.d_com_clipped).toarray()
178  control.add_perturb()
179  assert (relative_array_error(ng.array(control.d_com_clipped).toarray(), com + C) <
180  precision)
181 
182 
Here is the call graph for this function:

◆ test_add_perturb_voltage()

def test_rtcFFF.test_add_perturb_voltage ( )

Definition at line 162 of file test_rtcFFF.py.

162 def test_add_perturb_voltage():
163  C = np.random.random(sup.config.p_controller0.nactu)
164  control.add_perturb_voltage("test", C, 1)
165  assert (relative_array_error(
166  ng.array(control.d_perturb_map["test"][0]).toarray(), C) < precision)
167 
168 
Here is the call graph for this function:

◆ test_calibrate_img()

def test_rtcFFF.test_calibrate_img ( )

Definition at line 119 of file test_rtcFFF.py.

119 def test_calibrate_img():
120  centro.calibrate_img()
121  imgCal = (frame - dark) * flat
122  assert (relative_array_error(np.array(centro.d_img), imgCal) < precision)
123 
124 
Here is the call graph for this function:

◆ test_clipping()

def test_rtcFFF.test_clipping ( )

Definition at line 150 of file test_rtcFFF.py.

150 def test_clipping():
151  control.set_comRange(-1, 1)
152  C = (np.random.random(sup.config.p_controller0.nactu) - 0.5) * 4
153  control.set_com(C, C.size)
154  rtc.do_clipping(0)
155  C_clipped = C.copy()
156  C_clipped[np.where(C > 1)] = 1
157  C_clipped[np.where(C < -1)] = -1
158  assert (relative_array_error(ng.array(control.d_com_clipped).toarray(), C_clipped) <
159  precision)
160 
161 
Here is the call graph for this function:

◆ test_comp_voltage()

def test_rtcFFF.test_comp_voltage ( )

Definition at line 204 of file test_rtcFFF.py.

204 def test_comp_voltage():
205  volt_min = -1
206  volt_max = 1
207  control.set_comRange(volt_min, volt_max)
208  control.comp_voltage()
209  C = np.random.random(sup.config.p_controller0.nactu)
210  control.add_perturb_voltage("test", C, 1)
211  control.set_com(C, C.size)
212  com0 = ng.array(control.d_circularComs0).toarray()
213  com1 = ng.array(control.d_circularComs1).toarray()
214  control.comp_voltage()
215  delay = sup.config.p_controller0.delay
216  a = delay - int(delay)
217  b = 1 - a
218  commands = a * com0 + b * com1
219  comPertu = commands + C
220  comPertu[np.where(comPertu > volt_max)] = volt_max
221  comPertu[np.where(comPertu < volt_min)] = volt_min
222  assert (relative_array_error(ng.array(control.d_voltage).toarray(), comPertu) <
223  precision)
224 
225 
Here is the call graph for this function:

◆ test_disable_perturb_voltage()

def test_rtcFFF.test_disable_perturb_voltage ( )

Definition at line 183 of file test_rtcFFF.py.

183 def test_disable_perturb_voltage():
184  control.disable_perturb_voltage("test")
185  com = np.array(control.d_com)
186  control.add_perturb()
187  assert (relative_array_error(np.array(control.d_com), com) < precision)
188 
189 
Here is the call graph for this function:

◆ test_do_control_generic()

def test_rtcFFF.test_do_control_generic ( )

Definition at line 137 of file test_rtcFFF.py.

137 def test_do_control_generic():
138  slopes = np.array(control.d_centroids)
139  gain = control.gain
140  cmat = np.array(control.d_cmat)
141  commands = cmat.dot(slopes) * gain * (-1)
142  assert (relative_array_error(np.array(control.d_com), commands) < precision)
143 
144 
Here is the call graph for this function:

◆ test_doCentroids_bpcog()

def test_rtcFFF.test_doCentroids_bpcog ( )

Definition at line 258 of file test_rtcFFF.py.

258 def test_doCentroids_bpcog():
259  rtc.remove_centroider(0)
260  rtc.add_centroider(sup.context, sup.config.p_wfs0._nvalid,
261  sup.config.p_wfs0.npix / 2 - 0.5, sup.config.p_wfs0.pixsize,
262  False, 0, "bpcog")
263 
264  centro = rtc.d_centro[-1]
265  bpix = 8
266  centro.set_nmax(8)
267  centro.set_npix(sup.config.p_wfs0.npix)
268  centro.load_validpos(xvalid, yvalid, xvalid.size)
269  centro.load_img(frame, frame.shape[0])
270  centro.calibrate_img()
271  rtc.do_centroids(0)
272  bincube = np.array(sup.wfs.wfs.d_wfs[0].d_bincube)
273  bincube /= bincube.max()
274  slopes = np.zeros(sup.config.p_wfs0._nvalid * 2)
275  offset = centro.offset
276  scale = centro.scale
277  for k in range(sup.config.p_wfs0._nvalid):
278  imagette = bincube[:, :, k]
279  threshold = np.sort(imagette, axis=None)[-(bpix + 1)]
280  imagette -= threshold
281  imagette[np.where(imagette < 0)] = 0
282  tmp = center_of_mass(imagette)
283  slopes[k] = (tmp[0] - offset) * scale
284  slopes[k + sup.config.p_wfs0._nvalid] = (tmp[1] - offset) * scale
285  assert (relative_array_error(np.array(control.d_centroids), slopes) < precision)
Here is the call graph for this function:

◆ test_doCentroids_cog()

def test_rtcFFF.test_doCentroids_cog ( )

Definition at line 125 of file test_rtcFFF.py.

125 def test_doCentroids_cog():
126  bincube = np.array(sup.wfs.wfs.d_wfs[0].d_bincube)
127  slopes = np.zeros(sup.config.p_wfs0._nvalid * 2)
128  offset = centro.offset
129  scale = centro.scale
130  for k in range(sup.config.p_wfs0._nvalid):
131  tmp = center_of_mass(bincube[:, :, k])
132  slopes[k] = (tmp[0] - offset) * scale
133  slopes[k + sup.config.p_wfs0._nvalid] = (tmp[1] - offset) * scale
134  assert (relative_array_error(np.array(control.d_centroids), slopes) < precision)
135 
136 
Here is the call graph for this function:

◆ test_doCentroids_tcog()

def test_rtcFFF.test_doCentroids_tcog ( )

Definition at line 231 of file test_rtcFFF.py.

231 def test_doCentroids_tcog():
232  rtc.add_centroider(sup.context, sup.config.p_wfs0._nvalid,
233  sup.config.p_wfs0.npix / 2 - 0.5, sup.config.p_wfs0.pixsize,
234  False, 0, "tcog")
235 
236  centro = rtc.d_centro[-1]
237  threshold = 0.1
238  centro.set_threshold(threshold)
239  centro.set_npix(sup.config.p_wfs0.npix)
240  centro.load_validpos(xvalid, yvalid, xvalid.size)
241  centro.load_img(frame, frame.shape[0])
242  centro.calibrate_img()
243  rtc.do_centroids(0)
244  bincube = np.array(sup.wfs.wfs.d_wfs[0].d_bincube)
245  bincube /= bincube.max()
246  slopes = np.zeros(sup.config.p_wfs0._nvalid * 2)
247  offset = centro.offset
248  scale = centro.scale
249  bincube = bincube - threshold
250  bincube[np.where(bincube < 0)] = 0
251  for k in range(sup.config.p_wfs0._nvalid):
252  tmp = center_of_mass(bincube[:, :, k])
253  slopes[k] = (tmp[0] - offset) * scale
254  slopes[k + sup.config.p_wfs0._nvalid] = (tmp[1] - offset) * scale
255  assert (relative_array_error(np.array(control.d_centroids), slopes) < precision)
256 
257 
Here is the call graph for this function:

◆ test_enable_perturb_voltage()

def test_rtcFFF.test_enable_perturb_voltage ( )

Definition at line 190 of file test_rtcFFF.py.

190 def test_enable_perturb_voltage():
191  control.enable_perturb_voltage("test")
192  com = ng.array(control.d_com_clipped).toarray()
193  C = ng.array(control.d_perturb_map["test"][0]).toarray()
194  control.add_perturb()
195  assert (relative_array_error(ng.array(control.d_com_clipped).toarray(), com + C) <
196  precision)
197 
198 
Here is the call graph for this function:

◆ test_initCentro_nvalid()

def test_rtcFFF.test_initCentro_nvalid ( )

Definition at line 55 of file test_rtcFFF.py.

55 def test_initCentro_nvalid():
56  assert (centro.nvalid - sup.config.p_wfs0._nvalid < precision)
57 
58 

◆ test_initCentro_offset()

def test_rtcFFF.test_initCentro_offset ( )

Definition at line 59 of file test_rtcFFF.py.

59 def test_initCentro_offset():
60  assert (centro.offset - (sup.config.p_wfs0.npix / 2 - 0.5) < precision)
61 
62 

◆ test_initCentro_scale()

def test_rtcFFF.test_initCentro_scale ( )

Definition at line 63 of file test_rtcFFF.py.

63 def test_initCentro_scale():
64  assert (centro.scale - sup.config.p_wfs0.pixsize < precision)
65 
66 

◆ test_initCentro_type()

def test_rtcFFF.test_initCentro_type ( )

Definition at line 67 of file test_rtcFFF.py.

67 def test_initCentro_type():
68  assert (centro.type == "cog")
69 
70 

◆ test_initControl_delay()

def test_rtcFFF.test_initControl_delay ( )

Definition at line 83 of file test_rtcFFF.py.

83 def test_initControl_delay():
84  assert (control.delay - sup.config.p_controller0.delay < precision)
85 
86 

◆ test_initControl_nactu()

def test_rtcFFF.test_initControl_nactu ( )

Definition at line 75 of file test_rtcFFF.py.

75 def test_initControl_nactu():
76  assert (control.nactu - sup.config.p_controller0.nactu < precision)
77 
78 

◆ test_initControl_nslope()

def test_rtcFFF.test_initControl_nslope ( )

Definition at line 71 of file test_rtcFFF.py.

71 def test_initControl_nslope():
72  assert (control.nslope - sup.config.p_wfs0._nvalid * 2 < precision)
73 
74 

◆ test_initControl_type()

def test_rtcFFF.test_initControl_type ( )

Definition at line 79 of file test_rtcFFF.py.

79 def test_initControl_type():
80  assert (control.type == "generic")
81 
82 

◆ test_load_img()

def test_rtcFFF.test_load_img ( )

Definition at line 107 of file test_rtcFFF.py.

107 def test_load_img():
108  assert (relative_array_error(np.array(centro.d_img_raw), frame) < precision)
109 
110 
Here is the call graph for this function:

◆ test_load_validposX()

def test_rtcFFF.test_load_validposX ( )

Definition at line 91 of file test_rtcFFF.py.

91 def test_load_validposX():
92  assert (relative_array_error(np.array(centro.d_validx), xvalid) < precision)
93 
94 
Here is the call graph for this function:

◆ test_load_validposY()

def test_rtcFFF.test_load_validposY ( )

Definition at line 95 of file test_rtcFFF.py.

95 def test_load_validposY():
96  assert (relative_array_error(np.array(centro.d_validy), yvalid) < precision)
97 
98 
Here is the call graph for this function:

◆ test_remove_centroider()

def test_rtcFFF.test_remove_centroider ( )

Definition at line 226 of file test_rtcFFF.py.

226 def test_remove_centroider():
227  rtc.remove_centroider(0)
228  assert (rtc.d_centro == [])
229 
230 

◆ test_remove_perturb_voltage()

def test_rtcFFF.test_remove_perturb_voltage ( )

Definition at line 169 of file test_rtcFFF.py.

169 def test_remove_perturb_voltage():
170  control.remove_perturb_voltage("test")
171  assert (control.d_perturb_map == {})
172 
173 

◆ test_reset_perturb_voltage()

def test_rtcFFF.test_reset_perturb_voltage ( )

Definition at line 199 of file test_rtcFFF.py.

199 def test_reset_perturb_voltage():
200  control.reset_perturb_voltage()
201  assert (control.d_perturb_map == {})
202 
203 

◆ test_set_cmat()

def test_rtcFFF.test_set_cmat ( )

Definition at line 99 of file test_rtcFFF.py.

99 def test_set_cmat():
100  assert (relative_array_error(np.array(control.d_cmat), cmat) < precision)
101 
102 
Here is the call graph for this function:

◆ test_set_comRange()

def test_rtcFFF.test_set_comRange ( )

Definition at line 145 of file test_rtcFFF.py.

145 def test_set_comRange():
146  control.set_comRange(-1, 1)
147  assert (control.comRange == (-1, 1))
148 
149 

◆ test_set_dark()

def test_rtcFFF.test_set_dark ( )

Definition at line 111 of file test_rtcFFF.py.

111 def test_set_dark():
112  assert (relative_array_error(np.array(centro.d_dark), dark) < precision)
113 
114 
Here is the call graph for this function:

◆ test_set_flat()

def test_rtcFFF.test_set_flat ( )

Definition at line 115 of file test_rtcFFF.py.

115 def test_set_flat():
116  assert (relative_array_error(np.array(centro.d_flat), flat) < precision)
117 
118 
Here is the call graph for this function:

◆ test_set_gain()

def test_rtcFFF.test_set_gain ( )

Definition at line 103 of file test_rtcFFF.py.

103 def test_set_gain():
104  assert (control.gain - sup.config.p_controller0.gain < precision)
105 
106 

◆ test_set_npix()

def test_rtcFFF.test_set_npix ( )

Definition at line 87 of file test_rtcFFF.py.

87 def test_set_npix():
88  assert (centro.npix - sup.config.p_wfs0.npix < precision)
89 
90 

Variable Documentation

◆ centro

test_rtcFFF.centro = rtc.d_centro[0]

Definition at line 26 of file test_rtcFFF.py.

◆ cmat

test_rtcFFF.cmat = sup.rtc.get_command_matrix(0)

Definition at line 32 of file test_rtcFFF.py.

◆ com

test_rtcFFF.com = ng.array(rtc.d_control[0].d_com)

Definition at line 43 of file test_rtcFFF.py.

◆ config

test_rtcFFF.config
Initial value:
1 = load_config_from_file(os.getenv("COMPASS_ROOT") +
2  "/shesha/tests/pytest/par/test_sh.py")

Definition at line 11 of file test_rtcFFF.py.

◆ control

test_rtcFFF.control = rtc.d_control[0]

Definition at line 27 of file test_rtcFFF.py.

◆ dark

test_rtcFFF.dark = np.random.random(frame.shape)

Definition at line 45 of file test_rtcFFF.py.

◆ flat

test_rtcFFF.flat = np.random.random(frame.shape)

Definition at line 46 of file test_rtcFFF.py.

◆ frame

test_rtcFFF.frame = sup.wfs.get_wfs_image(0)

Definition at line 35 of file test_rtcFFF.py.

◆ idx_centro

test_rtcFFF.idx_centro

Definition at line 24 of file test_rtcFFF.py.

◆ ncentro

test_rtcFFF.ncentro

Definition at line 25 of file test_rtcFFF.py.

◆ precision

int test_rtcFFF.precision = 1e-2

Definition at line 9 of file test_rtcFFF.py.

◆ rtc

test_rtcFFF.rtc = Rtc()

Definition at line 18 of file test_rtcFFF.py.

◆ slp

test_rtcFFF.slp = ng.array(rtc.d_control[0].d_centroids)

Definition at line 41 of file test_rtcFFF.py.

◆ sup

test_rtcFFF.sup = Supervisor(config)

Definition at line 13 of file test_rtcFFF.py.

◆ xvalid

test_rtcFFF.xvalid = np.array(sup.rtc.rtc.d_centro[0].d_validx)

Definition at line 29 of file test_rtcFFF.py.

◆ yvalid

test_rtcFFF.yvalid = np.array(sup.rtc.rtc.d_centro[0].d_validy)

Definition at line 30 of file test_rtcFFF.py.