def __init__( self, plane: Plane, grid: aa.Grid2D, mat_plot_1d: MatPlot1D = MatPlot1D(), visuals_1d: Visuals1D = Visuals1D(), include_1d: Include1D = Include1D(), mat_plot_2d: MatPlot2D = MatPlot2D(), visuals_2d: Visuals2D = Visuals2D(), include_2d: Include2D = Include2D(), ): """ Plots the attributes of `Plane` 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 ---------- plane The plane the plotter plots. grid The 2D (y,x) grid of coordinates used to evaluate the plane'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_2d=mat_plot_2d, include_2d=include_2d, visuals_2d=visuals_2d, mat_plot_1d=mat_plot_1d, include_1d=include_1d, visuals_1d=visuals_1d, ) self.plane = plane self.grid = grid self._mass_plotter = MassPlotter( mass_obj=self.plane, 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, )
class TracerPlotter(Plotter): 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, ) def get_visuals_2d(self) -> aplt.Visuals2D: return self.get_visuals_2d_of_plane(plane_index=0) def get_visuals_2d_of_plane(self, plane_index: int) -> aplt.Visuals2D: return self.get_2d.via_tracer_from(tracer=self.tracer, grid=self.grid, plane_index=plane_index) def plane_plotter_from(self, plane_index: int) -> aplt.PlanePlotter: """ Returns an `PlanePlotter` corresponding to a `Plane` in the `Tracer`. Returns ------- plane_index The index of the plane in the `Tracer` used to make the `PlanePlotter`. """ plane_grid = self.tracer.traced_grid_list_from( grid=self.grid)[plane_index] return aplt.PlanePlotter( plane=self.tracer.planes[plane_index], grid=plane_grid, mat_plot_2d=self.mat_plot_2d, visuals_2d=self.get_visuals_2d_of_plane(plane_index=plane_index), include_2d=self.include_2d, ) 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 plane_indexes_from(self, plane_index: Optional[int]) -> List[int]: """ Returns a list of all indexes of the planes in the fit, which is iterated over in figures that plot individual figures of each plane in a tracer. Parameters ---------- plane_index A specific plane index which when input means that only a single plane index is returned. Returns ------- list A list of galaxy indexes corresponding to planes in the plane. """ if plane_index is None: return list(range(len(self.tracer.planes))) return [plane_index] def figures_2d_of_planes( self, plane_image: bool = False, plane_grid: bool = False, plane_index: Optional[int] = None, ): """ Plots source-plane images (e.g. the unlensed light) each individual `Plane` in the plotter's `Tracer` in 2D, which are computed via the plotter's 2D grid object. 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_image Whether or not to make a 2D plot (via `imshow`) of the image of the plane in the soure-plane (e.g. its unlensed light). plane_grid Whether or not to make a 2D plot (via `scatter`) of the lensed (y,x) coordinates of the plane in the source-plane. plane_index If input, plots for only a single plane based on its index in the tracer are created. """ plane_indexes = self.plane_indexes_from(plane_index=plane_index) for plane_index in plane_indexes: plane_plotter = self.plane_plotter_from(plane_index=plane_index) if plane_image: plane_plotter.figures_2d( plane_image=True, title_suffix=f" Of Plane {plane_index}", filename_suffix=f"_of_plane_{plane_index}", ) if plane_grid: plane_plotter.figures_2d( plane_grid=True, title_suffix=f" Of Plane {plane_index}", filename_suffix=f"_of_plane_{plane_index}", ) 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_tracer(self): """ Standard subplot of the attributes of the plotter's `Tracer` object. """ return self.subplot( image=True, source_plane=True, convergence=True, potential=True, deflections_y=True, deflections_x=True, ) def subplot_plane_images(self): """ Subplot of the image of every plane in its own plane. For example, for a 2 plane `Tracer`, this creates a subplot with 2 panels, one for the image-plane image and one for the source-plane (e.g. unlensed) image. If there are 3 planes, 3 panels are created, showing images at each plane. """ number_subplots = 2 * self.tracer.total_planes - 1 self.open_subplot_figure(number_subplots=number_subplots) plane_plotter = self.plane_plotter_from(plane_index=0) plane_plotter.figures_2d(image=True, title_suffix=" Of Plane 0") self.mat_plot_2d.subplot_index += 1 for plane_index in range(1, self.tracer.total_planes): plane_plotter = self.plane_plotter_from(plane_index=plane_index) plane_plotter.figures_2d(image=True, title_suffix=f" Of Plane {plane_index}") plane_plotter.figures_2d(plane_image=True, title_suffix=f" Of Plane {plane_index}") self.mat_plot_2d.output.subplot_to_figure( auto_filename=f"subplot_plane_images") self.close_subplot_figure()
class PlanePlotter(Plotter): def __init__( self, plane: Plane, grid: aa.Grid2D, mat_plot_1d: MatPlot1D = MatPlot1D(), visuals_1d: Visuals1D = Visuals1D(), include_1d: Include1D = Include1D(), mat_plot_2d: MatPlot2D = MatPlot2D(), visuals_2d: Visuals2D = Visuals2D(), include_2d: Include2D = Include2D(), ): """ Plots the attributes of `Plane` 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 ---------- plane The plane the plotter plots. grid The 2D (y,x) grid of coordinates used to evaluate the plane'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_2d=mat_plot_2d, include_2d=include_2d, visuals_2d=visuals_2d, mat_plot_1d=mat_plot_1d, include_1d=include_1d, visuals_1d=visuals_1d, ) self.plane = plane self.grid = grid self._mass_plotter = MassPlotter( mass_obj=self.plane, 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, ) def get_visuals_2d(self) -> Visuals2D: return self.get_2d.via_light_mass_obj_from( light_mass_obj=self.plane, grid=self.grid ) def figures_2d( self, image: bool = False, plane_image: bool = False, plane_grid: bool = False, convergence: bool = False, potential: bool = False, deflections_y: bool = False, deflections_x: bool = False, magnification: bool = False, contribution_map: bool = False, title_suffix: str = "", filename_suffix: str = "", ): """ Plots the individual attributes of the plotter's `Plane` object in 2D, which are computed via the plotter's 2D grid object. 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 ---------- image Whether or not to make a 2D plot (via `imshow`) of the image of plane in its image-plane (e.g. after lensing). plane_image Whether or not to make a 2D plot (via `imshow`) of the image of the plane in the soure-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. title_suffix Add a suffix to the end of the matplotlib title label. filename_suffix Add a suffix to the end of the filename the plot is saved to hard-disk using. """ if image: self.mat_plot_2d.plot_array( array=self.plane.image_2d_from(grid=self.grid), visuals_2d=self.get_visuals_2d(), auto_labels=aplt.AutoLabels( title=f"Image{title_suffix}", filename=f"image_2d{filename_suffix}" ), ) if plane_image: self.mat_plot_2d.plot_array( array=self.plane.plane_image_2d_from(grid=self.grid).array, visuals_2d=self.get_visuals_2d(), auto_labels=aplt.AutoLabels( title=f"Plane Image{title_suffix}", filename=f"plane_image{filename_suffix}", ), ) if plane_grid: self.mat_plot_2d.plot_grid( grid=self.grid, visuals_2d=self.get_visuals_2d(), auto_labels=aplt.AutoLabels( title=f"Plane Grid2D{title_suffix}", filename=f"plane_grid{filename_suffix}", ), ) 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.plane.contribution_map, visuals_2d=self.get_visuals_2d(), auto_labels=aplt.AutoLabels( title="Contribution Map", filename="contribution_map_2d" ), ) def subplot( self, image: bool = False, plane_image: bool = False, plane_grid: 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_plane", ): """ Plots the individual attributes of the plotter's `Plane` 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 `Plane` 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 plane in its image-plane (e.g. after lensing). plane_image Whether or not to include a 2D plot (via `imshow`) of the image of the plane in the soure-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, plane_image=plane_image, plane_grid=plane_grid, 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), )
class GalaxyPlotter(Plotter): def __init__( self, galaxy: Galaxy, grid: aa.Grid2D, mat_plot_1d: MatPlot1D = MatPlot1D(), visuals_1d: Visuals1D = Visuals1D(), include_1d: Include1D = Include1D(), mat_plot_2d: MatPlot2D = MatPlot2D(), visuals_2d: Visuals2D = Visuals2D(), include_2d: Include2D = Include2D(), ): """ Plots the attributes of `Galaxy` 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 ---------- galaxy The galaxy the plotter plots. grid The 2D (y,x) grid of coordinates used to evaluate the galaxy'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_2d=mat_plot_2d, include_2d=include_2d, visuals_2d=visuals_2d, mat_plot_1d=mat_plot_1d, include_1d=include_1d, visuals_1d=visuals_1d, ) self.galaxy = galaxy self.grid = grid self._mass_plotter = MassPlotter( mass_obj=self.galaxy, 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, ) def get_visuals_1d_light(self) -> Visuals1D: return self.get_1d.via_light_obj_from(light_obj=self.galaxy) def get_visuals_1d_mass(self) -> Visuals1D: return self.get_1d.via_mass_obj_from(mass_obj=self.galaxy, grid=self.grid) def get_visuals_2d(self) -> Visuals2D: return self.get_2d.via_light_mass_obj_from( light_mass_obj=self.galaxy, grid=self.grid ) def light_profile_plotter_from( self, light_profile: LightProfile ) -> LightProfilePlotter: """ Returns a `LightProfilePlotter` given an input light profile, which is typically used for plotting the individual light profiles of the plotter's `Galaxy` (e.g. in the function `figures_1d_decomposed`). Parameters ---------- light_profile The light profile which is used to create the `LightProfilePlotter`. Returns ------- LightProfilePlotter An object that plots the light profiles, often used for plotting attributes of the galaxy. """ return LightProfilePlotter( light_profile=light_profile, grid=self.grid, mat_plot_2d=self.mat_plot_2d, visuals_2d=self.get_2d.via_light_obj_from( light_obj=light_profile, grid=self.grid ), include_2d=self.include_2d, mat_plot_1d=self.mat_plot_1d, visuals_1d=self.get_1d.via_light_obj_from(light_obj=light_profile), include_1d=self.include_1d, ) def mass_profile_plotter_from( self, mass_profile: MassProfile ) -> MassProfilePlotter: """ Returns a `MassProfilePlotter` given an input mass profile, which is typically used for plotting the individual mass profiles of the plotter's `Galaxy` (e.g. in the function `figures_1d_decomposed`). Parameters ---------- mass_profile The mass profile which is used to create the `MassProfilePlotter`. Returns ------- MassProfilePlotter An object that plots the mass profiles, often used for plotting attributes of the galaxy. """ return MassProfilePlotter( mass_profile=mass_profile, grid=self.grid, mat_plot_2d=self.mat_plot_2d, visuals_2d=self.get_2d.via_mass_obj_from( mass_obj=mass_profile, grid=self.grid ), include_2d=self.include_2d, mat_plot_1d=self.mat_plot_1d, visuals_1d=self.get_1d.via_mass_obj_from( mass_obj=mass_profile, grid=self.grid ), include_1d=self.include_1d, ) def figures_1d( self, image: bool = False, convergence: bool = False, potential: bool = False ): """ Plots the individual attributes of the plotter's `Galaxy` object in 1D, which are computed via the plotter's grid object. If the plotter has a 1D grid object this is used to evaluate each quantity. If it has a 2D grid, a 1D grid is computed from each light profile of the galaxy. This is performed by aligning a 1D grid with the major-axis of each light profile in projection, uniformly computing 1D values based on the 2D grid's size and pixel-scale. This means that the summed 1D profile of a galaxy's quantity is the sum of each individual component aligned with the major-axis. The API is such that every plottable attribute of the `Galaxy` 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 1D plot (via `plot`) of the image. convergence Whether or not to make a 1D plot (via `imshow`) of the convergence. potential Whether or not to make a 1D plot (via `imshow`) of the potential. """ if self.mat_plot_1d.yx_plot.plot_axis_type is None: plot_axis_type_override = "semilogy" else: plot_axis_type_override = None if image: image_1d = self.galaxy.image_1d_from(grid=self.grid) self.mat_plot_1d.plot_yx( y=image_1d, x=image_1d.grid_radial, visuals_1d=self.get_visuals_1d_light(), auto_labels=aplt.AutoLabels( title="Image vs Radius", ylabel="Image ", xlabel="Radius", legend=self.galaxy.__class__.__name__, filename="image_1d", ), plot_axis_type_override=plot_axis_type_override, ) if convergence: convergence_1d = self.galaxy.convergence_1d_from(grid=self.grid) self.mat_plot_1d.plot_yx( y=convergence_1d, x=convergence_1d.grid_radial, visuals_1d=self.get_visuals_1d_mass(), auto_labels=aplt.AutoLabels( title="Convergence vs Radius", ylabel="Convergence ", xlabel="Radius", legend=self.galaxy.__class__.__name__, filename="convergence_1d", ), plot_axis_type_override=plot_axis_type_override, ) if potential: potential_1d = self.galaxy.potential_1d_from(grid=self.grid) self.mat_plot_1d.plot_yx( y=potential_1d, x=potential_1d.grid_radial, visuals_1d=self.get_visuals_1d_mass(), auto_labels=aplt.AutoLabels( title="Potential vs Radius", ylabel="Potential ", xlabel="Radius", legend=self.galaxy.__class__.__name__, filename="potential_1d", ), plot_axis_type_override=plot_axis_type_override, ) def figures_1d_decomposed( self, image: bool = False, convergence: bool = False, potential: bool = False, legend_labels: List[str] = None, ): """ Plots the individual attributes of the plotter's `Galaxy` object in 1D, which are computed via the plotter's grid object. This function makes a decomposed plot shows the 1D plot of the attribute for every light or mass profile in the galaxy, as well as their combined 1D plot. If the plotter has a 1D grid object this is used to evaluate each quantity. If it has a 2D grid, a 1D grid is computed from each light profile of the galaxy. This is performed by aligning a 1D grid with the major-axis of each light profile in projection, uniformly computing 1D values based on the 2D grid's size and pixel-scale. This means that the summed 1D profile of a galaxy's quantity is the sum of each individual component aligned with the major-axis. The API is such that every plottable attribute of the `Galaxy` 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 1D plot (via `plot`) of the image. convergence Whether or not to make a 1D plot (via `imshow`) of the convergence. potential Whether or not to make a 1D plot (via `imshow`) of the potential. legend_labels Manually overrides the labels of the plot's legend. """ plotter_list = [self] for i, light_profile in enumerate(self.galaxy.light_profile_list): light_profile_plotter = self.light_profile_plotter_from( light_profile=light_profile ) plotter_list.append(light_profile_plotter) multi_plotter = aplt.MultiYX1DPlotter( plotter_list=plotter_list, legend_labels=legend_labels ) if image: change_filename = False if multi_plotter.plotter_list[0].mat_plot_1d.output.filename is None: multi_plotter.plotter_list[0].set_filename( filename="image_1d_decomposed" ) change_filename = True multi_plotter.figure_1d(func_name="figures_1d", figure_name="image") if change_filename: multi_plotter.plotter_list[0].set_filename(filename=None) plotter_list = [self] + [ self.mass_profile_plotter_from(mass_profile=mass_profile) for mass_profile in self.galaxy.mass_profile_list ] multi_plotter = aplt.MultiYX1DPlotter( plotter_list=plotter_list, legend_labels=legend_labels ) if convergence: change_filename = False if multi_plotter.plotter_list[0].mat_plot_1d.output.filename is None: multi_plotter.plotter_list[0].set_filename( filename="convergence_1d_decomposed" ) change_filename = True multi_plotter.figure_1d(func_name="figures_1d", figure_name="convergence") if change_filename: multi_plotter.plotter_list[0].set_filename(filename=None) if potential: change_filename = False if multi_plotter.plotter_list[0].mat_plot_1d.output.filename is None: multi_plotter.plotter_list[0].set_filename( filename="potential_1d_decomposed" ) change_filename = True multi_plotter.figure_1d(func_name="figures_1d", figure_name="potential") if change_filename: multi_plotter.plotter_list[0].set_filename(filename=None) def figures_2d( self, image: 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 `Galaxy` object in 2D, which are computed via the plotter's 2D grid object. The API is such that every plottable attribute of the `Galaxy` 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. 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.galaxy.image_2d_from(grid=self.grid), visuals_2d=self.get_visuals_2d(), auto_labels=aplt.AutoLabels(title="Image", filename="image_2d"), ) 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.galaxy.contribution_map, visuals_2d=self.get_visuals_2d(), auto_labels=aplt.AutoLabels( title="Contribution Map", filename="contribution_map_2d" ), ) def subplot_of_light_profiles(self, image: bool = False): light_profile_plotters = [ self.light_profile_plotter_from(light_profile) for light_profile in self.galaxy.light_profile_list ] if image: self.subplot_of_plotters_figure( plotter_list=light_profile_plotters, name="image" ) def subplot_of_mass_profile_list( self, convergence: bool = False, potential: bool = False, deflections_y: bool = False, deflections_x: bool = False, ): mass_profile_plotters = [ self.mass_profile_plotter_from(mass_profile) for mass_profile in self.galaxy.mass_profile_list ] if convergence: self.subplot_of_plotters_figure( plotter_list=mass_profile_plotters, name="convergence" ) if potential: self.subplot_of_plotters_figure( plotter_list=mass_profile_plotters, name="potential" ) if deflections_y: self.subplot_of_plotters_figure( plotter_list=mass_profile_plotters, name="deflections_y" ) if deflections_x: self.subplot_of_plotters_figure( plotter_list=mass_profile_plotters, name="deflections_x" )