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 sup = Supervisor(config)
19 rtc.add_centroider(sup.context, sup.config.p_wfs0._nvalid, 0, sup.config.p_wfs0.pixsize,
20 False, 0,
"maskedpix")
21 rtc.add_controller(sup.context, sup.config.p_wfs0._nvalid,
22 sup.config.p_controller0.nslope, sup.config.p_controller0.nactu,
23 sup.config.p_controller0.delay, 0,
"generic", idx_centro=np.zeros(1), ncentro=1)
24 centro = rtc.d_centro[0]
25 control = rtc.d_control[0]
26 rtc.d_centro[0].set_npix(sup.config.p_wfs0.npix)
27 xvalid = np.array(sup.rtc.rtc.d_centro[0].d_validx)
28 yvalid = np.array(sup.rtc.rtc.d_centro[0].d_validy)
29 rtc.d_centro[0].load_validpos(xvalid, yvalid, xvalid.size)
30 cmat = sup.rtc.get_command_matrix(0)
31 rtc.d_control[0].set_cmat(cmat)
32 rtc.d_control[0].set_gain(sup.config.p_controller0.gain)
33 frame = sup.wfs.get_wfs_image(0)
35 rtc.d_centro[0].load_img(frame, frame.shape[0])
36 rtc.d_centro[0].calibrate_img()
39 slp = ng.array(rtc.d_control[0].d_centroids)
41 com = ng.array(rtc.d_control[0].d_com)
43 dark = np.random.random(frame.shape)
44 flat = np.random.random(frame.shape)
45 centro.set_dark(dark, frame.shape[0])
46 centro.set_flat(flat, frame.shape[0])
50 return np.abs((array1 - array2) / array2.max()).max()
54 binimg = np.array(centro.d_img)
55 slopes = np.zeros(xvalid.size)
56 psum = binimg[xvalid, yvalid].sum() / slopes.size
57 for k
in range(slopes.size):
58 slopes[k] = binimg[xvalid[k], yvalid[k]] / psum