Exemplo n.º 1
0
    def test__gaussian_centres_scatterer__from_config_or_via_manual_input(
            self):

        plotter = aplt.Plotter()

        assert plotter.gaussian_centres_scatterer.size == 10
        assert plotter.gaussian_centres_scatterer.marker == "+"
        assert plotter.gaussian_centres_scatterer.colors == ["k", "r"]

        plotter = aplt.Plotter(
            gaussian_centres_scatterer=aplt.GaussianCentreScatterer(
                size=1, marker=".", colors="k"))

        assert plotter.gaussian_centres_scatterer.size == 1
        assert plotter.gaussian_centres_scatterer.marker == "."
        assert plotter.gaussian_centres_scatterer.colors == ["k"]

        sub_plotter = aplt.SubPlotter()

        assert sub_plotter.gaussian_centres_scatterer.size == 10
        assert sub_plotter.gaussian_centres_scatterer.marker == "+"
        assert sub_plotter.gaussian_centres_scatterer.colors == ["k", "r"]

        sub_plotter = aplt.SubPlotter(
            gaussian_centres_scatterer=aplt.GaussianCentreScatterer.sub(
                marker="o", colors="r"))

        assert sub_plotter.gaussian_centres_scatterer.size == 10
        assert sub_plotter.gaussian_centres_scatterer.marker == "o"
        assert sub_plotter.gaussian_centres_scatterer.colors == ["r"]
Exemplo n.º 2
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)],
            gaussian_centres=[(1.0, 1.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)]],
            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)],
            gaussian_centres=[(1.0, 1.0)],
            plotter=aplt.Plotter(output=aplt.Output(
                path=plot_path, filename="array3", format="png")),
        )

        assert plot_path + "array3.png" in plot_patch.paths
Exemplo 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],
            gaussian_centres=[(1.0, 1.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],
            gaussian_centres=[(1.0, 1.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],
            gaussian_centres=[(1.0, 1.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
Exemplo n.º 4
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,
            gaussian_centres=[(1.0, 1.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,
            gaussian_centres=[(1.0, 1.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,
            gaussian_centres=[(1.0, 1.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
Exemplo n.º 5
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
Exemplo n.º 6
0
def test__all_quantities_are_output(
    gaussian_0,
    sub_grid_7x7,
    positions_7x7,
    include_all,
    profile_plotter_path,
    plot_patch,
):

    toy.plot.profile_image(
        gaussian=gaussian_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
Exemplo n.º 7
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)