Esempio n. 1
0
    def test__visuals_for_source_from_voronoi_mapper(self,
                                                     voronoi_mapper_9_3x3):

        include = aplt.Include2D(
            origin=True,
            border=True,
            mapper_source_grid_slim=True,
            mapper_source_pixelization_grid=True,
        )

        mapper_plotter = aplt.MapperPlotter(mapper=voronoi_mapper_9_3x3,
                                            include_2d=include)

        assert mapper_plotter.visuals_2d.origin == None
        assert mapper_plotter.visuals_source_with_include_2d.origin.in_list == [
            (0.0, 0.0)
        ]
        assert (mapper_plotter.visuals_source_with_include_2d.grid ==
                voronoi_mapper_9_3x3.source_grid_slim).all()
        assert (mapper_plotter.visuals_source_with_include_2d.pixelization_grid
                == voronoi_mapper_9_3x3.source_pixelization_grid).all()
        assert (mapper_plotter.visuals_source_with_include_2d.border ==
                voronoi_mapper_9_3x3.source_grid_slim.sub_border_grid).all()

        include = aplt.Include2D(origin=False,
                                 border=False,
                                 mapper_source_pixelization_grid=False)

        mapper_plotter = aplt.MapperPlotter(mapper=voronoi_mapper_9_3x3,
                                            include_2d=include)

        assert mapper_plotter.visuals_source_with_include_2d.origin == None
        assert mapper_plotter.visuals_source_with_include_2d.grid == None
        assert mapper_plotter.visuals_source_with_include_2d.border == None
    def test__attribute_for_visuals(self):

        visuals_2d = aplt.Visuals2D()
        include_2d = aplt.Include2D(origin=False)

        abstract_plotter = abstract_plotters.AbstractPlotter(
            visuals_2d=visuals_2d, include_2d=include_2d)
        attr = abstract_plotter.extract_2d(name="origin", value=1)

        assert attr == None

        include_2d = aplt.Include2D(origin=True)
        abstract_plotter = abstract_plotters.AbstractPlotter(
            visuals_2d=visuals_2d, include_2d=include_2d)
        attr = abstract_plotter.extract_2d(name="origin", value=1)

        assert attr == 1

        visuals_2d = aplt.Visuals2D(origin=10)

        include_2d = aplt.Include2D(origin=False)
        abstract_plotter = abstract_plotters.AbstractPlotter(
            visuals_2d=visuals_2d, include_2d=include_2d)
        attr = abstract_plotter.extract_2d(name="origin", value=2)

        assert attr == 10

        include_2d = aplt.Include2D(origin=True)
        abstract_plotter = abstract_plotters.AbstractPlotter(
            visuals_2d=visuals_2d, include_2d=include_2d)
        attr = abstract_plotter.extract_2d(name="origin", value=2)

        assert attr == 10
Esempio n. 3
0
def test__visuals_in_constructor_use_imaging_and_include(fit_imaging_7x7):

    visuals_2d = aplt.Visuals2D(origin=(1.0, 1.0), vector_field=2)

    include = aplt.Include2D(origin=True, mask=True, border=True)

    fit_imaging_plotter = aplt.FitImagingPlotter(fit=fit_imaging_7x7,
                                                 visuals_2d=visuals_2d,
                                                 include_2d=include)

    assert fit_imaging_plotter.visuals_2d.origin == (1.0, 1.0)
    assert fit_imaging_plotter.visuals_with_include_2d.origin == (1.0, 1.0)

    assert (fit_imaging_plotter.visuals_with_include_2d.mask ==
            fit_imaging_7x7.image.mask).all()
    assert (fit_imaging_plotter.visuals_with_include_2d.border ==
            fit_imaging_7x7.image.mask.border_grid_sub_1.binned).all()
    assert fit_imaging_plotter.visuals_with_include_2d.vector_field == 2

    include = aplt.Include2D(origin=False, mask=False, border=False)

    fit_imaging_plotter = aplt.FitImagingPlotter(fit=fit_imaging_7x7,
                                                 visuals_2d=visuals_2d,
                                                 include_2d=include)

    assert fit_imaging_plotter.visuals_with_include_2d.origin == (1.0, 1.0)
    assert fit_imaging_plotter.visuals_with_include_2d.mask == None
    assert fit_imaging_plotter.visuals_with_include_2d.border == None
    assert fit_imaging_plotter.visuals_with_include_2d.vector_field == 2
Esempio n. 4
0
    def test___visuals_in_constructor_use_array_and_include(
            self, array_2d_7x7):

        visuals_2d = aplt.Visuals2D(origin=(1.0, 1.0), vector_field=2)

        include = aplt.Include2D(origin=True, mask=True, border=True)

        array_plotter = aplt.Array2DPlotter(array=array_2d_7x7,
                                            visuals_2d=visuals_2d,
                                            include_2d=include)

        assert array_plotter.visuals_2d.origin == (1.0, 1.0)
        assert array_plotter.visuals_with_include_2d.origin == (1.0, 1.0)

        assert array_plotter.visuals_2d.mask == None
        assert (array_plotter.visuals_with_include_2d.mask == array_2d_7x7.mask
                ).all()

        assert array_plotter.visuals_2d.border == None
        assert (array_plotter.visuals_with_include_2d.border ==
                array_2d_7x7.mask.border_grid_sub_1.binned).all()

        assert array_plotter.visuals_2d.vector_field == 2
        assert array_plotter.visuals_with_include_2d.vector_field == 2

        include = aplt.Include2D(origin=False, mask=False, border=False)

        array_plotter = aplt.Array2DPlotter(array=array_2d_7x7,
                                            visuals_2d=visuals_2d,
                                            include_2d=include)

        assert array_plotter.visuals_with_include_2d.origin == (1.0, 1.0)
        assert array_plotter.visuals_with_include_2d.mask == None
        assert array_plotter.visuals_with_include_2d.border == None
        assert array_plotter.visuals_with_include_2d.vector_field == 2
Esempio n. 5
0
    def test__visuals_for_data_from_voronoi_mapper(self, voronoi_mapper_9_3x3):

        include = aplt.Include2D(origin=True,
                                 mask=True,
                                 mapper_data_pixelization_grid=True,
                                 border=True)

        mapper_plotter = aplt.MapperPlotter(mapper=voronoi_mapper_9_3x3,
                                            include_2d=include)

        assert mapper_plotter.visuals_data_with_include_2d.origin.in_list == [
            (0.0, 0.0)
        ]
        assert (mapper_plotter.visuals_data_with_include_2d.mask ==
                voronoi_mapper_9_3x3.source_grid_slim.mask).all()
        assert (mapper_plotter.visuals_data_with_include_2d.pixelization_grid
                == aa.Grid2D.uniform(shape_native=(2, 2),
                                     pixel_scales=0.1)).all()
        #      assert visuals.border.shape == (0, 2)

        include = aplt.Include2D(origin=False,
                                 mask=False,
                                 mapper_data_pixelization_grid=False,
                                 border=False)

        mapper_plotter = aplt.MapperPlotter(mapper=voronoi_mapper_9_3x3,
                                            include_2d=include)

        assert mapper_plotter.visuals_data_with_include_2d.origin == None
        assert mapper_plotter.visuals_data_with_include_2d.mask == None
        assert mapper_plotter.visuals_data_with_include_2d.grid == None
        assert mapper_plotter.visuals_data_with_include_2d.pixelization_grid == None
        assert mapper_plotter.visuals_data_with_include_2d.border == None
Esempio n. 6
0
    def test__visuals_for_data_from_rectangular_mapper(
            self, rectangular_mapper_7x7_3x3):
        include = aplt.Include2D(origin=True,
                                 mask=True,
                                 mapper_data_pixelization_grid=True,
                                 border=True)

        mapper_plotter = aplt.MapperPlotter(mapper=rectangular_mapper_7x7_3x3,
                                            include_2d=include)

        assert mapper_plotter.visuals_data_with_include_2d.origin.in_list == [
            (0.0, 0.0)
        ]
        assert (mapper_plotter.visuals_data_with_include_2d.mask ==
                rectangular_mapper_7x7_3x3.source_grid_slim.mask).all()
        assert mapper_plotter.visuals_data_with_include_2d.grid == None
        #  assert visuals.border == (0, 2)

        include = aplt.Include2D(origin=False,
                                 mask=False,
                                 mapper_data_pixelization_grid=False,
                                 border=False)

        mapper_plotter = aplt.MapperPlotter(mapper=rectangular_mapper_7x7_3x3,
                                            include_2d=include)

        assert mapper_plotter.visuals_data_with_include_2d.origin == None
        assert mapper_plotter.visuals_data_with_include_2d.mask == None
        assert mapper_plotter.visuals_data_with_include_2d.grid == None
        assert mapper_plotter.visuals_data_with_include_2d.border == None
Esempio n. 7
0
    def test__image_and_mapper_subplot_is_output_for_all_mappers(
        self,
        imaging_7x7,
        rectangular_mapper_7x7_3x3,
        voronoi_mapper_9_3x3,
        plot_path,
        plot_patch,
    ):

        mapper_plotter = aplt.MapperPlotter(
            mapper=rectangular_mapper_7x7_3x3,
            visuals_2d=aplt.Visuals2D(indexes=[[(0, 0), (0, 1)], [(1, 2)]],
                                      pixelization_indexes=[[0, 1], [2]]),
            mat_plot_2d=aplt.MatPlot2D(
                output=aplt.Output(path=plot_path, format="png")),
            include_2d=aplt.Include2D(mapper_source_pixelization_grid=True),
        )

        mapper_plotter.subplot_image_and_mapper(image=imaging_7x7.image)

        assert path.join(plot_path,
                         "subplot_image_and_mapper.png") in plot_patch.paths

        mapper_plotter.subplot_image_and_mapper(image=imaging_7x7.image)

        assert path.join(plot_path,
                         "subplot_image_and_mapper.png") in plot_patch.paths
Esempio n. 8
0
    def __init__(
        self,
        fit: FitImagingCI,
        mat_plot_2d: aplt.MatPlot2D = aplt.MatPlot2D(),
        visuals_2d: aplt.Visuals2D = aplt.Visuals2D(),
        include_2d: aplt.Include2D = aplt.Include2D(),
        mat_plot_1d: aplt.MatPlot1D = aplt.MatPlot1D(),
        visuals_1d: aplt.Visuals1D = aplt.Visuals1D(),
        include_1d: aplt.Include1D = aplt.Include1D(),
    ):
        """
        Plots the attributes of `FitImagingCI` objects using the matplotlib methods `imshow()`, `plot()` and many other 
        matplotlib functions which customize the plot's appearance.

        The `mat_plot_1d` and `mat_plot_2d` attribute wraps matplotlib function calls to make the figure. By default, 
        the settings passed to every matplotlib function called are those specified in 
        the `config/visualize/mat_wrap/*.ini` files, but a user can manually input values into `MatPlot1D` and 
        `MatPlot2D` to customize the figure's appearance.

        Overlaid on the figure are visuals, contained in the `Visuals1D` and `Visuals2D` object. Attributes may be 
        extracted from the `FitImagingCI` and plotted via the visuals object, if the corresponding entry 
        is `True` in the `Include1D` and `Include2D` object or the `config/visualize/include.ini` file.

        Parameters
        ----------
        fit
            The fit to an imaging dataset the plotter plots.
        get_visuals_2d
            A function which extracts from the `FitImaging` the 2D visuals which are plotted on figures.
        mat_plot_2d
            Contains objects which wrap the matplotlib function calls that make the plot.
        visuals_2d
            Contains visuals that can be overlaid on the plot.
        include_2d
            Specifies which attributes of the `Array2D` are extracted and plotted as visuals.
        mat_plot_1d
            Contains objects which wrap the matplotlib function calls that make 1D plots.
        visuals_1d
            Contains 1D visuals that can be overlaid on 1D plots.
        include_1d
            Specifies which attributes of the `ImagingCI` are extracted and plotted as visuals for 1D plots.            
        """
        super().__init__(
            mat_plot_2d=mat_plot_2d, include_2d=include_2d, visuals_2d=visuals_2d
        )

        self.visuals_1d = visuals_1d
        self.include_1d = include_1d
        self.mat_plot_1d = mat_plot_1d

        self.fit = fit

        self._fit_imaging_meta_plotter = FitImagingPlotterMeta(
            fit=self.fit,
            get_visuals_2d=self.get_visuals_2d,
            mat_plot_2d=self.mat_plot_2d,
            include_2d=self.include_2d,
            visuals_2d=self.visuals_2d,
        )
Esempio n. 9
0
    def test__works_with_all_extras_included(
        self,
        array_2d_7x7,
        grid_2d_7x7,
        mask_2d_7x7,
        grid_2d_irregular_7x7_list,
        plot_path,
        plot_patch,
    ):

        grid_plotter = aplt.Grid2DPlotter(
            grid=grid_2d_7x7,
            visuals_2d=aplt.Visuals2D(indexes=[0, 1, 2]),
            mat_plot_2d=aplt.MatPlot2D(output=aplt.Output(
                path=plot_path, filename="grid1", format="png")),
        )

        color_array = np.linspace(start=0.0,
                                  stop=1.0,
                                  num=grid_2d_7x7.shape_slim)

        grid_plotter.figure_2d(color_array=color_array)

        assert path.join(plot_path, "grid1.png") in plot_patch.paths

        grid_plotter = aplt.Grid2DPlotter(
            grid=grid_2d_7x7,
            visuals_2d=aplt.Visuals2D(indexes=[0, 1, 2]),
            mat_plot_2d=aplt.MatPlot2D(output=aplt.Output(
                path=plot_path, filename="grid2", format="png")),
            include_2d=aplt.Include2D(origin=True, mask=True, border=True),
        )

        grid_plotter.figure_2d(color_array=color_array)

        assert path.join(plot_path, "grid2.png") in plot_patch.paths

        visuals_2d = aplt.Visuals2D(
            origin=grid_2d_irregular_7x7_list,
            mask=mask_2d_7x7,
            border=mask_2d_7x7.border_grid_sub_1.binned,
            grid=grid_2d_7x7,
            positions=grid_2d_irregular_7x7_list,
            lines=grid_2d_irregular_7x7_list,
            array_overlay=array_2d_7x7,
            indexes=[0, 1, 2],
        )

        grid_plotter = aplt.Grid2DPlotter(
            grid=grid_2d_7x7,
            mat_plot_2d=aplt.MatPlot2D(output=aplt.Output(
                path=plot_path, filename="grid3", format="png")),
            visuals_2d=visuals_2d,
        )

        grid_plotter.figure_2d(color_array=color_array)

        assert path.join(plot_path, "grid3.png") in plot_patch.paths
Esempio n. 10
0
    def test__loads_default_values_from_config_if_not_input(self):

        include = aplt.Include2D()

        assert include.origin is True
        assert include.mask == True
        assert include.border is True
        assert include.parallel_overscan is True
        assert include.serial_prescan is True
        assert include.serial_overscan is False

        include = aplt.Include2D(origin=False,
                                 border=False,
                                 serial_overscan=True)

        assert include.origin is False
        assert include.mask == True
        assert include.border is False
        assert include.parallel_overscan is True
        assert include.serial_prescan is True
        assert include.serial_overscan is True
Esempio n. 11
0
def test__fit_sub_plot(fit_imaging_7x7, plot_path, plot_patch):

    fit_imaging_plotter = aplt.FitImagingPlotter(
        fit=fit_imaging_7x7,
        include_2d=aplt.Include2D(origin=True, mask=True, border=True),
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(path=plot_path, format="png")),
    )

    fit_imaging_plotter.subplot_fit_imaging()

    assert path.join(plot_path, "subplot_fit_imaging.png") in plot_patch.paths
Esempio n. 12
0
    def test___visuals_in_constructor_use_grid_and_include(self, grid_2d_7x7):

        visuals_2d = aplt.Visuals2D(origin=(1.0, 1.0), vector_field=2)

        include = aplt.Include2D(origin=True)

        grid_plotter = aplt.Grid2DPlotter(grid=grid_2d_7x7,
                                          visuals_2d=visuals_2d,
                                          include_2d=include)

        assert grid_plotter.visuals_2d.origin == (1.0, 1.0)
        assert grid_plotter.visuals_with_include_2d.origin == (1.0, 1.0)

        include = aplt.Include2D(origin=False)

        grid_plotter = aplt.Grid2DPlotter(grid=grid_2d_7x7,
                                          visuals_2d=visuals_2d,
                                          include_2d=include)

        assert grid_plotter.visuals_with_include_2d.origin == (1.0, 1.0)
        assert grid_plotter.visuals_with_include_2d.vector_field == 2
Esempio n. 13
0
    def test__works_with_all_extras_included(
        self,
        array_2d_7x7,
        mask_2d_7x7,
        grid_2d_7x7,
        grid_2d_irregular_7x7_list,
        plot_path,
        plot_patch,
    ):

        array_plotter = aplt.Array2DPlotter(
            array=array_2d_7x7,
            mat_plot_2d=aplt.MatPlot2D(output=aplt.Output(
                path=plot_path, filename="array1", format="png")),
        )

        array_plotter.figure_2d()

        assert path.join(plot_path, "array1.png") in plot_patch.paths

        array_plotter = aplt.Array2DPlotter(
            array=array_2d_7x7,
            include_2d=aplt.Include2D(origin=True, mask=True, border=True),
            mat_plot_2d=aplt.MatPlot2D(output=aplt.Output(
                path=plot_path, filename="array2", format="png")),
        )

        array_plotter.figure_2d()

        assert path.join(plot_path, "array2.png") in plot_patch.paths

        visuals_2d = aplt.Visuals2D(
            origin=grid_2d_irregular_7x7_list,
            mask=mask_2d_7x7,
            border=mask_2d_7x7.border_grid_sub_1.binned,
            grid=grid_2d_7x7,
            positions=grid_2d_irregular_7x7_list,
            #       lines=grid_2d_irregular_7x7_list,
            array_overlay=array_2d_7x7,
        )

        array_plotter = aplt.Array2DPlotter(
            array=array_2d_7x7,
            visuals_2d=visuals_2d,
            mat_plot_2d=aplt.MatPlot2D(output=aplt.Output(
                path=plot_path, filename="array3", format="png")),
        )

        array_plotter.figure_2d()

        assert path.join(plot_path, "array3.png") in plot_patch.paths
Esempio n. 14
0
def test__fit_quantities_are_output(fit_imaging_7x7, plot_path, plot_patch):

    fit_imaging_plotter = aplt.FitImagingPlotter(
        fit=fit_imaging_7x7,
        include_2d=aplt.Include2D(origin=True, mask=True, border=True),
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(path=plot_path, format="png")),
    )

    fit_imaging_plotter.figures_2d(
        image=True,
        noise_map=True,
        signal_to_noise_map=True,
        model_image=True,
        residual_map=True,
        normalized_residual_map=True,
        chi_squared_map=True,
    )

    assert path.join(plot_path, "image_2d.png") in plot_patch.paths
    assert path.join(plot_path, "noise_map.png") in plot_patch.paths
    assert path.join(plot_path, "signal_to_noise_map.png") in plot_patch.paths
    assert path.join(plot_path, "model_image.png") in plot_patch.paths
    assert path.join(plot_path, "residual_map.png") in plot_patch.paths
    assert path.join(plot_path,
                     "normalized_residual_map.png") in plot_patch.paths
    assert path.join(plot_path, "chi_squared_map.png") in plot_patch.paths

    plot_patch.paths = []

    fit_imaging_plotter.figures_2d(
        image=True,
        noise_map=False,
        signal_to_noise_map=False,
        model_image=True,
        chi_squared_map=True,
    )

    assert path.join(plot_path, "image_2d.png") in plot_patch.paths
    assert path.join(plot_path, "noise_map.png") not in plot_patch.paths
    assert path.join(plot_path,
                     "signal_to_noise_map.png") not in plot_patch.paths
    assert path.join(plot_path, "model_image.png") in plot_patch.paths
    assert path.join(plot_path, "residual_map.png") not in plot_patch.paths
    assert path.join(plot_path,
                     "normalized_residual_map.png") not in plot_patch.paths
    assert path.join(plot_path, "chi_squared_map.png") in plot_patch.paths
Esempio n. 15
0
def test__output_as_fits__correct_output_format(fit_imaging_7x7,
                                                grid_2d_irregular_7x7_list,
                                                mask_2d_7x7, plot_path,
                                                plot_patch):

    fit_imaging_plotter = aplt.FitImagingPlotter(
        fit=fit_imaging_7x7,
        include_2d=aplt.Include2D(origin=True, mask=True, border=True),
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(path=plot_path, format="fits")),
    )

    fit_imaging_plotter.figures_2d(image=True)

    image_from_plot = aa.util.array_2d.numpy_array_2d_from_fits(
        file_path=path.join(plot_path, "image.fits"), hdu=0)

    assert image_from_plot.shape == (5, 5)
Esempio n. 16
0
    def test__plot_rectangular_mapper__works_with_all_extras_included(
            self, rectangular_mapper_7x7_3x3, plot_path, plot_patch):

        mapper_plotter = aplt.MapperPlotter(
            mapper=rectangular_mapper_7x7_3x3,
            visuals_2d=aplt.Visuals2D(indexes=[[(0, 0), (0, 1)], [(1, 2)]],
                                      pixelization_indexes=[[0, 1], [2]]),
            mat_plot_2d=aplt.MatPlot2D(output=aplt.Output(
                path=plot_path, filename="mapper1", format="png")),
        )

        mapper_plotter.figure_2d()

        assert path.join(plot_path, "mapper1.png") in plot_patch.paths

        mapper_plotter = aplt.MapperPlotter(
            mapper=rectangular_mapper_7x7_3x3,
            visuals_2d=aplt.Visuals2D(indexes=[[(0, 0), (0, 1)], [(1, 2)]],
                                      pixelization_indexes=[[0, 1], [2]]),
            mat_plot_2d=aplt.MatPlot2D(output=aplt.Output(
                path=plot_path, filename="mapper2", format="png")),
        )

        mapper_plotter.figure_2d()

        assert path.join(plot_path, "mapper2.png") in plot_patch.paths

        mapper_plotter = aplt.MapperPlotter(
            mapper=rectangular_mapper_7x7_3x3,
            visuals_2d=aplt.Visuals2D(indexes=[[(0, 0), (0, 1)], [(1, 2)]],
                                      pixelization_indexes=[[0, 1], [2]]),
            mat_plot_2d=aplt.MatPlot2D(output=aplt.Output(
                path=plot_path, filename="mapper3", format="png")),
            include_2d=aplt.Include2D(origin=True,
                                      mapper_source_pixelization_grid=True),
        )

        mapper_plotter.figure_2d()

        assert path.join(plot_path, "mapper3.png") in plot_patch.paths