COMPASS  5.0.0
End-to-end AO simulation tool using GPU acceleration
testNoise.py
1 from tqdm import trange
2 import matplotlib.pyplot as plt
3 plt.ion()
4 
5 
6 def testNoise(noise=0.9, niter=100, close_loop=True):
7 
8  s1 = np.zeros(((niter, int(wao.sim.config.p_controller0.nvalid * 2))))
9  s2 = np.zeros(((niter, int(wao.sim.config.p_controller0.nvalid * 2))))
10  sub1 = np.zeros(((niter, int(wao.sim.config.p_controller0.nvalid))))
11  sub2 = np.zeros(((niter, int(wao.sim.config.p_controller0.nvalid))))
12  dimim = wao.sim.wfs.get_pyrimg(0).shape[0]
13  dimimHR = wao.sim.wfs.get_pyrimghr(0).shape[0]
14  dimscreen = wao.sim.atm.get_screen(0).shape[0]
15  im1 = np.zeros(((niter, dimim, dimim)))
16  im2 = np.zeros(((niter, dimim, dimim)))
17  #im1HR = np.zeros(((niter, dimimHR,dimimHR)))
18  #im2HR = np.zeros(((niter, dimimHR,dimimHR)))
19  screen1 = np.zeros(((niter, dimscreen, dimscreen)))
20  screen2 = np.zeros(((niter, dimscreen, dimscreen)))
21 
22  wao.sim.rtc.set_open_loop(0, 1)
23  wao.sim.atm.set_seed(0, 1234)
24  wao.sim.atm.refresh_screen(0)
25  wao.sim.wfs.set_noise(0, noise)
26  wao.sim.dms.resetdm(b"pzt", 0.)
27  wao.sim.dms.resetdm(b"tt", 0.)
28  if close_loop:
29  wao.sim.rtc.set_open_loop(0, 0)
30  #s1, v1, t1, aiData1, psfLE1 = wao.record_ao_circular_buffer(niter)
31 
32  for k in trange(niter):
33  wao.sim.next()
34  s1[k, :] = wao.sim.rtc.get_centroids(0)
35  sub1[k, :] = wao.sim.rtc.get_intensities(0)
36 
37  im1[k, :, :] = wao.sim.wfs.get_pyrimg(0)
38  # im1HR[k,:,:] = wao.sim.wfs.get_pyrimghr(0)
39  screen1[k, :, :] = wao.sim.atm.get_screen(0)
40  wao.sim.rtc.set_open_loop(0, 1)
41  wao.sim.atm.set_seed(0, 1234)
42  wao.sim.atm.refresh_screen(0)
43  wao.sim.wfs.set_noise(0, noise)
44  wao.sim.dms.resetdm(b"pzt", 0.)
45  wao.sim.dms.resetdm(b"tt", 0.)
46  if close_loop:
47  wao.sim.rtc.set_open_loop(0, 0)
48  #s2, v2, t2, aiData2, psfLE2 = wao.record_ao_circular_buffer(niter)
49 
50  for k in trange(niter):
51  wao.sim.next()
52  s2[k, :] = wao.sim.rtc.get_centroids(0)
53  sub2[k, :] = wao.sim.rtc.get_intensities(0)
54  im2[k, :, :] = wao.sim.wfs.get_pyrimg(0)
55  screen2[k, :, :] = wao.sim.atm.get_screen(0)
56  # im2HR[k,:,:] = wao.sim.wfs.get_pyrimghr(0)
57 
58  screenErr = np.abs(screen2 - screen1).max() / screen1.max()
59  imagesErr = np.abs(im2 - im1).max() / im1.max()
60  subErr = np.abs(sub2 - sub1).max() / sub1.max()
61  # imagesHRErr = np.abs(im2HR-im1HR).max()/im1HR.max()
62  imagesHRErr = 0.
63  slopesErr = np.abs(s2 - s1).max() / s1.max()
64  print("Screen Error =" + str(screenErr))
65  # print("Images HR Error ="+str(imagesHRErr))
66  print("Images Error =" + str(imagesErr))
67  print("Slopes Error =" + str(slopesErr))
68  print("Subsum Error =" + str(subErr))
69 
70  #print(np.abs(psfLE2-psfLE1).max())
71  #print(psfLE1.max())
72  #print(psfLE2.max())
73  return screenErr, imagesErr, imagesHRErr, slopesErr, subErr
74  #plt.figure(1)
75  #plt.clf()
76  #plt.matshow(s2-s1, aspect="auto", fignum=1)
77 
78 
79 #plt.matshow(im2[-1,:,:]-im1[-1,:,:], aspect="auto", fignum=2)
80 
81 errscreenList = []
82 imagesErrList = []
83 imagesHRErrList = []
84 slopesErrList = []
85 subErrList = []
86 for i in range(5):
87  errscreen, imagesErr, imagesHRErr, slopesErr, subErr = testNoise(0.5, 200, True)
88  errscreenList.append(errscreen)
89  imagesErrList.append(imagesErr)
90  imagesHRErrList.append(imagesHRErr)
91  slopesErrList.append(slopesErr)
92  subErrList.append(subErr)
93 
94 plt.figure(1)
95 plt.clf()
96 plt.plot(errscreenList)
97 plt.title("Screen Error")
98 
99 plt.figure(2)
100 plt.clf()
101 plt.plot(imagesErrList)
102 plt.title("images Error")
103 
104 plt.figure(3)
105 plt.clf()
106 plt.plot(slopesErrList)
107 plt.title("slopes Error")
108 
109 plt.figure(4)
110 plt.clf()
111 plt.plot(imagesHRErrList)
112 plt.title("images HR Error")
shesha.widgets.testNoise.testNoise
def testNoise(noise=0.9, niter=100, close_loop=True)
Definition: testNoise.py:6