COMPASS  5.0.0
End-to-end AO simulation tool using GPU acceleration
test_rtcFHF_pyramid.py
1 import numpy as np
2 import naga as ng
3 import os
4 from shesha.sutra_wrap import Rtc_FHF as Rtc
5 from shesha.supervisor.compassSupervisor import CompassSupervisor as Supervisor
6 from scipy.ndimage.measurements import center_of_mass
7 from shesha.util.utilities import load_config_from_file
8 
9 precision = 1e-2
10 
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)
15 
16 sup.next()
17 sup.rtc.open_loop(0)
18 sup.rtc.close_loop(0)
19 sup.rtc.do_control(0)
20 rtc = Rtc()
21 rtc.add_centroider(sup.context, sup.config.p_wfs0._nvalid, 0, sup.config.p_wfs0.pixsize, False,
22  0, "maskedpix")
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)
36 frame /= frame.max()
37 rtc.d_centro[0].load_img(frame, frame.shape[0])
38 rtc.d_centro[0].calibrate_img()
39 
40 rtc.do_centroids(0)
41 slp = ng.array(rtc.d_control[0].d_centroids)
42 rtc.do_control(0)
43 com = ng.array(rtc.d_control[0].d_com)
44 
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])
49 
50 
51 def relative_array_error(array1, array2):
52  return np.abs((array1 - array2) / array2.max()).max()
53 
54 
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
61  assert (relative_array_error(ng.array(control.d_centroids).toarray(), slopes) <
62  precision)
shesha.supervisor.compassSupervisor
Initialization and execution of a COMPASS supervisor.
Definition: compassSupervisor.py:1
shesha.sutra_wrap
Definition: sutra_wrap.py:1
shesha.util.utilities
Basic utilities function.
Definition: utilities.py:1
test_rtcFHF_pyramid.relative_array_error
def relative_array_error(array1, array2)
Definition: test_rtcFHF_pyramid.py:51
test_rtcFHF_pyramid.test_doCentroids_maskedPix
def test_doCentroids_maskedPix()
Definition: test_rtcFHF_pyramid.py:55