def subplot_detection_imaging(self, remove_zeros: bool = False): self.open_subplot_figure(number_subplots=4) self.set_title("Image") self.fit_imaging_detect_plotter.figures_2d(image=True) self.set_title("Signal-To-Noise Map") self.fit_imaging_detect_plotter.figures_2d(signal_to_noise_map=True) self.set_title(None) self.mat_plot_2d.plot_array( array=self.detection_array_from(remove_zeros=remove_zeros), visuals_2d=self.visuals_2d, auto_labels=aplt.AutoLabels(title="Increase in Log Evidence"), ) mass_array = self.subhalo_result.subhalo_mass_array_from() self.mat_plot_2d.plot_array( array=mass_array, visuals_2d=self.visuals_2d, auto_labels=aplt.AutoLabels(title="Subhalo Mass"), ) self.mat_plot_2d.output.subplot_to_figure( auto_filename="subplot_detection_imaging") self.close_subplot_figure()
def figures_2d(self, positions: bool = False, fluxes: bool = False): if positions: visuals_2d = self.get_visuals_2d() visuals_2d += visuals_2d.__class__( positions=self.fit.positions.model_positions) self.mat_plot_2d.plot_grid( grid=self.fit.point_dataset.positions, y_errors=self.fit.point_dataset.positions_noise_map, x_errors=self.fit.point_dataset.positions_noise_map, visuals_2d=visuals_2d, auto_labels=aplt.AutoLabels( title=f"{self.fit.point_dataset.name} Fit Positions", filename="fit_point_dataset_positions", ), buffer=0.1, ) # nasty hack to ensure subplot index between 2d and 1d plots are syncs. Need a refactor that mvoes subplot # functionality out of mat_plot and into plotter. if (self.mat_plot_1d.subplot_index is not None and self.mat_plot_2d.subplot_index is not None): self.mat_plot_1d.subplot_index = max( self.mat_plot_1d.subplot_index, self.mat_plot_2d.subplot_index) if fluxes: if self.fit.point_dataset.fluxes is not None: visuals_1d = self.get_visuals_1d() visuals_1d += visuals_1d.__class__( model_fluxes=self.fit.flux.model_fluxes) self.mat_plot_1d.plot_yx( y=self.fit.point_dataset.fluxes, y_errors=self.fit.point_dataset.fluxes_noise_map, visuals_1d=visuals_1d, auto_labels=aplt.AutoLabels( title=f" {self.fit.point_dataset.name} Fit Fluxes", filename="fit_point_dataset_fluxes", xlabel="Point Number", ), plot_axis_type_override="errorbar", )
def subplot( self, image: bool = False, source_plane: bool = False, convergence: bool = False, potential: bool = False, deflections_y: bool = False, deflections_x: bool = False, magnification: bool = False, contribution_map: bool = False, auto_filename: str = "subplot_tracer", ): """ Plots the individual attributes of the plotter's `Tracer` object in 2D on a subplot, which are computed via the plotter's 2D grid object. The API is such that every plottable attribute of the `Tracer` object is an input parameter of type bool of the function, which if switched to `True` means that it is included on the subplot. Parameters ---------- image Whether or not to include a 2D plot (via `imshow`) of the image of tracer in its image-plane (e.g. after lensing). source_plane Whether or not to include a 2D plot (via `imshow`) of the image of the tracer in the source-plane (e.g. its unlensed light). convergence Whether or not to include a 2D plot (via `imshow`) of the convergence. potential Whether or not to include a 2D plot (via `imshow`) of the potential. deflections_y Whether or not to include a 2D plot (via `imshow`) of the y component of the deflection angles. deflections_x Whether or not to include a 2D plot (via `imshow`) of the x component of the deflection angles. magnification Whether or not to include a 2D plot (via `imshow`) of the magnification. contribution_map Whether or not to include a 2D plot (via `imshow`) of the contribution map. auto_filename The default filename of the output subplot if written to hard-disk. """ self._subplot_custom_plot( image=image, source_plane=source_plane, convergence=convergence, potential=potential, deflections_y=deflections_y, deflections_x=deflections_x, magnification=magnification, contribution_map=contribution_map, auto_labels=aplt.AutoLabels(filename=auto_filename), )
def subplot( self, positions: bool = False, fluxes: bool = False, auto_filename: str = "subplot_fit_point", ): self._subplot_custom_plot( positions=positions, fluxes=fluxes, auto_labels=aplt.AutoLabels(filename=auto_filename), )
def figures_2d( self, image: bool = False, source_plane: bool = False, convergence: bool = False, potential: bool = False, deflections_y: bool = False, deflections_x: bool = False, magnification: bool = False, contribution_map: bool = False, ): """ Plots the individual attributes of the plotter's `Tracer` object in 2D, which are computed via the plotter's 2D grid object. The API is such that every plottable attribute of the `Tracer` object is an input parameter of type bool of the function, which if switched to `True` means that it is plotted. Parameters ---------- image Whether or not to make a 2D plot (via `imshow`) of the image of tracer in its image-plane (e.g. after lensing). source_plane Whether or not to make a 2D plot (via `imshow`) of the image of the tracer in the source-plane (e.g. its unlensed light). convergence Whether or not to make a 2D plot (via `imshow`) of the convergence. potential Whether or not to make a 2D plot (via `imshow`) of the potential. deflections_y Whether or not to make a 2D plot (via `imshow`) of the y component of the deflection angles. deflections_x Whether or not to make a 2D plot (via `imshow`) of the x component of the deflection angles. magnification Whether or not to make a 2D plot (via `imshow`) of the magnification. contribution_map Whether or not to make a 2D plot (via `imshow`) of the contribution map. """ if image: self.mat_plot_2d.plot_array( array=self.tracer.image_2d_from(grid=self.grid), visuals_2d=self.get_visuals_2d(), auto_labels=aplt.AutoLabels(title="Image", filename="image_2d"), ) if source_plane: self.figures_2d_of_planes(plane_image=True, plane_index=len(self.tracer.planes) - 1) self._mass_plotter.figures_2d( convergence=convergence, potential=potential, deflections_y=deflections_y, deflections_x=deflections_x, magnification=magnification, ) if contribution_map: self.mat_plot_2d.plot_array( array=self.tracer.contribution_map, visuals_2d=self.get_visuals_2d(), auto_labels=aplt.AutoLabels(title="Contribution Map", filename="contribution_map_2d"), )
def figures_2d_of_planes( self, plane_index: Optional[int] = None, subtracted_image: bool = False, model_image: bool = False, plane_image: bool = False, ): """ Plots images representing each individual `Plane` in the fit's `Tracer` in 2D, which are computed via the plotter's 2D grid object. These images subtract or omit the contribution of other planes in the plane, such that plots showing each individual plane are made. The API is such that every plottable attribute of the `Plane` object is an input parameter of type bool of the function, which if switched to `True` means that it is plotted. Parameters ---------- plane_index The index of the plane which figures are plotted for. subtracted_image Whether or not to make a 2D plot (via `imshow`) of the subtracted image of a plane, where this image is the fit's `data` minus the model images of all other planes, thereby showing an individual plane in the data. model_image Whether or not to make a 2D plot (via `imshow`) of the model image of a plane, where this image is the model image of one plane, thereby showing how much it contributes to the overall model image. plane_image Whether or not to make a 2D plot (via `imshow`) of the image of a plane in its source-plane (e.g. unlensed). Depending on how the fit is performed, this could either be an image of light profiles of the reconstruction of an `Inversion`. """ plane_indexes = self.plane_indexes_from(plane_index=plane_index) for plane_index in plane_indexes: if subtracted_image: if "vmin" in self.mat_plot_2d.cmap.kwargs: vmin_stored = True else: self.mat_plot_2d.cmap.kwargs["vmin"] = 0.0 vmin_stored = False if "vmax" in self.mat_plot_2d.cmap.kwargs: vmax_stored = True else: self.mat_plot_2d.cmap.kwargs["vmax"] = np.max( self.fit.model_images_of_planes[plane_index]) vmax_stored = False self.mat_plot_2d.plot_array( array=self.fit.subtracted_images_of_planes[plane_index], visuals_2d=self.get_visuals_2d(), auto_labels=aplt.AutoLabels( title=f"Subtracted Image of Plane {plane_index}", filename=f"subtracted_image_of_plane_{plane_index}", ), ) if not vmin_stored: self.mat_plot_2d.cmap.kwargs.pop("vmin") if not vmax_stored: self.mat_plot_2d.cmap.kwargs.pop("vmax") if model_image: if self.fit.inversion is None or plane_index == 0: self.mat_plot_2d.plot_array( array=self.fit.model_images_of_planes[plane_index], visuals_2d=self.get_visuals_2d(), auto_labels=aplt.AutoLabels( title=f"Model Image of Plane {plane_index}", filename=f"model_image_of_plane_{plane_index}", ), ) else: inversion_plotter = self.inversion_plotter_of_plane( plane_index=0) inversion_plotter.figures_2d(reconstructed_image=True) if plane_image: if not self.tracer.planes[plane_index].has_pixelization: self.tracer_plotter.figures_2d_of_planes( plane_image=True, plane_index=plane_index) elif self.tracer.planes[plane_index].has_pixelization: inversion_plotter = self.inversion_plotter_of_plane( plane_index=1) inversion_plotter.figures_2d_of_mapper(mapper_index=0, reconstruction=True)