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

Definition at line 55 of file test_rtcUHF.py.

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

◆ test_add_perturb()

def test_rtcUHF.test_add_perturb ( )

Definition at line 180 of file test_rtcUHF.py.

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

◆ test_add_perturb_voltage()

def test_rtcUHF.test_add_perturb_voltage ( )

Definition at line 168 of file test_rtcUHF.py.

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

◆ test_calibrate_img()

def test_rtcUHF.test_calibrate_img ( )

Definition at line 123 of file test_rtcUHF.py.

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

◆ test_clipping()

def test_rtcUHF.test_clipping ( )

Definition at line 156 of file test_rtcUHF.py.

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

◆ test_comp_voltage()

def test_rtcUHF.test_comp_voltage ( )

Definition at line 210 of file test_rtcUHF.py.

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

◆ test_disable_perturb_voltage()

def test_rtcUHF.test_disable_perturb_voltage ( )

Definition at line 189 of file test_rtcUHF.py.

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

◆ test_do_control_generic()

def test_rtcUHF.test_do_control_generic ( )

Definition at line 142 of file test_rtcUHF.py.

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

◆ test_doCentroids_bpcog()

def test_rtcUHF.test_doCentroids_bpcog ( )

Definition at line 267 of file test_rtcUHF.py.

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

◆ test_doCentroids_cog()

def test_rtcUHF.test_doCentroids_cog ( )

Definition at line 129 of file test_rtcUHF.py.

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

◆ test_doCentroids_tcog()

def test_rtcUHF.test_doCentroids_tcog ( )

Definition at line 237 of file test_rtcUHF.py.

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

◆ test_enable_perturb_voltage()

def test_rtcUHF.test_enable_perturb_voltage ( )

Definition at line 196 of file test_rtcUHF.py.

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

◆ test_initCentro_nvalid()

def test_rtcUHF.test_initCentro_nvalid ( )

Definition at line 59 of file test_rtcUHF.py.

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

◆ test_initCentro_offset()

def test_rtcUHF.test_initCentro_offset ( )

Definition at line 63 of file test_rtcUHF.py.

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

◆ test_initCentro_scale()

def test_rtcUHF.test_initCentro_scale ( )

Definition at line 67 of file test_rtcUHF.py.

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

◆ test_initCentro_type()

def test_rtcUHF.test_initCentro_type ( )

Definition at line 71 of file test_rtcUHF.py.

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

◆ test_initControl_delay()

def test_rtcUHF.test_initControl_delay ( )

Definition at line 87 of file test_rtcUHF.py.

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

◆ test_initControl_nactu()

def test_rtcUHF.test_initControl_nactu ( )

Definition at line 79 of file test_rtcUHF.py.

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

◆ test_initControl_nslope()

def test_rtcUHF.test_initControl_nslope ( )

Definition at line 75 of file test_rtcUHF.py.

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

◆ test_initControl_type()

def test_rtcUHF.test_initControl_type ( )

Definition at line 83 of file test_rtcUHF.py.

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

◆ test_load_img()

def test_rtcUHF.test_load_img ( )

Definition at line 111 of file test_rtcUHF.py.

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

◆ test_load_validposX()

def test_rtcUHF.test_load_validposX ( )

Definition at line 95 of file test_rtcUHF.py.

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

◆ test_load_validposY()

def test_rtcUHF.test_load_validposY ( )

Definition at line 99 of file test_rtcUHF.py.

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

◆ test_remove_centroider()

def test_rtcUHF.test_remove_centroider ( )

Definition at line 232 of file test_rtcUHF.py.

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

◆ test_remove_perturb_voltage()

def test_rtcUHF.test_remove_perturb_voltage ( )

Definition at line 175 of file test_rtcUHF.py.

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

◆ test_reset_perturb_voltage()

def test_rtcUHF.test_reset_perturb_voltage ( )

Definition at line 205 of file test_rtcUHF.py.

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

◆ test_set_cmat()

def test_rtcUHF.test_set_cmat ( )

Definition at line 103 of file test_rtcUHF.py.

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

◆ test_set_comRange()

def test_rtcUHF.test_set_comRange ( )

Definition at line 151 of file test_rtcUHF.py.

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

◆ test_set_dark()

def test_rtcUHF.test_set_dark ( )

Definition at line 115 of file test_rtcUHF.py.

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

◆ test_set_flat()

def test_rtcUHF.test_set_flat ( )

Definition at line 119 of file test_rtcUHF.py.

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

◆ test_set_gain()

def test_rtcUHF.test_set_gain ( )

Definition at line 107 of file test_rtcUHF.py.

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

◆ test_set_npix()

def test_rtcUHF.test_set_npix ( )

Definition at line 91 of file test_rtcUHF.py.

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

Variable Documentation

◆ centro

test_rtcUHF.centro = rtc.d_centro[0]

Definition at line 31 of file test_rtcUHF.py.

◆ cmat

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

Definition at line 37 of file test_rtcUHF.py.

◆ com

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

Definition at line 47 of file test_rtcUHF.py.

◆ config

test_rtcUHF.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_rtcUHF.py.

◆ control

test_rtcUHF.control = rtc.d_control[0]

Definition at line 32 of file test_rtcUHF.py.

◆ dark

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

Definition at line 49 of file test_rtcUHF.py.

◆ flat

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

Definition at line 50 of file test_rtcUHF.py.

◆ frame

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

Definition at line 40 of file test_rtcUHF.py.

◆ idx_centro

test_rtcUHF.idx_centro

Definition at line 29 of file test_rtcUHF.py.

◆ ncentro

test_rtcUHF.ncentro

Definition at line 30 of file test_rtcUHF.py.

◆ precision

int test_rtcUHF.precision = 1e-2

Definition at line 9 of file test_rtcUHF.py.

◆ rtc

test_rtcUHF.rtc = Rtc()

Definition at line 23 of file test_rtcUHF.py.

◆ slp

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

Definition at line 45 of file test_rtcUHF.py.

◆ sup

test_rtcUHF.sup = Supervisor(config)

Definition at line 14 of file test_rtcUHF.py.

◆ xvalid

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

Definition at line 34 of file test_rtcUHF.py.

◆ yvalid

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

Definition at line 35 of file test_rtcUHF.py.