PSFinfoc = psf.PSF(js,ajstrues[i,:],N,dxp,pupilRadius) noiseMean = 0. noiseStd = np.max(PSFinfoc.PSF)*noiseStdLevel whiteNoise = fsApd.generateWhiteNoise((PSFinfoc.PSF).shape,noiseMean,noiseStd) PSFinfocWthNoise = PSFinfoc.PSF+whiteNoise PSFoutfoc = psf.PSF(jswth4,ajswtha4,N,dxp,pupilRadius) whiteNoise = fsApd.generateWhiteNoise((PSFoutfoc.PSF).shape,noiseMean,noiseStd) PSFoutfocWthNoise = PSFoutfoc.PSF+whiteNoise phaseDivWthNoise = PD.phaseDiversity(PSFinfocWthNoise,PSFoutfocWthNoise,deltaZ,lbda,pxsize,F,pupilRadius,jmax) jsretrieved = phaseDivWthNoise.result['js'] ajsretrieveds[i,:] = phaseDivWthNoise.result['ajs'] rmse[i] = fs.RMSE(ajsretrieveds[i,:]*1e9*lbda/2/np.pi,ajstrues[i,:]*1e9*lbda/2/np.pi) rmsWFerrorsRetrieved[i] = fs.RMSwavefrontError(jsretrieved,ajsretrieveds[i,:]*1e9*lbda/2/np.pi) plt.figure() plt.hold(True) plt.plot(noiseStdLevels,rmsWFerrorsRetrieved,label='$\sigma_{WF,rms}$ retrieved') plt.plot(noiseStdLevels,rmsWFerrorsTrue,linewidth=2,c='grey',label='$\sigma_{WF,rms}$ true') plt.xlabel('noise Std level of PSF/PSF max') plt.ylabel('$\sigma_{WF,rms}$ retrieved [nm]') plt.grid() plt.figure() plt.plot(noiseStdLevels,rmse) plt.xlabel('noise Std level of PSF/PSF max') plt.ylabel('RMSE [nm]')
else: ajswtha4pos[jswth4 == 4] += a4dephasing ajswtha4neg[jswth4 == 4] -= a4dephasing PSFinfoc = psf.PSF(js, ajstrue, N, dxp, pupilRadius) PSFoutfocpos = psf.PSF(jswth4, ajswtha4pos, N, dxp, pupilRadius) PSFoutfocneg = psf.PSF(jswth4, ajswtha4neg, N, dxp, pupilRadius) phaseDiv = PD.phaseDiversity3PSFs(PSFinfoc.PSF, PSFoutfocpos.PSF, PSFoutfocneg.PSF, deltaZ, lbda, pxsize, F, pupilRadius, jmin, jmax) jsretrieved = phaseDiv.result['js'] ajsretrieved = phaseDiv.result['ajs'] rmse[i] = fs.RMSE(ajsretrieved * 1e9 * lbda / 2 / np.pi, ajstrue * 1e9 * lbda / 2 / np.pi) rmsWFerrorsRetrieved[i] = fs.RMSwavefrontError( jsretrieved, ajsretrieved * 1e9 * lbda / 2 / np.pi) rmsWFerrorMax = np.max(np.append(rmsWFerrors, rmsWFerrorsRetrieved)) rmsWFerrorMin = np.min(np.append(rmsWFerrors, rmsWFerrorsRetrieved)) fnamerms = '../../../fig/PDDev/test/rmsWFerrorsretrieved_rmsWFe%s' fnamermse = '../../../fig/PDDev/test/rmse_rmsWFe%s' fig = plt.figure() plt.hold(True) plt.plot(rmsWFerrors, rmsWFerrorsRetrieved) plt.plot([rmsWFerrorMin, rmsWFerrorMax], [rmsWFerrorMin, rmsWFerrorMax], linewidth=2, c='grey')
rmsWFeIDLtrue[i] = (((ajsIDLFile[i]).replace('.', '_')).split('_'))[-2] jsajsTrue = np.loadtxt(ajsTrueFolderPath + '\\' + ajsTrueFile[i]) jsTrue[i, :] = jsajsTrue[0, :] ajsTrue[i, :] = jsajsTrue[1, :] * 1e9 * lbda / 2 / np.pi jsajsIDL = np.loadtxt(ajsIDLFolderPath + '\\' + ajsIDLFile[i], delimiter=',', skiprows=1) jsIDL[i, :] = jsajsIDL[:, 0] ajsIDLmodal[i, :] = jsajsIDL[:, 1] * 1000 ajsIDLzonal[i, :] = jsajsIDL[:, 2] * 1000 rmsWFeIDLmodalretrieved[i] = fs.RMSwavefrontError(jsIDL[i, :], ajsIDLmodal[i, :]) rmsemodal[i] = fs.RMSE(ajsIDLmodal[i, :], ajsTrue[i, :]) rmsWFeIDLzonalretrieved[i] = fs.RMSwavefrontError(jsIDL[i, :], ajsIDLzonal[i, :]) rmsezonal[i] = fs.RMSE(ajsIDLzonal[i, :], ajsTrue[i, :]) rmsWFefolderPath = 'C:\\Users\\Jojo\\Desktop\\PdM-HEIG\\Science\\data\\devPD\\PSFforIDLtreatment\\PSFs' rmsWFerrorFolderPaths = os.listdir(rmsWFefolderPath) NrmsWFe = len(rmsWFerrorFolderPaths) rmsePy = np.zeros(NrmsWFe) rmsWFerrorsPyRetrieved = np.zeros(NrmsWFe) rmsWFeTruePy = np.zeros(NrmsWFe) jsretrieved = np.zeros([NrmsWFe, jmax - jmin + 1]) ajsretrieved = np.zeros([NrmsWFe, jmax - jmin + 1]) for irms, rmsWFdir in enumerate(rmsWFerrorFolderPaths):
#noiseStd = np.max(PSFoutfocneg.PSF)*noiseStdLevel #whiteNoise = fsApd.generateWhiteNoise((PSFoutfocneg.PSF).shape,noiseMean,noiseStd) #PSFoutfocnegWthNoise = PSFoutfocneg.PSF+whiteNoise phaseDivWoutNoise = PD.phaseDiversity3PSFs(PSFinfoc.PSF,PSFoutfocpos.PSF,PSFoutfocneg.PSF,deltaZ,lbda,pxsize,F,pupilRadius,jmin,jmax) #phaseDivWthNoise = PD.phaseDiversity3PSFs(PSFinfocWthNoise,PSFoutfocposWthNoise,PSFoutfocnegWthNoise,deltaZ,lbda,pxsize,F,pupilRadius,jmin,jmax) #print phaseDiv.result['ajs']*1e9*lbda/2/np.pi #print ajstrue*1e9*lbda/2/np.pi plt.figure() plt.hold(True) plt.plot(jscomplete,ajscomplete*1e9*lbda/2/np.pi,'b-',label='true, $\sigma_{WF,rms}$ = %5.3f nm' %(fs.RMSwavefrontError(js,ajstrue*1e9*lbda/2/np.pi))) plt.errorbar(phaseDivWoutNoise.result['js'],phaseDivWoutNoise.result['ajs']*1e9*lbda/2/np.pi,yerr=phaseDivWoutNoise.result['ajsSte']*1e9*lbda/2/np.pi ,color = 'red',lineStyle='-',label='retrieved wout noise, $\sigma_{WF,rms}$ = %5.3f nm, RMSE = %5.3f nm' %(fs.RMSwavefrontError(phaseDivWoutNoise.result['js'],phaseDivWoutNoise.result['ajs']*1e9*lbda/2/np.pi) ,fs.RMSE(phaseDivWoutNoise.result['ajs']*1e9*lbda/2/np.pi,ajscomplete*1e9*lbda/2/np.pi))) #plt.errorbar(phaseDivWthNoise.result['js'],phaseDivWthNoise.result['ajs']*1e9*lbda/2/np.pi,yerr=phaseDivWthNoise.result['ajsSte']*1e9*lbda/2/np.pi # ,color = 'green',lineStyle='-',label='retrieved wth noise, $\sigma_{WF,rms}$ = %5.3f nm, RMSE = %5.3f nm' # %(fs.RMSwavefrontError(phaseDivWthNoise.result['js'],phaseDivWthNoise.result['ajs']*1e9*lbda/2/np.pi) # ,fs.RMSE(phaseDivWthNoise.result['ajs']*1e9*lbda/2/np.pi,ajscomplete*1e9*lbda/2/np.pi))) plt.xlabel('j') plt.ylabel('aj [nm]') plt.xlim([jscomplete[0],jscomplete[-1]]) plt.legend(loc='upper center') plt.grid() fnameajsjs = '../../../fig/PDDev/test/ajs_js_jmax_%d_WoutN_rmsWFe_%d%s' plt.savefig(fnameajsjs % (jmax,rmsWFerror,'.png'), dpi=300) plt.savefig(fnameajsjs % (jmax,rmsWFerror,'.pdf'), dpi=300) plt.figure()
# %(jm,fs.RMSwavefrontError(phaseDivWoutNoise[ij].result['js'],phaseDivWoutNoise[ij].result['ajs']*1e9*lbda/2/np.pi) # ,fs.RMSE((phaseDivWoutNoise[ij].result['ajs'])[0:jmax[2]-3]*1e9*lbda/2/np.pi,ajscomplete*1e9*lbda/2/np.pi))) # else : plt.errorbar( phaseDivWoutNoise[ij].result['js'], phaseDivWoutNoise[ij].result['ajs'] * 1e9 * lbda / 2 / np.pi, yerr=phaseDivWoutNoise[ij].result['ajsSte'] * 1e9 * lbda / 2 / np.pi, lineStyle='-', label= 'retrieved jmax = %d, $\sigma_{WF,rms}$ = %5.3f nm, RMSE = %5.3f nm' % (jm, fs.RMSwavefrontError( phaseDivWoutNoise[ij].result['js'], phaseDivWoutNoise[ij].result['ajs'] * 1e9 * lbda / 2 / np.pi), fs.RMSE( (phaseDivWoutNoise[ij].result['ajs']) * 1e9 * lbda / 2 / np.pi, ajscomplete[0:jm - 3] * 1e9 * lbda / 2 / np.pi))) #plt.errorbar(phaseDivWthNoise.result['js'],phaseDivWthNoise.result['ajs']*1e9*lbda/2/np.pi,yerr=phaseDivWthNoise.result['ajsSte']*1e9*lbda/2/np.pi # ,color = 'green',lineStyle='-',label='retrieved wth noise, $\sigma_{WF,rms}$ = %5.3f nm, RMSE = %5.3f nm' # %(fs.RMSwavefrontError(phaseDivWthNoise.result['js'],phaseDivWthNoise.result['ajs']*1e9*lbda/2/np.pi) # ,fs.RMSE(phaseDivWthNoise.result['ajs']*1e9*lbda/2/np.pi,ajscomplete*1e9*lbda/2/np.pi))) plt.xlabel('j') plt.ylabel('aj [nm]') plt.xlim([np.min(jmax), np.max(jmax)]) plt.legend(loc='best', fontsize=16) plt.grid() fnameajsjs = '../../../fig/PDDev/test/ajs_js_jmaxstudy_WoutN_rmsWFe_%d%s' #plt.savefig(fnameajsjs % (rmsWFerror,'.png'), dpi=300) #plt.savefig(fnameajsjs % (rmsWFerror,'.pdf'), dpi=300)
PSFoutfoc = psf.PSF(jswth4,ajswtha4,N,dxp,pupilRadius) noiseMean = 0. noiseStd = np.max(PSFoutfoc.PSF)*noiseStdLevel whiteNoise = fsApd.generateWhiteNoise((PSFoutfoc.PSF).shape,noiseMean,noiseStd) PSFoutfocWthNoise = PSFoutfoc.PSF+whiteNoise phaseDivWoutNoise = PD.phaseDiversity(PSFinfoc.PSF,PSFoutfoc.PSF,deltaZ,lbda,pxsize,F,pupilRadius,jmax) phaseDivWthNoise = PD.phaseDiversity(PSFinfocWthNoise,PSFoutfocWthNoise,deltaZ,lbda,pxsize,F,pupilRadius,jmax) #print phaseDiv.result['ajs']*1e9*lbda/2/np.pi #print ajstrue*1e9*lbda/2/np.pi plt.figure() plt.hold(True) plt.plot(js,ajstrue*1e9*lbda/2/np.pi,'b-',label='true, $\sigma_{WF,rms}$ = %5.3f nm' %(fs.RMSwavefrontError(js,ajstrue*1e9*lbda/2/np.pi))) plt.xlim([js[0],js[-1]]) plt.hold(True) plt.plot(phaseDivWoutNoise.result['js'],phaseDivWoutNoise.result['ajs']*1e9*lbda/2/np.pi ,'r-',label='retrieved wout noise, $\sigma_{WF,rms}$ = %5.3f nm, RMSE = %5.3f nm' %(fs.RMSwavefrontError(phaseDivWoutNoise.result['js'],phaseDivWoutNoise.result['ajs']*1e9*lbda/2/np.pi) ,fs.RMSE(phaseDivWoutNoise.result['ajs']*1e9*lbda/2/np.pi,ajstrue*1e9*lbda/2/np.pi))) plt.plot(phaseDivWthNoise.result['js'],phaseDivWthNoise.result['ajs']*1e9*lbda/2/np.pi ,'g-',label='retrieved wth noise, $\sigma_{WF,rms}$ = %5.3f nm, RMSE = %5.3f nm' %(fs.RMSwavefrontError(phaseDivWthNoise.result['js'],phaseDivWthNoise.result['ajs']*1e9*lbda/2/np.pi) ,fs.RMSE(phaseDivWthNoise.result['ajs']*1e9*lbda/2/np.pi,ajstrue*1e9*lbda/2/np.pi))) plt.xlabel('j') plt.ylabel('aj [nm]') plt.legend(loc='best') plt.grid()
lbda, pxsize, F, pupilRadius, jmin, jmax) ajss[irmsWFe, iNretrieve, :] = phaseDivWthNoise.result['ajs'] ajsSte[irmsWFe, iNretrieve, :] = phaseDivWthNoise.result['ajsSte'] fnameajsjsWthe = '../../../fig/PDDev/test/ajs_js_WthE_rmsWFe_%d%s' fnameajsjsWoute = '../../../fig/PDDev/test/ajs_js_WoutE_rmsWFe_%d%s' fnamebxpajsjs = '../../../fig/PDDev/test/bxp_ajs_js_rmsWFe_%d%s' plt.ioff() for irmsWFe, rmsWFerror in enumerate(rmsWFerrors): meanAjsRetrieved = np.mean(ajss[irmsWFe, :, :], 0) * 1e9 * lbda / 2 / np.pi meanrmsWFerror = fs.RMSwavefrontError(jscomplete, meanAjsRetrieved) meanRMSE = fs.RMSE(meanAjsRetrieved, ajscomplete * 1e9 * lbda / 2 / np.pi) #Plot all the result fig = plt.figure() plt.title( 'Nretrieval = %d, $\sigma_{wf,rms}$ = %3.1fnm, noiseStdLevel = %4.3f [maxPSF]' % (Nretrieve, rmsWFerror, noiseStdLevel)) plt.hold(True) for iNretrieve in np.arange(Nretrieve - 1): plt.errorbar(jscomplete, ajss[irmsWFe, iNretrieve, :] * 1e9 * lbda / 2 / np.pi, yerr=ajsSte[irmsWFe, iNretrieve, :] * 1e9 * lbda / 2 / np.pi, linewidth=0.5, color='red') plt.errorbar( jscomplete,