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

Functions

def init_config (config)
 
def loop (n)
 
def preloop (n)
 
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)
 
def compute_btt2 ()
 
def compute_btt ()
 
def compute_cmatWithBtt (Btt, nfilt)
 
def compute_cmatWithBtt2 (Btt, nfilt)
 
def cov_cor (P, noise, trunc, alias, H, bp, tomo)
 
def save_it (filename)
 

Variables

 c = ch.carmaWrap_context(devices=np.array([6], dtype=np.int32))
 
string param_file = "/home/fferreira/compass/trunk/shesha/data/par/par4roket/correlation_study/roket_8m_1layer.py"
 _ _ | |_ ___ ___| |_ ___ | __/ _ \/ __| __/ __| | || __/__ \ |___ \ _____||___/__|___/ More...
 
bool error_flag = True
 
string filename = param_file.split('/')[-1]
 
string param_path = param_file.split(filename)[0]
 
int nfiltered = 20
 
int N_preloop = 1000
 
 niters = config.p_loop.niter
 
list winddirs = [0, 45, 90, 135, 180]
 
list windspeeds = [5., 10., 15., 20.]
 
 d = float(sys.argv[1])
 
 s = float(sys.argv[2])
 
 g = float(sys.argv[3])
 
string savename = "roket_8m_1layer_dir%d_speed%d_g%d_cpu.h5" % (d, s, g * 10)
 
 atm
 
 wfs
 
 tel
 
 dms
 
 tar
 
 rtc
 
 Btt
 
 P
 
 Dm
 
 cmat
 
 R = rtc.get_cmat(0)
 
 imat = rtc.get_imat(0)
 
 RD = np.dot(R, imat).astype(np.float32)
 
tuple gRD = (np.identity(RD.shape[0]) - config.p_controllers[0].gain * RD).astype(np.float32)
 
 com
 
 noise_com = noise_com[N_preloop:, :]
 
 alias_wfs_com = alias_wfs_com[N_preloop:, :]
 
 tomo_com = tomo_com[N_preloop:, :]
 
 H_com = H_com[N_preloop:, :]
 
 trunc_com = trunc_com[N_preloop:, :]
 
 bp_com = bp_com[N_preloop:, :]
 
 wf_com
 
 fit
 
 SR
 
 SR2
 
 psf_ortho
 

Function Documentation

◆ compute_btt()

def script_roket_cpu.compute_btt ( )

Definition at line 488 of file script_roket_cpu.py.

488 def compute_btt():
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 

◆ compute_btt2()

def script_roket_cpu.compute_btt2 ( )

| _ ) __ _ __(_)___ | _ \/ _` (-< (_-< |___/_,_/__/_/__/

Definition at line 437 of file script_roket_cpu.py.

437 def compute_btt2():
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 

◆ compute_cmatWithBtt()

def script_roket_cpu.compute_cmatWithBtt (   Btt,
  nfilt 
)

Definition at line 536 of file script_roket_cpu.py.

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 

◆ compute_cmatWithBtt2()

def script_roket_cpu.compute_cmatWithBtt2 (   Btt,
  nfilt 
)

Definition at line 554 of file script_roket_cpu.py.

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 

◆ cov_cor()

def script_roket_cpu.cov_cor (   P,
  noise,
  trunc,
  alias,
  H,
  bp,
  tomo 
)

/ __|_____ ____ _ _ _(_)__ _ _ _ __ ___ / _|___ __ ___ _ _ _ _ ___| |__ _| |_(_)___ _ _ | (__/ _ \ V / _‘ | ’_| / _‘ | ’ \/ _/ -_) > _|_ _| / _/ _ \ '_| '_/ -_) / _‘ | _| / _ \ ’ \ ______/_/__,_|_| |___,_|_||______| _____| _____/_| |_| ___|___,_|__|____/_||_|

Definition at line 581 of file script_roket_cpu.py.

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 
Here is the caller graph for this function:

◆ error_breakdown()

def script_roket_cpu.error_breakdown (   com,
  noise_com,
  alias_wfs_com,
  tomo_com,
  H_com,
  trunc_com,
  bp_com,
  wf_com,
  mod_com,
  fit,
  psf_ortho,
  i 
)

| __|_ _ _ _ ___ _ _ | _ )_ _ ___ __ _| |____| |_____ __ ___ _ | _|| '_| '_/ _ \ '_| | _ \ '_/ -_) _| / / _ / _ \ V V / ' \ |___|_| |_| ___/_| |___/_| _____,_|____,____/_/_/|_||_|

Compute the error breakdown of the AO simulation. Returns the error commands of each contributors. Suppose no delay (for now) and only 2 controllers : the main one, controller #0, (specified on the parameter file) and the geometric one, controller #1 (automatically added if roket is asked in the parameter file) Commands are computed by applying the loop filter on various kind of commands : (see schema_simulation_budget_erreur_v2)

- Ageom : Aliasing contribution on WFS direction
    Obtained by computing commands from DM orthogonal phase (projection + slopes_geom)

- B : Projection on the target direction
    Obtained as the commmands output of the geometric controller

- C : Wavefront
    Obtained by computing commands from DM parallel phase (RD*B)

- E : Wavefront + aliasing + ech/trunc + tomo
    Obtained by performing the AO loop iteration without noise on the WFS

- F : Wavefront + aliasing + tomo
    Obtained by performing the AO loop iteration without noise on the WFS and using phase deriving slopes

- G : tomo

Note rtc.get_err returns to -CMAT.slopes

:parameters: noise_com np.array((niter,nactu)) : Noise contribution Computed with com-E

alias_wfs_com np.array((niter,nactu)) : Aliasing on WFS direction contribution Computed with Ageom

tomo_com np.array((niter,nactu)) : Tomographic error contribution Computed with C-B

H_com np.array((niter,nactu)) : Filtered modes error Computed with B

trunc_com np.array((niter,nactu)) : sampling/truncature error contribution Computed with E-F

bp_com np.array((niter,nactu)) : Bandwidth error

wf_com np.array((niter,nactu)) : Reconstructed wavefront

mod_com np.array((niter,nactu)) : commanded modes

fit np.array((niter)) : fitting value

i (int) : current iteration number

Definition at line 307 of file script_roket_cpu.py.

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  ###########################################################################
315  ## Noise contribution
316  ###########################################################################
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  ###########################################################################
341  ## Sampling/truncature contribution
342  ###########################################################################
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  ###########################################################################
351  ## Aliasing contribution on WFS direction
352  ###########################################################################
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  ###########################################################################
378  ## Wavefront + filtered modes reconstruction
379  ###########################################################################
380  tar.atmos_trace(0, atm, tel)
381  rtc.docontrol_geo(1, dms, tar, 0)
382  B = rtc.get_command(1)
383 
384  ###########################################################################
385  ## Fitting
386  ###########################################################################
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  ###########################################################################
394  ## Filtered modes error & Commanded modes
395  ###########################################################################
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  ###########################################################################
404  ## Bandwidth error
405  ###########################################################################
406  C = mod_com[i, :] - mod_com[i - 1, :]
407 
408  bp_com[i, :] = gRD.dot(bp_com[i - 1, :]) - C
409 
410  ###########################################################################
411  ## Tomographic error
412  ###########################################################################
413  #G = F - (mod_com[i,:] + Ageom - np.dot(RDgeom,com[i-1,:]))
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 
Here is the caller graph for this function:

◆ init_config()

def script_roket_cpu.init_config (   config)

(_)_ __ (_) |_ ___ | | '_ | | __/ __| | | | | | | |___ \ |_|_| |_|_|__|___/

Definition at line 32 of file script_roket_cpu.py.

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 

◆ loop()

def script_roket_cpu.loop (   n)

/_\ / _ \ | |___ ___ _ __ / _ \ (_) | | / _ \/ _ \ '_ \ /_/ ____/ |____/___/ .__/ |_|

Performs the main AO loop for n interations. First, initialize buffers for error breakdown computations. Then, at the end of each iteration, just before applying the new DM shape, calls the error_breakdown function.

:param n: (int) : number of iterations

:return: com (np.array((n,nactus))) : full command buffer

noise_com (np.array((n,nactus))) : noise contribution for error breakdown

alias_wfs_com (np.array((n,nactus))) : aliasing estimation in the WFS direction

tomo_com (np.array((n,nactus))) : tomography error estimation

H_com (np.array((n,nactus))) : Filtered modes contribution for error breakdown

trunc_com (np.array((n,nactus))) : Truncature and sampling error of WFS

bp_com (np.array((n,nactus))) : Bandwidth error estimation on target

mod_com (np.array((n,nactus))) : Commanded modes expressed on the actuators

fit (float) : fitting (mean variance of the residual target phase after projection)

SR (float) : final strehl ratio returned by the simulation

Definition at line 140 of file script_roket_cpu.py.

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
Here is the call graph for this function:

◆ preloop()

def script_roket_cpu.preloop (   n)

Definition at line 228 of file script_roket_cpu.py.

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 

◆ save_it()

def script_roket_cpu.save_it (   filename)

/ __| __ ___ _____ __ \/ _` \ V / -_) |___/__,_|_/___|

Definition at line 617 of file script_roket_cpu.py.

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 
Here is the call graph for this function:

Variable Documentation

◆ alias_wfs_com

script_roket_cpu.alias_wfs_com = alias_wfs_com[N_preloop:, :]

Definition at line 705 of file script_roket_cpu.py.

◆ atm

script_roket_cpu.atm

Definition at line 694 of file script_roket_cpu.py.

◆ bp_com

script_roket_cpu.bp_com = bp_com[N_preloop:, :]

Definition at line 705 of file script_roket_cpu.py.

◆ Btt

script_roket_cpu.Btt

Definition at line 696 of file script_roket_cpu.py.

◆ c

script_roket_cpu.c = ch.carmaWrap_context(devices=np.array([6], dtype=np.int32))

Definition at line 21 of file script_roket_cpu.py.

◆ cmat

script_roket_cpu.cmat

Definition at line 698 of file script_roket_cpu.py.

◆ com

script_roket_cpu.com

Definition at line 705 of file script_roket_cpu.py.

◆ d

script_roket_cpu.d = float(sys.argv[1])

Definition at line 685 of file script_roket_cpu.py.

◆ Dm

script_roket_cpu.Dm

Definition at line 698 of file script_roket_cpu.py.

◆ dms

script_roket_cpu.dms

Definition at line 694 of file script_roket_cpu.py.

◆ error_flag

bool script_roket_cpu.error_flag = True

Definition at line 671 of file script_roket_cpu.py.

◆ filename

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

Definition at line 673 of file script_roket_cpu.py.

◆ fit

script_roket_cpu.fit

Definition at line 705 of file script_roket_cpu.py.

◆ g

script_roket_cpu.g = float(sys.argv[3])

Definition at line 687 of file script_roket_cpu.py.

◆ gRD

tuple script_roket_cpu.gRD = (np.identity(RD.shape[0]) - config.p_controllers[0].gain * RD).astype(np.float32)

Definition at line 703 of file script_roket_cpu.py.

◆ H_com

script_roket_cpu.H_com = H_com[N_preloop:, :]

Definition at line 705 of file script_roket_cpu.py.

◆ imat

script_roket_cpu.imat = rtc.get_imat(0)

Definition at line 701 of file script_roket_cpu.py.

◆ N_preloop

int script_roket_cpu.N_preloop = 1000

Definition at line 679 of file script_roket_cpu.py.

◆ nfiltered

int script_roket_cpu.nfiltered = 20

Definition at line 678 of file script_roket_cpu.py.

◆ niters

script_roket_cpu.niters = config.p_loop.niter

Definition at line 680 of file script_roket_cpu.py.

◆ noise_com

script_roket_cpu.noise_com = noise_com[N_preloop:, :]

Definition at line 705 of file script_roket_cpu.py.

◆ P

script_roket_cpu.P

Definition at line 696 of file script_roket_cpu.py.

◆ param_file

string script_roket_cpu.param_file = "/home/fferreira/compass/trunk/shesha/data/par/par4roket/correlation_study/roket_8m_1layer.py"

_ _ | |_ ___ ___| |_ ___ | __/ _ \/ __| __/ __| | || __/__ \ |___ \ _____||___/__|___/

Definition at line 670 of file script_roket_cpu.py.

◆ param_path

string script_roket_cpu.param_path = param_file.split(filename)[0]

Definition at line 674 of file script_roket_cpu.py.

◆ psf_ortho

script_roket_cpu.psf_ortho

Definition at line 705 of file script_roket_cpu.py.

◆ R

script_roket_cpu.R = rtc.get_cmat(0)

Definition at line 700 of file script_roket_cpu.py.

◆ RD

script_roket_cpu.RD = np.dot(R, imat).astype(np.float32)

Definition at line 702 of file script_roket_cpu.py.

◆ rtc

script_roket_cpu.rtc

Definition at line 694 of file script_roket_cpu.py.

◆ s

script_roket_cpu.s = float(sys.argv[2])

Definition at line 686 of file script_roket_cpu.py.

◆ savename

string script_roket_cpu.savename = "roket_8m_1layer_dir%d_speed%d_g%d_cpu.h5" % (d, s, g * 10)

Definition at line 689 of file script_roket_cpu.py.

◆ SR

script_roket_cpu.SR

Definition at line 705 of file script_roket_cpu.py.

◆ SR2

script_roket_cpu.SR2

Definition at line 705 of file script_roket_cpu.py.

◆ tar

script_roket_cpu.tar

Definition at line 694 of file script_roket_cpu.py.

◆ tel

script_roket_cpu.tel

Definition at line 694 of file script_roket_cpu.py.

◆ tomo_com

script_roket_cpu.tomo_com = tomo_com[N_preloop:, :]

Definition at line 705 of file script_roket_cpu.py.

◆ trunc_com

script_roket_cpu.trunc_com = trunc_com[N_preloop:, :]

Definition at line 705 of file script_roket_cpu.py.

◆ wf_com

script_roket_cpu.wf_com

Definition at line 705 of file script_roket_cpu.py.

◆ wfs

script_roket_cpu.wfs

Definition at line 694 of file script_roket_cpu.py.

◆ winddirs

list script_roket_cpu.winddirs = [0, 45, 90, 135, 180]

Definition at line 682 of file script_roket_cpu.py.

◆ windspeeds

list script_roket_cpu.windspeeds = [5., 10., 15., 20.]

Definition at line 683 of file script_roket_cpu.py.