6 from scipy.ndimage.measurements
import center_of_mass
11 config = load_config_from_file(os.getenv(
"COMPASS_ROOT") +
12 "/shesha/tests/pytest/par/test_pyrhr.py")
13 config.p_controller0.set_delay(0.0)
14 sup = Supervisor(config)
21 rtc.add_centroider(sup.context, sup.config.p_wfs0._nvalid, 0, sup.config.p_wfs0.pixsize,
False,
23 rtc.add_controller(sup.context, sup.config.p_wfs0._nvalid,
24 sup.config.p_controller0.nslope, sup.config.p_controller0.nactu,
25 sup.config.p_controller0.delay, 0,
"generic", idx_centro=np.zeros(1), ncentro=1)
26 centro = rtc.d_centro[0]
27 control = rtc.d_control[0]
28 rtc.d_centro[0].set_npix(sup.config.p_wfs0.npix)
29 xvalid = np.array(sup.rtc.rtc.d_centro[0].d_validx)
30 yvalid = np.array(sup.rtc.rtc.d_centro[0].d_validy)
31 rtc.d_centro[0].load_validpos(xvalid, yvalid, xvalid.size)
32 cmat = sup.rtc.get_command_matrix(0)
33 rtc.d_control[0].set_cmat(cmat)
34 rtc.d_control[0].set_gain(sup.config.p_controller0.gain)
35 frame = sup.wfs.get_wfs_image(0)
37 rtc.d_centro[0].load_img(frame, frame.shape[0])
38 rtc.d_centro[0].calibrate_img()
41 slp = ng.array(rtc.d_control[0].d_centroids)
43 com = ng.array(rtc.d_control[0].d_com)
45 dark = np.random.random(frame.shape)
46 flat = np.random.random(frame.shape)
47 centro.set_dark(dark, frame.shape[0])
48 centro.set_flat(flat, frame.shape[0])
52 return np.abs((array1 - array2) / array2.max()).max()
56 binimg = np.array(centro.d_img)
57 slopes = np.zeros(xvalid.size)
58 psum = binimg[xvalid, yvalid].sum() / slopes.size
59 for k
in range(slopes.size):
60 slopes[k] = binimg[xvalid[k], yvalid[k]] / psum