Commit e0fbfa4d by rfetick

### normalize gradient r0 up to infinity

parent 41b99d2c
 # -*- coding: utf-8 -*- """ Created on Tue Jun 1 10:20:53 2021 Show the analytical and numerical derivatives for Psfao @author: rfetick """ import matplotlib.pyplot as plt import numpy as np import copy from maoppy.psfmodel import Psfao from maoppy.instrument import muse_nfm Npix = 64 # pixel size of PSF wvl = 600*1e-9 # wavelength [m] #%% Initialize PSF model samp = muse_nfm.samp(wvl) # sampling (2.0 for Shannon-Nyquist) Pmodel = Psfao((Npix,Npix),system=muse_nfm,samp=samp) #%% Choose parameters r0 = 0.15 # Fried parameter [m] bck = 1e-5 # Phase PSD background [rad² m²] amp = 5.0 # Phase PSD Moffat amplitude [rad²] alpha = 1 # Phase PSD Moffat alpha [1/m] ratio = 1.2 theta = np.pi/4 beta = 1.6 # Phase PSD Moffat beta power law param = [r0,bck,amp,alpha,ratio,theta,beta] #%% Compute PSD derivative psd,_,g,_ = Pmodel.psd(param,grad=True) gnum = 0*g eps = 1e-5 for i in range(len(param)): dp = copy.copy(param) dp[i] += eps psd2,_ = Pmodel.psd(dp) gnum[i,...] = (psd2-psd)/eps #%% Plot results names = ['r0','bck','amp','alpha','ratio','theta','beta'] plt.figure(1) plt.clf() for i in range(len(param)): plt.subplot(2,len(param),i+1) plt.pcolormesh(g[i,...]) plt.axis('image') plt.axis('off') plt.title(names[i]) plt.colorbar(orientation='horizontal') plt.subplot(2,len(param),i+1+len(param)) plt.pcolormesh(gnum[i,...]) plt.axis('image') plt.axis('off') #plt.title(names[i]) plt.colorbar(orientation='horizontal') #%% Compute PSF derivative psf,g = Pmodel(param,grad=True) gnum = 0*g eps = 1e-5 for i in range(len(param)): dp = copy.copy(param) dp[i] += eps psf2 = Pmodel(dp) gnum[i,...] = (psf2-psf)/eps #%% Plot results names = ['r0','bck','amp','alpha','ratio','theta','beta'] plt.figure(2) plt.clf() for i in range(len(param)): plt.subplot(2,len(param),i+1) plt.pcolormesh(g[i,...]) plt.axis('image') plt.axis('off') plt.title(names[i]) plt.colorbar(orientation='horizontal') plt.subplot(2,len(param),i+1+len(param)) plt.pcolormesh(gnum[i,...]) plt.axis('image') plt.axis('off') #plt.title(names[i]) plt.colorbar(orientation='horizontal') \ No newline at end of file