def get_kappa_vector(self,theta1,theta2,zrange, n=1): try: Nz = len(zrange) except: zrange = [zrange] Nz = 1 N1 = len(theta1) N2 = len(theta2) vec_data = numpy.zeros( (Nz,N1,N2), dtype = complex ) theta = theta_comp_to_grid(theta1,theta2) if n==1: for i in range(Nz): vec_data[i] = self.kappa(theta,zrange[i]) else: dx = theta1[1]-theta1[0] dy = theta2[1]-theta2[0] for j in range(N1): for k in range(N2): t = theta_comp_to_grid( numpy.linspace(theta1[j]-0.5*dx, theta1[j]+0.5*dx, n), numpy.linspace(theta2[k]-0.5*dy, theta2[k]+0.5*dy, n) ) for i in range(Nz): vec_data[i,j,k] = numpy.mean(self.kappa(t,zrange[i])) return Lens3D_vector(Nz,N1,N2,vec_data)
def write_to_file(self,filename, z_range,theta1_range,theta2_range = None): if(theta2_range == None): theta2_range = theta1_range of = open(filename,'w') of.write('#positions measured in arcmin:\n') of.write('#redshift theta1 theta2 Sigma kappa gamma1 gamma2\n') theta = theta_comp_to_grid(theta1_range,theta2_range) for i in range(len(z_range)): z = z_range[i] if i==0: z0 = 0 else: z0 = z_range[i-1] kappa = self.kappa(theta,z) gamma = self.gamma(theta,z) Sigma = self.Sigma(theta,z0,z) for j in range(theta.shape[0]): for k in range(theta.shape[1]): of.write('%.3f %.3f %.3f %.6g %.6g %.6g %.6g\n' % \ (z, theta.real[j,k], theta.imag[j,k], Sigma[j,k], kappa[j,k], gamma.real[j,k], gamma.imag[j,k]) ) #end for #end for #end for of.close()
def get_Sigma_vector(self,theta1,theta2,zrange, n=1): """ n tells how many points to evaluate within the pixel there will be n^2 evaluations per pixel """ try: Nz = len(zrange) except: zrange = [zrange] Nz = 1 N1 = len(theta1) N2 = len(theta2) assert n>0 #make zrange[-1] = 0.0 zrange = numpy.concatenate( (zrange,[0.0]) ) vec_data = numpy.zeros( (Nz,N1,N2), dtype = complex ) theta = theta_comp_to_grid(theta1,theta2) if n==1: for i in range(Nz): vec_data[i] = self.Sigma(theta,zrange[i-1],zrange[i]) else: dx = theta1[1]-theta1[0] dy = theta2[1]-theta2[0] for j in range(N1): for k in range(N2): t = theta_comp_to_grid( numpy.linspace(theta1[j]-0.5*dx, theta1[j]+0.5*dx, n), numpy.linspace(theta2[k]-0.5*dy, theta2[k]+0.5*dy, n) ) for i in range(Nz): vec_data[i,j,k] = numpy.mean(self.Sigma(t,zrange[i-1], zrange[i])) if numpy.any(numpy.isinf(vec_data)): raise ValueError, "get_Sigma_vector : infinity encountered" return Lens3D_vector(Nz,N1,N2,vec_data)
def get_gamma_vector(self,theta1,theta2,zrange): try: Nz = len(zrange) except: zrange = [zrange] Nz = 1 N1 = len(theta1) N2 = len(theta2) vec_data = numpy.zeros( (Nz,N1,N2), dtype = complex ) theta = theta_comp_to_grid(theta1,theta2) for i in range(Nz): vec_data[i] = self.gamma(theta,zrange[i]) i = numpy.where(numpy.isnan(vec_data)) vec_data[i] = 0 return Lens3D_vector(Nz,N1,N2,vec_data)
theta_max = 3 sig_min = 200 sig_max = 500 #numpy.random.seed(2) z = numpy.random.random(N_clusters)*(zmax-zmin)+zmin theta = numpy.random.random((2,N_clusters))*(theta_max-theta_min)+theta_min theta = theta[0] + 1j*theta[1] sig = numpy.random.random(N_clusters)*(sig_max-sig_min)+sig_min print theta PS = ProfileSet() for i in range(N_clusters): PS.add( SIS(z[i],sig[i],theta[i]) ) z_source = 0.3 theta_1 = numpy.linspace(-3,3,30) theta_2 = numpy.linspace(-3,3,30) theta = theta_comp_to_grid(theta_1,theta_2) pylab.figure() PS.get_kappa_vector(theta_1,theta_2,(0.1,0.3) ).imshow_lens_plane(1,cmap=pylab.cm.gray,extent = theta_extent(theta)) PS.get_gamma_vector(theta_1,theta_2,(0.1,0.3) ).fieldplot_lens_plane(1,extent=(theta_1[0],theta_1[-1],theta_2[0],theta_2[-1]) ) pylab.figure() PS.plot_kappa(theta,z_source) pylab.figure() PS.plot_gammakappa(theta,0.3,normalize = True) pylab.show()