def test__open_and_close_subplot_figures(self):

        figure = aplt.Figure(figsize=(20, 20))

        plotter = abstract_plotters.AbstractPlotter(mat_plot_2d=aplt.MatPlot2D(
            figure=figure))

        plotter.mat_plot_2d.figure.open()

        assert plt.fignum_exists(num=1) is True

        plotter.mat_plot_2d.figure.close()

        assert plt.fignum_exists(num=1) is False

        plotter = abstract_plotters.AbstractPlotter(mat_plot_2d=aplt.MatPlot2D(
            figure=figure))

        assert plt.fignum_exists(num=1) is False

        plotter.open_subplot_figure(number_subplots=4)

        assert plt.fignum_exists(num=1) is True

        plotter.mat_plot_2d.figure.close()

        assert plt.fignum_exists(num=1) is False
    def test__uses_figure_or_subplot_configs_correctly(self):

        figure = aplt.Figure(figsize=(8, 8))
        cmap = aplt.Cmap(cmap="warm")

        mat_plot_2d = aplt.MatPlot2D(figure=figure, cmap=cmap)

        plotter = abstract_plotters.AbstractPlotter(mat_plot_2d=mat_plot_2d)

        assert plotter.mat_plot_2d.figure.config_dict["figsize"] == (8, 8)
        assert plotter.mat_plot_2d.figure.config_dict["aspect"] == "square"
        assert plotter.mat_plot_2d.cmap.config_dict["cmap"] == "warm"
        assert plotter.mat_plot_2d.cmap.config_dict["norm"] == "linear"

        figure = aplt.Figure()
        figure.is_for_subplot = True

        cmap = aplt.Cmap()
        cmap.is_for_subplot = True

        mat_plot_2d = aplt.MatPlot2D(figure=figure, cmap=cmap)

        plotter = abstract_plotters.AbstractPlotter(mat_plot_2d=mat_plot_2d)

        assert plotter.mat_plot_2d.figure.config_dict["figsize"] == None
        assert plotter.mat_plot_2d.figure.config_dict["aspect"] == "square"
        assert plotter.mat_plot_2d.cmap.config_dict["cmap"] == "jet"
        assert plotter.mat_plot_2d.cmap.config_dict["norm"] == "linear"
예제 #3
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
예제 #4
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
예제 #5
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
    def test__subplot_of_plotter_list_figure(self, imaging_7x7, plot_path,
                                             plot_patch):

        mat_plot_2d = aplt.MatPlot2D(
            output=aplt.Output(plot_path, format="png"))

        plotter_0 = aplt.ImagingPlotter(imaging=imaging_7x7,
                                        mat_plot_2d=mat_plot_2d)
        plotter_1 = aplt.ImagingPlotter(imaging=imaging_7x7)

        plotter_list = [plotter_0, plotter_1]

        multi_plotter = aplt.MultiFigurePlotter(plotter_list=plotter_list)
        multi_plotter.subplot_of_figure(func_name="figures_2d",
                                        figure_name="image")

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

        plot_patch.paths = []

        multi_plotter = aplt.MultiFigurePlotter(plotter_list=plotter_list)
        multi_plotter.subplot_of_figure(func_name="figures_2d",
                                        figure_name="image",
                                        noise_map=True)

        assert path.join(plot_path,
                         "subplot_image_list.png") in plot_patch.paths
예제 #7
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,
        )
def test__individual_attributes_are_output(interferometer_7, plot_path,
                                           plot_patch):

    interferometer_plotter = aplt.InterferometerPlotter(
        interferometer=interferometer_7,
        mat_plot_1d=aplt.MatPlot1D(
            output=aplt.Output(path=plot_path, format="png")),
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(path=plot_path, format="png")),
    )

    interferometer_plotter.figures_2d(
        visibilities=True,
        noise_map=True,
        u_wavelengths=True,
        v_wavelengths=True,
        uv_wavelengths=True,
        amplitudes_vs_uv_distances=True,
        phases_vs_uv_distances=True,
        dirty_image=True,
        dirty_noise_map=True,
        dirty_signal_to_noise_map=True,
        dirty_inverse_noise_map=True,
    )

    assert path.join(plot_path, "visibilities.png") in plot_patch.paths
    assert path.join(plot_path, "noise_map.png") in plot_patch.paths
    assert path.join(plot_path, "u_wavelengths.png") in plot_patch.paths
    assert path.join(plot_path, "v_wavelengths.png") in plot_patch.paths
    assert path.join(plot_path, "uv_wavelengths.png") in plot_patch.paths
    assert path.join(plot_path,
                     "amplitudes_vs_uv_distances.png") in plot_patch.paths
    assert path.join(plot_path,
                     "phases_vs_uv_distances.png") in plot_patch.paths
    assert path.join(plot_path, "dirty_image_2d.png") in plot_patch.paths
    assert path.join(plot_path, "dirty_noise_map_2d.png") in plot_patch.paths
    assert path.join(plot_path,
                     "dirty_signal_to_noise_map_2d.png") in plot_patch.paths
    assert path.join(plot_path,
                     "dirty_inverse_noise_map_2d.png") in plot_patch.paths

    plot_patch.paths = []

    interferometer_plotter.figures_2d(
        visibilities=True,
        u_wavelengths=False,
        v_wavelengths=True,
        amplitudes_vs_uv_distances=True,
    )

    assert path.join(plot_path, "visibilities.png") in plot_patch.paths
    assert not path.join(plot_path, "u_wavelengths.png") in plot_patch.paths
    assert path.join(plot_path, "v_wavelengths.png") in plot_patch.paths
    assert path.join(plot_path,
                     "amplitudes_vs_uv_distances.png") in plot_patch.paths
    assert path.join(plot_path,
                     "phases_vs_uv_distances.png") not in plot_patch.paths
def test__subplot_is_output(imaging_7x7, grid_2d_irregular_7x7_list,
                            mask_2d_7x7, plot_path, plot_patch):

    imaging_plot = aplt.ImagingPlotter(
        imaging=imaging_7x7,
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(plot_path, format="png")),
    )

    imaging_plot.subplot_imaging()

    assert path.join(plot_path, "subplot_imaging.png") in plot_patch.paths
예제 #10
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
예제 #11
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
예제 #12
0
    def test__plot_voronoi_mapper__works_with_all_extras_included(
            self, voronoi_mapper_9_3x3, plot_path, plot_patch):

        mapper_plotter = aplt.MapperPlotter(
            mapper=voronoi_mapper_9_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(
            visuals_2d=aplt.Visuals2D(indexes=[[(0, 0), (0, 1)], [(1, 2)]],
                                      pixelization_indexes=[[0, 1], [2]]),
            mapper=voronoi_mapper_9_3x3,
            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(
            visuals_2d=aplt.Visuals2D(indexes=[[(0, 0), (0, 1)], [(1, 2)]],
                                      pixelization_indexes=[[0, 1], [2]]),
            mapper=voronoi_mapper_9_3x3,
            mat_plot_2d=aplt.MatPlot2D(output=aplt.Output(
                path=plot_path, filename="mapper3", format="png")),
        )

        mapper_plotter.figure_2d()

        assert path.join(plot_path, "mapper3.png") in plot_patch.paths
    def test__plotter_number_of_subplots(self):

        plotter = abstract_plotters.AbstractPlotter(
            mat_plot_2d=aplt.MatPlot2D())

        rows, columns = plotter.mat_plot_2d.get_subplot_rows_columns(
            number_subplots=1)

        assert rows == 1
        assert columns == 2

        rows, columns = plotter.mat_plot_2d.get_subplot_rows_columns(
            number_subplots=4)

        assert rows == 2
        assert columns == 2
예제 #14
0
def test__inversion_subplot_is_output_for_all_inversions(
    imaging_7x7,
    rectangular_inversion_7x7_3x3,
    voronoi_inversion_9_3x3,
    plot_path,
    plot_patch,
):

    inversion_plotter = aplt.InversionPlotter(
        inversion=rectangular_inversion_7x7_3x3,
        visuals_2d=aplt.Visuals2D(indexes=[0], pixelization_indexes=[1]),
        mat_plot_2d=aplt.MatPlot2D(output=aplt.Output(path=plot_path, format="png")),
    )

    inversion_plotter.subplot_inversion()
    assert path.join(plot_path, "subplot_inversion.png") in plot_patch.paths
예제 #15
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
def test__individual_attributes_are_output(imaging_7x7,
                                           grid_2d_irregular_7x7_list,
                                           mask_2d_7x7, plot_path, plot_patch):

    visuals_2d = aplt.Visuals2D(mask=mask_2d_7x7,
                                positions=grid_2d_irregular_7x7_list)

    imaging_plotter = aplt.ImagingPlotter(
        imaging=imaging_7x7,
        visuals_2d=visuals_2d,
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(plot_path, format="png")),
    )

    imaging_plotter.figures_2d(
        image=True,
        noise_map=True,
        psf=True,
        inverse_noise_map=True,
        signal_to_noise_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, "psf.png") in plot_patch.paths
    assert path.join(plot_path, "inverse_noise_map.png") in plot_patch.paths
    assert path.join(plot_path, "signal_to_noise_map.png") in plot_patch.paths

    plot_patch.paths = []

    imaging_plotter.figures_2d(image=True,
                               psf=True,
                               inverse_noise_map=True,
                               absolute_signal_to_noise_map=True)

    assert path.join(plot_path, "image_2d.png") in plot_patch.paths
    assert not path.join(plot_path, "noise_map.png") in plot_patch.paths
    assert path.join(plot_path, "psf.png") in plot_patch.paths
    assert path.join(plot_path, "inverse_noise_map.png") in plot_patch.paths
    assert not path.join(plot_path,
                         "signal_to_noise_map.png") in plot_patch.paths
    assert path.join(plot_path,
                     "absolute_signal_to_noise_map.png") in plot_patch.paths
    assert not path.join(plot_path,
                         "potential_chi_squared_map.png") in plot_patch.paths
def test__subplots_are_output(interferometer_7, plot_path, plot_patch):

    interferometer_plotter = aplt.InterferometerPlotter(
        interferometer=interferometer_7,
        mat_plot_1d=aplt.MatPlot1D(
            output=aplt.Output(path=plot_path, format="png")),
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(path=plot_path, format="png")),
    )

    interferometer_plotter.subplot_interferometer()

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

    interferometer_plotter.subplot_dirty_images()

    assert path.join(plot_path, "subplot_dirty_images.png") in plot_patch.paths
예제 #18
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)
def test__output_as_fits__correct_output_format(imaging_7x7,
                                                grid_2d_irregular_7x7_list,
                                                mask_2d_7x7, plot_path,
                                                plot_patch):

    imaging_plotter = aplt.ImagingPlotter(
        imaging=imaging_7x7,
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(path=plot_path, format="fits")),
    )

    imaging_plotter.figures_2d(image=True,
                               psf=True,
                               absolute_signal_to_noise_map=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 == (7, 7)
def test__fit_sub_plots(fit_interferometer_7, plot_path, plot_patch):

    fit_interferometer_plotter = aplt.FitInterferometerPlotter(
        fit=fit_interferometer_7,
        mat_plot_1d=aplt.MatPlot1D(
            output=aplt.Output(path=plot_path, format="png")),
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(path=plot_path, format="png")),
    )

    fit_interferometer_plotter.subplot_fit_interferometer()

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

    fit_interferometer_plotter.subplot_fit_dirty_images()

    assert path.join(plot_path,
                     "subplot_fit_dirty_images.png") in plot_patch.paths
예제 #21
0
    def test__fits_files_output_correctly(self, array_2d_7x7, plot_path):

        plot_path = path.join(plot_path, "fits")

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

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

        array_plotter.figure_2d()

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

        assert (arr == array_2d_7x7.native).all()
    def test__subplot_figsize_for_number_of_subplots(self):

        plotter = abstract_plotters.AbstractPlotter()

        figsize = plotter.get_subplot_figsize(number_subplots=1)

        assert figsize == (18, 8)

        figsize = plotter.get_subplot_figsize(number_subplots=4)

        assert figsize == (13, 10)

        figure = aplt.Figure(figsize=(20, 20))

        plotter = abstract_plotters.AbstractPlotter(mat_plot_2d=aplt.MatPlot2D(
            figure=figure))

        figsize = plotter.get_subplot_figsize(number_subplots=4)

        assert figsize == (20, 20)
def test__fit_quantities_are_output(fit_interferometer_7, plot_path,
                                    plot_patch):

    fit_interferometer_plotter = aplt.FitInterferometerPlotter(
        fit=fit_interferometer_7,
        mat_plot_1d=aplt.MatPlot1D(
            output=aplt.Output(path=plot_path, format="png")),
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(path=plot_path, format="png")),
    )

    fit_interferometer_plotter.figures_2d(
        visibilities=True,
        noise_map=True,
        signal_to_noise_map=True,
        model_visibilities=True,
        residual_map_real=True,
        residual_map_imag=True,
        normalized_residual_map_real=True,
        normalized_residual_map_imag=True,
        chi_squared_map_real=True,
        chi_squared_map_imag=True,
        dirty_image=True,
        dirty_noise_map=True,
        dirty_signal_to_noise_map=True,
        dirty_model_image=True,
        dirty_residual_map=True,
        dirty_normalized_residual_map=True,
        dirty_chi_squared_map=True,
    )

    assert path.join(plot_path, "visibilities.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_visibilities.png") in plot_patch.paths
    assert (path.join(plot_path, "real_residual_map_vs_uv_distances.png")
            in plot_patch.paths)
    assert (path.join(plot_path, "real_residual_map_vs_uv_distances.png")
            in plot_patch.paths)
    assert (path.join(plot_path,
                      "real_normalized_residual_map_vs_uv_distances.png")
            in plot_patch.paths)
    assert (path.join(plot_path,
                      "imag_normalized_residual_map_vs_uv_distances.png")
            in plot_patch.paths)
    assert (path.join(plot_path, "imag_chi_squared_map_vs_uv_distances.png")
            in plot_patch.paths)
    assert (path.join(plot_path, "imag_chi_squared_map_vs_uv_distances.png")
            in plot_patch.paths)
    assert path.join(plot_path, "dirty_image_2d.png") in plot_patch.paths
    assert path.join(plot_path, "dirty_noise_map_2d.png") in plot_patch.paths
    assert path.join(plot_path,
                     "dirty_signal_to_noise_map_2d.png") in plot_patch.paths
    assert path.join(plot_path, "dirty_model_image_2d.png") in plot_patch.paths
    assert path.join(plot_path,
                     "dirty_residual_map_2d.png") in plot_patch.paths
    assert (path.join(plot_path, "dirty_normalized_residual_map_2d.png")
            in plot_patch.paths)
    assert path.join(plot_path,
                     "dirty_chi_squared_map_2d.png") in plot_patch.paths

    plot_patch.paths = []

    fit_interferometer_plotter.figures_2d(
        visibilities=True,
        noise_map=False,
        signal_to_noise_map=False,
        model_visibilities=True,
        chi_squared_map_real=True,
        chi_squared_map_imag=True,
    )

    assert path.join(plot_path, "visibilities.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_visibilities.png") in plot_patch.paths
    assert (path.join(plot_path, "real_residual_map_vs_uv_distances.png")
            not in plot_patch.paths)
    assert (path.join(plot_path, "imag_residual_map_vs_uv_distances.png")
            not in plot_patch.paths)
    assert (path.join(plot_path,
                      "real_normalized_residual_map_vs_uv_distances.png")
            not in plot_patch.paths)
    assert (path.join(plot_path,
                      "imag_normalized_residual_map_vs_uv_distances.png")
            not in plot_patch.paths)
    assert (path.join(plot_path, "real_chi_squared_map_vs_uv_distances.png")
            in plot_patch.paths)
    assert (path.join(plot_path, "imag_chi_squared_map_vs_uv_distances.png")
            in plot_patch.paths)
예제 #24
0
def test__individual_attributes_are_output_for_all_mappers(
    rectangular_inversion_7x7_3x3,
    voronoi_inversion_9_3x3,
    grid_2d_irregular_7x7_list,
    plot_path,
    plot_patch,
):

    inversion_plotter = aplt.InversionPlotter(
        inversion=rectangular_inversion_7x7_3x3,
        visuals_2d=aplt.Visuals2D(indexes=[0], pixelization_indexes=[1]),
        mat_plot_2d=aplt.MatPlot2D(output=aplt.Output(path=plot_path, format="png")),
    )

    inversion_plotter.figures_2d(
        reconstructed_image=True,
        reconstruction=True,
        errors=True,
        residual_map=True,
        normalized_residual_map=True,
        chi_squared_map=True,
        regularization_weight_list=True,
        interpolated_reconstruction=True,
        interpolated_errors=True,
    )

    assert path.join(plot_path, "reconstructed_image.png") in plot_patch.paths
    assert path.join(plot_path, "reconstruction.png") in plot_patch.paths
    assert path.join(plot_path, "errors.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
    assert path.join(plot_path, "regularization_weight_list.png") in plot_patch.paths
    assert path.join(plot_path, "interpolated_reconstruction.png") in plot_patch.paths
    assert path.join(plot_path, "interpolated_errors.png") in plot_patch.paths

    plot_patch.paths = []

    inversion_plotter = aplt.InversionPlotter(
        inversion=voronoi_inversion_9_3x3,
        visuals_2d=aplt.Visuals2D(indexes=[0], pixelization_indexes=[1]),
        mat_plot_2d=aplt.MatPlot2D(output=aplt.Output(path=plot_path, format="png")),
    )

    inversion_plotter.figures_2d(
        reconstructed_image=True,
        reconstruction=True,
        errors=True,
        residual_map=True,
        normalized_residual_map=True,
        chi_squared_map=True,
        regularization_weight_list=True,
        interpolated_reconstruction=True,
        interpolated_errors=True,
    )

    assert path.join(plot_path, "reconstructed_image.png") in plot_patch.paths
    assert path.join(plot_path, "reconstruction.png") in plot_patch.paths
    assert path.join(plot_path, "errors.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
    assert path.join(plot_path, "regularization_weight_list.png") in plot_patch.paths
    assert path.join(plot_path, "interpolated_reconstruction.png") in plot_patch.paths
    assert path.join(plot_path, "interpolated_errors.png") in plot_patch.paths

    plot_patch.paths = []

    inversion_plotter.figures_2d(
        reconstructed_image=True,
        errors=True,
        chi_squared_map=True,
        interpolated_reconstruction=True,
    )

    assert path.join(plot_path, "reconstructed_image.png") in plot_patch.paths
    assert path.join(plot_path, "reconstruction.png") not in plot_patch.paths
    assert path.join(plot_path, "errors.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
    assert path.join(plot_path, "interpolated_reconstruction.png") in plot_patch.paths
    assert path.join(plot_path, "interpolated_errors.png") not in plot_patch.paths