def plot_image_and_mapper(ccd_data, mapper, mask=None, positions=None, should_plot_centres=False, should_plot_grid=False, should_plot_border=False, image_pixels=None, source_pixels=None, units='arcsec', kpc_per_arcsec=None, output_path=None, output_filename='image_and_mapper', output_format='show'): rows, columns, figsize = plotter_util.get_subplot_rows_columns_figsize( number_subplots=2) plt.figure(figsize=figsize) plt.subplot(rows, columns, 1) ccd_plotters.plot_image(ccd_data=ccd_data, mask=mask, positions=positions, as_subplot=True, units=units, kpc_per_arcsec=None, xyticksize=16, norm='linear', norm_min=None, norm_max=None, linthresh=0.05, linscale=0.01, figsize=None, aspect='equal', cmap='jet', cb_ticksize=10, titlesize=10, xlabelsize=10, ylabelsize=10, output_path=output_path, output_format=output_format) image_grid = convert_grid(grid=mapper.grid_stack.regular.unlensed_grid, units=units, kpc_per_arcsec=kpc_per_arcsec) point_colors = itertools.cycle(["y", "r", "k", "g", "m"]) plot_image_plane_image_pixels(grid=image_grid, image_pixels=image_pixels, point_colors=point_colors) plot_image_plane_source_pixels(grid=image_grid, mapper=mapper, source_pixels=source_pixels, point_colors=point_colors) plt.subplot(rows, columns, 2) plot_mapper(mapper=mapper, should_plot_centres=should_plot_centres, should_plot_grid=should_plot_grid, should_plot_border=should_plot_border, image_pixels=image_pixels, source_pixels=source_pixels, as_subplot=True, units=units, kpc_per_arcsec=kpc_per_arcsec, figsize=None) plotter_util.output_subplot_array(output_path=output_path, output_filename=output_filename, output_format=output_format) plt.close()
print(ccd_data.psf) # To fit an image, we first specify a mask. A mask describes the sections of the image that we fit. # Typically, we want to mask out regions of the image where the lens and source galaxies are not visible, for example # at the edges where the signal is entirely background sky and noise. # For the image we simulated, a 3" circular mask will do the job. mask = ma.Mask.circular(shape=ccd_data.shape, pixel_scale=ccd_data.pixel_scale, radius_arcsec=3.0) print(mask) # 1 = True, which means the pixel is masked. Edge pixels are indeed masked. print(mask[48:53, 48:53]) # Whereas central pixels are False and therefore unmasked. # We can use a ccd_plotter to compare the mask and the image - this is useful if we really want to 'tailor' a # mask to the lensed source's light (which in this example, we won't). ccd_plotters.plot_image(ccd_data=ccd_data, mask=mask) # We can also use the mask to 'zoom' our plot around the masked region only - meaning that if our image is very large, # we can focus-in on the lens and source galaxies. # You'll see this is an option for pretty much every plotter in PyAutoLens, and is something we'll do often throughout # the tutorials. ccd_plotters.plot_image(ccd_data=ccd_data, mask=mask, zoom_around_mask=True) # We can also remove all pixels output of the mask in the plot, which means that if bright pixels outside the mask # are messing up the color scheme and plot, they'll removed. Again, we'll do this throughout the code. ccd_plotters.plot_image(ccd_data=ccd_data, mask=mask, extract_array_from_mask=True, zoom_around_mask=True) # Now we've loaded the ccd data and created a mask, we use them to create a 'lens data' object, which we'll perform # using the lens_data module (imported as 'ld').
return ccd.CCDData.simulate(array=tracer.image_plane_image_for_simulation, pixel_scale=0.05, exposure_time=300.0, psf=psf, background_sky_level=0.1, add_noise=True) # Now, lets simulate the source, mask it, and use a plot to check the masking is appropriate. ccd_data = simulate() mask = msk.Mask.circular_annular(shape=ccd_data.shape, pixel_scale=ccd_data.pixel_scale, inner_radius_arcsec=1.0, outer_radius_arcsec=2.2) ccd_plotters.plot_image(ccd_data=ccd_data, mask=mask) # Next, lets set this image up as lens data, and setup a tracer using the input lens galaxy model (we don't need # to provide the source's light profile, as we're using a mapper to reconstruct it). lens_data = ld.LensData(ccd_data=ccd_data, mask=mask, sub_grid_size=1) lens_galaxy = g.Galaxy(mass=mp.EllipticalIsothermal( centre=(0.0, 0.0), axis_ratio=0.8, phi=135.0, einstein_radius=1.6)) tracer = ray_tracing.TracerImageSourcePlanes( lens_galaxies=[lens_galaxy], source_galaxies=[g.Galaxy()], image_plane_grid_stack=lens_data.grid_stack) # We'll use another rectangular pixelization and mapper to perform the reconstruction rectangular = pix.Rectangular(shape=(25, 25)) mapper = rectangular.mapper_from_grid_stack_and_border( grid_stack=tracer.source_plane.grid_stack, border=None)
# edge-effects do not degrade our simulation's PSF convolution. print(tracer.image_plane_image.shape) print(tracer.image_plane_image_for_simulation.shape) # Now, to simulate the ccd imaging data, we pass the tracer's image-plane image to the ccd module's simulate # function. This adds the following effects to the image: # 1) Telescope optics: Using the Point Spread Function above. # 2) The Background Sky: Although the image that is returned is automatically background sky subtracted. # 3) Poisson noise: Due to the background sky, lens galaxy and source galaxy Poisson photon counts. simulated_ccd = ccd.CCDData.simulate(array=tracer.image_plane_image_for_simulation, pixel_scale=0.1, exposure_time=300.0, psf=psf, background_sky_level=0.1, add_noise=True) # Lets plot the image - we can see the image has been blurred due to the telescope optics and noise has been added. ccd_plotters.plot_image(ccd_data=simulated_ccd) # Finally, lets output these files to.fits files, we'll begin to analyze them in the next tutorial! path = '/path/to/AutoLens/workspace/howtolens/chapter_1_introduction' path = '/home/jammy/PyCharm/Projects/AutoLens/workspace/howtolens/chapter_1_introduction' # If you are using Docker, the path you should use to output these images is (e.g. comment out this line) # path = '/home/user/workspace/howtolens/chapter_1_introduction' # If you arn't using docker, you need to change the path below to the chapter 2 directory and uncomment it # path = '/path/to/user/workspace/howtolens/chapter_1_introduction' ccd.output_ccd_data_to_fits(ccd_data=simulated_ccd, image_path=path+'/data/image.fits', noise_map_path=path+'/data/noise_map.fits', psf_path=path+'/data/psf.fits', overwrite=True)