COMPASS  5.0.0
End-to-end AO simulation tool using GPU acceleration
test_rtc_standalone_pyr.py
1 """script to test rtc_standalone feature
2 
3 Usage:
4  test_rtc_standalone <parameters_filename> [options]
5 
6 with 'parameters_filename' the path to the parameters file
7 
8 Options:
9  -h --help Show this help message and exit
10  -d, --devices devices Specify the devices
11 """
12 
13 from docopt import docopt
14 from tqdm import tqdm
15 
16 from carmaWrap import threadSync
17 import numpy as np
18 import shesha.sim
19 import shesha.init
20 from shesha.constants import CONST
21 import time
22 import matplotlib.pyplot as plt
23 plt.ion()
24 
25 arguments = docopt(__doc__)
26 param_file = arguments["<parameters_filename>"]
27 
28 # Get parameters from file
29 sim = shesha_sim.Simulator(param_file)
30 sim.config.p_loop.set_niter(100)
31 
32 if arguments["--devices"]:
33  devices = []
34  for k in range(len(arguments["--devices"])):
35  devices.append(int(arguments["--devices"][k]))
36  sim.config.p_loop.set_devices(devices)
37 
38 sim.init_sim()
39 nactu = sim.config.p_controller0.nactu
40 nvalid = sim.config.p_controller0.nvalid
41 offset = 0
42 p_wfs = sim.config.p_wfs0
43 p_centroider = sim.config.p_centroider0
44 scale = (p_wfs.Lambda * 1e-6 / sim.config.p_tel.diam) * \
45  p_wfs.pyr_ampl * CONST.RAD2ARCSEC
46 
47 rtc_standalone = shesha_init.rtc_standalone(sim.c, len(sim.config.p_wfss), nvalid, nactu,
48  sim.config.p_centroider0.type,
49  sim.config.p_controller0.delay, offset,
50  scale)
51 rtc_standalone.set_cmat(0, sim.rtc.get_cmat(0))
52 rtc_standalone.set_decayFactor(0, np.ones(nactu, dtype=np.float32))
53 rtc_standalone.set_matE(0, np.identity(nactu, dtype=np.float32))
54 rtc_standalone.set_modal_gains(
55  0,
56  np.ones(nactu, dtype=np.float32) * sim.config.p_controller0.gain)
57 
58 s_ref = np.zeros((sim.config.p_loop.niter, 2 * nvalid.sum()), dtype=np.float32)
59 s = s_ref.copy()
60 c = np.zeros((sim.config.p_loop.niter, nactu), dtype=np.float32)
61 c_ref = c.copy()
62 img = sim.wfs.get_pyrimg(0)
63 img = np.zeros((sim.config.p_loop.niter, img.shape[0], img.shape[1]), dtype=np.float32)
64 
65 for k in tqdm(range(sim.config.p_loop.niter)):
66  sim.next()
67  img[k, :, :] = sim.wfs.get_pyrimg(0)
68  s_ref[k, :] = sim.rtc.get_centroids(0)
69  c_ref[k, :] = sim.rtc.get_com(0)
70 
71 rtc_standalone.load_rtc_validpos(0, sim.config.p_wfs0._validsubsy,
72  sim.config.p_wfs0._validsubsx)
73 rtc_standalone.set_open_loop(0, 1)
74 rtc_standalone.set_open_loop(0, 0)
75 
76 rtc_time = 0
77 for k in tqdm(range(sim.config.p_loop.niter)):
78  rtc_standalone.load_rtc_pyrimg(0, img[k, :, :].copy())
79  a = time.time()
80  rtc_standalone.do_centroids(0)
81  threadSync()
82  rtc_standalone.do_control(0)
83  threadSync()
84  rtc_standalone.save_com(0)
85  rtc_time += (time.time() - a)
86  s[k, :] = rtc_standalone.get_centroids(0)
87  c[k, :] = rtc_standalone.get_com(0)
88 
89 print("RTC speed : ", 1 / (rtc_time / sim.config.p_loop.niter), " fps")
shesha.constants
Numerical constants for shesha and config enumerations for safe-typing.
Definition: constants.py:1
shesha.init
Python package for COMPASS simulation initialization.
Definition: shesha/shesha/init/__init__.py:1