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
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
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
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___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
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__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
def test__add_visuals_together__replaces_nones(self): visuals_1 = aplt.Visuals2D(mask=1) visuals_0 = aplt.Visuals2D(border=10) visuals = visuals_0 + visuals_1 assert visuals.mask == 1 assert visuals.border == 10 assert visuals_1.mask == 1 assert visuals_1.border == 10 assert visuals_0.border == 10 assert visuals_0.mask == None visuals_0 = aplt.Visuals2D(mask=1) visuals_1 = aplt.Visuals2D(mask=2) visuals = visuals_1 + visuals_0 assert visuals.mask == 1 assert visuals.border == None assert visuals_1.mask == 2
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
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__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
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___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
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