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

Functions

def import_im (nb_im, path)
 
def create_P (bin_factor, size)
 
def calib_pyr (centers, wfs_numbers, bin_factor=1, crop_factor=0)
 
def pyr_aquisition (n=0)
 
def get_slope_pyrhr (npup, valid_pixel)
 
def crop_im (im, taille_sortie)
 
def binning_im (im, bin_factor)
 
def binning_im_2 (im, bin_factor)
 
def loop (n, d_valid_pix=[], d_P=[], offset=[], bool_fake_wfs=np.zeros(len(config.p_wfss)), bin_factor=[], crop_factor=[], cube_im=[])
 

Variables

string error = 'command line should be:"python -i test.py parameters_filename"\n with "parameters_filename" the path to the parameters file'
 
 param_file = sys.argv[1]
 
 filename = param_file.split('/')[-1]
 
 param_path = param_file.split(filename)[0]
 
string simul_name = ""
 
int clean = 1
 
dictionary matricesToLoad = {}
 
 param_dict = h5u.params_dictionary(config)
 
 c = ch.carmaWrap_context(devices=config.p_loop.devices)
 
 wfs
 
 tel
 
 atm
 
 dms = ao.dm_init(config.p_dms, config.p_wfss, wfs, config.p_geom, config.p_tel)
 
 tar
 
 rtc
 
 bool_fake_wfs = np.zeros(len(config.p_wfss), dtype=np.int32)
 
 crop_factor = np.zeros(sum(bool_fake_wfs))
 
 size_c = np.zeros(sum(bool_fake_wfs))
 
list centers_fake_wfs = []
 
list d_P = []
 
 offset = np.zeros((2, 4, sum(bool_fake_wfs)))
 
 size = np.zeros(sum(bool_fake_wfs))
 
 bin_factor = np.zeros(sum(bool_fake_wfs))
 
list d_valid_pix = []
 
int w = 0
 
int nb_im = 100
 
string path = '/home/sdurand/RecordPyrImages_2017_06_06_07h49/pyrImageCube.fits'
 
def pyr_im_cube = import_im(nb_im, path)
 
 fake_pos = np.where(bool_fake_wfs == 1)
 
 npup = config.p_wfss[w]._validsubsx.shape[0]
 
 valid_pix = np.zeros((2, npup), dtype=np.int32)
 
 cube_im
 

Function Documentation

◆ binning_im()

def closed_loop_fake_wfs.binning_im (   im,
  bin_factor 
)

Definition at line 208 of file closed_loop_fake_wfs.py.

208 def binning_im(im, bin_factor):
209 
210  bin_factor = np.int32(bin_factor)
211  size = im.shape[0]
212  size_bin = size / bin_factor
213  binimage = np.zeros((size_bin, size_bin), dtype=np.float32)
214 
215  a = np.arange(size)
216  xx, yy = np.meshgrid(a, a)
217  xx = xx / bin_factor
218  yy = yy / bin_factor
219  for i in range(size):
220  for j in range(size):
221  binimage[xx[i, j], yy[i, j]] += im[i, j]
222  return binimage / (bin_factor**2)
223 
224 
225 #@autojit

◆ binning_im_2()

def closed_loop_fake_wfs.binning_im_2 (   im,
  bin_factor 
)

Definition at line 226 of file closed_loop_fake_wfs.py.

226 def binning_im_2(im, bin_factor):
227  size = im.shape[0]
228  bin_factor = np.int32(bin_factor)
229  P = create_P(bin_factor, size) #
230  #GP = gpu.garray(P)
231  #Gim = gpu.garray(im)
232  binimage = ((P.T).dot(im)).dot(P)
233  #binimage = ((GP.T).dot(Gim)).dot(GP)
234 
235  return binimage / (bin_factor**2)
236 
237 
Here is the call graph for this function:

◆ calib_pyr()

def closed_loop_fake_wfs.calib_pyr (   centers,
  wfs_numbers,
  bin_factor = 1,
  crop_factor = 0 
)

Definition at line 130 of file closed_loop_fake_wfs.py.

130 def calib_pyr(centers, wfs_numbers, bin_factor=1, crop_factor=0):
131 
132  #initialisation
133  #offset 4 roi :
134  offset = np.zeros((2, 4))
135  j = [2, 1, 0, 3]
136  npup = config.p_wfss[wfs_numbers]._validsubsx.shape[0]
137  #decoupage 4 roi
138  for i in range(4):
139  #decoupage coordonnee
140  #x :
141  subx = config.p_wfss[wfs_numbers]._validsubsx[npup * (i) / 4:npup * (i + 1) / 4]
142  #y :
143  suby = config.p_wfss[wfs_numbers]._validsubsy[npup * (i) / 4:npup * (i + 1) / 4]
144  # calcul des 4 centres
145  center_compass = [((np.max(subx) - np.min(subx)) / 2.) + np.min(subx),
146  ((np.max(suby) - np.min(suby)) / 2.) + np.min(suby)]
147  # calcul des offsets
148  offset[:, i] = [
149  np.int32((centers[j[i]][0] - crop_factor / 2.) / bin_factor) -
150  center_compass[0],
151  np.int32((centers[j[i]][1] - crop_factor / 2.) / bin_factor) -
152  center_compass[1]
153  ]
154 
155  return offset
156 
157 

◆ create_P()

def closed_loop_fake_wfs.create_P (   bin_factor,
  size 
)

Definition at line 125 of file closed_loop_fake_wfs.py.

125 def create_P(bin_factor, size):
126  return np.repeat(
127  np.identity(size / bin_factor, dtype=np.float32), bin_factor, axis=0)
128 
129 
Here is the caller graph for this function:

◆ crop_im()

def closed_loop_fake_wfs.crop_im (   im,
  taille_sortie 
)

Definition at line 195 of file closed_loop_fake_wfs.py.

195 def crop_im(im, taille_sortie):
196 
197  #im_crop = np.zeros((taille_sortie,taille_sortie),dtype=np.float32)
198  size = im.shape[0]
199  im_crop = im[np.int32((size / 2.) - (taille_sortie / 2.)):np.int32(
200  (size / 2.) + (taille_sortie / 2)),
201  np.int32((size / 2.) - (taille_sortie / 2.)):np.int32(
202  (size / 2.) + (taille_sortie / 2.))]
203 
204  return im_crop
205 
206 
207 @autojit
Here is the caller graph for this function:

◆ get_slope_pyrhr()

def closed_loop_fake_wfs.get_slope_pyrhr (   npup,
  valid_pixel 
)

Definition at line 175 of file closed_loop_fake_wfs.py.

175 def get_slope_pyrhr(npup, valid_pixel):
176 
177  pup = np.zeros((npup / 4, 4))
178  j = [0, 2, 3, 1]
179  for i in range(4):
180  pup[:, i] = valid_pixel[(npup / 4) * j[i]:(npup / 4) * (j[i] + 1)]
181  tot = np.sum(pup, axis=1)
182  t = np.average(tot)
183 
184  gx = (pup[:, 0] + pup[:, 2] - (pup[:, 1] + pup[:, 3])) / t
185  gy = (pup[:, 0] + pup[:, 1] - (pup[:, 2] + pup[:, 3])) / t
186  #gz = (pup[:,0] - pup[:,1] - pup[:,2] + pup[:,3]) / t
187 
188  slope = np.append(gx, gy) * (
189  (config.p_wfss[0].pyr_ampl * config.p_wfss[0].Lambda * 1e-6) /
190  config.p_tel.diam) * (180 / np.pi) * 3600
191 
192  return slope
193 
194 

◆ import_im()

def closed_loop_fake_wfs.import_im (   nb_im,
  path 
)

Definition at line 115 of file closed_loop_fake_wfs.py.

115 def import_im(nb_im, path):
116  im = fits.open(path)
117  size = im[0].data.shape[0]
118  pyr_im_cube = np.zeros((nb_im, size, size), dtype=np.float32)
119  for i in range(nb_im):
120  pyr_im_cube[i] = im[i].data
121  im.close()
122  return pyr_im_cube
123 
124 

◆ loop()

def closed_loop_fake_wfs.loop (   n,
  d_valid_pix = [],
  d_P = [],
  offset = [],
  bool_fake_wfs = np.zeros(len(config.p_wfss)),
  bin_factor = [],
  crop_factor = [],
  cube_im = [] 
)

Definition at line 238 of file closed_loop_fake_wfs.py.

238 def loop(n, d_valid_pix=[], d_P=[], offset=[],
239  bool_fake_wfs=np.zeros(len(config.p_wfss)), bin_factor=[], crop_factor=[],
240  cube_im=[]):
241  print("----------------------------------------------------")
242  print("iter# | S.E. SR | L.E. SR | Est. Rem. | framerate")
243  print("----------------------------------------------------")
244  t0 = time.time()
245  #fake_pos = np.where(bool_fake_wfs==1)
246 
247  for i in range(n):
248  atm.move_atmos()
249  if (config.p_controllers[0].type_control == "geo"):
250  for t in range(config.p_target.ntargets):
251  tar.atmos_trace(t, atm, tel)
252  rtc.docontrol_geo(0, dms, tar, 0)
253  rtc.applycontrol(0, dms)
254  tar.dmtrace(0, dms)
255 
256  else:
257  for t in range(config.p_target.ntargets):
258  tar.atmos_trace(t, atm, tel)
259  tar.dmtrace(t, dms)
260 
261  fake_it = 0
262  for w in range(len(config.p_wfss)):
263  wfs.sensors_trace(w, "all", tel, atm, dms)
264  if bool_fake_wfs[w]: #verif fake_wfs
265  if (config.p_wfss[w].type_wfs == 'pyrhr'): # verif type_wfs = pyrhr
266  if (bin_factor[fake_it] > 1): # verif bining
267  if (cube_im == []): # verif bincube not here
268  pyr_im = pyr_aquisition(i) # aquistion image
269  pyr_im_crop = crop_im(
270  pyr_im,
271  pyr_im.shape[0] - crop_factor[w]) # crop image
272 
273  else:
274  pyr_im_crop = crop_im(cube_im[i],
275  cube_im[i].shape[0] - 2).astype(
276  np.float32) # crop image
277 
278  d_imhr = ch.carmaWrap_obj_Float2D(
279  ch.carmaWrap_context(), data=pyr_im_crop /
280  (bin_factor[fake_it]**2)) # inject pyr_image in GPU
281  d_imlr = d_P[fake_it].gemm(d_imhr, 't', 'n').gemm(
282  d_P[fake_it]) # bining GPU
283  else:
284  if (cube_im == []):
285  pyr_im = pyr_aquisition(i) # aquistion image
286  d_imlr = ch.carmaWrap_obj_Float2D(
287  ch.carmaWrap_context(),
288  data=pyr_im) # inject pyr_image in GPU
289  else:
290  d_imlr = ch.carmaWrap_obj_Float2D(
291  ch.carmaWrap_context(),
292  data=cube_im[i]) # inject pyr_image in GPU
293  # valable seulmement pour wf0 :
294  wfs.copy_pyrimg(
295  w, d_imlr, d_valid_pix[fake_it][0],
296  d_valid_pix[fake_it][1]) # envoie de l image pyramide
297 
298  elif (config.p_wfss[w].type_wfs == 'sh'): # verif type_wfs = pyrhr
299  print("TODO SH")
300  else:
301  print("error")
302  fake_it += 1 # increment for fake_wfs
303  else:
304  wfs.sensors_compimg(w) # normal wfs
305 
306  rtc.docentroids(0)
307  #slope_compass_0[:,i] = rtc.get_centroids(0)
308  rtc.docontrol(0)
309 
310  rtc.applycontrol(0, dms)
311 
312  if ((i + 1) % 100 == 0):
313  strehltmp = tar.get_strehl(0)
314  print(i + 1, "\t", strehltmp[0], "\t", strehltmp[1])
315  t1 = time.time()
316  print(" loop execution time:", t1 - t0, " (", n, "iterations), ", (t1 - t0) / n,
317  "(mean) ", n / (t1 - t0), "Hz")
318 
319 
320 #____________________________________________________________
321 # lib sesam
322 # sesam_class
323 # init vector fake_wfs -->
Here is the call graph for this function:

◆ pyr_aquisition()

def closed_loop_fake_wfs.pyr_aquisition (   n = 0)

Definition at line 158 of file closed_loop_fake_wfs.py.

158 def pyr_aquisition(n=0):
159 
160  #fonction d'aquisition d'image pour la pyramide
161  #lib sesame python
162  # cam 10gbit.py
163  # ten gb class
164  # get_image(1, num_cam) -->
165  #im_path = ['pyrimgforSeb1.fits','pyrimgforSeb2.fits','pyrimgforSeb3.fits','pyrimgforSeb4.fits','pyrimgforSeb5.fits','pyrimgforSeb6.fits']
166  #im = fits.open('/home/sdurand/im_pyr_banc/'+ im_path[n])
167  #pyr_im = im[0].data
168  path = '/home/sdurand/RecordPyrImages_2017_06_06_07h49/pyrImageCube.fits'
169  im = fits.open(path)
170  pyr_im = im[n].data
171  im.close()
172  return pyr_im
173 
174 
Here is the caller graph for this function:

Variable Documentation

◆ atm

closed_loop_fake_wfs.atm
Initial value:
1 = ao.atmos_init(c, config.p_atmos, config.p_tel, config.p_geom, config.p_loop,
2  config.p_wfss, wfs, config.p_target, clean=clean,
3  load=matricesToLoad)

Definition at line 81 of file closed_loop_fake_wfs.py.

◆ bin_factor

closed_loop_fake_wfs.bin_factor = np.zeros(sum(bool_fake_wfs))

Definition at line 335 of file closed_loop_fake_wfs.py.

◆ bool_fake_wfs

closed_loop_fake_wfs.bool_fake_wfs = np.zeros(len(config.p_wfss), dtype=np.int32)

Definition at line 324 of file closed_loop_fake_wfs.py.

◆ c

closed_loop_fake_wfs.c = ch.carmaWrap_context(devices=config.p_loop.devices)

Definition at line 73 of file closed_loop_fake_wfs.py.

◆ centers_fake_wfs

list closed_loop_fake_wfs.centers_fake_wfs = []

Definition at line 331 of file closed_loop_fake_wfs.py.

◆ clean

int closed_loop_fake_wfs.clean = 1

Definition at line 59 of file closed_loop_fake_wfs.py.

◆ crop_factor

closed_loop_fake_wfs.crop_factor = np.zeros(sum(bool_fake_wfs))

Definition at line 329 of file closed_loop_fake_wfs.py.

◆ cube_im

closed_loop_fake_wfs.cube_im

Definition at line 396 of file closed_loop_fake_wfs.py.

◆ d_P

closed_loop_fake_wfs.d_P = []

Definition at line 332 of file closed_loop_fake_wfs.py.

◆ d_valid_pix

closed_loop_fake_wfs.d_valid_pix = []

Definition at line 336 of file closed_loop_fake_wfs.py.

◆ dms

closed_loop_fake_wfs.dms = ao.dm_init(config.p_dms, config.p_wfss, wfs, config.p_geom, config.p_tel)

Definition at line 87 of file closed_loop_fake_wfs.py.

◆ error

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

Definition at line 29 of file closed_loop_fake_wfs.py.

◆ fake_pos

closed_loop_fake_wfs.fake_pos = np.where(bool_fake_wfs == 1)

Definition at line 359 of file closed_loop_fake_wfs.py.

◆ filename

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

Definition at line 35 of file closed_loop_fake_wfs.py.

◆ matricesToLoad

closed_loop_fake_wfs.matricesToLoad = {}

Definition at line 60 of file closed_loop_fake_wfs.py.

◆ nb_im

int closed_loop_fake_wfs.nb_im = 100

Definition at line 353 of file closed_loop_fake_wfs.py.

◆ npup

closed_loop_fake_wfs.npup = config.p_wfss[w]._validsubsx.shape[0]

Definition at line 380 of file closed_loop_fake_wfs.py.

◆ offset

closed_loop_fake_wfs.offset = np.zeros((2, 4, sum(bool_fake_wfs)))

Definition at line 333 of file closed_loop_fake_wfs.py.

◆ param_dict

closed_loop_fake_wfs.param_dict = h5u.params_dictionary(config)

Definition at line 63 of file closed_loop_fake_wfs.py.

◆ param_file

closed_loop_fake_wfs.param_file = sys.argv[1]

Definition at line 33 of file closed_loop_fake_wfs.py.

◆ param_path

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

Definition at line 36 of file closed_loop_fake_wfs.py.

◆ path

string closed_loop_fake_wfs.path = '/home/sdurand/RecordPyrImages_2017_06_06_07h49/pyrImageCube.fits'

Definition at line 354 of file closed_loop_fake_wfs.py.

◆ pyr_im_cube

closed_loop_fake_wfs.pyr_im_cube = import_im(nb_im, path)

Definition at line 355 of file closed_loop_fake_wfs.py.

◆ rtc

closed_loop_fake_wfs.rtc
Initial value:
1 = ao.rtc_init(tel, wfs, config.p_wfss, dms, config.p_dms, config.p_geom,
2  config.p_rtc, config.p_atmos, atm, config.p_tel, config.p_loop,
3  clean=clean, simul_name=simul_name, load=matricesToLoad)

Definition at line 96 of file closed_loop_fake_wfs.py.

◆ simul_name

string closed_loop_fake_wfs.simul_name = ""

Definition at line 52 of file closed_loop_fake_wfs.py.

◆ size

closed_loop_fake_wfs.size = np.zeros(sum(bool_fake_wfs))

Definition at line 334 of file closed_loop_fake_wfs.py.

◆ size_c

closed_loop_fake_wfs.size_c = np.zeros(sum(bool_fake_wfs))

Definition at line 330 of file closed_loop_fake_wfs.py.

◆ tar

closed_loop_fake_wfs.tar
Initial value:
1 = ao.target_init(c, tel, config.p_target, config.p_atmos, config.p_geom,
2  config.p_tel, config.p_dms, config.p_wfss)

Definition at line 91 of file closed_loop_fake_wfs.py.

◆ tel

closed_loop_fake_wfs.tel

Definition at line 76 of file closed_loop_fake_wfs.py.

◆ valid_pix

closed_loop_fake_wfs.valid_pix = np.zeros((2, npup), dtype=np.int32)

Definition at line 381 of file closed_loop_fake_wfs.py.

◆ w

int closed_loop_fake_wfs.w = 0

Definition at line 340 of file closed_loop_fake_wfs.py.

◆ wfs

closed_loop_fake_wfs.wfs

Definition at line 76 of file closed_loop_fake_wfs.py.