Ejemplo n.º 1
0
    def test__setup_pixelization__galaxy_has_pixelization__returns_grids_with_pix_grid(
            self):

        ma = mask.Mask(np.array([[False, False, False], [False, False, False],
                                 [False, True, False]]),
                       pixel_scale=1.0)

        grid_stack = grids.GridStack.grid_stack_from_mask_sub_grid_size_and_psf_shape(
            mask=ma, sub_grid_size=1, psf_shape=(1, 1))

        galaxy = g.Galaxy(
            pixelization=pixelizations.AdaptiveMagnification(shape=(3, 3)),
            regularization=regularization.Constant())

        image_plane_pix_grids = \
            pixelizations.setup_image_plane_pixelization_grid_from_galaxies_and_grid_stack(galaxies=[galaxy, galaxy],
                                                                                           grid_stack=grid_stack)

        assert (image_plane_pix_grids.regular == grid_stack.regular).all()
        assert (image_plane_pix_grids.sub == grid_stack.sub).all()
        assert (image_plane_pix_grids.blurring == grid_stack.blurring).all()
        assert image_plane_pix_grids.pix == pytest.approx(
            np.array([[1.0, -1.0], [1.0, 0.0], [1.0, 1.0], [0.0, -1.0],
                      [0.0, 0.0], [0.0, 1.0], [-1.0, -1.0], [-1.0, 1.0]]),
            1.0e-4)
Ejemplo n.º 2
0
    def test__5_simple_grid__include_sub_grid__sets_up_correct_mapper(self):

        regular_grid = np.array([[1.0, 1.0], [-1.0, 1.0], [0.0, 0.0],
                                 [1.0, -1.0], [-1.0, -1.0]])

        sub_grid = np.array([[1.0, 1.0], [1.0, 1.0], [1.0, 1.0], [0.0, 0.0],
                             [-1.0, 1.0], [-1.0, 1.0], [-1.0, 1.0], [0.0, 0.0],
                             [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0],
                             [1.0, -1.0], [1.0, -1.0], [1.0, -1.0], [0.0, 0.0],
                             [-1.0, -1.0], [-1.0, -1.0], [-1.0, -1.0],
                             [0.0, 0.0]])

        sub_to_regular = np.array(
            [0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4])

        pixel_centers = regular_grid

        regular_to_sparse = np.array([0, 1, 2, 3, 4])

        grid_stack = MockGridStack(regular=regular_grid,
                                   sub=MockSubGrid(sub_grid,
                                                   sub_to_regular,
                                                   sub_grid_size=2),
                                   pix=pixel_centers,
                                   regular_to_nearest_pix=regular_to_sparse)

        pix = pixelizations.AdaptiveMagnification(shape=(5, 1))

        mapper = pix.mapper_from_grid_stack_and_border(grid_stack=grid_stack,
                                                       border=None)

        assert mapper.is_image_plane_pixelization == True
        assert mapper.geometry.shape_arc_seconds == pytest.approx((2.0, 2.0),
                                                                  1.0e-4)
        assert (mapper.geometry.pixel_centres == pixel_centers).all()
        assert mapper.geometry.origin == (0.0, 0.0)

        assert isinstance(mapper, pm.VoronoiMapper)

        assert (mapper.mapping_matrix == np.array([[0.75, 0.0, 0.25, 0.0, 0.0],
                                                   [0.0, 0.75, 0.25, 0.0, 0.0],
                                                   [0.0, 0.0, 1.0, 0.0, 0.0],
                                                   [0.0, 0.0, 0.25, 0.75, 0.0],
                                                   [0.0, 0.0, 0.25, 0.0,
                                                    0.75]])).all()

        reg = regularization.Constant(coefficients=(1.0, ))
        regularization_matrix = reg.regularization_matrix_from_pixel_neighbors(
            mapper.geometry.pixel_neighbors,
            mapper.geometry.pixel_neighbors_size)

        assert (regularization_matrix == np.array(
            [[3.00000001, -1.0, -1.0, -1.0, 0.0],
             [-1.0, 3.00000001, -1.0, 0.0, -1.0],
             [-1.0, -1.0, 4.00000001, -1.0, -1.0],
             [-1.0, 0.0, -1.0, 3.00000001, -1.0],
             [0.0, -1.0, -1.0, -1.0, 3.00000001]])).all()
Ejemplo n.º 3
0
    def test__3x3_simple_grid__include_mask__create_using_regular_grid(self):

        regular_grid = np.array([[1.0, 0.0], [0.0, -1.0], [0.0, 0.0],
                                 [0.0, 1.0], [-1.0, 0.0]])

        mask = msk.Mask(array=np.array([[True, False, True],
                                        [False, False, False],
                                        [True, False, True]]),
                        pixel_scale=1.0)

        sub_grid = np.array([[1.0, 0.0], [0.0, -1.0], [0.0, 0.0], [0.0, 1.0],
                             [-1.0, 0.0]])
        sub_to_regular = np.array([0, 1, 2, 3, 4])

        regular_grid = grids.RegularGrid(arr=regular_grid, mask=mask)
        sub_grid = MockSubGrid(sub_grid, sub_to_regular, sub_grid_size=1)

        pix = pixelizations.AdaptiveMagnification(shape=(3, 3))
        image_plane_pix = pix.image_plane_pix_grid_from_regular_grid(
            regular_grid=regular_grid)

        grid_stack = MockGridStack(
            regular=regular_grid,
            sub=sub_grid,
            pix=image_plane_pix.sparse_grid,
            regular_to_nearest_pix=image_plane_pix.regular_to_sparse)

        mapper = pix.mapper_from_grid_stack_and_border(grid_stack=grid_stack,
                                                       border=None)

        assert mapper.is_image_plane_pixelization == True
        assert mapper.geometry.shape_arc_seconds == pytest.approx((2.0, 2.0),
                                                                  1.0e-4)
        assert (mapper.geometry.pixel_centres == image_plane_pix.sparse_grid
                ).all()
        assert mapper.geometry.origin == pytest.approx((0.0, 0.0), 1.0e-4)

        assert isinstance(mapper, pm.VoronoiMapper)

        assert (mapper.mapping_matrix == np.array([[1.0, 0.0, 0.0, 0.0, 0.0],
                                                   [0.0, 1.0, 0.0, 0.0, 0.0],
                                                   [0.0, 0.0, 1.0, 0.0, 0.0],
                                                   [0.0, 0.0, 0.0, 1.0, 0.0],
                                                   [0.0, 0.0, 0.0, 0.0,
                                                    1.0]])).all()

        reg = regularization.Constant(coefficients=(1.0, ))
        regularization_matrix = reg.regularization_matrix_from_pixel_neighbors(
            mapper.geometry.pixel_neighbors,
            mapper.geometry.pixel_neighbors_size)

        assert (regularization_matrix == np.array(
            [[3.00000001, -1.0, -1.0, -1.0, 0.0],
             [-1.0, 3.00000001, -1.0, 0.0, -1.0],
             [-1.0, -1.0, 4.00000001, -1.0, -1.0],
             [-1.0, 0.0, -1.0, 3.00000001, -1.0],
             [0.0, -1.0, -1.0, -1.0, 3.00000001]])).all()
Ejemplo n.º 4
0
    def test__same_as_above_but_grid_requires_border_relocation(self):

        regular_grid = np.array([[1.0, -1.0], [1.0, 1.0], [0.0, 0.0],
                                 [-1.0, -1.0], [-1.0, 1.0]])
        sub_grid = np.array([[2.0, 2.0], [2.0, 2.0], [2.0, 2.0], [2.0, 2.0],
                             [-2.0, -2.0]])
        # These will all be relocated to the regular grid edge.
        pix_grid = np.array([[1.1, -1.1], [1.1, 1.1], [0.0, 0.0], [-1.1, -1.1],
                             [-1.1, 1.1]])

        border = grids.RegularGridBorder(arr=np.array([0, 1, 3, 4]))

        sub_to_regular = np.array([0, 1, 2, 3, 4])

        regular_to_sparse = np.array([0, 1, 2, 3, 4])

        grid_stack = MockGridStack(regular=regular_grid,
                                   sub=MockSubGrid(sub_grid,
                                                   sub_to_regular,
                                                   sub_grid_size=1),
                                   pix=pix_grid,
                                   regular_to_nearest_pix=regular_to_sparse)

        pix = pixelizations.AdaptiveMagnification(shape=(5, 1))

        mapper = pix.mapper_from_grid_stack_and_border(grid_stack=grid_stack,
                                                       border=border)

        assert mapper.is_image_plane_pixelization == True
        assert mapper.geometry.shape_arc_seconds == pytest.approx((2.0, 2.0),
                                                                  1.0e-4)
        assert mapper.geometry.pixel_centres == pytest.approx(
            regular_grid, 1e-4)
        assert mapper.geometry.origin == (0.0, 0.0)

        assert isinstance(mapper, pm.VoronoiMapper)

        assert (mapper.mapping_matrix == np.array([[0.0, 1.0, 0.0, 0.0, 0.0],
                                                   [0.0, 1.0, 0.0, 0.0, 0.0],
                                                   [0.0, 1.0, 0.0, 0.0, 0.0],
                                                   [0.0, 1.0, 0.0, 0.0, 0.0],
                                                   [0.0, 0.0, 0.0, 1.0,
                                                    0.0]])).all()

        reg = regularization.Constant(coefficients=(1.0, ))
        regularization_matrix = reg.regularization_matrix_from_pixel_neighbors(
            mapper.geometry.pixel_neighbors,
            mapper.geometry.pixel_neighbors_size)

        assert (regularization_matrix == np.array(
            [[3.00000001, -1.0, -1.0, -1.0, 0.0],
             [-1.0, 3.00000001, -1.0, 0.0, -1.0],
             [-1.0, -1.0, 4.00000001, -1.0, -1.0],
             [-1.0, 0.0, -1.0, 3.00000001, -1.0],
             [0.0, -1.0, -1.0, -1.0, 3.00000001]])).all()
Ejemplo n.º 5
0
    def test__setup_pixelization__galaxy_has_pixelization__but_grid_is_padded_grid__returns_normal_grids(
            self):

        ma = mask.Mask(np.array([[False, False, False], [False, False, False],
                                 [False, True, False]]),
                       pixel_scale=1.0)

        grid_stack = grids.GridStack.padded_grid_stack_from_mask_sub_grid_size_and_psf_shape(
            mask=ma, sub_grid_size=1, psf_shape=(1, 1))

        galaxy = g.Galaxy(
            pixelization=pixelizations.AdaptiveMagnification(shape=(3, 3)),
            regularization=regularization.Constant())

        image_plane_pix_grids = \
            pixelizations.setup_image_plane_pixelization_grid_from_galaxies_and_grid_stack(galaxies=[galaxy, galaxy],
                                                                                           grid_stack=grid_stack)

        assert image_plane_pix_grids == grid_stack
Ejemplo n.º 6
0
print()

sub_grid_size = 4
radius_arcsec = 3.0
psf_shape = (21, 21)
pixelization_shape = (30, 30)

print('sub grid size = ' + str(sub_grid_size))
print('circular mask radius = ' + str(radius_arcsec) + '\n')
print('psf shape = ' + str(psf_shape) + '\n')
print('pixelization shape = ' + str(pixelization_shape) + '\n')

lens_galaxy = g.Galaxy(mass=mp.EllipticalIsothermal(
    centre=(0.0, 0.0), einstein_radius=1.6, axis_ratio=0.7, phi=45.0))

pixelization = pix.AdaptiveMagnification(shape=pixelization_shape)

source_galaxy = g.Galaxy(pixelization=pixelization,
                         regularization=reg.Constant(coefficients=(1.0, )))

for image_type in ['LSST', 'Euclid', 'HST', 'HST_Up', 'AO']:

    ccd_data = tools.load_profiling_ccd_data(image_type=image_type,
                                             lens_name='no_lens_source_smooth',
                                             psf_shape=psf_shape)
    mask = msk.Mask.circular(shape=ccd_data.shape,
                             pixel_scale=ccd_data.pixel_scale,
                             radius_arcsec=radius_arcsec)
    lens_data = ld.LensData(ccd_data=ccd_data,
                            mask=mask,
                            sub_grid_size=sub_grid_size)
Ejemplo n.º 7
0
    list_.append(data)
    results = pd.concat(list_)


image_plane_grid_stack = grids.GridStack.from_shape_pixel_scale_and_sub_size(shape_2d=(301, 301), pixel_scales=0.03,
                                                                      sub_size=2)

for i in range(len(results)):
    lens_galaxy = al.Galaxy(mass=al.mp.EllipticalIsothermal(centre=(results['lens_mass_centre_0'][i], results['lens_mass_centre_1'][i]),
                                                    axis_ratio=results['lens_mass_axis_ratio'][i], phi=results['lens_mass_phi'][i],
                                                    einstein_radius=results['lens_mass_einstein_radius'][i]),
                       shear=al.mp.ExternalShear(magnitude=results['lens_shear_magnitude'][i], phi=results['lens_shear_phi'][i]),
                        redshift = slacs['z_lens'][i])

    source_galaxy = al.Galaxy(pixelization=pix.AdaptiveMagnification(shape_2d=(results['source_pixelization_shape_0'][i],
                                                                       results['source_pixelization_shape_1'][i])),
                         regularization=reg.Constant(results['source_regularization_coefficients_0'][i]),
                         redshift=slacs['z_source'][i])

    tracer = ray_tracing.TracerImageSourcePlanes(lens_galaxies=[lens_galaxy], source_galaxies=[source_galaxy],
                                             image_plane_grid_stack=image_plane_grid_stack, cosmology=cosmology.Planck15)
    einstein_mass = tracer.einstein_masses_of_planes[0]

    M_Ein.append(einstein_mass)

fig, ax = plt.subplots()

cm = plt.get_cmap('gist_rainbow')
ax.set_color_cycle([cm(1.*i/len(slacs)) for i in range(len(slacs))])
marker = ['o', '+','v','<','s','p','*','D','h','x','8','1','2','3','4',]
Ejemplo n.º 8
0
#    results = pd.concat(list_)

image_plane_grid_stack = grids.GridStack.from_shape_pixel_scale_and_sub_size(
    shape_2d=ccd_data.shape, pixel_scales=ccd_data.pixel_scales, sub_size=2)

#print(data)
#print(data.iloc[0,16])

lens_galaxy = al.Galaxy(mass=al.mp.EllipticalIsothermal(
    centre=(data.iloc[0, 5], data.iloc[0, 6]),
    axis_ratio=data.iloc[0, 7],
    phi=data.iloc[0, 8],
    einstein_radius=data.iloc[0, 9]),
                        redshift=0.285)
source_galaxy = al.Galaxy(
    pixelization=pix.AdaptiveMagnification(shape_2d=(data.iloc[0, 14],
                                                     data.iloc[0, 15])),
    regularization=reg.Constant(data.iloc[0, 16]),
    redshift=0.575)

#image_plane_grid_stack = grids.GridStack.from_shape_pixel_scale_and_sub_size(shape_2d=(301, 301), pixel_scales=0.03,
#                                                                      sub_size=2)

tracer = ray_tracing.TracerImageSourcePlanes(
    lens_galaxies=[lens_galaxy],
    source_galaxies=[source_galaxy],
    image_plane_grid_stack=lens_data.grid_stack,
    cosmology=cosmology.Planck15)

print(np.log10(tracer.einstein_masses_of_planes[0]))
Ejemplo n.º 9
0
        def test__number_of_pixels_and_regularization_set_up_correctly(self):

            pix = pixelizations.AdaptiveMagnification(shape=(3, 3))

            assert pix.shape == (3, 3)
    lens_galaxy_low = al.Galaxy(
        mass=al.mp.EllipticalIsothermal(
            centre=(results.loc[lens[i]]['param']['lens_mass_centre_0'],
                    results.loc[lens[i]]['param']['lens_mass_centre_1']),
            axis_ratio=results.loc[lens[i]]['+error']['lens_mass_axis_ratio'],
            phi=results.loc[lens[i]]['param']['lens_mass_phi'],
            einstein_radius=results.loc[
                lens[i]]['-error']['lens_mass_einstein_radius']),
        shear=al.mp.ExternalShear(
            magnitude=results.loc[lens[i]]['param']['lens_shear_magnitude'],
            phi=results.loc[lens[i]]['param']['lens_shear_phi']),
        redshift=slacs['z_lens'][i])

    source_galaxy = al.Galaxy(
        pixelization=pix.AdaptiveMagnification(shape_2d=(
            results.loc[lens[i]]['param']['source_pixelization_shape_0'],
            results.loc[lens[i]]['param']['source_pixelization_shape_1'])),
        regularization=reg.Constant(results.loc[lens[i]]['param']
                                    ['source_regularization_coefficients_0']),
        redshift=slacs['z_source'][i])

    tracer = ray_tracing.TracerImageSourcePlanes(
        lens_galaxies=[lens_galaxy],
        source_galaxies=[source_galaxy],
        image_plane_grid_stack=image_plane_grid_stack,
        cosmology=cosmology.Planck15)
    tracer_error_hi = ray_tracing.TracerImageSourcePlanes(
        lens_galaxies=[lens_galaxy_hi],
        source_galaxies=[source_galaxy],
        image_plane_grid_stack=image_plane_grid_stack,
        cosmology=cosmology.Planck15)