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

Definition at line 59 of file test_rtcFHU.py.

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

◆ test_add_perturb()

def test_rtcFHU.test_add_perturb ( )

Definition at line 184 of file test_rtcFHU.py.

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

◆ test_add_perturb_voltage()

def test_rtcFHU.test_add_perturb_voltage ( )

Definition at line 172 of file test_rtcFHU.py.

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

◆ test_calibrate_img()

def test_rtcFHU.test_calibrate_img ( )

Definition at line 127 of file test_rtcFHU.py.

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

◆ test_clipping()

def test_rtcFHU.test_clipping ( )

Definition at line 160 of file test_rtcFHU.py.

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

◆ test_comp_voltage()

def test_rtcFHU.test_comp_voltage ( )

Definition at line 214 of file test_rtcFHU.py.

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

◆ test_disable_perturb_voltage()

def test_rtcFHU.test_disable_perturb_voltage ( )

Definition at line 193 of file test_rtcFHU.py.

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

◆ test_do_control_generic()

def test_rtcFHU.test_do_control_generic ( )

Definition at line 146 of file test_rtcFHU.py.

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

◆ test_doCentroids_bpcog()

def test_rtcFHU.test_doCentroids_bpcog ( )

Definition at line 273 of file test_rtcFHU.py.

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

◆ test_doCentroids_cog()

def test_rtcFHU.test_doCentroids_cog ( )

Definition at line 133 of file test_rtcFHU.py.

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

◆ test_doCentroids_tcog()

def test_rtcFHU.test_doCentroids_tcog ( )

Definition at line 243 of file test_rtcFHU.py.

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

◆ test_enable_perturb_voltage()

def test_rtcFHU.test_enable_perturb_voltage ( )

Definition at line 200 of file test_rtcFHU.py.

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

◆ test_initCentro_nvalid()

def test_rtcFHU.test_initCentro_nvalid ( )

Definition at line 63 of file test_rtcFHU.py.

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

◆ test_initCentro_offset()

def test_rtcFHU.test_initCentro_offset ( )

Definition at line 67 of file test_rtcFHU.py.

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

◆ test_initCentro_scale()

def test_rtcFHU.test_initCentro_scale ( )

Definition at line 71 of file test_rtcFHU.py.

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

◆ test_initCentro_type()

def test_rtcFHU.test_initCentro_type ( )

Definition at line 75 of file test_rtcFHU.py.

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

◆ test_initControl_delay()

def test_rtcFHU.test_initControl_delay ( )

Definition at line 91 of file test_rtcFHU.py.

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

◆ test_initControl_nactu()

def test_rtcFHU.test_initControl_nactu ( )

Definition at line 83 of file test_rtcFHU.py.

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

◆ test_initControl_nslope()

def test_rtcFHU.test_initControl_nslope ( )

Definition at line 79 of file test_rtcFHU.py.

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

◆ test_initControl_type()

def test_rtcFHU.test_initControl_type ( )

Definition at line 87 of file test_rtcFHU.py.

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

◆ test_load_img()

def test_rtcFHU.test_load_img ( )

Definition at line 115 of file test_rtcFHU.py.

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

◆ test_load_validposX()

def test_rtcFHU.test_load_validposX ( )

Definition at line 99 of file test_rtcFHU.py.

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

◆ test_load_validposY()

def test_rtcFHU.test_load_validposY ( )

Definition at line 103 of file test_rtcFHU.py.

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

◆ test_remove_centroider()

def test_rtcFHU.test_remove_centroider ( )

Definition at line 238 of file test_rtcFHU.py.

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

◆ test_remove_perturb_voltage()

def test_rtcFHU.test_remove_perturb_voltage ( )

Definition at line 179 of file test_rtcFHU.py.

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

◆ test_reset_perturb_voltage()

def test_rtcFHU.test_reset_perturb_voltage ( )

Definition at line 209 of file test_rtcFHU.py.

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

◆ test_set_cmat()

def test_rtcFHU.test_set_cmat ( )

Definition at line 107 of file test_rtcFHU.py.

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

◆ test_set_comRange()

def test_rtcFHU.test_set_comRange ( )

Definition at line 155 of file test_rtcFHU.py.

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

◆ test_set_dark()

def test_rtcFHU.test_set_dark ( )

Definition at line 119 of file test_rtcFHU.py.

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

◆ test_set_flat()

def test_rtcFHU.test_set_flat ( )

Definition at line 123 of file test_rtcFHU.py.

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

◆ test_set_gain()

def test_rtcFHU.test_set_gain ( )

Definition at line 111 of file test_rtcFHU.py.

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

◆ test_set_npix()

def test_rtcFHU.test_set_npix ( )

Definition at line 95 of file test_rtcFHU.py.

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

Variable Documentation

◆ centro

test_rtcFHU.centro = rtc.d_centro[0]

Definition at line 35 of file test_rtcFHU.py.

◆ cmat

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

Definition at line 41 of file test_rtcFHU.py.

◆ com

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

Definition at line 51 of file test_rtcFHU.py.

◆ config

test_rtcFHU.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_rtcFHU.py.

◆ control

test_rtcFHU.control = rtc.d_control[0]

Definition at line 36 of file test_rtcFHU.py.

◆ dark

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

Definition at line 53 of file test_rtcFHU.py.

◆ flat

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

Definition at line 54 of file test_rtcFHU.py.

◆ frame

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

Definition at line 44 of file test_rtcFHU.py.

◆ idx_centro

test_rtcFHU.idx_centro

Definition at line 33 of file test_rtcFHU.py.

◆ ncentro

test_rtcFHU.ncentro

Definition at line 34 of file test_rtcFHU.py.

◆ precision

int test_rtcFHU.precision = 1e-2

Definition at line 9 of file test_rtcFHU.py.

◆ push4imat

test_rtcFHU.push4imat

Definition at line 15 of file test_rtcFHU.py.

◆ rtc

test_rtcFHU.rtc = Rtc()

Definition at line 27 of file test_rtcFHU.py.

◆ slp

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

Definition at line 49 of file test_rtcFHU.py.

◆ sup

test_rtcFHU.sup = Supervisor(config)

Definition at line 18 of file test_rtcFHU.py.

◆ unitpervolt

test_rtcFHU.unitpervolt

Definition at line 14 of file test_rtcFHU.py.

◆ xvalid

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

Definition at line 38 of file test_rtcFHU.py.

◆ yvalid

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

Definition at line 39 of file test_rtcFHU.py.