COMPASS  5.0.0
End-to-end AO simulation tool using GPU acceleration
script_roket_cpu.py
1 """
2 Created on Wed Apr 27 09:28:23 2016
3 
4 @author: fferreira
5 """
6 
7 import cProfile
8 import pstats as ps
9 
10 import sys, os
11 import numpy as np
12 import carmaWrap as ch
13 import shesha as ao
14 import time
15 import matplotlib.pyplot as pl
16 pl.ion()
17 import hdf5_util as h5u
18 import pandas
19 from scipy.sparse import csr_matrix
20 
21 c = ch.carmaWrap_context(devices=np.array([6], dtype=np.int32))
22 
23 
30 
31 
32 def init_config(config):
33  if (hasattr(config, "simul_name")):
34  if (config.simul_name is None):
35  simul_name = ""
36  else:
37  simul_name = config.simul_name
38  else:
39  simul_name = ""
40  print("simul name is", simul_name)
41 
42  matricesToLoad = {}
43  if (simul_name == b""):
44  clean = 1
45  else:
46  clean = 0
47  param_dict = h5u.params_dictionary(config)
48  matricesToLoad = h5u.checkMatricesDataBase(os.environ["SHESHA_ROOT"] + "/data/",
49  config, param_dict)
50  #initialisation:
51  # context
52 
53  #c=ch.carmaWrap_context(devices=np.array([4,5,6,7], dtype=np.int32))
54  #c.set_active_device(device)
55 
56  # wfs
57  print("->wfs")
58  wfs, tel = ao.wfs_init(config.p_wfss, config.p_atmos, config.p_tel, config.p_geom,
59  config.p_target, config.p_loop, config.p_dms)
60 
61  # atmos
62  print("->atmos")
63  atm = ao.atmos_init(c, config.p_atmos, config.p_tel, config.p_geom, config.p_loop,
64  config.p_wfss, wfs, config.p_target, rank=0, clean=clean,
65  load=matricesToLoad)
66 
67  # dm
68  print("->dm")
69  dms = ao.dm_init(config.p_dms, config.p_wfss, wfs, config.p_geom, config.p_tel)
70 
71  # target
72  print("->target")
73  tar = ao.target_init(c, tel, config.p_target, config.p_atmos, config.p_geom,
74  config.p_tel, config.p_dms)
75 
76  print("->rtc")
77  # rtc
78  rtc = ao.rtc_init(tel, wfs, config.p_wfss, dms, config.p_dms, config.p_geom,
79  config.p_rtc, config.p_atmos, atm, config.p_tel, config.p_loop,
80  clean=clean, simul_name=simul_name, load=matricesToLoad)
81 
82  if not clean:
83  h5u.validDataBase(os.environ["SHESHA_ROOT"] + "/data/", matricesToLoad)
84 
85  print("====================")
86  print("init done")
87  print("====================")
88  print("objects initialzed on GPU:")
89  print("--------------------------------------------------------")
90  print(atm)
91  print(wfs)
92  print(dms)
93  print(tar)
94  print(rtc)
95 
96  print("----------------------------------------------------")
97  print("iter# | SE SR image | LE SR image | Fitting | LE SR phase var")
98  print("----------------------------------------------------")
99 
100  error_flag = True in [w.roket for w in config.p_wfss]
101 
102  return atm, wfs, tel, dms, tar, rtc
103 
104 
105 
112 def loop(n):
113  """
114  Performs the main AO loop for n interations. First, initialize buffers
115  for error breakdown computations. Then, at the end of each iteration, just
116  before applying the new DM shape, calls the error_breakdown function.
117 
118  :param n: (int) : number of iterations
119 
120  :return:
121  com : (np.array((n,nactus))) : full command buffer
122 
123  noise_com : (np.array((n,nactus))) : noise contribution for error breakdown
124 
125  alias_wfs_com : (np.array((n,nactus))) : aliasing estimation in the WFS direction
126 
127  tomo_com : (np.array((n,nactus))) : tomography error estimation
128 
129  H_com : (np.array((n,nactus))) : Filtered modes contribution for error breakdown
130 
131  trunc_com : (np.array((n,nactus))) : Truncature and sampling error of WFS
132 
133  bp_com : (np.array((n,nactus))) : Bandwidth error estimation on target
134 
135  mod_com : (np.array((n,nactus))) : Commanded modes expressed on the actuators
136 
137  fit : (float) : fitting (mean variance of the residual target phase after projection)
138 
139  SR : (float) : final strehl ratio returned by the simulation
140  """
141  if (error_flag):
142  # Initialize buffers for error breakdown
143  nactu = rtc.get_command(0).size
144  com = np.zeros((n, nactu), dtype=np.float32)
145  noise_com = np.zeros((n, nactu), dtype=np.float32)
146  alias_wfs_com = np.copy(noise_com)
147  wf_com = np.copy(noise_com)
148  tomo_com = np.copy(noise_com)
149  trunc_com = np.copy(noise_com)
150  H_com = np.copy(noise_com)
151  mod_com = np.copy(noise_com)
152  bp_com = np.copy(noise_com)
153  fit = np.zeros(n)
154  psf_ortho = tar.get_image(0, 'se') * 0.
155 
156  t0 = time.time()
157  for i in range(n):
158  atm.move_atmos()
159 
160  if (config.p_controllers[0].type == b"geo"):
161  for t in range(config.p_target.ntargets):
162  tar.atmos_trace(t, atm, tel)
163  rtc.docontrol_geo(0, dms, tar, 0)
164  rtc.applycontrol(0, dms)
165  tar.dmtrace(0, dms)
166  else:
167  for t in range(config.p_target.ntargets):
168  tar.atmos_trace(t, atm, tel)
169  tar.dmtrace(t, dms)
170  for w in range(len(config.p_wfss)):
171  wfs.sensors_trace(w, "all", tel, atm, dms)
172  wfs.sensors_compimg(w)
173  rtc.docentroids(0)
174  rtc.docontrol(0)
175 
176  if (error_flag):
177  #compute the error breakdown for this iteration
178  error_breakdown(com, noise_com, alias_wfs_com, tomo_com, H_com,
179  trunc_com, bp_com, wf_com, mod_com, fit, psf_ortho, i)
180 
181  rtc.applycontrol(0, dms)
182 
183  if ((i + 1) % 10 == 0 and i > -1):
184  strehltmp = tar.get_strehl(0)
185  print(i + 1, "\t", strehltmp[0], "\t", strehltmp[1], "\t",
186  np.exp(-strehltmp[2]), "\t", np.exp(-strehltmp[3]))
187  t1 = time.time()
188  print(" loop execution time:", t1 - t0, " (", n, "iterations), ", (t1 - t0) / n,
189  "(mean) ", n / (t1 - t0), "Hz")
190  if (error_flag):
191  #Returns the error breakdown
192  SR2 = np.exp(-tar.get_strehl(0, comp_strehl=False)[3])
193  SR = tar.get_strehl(0, comp_strehl=False)[1]
194  #bp_com[-1,:] = bp_com[-2,:]
195  #SR = tar.get_strehl(0,comp_strehl=False)[1]
196  return com, noise_com, alias_wfs_com, tomo_com, H_com, trunc_com, bp_com, mod_com, np.mean(
197  fit[N_preloop:]), SR, SR2, psf_ortho
198 
199 
200 def preloop(n):
201  """
202  Performs the main AO loop for n interations. First, initialize buffers
203  for error breakdown computations. Then, at the end of each iteration, just
204  before applying the new DM shape, calls the error_breakdown function.
205 
206  :param n: (int) : number of iterations
207 
208  :return:
209  com : (np.array((n,nactus))) : full command buffer
210 
211  noise_com : (np.array((n,nactus))) : noise contribution for error breakdown
212 
213  alias_wfs_com : (np.array((n,nactus))) : aliasing estimation in the WFS direction
214 
215  tomo_com : (np.array((n,nactus))) : tomography error estimation
216 
217  H_com : (np.array((n,nactus))) : Filtered modes contribution for error breakdown
218 
219  trunc_com : (np.array((n,nactus))) : Truncature and sampling error of WFS
220 
221  bp_com : (np.array((n,nactus))) : Bandwidth error estimation on target
222 
223  mod_com : (np.array((n,nactus))) : Commanded modes expressed on the actuators
224 
225  fit : (float) : fitting (mean variance of the residual target phase after projection)
226 
227  SR : (float) : final strehl ratio returned by the simulation
228  """
229  for i in range(0, n):
230  atm.move_atmos()
231 
232  if (config.p_controllers[0].type == b"geo"):
233  for t in range(config.p_target.ntargets):
234  tar.atmos_trace(t, atm, tel)
235  rtc.docontrol_geo(0, dms, tar, 0)
236  rtc.applycontrol(0, dms)
237  else:
238  for t in range(config.p_target.ntargets):
239  tar.atmos_trace(t, atm, tel)
240  for w in range(len(config.p_wfss)):
241  wfs.sensors_trace(w, "all", tel, atm, dms)
242  wfs.sensors_compimg(w)
243  rtc.docentroids(0)
244  rtc.docontrol(0)
245 
246  rtc.applycontrol(0, dms)
247 
248 
249 
255 def error_breakdown(com, noise_com, alias_wfs_com, tomo_com, H_com, trunc_com, bp_com,
256  wf_com, mod_com, fit, psf_ortho, i):
257  """
258  Compute the error breakdown of the AO simulation. Returns the error commands of
259  each contributors. Suppose no delay (for now) and only 2 controllers : the main one, controller #0, (specified on the parameter file)
260  and the geometric one, controller #1 (automatically added if roket is asked in the parameter file)
261  Commands are computed by applying the loop filter on various kind of commands : (see schema_simulation_budget_erreur_v2)
262 
263  - Ageom : Aliasing contribution on WFS direction
264  Obtained by computing commands from DM orthogonal phase (projection + slopes_geom)
265 
266  - B : Projection on the target direction
267  Obtained as the commmands output of the geometric controller
268 
269  - C : Wavefront
270  Obtained by computing commands from DM parallel phase (RD*B)
271 
272  - E : Wavefront + aliasing + ech/trunc + tomo
273  Obtained by performing the AO loop iteration without noise on the WFS
274 
275  - F : Wavefront + aliasing + tomo
276  Obtained by performing the AO loop iteration without noise on the WFS and using phase deriving slopes
277 
278  - G : tomo
279 
280  Note : rtc.get_err returns to -CMAT.slopes
281 
282  :parameters:
283  noise_com : np.array((niter,nactu)) : Noise contribution
284  Computed with com-E
285 
286  alias_wfs_com : np.array((niter,nactu)) : Aliasing on WFS direction contribution
287  Computed with Ageom
288 
289  tomo_com : np.array((niter,nactu)) : Tomographic error contribution
290  Computed with C-B
291 
292  H_com : np.array((niter,nactu)) : Filtered modes error
293  Computed with B
294 
295  trunc_com : np.array((niter,nactu)) : sampling/truncature error contribution
296  Computed with E-F
297 
298  bp_com : np.array((niter,nactu)) : Bandwidth error
299 
300  wf_com : np.array((niter,nactu)) : Reconstructed wavefront
301 
302  mod_com : np.array((niter,nactu)) : commanded modes
303 
304  fit : np.array((niter)) : fitting value
305 
306  i : (int) : current iteration number
307 
308  """
309  g = config.p_controllers[0].gain
310  Dcom = rtc.get_command(0)
311  Derr = rtc.get_err(0)
312  com[i, :] = Dcom
313  tarphase = tar.get_phase(0)
314 
317  if (config.p_wfss[0].type == b"sh"):
318  ideal_bincube = wfs.get_bincubeNotNoisy(0)
319  bincube = wfs.get_bincube(0)
320  if (config.p_centroiders[0].type == b"tcog"
321  ): # Select the same pixels with or without noise
322  invalidpix = np.where(bincube <= config.p_centroiders[0].thresh)
323  ideal_bincube[invalidpix] = 0
324  rtc.setthresh(0, -1e16)
325  wfs.set_bincube(0, ideal_bincube)
326  elif (config.p_wfss[0].type == b"pyrhr"):
327  ideal_pyrimg = wfs.get_binimg_notnoisy(0)
328  wfs.set_pyrimg(0, ideal_pyrimg)
329 
330  rtc.docentroids(0)
331  if (config.p_centroiders[0].type == b"tcog"):
332  rtc.setthresh(0, config.p_centroiders[0].thresh)
333 
334  rtc.docontrol(0)
335  E = rtc.get_err(0)
336  # Apply loop filter to get contribution of noise on commands
337  if (i + 1 < config.p_loop.niter):
338  noise_com[i + 1, :] = gRD.dot(noise_com[i, :]) + g * (Derr - E)
339 
340 
343  rtc.docentroids_geom(0)
344  rtc.docontrol(0)
345  F = rtc.get_err(0)
346  # Apply loop filter to get contribution of sampling/truncature on commands
347  if (i + 1 < config.p_loop.niter):
348  trunc_com[i + 1, :] = gRD.dot(trunc_com[i, :]) + g * (E - F)
349 
350 
353  rtc.docontrol_geo_onwfs(1, dms, wfs, 0)
354  rtc.applycontrol(1, dms)
355  for w in range(len(config.p_wfss)):
356  wfs.sensors_trace(w, "dm", tel, atm, dms)
357  """
358  wfs.sensors_compimg(0)
359  if(config.p_wfss[0].type == b"sh"):
360  ideal_bincube = wfs.get_bincubeNotNoisy(0)
361  bincube = wfs.get_bincube(0)
362  if(config.p_centroiders[0].type == b"tcog"): # Select the same pixels with or without noise
363  invalidpix = np.where(bincube <= config.p_centroiders[0].thresh)
364  ideal_bincube[invalidpix] = 0
365  rtc.setthresh(0,-1e16)
366  wfs.set_bincube(0,ideal_bincube)
367  elif(config.p_wfss[0].type == b"pyrhr"):
368  ideal_pyrimg = wfs.get_binimg_notnoisy(0)
369  wfs.set_pyrimg(0,ideal_pyrimg)
370  """
371  rtc.docentroids_geom(0)
372  rtc.docontrol(0)
373  Ageom = rtc.get_err(0)
374  if (i + 1 < config.p_loop.niter):
375  alias_wfs_com[i + 1, :] = gRD.dot(alias_wfs_com[i, :]) + g * (Ageom)
376 
377 
380  tar.atmos_trace(0, atm, tel)
381  rtc.docontrol_geo(1, dms, tar, 0)
382  B = rtc.get_command(1)
383 
384 
387  rtc.applycontrol(1, dms)
388  tar.dmtrace(0, dms, do_phase_var=0)
389  fit[i] = tar.get_strehl(0, comp_strehl=False)[2]
390  if (i >= N_preloop):
391  psf_ortho += tar.get_image(0, 'se') / niters
392 
393 
396  modes = P.dot(B)
397  modes_filt = modes.copy() * 0.
398  modes_filt[-nfiltered - 2:-2] = modes[-nfiltered - 2:-2]
399  H_com[i, :] = Btt.dot(modes_filt)
400  modes[-nfiltered - 2:-2] = 0
401  mod_com[i, :] = Btt.dot(modes)
402 
403 
406  C = mod_com[i, :] - mod_com[i - 1, :]
407 
408  bp_com[i, :] = gRD.dot(bp_com[i - 1, :]) - C
409 
410 
414  for w in range(len(config.p_wfss)):
415  wfs.sensors_trace(w, "atmos", tel, atm, dms)
416  rtc.docontrol_geo_onwfs(1, dms, wfs, 0)
417  G = rtc.get_command(1)
418  modes = P.dot(G)
419  modes[-nfiltered - 2:-2] = 0
420  wf_com[i, :] = Btt.dot(modes)
421 
422  G = mod_com[i, :] - wf_com[i, :]
423  if (i + 1 < config.p_loop.niter):
424  tomo_com[i + 1, :] = gRD.dot(tomo_com[i, :]) - g * RD.dot(G)
425 
426  # Without anyone noticing...
427  tar.set_phase(0, tarphase)
428  rtc.setCom(0, Dcom)
429 
430 
431 
438  IF = rtc.get_IFsparse(1).T
439  N = IF.shape[0]
440  n = IF.shape[1]
441  #T = IF[:,-2:].copy()
442  T = rtc.get_IFtt(1)
443  #IF = IF[:,:n-2]
444  n = IF.shape[1]
445 
446  delta = IF.T.dot(IF).toarray() / N
447 
448  # Tip-tilt + piston
449  Tp = np.ones((T.shape[0], T.shape[1] + 1))
450  Tp[:, :2] = T.copy() #.toarray()
451  deltaT = IF.T.dot(Tp) / N
452  # Tip tilt projection on the pzt dm
453  tau = np.linalg.inv(delta).dot(deltaT)
454 
455  # Famille generatrice sans tip tilt
456  G = np.identity(n)
457  tdt = tau.T.dot(delta).dot(tau)
458  subTT = tau.dot(np.linalg.inv(tdt)).dot(tau.T).dot(delta)
459  G -= subTT
460 
461  # Base orthonormee sans TT
462  gdg = G.T.dot(delta).dot(G)
463  U, s, V = np.linalg.svd(gdg)
464  U = U[:, :U.shape[1] - 3]
465  s = s[:s.size - 3]
466  L = np.identity(s.size) / np.sqrt(s)
467  B = G.dot(U).dot(L)
468 
469  # Rajout du TT
470  TT = T.T.dot(T) / N #.toarray()/N
471  Btt = np.zeros((n + 2, n - 1))
472  Btt[:B.shape[0], :B.shape[1]] = B
473  mini = 1. / np.sqrt(TT)
474  mini[0, 1] = 0
475  mini[1, 0] = 0
476  Btt[n:, n - 3:] = mini
477 
478  # Calcul du projecteur actus-->modes
479  delta = np.zeros((n + T.shape[1], n + T.shape[1]))
480  #IF = rtc.get_IFsparse(1).T
481  delta[:-2, :-2] = IF.T.dot(IF).toarray() / N
482  delta[-2:, -2:] = T.T.dot(T) / N
483  P = Btt.T.dot(delta)
484 
485  return Btt.astype(np.float32), P.astype(np.float32)
486 
487 
489  IF = rtc.get_IFsparse(1).T
490  N = IF.shape[0]
491  n = IF.shape[1]
492  T = IF[:, -2:].copy()
493  IF = IF[:, :n - 2]
494  n = IF.shape[1]
495 
496  delta = IF.T.dot(IF).toarray() / N
497 
498  # Tip-tilt + piston
499  Tp = np.ones((T.shape[0], T.shape[1] + 1))
500  Tp[:, :2] = T.toarray()
501  deltaT = IF.T.dot(Tp) / N
502  # Tip tilt projection on the pzt dm
503  tau = np.linalg.inv(delta).dot(deltaT)
504 
505  # Famille génératrice sans tip tilt
506  G = np.identity(n)
507  tdt = tau.T.dot(delta).dot(tau)
508  subTT = tau.dot(np.linalg.inv(tdt)).dot(tau.T).dot(delta)
509  G -= subTT
510 
511  # Base orthonormée sans TT
512  gdg = G.T.dot(delta).dot(G)
513  U, s, V = np.linalg.svd(gdg)
514  U = U[:, :U.shape[1] - 3]
515  s = s[:s.size - 3]
516  L = np.identity(s.size) / np.sqrt(s)
517  B = G.dot(U).dot(L)
518 
519  # Rajout du TT
520  TT = T.T.dot(T).toarray() / N
521  Btt = np.zeros((n + 2, n - 1))
522  Btt[:B.shape[0], :B.shape[1]] = B
523  mini = 1. / np.sqrt(TT)
524  mini[0, 1] = 0
525  mini[1, 0] = 0
526  Btt[n:, n - 3:] = mini
527 
528  # Calcul du projecteur actus-->modes
529  IF = rtc.get_IFsparse(1).T
530  delta = IF.T.dot(IF).toarray() / N
531  P = Btt.T.dot(delta)
532 
533  return Btt.astype(np.float32), P.astype(np.float32)
534 
535 
536 def compute_cmatWithBtt(Btt, nfilt):
537  D = rtc.get_imat(0)
538  #D = ao.imat_geom(wfs,config.p_wfss,config.p_controllers[0],dms,config.p_dms,meth=0)
539  # Filtering on Btt modes
540  Btt_filt = np.zeros((Btt.shape[0], Btt.shape[1] - nfilt))
541  Btt_filt[:, :Btt_filt.shape[1] - 2] = Btt[:, :Btt.shape[1] - (nfilt + 2)]
542  Btt_filt[:, Btt_filt.shape[1] - 2:] = Btt[:, Btt.shape[1] - 2:]
543 
544  # Modal interaction basis
545  Dm = D.dot(Btt_filt)
546  # Direct inversion
547  Dmp = np.linalg.inv(Dm.T.dot(Dm)).dot(Dm.T)
548  # Command matrix
549  cmat = Btt_filt.dot(Dmp)
550 
551  return Dm.astype(np.float32), cmat.astype(np.float32)
552 
553 
554 def compute_cmatWithBtt2(Btt, nfilt):
555  D = rtc.get_imat(0)
556 
557  # Modal interaction basis
558  Dm = D.dot(Btt)
559  # Filtering on modal imat
560  DmtDm = Dm.T.dot(Dm)
561  U, s, V = np.linalg.svd(DmtDm)
562  s = 1. / s
563  s[s.shape[0] - nfilt - 2:s.shape[0] - 2] = 0.
564  DmtDm1 = U.dot(np.diag(s)).dot(U.T)
565  Dmp = DmtDm1.dot(Dm.T)
566  # Command matrix
567  cmat = Btt.dot(Dmp)
568 
569  return Dm.astype(np.float32), cmat.astype(np.float32)
570 
571 
572 
579 
580 
581 def cov_cor(P, noise, trunc, alias, H, bp, tomo):
582  cov = np.zeros((6, 6))
583  bufdict = {
584  "0": noise.T,
585  "1": trunc.T,
586  "2": alias.T,
587  "3": H.T,
588  "4": bp.T,
589  "5": tomo.T
590  }
591  for i in range(cov.shape[0]):
592  for j in range(cov.shape[1]):
593  if (j >= i):
594  tmpi = P.dot(bufdict[str(i)])
595  tmpj = P.dot(bufdict[str(j)])
596  cov[i, j] = np.sum(
597  np.mean(tmpi * tmpj, axis=1) -
598  np.mean(tmpi, axis=1) * np.mean(tmpj, axis=1))
599  else:
600  cov[i, j] = cov[j, i]
601 
602  s = np.reshape(np.diag(cov), (cov.shape[0], 1))
603  sst = np.dot(s, s.T)
604  cor = cov / np.sqrt(sst)
605 
606  return cov, cor
607 
608 
609 
615 
616 
617 def save_it(filename):
618  IF = rtc.get_IFsparse(1)
619  TT = rtc.get_IFtt(1)
620 
621  tmp = (config.p_geom._ipupil.shape[0] -
622  (config.p_dms[0]._n2 - config.p_dms[0]._n1 + 1)) / 2
623  tmp_e0 = config.p_geom._ipupil.shape[0] - tmp
624  tmp_e1 = config.p_geom._ipupil.shape[1] - tmp
625  pup = config.p_geom._ipupil[tmp:tmp_e0, tmp:tmp_e1]
626  indx_pup = np.where(pup.flatten() > 0)[0].astype(np.int32)
627  dm_dim = config.p_dms[0]._n2 - config.p_dms[0]._n1 + 1
628  cov, cor = cov_cor(P, noise_com, trunc_com, alias_wfs_com, H_com, bp_com, tomo_com)
629  psf = tar.get_image(0, "le", fluxNorm=False)
630 
631  fname = "/home/fferreira/Data/" + filename
632  pdict = {
633  "noise": noise_com.T,
634  "aliasing": alias_wfs_com.T,
635  "tomography": tomo_com.T,
636  "filtered modes": H_com.T,
637  "non linearity": trunc_com.T,
638  "bandwidth": bp_com.T,
639  "wf_com": wf_com.T,
640  "P": P,
641  "Btt": Btt,
642  "IF.data": IF.data,
643  "IF.indices": IF.indices,
644  "IF.indptr": IF.indptr,
645  "TT": TT,
646  "dm_dim": dm_dim,
647  "indx_pup": indx_pup,
648  "fitting": fit,
649  "SR": SR,
650  "SR2": SR2,
651  "cov": cov,
652  "cor": cor,
653  "psfortho": np.fft.fftshift(psf_ortho),
654  "dm.xpos": config.p_dms[0]._xpos,
655  "dm.ypos": config.p_dms[0]._ypos
656  }
657  h5u.save_h5(fname, "psf", config, psf)
658  #h5u.writeHdf5SingleDataset(fname,com.T,datasetName="com")
659  for k in list(pdict.keys()):
660  h5u.save_hdf5(fname, k, pdict[k])
661 
662 
663 
670 param_file = "/home/fferreira/compass/trunk/shesha/data/par/par4roket/correlation_study/roket_8m_1layer.py"
671 error_flag = True
672 if (param_file.split('.')[-1] == b"py"):
673  filename = param_file.split('/')[-1]
674  param_path = param_file.split(filename)[0]
675  sys.path.insert(0, param_path)
676  exec("import %s as config" % filename.split(".py")[0])
677  #sys.path.remove(param_path)
678 nfiltered = 20
679 N_preloop = 1000
680 niters = config.p_loop.niter
681 config.p_loop.set_niter(niters + N_preloop)
682 winddirs = [0, 45, 90, 135, 180]
683 windspeeds = [5., 10., 15., 20.]
684 
685 d = float(sys.argv[1])
686 s = float(sys.argv[2])
687 g = float(sys.argv[3])
688 
689 savename = "roket_8m_1layer_dir%d_speed%d_g%d_cpu.h5" % (d, s, g * 10)
690 config.p_atmos.set_winddir([d])
691 config.p_atmos.set_windspeed([s])
692 config.p_controllers[0].set_gain(g)
693 
694 atm, wfs, tel, dms, tar, rtc = init_config(config)
695 #config.p_loop.set_niter(niters)
696 Btt, P = compute_btt2()
697 rtc.load_Btt(1, Btt.dot(Btt.T))
698 Dm, cmat = compute_cmatWithBtt(Btt, nfiltered)
699 rtc.set_cmat(0, cmat)
700 R = rtc.get_cmat(0)
701 imat = rtc.get_imat(0)
702 RD = np.dot(R, imat).astype(np.float32)
703 gRD = (np.identity(RD.shape[0]) - config.p_controllers[0].gain * RD).astype(np.float32)
704 
705 com, noise_com, alias_wfs_com, tomo_com, H_com, trunc_com, bp_com, wf_com, fit, SR, SR2, psf_ortho = loop(
706  niters + N_preloop)
707 noise_com = noise_com[N_preloop:, :]
708 trunc_com = trunc_com[N_preloop:, :]
709 alias_wfs_com = alias_wfs_com[N_preloop:, :]
710 H_com = H_com[N_preloop:, :]
711 bp_com = bp_com[N_preloop:, :]
712 tomo_com = tomo_com[N_preloop:, :]
713 save_it(savename)
script_roket_cpu.save_it
def save_it(filename)
Definition: script_roket_cpu.py:617
script_roket_cpu.compute_cmatWithBtt2
def compute_cmatWithBtt2(Btt, nfilt)
Definition: script_roket_cpu.py:554
script_roket_cpu.error_breakdown
def error_breakdown(com, noise_com, alias_wfs_com, tomo_com, H_com, trunc_com, bp_com, wf_com, mod_com, fit, psf_ortho, i)
Definition: script_roket_cpu.py:307
script_roket_cpu.compute_cmatWithBtt
def compute_cmatWithBtt(Btt, nfilt)
Definition: script_roket_cpu.py:536
script_roket_cpu.loop
def loop(n)
Definition: script_roket_cpu.py:140
script_roket_cpu.init_config
def init_config(config)
Definition: script_roket_cpu.py:32
script_roket_cpu.compute_btt2
def compute_btt2()
Definition: script_roket_cpu.py:437
script_roket_cpu.compute_btt
def compute_btt()
Definition: script_roket_cpu.py:488
script_roket_cpu.cov_cor
def cov_cor(P, noise, trunc, alias, H, bp, tomo)
Definition: script_roket_cpu.py:581
script_roket_cpu.preloop
def preloop(n)
Definition: script_roket_cpu.py:228