def make_image_1(): image = scaled_array.ScaledSquarePixelArray(array=10.0 * np.ones((4, 4)), pixel_scale=6.0) psf = im.PSF(array=11.0 * np.ones((3, 3)), pixel_scale=6.0, renormalize=False) noise_map = im.NoiseMap(array=12.0 * np.ones((4, 4)), pixel_scale=6.0) background_noise_map = im.NoiseMap(array=13.0 * np.ones((4, 4)), pixel_scale=6.0) poisson_noise_map = im.PoissonNoiseMap(array=14.0 * np.ones((4, 4)), pixel_scale=6.0) exposure_time_map = im.ExposureTimeMap(array=15.0 * np.ones((4, 4)), pixel_scale=6.0) background_sky_map = scaled_array.ScaledSquarePixelArray(array=16.0 * np.ones((4, 4)), pixel_scale=6.0) return im.CCDData(image=image, pixel_scale=6.0, psf=psf, noise_map=noise_map, background_noise_map=background_noise_map, poisson_noise_map=poisson_noise_map, exposure_time_map=exposure_time_map, background_sky_map=background_sky_map)
def make_ccd(): image = scaled_array.ScaledSquarePixelArray(array=np.ones((4, 4)), pixel_scale=3.0) psf = ccd.PSF(array=np.ones((3, 3)), pixel_scale=3.0, renormalize=False) noise_map = ccd.NoiseMap(array=2.0 * np.ones((4, 4)), pixel_scale=3.0) background_noise_map = ccd.NoiseMap(array=3.0 * np.ones((4, 4)), pixel_scale=3.0) poisson_noise_map = ccd.PoissonNoiseMap(array=4.0 * np.ones((4, 4)), pixel_scale=3.0) exposure_time_map = ccd.ExposureTimeMap(array=5.0 * np.ones((4, 4)), pixel_scale=3.0) background_sky_map = scaled_array.ScaledSquarePixelArray(array=6.0 * np.ones((4, 4)), pixel_scale=3.0) return ccd.CCDData(image=image, pixel_scale=3.0, psf=psf, noise_map=noise_map, background_noise_map=background_noise_map, poisson_noise_map=poisson_noise_map, exposure_time_map=exposure_time_map, background_sky_map=background_sky_map)
def phase(): pixel_scale = 0.1 image_shape = (150, 150) tools.reset_paths(test_name=test_name, output_path=output_path) grid_stack = grids.GridStack.from_shape_pixel_scale_and_sub_grid_size(shape=image_shape, pixel_scale=pixel_scale, sub_grid_size=4) galaxy = g.Galaxy(mass=mp.SphericalIsothermal(centre=(0.0, 0.0), einstein_radius=1.0)) deflections = galaxy_util.deflections_of_galaxies_from_grid(galaxies=[galaxy], grid=grid_stack.sub) deflections_y = grid_stack.regular.scaled_array_from_array_1d(array_1d=deflections[:,0]) deflections_x = grid_stack.regular.scaled_array_from_array_1d(array_1d=deflections[:,1]) noise_map = scaled_array.ScaledSquarePixelArray(array=np.ones(deflections_y.shape), pixel_scale=pixel_scale) data_y = gd.GalaxyData(image=deflections_y, noise_map=noise_map, pixel_scale=pixel_scale) data_x = gd.GalaxyData(image=deflections_x, noise_map=noise_map, pixel_scale=pixel_scale) phase = ph.GalaxyFitPhase(galaxies=dict(gal=gm.GalaxyModel(light=mp.SphericalIsothermal)), use_deflections=True, sub_grid_size=4, optimizer_class=nl.MultiNest, phase_name=test_name+'/') phase.run(galaxy_data=[data_y, data_x])
def phase(): pixel_scale = 0.1 image_shape = (150, 150) tools.reset_paths(test_name=test_name, output_path=output_path) grid_stack = grids.GridStack.from_shape_pixel_scale_and_sub_grid_size( shape=image_shape, pixel_scale=pixel_scale, sub_grid_size=4) galaxy = g.Galaxy(mass=lp.SphericalExponential( centre=(0.0, 0.0), intensity=1.0, effective_radius=0.5)) intensities = galaxy_util.intensities_of_galaxies_from_grid( galaxies=[galaxy], grid=grid_stack.sub) intensities = grid_stack.regular.scaled_array_from_array_1d( array_1d=intensities) noise_map = scaled_array.ScaledSquarePixelArray(array=np.ones( intensities.shape), pixel_scale=pixel_scale) data = gd.GalaxyData(image=intensities, noise_map=noise_map, pixel_scale=pixel_scale) phase = ph.GalaxyFitPhase( galaxies=dict(gal=gm.GalaxyModel(light=lp.SphericalExponential)), use_intensities=True, sub_grid_size=4, optimizer_class=nl.MultiNest, phase_name=test_name + '/') phase.run(galaxy_data=[data])
def make_galaxy_data(image, mask): noise_map = sca.ScaledSquarePixelArray(array=2.0 * np.ones((4, 4)), pixel_scale=3.0) galaxy_data = gd.GalaxyData(image=image, noise_map=noise_map, pixel_scale=3.0) return gd.GalaxyFitData(galaxy_data=galaxy_data, mask=mask, use_intensities=True)
def make_image(): image = scaled_array.ScaledSquarePixelArray(array=np.ones((3, 3)), pixel_scale=1.0) noise_map = im.NoiseMap(array=2.0 * np.ones((3, 3)), pixel_scale=1.0) psf = im.PSF(array=3.0 * np.ones((1, 1)), pixel_scale=1.0) return im.CCDData(image=image, pixel_scale=1.0, noise_map=noise_map, psf=psf)
def make_ccd(): image = scaled_array.ScaledSquarePixelArray(array=np.ones((3, 3)), pixel_scale=1.0) noise_map = im.NoiseMap(array=2.0 * np.ones((3, 3)), pixel_scale=1.0) psf = im.PSF(array=3.0 * np.ones((1, 1)), pixel_scale=1.0) return im.CCDData(image=image, pixel_scale=1.0, noise_map=noise_map, psf=psf, exposure_time_map=2.0 * np.ones((3, 3)), background_sky_map=3.0 * np.ones((3, 3)))
def scaled_array_from_array_1d(self, array_1d): """ Map a 1D array the same dimension as the grid to its original masked 2D array and return it as a scaled \ array. Parameters ----------- array_1d : ndarray The 1D array of which is mapped to a 2D scaled array. """ return scaled_array.ScaledSquarePixelArray( array=self.array_2d_from_array_1d(array_1d), pixel_scale=self.mask.pixel_scale, origin=self.mask.origin)
def make_ccd_data(): pixel_scale = 1.0 image = scaled_array.ScaledSquarePixelArray(array=np.array( np.zeros(shape)), pixel_scale=pixel_scale) psf = ccd.PSF(array=np.ones((3, 3)), pixel_scale=pixel_scale) noise_map = ccd.NoiseMap(np.ones(shape), pixel_scale=1.0) return ccd.CCDData(image=image, pixel_scale=pixel_scale, psf=psf, noise_map=noise_map)
def make_image(): return sca.ScaledSquarePixelArray(array=np.ones((4, 4)), pixel_scale=3.0)
sub_grid_size=4) # Now lets create a galaxy, using a simple singular isothermal sphere. galaxy = g.Galaxy(mass=mp.SphericalIsothermal(centre=(0.0, 0.0), einstein_radius=1.0)) # Next, we'll generate its surface density profile. Note that, because we're using the galaxy_util surface density # function, the sub-grid of the grid-stack that is passed to this function is used to over-sample the surface density. # The surface density averages over this sub-grid, such that it is the shape of the image (250, 250). surface_density = galaxy_util.surface_density_of_galaxies_from_grid(galaxies=[galaxy], grid=grid_stack.sub) surface_density = grid_stack.regular.scaled_array_from_array_1d(array_1d=surface_density) # Now, we'll set this surface density up as our 'galaxy-data', meaning that it is what we'll fit via a non-linear # search phase. To perform a fit we need a noise-map to help define our chi-squared. Given we are fitting a direct # lensing quantity the actual values of this noise-map arn't particularly important, so we'll just use a noise-map of # all 0.1's noise_map = scaled_array.ScaledSquarePixelArray(array=0.1*np.ones(surface_density.shape), pixel_scale=pixel_scale) data = gd.GalaxyData(image=surface_density, noise_map=noise_map, pixel_scale=pixel_scale) # The fit will use a mask, which we setup like any other fit. Lets use a circular mask of 2.0" def mask_function_circular(image): return msk.Mask.circular(shape=image.shape, pixel_scale=image.pixel_scale, radius_arcsec=2.0) # We can now use a special phase, called a 'GalaxyFitPhase', to fit this surface density with a model galaxy the # mass-profiles of which we get to choose. We'll fit it with a singular isothermal sphere and should see we retrieve # the input model above. phase = ph.GalaxyFitPhase(galaxies=dict(lens=gm.GalaxyModel(mass=mp.SphericalIsothermal)), use_surface_density=True, sub_grid_size=4, mask_function=mask_function_circular, optimizer_class=nl.MultiNest, phase_name='/galaxy_surface_density_fit') phase.run(galaxy_data=[data])
def make_noise_map(): return scaled_array.ScaledSquarePixelArray(array=np.ones((3, 3)), pixel_scale=3.0)
source_galaxy = g.Galaxy(redshift=1.0) # We'll use a tracer to compute our multi-plane deflection angles. tracer = ray_tracing.TracerMultiPlanes( galaxies=[lens_galaxy, perturber, source_galaxy], image_plane_grid_stack=grid_stack) # We'll now extract the deflection angles from the tracer - we will extract the two deflection angle maps (y and x) # separately. deflections_y = tracer.deflections_y deflections_x = tracer.deflections_x # Next, we create each deflection angle map as its own GalaxyData object. Again, this needs a somewhat arbritary # noise-map to be used in a fit. noise_map = scaled_array.ScaledSquarePixelArray(array=0.1 * np.ones(deflections_y.shape), pixel_scale=pixel_scale) data_y = gd.GalaxyData(image=deflections_y, noise_map=noise_map, pixel_scale=pixel_scale) data_x = gd.GalaxyData(image=deflections_x, noise_map=noise_map, pixel_scale=pixel_scale) # The fit will use a mask, which we setup like any other fit. Lets use a circular mask of 2.0" def mask_function_circular(image): return msk.Mask.circular(shape=image.shape, pixel_scale=image.pixel_scale, radius_arcsec=2.5)