2 Created on Wed Oct 5 14:28:23 2016
11 sys.path.append(
'/home/fferreira/compass/shesha/test/roket/tools/')
12 sys.path.append(
'/home/fferreira/compass/shesha/test/gamora/')
14 import roket_exploitation
as rexp
17 import matplotlib.pyplot
as plt
21 font = {
'family':
'normal',
'weight':
'bold',
'size': 22}
23 matplotlib.rc(
'font', **font)
27 otftel, otf, psf, gpu = gamora.psf_rec_Vii(filename)
32 cov_err = rexp.get_coverr_independence(filename)
33 otfteli, otf2i, psfi, gpu = gamora.psf_rec_Vii(filenames[11], covmodes=cov_err)
38 f = h5py.File(filename,
'r')
39 psf_compass = np.fft.fftshift(f[
"psf"][:])
48 N1 = np.linalg.inv(Nact)
49 Caniso = N1.dot(Caniso).dot(N1)
50 Cbp = N1.dot(Cbp).dot(N1)
51 Ccov = N1.dot(Ccov).dot(N1)
55 Ctt[:-2, :-2] = Ccov_filtered
59 tmp[:-2, :-2] = Caniso_filtered
63 tmp[:-2, :-2] = Cbp_filtered
68 cov_err = P.dot(Ctt).dot(P.T)
69 otftels, otf2s, psfs, gpu = gamora.psf_rec_Vii(filename, fitting=
False,
70 cov=cov_err.astype(np.float32))
72 print(
"PSF estimated in ", tac - tic,
" seconds")
73 t = f[
"tomography"][:]
76 tb = tb.dot(tb.T) / float(tb.shape[1])
77 cov_err = P.dot(tb).dot(P.T)
78 otftel, otf2, psf, gpu = gamora.psf_rec_Vii(filename, fitting=
False,
79 cov=cov_err.astype(np.float32))
81 Lambda_tar = f.attrs[
"target.Lambda"][0]
82 RASC = 180 / np.pi * 3600.
83 pixsize = Lambda_tar * 1e-6 / (
84 psf.shape[0] * f.attrs[
"tel_diam"] / f.attrs[
"pupdiam"]) * RASC
85 x = (np.arange(psf.shape[0]) - psf.shape[0] / 2) * pixsize / (
86 Lambda_tar * 1e-6 / f.attrs[
"tel_diam"] * RASC)
89 plt.semilogy(x, psf[psf.shape[0] / 2, :], color=
"blue")
90 plt.semilogy(x, psfs[psf.shape[0] / 2, :], color=
"red")
91 plt.xlabel(
"X-axis angular distance [units of lambda/D]")
92 plt.ylabel(
"Normalized intensity")
93 plt.legend([
"PSF exp",
"PSF model"])
96 plt.legend([
"PSF exp",
"PSF model"])
98 plt.semilogy(x, psf[:, psf.shape[0] / 2], color=
"blue")
99 plt.semilogy(x, psfs[:, psf.shape[0] / 2], color=
"red")
100 plt.xlabel(
"Y-axis angular distance [units of lambda/D]")
101 plt.ylabel(
"Normalized intensity")
104 plt.legend([
"PSF exp",
"PSF model"])
107 #plt.semilogy(x,psfc[psf.shape[0]/2,:],color="purple")
109 plt.semilogy(x,psfs[psf.shape[0]/2,:],color="black")
110 #plt.legend(["PSF rec","PSF ind. assumption", "PSF COMPASS", "PSF corrected", "PSF synth"])
111 plt.legend(["PSF rec","PSF ind. assumption", "PSF COMPASS", "PSF synth"])
113 plt.legend(["PSF rec","PSF ind. assumption", "PSF COMPASS", "PSF corrected"])
115 plt.semilogy(x,psfs[psf.shape[0]/2,:],color="purple")
116 plt.legend(["PSF rec","PSF ind. assumption", "PSF COMPASS", "PSF synth"])
119 plt.legend(["PSF rec","PSF ind. assumption", "PSF COMPASS"])
123 return psf_compass, psf, psfs
127 IF, T = rexp.get_IF(filename)
133 delta = IF.T.dot(IF).toarray() / N
136 Tp = np.ones((T.shape[0], T.shape[1] + 1))
138 deltaT = IF.T.dot(Tp) / N
140 tau = np.linalg.inv(delta).dot(deltaT)
144 tdt = tau.T.dot(delta).dot(tau)
145 subTT = tau.dot(np.linalg.inv(tdt)).dot(tau.T).dot(delta)
148 return G.T.dot(C).dot(G)
152 IF, T = rexp.get_IF(filename)
158 delta = IF.T.dot(IF).toarray() / N
160 deltaT = IF.T.dot(T) / N
162 tau = np.linalg.inv(delta).dot(deltaT)
166 tdt = tau.T.dot(delta).dot(tau)
167 subTT = tau.dot(np.linalg.inv(tdt)).dot(tau.T).dot(delta)
170 return G.T.dot(C).dot(G)
174 f = h5py.File(filename,
'r')
175 Lambda_tar = f.attrs[
"target.Lambda"][0]
176 Lambda_wfs = f.attrs[
"wfs.Lambda"]
177 dt = f.attrs[
"ittime"]
178 gain = f.attrs[
"gain"]
179 wxpos = f.attrs[
"wfs.xpos"][0]
180 wypos = f.attrs[
"wfs.ypos"][0]
181 r0 = f.attrs[
"r0"] * (Lambda_tar / Lambda_wfs)**(6. / 5.)
182 RASC = 180. / np.pi * 3600.
183 xpos = f[
"dm.xpos"][:]
184 ypos = f[
"dm.ypos"][:]
185 p2m = f.attrs[
"tel_diam"] / f.attrs[
"pupdiam"]
186 pupshape = int(2**np.ceil(np.log2(f.attrs[
"pupdiam"]) + 1))
187 xactu = (xpos - pupshape / 2) * p2m
188 yactu = (ypos - pupshape / 2) * p2m
189 Ccov = np.zeros((xpos.size, xpos.size))
190 Caniso = np.zeros((xpos.size, xpos.size))
191 Cbp = np.zeros((xpos.size, xpos.size))
192 xx = np.tile(xactu, (xactu.shape[0], 1))
193 yy = np.tile(yactu, (yactu.shape[0], 1))
197 for l
in range(f.attrs[
"nscreens"]):
198 H = f.attrs[
"atm.alt"][l]
199 L0 = f.attrs[
"L0"][l]
200 speed = f.attrs[
"windspeed"][l]
201 theta = f.attrs[
"winddir"][l] * np.pi / 180.
202 frac = f.attrs[
"frac"][l]
204 Htheta = np.linalg.norm([wxpos, wypos]) / RASC * H
205 vdt = speed * dt / gain
207 M = np.zeros((xpos.size, xpos.size))
211 angleht = np.arctan2(wypos, wxpos)
212 fc = xactu[1] - xactu[0]
215 M = np.linalg.norm([xij, yij], axis=0)
216 Mvdt = np.linalg.norm([xij - vdt * np.cos(theta), yij - vdt * np.sin(theta)],
218 Mht = np.linalg.norm(
219 [xij - Htheta * np.cos(angleht), yij - Htheta * np.sin(angleht)], axis=0)
220 Mhvdt = np.linalg.norm([
221 xij - vdt * np.cos(theta) - Htheta * np.cos(angleht),
222 yij - vdt * np.sin(theta) - Htheta * np.sin(angleht)
232 Ccov += 0.5 * (Dphi.dphi_lowpass(Mhvdt,fc,L0,tabx,taby) - Dphi.dphi_lowpass(Mht,fc,L0,tabx,taby) \
233 - Dphi.dphi_lowpass(Mvdt,fc,L0,tabx,taby) + Dphi.dphi_lowpass(M,fc,L0,tabx,taby)) * (1./r0)**(5./3.) * frac
235 Caniso += 0.5 * (Dphi.dphi_lowpass(Mht, fc, L0, tabx, taby) - Dphi.dphi_lowpass(
236 M, fc, L0, tabx, taby)) * (1. / r0)**(5. / 3.) * frac
237 Cbp += 0.5 * (Dphi.dphi_lowpass(Mvdt, fc, L0, tabx, taby) - Dphi.dphi_lowpass(
238 M, fc, L0, tabx, taby)) * (1. / r0)**(5. / 3.) * frac
241 Sp = (Lambda_tar / (2 * np.pi))**2
243 return (Caniso + Caniso.T) * Sp, (Cbp + Cbp.T) * Sp, Ccov * Sp
247 C = np.zeros((Ccov.shape[0] + 2, Ccov.shape[0] + 2))
248 IF, T = rexp.get_IF(filename)
252 deltaTT = T.T.dot(T) / N
253 deltaF = IF.T.dot(T) / N
254 pzt2tt = np.linalg.inv(deltaTT).dot(deltaF.T)
257 C[-2:, -2:] = pzt2tt.dot(CTT).dot(pzt2tt.T)
264 nmodes = (files[0])[
"P"][:].shape[0]
265 P = (files[0])[
"P"][:]
266 xpos = files[0].attrs[
"wfs.xpos"][0]
267 ypos = files[0].attrs[
"wfs.ypos"][0]
268 contributors = [
"tomography",
"bandwidth"]
269 Lambda_tar = files[0].attrs[
"target.Lambda"][0]
270 Lambda_wfs = files[0].attrs[
"wfs.Lambda"][0]
271 L0 = files[0].attrs[
"L0"][0]
272 dt = files[0].attrs[
"ittime"]
273 H = files[0].attrs[
"atm.alt"][0]
274 RASC = 180 / np.pi * 3600.
275 Htheta = np.linalg.norm(
278 r0 = files[0].attrs[
"r0"] * (Lambda_tar / Lambda_wfs)**(6. / 5.)
280 vartomo = np.zeros((nfiles, nmodes))
281 varbp = np.zeros((nfiles, nmodes))
282 vartot = np.zeros((nfiles, nmodes))
283 theta = np.zeros(nfiles)
284 speeds = np.zeros(nfiles)
285 gain = np.zeros(nfiles)
291 print(
"Loading data...")
293 vartot[ind, :] = rexp.variance(f, contributors) * ((2 * np.pi / Lambda_tar)**2)
294 vartomo[ind, :] = rexp.variance(f, [
"tomography"]) * (
295 (2 * np.pi / Lambda_tar)**2)
296 varbp[ind, :] = rexp.variance(f, [
"bandwidth"]) * ((2 * np.pi / Lambda_tar)**2)
297 theta[ind] = f.attrs[
"winddir"][0]
298 speeds[ind] = f.attrs[
"windspeed"][0]
299 gain[ind] = float(
'%.1f' % f.attrs[
"gain"][0])
301 print(ind,
"/", len(files))
303 covar = (vartot - (vartomo + varbp)) / 2.
305 stot = np.sum(vartot, axis=1)
306 sbp = np.sum(varbp, axis=1)
307 stomo = np.sum(vartomo, axis=1)
308 scov = np.sum(covar, axis=1)
310 return stot, sbp, stomo, scov, covar
314 f = h5py.File(filename,
'r')
315 Lambda_tar = f.attrs[
"target.Lambda"][0]
316 RASC = 180 / np.pi * 3600.
317 pixsize = Lambda_tar * 1e-6 / (
318 psf.shape[0] * f.attrs[
"tel_diam"] / f.attrs[
"pupdiam"]) * RASC
319 x = (np.arange(psf.shape[0]) - psf.shape[0] / 2) * pixsize / (
320 Lambda_tar * 1e-6 / f.attrs[
"tel_diam"] * RASC)
321 w = int(N * (Lambda_tar * 1e-6 / f.attrs[
"tel_diam"] * RASC) / pixsize)
322 mid = psf.shape[0] / 2
323 psfe = psf[mid - w:mid + w, mid - w:mid + w]
325 plt.matshow(np.log10(psfe))
326 xt = np.linspace(0, psfe.shape[0] - 1, 6).astype(np.int32)
327 yt = np.linspace(-N, N, 6).astype(np.int32)
332 return psf[mid - w:mid + w, mid - w:mid + w]
336 f = h5py.File(filename,
'r')
337 Lambda_tar = f.attrs[
"target.Lambda"][0]
338 RASC = 180 / np.pi * 3600.
339 pixsize = Lambda_tar * 1e-6 / (
340 psf.shape[0] * f.attrs[
"tel_diam"] / f.attrs[
"pupdiam"]) * RASC
341 x = (np.arange(psf.shape[0]) - psf.shape[0] / 2) * pixsize / (
342 Lambda_tar * 1e-6 / f.attrs[
"tel_diam"] * RASC)
345 plt.semilogy(x, psf[psf.shape[0] / 2, :], color=
"blue")
346 plt.semilogy(x, psfs[psf.shape[0] / 2, :], color=
"red")
347 plt.xlabel(
"X-axis angular distance [units of lambda/D]")
348 plt.ylabel(
"Normalized intensity")
349 plt.legend([
"PSF exp",
"PSF model"])
353 plt.semilogy(x, psf[:, psf.shape[0] / 2], color=
"blue")
354 plt.semilogy(x, psfs[:, psf.shape[0] / 2], color=
"red")
355 plt.xlabel(
"Y-axis angular distance [units of lambda/D]")
356 plt.ylabel(
"Normalized intensity")
357 plt.legend([
"PSF exp",
"PSF model"])
364 p = 1j * 2 * np.pi * f
365 return np.abs(1 / (1 + g * Fe / p * np.exp(-dt * p)))**2
369 p = 1j * 2 * np.pi * f
370 return np.abs(1 - np.exp(-p * dt / g))**2
374 rfile = h5py.File(filename,
'r')
375 v = rfile.attrs[
"windspeed"][0]
376 dt = rfile.attrs[
"ittime"]
378 g = rfile.attrs[
"gain"]
379 Lambda_tar = rfile.attrs[
"target.Lambda"][0]
380 Lambda_wfs = rfile.attrs[
"wfs.Lambda"][0]
381 r0 = rfile.attrs[
"r0"] * (Lambda_tar / Lambda_wfs)**(6. / 5.)
382 d = rfile.attrs[
"tel_diam"] / rfile.attrs[
"nxsub"]
384 f = np.linspace(0.1, fc * 1.5, 1000)
385 H =
Hcor(f, Fe, g, dt)
389 plt.plot(f, Hr, color=
"red")
390 plt.plot([fc, fc], [H.min(), Hr.max()])
394 datapath =
'/home/fferreira/Data/correlation/'
395 filenames = glob.glob(datapath +
'roket_8m_1layer_dir*_cpu.h5')
398 files.append(h5py.File(f,
'r'))
400 tabx, taby = Dphi.tabulateIj0()
402 nfiles = len(filenames)
403 theta = np.zeros(nfiles)
404 speeds = np.zeros(nfiles)
405 gain = np.zeros(nfiles)
406 SRcompass = np.zeros(nfiles)
407 SRroket = np.zeros(nfiles)
408 SRi = np.zeros(nfiles)
409 fROKET = h5py.File(
'ROKETStudy.h5',
'r')
410 psfr = fROKET[
"psf"][:]
411 psfi = fROKET[
"psfi"][:]
412 nrjcompass = np.zeros(nfiles)
413 nrjroket = np.zeros(nfiles)
414 nrji = np.zeros(nfiles)
418 theta[ind] = f.attrs[
"winddir"][0]
419 speeds[ind] = f.attrs[
"windspeed"][0]
420 gain[ind] = float(
'%.1f' % f.attrs[
"gain"][0])
421 SRcompass[ind] = f[
"psf"][:].max()
422 SRroket[ind] = psfr[:, :, ind].max()
423 SRi[ind] = psfi[:, :, ind].max()
424 nrjcompass[ind] = np.sum(
425 ensquare_PSF(filenames[ind], np.fft.fftshift(f[
"psf"][:]),
426 5)) / f[
"psf"][:].sum()
427 nrjroket[ind] = np.sum(
ensquare_PSF(filenames[ind], psfr[:, :, ind],
428 5)) / psfr[:, :, ind].sum()
429 nrji[ind] = np.sum(
ensquare_PSF(filenames[ind], psfi[:, :, ind],
430 5)) / psfi[:, :, ind].sum()
433 eSR = np.abs(SRroket-SRcompass) / SRcompass
434 eSRi = np.abs(SRi - SRcompass) / SRcompass
435 enrj = np.abs(nrjroket-nrjcompass) / nrjcompass
436 enrji = np.abs(nrji-nrjcompass) / nrjcompass
439 plt.scatter(SRcompass,SRroket,s=200)
440 plt.plot([SRcompass.min(),SRcompass.max()],[SRcompass.min(),SRcompass.max()],color="red")
441 plt.xlabel("COMPASS Strehl ratio")
442 plt.ylabel("ROKET Strehl ratio")
444 plt.scatter(nrjcompass,nrjroket,s=200)
445 plt.plot([nrjcompass.min(),nrjcompass.max()],[nrjcompass.min(),nrjcompass.max()],color="red")
446 plt.xlabel("COMPASS PSF ensquared energy")
447 plt.ylabel("ROKET PSF ensquared energy")
449 colors = ["blue","red","green","black","yellow"]
452 for t in np.unique(theta):
453 ind = np.where(theta == t)
454 plt.scatter(SRcompass[ind],SRi[ind],s=200,color=colors[indc])
456 plt.legend(["0 deg","45 deg","90 deg","135 deg","180 deg"])
457 plt.plot([SRcompass.min(),SRcompass.max()],[SRcompass.min(),SRcompass.max()],color="red")
458 plt.xlabel("COMPASS Strehl ratio")
459 plt.ylabel("ROKET Strehl ratio")
463 for t in np.unique(theta):
464 ind = np.where(theta == t)
465 plt.scatter(nrjcompass[ind],nrji[ind],s=200,color=colors[indc])
467 plt.legend(["0 deg","45 deg","90 deg","135 deg","180 deg"])
468 plt.plot([nrjcompass.min(),nrjcompass.max()],[nrjcompass.min(),nrjcompass.max()],color="red")
469 plt.xlabel("COMPASS PSF ensquared energy")
470 plt.ylabel("ROKET PSF ensquared energy")
472 f = h5py.File(
'corStudy_Nact.h5',
'r')
477 SR = np.max(psf, axis=(0, 1))
478 SRs = np.max(psfs, axis=(0, 1))
480 colors = [
"blue",
"red",
"green"]
483 for g
in np.unique(gain):
484 plt.subplot(2, 2, k + 1)
485 plt.title(
"g = %.1f" % (g))
486 for i
in range(len(colors)):
488 v = np.unique(speeds)[i]
489 ind = np.where((gain == g) * (speeds == v))
490 plt.scatter(SR[ind], SRs[ind], color=c, s=200)
491 plt.legend([
"10 m/s",
"15 m/s",
"20 m/s"], loc=2)
492 plt.xlabel(
"SR ROKET")
493 plt.ylabel(
"SR model")
494 plt.plot([SR.min(), SR.max()], [SR.min(), SR.max()], color=
"red")
497 # Illustration du probleme
498 #psf_compass, psf, psfs = compute_and_compare_PSFs(filenames[13],plot=True)
499 # psf_compass = np.zeros((2048,2048,len(filenames)))
500 # psf = np.zeros((2048,2048,len(filenames)))
501 # psfi = np.zeros((2048,2048,len(filenames)))
502 # SR = np.zeros(len(filenames))
503 # SRi = np.zeros(len(filenames))
504 # SRcompass = np.zeros(len(filenames))
505 # nrj20 = np.zeros(len(filenames))
506 # nrj20s = np.zeros(len(filenames))
507 # nrj5 = np.zeros(len(filenames))
508 # nrj5i = np.zeros(len(filenames))
509 # nrj5compass = np.zeros(len(filenames))
512 # for f in filenames:
513 # ff = h5py.File(f,'r')
514 # psf_compass[:,:,cc] = np.fft.fftshift(ff["psf"][:])
515 # psf[:,:,cc] = compute_psf(f)
516 # psfi[:,:,cc] = compute_psf_independence(f)
517 # #psf_compass, psf[:,:,cc], psfs[:,:,cc] = compute_and_compare_PSFs(f)
518 # SR[cc] = psf[:,:,cc].max()
519 # SRi[cc] = psfi[:,:,cc].max()
520 # SRcompass[cc] = psf_compass[:,:,cc].max()
521 # # nrj20[cc] = ensquare_PSF(f,psf[:,:,cc],20).sum()/psf[:,:,cc].sum()
522 # # nrj20s[cc] = ensquare_PSF(f,psfs[:,:,cc],20).sum()/psfs[:,:,cc].sum()
523 # nrj5[cc] = ensquare_PSF(f,psf[:,:,cc],5).sum()/psf[:,:,cc].sum()
524 # nrj5i[cc] = ensquare_PSF(f,psfi[:,:,cc],5).sum()/psfi[:,:,cc].sum()
525 # nrj5compass[cc] = ensquare_PSF(f,psf_compass[:,:,cc],5).sum()/psf_compass[:,:,cc].sum()
531 # f = h5py.File("ROKETStudy.h5")
533 # f["filenames"] = filenames
535 # f["psf_compass"] = psf_compass
538 # f["SRcompass"] = SRcompass
539 # #f["nrj20"] = nrj20
540 # #f["nrj20s"] = nrj20s
543 # f["nrj5compass"] = nrj5compass
553 files.append(h5py.File(f,'r'))
558 nmodes = (files[0])["P"][:].shape[0]
559 P = (files[0])["P"][:]
560 xpos = files[0].attrs["wfs.xpos"][0]
561 ypos = files[0].attrs["wfs.ypos"][0]
562 contributors = ["tomography", "bandwidth"]
563 Lambda_tar = files[0].attrs["target.Lambda"][0]
564 Lambda_wfs = files[0].attrs["wfs.Lambda"][0]
565 L0 = files[0].attrs["L0"][0]
566 dt = files[0].attrs["ittime"]
567 H = files[0].attrs["atm.alt"][0]
568 RASC = 180/np.pi * 3600.
569 Htheta = np.linalg.norm([xpos,ypos])/RASC*H# np.sqrt(2)*4/RASC*H # Hardcoded for angular separation of sqrt(2)*4 arcsec
570 r0 = files[0].attrs["r0"] * (Lambda_tar/Lambda_wfs)**(6./5.)
572 vartomo = np.zeros((nfiles,nmodes))
573 varbp = np.zeros((nfiles,nmodes))
574 vartot = np.zeros((nfiles,nmodes))
575 theta = np.zeros(nfiles)
576 speeds = np.zeros(nfiles)
577 gain = np.zeros(nfiles)
579 # Illustration du probleme
580 otftel, otf2, psf, gpu = gamora.psf_rec_Vii(filenames[11])
581 cov_err = rexp.get_coverr_independence(filenames[11])
582 otfteli, otf2i, psfi, gpu = gamora.psf_rec_Vii(filenames[11],covmodes=cov_err)
583 psf_compass = np.fft.fftshift(files[11]["psf"][:])
584 RASC = 180/np.pi*3600.
585 pixsize = Lambda_tar*1e-6 / (psf.shape[0] * 8./640) * RASC
586 x = (np.arange(psf.shape[0]) - psf.shape[0]/2) * pixsize / (Lambda_tar*1e-6/8. * RASC)
587 plt.semilogy(x,psf[psf.shape[0]/2,:])
588 plt.semilogy(x,psfi[psf.shape[0]/2,:],color="green")
589 plt.semilogy(x,psf_compass[psf.shape[0]/2,:],color="red")
590 plt.xlabel("Angular distance [units of lambda/D]")
591 plt.ylabel("Normalized intensity")
592 plt.legend(["PSF rec","PSF ind. assumption", "PSF COMPASS"])
595 # data[:,0,i] = var(tomo+bp) for file #i
596 # data[:,1,i] = var(tomo) for file #i
597 # data[:,2,i] = var(bp) for file #i
598 # data[:,3,i] = var(tomo)+var(bp) for file #i
600 print("Loading data...")
602 #vartot[ind,:] = rexp.variance(f, contributors) * ((2*np.pi/Lambda_tar)**2)
603 #vartomo[ind,:] = rexp.variance(f, ["tomography"]) * ((2*np.pi/Lambda_tar)**2)
604 #varbp[ind,:] = rexp.variance(f, ["bandwidth"]) * ((2*np.pi/Lambda_tar)**2)
605 theta[ind] = f.attrs["winddir"][0]
606 speeds[ind] = f.attrs["windspeed"][0]
607 gain[ind] = float('%.1f' % f.attrs["gain"][0])
609 print(ind,"/",len(files))
611 covar = (vartot - (vartomo+varbp))/2.
613 stot = np.sum(vartot,axis=1)
614 sbp = np.sum(varbp,axis=1)
615 stomo = np.sum(vartomo,axis=1)
616 scov = np.sum(covar,axis=1)
620 print("Building models...")
622 Htheta = np.ones(nfiles) * Htheta
623 gamma = np.arctan2(ypos,xpos) - theta*np.pi/180.
624 rho = np.sqrt(Htheta**2 + (vdt)**2 - 2*Htheta*vdt*np.cos(np.pi-gamma))
625 # Covariance matrices models on actuators space
626 xpos = files[11]["dm.xpos"][:]
627 ypos = files[11]["dm.ypos"][:]
628 p2m = files[11].attrs["tel_diam"] / files[11].attrs["pupdiam"]
629 pupshape = long(2 ** np.ceil(np.log2(files[11].attrs["pupdiam"]) + 1))
630 xactu = (xpos - pupshape/2) * p2m
631 yactu = (ypos - pupshape/2) * p2m
632 M = np.zeros((1304,1304))
636 angleht = np.arctan2(files[11].attrs["wfs.ypos"][0],files[11].attrs["wfs.xpos"][0])
637 anglehvdt = gamma/2. - theta*np.pi/180.
638 thetar = theta*np.pi/180.
640 for i in range(1304):
641 for j in range(1304):
642 Mvdt[i,j] = (np.sqrt((xactu[i]-(xactu[j]+vdt[11]*np.cos(thetar[11])))**2 + (yactu[i]-(yactu[j]+vdt[11]*np.sin(thetar[11])))**2))
643 M[i,j] = (np.sqrt((xactu[i]-xactu[j])**2 + (yactu[i]-yactu[j])**2))
644 Mht[i,j] = (np.sqrt((xactu[i]-(xactu[j]+Htheta[11]*np.cos(angleht)))**2 + (yactu[i]-(yactu[j]+Htheta[11]*np.sin(angleht)))**2))
645 #Mhvdt[i,j] = (np.sqrt((xactu[i]-(xactu[j]+rho[11]*np.cos(anglehvdt[11])))**2 + (yactu[i]-(yactu[j]+rho[11]*np.sin(anglehvdt[11])))**2))
646 Mhvdt[i,j] = (np.sqrt(((xactu[i]-vdt[11]*np.cos(thetar[11]))-(xactu[j]+Htheta[11]*np.cos(angleht)))**2 + ((yactu[i]-vdt[11]*np.sin(thetar[11]))-(yactu[j]+Htheta[11]*np.sin(angleht)))**2))
648 Ccov = (Dphi.dphi_lowpass(Mhvdt,0.2,L0,tabx,taby) - Dphi.dphi_lowpass(Mht,0.2,L0,tabx,taby) \
649 - Dphi.dphi_lowpass(Mvdt,0.2,L0,tabx,taby) + Dphi.dphi_lowpass(M,0.2,L0,tabx,taby)) * (1/r0)**(5./3.)
652 mtomo = Dphi.dphi_lowpass(Htheta,0.2,L0, tabx, taby) * (1/r0)**(5./3.)
653 mbp = Dphi.dphi_lowpass(vdt ,0.2, L0, tabx, taby) * (1/r0)**(5./3.)
654 mtot = Dphi.dphi_lowpass(rho,0.2,L0,tabx,taby) * (1/r0)**(5./3.)
657 print("Computing piston correction...")
658 pup = gamora.get_pup(filenames[11])
659 r = np.zeros((8192,8192))
660 p2m = files[11].attrs["tel_diam"]/pup.shape[0]
661 Npts = files[11]["indx_pup"].size
662 for k in range(r.shape[0]):
663 for j in range(r.shape[0]):
664 r[k,j] = np.sqrt((k-r.shape[0]/2+0.5)**2+(j-r.shape[0]/2+0.5)**2) * p2m
666 ipup = np.zeros((8192,8192))
667 ipup[3776:3776+640,3776:3776+640] = pup
668 dphi_map = Dphi.dphi_lowpass(r,0.2,L0,tabx,taby) * (1/r0)**(5./3.)
669 fpup = np.fft.fft2(ipup)#,s=[8192,8192])
670 fdphi = np.fft.fft2(dphi_map)#,s=[8192,8192])
671 fconv = fpup * fpup * fdphi
672 dconv = np.fft.ifft2(fconv).real / Npts / Npts
673 mini = np.where(dconv == dconv.min())
674 dutil = dconv[mini[0][0],mini[1][0]:]
675 #Avdt = dconv[mini[0]+(vdt/p2m).astype(np.int16),mini[1]] - dconv[mini]
676 Pbp = np.interp(vdt/p2m,np.arange(dutil.shape[0]),dutil) - dutil[0]
677 Ptomo = (np.interp(Htheta/gain/p2m,np.arange(dutil.shape[0]),dutil) - dutil[0])*gain**2
678 Ptot = np.interp(rho/p2m,np.arange(dutil.shape[0]),dutil) - dutil[0]
683 mcov = (-mtomo - mbp + mtot)*0.5
687 m = (np.arange(nmodes)+1)**(-5/6.)
689 m = m * (mcov[11] / (2*np.pi/Lambda_tar)**2)
692 cov_err2 = P.dot(cov_err).dot(P.T) + 2*np.diag(m)
693 otftelc, otf2c, psfc, gpu = gamora.psf_rec_Vii(filenames[11],cov=cov_err2.astype(np.float32))
695 plt.semilogy(x,psf_compass[psf.shape[0]/2,:],color="red")
696 plt.semilogy(x,psfi[psf.shape[0]/2,:],color="green")
697 plt.semilogy(x,psfc[psf.shape[0]/2,:],color="blue")
698 plt.xlabel("Angular distance [units of lambda/D]")
699 plt.ylabel("Normalized intensity")
700 plt.legend([ "PSF COMPASS","PSF ind. assumption","PSF corrected"])
703 xpos = files[11]["dm.xpos"][:]
704 ypos = files[11]["dm.ypos"][:]
705 dm_dim = files[11]["dm_dim"].value
706 xpos -= (pupshape-dm_dim)/2
707 ypos -= (pupshape-dm_dim)/2
708 influ = np.load("influ.npy")
709 influ2 = np.zeros((dm_dim,dm_dim))
711 indx_pup = files[11]["indx_pup"][:]
712 pup = np.zeros((dm_dim,dm_dim)).flatten()
714 pup = pup.reshape((dm_dim,dm_dim))
716 influshape = influ.shape[0]
717 A = np.zeros((xpos.size,xpos.size))
719 xx = np.cos(0*theta[11]*np.pi/180.)*rr/p2m
720 yy = np.sin(0*theta[11]*np.pi/180.)*rr/p2m
722 pup2[(ind2[0]+xx).astype(np.int32),(ind2[1]+yy).astype(np.int32)] = 1.
724 for i in range(xpos.size):
726 influ2[xpos[i]-influshape/2+1:xpos[i]+influshape/2+1,ypos[i]-influshape/2+1:ypos[i]+influshape/2+1] = influ
728 for j in range(xpos.size):
729 if(tmp[xpos[j]-influshape/2+1+xx:xpos[j]+influshape/2+1+xx,ypos[j]-influshape/2+1+yy:ypos[j]+influshape/2+1+yy].shape == influ.shape):
731 tmp[xpos[j]-influshape/2+1+xx:xpos[j]+influshape/2+1+xx,ypos[j]-influshape/2+1+yy:ypos[j]+influshape/2+1+yy] = influ
733 A[i,j] = (influ2*tmp).sum()