Exemplo n.º 1
0
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)
Exemplo n.º 2
0
    def test__multiple_use_methods__raises_exception(self, image, mask):

        galaxy_data = gd.GalaxyData(image=image,
                                    noise_map=2.0 * np.ones((4, 4)),
                                    pixel_scale=3.0)

        with pytest.raises(exc.GalaxyException):
            gd.GalaxyFitData(galaxy_data=galaxy_data,
                             mask=mask,
                             sub_grid_size=2,
                             use_intensities=True,
                             use_surface_density=True)

        with pytest.raises(exc.GalaxyException):
            gd.GalaxyFitData(galaxy_data=galaxy_data,
                             mask=mask,
                             sub_grid_size=2,
                             use_intensities=True,
                             use_potential=True)

        with pytest.raises(exc.GalaxyException):
            gd.GalaxyFitData(galaxy_data=galaxy_data,
                             mask=mask,
                             sub_grid_size=2,
                             use_intensities=True,
                             use_deflections_y=True)

        with pytest.raises(exc.GalaxyException):
            gd.GalaxyFitData(galaxy_data=galaxy_data,
                             mask=mask,
                             sub_grid_size=2,
                             use_intensities=True,
                             use_surface_density=True,
                             use_potential=True)

        with pytest.raises(exc.GalaxyException):
            gd.GalaxyFitData(galaxy_data=galaxy_data,
                             mask=mask,
                             sub_grid_size=2,
                             use_intensities=True,
                             use_surface_density=True,
                             use_potential=True,
                             use_deflections_x=True)
Exemplo n.º 3
0
    def test__no_use_method__raises_exception(self, image, mask):

        galaxy_data = gd.GalaxyData(image=image,
                                    noise_map=2.0 * np.ones((4, 4)),
                                    pixel_scale=3.0)

        with pytest.raises(exc.GalaxyException):
            gd.GalaxyFitData(galaxy_data=galaxy_data,
                             mask=mask,
                             sub_grid_size=2)
Exemplo n.º 4
0
    def test__galaxy_data_deflections_x(self, image, mask):

        galaxy_data = gd.GalaxyData(image=image,
                                    noise_map=2.0 * np.ones((4, 4)),
                                    pixel_scale=3.0)

        galaxy_fit_data = gd.GalaxyFitData(galaxy_data=galaxy_data,
                                           mask=mask,
                                           sub_grid_size=2,
                                           use_deflections_x=True)

        assert galaxy_fit_data.pixel_scale == 3.0
        assert (galaxy_fit_data.image == np.ones((4, 4))).all()
        assert (galaxy_fit_data.noise_map == 2.0 * np.ones((4, 4))).all()
        assert (galaxy_fit_data.mask == np.array([[True, True, True, True],
                                                  [True, False, False, True],
                                                  [True, False, False, True],
                                                  [True, True, True,
                                                   True]])).all()
        assert (galaxy_fit_data.image_1d == np.ones(4)).all()
        assert (galaxy_fit_data.noise_map_1d == 2.0 * np.ones(4)).all()
        assert (galaxy_fit_data.mask_1d == np.array(
            [False, False, False, False])).all()

        galaxy = MockGalaxy(value=1, shape=4)

        deflections_x = galaxy_fit_data.profile_quantity_from_galaxy_and_sub_grid(
            galaxies=[galaxy], sub_grid=galaxy_fit_data.grid_stack.sub)

        assert (deflections_x == np.array([1.0, 1.0, 1.0, 1.0])).all()

        galaxy = g.Galaxy(mass=mp.SphericalIsothermal(einstein_radius=1.0))

        deflections_gal = galaxy.deflections_from_grid(
            grid=galaxy_fit_data.grid_stack.sub)
        deflections_gal = np.asarray([
            galaxy_fit_data.grid_stack.sub.sub_data_to_regular_data(
                deflections_gal[:, 0]),
            galaxy_fit_data.grid_stack.sub.sub_data_to_regular_data(
                deflections_gal[:, 1])
        ]).T

        deflections_gd = galaxy_fit_data.profile_quantity_from_galaxy_and_sub_grid(
            galaxies=[galaxy], sub_grid=galaxy_fit_data.grid_stack.sub)

        assert (deflections_gal[:, 1] == deflections_gd).all()
Exemplo n.º 5
0
    def test__galaxy_data_intensities(self, image, mask):

        galaxy_data = gd.GalaxyData(image=image,
                                    noise_map=2.0 * np.ones((4, 4)),
                                    pixel_scale=3.0)

        galaxy_fit_data = gd.GalaxyFitData(galaxy_data=galaxy_data,
                                           mask=mask,
                                           sub_grid_size=2,
                                           use_intensities=True)

        assert galaxy_fit_data.pixel_scale == 3.0
        assert (galaxy_fit_data.image == np.ones((4, 4))).all()
        assert (galaxy_fit_data.noise_map == 2.0 * np.ones((4, 4))).all()
        assert (galaxy_fit_data.mask == np.array([[True, True, True, True],
                                                  [True, False, False, True],
                                                  [True, False, False, True],
                                                  [True, True, True,
                                                   True]])).all()
        assert (galaxy_fit_data.image_1d == np.ones(4)).all()
        assert (galaxy_fit_data.noise_map_1d == 2.0 * np.ones(4)).all()
        assert (galaxy_fit_data.mask_1d == np.array(
            [False, False, False, False])).all()

        galaxy = MockGalaxy(value=1, shape=4)

        intensities = galaxy_fit_data.profile_quantity_from_galaxy_and_sub_grid(
            galaxies=[galaxy], sub_grid=galaxy_fit_data.grid_stack.sub)

        assert (intensities == np.array([1.0, 1.0, 1.0, 1.0])).all()

        galaxy = g.Galaxy(light=lp.SphericalSersic(intensity=1.0))

        intensities_gal = galaxy.intensities_from_grid(
            grid=galaxy_fit_data.grid_stack.sub)
        intensities_gal = galaxy_fit_data.grid_stack.sub.sub_data_to_regular_data(
            sub_array=intensities_gal)

        intensities_gd = galaxy_fit_data.profile_quantity_from_galaxy_and_sub_grid(
            galaxies=[galaxy], sub_grid=galaxy_fit_data.grid_stack.sub)

        assert (intensities_gal == intensities_gd).all()
Exemplo n.º 6
0
    def make_analysis(self, galaxy_data, results=None, mask=None):
        """
        Create an lens object. Also calls the prior passing and lens_data modifying
        functions to allow child classes to change the behaviour of the phase.

        Parameters
        ----------
        galaxy_data
        mask: Mask
            The default masks passed in by the pipeline
        results: autofit.tools.pipeline.ResultsCollection
            The result from the previous phase

        Returns
        -------
        lens: Analysis
            An lens object that the non-linear optimizer calls to determine the fit of a
             set of values
        """

        mask = setup_phase_mask(
            data=galaxy_data[0],
            mask=mask,
            mask_function=self.mask_function,
            inner_mask_radii=None,
        )

        if self.use_image or self.use_convergence or self.use_potential:

            galaxy_data = gd.GalaxyFitData(
                galaxy_data=galaxy_data[0],
                mask=mask,
                pixel_scale_interpolation_grid=self.
                pixel_scale_interpolation_grid,
                use_image=self.use_image,
                use_convergence=self.use_convergence,
                use_potential=self.use_potential,
                use_deflections_y=self.use_deflections,
                use_deflections_x=self.use_deflections,
            )

            return AnalysisSingle(
                galaxy_data=galaxy_data,
                cosmology=self.cosmology,
                image_path=self.optimizer.image_path,
                results=results,
            )

        elif self.use_deflections:

            galaxy_data_y = gd.GalaxyFitData(
                galaxy_data=galaxy_data[0],
                mask=mask,
                pixel_scale_interpolation_grid=self.
                pixel_scale_interpolation_grid,
                use_image=self.use_image,
                use_convergence=self.use_convergence,
                use_potential=self.use_potential,
                use_deflections_y=self.use_deflections,
                use_deflections_x=False,
            )

            galaxy_data_x = gd.GalaxyFitData(
                galaxy_data=galaxy_data[1],
                mask=mask,
                pixel_scale_interpolation_grid=self.
                pixel_scale_interpolation_grid,
                use_image=self.use_image,
                use_convergence=self.use_convergence,
                use_potential=self.use_potential,
                use_deflections_y=False,
                use_deflections_x=self.use_deflections,
            )

            return AnalysisDeflections(
                galaxy_data_y=galaxy_data_y,
                galaxy_data_x=galaxy_data_x,
                cosmology=self.cosmology,
                image_path=self.optimizer.image_path,
                results=results,
            )
def make_galaxy_data_deflections_x(galaxy_data, mask):
    return gd.GalaxyFitData(galaxy_data=galaxy_data,
                            mask=mask,
                            sub_grid_size=2,
                            use_deflections_x=True)
def make_galaxy_data_potential(galaxy_data, mask):
    return gd.GalaxyFitData(galaxy_data=galaxy_data,
                            mask=mask,
                            sub_grid_size=2,
                            use_potential=True)
def make_galaxy_data_surface_density(galaxy_data, mask):
    return gd.GalaxyFitData(galaxy_data=galaxy_data,
                            mask=mask,
                            sub_grid_size=2,
                            use_surface_density=True)
Exemplo n.º 10
0
def make_galaxy_data_intensities(galaxy_data, mask):
    return gd.GalaxyFitData(galaxy_data=galaxy_data,
                            mask=mask,
                            sub_grid_size=2,
                            use_intensities=True)