Exemplo n.º 1
0
def make_li_blur_stack():

    image_0 = np.array([[0.0, 0.0, 0.0, 0.0], [0.0, 1.0, 1.0, 0.0],
                        [0.0, 1.0, 1.0, 0.0], [0.0, 0.0, 0.0, 0.0]])
    psf_0 = ccd.PSF(array=(np.array([[1.0, 1.0, 1.0], [1.0, 1.0, 1.0],
                                     [1.0, 1.0, 1.0]])),
                    pixel_scale=1.0,
                    renormalize=False)
    ccd_0 = ccd.CCDData(image_0,
                        pixel_scale=1.0,
                        psf=psf_0,
                        noise_map=np.ones((4, 4)))

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

    image_1 = np.array([[0.0, 0.0, 0.0, 0.0], [0.0, 1.0, 1.0, 0.0],
                        [0.0, 1.0, 1.0, 0.0], [0.0, 0.0, 0.0, 0.0]])
    psf_1 = ccd.PSF(array=(np.array([[1.0, 1.0, 1.0], [1.0, 1.0, 1.0],
                                     [1.0, 1.0, 1.0]])),
                    pixel_scale=1.0,
                    renormalize=False)
    ccd_1 = ccd.CCDData(image_1,
                        pixel_scale=1.0,
                        psf=psf_1,
                        noise_map=np.ones((4, 4)))

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

    return lds.LensDataStack(ccd_datas=[ccd_0, ccd_1],
                             masks=[mask_0, mask_1],
                             sub_grid_size=1)
Exemplo n.º 2
0
    def test___3x3_padded_image__one_psf_blurs__other_asymmetric(self):

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

        padded_grid_stack = grids.GridStack.padded_grid_stack_from_mask_sub_grid_size_and_psf_shape(
            mask=mask, sub_grid_size=1, psf_shape=(3, 3))

        psf_0 = im.PSF(array=(np.array([[0.0, 0.0, 0.0], [0.0, 1.0, 0.0],
                                        [0.0, 0.0, 0.0]])),
                       pixel_scale=1.0)

        psf_1 = im.PSF(array=(np.array([[0.0, 3.0, 0.0], [0.0, 1.0, 2.0],
                                        [0.0, 0.0, 0.0]])),
                       pixel_scale=1.0)

        unmasked_image_1d_1 = np.zeros(25)
        unmasked_image_1d_1[12] = 1.0

        unmasked_blurred_images_of_datas = \
            stack_util.unmasked_blurred_image_of_datas_from_padded_grid_stacks_psfs_and_unmasked_images(
            padded_grid_stacks=[padded_grid_stack, padded_grid_stack], psfs=[psf_0, psf_1],
            unmasked_images_1d=[np.ones(25), unmasked_image_1d_1])

        assert (unmasked_blurred_images_of_datas[0] == np.ones((3, 3))).all()
        assert (unmasked_blurred_images_of_datas[1] == np.array(
            [[0.0, 3.0, 0.0], [0.0, 1.0, 2.0], [0.0, 0.0, 0.0]])).all()
Exemplo n.º 3
0
    def test__constructor_inputs(self):

        psf_0 = im.PSF(np.ones((7, 7)), 1)
        ccd_0 = im.CCDData(np.ones((51, 51)),
                           pixel_scale=3.,
                           psf=psf_0,
                           noise_map=np.ones((51, 51)))
        mask_0 = msk.Mask.unmasked_for_shape_and_pixel_scale(shape=(51, 51),
                                                             pixel_scale=1.0,
                                                             invert=True)
        mask_0[26, 26] = False

        psf_1 = im.PSF(np.ones((7, 7)), 1)
        ccd_1 = im.CCDData(np.ones((51, 51)),
                           pixel_scale=3.,
                           psf=psf_1,
                           noise_map=np.ones((51, 51)))
        mask_1 = msk.Mask.unmasked_for_shape_and_pixel_scale(shape=(51, 51),
                                                             pixel_scale=1.0,
                                                             invert=True)
        mask_1[26, 26] = False

        lens_data_stack = lis.LensDataStack(ccd_datas=[ccd_0, ccd_1],
                                            masks=[mask_0, mask_1],
                                            sub_grid_size=8,
                                            image_psf_shape=(5, 5),
                                            mapping_matrix_psf_shape=(3, 3),
                                            positions=[np.array([[1.0, 1.0]])])

        assert lens_data_stack.sub_grid_size == 8
        assert lens_data_stack.convolvers_image[0].psf_shape == (5, 5)
        assert lens_data_stack.convolvers_mapping_matrix[0].psf_shape == (3, 3)
        assert lens_data_stack.convolvers_image[1].psf_shape == (5, 5)
        assert lens_data_stack.convolvers_mapping_matrix[1].psf_shape == (3, 3)
        assert (lens_data_stack.positions[0] == np.array([[1.0, 1.0]])).all()
Exemplo n.º 4
0
    def test___same_as_above__use_galaxies_to_make_plane_images(self):

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

        padded_grid_stack = grids.GridStack.padded_grid_stack_from_mask_sub_grid_size_and_psf_shape(
            mask=mask, sub_grid_size=1, psf_shape=(3, 3))

        psf_0 = im.PSF(array=(np.array([[0.0, 0.0, 0.0], [0.0, 1.0, 0.0],
                                        [0.0, 0.0, 0.0]])),
                       pixel_scale=1.0)

        psf_1 = im.PSF(array=(np.array([[0.0, 3.0, 0.0], [0.0, 1.0, 2.0],
                                        [0.0, 0.0, 0.0]])),
                       pixel_scale=1.0)

        g0 = g.Galaxy(light_profile=lp.EllipticalSersic(intensity=0.1))
        g1 = g.Galaxy(light_profile=lp.EllipticalSersic(intensity=0.2))

        tracer = ray_tracing_stack.TracerImagePlaneStack(
            lens_galaxies=[g0, g1],
            image_plane_grid_stacks=[padded_grid_stack, padded_grid_stack])

        manual_blurred_image_00 = tracer.image_plane.image_plane_images_1d_of_galaxies[
            0][0]
        manual_blurred_image_00 = padded_grid_stack.regular.map_to_2d_keep_padded(
            padded_array_1d=manual_blurred_image_00)
        manual_blurred_image_00 = psf_0.convolve(array=manual_blurred_image_00)

        manual_blurred_image_01 = tracer.image_plane.image_plane_images_1d_of_galaxies[
            0][1]
        manual_blurred_image_01 = padded_grid_stack.regular.map_to_2d_keep_padded(
            padded_array_1d=manual_blurred_image_01)
        manual_blurred_image_01 = psf_0.convolve(array=manual_blurred_image_01)

        manual_blurred_image_10 = tracer.image_plane.image_plane_images_1d_of_galaxies[
            1][0]
        manual_blurred_image_10 = padded_grid_stack.regular.map_to_2d_keep_padded(
            padded_array_1d=manual_blurred_image_10)
        manual_blurred_image_10 = psf_1.convolve(array=manual_blurred_image_10)

        manual_blurred_image_11 = tracer.image_plane.image_plane_images_1d_of_galaxies[
            1][1]
        manual_blurred_image_11 = padded_grid_stack.regular.map_to_2d_keep_padded(
            padded_array_1d=manual_blurred_image_11)
        manual_blurred_image_11 = psf_1.convolve(array=manual_blurred_image_11)

        unmasked_blurred_image_of_datas_and_planes = \
            stack_util.unmasked_blurred_image_of_datas_and_planes_from_padded_grid_stacks_and_psf(
                planes=tracer.planes, padded_grid_stacks=[padded_grid_stack, padded_grid_stack], psfs=[psf_0, psf_1])

        assert unmasked_blurred_image_of_datas_and_planes[0][0] == \
                pytest.approx(manual_blurred_image_00[1:4, 1:4] + manual_blurred_image_01[1:4, 1:4], 1.0e-4)
        assert unmasked_blurred_image_of_datas_and_planes[1][0] == \
                pytest.approx(manual_blurred_image_10[1:4, 1:4] + manual_blurred_image_11[1:4, 1:4], 1.0e-4)
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
        def test__1x2_image__tracing_fits_data_with_chi_sq_5_and_chi_sq_4(
                self):

            psf_0 = ccd.PSF(array=(np.array([[0.0, 0.0, 0.0], [0.0, 1.0, 0.0],
                                             [0.0, 0.0, 0.0]])),
                            pixel_scale=1.0)
            ccd_0 = ccd.CCDData(5.0 * np.ones((3, 4)),
                                pixel_scale=1.0,
                                psf=psf_0,
                                noise_map=np.ones((3, 4)))
            ccd_0.image[1, 2] = 4.0
            mask_0 = msk.Mask(array=np.array([[True, True, True, True],
                                              [True, False, False, True],
                                              [True, True, True, True]]),
                              pixel_scale=1.0)

            psf_1 = ccd.PSF(array=(np.array([[0.0, 0.0, 0.0], [0.0, 1.0, 0.0],
                                             [0.0, 0.0, 0.0]])),
                            pixel_scale=1.0)
            ccd_1 = ccd.CCDData(5.0 * np.ones((3, 4)),
                                pixel_scale=1.0,
                                psf=psf_1,
                                noise_map=np.ones((3, 4)))
            mask_1 = msk.Mask(array=np.array([[True, True, True, True],
                                              [True, False, False, True],
                                              [True, True, True, True]]),
                              pixel_scale=1.0)

            li_stack = lds.LensDataStack(ccd_datas=[ccd_0, ccd_1],
                                         masks=[mask_0, mask_1],
                                         sub_grid_size=1)

            # Setup as a ray trace instance, using a light profile for the lens

            g0 = g.Galaxy(light_profile=MockLightProfile(value=1.0, size=2))
            tracer = ray_tracing_stack.TracerImagePlaneStack(
                lens_galaxies=[g0],
                image_plane_grid_stacks=li_stack.grid_stacks)

            fit = lens_fit_stack.LensProfileFitStack(lens_data_stack=li_stack,
                                                     tracer=tracer)

            assert fit.chi_squared == 25.0 + 32.0
            assert fit.reduced_chi_squared == (25.0 + 32.0) / 2.0
            assert fit.likelihood == -0.5 * (
                (25.0 + 2.0 * np.log(2 * np.pi * 1.0)) +
                (32.0 + 2.0 * np.log(2 * np.pi * 1.0)))
Exemplo n.º 7
0
def make_lens_image():
    ccd_data = ccd.CCDData(np.array(np.zeros(shape)),
                           pixel_scale=1.0,
                           psf=ccd.PSF(np.ones((3, 3)), pixel_scale=1.0),
                           noise_map=ccd.NoiseMap(np.ones(shape),
                                                  pixel_scale=1.0))
    mask = msk.Mask.circular(shape=shape, pixel_scale=1, radius_arcsec=3.0)
    return li.LensData(ccd_data=ccd_data, mask=mask)
Exemplo n.º 8
0
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)
Exemplo n.º 9
0
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)))
Exemplo n.º 10
0
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)
Exemplo n.º 11
0
        def test__image__tracing_fits_data_perfectly__no_psf_blurring__lh_is_noise_normalization(
                self):

            psf_0 = ccd.PSF(array=(np.array([[0.0, 0.0, 0.0], [0.0, 1.0, 0.0],
                                             [0.0, 0.0, 0.0]])),
                            pixel_scale=1.0)
            ccd_0 = ccd.CCDData(np.ones((3, 3)),
                                pixel_scale=1.0,
                                psf=psf_0,
                                noise_map=np.ones((3, 3)))
            mask_0 = msk.Mask(array=np.array([[True, True, True],
                                              [True, False, True],
                                              [True, True, True]]),
                              pixel_scale=1.0)

            psf_1 = ccd.PSF(array=(np.array([[0.0, 0.0, 0.0], [0.0, 1.0, 0.0],
                                             [0.0, 0.0, 0.0]])),
                            pixel_scale=1.0)
            ccd_1 = ccd.CCDData(np.ones((3, 3)),
                                pixel_scale=1.0,
                                psf=psf_1,
                                noise_map=np.ones((3, 3)))
            mask_1 = msk.Mask(array=np.array([[True, True, True],
                                              [True, False, True],
                                              [True, True, True]]),
                              pixel_scale=1.0)

            li_stack = lds.LensDataStack(ccd_datas=[ccd_0, ccd_1],
                                         masks=[mask_0, mask_1],
                                         sub_grid_size=1)

            g0 = g.Galaxy(light_profile=MockLightProfile(value=1.0))
            tracer = ray_tracing_stack.TracerImagePlaneStack(
                lens_galaxies=[g0],
                image_plane_grid_stacks=li_stack.grid_stacks)

            fit = lens_fit_stack.LensProfileFitStack(lens_data_stack=li_stack,
                                                     tracer=tracer)
            assert fit.likelihood == 2.0 * -0.5 * np.log(2 * np.pi * 1.0)
Exemplo n.º 12
0
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)
Exemplo n.º 13
0
def make_li_manual_stack():

    image_0 = np.array([[0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 1.0, 2.0, 3.0, 0.0],
                        [0.0, 4.0, 5.0, 6.0, 0.0], [0.0, 7.0, 8.0, 9.0, 0.0],
                        [0.0, 0.0, 0.0, 0.0, 0.0]])
    psf_0 = ccd.PSF(array=(np.array([[1.0, 5.0, 9.0], [2.0, 5.0, 1.0],
                                     [3.0, 4.0, 0.0]])),
                    pixel_scale=1.0)
    ccd_0 = ccd.CCDData(image_0,
                        pixel_scale=1.0,
                        psf=psf_0,
                        noise_map=np.ones((5, 5)))
    mask_0 = msk.Mask(array=np.array([[True, True, True, True, True],
                                      [True, False, False, False, True],
                                      [True, False, False, False, True],
                                      [True, False, False, False, True],
                                      [True, True, True, True, True]]),
                      pixel_scale=1.0)

    image_1 = np.array([[0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 1.0, 2.0, 3.0, 0.0],
                        [0.0, 4.0, 6.0, 6.0, 0.0], [0.0, 7.0, 8.0, 9.0, 0.0],
                        [0.0, 0.0, 0.0, 0.0, 0.0]])
    psf_1 = ccd.PSF(array=(np.array([[1.0, 1.0, 1.0], [2.0, 1.0, 1.0],
                                     [3.0, 1.0, 0.0]])),
                    pixel_scale=1.0)
    ccd_1 = ccd.CCDData(image_1,
                        pixel_scale=1.0,
                        psf=psf_1,
                        noise_map=np.ones((5, 5)))
    mask_1 = msk.Mask(array=np.array([[True, True, True, True, True],
                                      [True, False, False, False, True],
                                      [True, False, False, False, True],
                                      [True, False, False, True, True],
                                      [True, True, True, True, True]]),
                      pixel_scale=1.0)

    return lds.LensDataStack(ccd_datas=[ccd_0, ccd_1],
                             masks=[mask_0, mask_1],
                             sub_grid_size=1)
Exemplo n.º 14
0
    def test__constructor_inputs(self):

        psf = ccd.PSF(np.ones((7, 7)), 1)
        image = ccd.CCDData(np.ones((51, 51)), pixel_scale=3., psf=psf, noise_map=np.ones((51, 51)))
        mask = msk.Mask.unmasked_for_shape_and_pixel_scale(shape=(51, 51), pixel_scale=1.0, invert=True)
        mask[26, 26] = False

        lens_data = ld.LensData(image, mask, sub_grid_size=8, image_psf_shape=(5, 5),
                                 mapping_matrix_psf_shape=(3, 3), positions=[np.array([[1.0, 1.0]])])

        assert lens_data.sub_grid_size == 8
        assert lens_data.convolver_image.psf_shape == (5, 5)
        assert lens_data.convolver_mapping_matrix.psf_shape == (3, 3)
        assert (lens_data.positions[0] == np.array([[1.0, 1.0]])).all()

        assert lens_data.image_psf_shape == (5,5)
        assert lens_data.mapping_matrix_psf_shape == (3,3)
Exemplo n.º 15
0
def make_lens_data_blur():

    psf = ccd.PSF(array=(np.array([[1.0, 1.0, 1.0], [1.0, 1.0, 1.0],
                                   [1.0, 1.0, 1.0]])),
                  pixel_scale=1.0,
                  renormalize=False)
    im = ccd.CCDData(image=5.0 * np.ones((6, 6)),
                     pixel_scale=1.0,
                     psf=psf,
                     noise_map=np.ones((6, 6)),
                     exposure_time_map=3.0 * np.ones((6, 6)),
                     background_sky_map=4.0 * np.ones((6, 6)))

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

    return ld.LensData(ccd_data=im, mask=ma, sub_grid_size=2)
Exemplo n.º 16
0
    def test___if_galaxy_has_pixelization__unmasked_image_is_none(self):

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

        padded_grid_stack = grids.GridStack.padded_grid_stack_from_mask_sub_grid_size_and_psf_shape(
            mask=mask, sub_grid_size=1, psf_shape=(3, 3))

        psf_0 = im.PSF(array=(np.array([[0.0, 0.0, 0.0], [0.0, 1.0, 0.0],
                                        [0.0, 0.0, 0.0]])),
                       pixel_scale=1.0)

        psf_1 = im.PSF(array=(np.array([[0.0, 3.0, 0.0], [0.0, 1.0, 2.0],
                                        [0.0, 0.0, 0.0]])),
                       pixel_scale=1.0)

        g0 = g.Galaxy(light_profile=lp.EllipticalSersic(intensity=0.1),
                      pixelization=pix.Rectangular(),
                      regularization=reg.Constant())
        g1 = g.Galaxy(light_profile=lp.EllipticalSersic(intensity=0.2))
        g2 = g.Galaxy(mass_profile=mp.SphericalIsothermal(einstein_radius=1.0))

        tracer = ray_tracing_stack.TracerImageSourcePlanesStack(
            lens_galaxies=[g0, g1, g2],
            source_galaxies=[g0, g1],
            image_plane_grid_stacks=[padded_grid_stack, padded_grid_stack])

        unmasked_blurred_image_of_datas_planes_and_galaxies = \
            stack_util.unmasked_blurred_image_of_datas_planes_and_galaxies_from_padded_grid_stacks_and_psf(
                planes=tracer.planes, padded_grid_stacks=[padded_grid_stack, padded_grid_stack], psfs=[psf_0, psf_1])

        assert unmasked_blurred_image_of_datas_planes_and_galaxies[0][0][
            0] == None
        assert type(unmasked_blurred_image_of_datas_planes_and_galaxies[0][0]
                    [1]) == scaled_array.ScaledSquarePixelArray
        assert unmasked_blurred_image_of_datas_planes_and_galaxies[1][0][
            0] == None
        assert type(unmasked_blurred_image_of_datas_planes_and_galaxies[1][0]
                    [1]) == scaled_array.ScaledSquarePixelArray
        assert unmasked_blurred_image_of_datas_planes_and_galaxies[0][1][
            0] == None
        assert type(unmasked_blurred_image_of_datas_planes_and_galaxies[0][1]
                    [1]) == scaled_array.ScaledSquarePixelArray
        assert unmasked_blurred_image_of_datas_planes_and_galaxies[1][1][
            0] == None
        assert type(unmasked_blurred_image_of_datas_planes_and_galaxies[1][1]
                    [1]) == scaled_array.ScaledSquarePixelArray

        g0 = g.Galaxy(light_profile=lp.EllipticalSersic(intensity=0.1))
        g1 = g.Galaxy(light_profile=lp.EllipticalSersic(intensity=0.2),
                      pixelization=pix.Rectangular(),
                      regularization=reg.Constant())
        g2 = g.Galaxy(mass_profile=mp.SphericalIsothermal(einstein_radius=1.0))

        tracer = ray_tracing_stack.TracerImageSourcePlanesStack(
            lens_galaxies=[g0, g1, g2],
            source_galaxies=[g0, g1],
            image_plane_grid_stacks=[padded_grid_stack, padded_grid_stack])

        unmasked_blurred_image_of_datas_planes_and_galaxies = \
            stack_util.unmasked_blurred_image_of_datas_planes_and_galaxies_from_padded_grid_stacks_and_psf(
                planes=tracer.planes, padded_grid_stacks=[padded_grid_stack, padded_grid_stack], psfs=[psf_0, psf_1])

        assert type(unmasked_blurred_image_of_datas_planes_and_galaxies[0][0]
                    [0]) == scaled_array.ScaledSquarePixelArray
        assert unmasked_blurred_image_of_datas_planes_and_galaxies[0][0][
            1] == None
        assert type(unmasked_blurred_image_of_datas_planes_and_galaxies[1][0]
                    [0]) == scaled_array.ScaledSquarePixelArray
        assert unmasked_blurred_image_of_datas_planes_and_galaxies[1][0][
            1] == None
        assert type(unmasked_blurred_image_of_datas_planes_and_galaxies[0][1]
                    [0]) == scaled_array.ScaledSquarePixelArray
        assert unmasked_blurred_image_of_datas_planes_and_galaxies[0][1][
            1] == None
        assert type(unmasked_blurred_image_of_datas_planes_and_galaxies[1][1]
                    [0]) == scaled_array.ScaledSquarePixelArray
        assert unmasked_blurred_image_of_datas_planes_and_galaxies[1][1][
            1] == None
Exemplo n.º 17
0
    def test___same_as_above__image_and_source_plane(self):

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

        padded_grid_stack = grids.GridStack.padded_grid_stack_from_mask_sub_grid_size_and_psf_shape(
            mask=mask, sub_grid_size=1, psf_shape=(3, 3))

        psf_0 = im.PSF(array=(np.array([[0.0, 0.0, 0.0], [0.0, 1.0, 0.0],
                                        [0.0, 0.0, 0.0]])),
                       pixel_scale=1.0)

        psf_1 = im.PSF(array=(np.array([[0.0, 3.0, 0.0], [0.0, 1.0, 2.0],
                                        [0.0, 0.0, 0.0]])),
                       pixel_scale=1.0)

        g0 = g.Galaxy(light_profile=lp.EllipticalSersic(intensity=0.1))
        g1 = g.Galaxy(light_profile=lp.EllipticalSersic(intensity=0.2))
        g2 = g.Galaxy(mass_profile=mp.SphericalIsothermal(einstein_radius=1.0))

        tracer = ray_tracing_stack.TracerImageSourcePlanesStack(
            lens_galaxies=[g0, g1, g2],
            source_galaxies=[g0, g1],
            image_plane_grid_stacks=[padded_grid_stack, padded_grid_stack])

        manual_blurred_image_i00 = tracer.image_plane.image_plane_images_1d_of_galaxies[
            0][0]
        manual_blurred_image_i00 = padded_grid_stack.regular.map_to_2d_keep_padded(
            padded_array_1d=manual_blurred_image_i00)
        manual_blurred_image_i00 = psf_0.convolve(
            array=manual_blurred_image_i00)

        manual_blurred_image_i01 = tracer.image_plane.image_plane_images_1d_of_galaxies[
            0][1]
        manual_blurred_image_i01 = padded_grid_stack.regular.map_to_2d_keep_padded(
            padded_array_1d=manual_blurred_image_i01)
        manual_blurred_image_i01 = psf_0.convolve(
            array=manual_blurred_image_i01)

        manual_blurred_image_i10 = tracer.image_plane.image_plane_images_1d_of_galaxies[
            1][0]
        manual_blurred_image_i10 = padded_grid_stack.regular.map_to_2d_keep_padded(
            padded_array_1d=manual_blurred_image_i10)
        manual_blurred_image_i10 = psf_1.convolve(
            array=manual_blurred_image_i10)

        manual_blurred_image_i11 = tracer.image_plane.image_plane_images_1d_of_galaxies[
            1][1]
        manual_blurred_image_i11 = padded_grid_stack.regular.map_to_2d_keep_padded(
            padded_array_1d=manual_blurred_image_i11)
        manual_blurred_image_i11 = psf_1.convolve(
            array=manual_blurred_image_i11)

        manual_blurred_image_s00 = tracer.source_plane.image_plane_images_1d_of_galaxies[
            0][0]
        manual_blurred_image_s00 = padded_grid_stack.regular.map_to_2d_keep_padded(
            padded_array_1d=manual_blurred_image_s00)
        manual_blurred_image_s00 = psf_0.convolve(
            array=manual_blurred_image_s00)

        manual_blurred_image_s01 = tracer.source_plane.image_plane_images_1d_of_galaxies[
            0][1]
        manual_blurred_image_s01 = padded_grid_stack.regular.map_to_2d_keep_padded(
            padded_array_1d=manual_blurred_image_s01)
        manual_blurred_image_s01 = psf_0.convolve(
            array=manual_blurred_image_s01)

        manual_blurred_image_s10 = tracer.source_plane.image_plane_images_1d_of_galaxies[
            1][0]
        manual_blurred_image_s10 = padded_grid_stack.regular.map_to_2d_keep_padded(
            padded_array_1d=manual_blurred_image_s10)
        manual_blurred_image_s10 = psf_1.convolve(
            array=manual_blurred_image_s10)

        manual_blurred_image_s11 = tracer.source_plane.image_plane_images_1d_of_galaxies[
            1][1]
        manual_blurred_image_s11 = padded_grid_stack.regular.map_to_2d_keep_padded(
            padded_array_1d=manual_blurred_image_s11)
        manual_blurred_image_s11 = psf_1.convolve(
            array=manual_blurred_image_s11)

        unmasked_blurred_image_of_datas_planes_and_galaxies = \
            stack_util.unmasked_blurred_image_of_datas_planes_and_galaxies_from_padded_grid_stacks_and_psf(
                planes=tracer.planes, padded_grid_stacks=[padded_grid_stack, padded_grid_stack], psfs=[psf_0, psf_1])

        assert (unmasked_blurred_image_of_datas_planes_and_galaxies[0][0][0] ==
                manual_blurred_image_i00[1:4, 1:4]).all()
        assert (unmasked_blurred_image_of_datas_planes_and_galaxies[0][0][1] ==
                manual_blurred_image_i01[1:4, 1:4]).all()
        assert (unmasked_blurred_image_of_datas_planes_and_galaxies[1][0][0] ==
                manual_blurred_image_i10[1:4, 1:4]).all()
        assert (unmasked_blurred_image_of_datas_planes_and_galaxies[1][0][1] ==
                manual_blurred_image_i11[1:4, 1:4]).all()
        assert (unmasked_blurred_image_of_datas_planes_and_galaxies[0][1][0] ==
                manual_blurred_image_s00[1:4, 1:4]).all()
        assert (unmasked_blurred_image_of_datas_planes_and_galaxies[0][1][1] ==
                manual_blurred_image_s01[1:4, 1:4]).all()
        assert (unmasked_blurred_image_of_datas_planes_and_galaxies[1][1][0] ==
                manual_blurred_image_s10[1:4, 1:4]).all()
        assert (unmasked_blurred_image_of_datas_planes_and_galaxies[1][1][1] ==
                manual_blurred_image_s11[1:4, 1:4]).all()
Exemplo n.º 18
0
def test__simulate_lensed_source_and_fit__no_psf_blurring__chi_squared_is_0__noise_normalization_correct(
):

    psf = ccd.PSF(array=np.array([[0.0, 0.0, 0.0], [0.0, 1.0, 0.0],
                                  [0.0, 0.0, 0.0]]),
                  pixel_scale=0.2)

    grid_stack = grids.GridStack.grid_stack_for_simulation(shape=(11, 11),
                                                           pixel_scale=0.2,
                                                           psf_shape=psf.shape,
                                                           sub_grid_size=2)

    lens_galaxy = g.Galaxy(light=lp.EllipticalSersic(centre=(0.1, 0.1),
                                                     intensity=0.1),
                           mass=mp.EllipticalIsothermal(centre=(0.1, 0.1),
                                                        einstein_radius=1.8))

    source_galaxy = g.Galaxy(
        light=lp.EllipticalExponential(centre=(0.1, 0.1), intensity=0.5))

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

    ccd_simulated = ccd.CCDData.simulate(
        array=tracer.image_plane_image_for_simulation,
        pixel_scale=0.2,
        exposure_time=300.0,
        psf=psf,
        background_sky_level=None,
        add_noise=False)
    ccd_simulated.noise_map = np.ones(ccd_simulated.image.shape)

    path = "{}/data/simulate_and_fit".format(
        os.path.dirname(os.path.realpath(
            __file__)))  # Setup path so we can output the simulated image.

    try:
        shutil.rmtree(path)
    except FileNotFoundError:
        pass

    if os.path.exists(path) == False:
        os.makedirs(path)

    array_util.numpy_array_to_fits(array=ccd_simulated.image,
                                   file_path=path + '/image.fits')
    array_util.numpy_array_to_fits(array=ccd_simulated.noise_map,
                                   file_path=path + '/noise_map.fits')
    array_util.numpy_array_to_fits(array=psf, file_path=path + '/psf.fits')

    ccd_data = ccd.load_ccd_data_from_fits(image_path=path + '/image.fits',
                                           noise_map_path=path +
                                           '/noise_map.fits',
                                           psf_path=path + '/psf.fits',
                                           pixel_scale=0.2)

    mask = msk.Mask.circular(shape=ccd_data.image.shape,
                             pixel_scale=0.2,
                             radius_arcsec=0.8)

    lens_data = ld.LensData(ccd_data=ccd_data, mask=mask, sub_grid_size=2)

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

    fitter = lens_fit.LensProfileFit(lens_data=lens_data, tracer=tracer)

    assert fitter.chi_squared == 0.0