def test__fit_sub_plot__all_types_of_galaxy_fit(
    gal_fit_7x7_image,
    gal_fit_7x7_convergence,
    gal_fit_7x7_potential,
    gal_fit_7x7_deflections_y,
    gal_fit_7x7_deflections_x,
    positions_7x7,
    include_all,
    plot_patch,
    galaxy_fit_plotter_path,
):
    aplt.fit_galaxy.subplot_fit_galaxy(
        fit=gal_fit_7x7_image,
        positions=positions_7x7,
        include=include_all,
        sub_plotter=aplt.SubPlotter(
            output=aplt.Output(path=galaxy_fit_plotter_path, format="png")),
    )

    assert galaxy_fit_plotter_path + "subplot_fit_galaxy.png" in plot_patch.paths

    aplt.fit_galaxy.subplot_fit_galaxy(
        fit=gal_fit_7x7_convergence,
        positions=positions_7x7,
        include=include_all,
        sub_plotter=aplt.SubPlotter(
            output=aplt.Output(path=galaxy_fit_plotter_path, format="png")),
    )

    assert galaxy_fit_plotter_path + "subplot_fit_galaxy.png" in plot_patch.paths

    aplt.fit_galaxy.subplot_fit_galaxy(
        fit=gal_fit_7x7_potential,
        positions=positions_7x7,
        include=include_all,
        sub_plotter=aplt.SubPlotter(
            output=aplt.Output(path=galaxy_fit_plotter_path, format="png")),
    )

    assert galaxy_fit_plotter_path + "subplot_fit_galaxy.png" in plot_patch.paths

    aplt.fit_galaxy.subplot_fit_galaxy(
        fit=gal_fit_7x7_deflections_y,
        positions=positions_7x7,
        include=include_all,
        sub_plotter=aplt.SubPlotter(
            output=aplt.Output(path=galaxy_fit_plotter_path, format="png")),
    )

    assert galaxy_fit_plotter_path + "subplot_fit_galaxy.png" in plot_patch.paths

    aplt.fit_galaxy.subplot_fit_galaxy(
        fit=gal_fit_7x7_deflections_x,
        positions=positions_7x7,
        include=include_all,
        sub_plotter=aplt.SubPlotter(
            output=aplt.Output(path=galaxy_fit_plotter_path, format="png")),
    )

    assert galaxy_fit_plotter_path + "subplot_fit_galaxy.png" in plot_patch.paths
Esempio n. 2
0
    def test__plot_rectangular_mapper__works_with_all_extras_included(
        self, rectangular_mapper_7x7_3x3, plot_path, plot_patch
    ):

        plotter = aplt.Plotter(
            output=aplt.Output(path=plot_path, filename="mapper1", format="png")
        )

        plotter.plot_rectangular_mapper(
            mapper=rectangular_mapper_7x7_3x3,
            include_pixelization_grid=True,
            include_grid=True,
            include_border=True,
            light_profile_centres=[(1.0, 1.0)],
            mass_profile_centres=[(1.0, 1.0)],
            multiple_images=[(1.0, 1.0)],
            critical_curves=[(1.0, 1.0), (2.0, 2.0)],
            caustics=[(1.0, 1.0), (2.0, 2.0)],
            image_pixel_indexes=[[(0, 0), (0, 1)], [(1, 2)]],
            source_pixel_indexes=[[0, 1], [2]],
        )

        assert plot_path + "mapper1.png" in plot_patch.paths

        plotter = aplt.Plotter(
            output=aplt.Output(path=plot_path, filename="mapper2", format="png")
        )

        plotter.plot_rectangular_mapper(
            mapper=rectangular_mapper_7x7_3x3,
            include_pixelization_grid=True,
            include_grid=True,
            include_border=True,
            light_profile_centres=[(1.0, 1.0)],
            mass_profile_centres=[(1.0, 1.0)],
            multiple_images=[(1.0, 1.0)],
            critical_curves=[(1.0, 1.0), (2.0, 2.0)],
            caustics=[(1.0, 1.0), (2.0, 2.0)],
            image_pixel_indexes=[[(0, 0), (0, 1)], [(1, 2)]],
            source_pixel_indexes=[[0, 1], [2]],
        )

        assert plot_path + "mapper2.png" in plot_patch.paths

        aplt.mapper_obj(
            mapper=rectangular_mapper_7x7_3x3,
            light_profile_centres=[(1.0, 1.0)],
            mass_profile_centres=[(1.0, 1.0)],
            multiple_images=[(1.0, 1.0)],
            critical_curves=[(1.0, 1.0), (2.0, 2.0)],
            caustics=[(1.0, 1.0), (2.0, 2.0)],
            image_pixel_indexes=[[(0, 0), (0, 1)], [(1, 2)]],
            source_pixel_indexes=[[0, 1], [2]],
            plotter=aplt.Plotter(
                output=aplt.Output(path=plot_path, filename="mapper3", format="png")
            ),
        )

        assert plot_path + "mapper3.png" in plot_patch.paths
Esempio n. 3
0
    def test__plot_grid__works_with_all_extras_included(self, plot_path, plot_patch):
        grid = aa.grid.uniform(shape_2d=(11, 11), pixel_scales=1.0)
        color_array = np.linspace(start=0.0, stop=1.0, num=grid.shape_1d)

        plotter = aplt.Plotter(
            output=aplt.Output(path=plot_path, filename="grid1", format="png")
        )

        plotter.plot_grid(
            grid=grid,
            color_array=color_array,
            axis_limits=[-1.5, 1.5, -2.5, 2.5],
            light_profile_centres=[(1.0, 1.0)],
            mass_profile_centres=[(1.0, 1.0)],
            multiple_images=[(1.0, 1.0)],
            critical_curves=[(1.0, 1.0), (2.0, 2.0)],
            caustics=[(1.0, 1.0), (2.0, 2.0)],
            indexes=[0, 1, 2, 14],
            symmetric_around_centre=False,
        )

        assert plot_path + "grid1.png" in plot_patch.paths

        plotter = aplt.Plotter(
            output=aplt.Output(path=plot_path, filename="grid2", format="png")
        )

        plotter.plot_grid(
            grid=grid,
            color_array=color_array,
            axis_limits=[-1.5, 1.5, -2.5, 2.5],
            light_profile_centres=[(1.0, 1.0)],
            mass_profile_centres=[(1.0, 1.0)],
            multiple_images=[(1.0, 1.0)],
            critical_curves=[(1.0, 1.0), (2.0, 2.0)],
            caustics=[(1.0, 1.0), (2.0, 2.0)],
            indexes=[0, 1, 2, 14],
            symmetric_around_centre=True,
        )

        assert plot_path + "grid2.png" in plot_patch.paths

        aplt.grid(
            grid=grid,
            color_array=color_array,
            axis_limits=[-1.5, 1.5, -2.5, 2.5],
            light_profile_centres=[(1.0, 1.0)],
            mass_profile_centres=[(1.0, 1.0)],
            multiple_images=[(1.0, 1.0)],
            critical_curves=[(1.0, 1.0), (2.0, 2.0)],
            caustics=[(1.0, 1.0), (2.0, 2.0)],
            indexes=[0, 1, 2, 14],
            symmetric_around_centre=True,
            plotter=aplt.Plotter(
                output=aplt.Output(path=plot_path, filename="grid3", format="png")
            ),
        )

        assert plot_path + "grid3.png" in plot_patch.paths
Esempio n. 4
0
def test__all_quantities_are_output(mp_0, sub_grid_7x7, positions_7x7,
                                    include_all, mp_plotter_path, plot_patch):

    aast.plot.mp.convergence(
        mass_profile=mp_0,
        grid=sub_grid_7x7,
        positions=positions_7x7,
        include=include_all,
        plotter=aplt.Plotter(
            output=aplt.Output(mp_plotter_path, format="png")),
    )

    assert mp_plotter_path + "convergence.png" in plot_patch.paths

    aast.plot.mp.potential(
        mass_profile=mp_0,
        grid=sub_grid_7x7,
        positions=positions_7x7,
        include=include_all,
        plotter=aplt.Plotter(
            output=aplt.Output(mp_plotter_path, format="png")),
    )

    assert mp_plotter_path + "potential.png" in plot_patch.paths

    aast.plot.mp.deflections_y(
        mass_profile=mp_0,
        grid=sub_grid_7x7,
        positions=positions_7x7,
        include=include_all,
        plotter=aplt.Plotter(
            output=aplt.Output(mp_plotter_path, format="png")),
    )

    assert mp_plotter_path + "deflections_y.png" in plot_patch.paths

    aast.plot.mp.deflections_x(
        mass_profile=mp_0,
        grid=sub_grid_7x7,
        positions=positions_7x7,
        include=include_all,
        plotter=aplt.Plotter(
            output=aplt.Output(mp_plotter_path, format="png")),
    )

    assert mp_plotter_path + "deflections_x.png" in plot_patch.paths

    aast.plot.mp.magnification(
        mass_profile=mp_0,
        grid=sub_grid_7x7,
        positions=positions_7x7,
        include=include_all,
        plotter=aplt.Plotter(
            output=aplt.Output(mp_plotter_path, format="png")),
    )

    assert mp_plotter_path + "magnification.png" in plot_patch.paths
Esempio n. 5
0
    def test__plot_array__fits_files_output_correctly(self, plot_path):

        plot_path = plot_path + "/fits/"

        if os.path.exists(plot_path):
            shutil.rmtree(plot_path)

        arr = aa.array.ones(shape_2d=(31, 31), pixel_scales=(1.0, 1.0), sub_size=2)

        plotter = aplt.Plotter(
            output=aplt.Output(path=plot_path, filename="array", format="fits")
        )

        plotter.plot_array(array=arr)

        arr = aa.util.array.numpy_array_2d_from_fits(
            file_path=plot_path + "/array.fits", hdu=0
        )

        assert (arr == np.ones(shape=(31, 31))).all()

        mask = aa.mask.circular(
            shape_2d=(31, 31), pixel_scales=(1.0, 1.0), radius=5.0, centre=(2.0, 2.0)
        )

        masked_array = aa.masked.array.manual_2d(array=arr, mask=mask)

        plotter.plot_array(array=masked_array)

        arr = aa.util.array.numpy_array_2d_from_fits(
            file_path=plot_path + "/array.fits", hdu=0
        )

        assert arr.shape == (13, 13)
Esempio n. 6
0
    def test__plot_line__works_with_all_extras_included(self, plot_path, plot_patch):

        plotter = aplt.Plotter(
            output=aplt.Output(path=plot_path, filename="line1", format="png")
        )

        plotter.plot_line(
            y=np.array([1.0, 2.0, 3.0]),
            x=np.array([0.5, 1.0, 1.5]),
            plot_axis_type="loglog",
            vertical_lines=[1.0, 2.0],
            label="line0",
            vertical_line_labels=["line1", "line2"],
        )

        assert plot_path + "line1.png" in plot_patch.paths

        plotter = aplt.Plotter(
            output=aplt.Output(path=plot_path, filename="line2", format="png")
        )

        plotter.plot_line(
            y=np.array([1.0, 2.0, 3.0]),
            x=np.array([0.5, 1.0, 1.5]),
            plot_axis_type="semilogy",
            vertical_lines=[1.0, 2.0],
            label="line0",
            vertical_line_labels=["line1", "line2"],
        )

        assert plot_path + "line2.png" in plot_patch.paths

        aplt.line(
            y=np.array([1.0, 2.0, 3.0]),
            x=np.array([0.5, 1.0, 1.5]),
            plot_axis_type="loglog",
            vertical_lines=[1.0, 2.0],
            label="line0",
            vertical_line_labels=["line1", "line2"],
            plotter=aplt.Plotter(
                output=aplt.Output(path=plot_path, filename="line3", format="png")
            ),
        )

        assert plot_path + "line3.png" in plot_patch.paths
Esempio n. 7
0
    def test__plot_voronoi_mapper__works_with_all_extras_included(
        self, voronoi_mapper_9_3x3, plot_path, plot_patch
    ):

        plotter = aplt.Plotter(
            output=aplt.Output(path=plot_path, filename="mapper1", format="png")
        )

        plotter.plot_voronoi_mapper(
            mapper=voronoi_mapper_9_3x3,
            include_pixelization_grid=True,
            include_grid=True,
            include_border=True,
            image_pixel_indexes=[[(0, 0), (0, 1)], [(1, 2)]],
            source_pixel_indexes=[[0, 1], [2]],
        )

        assert plot_path + "mapper1.png" in plot_patch.paths

        plotter = aplt.Plotter(
            output=aplt.Output(path=plot_path, filename="mapper2", format="png")
        )

        plotter.plot_voronoi_mapper(
            mapper=voronoi_mapper_9_3x3,
            include_pixelization_grid=True,
            include_grid=True,
            include_border=True,
            image_pixel_indexes=[[(0, 0), (0, 1)], [(1, 2)]],
            source_pixel_indexes=[[0, 1], [2]],
        )

        assert plot_path + "mapper2.png" in plot_patch.paths

        aplt.mapper_obj(
            mapper=voronoi_mapper_9_3x3,
            image_pixel_indexes=[[(0, 0), (0, 1)], [(1, 2)]],
            source_pixel_indexes=[[0, 1], [2]],
            plotter=aplt.Plotter(
                output=aplt.Output(path=plot_path, filename="mapper3", format="png")
            ),
        )

        assert plot_path + "mapper3.png" in plot_patch.paths
def test__all_quantities_are_output(
    lp_0, sub_grid_7x7, positions_7x7, include_all, profile_plotter_path, plot_patch
):

    aast.plot.lp.profile_image(
        light_profile=lp_0,
        grid=sub_grid_7x7,
        positions=positions_7x7,
        include=include_all,
        plotter=aplt.Plotter(output=aplt.Output(profile_plotter_path, format="png")),
    )

    assert profile_plotter_path + "profile_image.png" in plot_patch.paths
def test__individual_images_are_output(
    gal_x1_lp_x1_mp,
    sub_grid_7x7,
    mask_7x7,
    positions_7x7,
    include_all,
    galaxy_plotter_path,
    plot_patch,
):

    aplt.galaxy.profile_image(
        galaxy=gal_x1_lp_x1_mp,
        grid=sub_grid_7x7,
        positions=positions_7x7,
        include=include_all,
        plotter=aplt.Plotter(output=aplt.Output(galaxy_plotter_path, format="png")),
    )

    assert galaxy_plotter_path + "profile_image.png" in plot_patch.paths

    aplt.galaxy.convergence(
        galaxy=gal_x1_lp_x1_mp,
        grid=sub_grid_7x7,
        positions=positions_7x7,
        include=include_all,
        plotter=aplt.Plotter(output=aplt.Output(galaxy_plotter_path, format="png")),
    )

    assert galaxy_plotter_path + "convergence.png" in plot_patch.paths

    aplt.galaxy.potential(
        galaxy=gal_x1_lp_x1_mp,
        grid=sub_grid_7x7,
        positions=positions_7x7,
        include=include_all,
        plotter=aplt.Plotter(output=aplt.Output(galaxy_plotter_path, format="png")),
    )

    assert galaxy_plotter_path + "potential.png" in plot_patch.paths

    aplt.galaxy.deflections_y(
        galaxy=gal_x1_lp_x1_mp,
        grid=sub_grid_7x7,
        positions=positions_7x7,
        include=include_all,
        plotter=aplt.Plotter(output=aplt.Output(galaxy_plotter_path, format="png")),
    )

    assert galaxy_plotter_path + "deflections_y.png" in plot_patch.paths

    aplt.galaxy.deflections_x(
        galaxy=gal_x1_lp_x1_mp,
        grid=sub_grid_7x7,
        positions=positions_7x7,
        include=include_all,
        plotter=aplt.Plotter(output=aplt.Output(galaxy_plotter_path, format="png")),
    )

    assert galaxy_plotter_path + "deflections_x.png" in plot_patch.paths

    aplt.galaxy.magnification(
        galaxy=gal_x1_lp_x1_mp,
        grid=sub_grid_7x7,
        positions=positions_7x7,
        include=include_all,
        plotter=aplt.Plotter(output=aplt.Output(galaxy_plotter_path, format="png")),
    )

    assert galaxy_plotter_path + "magnification.png" in plot_patch.paths

    gal_x1_lp_x1_mp.hyper_galaxy = aast.HyperGalaxy()
    gal_x1_lp_x1_mp.hyper_model_image = aa.array.ones(shape_2d=(7, 7), pixel_scales=0.1)
    gal_x1_lp_x1_mp.hyper_galaxy_image = aa.array.ones(
        shape_2d=(7, 7), pixel_scales=0.1
    )

    aplt.galaxy.contribution_map(
        galaxy=gal_x1_lp_x1_mp,
        mask=mask_7x7,
        positions=positions_7x7,
        include=include_all,
        plotter=aplt.Plotter(output=aplt.Output(galaxy_plotter_path, format="png")),
    )

    assert galaxy_plotter_path + "contribution_map.png" in plot_patch.paths
def test__individual_galaxy_quantities__all_are_output(
    gal_x1_lp_x1_mp,
    sub_grid_7x7,
    positions_7x7,
    include_all,
    galaxy_plotter_path,
    plot_patch,
):
    aplt.galaxy.profile_image_subplot(
        galaxy=gal_x1_lp_x1_mp,
        grid=sub_grid_7x7,
        positions=positions_7x7,
        include=include_all,
        sub_plotter=aplt.SubPlotter(
            output=aplt.Output(galaxy_plotter_path, format="png")
        ),
    )

    assert galaxy_plotter_path + "profile_image_subplot.png" in plot_patch.paths

    aplt.galaxy.convergence_subplot(
        galaxy=gal_x1_lp_x1_mp,
        grid=sub_grid_7x7,
        positions=positions_7x7,
        include=include_all,
        sub_plotter=aplt.SubPlotter(
            output=aplt.Output(galaxy_plotter_path, format="png")
        ),
    )

    assert galaxy_plotter_path + "convergence_subplot.png" in plot_patch.paths

    aplt.galaxy.potential_subplot(
        galaxy=gal_x1_lp_x1_mp,
        grid=sub_grid_7x7,
        positions=positions_7x7,
        include=include_all,
        sub_plotter=aplt.SubPlotter(
            output=aplt.Output(galaxy_plotter_path, format="png")
        ),
    )

    assert galaxy_plotter_path + "potential_subplot.png" in plot_patch.paths

    aplt.galaxy.deflections_y_subplot(
        galaxy=gal_x1_lp_x1_mp,
        grid=sub_grid_7x7,
        positions=positions_7x7,
        include=include_all,
        sub_plotter=aplt.SubPlotter(
            output=aplt.Output(galaxy_plotter_path, format="png")
        ),
    )

    assert galaxy_plotter_path + "deflections_y_subplot.png" in plot_patch.paths

    aplt.galaxy.deflections_x_subplot(
        galaxy=gal_x1_lp_x1_mp,
        grid=sub_grid_7x7,
        positions=positions_7x7,
        include=include_all,
        sub_plotter=aplt.SubPlotter(
            output=aplt.Output(galaxy_plotter_path, format="png")
        ),
    )

    assert galaxy_plotter_path + "deflections_x_subplot.png" in plot_patch.paths
Esempio n. 11
0
    def test__plot_array__works_with_all_extras_included(self, plot_path, plot_patch):

        array = aa.array.ones(shape_2d=(31, 31), pixel_scales=(1.0, 1.0), sub_size=2)

        mask = aa.mask.circular(
            shape_2d=array.shape_2d,
            pixel_scales=array.pixel_scales,
            radius=5.0,
            centre=(2.0, 2.0),
        )

        grid = aa.grid.uniform(shape_2d=(11, 11), pixel_scales=0.5)

        plotter = aplt.Plotter(
            output=aplt.Output(path=plot_path, filename="array1", format="png")
        )

        plotter.plot_array(
            array=array,
            mask=mask,
            grid=grid,
            positions=[(-1.0, -1.0)],
            light_profile_centres=[(1.0, 1.0)],
            mass_profile_centres=[(1.0, 1.0)],
            multiple_images=[(1.0, 1.0)],
            critical_curves=[(1.0, 1.0), (2.0, 2.0)],
            caustics=[(1.0, 1.0), (2.0, 2.0)],
            include_origin=True,
            include_border=True,
        )

        assert plot_path + "array1.png" in plot_patch.paths

        plotter = aplt.Plotter(
            output=aplt.Output(path=plot_path, filename="array2", format="png")
        )

        plotter.plot_array(
            array=array,
            mask=mask,
            grid=grid,
            positions=[[(1.0, 1.0), (2.0, 2.0)], [(-1.0, -1.0)]],
            critical_curves=[[(1.0, 1.0), (2.0, 2.0)], [(2.0, 4.0), (5.0, 6.0)]],
            include_origin=True,
            include_border=True,
        )

        assert plot_path + "array2.png" in plot_patch.paths

        aplt.array(
            array=array,
            mask=mask,
            grid=grid,
            positions=[(-1.0, -1.0)],
            light_profile_centres=[(1.0, 1.0)],
            mass_profile_centres=[(1.0, 1.0)],
            multiple_images=[(1.0, 1.0)],
            critical_curves=[(1.0, 1.0), (2.0, 2.0)],
            caustics=[(1.0, 1.0), (2.0, 2.0)],
            plotter=aplt.Plotter(
                output=aplt.Output(path=plot_path, filename="array3", format="png")
            ),
        )

        assert plot_path + "array3.png" in plot_patch.paths