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

Definition at line 58 of file test_rtcUHU.py.

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

◆ test_add_perturb()

def test_rtcUHU.test_add_perturb ( )

Definition at line 183 of file test_rtcUHU.py.

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

◆ test_add_perturb_voltage()

def test_rtcUHU.test_add_perturb_voltage ( )

Definition at line 171 of file test_rtcUHU.py.

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

◆ test_calibrate_img()

def test_rtcUHU.test_calibrate_img ( )

Definition at line 126 of file test_rtcUHU.py.

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

◆ test_clipping()

def test_rtcUHU.test_clipping ( )

Definition at line 159 of file test_rtcUHU.py.

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

◆ test_comp_voltage()

def test_rtcUHU.test_comp_voltage ( )

Definition at line 213 of file test_rtcUHU.py.

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

◆ test_disable_perturb_voltage()

def test_rtcUHU.test_disable_perturb_voltage ( )

Definition at line 192 of file test_rtcUHU.py.

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

◆ test_do_control_generic()

def test_rtcUHU.test_do_control_generic ( )

Definition at line 145 of file test_rtcUHU.py.

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

◆ test_doCentroids_bpcog()

def test_rtcUHU.test_doCentroids_bpcog ( )

Definition at line 272 of file test_rtcUHU.py.

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

◆ test_doCentroids_cog()

def test_rtcUHU.test_doCentroids_cog ( )

Definition at line 132 of file test_rtcUHU.py.

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

◆ test_doCentroids_tcog()

def test_rtcUHU.test_doCentroids_tcog ( )

Definition at line 242 of file test_rtcUHU.py.

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

◆ test_enable_perturb_voltage()

def test_rtcUHU.test_enable_perturb_voltage ( )

Definition at line 199 of file test_rtcUHU.py.

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

◆ test_initCentro_nvalid()

def test_rtcUHU.test_initCentro_nvalid ( )

Definition at line 62 of file test_rtcUHU.py.

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

◆ test_initCentro_offset()

def test_rtcUHU.test_initCentro_offset ( )

Definition at line 66 of file test_rtcUHU.py.

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

◆ test_initCentro_scale()

def test_rtcUHU.test_initCentro_scale ( )

Definition at line 70 of file test_rtcUHU.py.

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

◆ test_initCentro_type()

def test_rtcUHU.test_initCentro_type ( )

Definition at line 74 of file test_rtcUHU.py.

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

◆ test_initControl_delay()

def test_rtcUHU.test_initControl_delay ( )

Definition at line 90 of file test_rtcUHU.py.

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

◆ test_initControl_nactu()

def test_rtcUHU.test_initControl_nactu ( )

Definition at line 82 of file test_rtcUHU.py.

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

◆ test_initControl_nslope()

def test_rtcUHU.test_initControl_nslope ( )

Definition at line 78 of file test_rtcUHU.py.

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

◆ test_initControl_type()

def test_rtcUHU.test_initControl_type ( )

Definition at line 86 of file test_rtcUHU.py.

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

◆ test_load_img()

def test_rtcUHU.test_load_img ( )

Definition at line 114 of file test_rtcUHU.py.

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

◆ test_load_validposX()

def test_rtcUHU.test_load_validposX ( )

Definition at line 98 of file test_rtcUHU.py.

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

◆ test_load_validposY()

def test_rtcUHU.test_load_validposY ( )

Definition at line 102 of file test_rtcUHU.py.

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

◆ test_remove_centroider()

def test_rtcUHU.test_remove_centroider ( )

Definition at line 237 of file test_rtcUHU.py.

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

◆ test_remove_perturb_voltage()

def test_rtcUHU.test_remove_perturb_voltage ( )

Definition at line 178 of file test_rtcUHU.py.

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

◆ test_reset_perturb_voltage()

def test_rtcUHU.test_reset_perturb_voltage ( )

Definition at line 208 of file test_rtcUHU.py.

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

◆ test_set_cmat()

def test_rtcUHU.test_set_cmat ( )

Definition at line 106 of file test_rtcUHU.py.

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

◆ test_set_comRange()

def test_rtcUHU.test_set_comRange ( )

Definition at line 154 of file test_rtcUHU.py.

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

◆ test_set_dark()

def test_rtcUHU.test_set_dark ( )

Definition at line 118 of file test_rtcUHU.py.

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

◆ test_set_flat()

def test_rtcUHU.test_set_flat ( )

Definition at line 122 of file test_rtcUHU.py.

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

◆ test_set_gain()

def test_rtcUHU.test_set_gain ( )

Definition at line 110 of file test_rtcUHU.py.

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

◆ test_set_npix()

def test_rtcUHU.test_set_npix ( )

Definition at line 94 of file test_rtcUHU.py.

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

Variable Documentation

◆ centro

test_rtcUHU.centro = rtc.d_centro[0]

Definition at line 34 of file test_rtcUHU.py.

◆ cmat

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

Definition at line 40 of file test_rtcUHU.py.

◆ com

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

Definition at line 50 of file test_rtcUHU.py.

◆ config

test_rtcUHU.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_rtcUHU.py.

◆ control

test_rtcUHU.control = rtc.d_control[0]

Definition at line 35 of file test_rtcUHU.py.

◆ dark

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

Definition at line 52 of file test_rtcUHU.py.

◆ flat

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

Definition at line 53 of file test_rtcUHU.py.

◆ frame

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

Definition at line 43 of file test_rtcUHU.py.

◆ idx_centro

test_rtcUHU.idx_centro

Definition at line 32 of file test_rtcUHU.py.

◆ ncentro

test_rtcUHU.ncentro

Definition at line 33 of file test_rtcUHU.py.

◆ precision

int test_rtcUHU.precision = 1e-2

Definition at line 9 of file test_rtcUHU.py.

◆ push4imat

test_rtcUHU.push4imat

Definition at line 15 of file test_rtcUHU.py.

◆ rtc

test_rtcUHU.rtc = Rtc()

Definition at line 26 of file test_rtcUHU.py.

◆ slp

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

Definition at line 48 of file test_rtcUHU.py.

◆ sup

test_rtcUHU.sup = Supervisor(config)

Definition at line 18 of file test_rtcUHU.py.

◆ unitpervolt

test_rtcUHU.unitpervolt

Definition at line 14 of file test_rtcUHU.py.

◆ xvalid

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

Definition at line 37 of file test_rtcUHU.py.

◆ yvalid

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

Definition at line 38 of file test_rtcUHU.py.