COMPASS  5.0.0
End-to-end AO simulation tool using GPU acceleration
test_rtcFHF 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 = sup.wfs.get_wfs_image(0)
 
 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_rtcFHF.relative_array_error (   array1,
  array2 
)

Definition at line 52 of file test_rtcFHF.py.

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

◆ test_add_perturb()

def test_rtcFHF.test_add_perturb ( )

Definition at line 177 of file test_rtcFHF.py.

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

◆ test_add_perturb_voltage()

def test_rtcFHF.test_add_perturb_voltage ( )

Definition at line 165 of file test_rtcFHF.py.

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

◆ test_calibrate_img()

def test_rtcFHF.test_calibrate_img ( )

Definition at line 120 of file test_rtcFHF.py.

120 def test_calibrate_img():
121  centro.calibrate_img()
122  imgCal = (frame - dark) * flat
123  assert (relative_array_error(ng.array(centro.d_img).toarray(), imgCal) < precision)
124 
125 
Here is the call graph for this function:

◆ test_clipping()

def test_rtcFHF.test_clipping ( )

Definition at line 153 of file test_rtcFHF.py.

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

◆ test_comp_voltage()

def test_rtcFHF.test_comp_voltage ( )

Definition at line 208 of file test_rtcFHF.py.

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

◆ test_disable_perturb_voltage()

def test_rtcFHF.test_disable_perturb_voltage ( )

Definition at line 186 of file test_rtcFHF.py.

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

◆ test_do_control_generic()

def test_rtcFHF.test_do_control_generic ( )

Definition at line 139 of file test_rtcFHF.py.

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

◆ test_doCentroids_bpcog()

def test_rtcFHF.test_doCentroids_bpcog ( )

Definition at line 263 of file test_rtcFHF.py.

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

◆ test_doCentroids_cog()

def test_rtcFHF.test_doCentroids_cog ( )

Definition at line 126 of file test_rtcFHF.py.

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

◆ test_doCentroids_tcog()

def test_rtcFHF.test_doCentroids_tcog ( )

Definition at line 235 of file test_rtcFHF.py.

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

◆ test_enable_perturb_voltage()

def test_rtcFHF.test_enable_perturb_voltage ( )

Definition at line 194 of file test_rtcFHF.py.

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

◆ test_initCentro_nvalid()

def test_rtcFHF.test_initCentro_nvalid ( )

Definition at line 56 of file test_rtcFHF.py.

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

◆ test_initCentro_offset()

def test_rtcFHF.test_initCentro_offset ( )

Definition at line 60 of file test_rtcFHF.py.

60 def test_initCentro_offset():
61  assert (centro.offset - (sup.config.p_wfs0.npix / 2 - 0.5) < precision)
62 
63 

◆ test_initCentro_scale()

def test_rtcFHF.test_initCentro_scale ( )

Definition at line 64 of file test_rtcFHF.py.

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

◆ test_initCentro_type()

def test_rtcFHF.test_initCentro_type ( )

Definition at line 68 of file test_rtcFHF.py.

68 def test_initCentro_type():
69  assert (centro.type == "cog")
70 
71 

◆ test_initControl_delay()

def test_rtcFHF.test_initControl_delay ( )

Definition at line 84 of file test_rtcFHF.py.

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

◆ test_initControl_nactu()

def test_rtcFHF.test_initControl_nactu ( )

Definition at line 76 of file test_rtcFHF.py.

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

◆ test_initControl_nslope()

def test_rtcFHF.test_initControl_nslope ( )

Definition at line 72 of file test_rtcFHF.py.

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

◆ test_initControl_type()

def test_rtcFHF.test_initControl_type ( )

Definition at line 80 of file test_rtcFHF.py.

80 def test_initControl_type():
81  assert (control.type == "generic")
82 
83 

◆ test_load_img()

def test_rtcFHF.test_load_img ( )

Definition at line 108 of file test_rtcFHF.py.

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

◆ test_load_validposX()

def test_rtcFHF.test_load_validposX ( )

Definition at line 92 of file test_rtcFHF.py.

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

◆ test_load_validposY()

def test_rtcFHF.test_load_validposY ( )

Definition at line 96 of file test_rtcFHF.py.

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

◆ test_remove_centroider()

def test_rtcFHF.test_remove_centroider ( )

Definition at line 230 of file test_rtcFHF.py.

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

◆ test_remove_perturb_voltage()

def test_rtcFHF.test_remove_perturb_voltage ( )

Definition at line 172 of file test_rtcFHF.py.

172 def test_remove_perturb_voltage():
173  control.remove_perturb_voltage("test")
174  assert (control.d_perturb_map == {})
175 
176 

◆ test_reset_perturb_voltage()

def test_rtcFHF.test_reset_perturb_voltage ( )

Definition at line 203 of file test_rtcFHF.py.

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

◆ test_set_cmat()

def test_rtcFHF.test_set_cmat ( )

Definition at line 100 of file test_rtcFHF.py.

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

◆ test_set_comRange()

def test_rtcFHF.test_set_comRange ( )

Definition at line 148 of file test_rtcFHF.py.

148 def test_set_comRange():
149  control.set_comRange(-1, 1)
150  assert (control.comRange == (-1, 1))
151 
152 

◆ test_set_dark()

def test_rtcFHF.test_set_dark ( )

Definition at line 112 of file test_rtcFHF.py.

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

◆ test_set_flat()

def test_rtcFHF.test_set_flat ( )

Definition at line 116 of file test_rtcFHF.py.

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

◆ test_set_gain()

def test_rtcFHF.test_set_gain ( )

Definition at line 104 of file test_rtcFHF.py.

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

◆ test_set_npix()

def test_rtcFHF.test_set_npix ( )

Definition at line 88 of file test_rtcFHF.py.

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

Variable Documentation

◆ centro

test_rtcFHF.centro = rtc.d_centro[0]

Definition at line 27 of file test_rtcFHF.py.

◆ cmat

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

Definition at line 33 of file test_rtcFHF.py.

◆ com

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

Definition at line 44 of file test_rtcFHF.py.

◆ config

test_rtcFHF.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_rtcFHF.py.

◆ control

test_rtcFHF.control = rtc.d_control[0]

Definition at line 28 of file test_rtcFHF.py.

◆ dark

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

Definition at line 46 of file test_rtcFHF.py.

◆ flat

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

Definition at line 47 of file test_rtcFHF.py.

◆ frame

test_rtcFHF.frame = sup.wfs.get_wfs_image(0)

Definition at line 36 of file test_rtcFHF.py.

◆ idx_centro

test_rtcFHF.idx_centro

Definition at line 25 of file test_rtcFHF.py.

◆ ncentro

test_rtcFHF.ncentro

Definition at line 26 of file test_rtcFHF.py.

◆ precision

int test_rtcFHF.precision = 1e-2

Definition at line 9 of file test_rtcFHF.py.

◆ rtc

test_rtcFHF.rtc = Rtc()

Definition at line 19 of file test_rtcFHF.py.

◆ slp

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

Definition at line 42 of file test_rtcFHF.py.

◆ sup

test_rtcFHF.sup = Supervisor(config)

Definition at line 14 of file test_rtcFHF.py.

◆ xvalid

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

Definition at line 30 of file test_rtcFHF.py.

◆ yvalid

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

Definition at line 31 of file test_rtcFHF.py.