COMPASS  5.0.0
End-to-end AO simulation tool using GPU acceleration
debug_pyr.py
1 import cProfile
2 import pstats as ps
3 
4 import sys
5 import os
6 import numpy as np
7 import carmaWrap as ch
8 import shesha as ao
9 import time
10 import matplotlib.pyplot as pl
11 import hdf5_util as h5u
12 
13 print("TEST SHESHA\n closed loop: call loop(int niter)")
14 
15 if (len(sys.argv) != 2):
16  error = 'command line should be:"python -i test.py parameters_filename"\n with "parameters_filename" the path to the parameters file'
17  raise Exception(error)
18 
19 # get parameters from file
20 param_file = sys.argv[1]
21 if (param_file.split('.')[-1] == b"py"):
22  filename = param_file.split('/')[-1]
23  param_path = param_file.split(filename)[0]
24  sys.path.insert(0, param_path)
25  exec("import %s as config" % filename.split(".py")[0])
26  sys.path.remove(param_path)
27 elif (param_file.split('.')[-1] == b"h5"):
28  sys.path.insert(0, os.environ["SHESHA_ROOT"] + "/data/par/par4bench/")
29  import scao_sh_16x16_8pix as config
30  sys.path.remove(os.environ["SHESHA_ROOT"] + "/data/par/par4bench/")
31  h5u.configFromH5(param_file, config)
32 else:
33  raise ValueError("Parameter file extension must be .py or .h5")
34 
35 print("param_file is", param_file)
36 
37 if (hasattr(config, "simul_name")):
38  if (config.simul_name is None):
39  simul_name = ""
40  else:
41  simul_name = config.simul_name
42  print("simul name is", simul_name)
43 else:
44  simul_name = ""
45 
46 matricesToLoad = {}
47 if (simul_name == b""):
48  clean = 1
49 else:
50  clean = 0
51  param_dict = h5u.params_dictionary(config)
52  matricesToLoad = h5u.checkMatricesDataBase(os.environ["SHESHA_ROOT"] + "/data/",
53  config, param_dict)
54 # initialisation:
55 # context
56 c = ch.carmaWrap_context(0)
57 # c.set_active_device(0) #useful only if you use ch.carmaWrap_context()
58 
59 # wfs
60 config.p_wfs0.set_atmos_seen(0)
61 config.p_wfs0.set_pyr_ampl(3)
62 
63 # dm
64 config.p_dm1 = ao.Param_dm()
65 config.p_dms = [config.p_dm1]
66 config.p_dm1.set_type("tt")
67 config.p_dm1.set_alt(0.)
68 config.p_dm1.set_unitpervolt(1.)
69 lambda_d = 1. #config.p_wfs0.Lambda / config.p_tel.diam * 180 / np.pi * 3600
70 config.p_dm1.set_push4imat(2. * lambda_d)
71 
72 # controllers
73 config.p_controller0.set_ndm([0])
74 
75 import matplotlib.pyplot as plt
76 plt.ion()
77 npts = 16
78 index = 1
79 while npts <= 512:
80  config.p_wfs0.set_pyr_npts(npts)
81  # wfs
82  print("->wfs")
83  wfs, tel = ao.wfs_init(config.p_wfss, config.p_atmos, config.p_tel, config.p_geom,
84  config.p_target, config.p_loop, config.p_dms)
85 
86  # dm
87  print("->dm")
88  dms = ao.dm_init(config.p_dms, config.p_wfss, wfs, config.p_geom, config.p_tel)
89 
90  print("->rtc")
91  # rtc
92  rtc = ao.rtc_init(tel, wfs, config.p_wfss, dms, config.p_dms, config.p_geom,
93  config.p_rtc, None, None, config.p_tel, config.p_loop, clean=clean,
94  simul_name=simul_name, load=matricesToLoad)
95 
96  if not clean:
97  h5u.validDataBase(os.environ["SHESHA_ROOT"] + "/data/", matricesToLoad)
98 
99  print("====================")
100  print("init done")
101  print("====================")
102  print("objects initialzed on GPU:")
103  print("--------------------------------------------------------")
104  print(wfs)
105  print(dms)
106  print(rtc)
107 
108  imat = rtc.get_imat(0)
109 
110  plt.subplot(2, 3, index)
111  plt.plot(imat[:, -1], label="Tip")
112  plt.plot(imat[:, -2], label="Tilt")
113  plt.legend()
114  plt.title("%s_npts%d_ampl%.2f" % (param_file, config.p_wfs0.pyr_npts,
115  config.p_wfs0.pyr_ampl))
116  npts <<= 1
117  index += 1