COMPASS  5.0.0
End-to-end AO simulation tool using GPU acceleration
test_rtcUFF 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 = np.array(sup.wfs.wfs.d_wfs[0].d_camimg)
 
 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_rtcUFF.relative_array_error (   array1,
  array2 
)

Definition at line 54 of file test_rtcUFF.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_rtcUFF.test_add_perturb ( )

Definition at line 179 of file test_rtcUFF.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_rtcUFF.test_add_perturb_voltage ( )

Definition at line 167 of file test_rtcUFF.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_rtcUFF.test_calibrate_img ( )

Definition at line 122 of file test_rtcUFF.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_rtcUFF.test_clipping ( )

Definition at line 155 of file test_rtcUFF.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_rtcUFF.test_comp_voltage ( )

Definition at line 209 of file test_rtcUFF.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_rtcUFF.test_disable_perturb_voltage ( )

Definition at line 188 of file test_rtcUFF.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_rtcUFF.test_do_control_generic ( )

Definition at line 141 of file test_rtcUFF.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_rtcUFF.test_doCentroids_bpcog ( )

Definition at line 266 of file test_rtcUFF.py.

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

◆ test_doCentroids_cog()

def test_rtcUFF.test_doCentroids_cog ( )

Definition at line 128 of file test_rtcUFF.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_rtcUFF.test_doCentroids_tcog ( )

Definition at line 236 of file test_rtcUFF.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 = 5000
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  slopes = np.zeros(sup.config.p_wfs0._nvalid * 2)
250  offset = centro.offset
251  scale = centro.scale
252  vx = sup.config.p_wfs0._validsubsx
253  vy = sup.config.p_wfs0._validsubsy
254  npix = sup.config.p_wfs0.npix
255  for k in range(sup.config.p_wfs0._nvalid):
256  imagette = frame[vx[k]:vx[k] + npix, vy[k]:vy[k] + npix].astype(
257  np.float32) - threshold
258  imagette[np.where(imagette < 0)] = 0
259  tmp = center_of_mass(imagette)
260  slopes[k] = (tmp[0] - offset) * scale
261  slopes[k + sup.config.p_wfs0._nvalid] = (tmp[1] - offset) * scale
262  assert (relative_array_error(ng.array(control.d_centroids).toarray(), slopes) <
263  precision)
264 
265 
Here is the call graph for this function:

◆ test_enable_perturb_voltage()

def test_rtcUFF.test_enable_perturb_voltage ( )

Definition at line 195 of file test_rtcUFF.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_rtcUFF.test_initCentro_nvalid ( )

Definition at line 58 of file test_rtcUFF.py.

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

◆ test_initCentro_offset()

def test_rtcUFF.test_initCentro_offset ( )

Definition at line 62 of file test_rtcUFF.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_rtcUFF.test_initCentro_scale ( )

Definition at line 66 of file test_rtcUFF.py.

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

◆ test_initCentro_type()

def test_rtcUFF.test_initCentro_type ( )

Definition at line 70 of file test_rtcUFF.py.

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

◆ test_initControl_delay()

def test_rtcUFF.test_initControl_delay ( )

Definition at line 86 of file test_rtcUFF.py.

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

◆ test_initControl_nactu()

def test_rtcUFF.test_initControl_nactu ( )

Definition at line 78 of file test_rtcUFF.py.

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

◆ test_initControl_nslope()

def test_rtcUFF.test_initControl_nslope ( )

Definition at line 74 of file test_rtcUFF.py.

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

◆ test_initControl_type()

def test_rtcUFF.test_initControl_type ( )

Definition at line 82 of file test_rtcUFF.py.

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

◆ test_load_img()

def test_rtcUFF.test_load_img ( )

Definition at line 110 of file test_rtcUFF.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_rtcUFF.test_load_validposX ( )

Definition at line 94 of file test_rtcUFF.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_rtcUFF.test_load_validposY ( )

Definition at line 98 of file test_rtcUFF.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_remove_centroider()

def test_rtcUFF.test_remove_centroider ( )

Definition at line 231 of file test_rtcUFF.py.

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

◆ test_remove_perturb_voltage()

def test_rtcUFF.test_remove_perturb_voltage ( )

Definition at line 174 of file test_rtcUFF.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_rtcUFF.test_reset_perturb_voltage ( )

Definition at line 204 of file test_rtcUFF.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_rtcUFF.test_set_cmat ( )

Definition at line 102 of file test_rtcUFF.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_rtcUFF.test_set_comRange ( )

Definition at line 150 of file test_rtcUFF.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_rtcUFF.test_set_dark ( )

Definition at line 114 of file test_rtcUFF.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_rtcUFF.test_set_flat ( )

Definition at line 118 of file test_rtcUFF.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_rtcUFF.test_set_gain ( )

Definition at line 106 of file test_rtcUFF.py.

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

◆ test_set_npix()

def test_rtcUFF.test_set_npix ( )

Definition at line 90 of file test_rtcUFF.py.

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

Variable Documentation

◆ centro

test_rtcUFF.centro = rtc.d_centro[0]

Definition at line 30 of file test_rtcUFF.py.

◆ cmat

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

Definition at line 36 of file test_rtcUFF.py.

◆ com

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

Definition at line 46 of file test_rtcUFF.py.

◆ config

test_rtcUFF.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_rtcUFF.py.

◆ control

test_rtcUFF.control = rtc.d_control[0]

Definition at line 31 of file test_rtcUFF.py.

◆ dark

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

Definition at line 48 of file test_rtcUFF.py.

◆ flat

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

Definition at line 49 of file test_rtcUFF.py.

◆ frame

test_rtcUFF.frame = np.array(sup.wfs.wfs.d_wfs[0].d_camimg)

Definition at line 39 of file test_rtcUFF.py.

◆ idx_centro

test_rtcUFF.idx_centro

Definition at line 28 of file test_rtcUFF.py.

◆ ncentro

test_rtcUFF.ncentro

Definition at line 29 of file test_rtcUFF.py.

◆ precision

int test_rtcUFF.precision = 1e-2

Definition at line 9 of file test_rtcUFF.py.

◆ rtc

test_rtcUFF.rtc = Rtc()

Definition at line 22 of file test_rtcUFF.py.

◆ slp

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

Definition at line 44 of file test_rtcUFF.py.

◆ sup

test_rtcUFF.sup = Supervisor(config)

Definition at line 13 of file test_rtcUFF.py.

◆ xvalid

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

Definition at line 33 of file test_rtcUFF.py.

◆ yvalid

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

Definition at line 34 of file test_rtcUFF.py.