COMPASS  5.0.0
End-to-end AO simulation tool using GPU acceleration
test_rtc_cacao 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 ()
 
def test_publish_calPix ()
 
def test_publish_loopData ()
 

Variables

int precision = 1e-5
 
 config
 
 sup = Supervisor(config)
 
 rtc = Rtc("compass_calPix", "compass_loopData")
 
 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_rtc_cacao.relative_array_error (   array1,
  array2 
)

Definition at line 54 of file test_rtc_cacao.py.

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

◆ test_add_perturb()

def test_rtc_cacao.test_add_perturb ( )

Definition at line 179 of file test_rtc_cacao.py.

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

◆ test_add_perturb_voltage()

def test_rtc_cacao.test_add_perturb_voltage ( )

Definition at line 167 of file test_rtc_cacao.py.

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

◆ test_calibrate_img()

def test_rtc_cacao.test_calibrate_img ( )

Definition at line 122 of file test_rtc_cacao.py.

122 def test_calibrate_img():
123  centro.calibrate_img()
124  imgCal = (frame - dark) * flat
125  assert (relative_array_error(ng.array(centro.d_img).toarray(), imgCal) < precision)
126 
127 
Here is the call graph for this function:

◆ test_clipping()

def test_rtc_cacao.test_clipping ( )

Definition at line 155 of file test_rtc_cacao.py.

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

◆ test_comp_voltage()

def test_rtc_cacao.test_comp_voltage ( )

Definition at line 209 of file test_rtc_cacao.py.

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

◆ test_disable_perturb_voltage()

def test_rtc_cacao.test_disable_perturb_voltage ( )

Definition at line 188 of file test_rtc_cacao.py.

188 def test_disable_perturb_voltage():
189  control.disable_perturb_voltage("test")
190  com = ng.array(control.d_com).toarray()
191  control.add_perturb()
192  assert (relative_array_error(ng.array(control.d_com).toarray(), com) < precision)
193 
194 
Here is the call graph for this function:

◆ test_do_control_generic()

def test_rtc_cacao.test_do_control_generic ( )

Definition at line 141 of file test_rtc_cacao.py.

141 def test_do_control_generic():
142  slopes = ng.array(control.d_centroids).toarray()
143  gain = control.gain
144  cmat = ng.array(control.d_cmat).toarray()
145  commands = cmat.dot(slopes) * gain * (-1)
146  assert (relative_array_error(ng.array(control.d_com).toarray(), commands) <
147  precision)
148 
149 
Here is the call graph for this function:

◆ test_doCentroids_bpcog()

def test_rtc_cacao.test_doCentroids_bpcog ( )

Definition at line 264 of file test_rtc_cacao.py.

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

◆ test_doCentroids_cog()

def test_rtc_cacao.test_doCentroids_cog ( )

Definition at line 128 of file test_rtc_cacao.py.

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

◆ test_doCentroids_tcog()

def test_rtc_cacao.test_doCentroids_tcog ( )

Definition at line 236 of file test_rtc_cacao.py.

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

◆ test_enable_perturb_voltage()

def test_rtc_cacao.test_enable_perturb_voltage ( )

Definition at line 195 of file test_rtc_cacao.py.

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

◆ test_initCentro_nvalid()

def test_rtc_cacao.test_initCentro_nvalid ( )

Definition at line 58 of file test_rtc_cacao.py.

58 def test_initCentro_nvalid():
59  assert (centro.nvalid - sup.config.p_wfs0._nvalid < precision)
60 
61 

◆ test_initCentro_offset()

def test_rtc_cacao.test_initCentro_offset ( )

Definition at line 62 of file test_rtc_cacao.py.

62 def test_initCentro_offset():
63  assert (centro.offset - (sup.config.p_wfs0.npix / 2 - 0.5) < precision)
64 
65 

◆ test_initCentro_scale()

def test_rtc_cacao.test_initCentro_scale ( )

Definition at line 66 of file test_rtc_cacao.py.

66 def test_initCentro_scale():
67  assert (centro.scale - sup.config.p_wfs0.pixsize < precision)
68 
69 

◆ test_initCentro_type()

def test_rtc_cacao.test_initCentro_type ( )

Definition at line 70 of file test_rtc_cacao.py.

70 def test_initCentro_type():
71  assert (centro.type == "cog")
72 
73 

◆ test_initControl_delay()

def test_rtc_cacao.test_initControl_delay ( )

Definition at line 86 of file test_rtc_cacao.py.

86 def test_initControl_delay():
87  assert (control.delay - sup.config.p_controller0.delay < precision)
88 
89 

◆ test_initControl_nactu()

def test_rtc_cacao.test_initControl_nactu ( )

Definition at line 78 of file test_rtc_cacao.py.

78 def test_initControl_nactu():
79  assert (control.nactu - sup.config.p_controller0.nactu < precision)
80 
81 

◆ test_initControl_nslope()

def test_rtc_cacao.test_initControl_nslope ( )

Definition at line 74 of file test_rtc_cacao.py.

74 def test_initControl_nslope():
75  assert (control.nslope - sup.config.p_wfs0._nvalid * 2 < precision)
76 
77 

◆ test_initControl_type()

def test_rtc_cacao.test_initControl_type ( )

Definition at line 82 of file test_rtc_cacao.py.

82 def test_initControl_type():
83  assert (control.type == "generic")
84 
85 

◆ test_load_img()

def test_rtc_cacao.test_load_img ( )

Definition at line 110 of file test_rtc_cacao.py.

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

◆ test_load_validposX()

def test_rtc_cacao.test_load_validposX ( )

Definition at line 94 of file test_rtc_cacao.py.

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

◆ test_load_validposY()

def test_rtc_cacao.test_load_validposY ( )

Definition at line 98 of file test_rtc_cacao.py.

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

◆ test_publish_calPix()

def test_rtc_cacao.test_publish_calPix ( )

Definition at line 295 of file test_rtc_cacao.py.

295 def test_publish_calPix():
296  centro = rtc.d_centro[-1]
297  rtc.publish()
298  interface = CacaoInterface.getInterface("compass_calPix")
299  tmp = np.array(interface)
300  assert (relative_array_error(np.array(centro.d_img), tmp) < precision)
301 
302 
303 @pytest.mark.skip(reason="intensities disabled")
Here is the call graph for this function:

◆ test_publish_loopData()

def test_rtc_cacao.test_publish_loopData ( )

Definition at line 304 of file test_rtc_cacao.py.

304 def test_publish_loopData():
305  centro = rtc.d_centro[-1]
306  rtc.publish()
307  it = CacaoInterface.getInterface("compass_loopData")
308  data = np.array(it)
309  nvalid = sup.config.p_wfs0._nvalid
310  nslopes = sup.config.p_controller0.nslope
311  nactus = sup.config.p_controller0.nactu
312  tmp = np.zeros(nvalid + nslopes + nactus)
313  tmp[:nvalid] = np.array(centro.d_intensities)
314  tmp[nvalid:nvalid + nslopes] = np.array(control.d_centroids)
315  tmp[nvalid + nslopes:] = np.array(control.d_com)
316  assert (relative_array_error(data, tmp) < precision)
Here is the call graph for this function:

◆ test_remove_centroider()

def test_rtc_cacao.test_remove_centroider ( )

Definition at line 231 of file test_rtc_cacao.py.

231 def test_remove_centroider():
232  rtc.remove_centroider(0)
233  assert (rtc.d_centro == [])
234 
235 

◆ test_remove_perturb_voltage()

def test_rtc_cacao.test_remove_perturb_voltage ( )

Definition at line 174 of file test_rtc_cacao.py.

174 def test_remove_perturb_voltage():
175  control.remove_perturb_voltage("test")
176  assert (control.d_perturb_map == {})
177 
178 

◆ test_reset_perturb_voltage()

def test_rtc_cacao.test_reset_perturb_voltage ( )

Definition at line 204 of file test_rtc_cacao.py.

204 def test_reset_perturb_voltage():
205  control.reset_perturb_voltage()
206  assert (control.d_perturb_map == {})
207 
208 

◆ test_set_cmat()

def test_rtc_cacao.test_set_cmat ( )

Definition at line 102 of file test_rtc_cacao.py.

102 def test_set_cmat():
103  assert (relative_array_error(ng.array(control.d_cmat).toarray(), cmat) < precision)
104 
105 
Here is the call graph for this function:

◆ test_set_comRange()

def test_rtc_cacao.test_set_comRange ( )

Definition at line 150 of file test_rtc_cacao.py.

150 def test_set_comRange():
151  control.set_comRange(-1, 1)
152  assert (control.comRange == (-1, 1))
153 
154 

◆ test_set_dark()

def test_rtc_cacao.test_set_dark ( )

Definition at line 114 of file test_rtc_cacao.py.

114 def test_set_dark():
115  assert (relative_array_error(ng.array(centro.d_dark).toarray(), dark) < precision)
116 
117 
Here is the call graph for this function:

◆ test_set_flat()

def test_rtc_cacao.test_set_flat ( )

Definition at line 118 of file test_rtc_cacao.py.

118 def test_set_flat():
119  assert (relative_array_error(ng.array(centro.d_flat).toarray(), flat) < precision)
120 
121 
Here is the call graph for this function:

◆ test_set_gain()

def test_rtc_cacao.test_set_gain ( )

Definition at line 106 of file test_rtc_cacao.py.

106 def test_set_gain():
107  assert (control.gain - sup.config.p_controller0.gain < precision)
108 
109 

◆ test_set_npix()

def test_rtc_cacao.test_set_npix ( )

Definition at line 90 of file test_rtc_cacao.py.

90 def test_set_npix():
91  assert (centro.npix - sup.config.p_wfs0.npix < precision)
92 
93 

Variable Documentation

◆ centro

test_rtc_cacao.centro = rtc.d_centro[0]

Definition at line 29 of file test_rtc_cacao.py.

◆ cmat

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

Definition at line 35 of file test_rtc_cacao.py.

◆ com

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

Definition at line 46 of file test_rtc_cacao.py.

◆ config

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

Definition at line 14 of file test_rtc_cacao.py.

◆ control

test_rtc_cacao.control = rtc.d_control[0]

Definition at line 30 of file test_rtc_cacao.py.

◆ dark

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

Definition at line 48 of file test_rtc_cacao.py.

◆ flat

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

Definition at line 49 of file test_rtc_cacao.py.

◆ frame

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

Definition at line 38 of file test_rtc_cacao.py.

◆ idx_centro

test_rtc_cacao.idx_centro

Definition at line 27 of file test_rtc_cacao.py.

◆ ncentro

test_rtc_cacao.ncentro

Definition at line 28 of file test_rtc_cacao.py.

◆ precision

int test_rtc_cacao.precision = 1e-5

Definition at line 12 of file test_rtc_cacao.py.

◆ rtc

test_rtc_cacao.rtc = Rtc("compass_calPix", "compass_loopData")

Definition at line 21 of file test_rtc_cacao.py.

◆ slp

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

Definition at line 44 of file test_rtc_cacao.py.

◆ sup

test_rtc_cacao.sup = Supervisor(config)

Definition at line 16 of file test_rtc_cacao.py.

◆ xvalid

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

Definition at line 32 of file test_rtc_cacao.py.

◆ yvalid

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

Definition at line 33 of file test_rtc_cacao.py.