COMPASS  5.0.0
End-to-end AO simulation tool using GPU acceleration
script_SH39m Namespace Reference

Functions

def makeFITSHeader (filepath, df)
 
def initSimu (config, c)
 
def loop (n, wfs, tel, atm, dms, tar, rtc)
 

Variables

string simulName = "SH_39m"
 
string pathResults = "/volumes/hra/micado/RunSH39m_RoundPupil/"
 
string dBResult = "SH39m_RoundPupil.h5"
 
string error = 'command line should be:"python -i test.py parameters_filename"\n with "parameters_filename" the path to the parameters file'
 
list freqs = [500.]
 
list npixs = [8]
 
list pixsizes = [1]
 
list gainslist = [0.3]
 
list bps = [10]
 
list magnitudes = [11, 12, 13, 14, 15, 16]
 
list RONS = [2, 10]
 
int nKL_Filt = 450
 
 param_file = sys.argv[1]
 
 filename = param_file.split('/')[-1]
 
 param_path = param_file.split(filename)[0]
 
string simul_name = ""
 
dictionary matricesToLoad = {}
 
int clean = 1
 
 param_dict = h5u.params_dictionary(config)
 
 c = ch.carmaWrap_context(devices=np.array([0, 1, 2, 3], dtype=np.int32))
 
int mimg = 0.
 
list SR = []
 
 colnames = h5u.params_dictionary(config)
 
dictionary simunames
 
 resAll
 
 Nsimutot
 
int NCurrSim = 0
 
float pxsize
 
 res
 
 wfs
 
 tel
 
 atm
 
 dms
 
 tar
 
 rtc
 
int nfilt = nKL_Filt
 
 cmat
 
 lambdaTargetList
 
 sr_le
 
 sr_se
 
 numiter
 
 dfparams
 
list PSFNameList = []
 
 PSFtarget = tar.get_image(t, "le")
 
 date = time.strftime("_%d-%m-%Y_%H:%M:%S_")
 
string lam = "%3.2f" % tar.Lambda.tolist()[t]
 
string PSFName = "SH_" + lam + "_" + date + ".fits"
 
 clobber
 
string lam2 = "%3.2f" % tar.Lambda.tolist()[t]
 
string filepath = pathResults + "PSFs/" + PSFName
 
 hdulist = pf.open(filepath)
 
 header = hdulist[0].header
 
 complevel
 
 complib
 

Function Documentation

◆ initSimu()

def script_SH39m.initSimu (   config,
  c 
)

Definition at line 127 of file script_SH39m.py.

127 def initSimu(config, c):
128  # wfs
129  param_dict = h5u.params_dictionary(config)
130  matricesToLoad = h5u.checkMatricesDataBase(os.environ["SHESHA_ROOT"] + "/data/",
131  config, param_dict)
132  print("->wfs")
133  wfs, tel = ao.wfs_init(config.p_wfss, config.p_atmos, config.p_tel, config.p_geom,
134  config.p_target, config.p_loop, config.p_dms)
135  # atmos
136  print("->atmos")
137  atm = ao.atmos_init(c, config.p_atmos, config.p_tel, config.p_geom, config.p_loop,
138  config.p_wfss, wfs, config.p_target, rank=0, clean=clean,
139  load=matricesToLoad)
140 
141  # dm
142  print("->dm")
143  dms = ao.dm_init(config.p_dms, config.p_wfss, wfs, config.p_geom, config.p_tel)
144 
145  # target
146  print("->target")
147  tar = ao.target_init(c, tel, config.p_target, config.p_atmos, config.p_geom,
148  config.p_tel, config.p_dms)
149 
150  print("->rtc")
151  # rtc
152  rtc = ao.rtc_init(tel, wfs, config.p_wfss, dms, config.p_dms, config.p_geom,
153  config.p_rtc, config.p_atmos, atm, config.p_tel, config.p_loop,
154  do_refslp=False, clean=clean, simul_name=simul_name,
155  load=matricesToLoad)
156 
157  h5u.validDataBase(os.environ["SHESHA_ROOT"] + "/data/", matricesToLoad)
158 
159  print("====================")
160  print("init done")
161  print("====================")
162  print("objects initialzed on GPU:")
163  print("--------------------------------------------------------")
164  print(atm)
165  print(wfs)
166  print(dms)
167  print(tar)
168  print(rtc)
169  return wfs, tel, atm, dms, tar, rtc
170 
171 

◆ loop()

def script_SH39m.loop (   n,
  wfs,
  tel,
  atm,
  dms,
  tar,
  rtc 
)

Definition at line 172 of file script_SH39m.py.

172 def loop(n, wfs, tel, atm, dms, tar, rtc):
173  t0 = time.time()
174  print("----------------------------------------------------")
175  print("iter# | S.E. SR | L.E. SR | Est. Rem. | framerate")
176  print("----------------------------------------------------")
177  sr_se = []
178  sr_le = []
179  numiter = []
180  for i in range(n):
181  atm.move_atmos()
182 
183  if (config.p_controllers[0].type == b"geo"):
184  for t in range(config.p_target.ntargets):
185  tar.atmos_trace(t, atm, tel)
186  rtc.do_control_geo(0, dms, tar, 0)
187  rtc.apply_control(0)
188  tar.dmtrace(0, dms)
189  else:
190  for t in range(config.p_target.ntargets):
191  tar.atmos_trace(t, atm, tel)
192  tar.dmtrace(t, dms)
193  for w in range(len(config.p_wfss)):
194  wfs.raytrace(w, "all", tel, atm, dms)
195  wfs.sensors_compimg(w)
196 
197  rtc.do_centroids(0)
198  rtc.docontrol(0)
199  rtc.apply_control(0)
200 
201  if ((i + 1) % 100 == 0):
202  print("Iter#:", i + 1)
203  #for t in range(config.p_target.ntargets):
204  t = 1
205  SR = tar.get_strehl(t)
206  print("Tar %d at %3.2fMicrons:" % (t + 1, tar.Lambda[t]))
207  signal_se = "SR S.E: %1.2f " % SR[0]
208  signal_le = "SR L.E: %1.2f " % SR[1]
209 
210  print(signal_se + signal_le)
211  #print(i+1,"\t",,SR[0],"\t",SR[1])
212  sr_le.append(SR[1])
213  sr_se.append(SR[0])
214  numiter.append(i + 1)
215 
216 
217 #
218 # plt.pause(0.01)
219 # plt.scatter(numiter, sr_le, color="green", label="Long Exposure")
220 # plt.plot(numiter, sr_le, color="green")
221 # plt.scatter(numiter, sr_se, color="red", label="Short Exposure")
222 # plt.plot(numiter, sr_se, color="red")
223 
224  t1 = time.time()
225  print(" loop execution time:", t1 - t0, " (", n, "iterations), ", (t1 - t0) / n,
226  "(mean) ", n / (t1 - t0), "Hz")
227  SRList = []
228  for t in range(config.p_target.ntargets):
229  SR = tar.get_strehl(t)
230  SRList.append(SR[1]) # Saving Long Exp SR
231  return SRList, tar.Lambda.tolist(), sr_le, sr_se, numiter
232 

◆ makeFITSHeader()

def script_SH39m.makeFITSHeader (   filepath,
  df 
)

Definition at line 107 of file script_SH39m.py.

107 def makeFITSHeader(filepath, df):
108  hdulist = pf.open(filepath) # read file
109  header = hdulist[0].header
110  names = np.sort(list(set(df))).tolist()
111  for name in names:
112  val = df[name][0]
113  if (type(val) is list):
114  value = ""
115  for v in val:
116  value += (str(v) + " ")
117  elif (type(val) is np.ndarray):
118  value = ""
119  for v in val:
120  value += (str(v) + " ")
121  else:
122  value = val
123  header.set(name, value, '')
124  hdulist.writeto(filepath, clobber=True) # Save changes to file
125 
126 

Variable Documentation

◆ atm

script_SH39m.atm

Definition at line 314 of file script_SH39m.py.

◆ bps

list script_SH39m.bps = [10]

Definition at line 40 of file script_SH39m.py.

◆ c

script_SH39m.c = ch.carmaWrap_context(devices=np.array([0, 1, 2, 3], dtype=np.int32))

Definition at line 102 of file script_SH39m.py.

◆ clean

int script_SH39m.clean = 1

Definition at line 94 of file script_SH39m.py.

◆ clobber

script_SH39m.clobber

Definition at line 361 of file script_SH39m.py.

◆ cmat

script_SH39m.cmat
Initial value:
1 = ao.compute_cmatWithKL(rtc, config.p_controllers[0],
2  dms, config.p_dms,
3  config.p_geom, config.p_atmos,
4  config.p_tel, nfilt)

Definition at line 317 of file script_SH39m.py.

◆ colnames

script_SH39m.colnames = h5u.params_dictionary(config)

Definition at line 244 of file script_SH39m.py.

◆ complevel

script_SH39m.complevel

Definition at line 383 of file script_SH39m.py.

◆ complib

script_SH39m.complib

Definition at line 384 of file script_SH39m.py.

◆ date

script_SH39m.date = time.strftime("_%d-%m-%Y_%H:%M:%S_")

Definition at line 354 of file script_SH39m.py.

◆ dBResult

string script_SH39m.dBResult = "SH39m_RoundPupil.h5"

Definition at line 23 of file script_SH39m.py.

◆ dfparams

script_SH39m.dfparams
Initial value:
1 = h5u.params_dictionary(
2  config)

Definition at line 326 of file script_SH39m.py.

◆ dms

script_SH39m.dms

Definition at line 314 of file script_SH39m.py.

◆ error

string script_SH39m.error = 'command line should be:"python -i test.py parameters_filename"\n with "parameters_filename" the path to the parameters file'

Definition at line 27 of file script_SH39m.py.

◆ filename

script_SH39m.filename = param_file.split('/')[-1]

Definition at line 68 of file script_SH39m.py.

◆ filepath

string script_SH39m.filepath = pathResults + "PSFs/" + PSFName

Definition at line 364 of file script_SH39m.py.

◆ freqs

list script_SH39m.freqs = [500.]

Definition at line 36 of file script_SH39m.py.

◆ gainslist

list script_SH39m.gainslist = [0.3]

Definition at line 39 of file script_SH39m.py.

◆ hdulist

script_SH39m.hdulist = pf.open(filepath)

Definition at line 367 of file script_SH39m.py.

◆ header

script_SH39m.header = hdulist[0].header

Definition at line 368 of file script_SH39m.py.

◆ lam

string script_SH39m.lam = "%3.2f" % tar.Lambda.tolist()[t]

Definition at line 355 of file script_SH39m.py.

◆ lam2

string script_SH39m.lam2 = "%3.2f" % tar.Lambda.tolist()[t]

Definition at line 362 of file script_SH39m.py.

◆ lambdaTargetList

script_SH39m.lambdaTargetList

Definition at line 324 of file script_SH39m.py.

◆ magnitudes

list script_SH39m.magnitudes = [11, 12, 13, 14, 15, 16]

Definition at line 41 of file script_SH39m.py.

◆ matricesToLoad

script_SH39m.matricesToLoad = {}

Definition at line 92 of file script_SH39m.py.

◆ mimg

int script_SH39m.mimg = 0.

Definition at line 233 of file script_SH39m.py.

◆ NCurrSim

int script_SH39m.NCurrSim = 0

Definition at line 284 of file script_SH39m.py.

◆ nfilt

int script_SH39m.nfilt = nKL_Filt

Definition at line 316 of file script_SH39m.py.

◆ nKL_Filt

script_SH39m.nKL_Filt = 450

Definition at line 43 of file script_SH39m.py.

◆ npixs

list script_SH39m.npixs = [8]

Definition at line 37 of file script_SH39m.py.

◆ Nsimutot

script_SH39m.Nsimutot
Initial value:
1 = len(gainslist) * len(magnitudes) * len(bps) * len(RONS) * len(pixsizes) * len(
2  npixs) * len(freqs)

Definition at line 282 of file script_SH39m.py.

◆ numiter

script_SH39m.numiter

Definition at line 324 of file script_SH39m.py.

◆ param_dict

script_SH39m.param_dict = h5u.params_dictionary(config)

Definition at line 97 of file script_SH39m.py.

◆ param_file

script_SH39m.param_file = sys.argv[1]

Definition at line 66 of file script_SH39m.py.

◆ param_path

script_SH39m.param_path = param_file.split(filename)[0]

Definition at line 69 of file script_SH39m.py.

◆ pathResults

string script_SH39m.pathResults = "/volumes/hra/micado/RunSH39m_RoundPupil/"

Definition at line 22 of file script_SH39m.py.

◆ pixsizes

list script_SH39m.pixsizes = [1]

Definition at line 38 of file script_SH39m.py.

◆ PSFName

string script_SH39m.PSFName = "SH_" + lam + "_" + date + ".fits"

Definition at line 357 of file script_SH39m.py.

◆ PSFNameList

list script_SH39m.PSFNameList = []

Definition at line 351 of file script_SH39m.py.

◆ PSFtarget

script_SH39m.PSFtarget = tar.get_image(t, "le")

Definition at line 353 of file script_SH39m.py.

◆ pxsize

float script_SH39m.pxsize
Initial value:
1 = pixsize * config.p_wfs0.Lambda / (
2  config.p_tel.diam / config.p_wfs0.nxsub) * 0.206265

Definition at line 290 of file script_SH39m.py.

◆ res

script_SH39m.res
Initial value:
1 = pd.DataFrame(
2  columns=list(colnames.keys()) +
3  list(simunames.keys()))

Definition at line 302 of file script_SH39m.py.

◆ resAll

script_SH39m.resAll
Initial value:
1 = db.readDataBase(
2  fullpath=pathResults + dBResult)

Definition at line 263 of file script_SH39m.py.

◆ RONS

list script_SH39m.RONS = [2, 10]

Definition at line 42 of file script_SH39m.py.

◆ rtc

script_SH39m.rtc

Definition at line 314 of file script_SH39m.py.

◆ simul_name

string script_SH39m.simul_name = ""

Definition at line 85 of file script_SH39m.py.

◆ simulName

string script_SH39m.simulName = "SH_39m"

Definition at line 19 of file script_SH39m.py.

◆ simunames

dictionary script_SH39m.simunames
Initial value:
1 = {
2  "PSFFilenames": None,
3  "srir": None,
4  "lambdaTarget": None,
5  "nbBrightest": None,
6  "sr_le": None,
7  "sr_se": None,
8  "numiter": None,
9  "NklFilt": None,
10  "NklTot": None,
11  "Nkl": None,
12  "eigenvals": None,
13  "Nphotons": None,
14  "Nactu": None,
15  "RON": None,
16  "Nslopes": None
17 }

Definition at line 245 of file script_SH39m.py.

◆ SR

script_SH39m.SR = []

Definition at line 235 of file script_SH39m.py.

◆ sr_le

script_SH39m.sr_le

Definition at line 324 of file script_SH39m.py.

◆ sr_se

script_SH39m.sr_se

Definition at line 324 of file script_SH39m.py.

◆ tar

script_SH39m.tar

Definition at line 314 of file script_SH39m.py.

◆ tel

script_SH39m.tel

Definition at line 314 of file script_SH39m.py.

◆ wfs

script_SH39m.wfs

Definition at line 314 of file script_SH39m.py.