te1=0.076 te2=0.048 #psi=te1*r1 #psi=te2*r2+te1*r1 psi=numpy.zeros(n,dtype=double) kappa0=dot(kmat,psi) nx=120 kap_grid0=smooth_pbl.grid_field_gaussian(x1,y1,kappa0,nx,nx) #sys.exit() C_invhat=numpy.dot(numpy.dot(numpy.transpose(Vh),numpy.diag(s)),numpy.transpose(U)) C_inv=numpy.zeros((n,n),dtype=double) C_inv[n_strong:n,n_strong:n]=C_invhat zw=numpy.append((zs-0.1832)/zs,(1.4-0.1832)/1.4+numpy.zeros(n_weak,dtype=double)) delx,dely,chi_prevmat=smooth_pbl.chisq(x1,y1,id_image,n_strong,n_weak,a1mat,a2mat,strong_weight,C_inv,psi,g1mat,g2mat,kmat,e1,e2,zw) chi_prev=sum(chi_prevmat) print "chi_start= ",chi_prev eps=0.1 del_chi=100 n_iter=10 eps=0.01 #while (del_chi>eps): for i in xrange(1): C_kap,dpsi=smooth_pbl.create_psi(x1,y1,id_image,n_strong,n_weak,a1mat,a2mat,strong_weight,psi,kmat,g1mat,g2mat,C_inv,e1,e2,zw,sig_e,W) psi+=dpsi delta_x,delta_y,chi2=smooth_pbl.chisq(x1,y1,id_image,n_strong,n_weak,a1mat,a2mat,strong_weight,C_inv,psi,g1mat,g2mat,kmat,e1,e2,zw) print "chi= ",chi2 print "iter" del_chi=(chi_prev-chi2)
# nx=60 # kap_grid=smooth_pbl.grid_field_gaussain(x1,y1,kappa,nx,nx) C=numpy.dot(W,numpy.dot(W,numpy.diag(sigma*sigma)).T) U,s,Vh=scipy.linalg.svd(C) eig1=s alpha=5.e-5*hsm0*hsm0 e1=e1_sm.copy() e2=e2_sm.copy() s=eig1/(eig1**2+alpha**2) psi=numpy.zeros(n,dtype=double) C_inv=numpy.dot(numpy.dot(numpy.transpose(Vh),numpy.diag(s)),numpy.transpose(U)) zw=(1.4-0.165)/1.4 chi_prevmat=smooth_pbl.chisq(C_inv,psi,g1mat,g2mat,kmat,e1,e2,zw) chi_prev=sum(chi_prevmat) eps=0.1 del_chi=1000 n_iter=10 eps=0.01 while (del_chi>eps): L1,L2,dpsi=smooth_pbl.create_psi(psi,kmat,g1mat,g2mat,C_inv,e1,e2,zw) psi+=dpsi chi2mat=smooth_pbl.chisq(C_inv,psi,g1mat,g2mat,kmat,e1,e2,zw) chi2=sum(chi2mat) print "iter" del_chi=(chi_prev-chi2) chi_prev=chi2