def test_convergence_direct(): z_final = 2.0 #Start a bucket of light rays from these positions b = np.linspace(0.0,tracer.lens[0].side_angle.to(deg).value,512) xx,yy = np.meshgrid(b,b) pos = np.array([xx,yy]) * deg #Compute the convergence conv = tracer.convergenceDirect(pos,z=z_final) #Wrap into a ConvergenceMap and visualize conv_map = ConvergenceMap(data=conv,angle=tracer.lens[0].side_angle) conv_map.visualize(colorbar=True) conv_map.savefig("convergence_direct.png")
def excursion(cmd_args,smooth=0.5*u.arcmin,threshold=0.02,fontsize=22): #Set up plot fig,ax = plt.subplots(1,2,figsize=(16,8)) #Load map conv = ConvergenceMap.load(os.path.join(fiducial["c0"].getMapSet("kappa").home,"WLconv_z2.00_0001r.fits")) conv.smooth(smooth,kind="gaussianFFT",inplace=True) #Build excursion set exc_data = np.zeros_like(conv.data) exc_data[conv.data>threshold] = 1. exc = ConvergenceMap(exc_data,angle=conv.side_angle) #Define binary colorbar cmap = plt.get_cmap("RdBu") cmaplist = [ cmap(i) for i in range(cmap.N) ] cmap = cmap.from_list("binary map",cmaplist,cmap.N) bounds = np.array([0.0,0.5,1.0]) norm = matplotlib.colors.BoundaryNorm(bounds,cmap.N) #Plot the two alongside conv.visualize(colorbar=True,cbar_label=r"$\kappa$",fig=fig,ax=ax[0]) exc.visualize(colorbar=True,cmap="binary",norm=norm,fig=fig,ax=ax[1]) #Overlay boundary on the image mask = conv.mask(exc_data.astype(np.int8)) i,j = np.where(mask.boundary>0) scale = conv.resolution.to(u.deg).value ax[0].scatter(j*scale,i*scale,color="red",marker=".",s=0.5) ax[0].set_xlim(0,conv.side_angle.to(u.deg).value) ax[0].set_ylim(0,conv.side_angle.to(u.deg).value) #Format right colorbar cbar = exc.ax.get_images()[0].colorbar cbar.outline.set_linewidth(1) cbar.outline.set_edgecolor("black") cbar_ticks = cbar.set_ticks([0,0.25,0.5,0.75,1]) cbar.ax.set_yticklabels(["",r"$\kappa<\kappa_0$","",r"$\kappa>\kappa_0$",""],rotation=90) #Save fig.tight_layout() fig.savefig("{0}/excursion.{0}".format(cmd_args.type))
def test_ray_simple(): z_final = 2.0 start = time.time() last_timestamp = start #Start a bucket of light rays from these positions b = np.linspace(0.0,tracer.lens[0].side_angle.to(deg).value,512) xx,yy = np.meshgrid(b,b) pos = np.array([xx,yy]) * deg #Trace the rays fin = tracer.shoot(pos,z=z_final) now = time.time() logging.info("Ray tracing completed in {0:.3f}s".format(now-last_timestamp)) last_timestamp = now #Build the deflection plane dfl = DeflectionPlane(fin.value-pos.value,angle=tracer.lens[0].side_angle,redshift=tracer.redshift[-1],cosmology=tracer.lens[0].cosmology,unit=pos.unit) #Compute shear and convergence conv = dfl.convergence() shear = dfl.shear() omega = dfl.omega() now = time.time() logging.info("Weak lensing calculations completed in {0:.3f}s".format(now-last_timestamp)) last_timestamp = now #Finally visualize the result conv.visualize(colorbar=True) conv.savefig("raytraced_convergence.png") omega.visualize(colorbar=True) omega.savefig("raytraced_omega.png") shear.visualize(colorbar=True) shear.savefig("raytraced_shear.png") #We want to plot the power spectrum of the raytraced maps fig,ax = plt.subplots() l_edges = np.arange(200.0,10000.0,100.0) l,Pl = conv.powerSpectrum(l_edges) ax.plot(l,l*(l+1)*Pl/(2.0*np.pi),label="From ray positions") #And why not, E and B modes too figEB,axEB = plt.subplots() l,EEl,BBl,EBl = shear.decompose(l_edges) axEB.plot(l,l*(l+1)*EEl/(2.0*np.pi),label="EE From ray positions",color="black") axEB.plot(l,l*(l+1)*BBl/(2.0*np.pi),label="BB From ray positions",color="green") axEB.plot(l,l*(l+1)*np.abs(EBl)/(2.0*np.pi),label="EB From ray positions",color="blue") #Now compute the shear and convergence raytracing the actual jacobians (more expensive computationally cause it computes the jacobian at every step) finJ = tracer.shoot(pos,z=z_final,kind="jacobians") conv = ConvergenceMap(data=1.0-0.5*(finJ[0]+finJ[3]),angle=conv.side_angle) shear = ShearMap(data=np.array([0.5*(finJ[3]-finJ[0]),-0.5*(finJ[1]+finJ[2])]),angle=shear.side_angle) now = time.time() logging.info("Jacobian ray tracing completed in {0:.3f}s".format(now-last_timestamp)) last_timestamp = now #Finally visualize the result conv.visualize(colorbar=True) conv.savefig("raytraced_convergence_jacobian.png") shear.visualize(colorbar=True) shear.savefig("raytraced_shear_jacobian.png") #We want to plot the power spectrum of the raytraced maps l,Pl = conv.powerSpectrum(l_edges) ax.plot(l,l*(l+1)*Pl/(2.0*np.pi),label="From Jacobians") ax.set_xlabel(r"$l$") ax.set_ylabel(r"$l(l+1)P_l/2\pi$") ax.set_xscale("log") ax.set_yscale("log") ax.legend() fig.savefig("raytracing_conv_power.png") #And why not, E and B modes too axEB.plot(l,l*(l+1)*EEl/(2.0*np.pi),label="EE From jacobians",color="black",linestyle="--") axEB.plot(l,l*(l+1)*BBl/(2.0*np.pi),label="BB From jacobians",color="green",linestyle="--") axEB.plot(l,l*(l+1)*np.abs(EBl)/(2.0*np.pi),label="EB From jacobians",color="blue",linestyle="--") axEB.set_xlabel(r"$l$") axEB.set_ylabel(r"$l(l+1)P_l/2\pi$") axEB.set_xscale("log") axEB.set_yscale("log") axEB.legend(loc="lower right",prop={"size":10}) figEB.savefig("raytracing_shear_power.png") now = time.time() logging.info("Total runtime {0:.3f}s".format(now-start))