COMPASS  5.0.0
End-to-end AO simulation tool using GPU acceleration
test_rtcFFU 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
 
 push4imat
 
 unitpervolt
 
 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_rtcFFU.relative_array_error (   array1,
  array2 
)

Definition at line 57 of file test_rtcFFU.py.

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

◆ test_add_perturb()

def test_rtcFFU.test_add_perturb ( )

Definition at line 182 of file test_rtcFFU.py.

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

◆ test_add_perturb_voltage()

def test_rtcFFU.test_add_perturb_voltage ( )

Definition at line 170 of file test_rtcFFU.py.

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

◆ test_calibrate_img()

def test_rtcFFU.test_calibrate_img ( )

Definition at line 125 of file test_rtcFFU.py.

125 def test_calibrate_img():
126  centro.calibrate_img()
127  imgCal = (frame.astype(np.float32) - dark) * flat
128  assert (relative_array_error(ng.array(centro.d_img).toarray(), imgCal) < precision)
129 
130 
Here is the call graph for this function:

◆ test_clipping()

def test_rtcFFU.test_clipping ( )

Definition at line 158 of file test_rtcFFU.py.

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

◆ test_comp_voltage()

def test_rtcFFU.test_comp_voltage ( )

Definition at line 212 of file test_rtcFFU.py.

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

◆ test_disable_perturb_voltage()

def test_rtcFFU.test_disable_perturb_voltage ( )

Definition at line 191 of file test_rtcFFU.py.

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

◆ test_do_control_generic()

def test_rtcFFU.test_do_control_generic ( )

Definition at line 144 of file test_rtcFFU.py.

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

◆ test_doCentroids_bpcog()

def test_rtcFFU.test_doCentroids_bpcog ( )

Definition at line 271 of file test_rtcFFU.py.

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

◆ test_doCentroids_cog()

def test_rtcFFU.test_doCentroids_cog ( )

Definition at line 131 of file test_rtcFFU.py.

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

◆ test_doCentroids_tcog()

def test_rtcFFU.test_doCentroids_tcog ( )

Definition at line 241 of file test_rtcFFU.py.

241 def test_doCentroids_tcog():
242  rtc.add_centroider(sup.context, sup.config.p_wfs0._nvalid,
243  sup.config.p_wfs0.npix / 2 - 0.5, sup.config.p_wfs0.pixsize,
244  False, 0, "tcog")
245 
246  centro = rtc.d_centro[-1]
247  threshold = 500
248  centro.set_threshold(threshold)
249  centro.set_npix(sup.config.p_wfs0.npix)
250  centro.load_validpos(xvalid, yvalid, xvalid.size)
251  centro.load_img(frame, frame.shape[0])
252  centro.calibrate_img()
253  rtc.do_centroids(0)
254  slopes = np.zeros(sup.config.p_wfs0._nvalid * 2)
255  offset = centro.offset
256  scale = centro.scale
257  vx = sup.config.p_wfs0._validsubsx
258  vy = sup.config.p_wfs0._validsubsy
259  npix = sup.config.p_wfs0.npix
260  for k in range(sup.config.p_wfs0._nvalid):
261  imagette = frame[vx[k]:vx[k] + npix, vy[k]:vy[k] + npix].astype(
262  np.float32) - threshold
263  imagette[np.where(imagette < 0)] = 0
264  tmp = center_of_mass(imagette)
265  slopes[k] = (tmp[0] - offset) * scale
266  slopes[k + sup.config.p_wfs0._nvalid] = (tmp[1] - offset) * scale
267  assert (relative_array_error(ng.array(control.d_centroids).toarray(), slopes) <
268  precision)
269 
270 
Here is the call graph for this function:

◆ test_enable_perturb_voltage()

def test_rtcFFU.test_enable_perturb_voltage ( )

Definition at line 198 of file test_rtcFFU.py.

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

◆ test_initCentro_nvalid()

def test_rtcFFU.test_initCentro_nvalid ( )

Definition at line 61 of file test_rtcFFU.py.

61 def test_initCentro_nvalid():
62  assert (centro.nvalid - sup.config.p_wfs0._nvalid < precision)
63 
64 

◆ test_initCentro_offset()

def test_rtcFFU.test_initCentro_offset ( )

Definition at line 65 of file test_rtcFFU.py.

65 def test_initCentro_offset():
66  assert (centro.offset - (sup.config.p_wfs0.npix / 2 - 0.5) < precision)
67 
68 

◆ test_initCentro_scale()

def test_rtcFFU.test_initCentro_scale ( )

Definition at line 69 of file test_rtcFFU.py.

69 def test_initCentro_scale():
70  assert (centro.scale - sup.config.p_wfs0.pixsize < precision)
71 
72 

◆ test_initCentro_type()

def test_rtcFFU.test_initCentro_type ( )

Definition at line 73 of file test_rtcFFU.py.

73 def test_initCentro_type():
74  assert (centro.type == "cog")
75 
76 

◆ test_initControl_delay()

def test_rtcFFU.test_initControl_delay ( )

Definition at line 89 of file test_rtcFFU.py.

89 def test_initControl_delay():
90  assert (control.delay - sup.config.p_controller0.delay < precision)
91 
92 

◆ test_initControl_nactu()

def test_rtcFFU.test_initControl_nactu ( )

Definition at line 81 of file test_rtcFFU.py.

81 def test_initControl_nactu():
82  assert (control.nactu - sup.config.p_controller0.nactu < precision)
83 
84 

◆ test_initControl_nslope()

def test_rtcFFU.test_initControl_nslope ( )

Definition at line 77 of file test_rtcFFU.py.

77 def test_initControl_nslope():
78  assert (control.nslope - sup.config.p_wfs0._nvalid * 2 < precision)
79 
80 

◆ test_initControl_type()

def test_rtcFFU.test_initControl_type ( )

Definition at line 85 of file test_rtcFFU.py.

85 def test_initControl_type():
86  assert (control.type == "generic")
87 
88 

◆ test_load_img()

def test_rtcFFU.test_load_img ( )

Definition at line 113 of file test_rtcFFU.py.

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

◆ test_load_validposX()

def test_rtcFFU.test_load_validposX ( )

Definition at line 97 of file test_rtcFFU.py.

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

◆ test_load_validposY()

def test_rtcFFU.test_load_validposY ( )

Definition at line 101 of file test_rtcFFU.py.

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

◆ test_remove_centroider()

def test_rtcFFU.test_remove_centroider ( )

Definition at line 236 of file test_rtcFFU.py.

236 def test_remove_centroider():
237  rtc.remove_centroider(0)
238  assert (rtc.d_centro == [])
239 
240 

◆ test_remove_perturb_voltage()

def test_rtcFFU.test_remove_perturb_voltage ( )

Definition at line 177 of file test_rtcFFU.py.

177 def test_remove_perturb_voltage():
178  control.remove_perturb_voltage("test")
179  assert (control.d_perturb_map == {})
180 
181 

◆ test_reset_perturb_voltage()

def test_rtcFFU.test_reset_perturb_voltage ( )

Definition at line 207 of file test_rtcFFU.py.

207 def test_reset_perturb_voltage():
208  control.reset_perturb_voltage()
209  assert (control.d_perturb_map == {})
210 
211 

◆ test_set_cmat()

def test_rtcFFU.test_set_cmat ( )

Definition at line 105 of file test_rtcFFU.py.

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

◆ test_set_comRange()

def test_rtcFFU.test_set_comRange ( )

Definition at line 153 of file test_rtcFFU.py.

153 def test_set_comRange():
154  control.set_comRange(-1, 1)
155  assert (control.comRange == (-1, 1))
156 
157 

◆ test_set_dark()

def test_rtcFFU.test_set_dark ( )

Definition at line 117 of file test_rtcFFU.py.

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

◆ test_set_flat()

def test_rtcFFU.test_set_flat ( )

Definition at line 121 of file test_rtcFFU.py.

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

◆ test_set_gain()

def test_rtcFFU.test_set_gain ( )

Definition at line 109 of file test_rtcFFU.py.

109 def test_set_gain():
110  assert (control.gain - sup.config.p_controller0.gain < precision)
111 
112 

◆ test_set_npix()

def test_rtcFFU.test_set_npix ( )

Definition at line 93 of file test_rtcFFU.py.

93 def test_set_npix():
94  assert (centro.npix - sup.config.p_wfs0.npix < precision)
95 
96 

Variable Documentation

◆ centro

test_rtcFFU.centro = rtc.d_centro[0]

Definition at line 33 of file test_rtcFFU.py.

◆ cmat

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

Definition at line 39 of file test_rtcFFU.py.

◆ com

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

Definition at line 49 of file test_rtcFFU.py.

◆ config

test_rtcFFU.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_rtcFFU.py.

◆ control

test_rtcFFU.control = rtc.d_control[0]

Definition at line 34 of file test_rtcFFU.py.

◆ dark

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

Definition at line 51 of file test_rtcFFU.py.

◆ flat

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

Definition at line 52 of file test_rtcFFU.py.

◆ frame

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

Definition at line 42 of file test_rtcFFU.py.

◆ idx_centro

test_rtcFFU.idx_centro

Definition at line 31 of file test_rtcFFU.py.

◆ ncentro

test_rtcFFU.ncentro

Definition at line 32 of file test_rtcFFU.py.

◆ precision

int test_rtcFFU.precision = 1e-2

Definition at line 9 of file test_rtcFFU.py.

◆ push4imat

test_rtcFFU.push4imat

Definition at line 13 of file test_rtcFFU.py.

◆ rtc

test_rtcFFU.rtc = Rtc()

Definition at line 25 of file test_rtcFFU.py.

◆ slp

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

Definition at line 47 of file test_rtcFFU.py.

◆ sup

test_rtcFFU.sup = Supervisor(config)

Definition at line 17 of file test_rtcFFU.py.

◆ unitpervolt

test_rtcFFU.unitpervolt

Definition at line 14 of file test_rtcFFU.py.

◆ xvalid

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

Definition at line 36 of file test_rtcFFU.py.

◆ yvalid

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

Definition at line 37 of file test_rtcFFU.py.