def test__fit_sub_plot_real_space(
    fit_interferometer_7x7,
    fit_interferometer_x2_galaxy_inversion_7x7,
    include_2d_all,
    plot_path,
    plot_patch,
):

    fit_interferometer_plotter = aplt.FitInterferometerPlotter(
        fit=fit_interferometer_7x7,
        include_2d=include_2d_all,
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(plot_path, format="png")),
    )

    fit_interferometer_plotter.subplot_fit_real_space()

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

    plot_patch.paths = []

    fit_interferometer_plotter = aplt.FitInterferometerPlotter(
        fit=fit_interferometer_x2_galaxy_inversion_7x7,
        include_2d=include_2d_all,
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(plot_path, format="png")),
    )

    fit_interferometer_plotter.subplot_fit_real_space()

    assert path.join(plot_path,
                     "subplot_fit_real_space.png") in plot_patch.paths
Exemple #2
0
def test__fit_sub_plot__all_types_of_fit(
    fit_quantity_7x7_array_2d,
    fit_quantity_7x7_vector_yx_2d,
    include_2d_all,
    plot_patch,
    plot_path,
):

    fit_quantity_plotter = aplt.FitQuantityPlotter(
        fit=fit_quantity_7x7_array_2d,
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(path=plot_path, format="png")),
    )

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

    fit_quantity_plotter = aplt.FitQuantityPlotter(
        fit=fit_quantity_7x7_vector_yx_2d,
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(path=plot_path, format="png")),
    )

    fit_quantity_plotter.subplot_fit_quantity()

    print(plot_patch.paths)

    assert path.join(plot_path,
                     "subplot_fit_quantity_y.png") in plot_patch.paths
    assert path.join(plot_path,
                     "subplot_fit_quantity_x.png") in plot_patch.paths
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,
    include_2d_all,
    plot_patch,
    plot_path,
):

    fit_galaxy_plotter = aplt.FitGalaxyPlotter(
        fit=gal_fit_7x7_image,
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(path=plot_path, format="png")),
    )

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

    fit_galaxy_plotter = aplt.FitGalaxyPlotter(
        fit=gal_fit_7x7_convergence,
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(path=plot_path, format="png")),
    )

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

    fit_galaxy_plotter = aplt.FitGalaxyPlotter(
        fit=gal_fit_7x7_potential,
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(path=plot_path, format="png")),
    )

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

    fit_galaxy_plotter = aplt.FitGalaxyPlotter(
        fit=gal_fit_7x7_deflections_y,
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(path=plot_path, format="png")),
    )

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

    fit_galaxy_plotter = aplt.FitGalaxyPlotter(
        fit=gal_fit_7x7_deflections_x,
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(path=plot_path, format="png")),
    )

    fit_galaxy_plotter.subplot_fit_galaxy()
    assert path.join(plot_path, "subplot_fit_galaxy.png") in plot_patch.paths
Exemple #4
0
def test__subplots_galaxy_quantities__all_are_output(
    gal_x1_lp_x1_mp,
    sub_grid_2d_7x7,
    grid_2d_irregular_7x7_list,
    include_2d_all,
    plot_path,
    plot_patch,
):

    galaxy_plotter = aplt.GalaxyPlotter(
        galaxy=gal_x1_lp_x1_mp,
        grid=sub_grid_2d_7x7,
        include_2d=include_2d_all,
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(plot_path, format="png")),
    )
    galaxy_plotter.subplot_of_light_profiles(image=True)

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

    galaxy_plotter.subplot_of_mass_profiles(convergence=True,
                                            potential=True,
                                            deflections_y=True,
                                            deflections_x=True)

    assert path.join(plot_path, "subplot_convergence.png") in plot_patch.paths
    assert path.join(plot_path, "subplot_potential.png") in plot_patch.paths
    assert path.join(plot_path,
                     "subplot_deflections_y.png") in plot_patch.paths
    assert path.join(plot_path,
                     "subplot_deflections_x.png") in plot_patch.paths
Exemple #5
0
def test__figures_2d__all_are_output(
    gal_x1_lp_x1_mp,
    sub_grid_2d_7x7,
    mask_2d_7x7,
    grid_2d_irregular_7x7_list,
    include_2d_all,
    plot_path,
    plot_patch,
):

    galaxy_plotter = aplt.GalaxyPlotter(
        galaxy=gal_x1_lp_x1_mp,
        grid=sub_grid_2d_7x7,
        include_2d=include_2d_all,
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(plot_path, format="png")),
    )
    galaxy_plotter.figures_2d(image=True, convergence=True)

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

    gal_x1_lp_x1_mp.hyper_galaxy = ag.HyperGalaxy()
    gal_x1_lp_x1_mp.hyper_model_image = ag.Array2D.ones(shape_native=(7, 7),
                                                        pixel_scales=0.1)
    gal_x1_lp_x1_mp.hyper_galaxy_image = ag.Array2D.ones(shape_native=(7, 7),
                                                         pixel_scales=0.1)

    galaxy_plotter.figures_2d(contribution_map=True)
    assert path.join(plot_path, "contribution_map_2d.png") in plot_patch.paths
Exemple #6
0
def test__all_individual_plotter__output_file_with_default_name(
    plane_7x7,
    sub_grid_2d_7x7,
    mask_2d_7x7,
    grid_2d_irregular_7x7_list,
    include_2d_all,
    plot_path,
    plot_patch,
):

    plane_plotter = aplt.PlanePlotter(
        plane=plane_7x7,
        grid=sub_grid_2d_7x7,
        include_2d=include_2d_all,
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(plot_path, format="png")),
    )

    plane_plotter.figures_2d(image=True, plane_image=True, plane_grid=True)

    assert path.join(plot_path, "image_2d.png") in plot_patch.paths
    assert path.join(plot_path, "plane_image.png") in plot_patch.paths
    assert path.join(plot_path, "plane_grid.png") in plot_patch.paths

    plane_7x7.galaxies[0].hyper_galaxy = ag.HyperGalaxy()
    plane_7x7.galaxies[0].hyper_model_image = ag.Array2D.ones(shape_native=(7,
                                                                            7),
                                                              pixel_scales=0.1)
    plane_7x7.galaxies[0].hyper_galaxy_image = ag.Array2D.ones(
        shape_native=(7, 7), pixel_scales=0.1)

    plane_plotter.figures_2d(contribution_map=True)

    assert path.join(plot_path, "contribution_map_2d.png") in plot_patch.paths
def test__figures_2d__all_are_output(
    mp_0,
    sub_grid_2d_7x7,
    grid_2d_irregular_7x7_list,
    include_2d_all,
    plot_path,
    plot_patch,
):

    mass_profile_plotter = aplt.MassProfilePlotter(
        mass_profile=mp_0,
        grid=sub_grid_2d_7x7,
        include_2d=include_2d_all,
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(plot_path, format="png")),
    )
    mass_profile_plotter.figures_2d(
        convergence=True,
        potential=True,
        deflections_y=True,
        deflections_x=True,
        magnification=True,
    )

    assert path.join(plot_path, "convergence_2d.png") in plot_patch.paths
    assert path.join(plot_path, "potential_2d.png") in plot_patch.paths
    assert path.join(plot_path, "deflections_y_2d.png") in plot_patch.paths
    assert path.join(plot_path, "deflections_x_2d.png") in plot_patch.paths
    assert path.join(plot_path, "magnification_2d.png") in plot_patch.paths
Exemple #8
0
def test__fit_individuals__source_and_galaxy__dependent_on_input(
        fit_imaging_x2_galaxy_7x7, include_2d_all, plot_path, plot_patch):

    fit_imaging_plotter = aplt.FitImagingPlotter(
        fit=fit_imaging_x2_galaxy_7x7,
        include_2d=include_2d_all,
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(plot_path, format="png")),
    )

    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
Exemple #9
0
def test__plot_contribution_map_list(
    contribution_map_7x7, mask_2d_7x7, include_2d_all, plot_path, plot_patch
):

    hyper_plotter = aplt.HyperPlotter(
        include_2d=include_2d_all,
        mat_plot_2d=aplt.MatPlot2D(output=aplt.Output(plot_path, format="png")),
    )

    hyper_plotter.subplot_contribution_map_list(
        contribution_map_list_list=[contribution_map_7x7, contribution_map_7x7, None]
    )

    assert path.join(plot_path, "subplot_contribution_map_list.png") in plot_patch.paths
Exemple #10
0
def test__plot_hyper_images_of_galaxies(hyper_galaxy_image_path_dict_7x7,
                                        mask_2d_7x7, include_2d_all, plot_path,
                                        plot_patch):

    hyper_plotter = aplt.HyperPlotter(
        include_2d=include_2d_all,
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(plot_path, format="png")),
    )

    hyper_plotter.subplot_hyper_images_of_galaxies(
        hyper_galaxy_image_path_dict=hyper_galaxy_image_path_dict_7x7)
    assert (path.join(plot_path, "subplot_hyper_images_of_galaxies.png")
            in plot_patch.paths)
    def __init__(
            self,
            fit: FitImaging,
            mat_plot_2d: aplt.MatPlot2D = aplt.MatPlot2D(),
            visuals_2d: aplt.Visuals2D = aplt.Visuals2D(),
            include_2d: aplt.Include2D = aplt.Include2D(),
    ):
        """
        Plots the attributes of `FitImaging` objects using the matplotlib method `imshow()` and many other matplotlib
        functions which customize the plot's appearance.

        The `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 `MatPlot2d` to customize the figure's appearance.

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

        Parameters
        ----------
        fit
            The fit to an imaging dataset the plotter plots.
        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.
        """
        super().__init__(mat_plot_2d=mat_plot_2d,
                         include_2d=include_2d,
                         visuals_2d=visuals_2d)

        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,
        )

        self.figures_2d = self._fit_imaging_meta_plotter.figures_2d
        self.subplot = self._fit_imaging_meta_plotter.subplot
        self.subplot_fit_imaging = self._fit_imaging_meta_plotter.subplot_fit_imaging
Exemple #12
0
    def __init__(
            self,
            subhalo_result: SubhaloResult,
            fit_imaging_detect,
            use_log_evidences: bool = True,
            use_stochastic_log_likelihoods: bool = False,
            mat_plot_2d: aplt.MatPlot2D = aplt.MatPlot2D(),
            visuals_2d: aplt.Visuals2D = aplt.Visuals2D(),
            include_2d: aplt.Include2D = aplt.Include2D(),
    ):
        super().__init__(mat_plot_2d=mat_plot_2d,
                         include_2d=include_2d,
                         visuals_2d=visuals_2d)

        self.subhalo_result = subhalo_result
        self.fit_imaging_detect = fit_imaging_detect
        self.use_log_evidences = use_log_evidences
        self.use_stochastic_log_likelihoods = use_stochastic_log_likelihoods
Exemple #13
0
def test__figures_2d__all_are_output(
    lp_0,
    sub_grid_2d_7x7,
    grid_2d_irregular_7x7_list,
    include_2d_all,
    plot_path,
    plot_patch,
):

    light_profile_plotter = aplt.LightProfilePlotter(
        light_profile=lp_0,
        grid=sub_grid_2d_7x7,
        include_2d=include_2d_all,
        mat_plot_2d=aplt.MatPlot2D(output=aplt.Output(plot_path, format="png")),
    )

    light_profile_plotter.figures_2d(image=True)

    assert path.join(plot_path, "image_2d.png") in plot_patch.paths
Exemple #14
0
    def __init__(
            self,
            point_dict: PointDict,
            mat_plot_1d: aplt.MatPlot1D = aplt.MatPlot1D(),
            visuals_1d: aplt.Visuals1D = aplt.Visuals1D(),
            include_1d: aplt.Include1D = aplt.Include1D(),
            mat_plot_2d: aplt.MatPlot2D = aplt.MatPlot2D(),
            visuals_2d: aplt.Visuals2D = aplt.Visuals2D(),
            include_2d: aplt.Include2D = aplt.Include2D(),
    ):
        super().__init__(
            mat_plot_1d=mat_plot_1d,
            visuals_1d=visuals_1d,
            include_1d=include_1d,
            mat_plot_2d=mat_plot_2d,
            include_2d=include_2d,
            visuals_2d=visuals_2d,
        )

        self.point_dict = point_dict
Exemple #15
0
def test__subplot_of_galaxy(fit_imaging_x2_galaxy_7x7, include_2d_all,
                            plot_path, plot_patch):

    fit_imaging_plotter = aplt.FitImagingPlotter(
        fit=fit_imaging_x2_galaxy_7x7,
        include_2d=include_2d_all,
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(plot_path, format="png")),
    )
    fit_imaging_plotter.subplots_of_galaxies()
    assert path.join(plot_path, "subplot_of_galaxy_0.png") in plot_patch.paths
    assert path.join(plot_path, "subplot_of_galaxy_1.png") in plot_patch.paths

    plot_patch.paths = []

    fit_imaging_plotter.subplots_of_galaxies(galaxy_index=0)

    assert path.join(plot_path, "subplot_of_galaxy_0.png") in plot_patch.paths
    assert path.join(plot_path,
                     "subplot_of_galaxy_1.png") not in plot_patch.paths
    def __init__(
            self,
            fit: FitPointDataset,
            mat_plot_1d: aplt.MatPlot1D = aplt.MatPlot1D(),
            visuals_1d: aplt.Visuals1D = aplt.Visuals1D(),
            include_1d: aplt.Include1D = aplt.Include1D(),
            mat_plot_2d: aplt.MatPlot2D = aplt.MatPlot2D(),
            visuals_2d: aplt.Visuals2D = aplt.Visuals2D(),
            include_2d: aplt.Include2D = aplt.Include2D(),
    ):
        super().__init__(
            mat_plot_1d=mat_plot_1d,
            visuals_1d=visuals_1d,
            include_1d=include_1d,
            mat_plot_2d=mat_plot_2d,
            include_2d=include_2d,
            visuals_2d=visuals_2d,
        )

        self.fit = fit
Exemple #17
0
def test__plot_individual_images(
    hyper_galaxy_image_0_7x7,
    contribution_map_7x7,
    include_2d_all,
    plot_path,
    plot_patch,
):

    hyper_plotter = aplt.HyperPlotter(
        include_2d=include_2d_all,
        mat_plot_2d=aplt.MatPlot2D(output=aplt.Output(plot_path, format="png")),
    )

    hyper_plotter.figure_hyper_galaxy_image(galaxy_image=hyper_galaxy_image_0_7x7)

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

    hyper_plotter.figure_contribution_map(contribution_map=contribution_map_7x7)

    assert path.join(plot_path, "contribution_map_2d.png") in plot_patch.paths
Exemple #18
0
def test__figures_of_galaxies(fit_imaging_x2_galaxy_7x7, include_2d_all,
                              plot_path, plot_patch):

    fit_imaging_plotter = aplt.FitImagingPlotter(
        fit=fit_imaging_x2_galaxy_7x7,
        include_2d=include_2d_all,
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(plot_path, format="png")),
    )

    fit_imaging_plotter.figures_2d_of_galaxies(subtracted_image=True)

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

    fit_imaging_plotter.figures_2d_of_galaxies(model_image=True)

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

    plot_patch.paths = []

    fit_imaging_plotter.figures_2d_of_galaxies(subtracted_image=True,
                                               galaxy_index=0)

    assert path.join(plot_path,
                     "subtracted_image_of_galaxy_0.png") in plot_patch.paths
    assert (path.join(plot_path, "subtracted_image_of_galaxy_1.png")
            not in plot_patch.paths)

    fit_imaging_plotter.figures_2d_of_galaxies(model_image=True,
                                               galaxy_index=1)

    assert path.join(plot_path,
                     "model_image_of_galaxy_0.png") not in plot_patch.paths
    assert path.join(plot_path,
                     "model_image_of_galaxy_1.png") in plot_patch.paths
    def __init__(
            self,
            tracer: Tracer,
            grid: aa.type.Grid2DLike,
            mat_plot_1d: aplt.MatPlot1D = aplt.MatPlot1D(),
            visuals_1d: aplt.Visuals1D = aplt.Visuals1D(),
            include_1d: aplt.Include1D = aplt.Include1D(),
            mat_plot_2d: aplt.MatPlot2D = aplt.MatPlot2D(),
            visuals_2d: aplt.Visuals2D = aplt.Visuals2D(),
            include_2d: aplt.Include2D = aplt.Include2D(),
    ):
        """
        Plots the attributes of `Tracer` objects using the matplotlib methods `plot()` and `imshow()` and many 
        other matplotlib functions which customize the plot's appearance.

        The `mat_plot_1d` and `mat_plot_2d` attributes wrap 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 `MatPlot2D` to 
        customize the figure's appearance.

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

        Parameters
        ----------
        tracer
            The tracer the plotter plots.
        grid
            The 2D (y,x) grid of coordinates used to evaluate the tracer's light and mass quantities that are plotted.
        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 `MassProfile` are extracted and plotted as visuals for 1D plots.
        mat_plot_2d
            Contains objects which wrap the matplotlib function calls that make 2D plots.
        visuals_2d
            Contains 2D visuals that can be overlaid on 2D plots.
        include_2d
            Specifies which attributes of the `MassProfile` are extracted and plotted as visuals for 2D plots.
        """
        super().__init__(
            mat_plot_1d=mat_plot_1d,
            visuals_1d=visuals_1d,
            include_1d=include_1d,
            mat_plot_2d=mat_plot_2d,
            include_2d=include_2d,
            visuals_2d=visuals_2d,
        )

        self.tracer = tracer
        self.grid = grid

        self._mass_plotter = MassPlotter(
            mass_obj=self.tracer,
            grid=self.grid,
            get_visuals_2d=self.get_visuals_2d,
            mat_plot_2d=self.mat_plot_2d,
            include_2d=self.include_2d,
            visuals_2d=self.visuals_2d,
        )