def test__2d__via_light_obj_from(lp_0, grid_2d_7x7): visuals_2d = aplt.Visuals2D(vectors=2) include_2d = aplt.Include2D(origin=True, mask=True, border=True, light_profile_centres=True) get_visuals = GetVisuals2D(include=include_2d, visuals=visuals_2d) visuals_2d_via = get_visuals.via_light_obj_from(light_obj=lp_0, grid=grid_2d_7x7) assert visuals_2d_via.origin.in_list == [(0.0, 0.0)] assert (visuals_2d_via.mask == grid_2d_7x7.mask).all() assert (visuals_2d_via.border == grid_2d_7x7.mask.border_grid_sub_1.binned ).all() assert visuals_2d_via.light_profile_centres.in_list == [lp_0.centre] assert visuals_2d_via.vectors == 2 include_2d = aplt.Include2D(origin=False, mask=False, border=False, light_profile_centres=False) get_visuals = GetVisuals2D(include=include_2d, visuals=visuals_2d) visuals_2d_via = get_visuals.via_light_obj_from(light_obj=lp_0, grid=grid_2d_7x7) assert visuals_2d_via.origin is None assert visuals_2d_via.mask is None assert visuals_2d_via.border is None assert visuals_2d_via.light_profile_centres is None assert visuals_2d_via.vectors == 2
def test__2d__via_light_mass_obj(gal_x1_lp_x1_mp, grid_2d_7x7): visuals_2d = aplt.Visuals2D(vectors=2) include_2d = aplt.Include2D( origin=True, mask=True, border=True, light_profile_centres=True, mass_profile_centres=True, critical_curves=True, ) get_visuals = GetVisuals2D(include=include_2d, visuals=visuals_2d) visuals_2d_via = get_visuals.via_light_mass_obj_from( light_mass_obj=gal_x1_lp_x1_mp, grid=grid_2d_7x7) assert visuals_2d_via.origin.in_list == [(0.0, 0.0)] assert (visuals_2d_via.mask == grid_2d_7x7.mask).all() assert (visuals_2d_via.border == grid_2d_7x7.mask.border_grid_sub_1.binned ).all() assert visuals_2d_via.light_profile_centres.in_list == [ gal_x1_lp_x1_mp.light_profile_0.centre ] assert visuals_2d_via.mass_profile_centres.in_list == [ gal_x1_lp_x1_mp.mass_profile_0.centre ] assert (visuals_2d_via.critical_curves[0] == gal_x1_lp_x1_mp.critical_curves_from(grid=grid_2d_7x7)[0]).all() assert visuals_2d_via.vectors == 2 include_2d = aplt.Include2D( origin=False, mask=False, border=False, light_profile_centres=False, mass_profile_centres=False, critical_curves=False, ) get_visuals = GetVisuals2D(include=include_2d, visuals=visuals_2d) visuals_2d_via = get_visuals.via_light_mass_obj_from( light_mass_obj=gal_x1_lp_x1_mp, grid=grid_2d_7x7) assert visuals_2d_via.origin is None assert visuals_2d_via.mask is None assert visuals_2d_via.border is None assert visuals_2d_via.light_profile_centres is None assert visuals_2d_via.mass_profile_centres is None assert visuals_2d_via.critical_curves is None assert visuals_2d_via.vectors == 2
def test__via_fit_imaging_from(fit_imaging_x2_galaxy_7x7, grid_2d_7x7): visuals_2d = aplt.Visuals2D(origin=(1.0, 1.0), vectors=2) include_2d = aplt.Include2D( origin=True, mask=True, border=True, light_profile_centres=True, mass_profile_centres=True, critical_curves=True, ) get_visuals = GetVisuals2D(include=include_2d, visuals=visuals_2d) visuals_2d_via = get_visuals.via_fit_imaging_from( fit=fit_imaging_x2_galaxy_7x7) assert visuals_2d_via.origin == (1.0, 1.0) assert (visuals_2d_via.mask == fit_imaging_x2_galaxy_7x7.mask).all() assert (visuals_2d_via.border == fit_imaging_x2_galaxy_7x7.mask.border_grid_sub_1.binned).all() assert visuals_2d_via.light_profile_centres.in_list == [(0.0, 0.0), (0.0, 0.0)] assert visuals_2d_via.mass_profile_centres.in_list == [(0.0, 0.0)] assert (visuals_2d_via.critical_curves[0] == fit_imaging_x2_galaxy_7x7. plane.critical_curves_from(grid=grid_2d_7x7)[0]).all() assert visuals_2d_via.vectors == 2 include_2d = aplt.Include2D( origin=False, mask=False, border=False, light_profile_centres=False, mass_profile_centres=False, critical_curves=False, ) get_visuals = GetVisuals2D(include=include_2d, visuals=visuals_2d) visuals_2d_via = get_visuals.via_fit_imaging_from( fit=fit_imaging_x2_galaxy_7x7) assert visuals_2d_via.origin == (1.0, 1.0) assert visuals_2d_via.mask is None assert visuals_2d_via.border is None assert visuals_2d_via.light_profile_centres is None assert visuals_2d_via.mass_profile_centres is None assert visuals_2d_via.critical_curves is None assert visuals_2d_via.vectors == 2
def test__visuals_with_include_2d(gal_x1_lp_x1_mp, grid_2d_7x7): visuals_2d = aplt.Visuals2D(vector_field=2) include = aplt.Include2D( origin=True, mask=True, border=True, light_profile_centres=True, mass_profile_centres=True, critical_curves=True, caustics=True, ) galaxy_plotter = aplt.GalaxyPlotter( galaxy=gal_x1_lp_x1_mp, grid=grid_2d_7x7, visuals_2d=visuals_2d, include_2d=include, ) assert galaxy_plotter.visuals_with_include_2d.origin.in_list == [(0.0, 0.0) ] assert ( galaxy_plotter.visuals_with_include_2d.mask == grid_2d_7x7.mask).all() assert (galaxy_plotter.visuals_with_include_2d.border == grid_2d_7x7.mask.border_grid_sub_1.binned).all() assert galaxy_plotter.visuals_with_include_2d.light_profile_centres.in_list == [ gal_x1_lp_x1_mp.light_profile_0.centre ] assert galaxy_plotter.visuals_with_include_2d.mass_profile_centres.in_list == [ gal_x1_lp_x1_mp.mass_profile_0.centre ] assert galaxy_plotter.visuals_with_include_2d.vector_field == 2 include = aplt.Include2D(origin=False, mask=False, border=False) galaxy_plotter = aplt.GalaxyPlotter( galaxy=gal_x1_lp_x1_mp, grid=grid_2d_7x7, visuals_2d=visuals_2d, include_2d=include, ) assert galaxy_plotter.visuals_with_include_2d.origin == None assert galaxy_plotter.visuals_with_include_2d.mask == None assert galaxy_plotter.visuals_with_include_2d.border == None assert galaxy_plotter.visuals_with_include_2d.vector_field == 2
def __init__( self, fit: FitImaging, mat_plot_2d: aplt.MatPlot2D = aplt.MatPlot2D(), visuals_2d: aplt.Visuals2D = aplt.Visuals2D(), include_2d: aplt.Include2D = aplt.Include2D(), ): """ Plots the attributes of `FitImaging` objects using the matplotlib method `imshow()` and many other matplotlib functions which customize the plot's appearance. The `mat_plot_2d` attribute wraps matplotlib function calls to make the figure. By default, the settings passed to every matplotlib function called are those specified in the `config/visualize/mat_wrap/*.ini` files, but a user can manually input values into `MatPlot2d` to customize the figure's appearance. Overlaid on the figure are visuals, contained in the `Visuals2D` object. Attributes may be extracted from the `FitImaging` and plotted via the visuals object, if the corresponding entry is `True` in the `Include2D` object or the `config/visualize/include.ini` file. Parameters ---------- fit The fit to an imaging dataset the plotter plots. mat_plot_2d Contains objects which wrap the matplotlib function calls that make the plot. visuals_2d Contains visuals that can be overlaid on the plot. include_2d Specifies which attributes of the `Array2D` are extracted and plotted as visuals. """ super().__init__(mat_plot_2d=mat_plot_2d, include_2d=include_2d, visuals_2d=visuals_2d) self.fit = fit self._fit_imaging_meta_plotter = FitImagingPlotterMeta( fit=self.fit, get_visuals_2d=self.get_visuals_2d, mat_plot_2d=self.mat_plot_2d, include_2d=self.include_2d, visuals_2d=self.visuals_2d, ) self.figures_2d = self._fit_imaging_meta_plotter.figures_2d self.subplot = self._fit_imaging_meta_plotter.subplot self.subplot_fit_imaging = self._fit_imaging_meta_plotter.subplot_fit_imaging
def __init__( self, subhalo_result: SubhaloResult, fit_imaging_detect, use_log_evidences: bool = True, use_stochastic_log_likelihoods: bool = False, mat_plot_2d: aplt.MatPlot2D = aplt.MatPlot2D(), visuals_2d: aplt.Visuals2D = aplt.Visuals2D(), include_2d: aplt.Include2D = aplt.Include2D(), ): super().__init__(mat_plot_2d=mat_plot_2d, include_2d=include_2d, visuals_2d=visuals_2d) self.subhalo_result = subhalo_result self.fit_imaging_detect = fit_imaging_detect self.use_log_evidences = use_log_evidences self.use_stochastic_log_likelihoods = use_stochastic_log_likelihoods
def __init__( self, fit: FitPointDataset, mat_plot_1d: aplt.MatPlot1D = aplt.MatPlot1D(), visuals_1d: aplt.Visuals1D = aplt.Visuals1D(), include_1d: aplt.Include1D = aplt.Include1D(), mat_plot_2d: aplt.MatPlot2D = aplt.MatPlot2D(), visuals_2d: aplt.Visuals2D = aplt.Visuals2D(), include_2d: aplt.Include2D = aplt.Include2D(), ): super().__init__( mat_plot_1d=mat_plot_1d, visuals_1d=visuals_1d, include_1d=include_1d, mat_plot_2d=mat_plot_2d, include_2d=include_2d, visuals_2d=visuals_2d, ) self.fit = fit
def __init__( self, point_dict: PointDict, mat_plot_1d: aplt.MatPlot1D = aplt.MatPlot1D(), visuals_1d: aplt.Visuals1D = aplt.Visuals1D(), include_1d: aplt.Include1D = aplt.Include1D(), mat_plot_2d: aplt.MatPlot2D = aplt.MatPlot2D(), visuals_2d: aplt.Visuals2D = aplt.Visuals2D(), include_2d: aplt.Include2D = aplt.Include2D(), ): super().__init__( mat_plot_1d=mat_plot_1d, visuals_1d=visuals_1d, include_1d=include_1d, mat_plot_2d=mat_plot_2d, include_2d=include_2d, visuals_2d=visuals_2d, ) self.point_dict = point_dict
def test__visuals_with_include_2d(lp_0, grid_2d_7x7): visuals_2d = aplt.Visuals2D(vector_field=2) include = aplt.Include2D( origin=True, mask=True, border=True, light_profile_centres=True, critical_curves=True, caustics=True, ) light_profile_plotter = aplt.LightProfilePlotter( light_profile=lp_0, grid=grid_2d_7x7, visuals_2d=visuals_2d, include_2d=include ) assert light_profile_plotter.visuals_with_include_2d.origin.in_list == [(0.0, 0.0)] assert ( light_profile_plotter.visuals_with_include_2d.mask == grid_2d_7x7.mask ).all() assert ( light_profile_plotter.visuals_with_include_2d.border == grid_2d_7x7.mask.border_grid_sub_1.binned ).all() assert ( light_profile_plotter.visuals_with_include_2d.light_profile_centres.in_list == [lp_0.centre] ) assert light_profile_plotter.visuals_with_include_2d.vector_field == 2 include = aplt.Include2D(origin=False, mask=False, border=False) light_profile_plotter = aplt.LightProfilePlotter( light_profile=lp_0, grid=grid_2d_7x7, visuals_2d=visuals_2d, include_2d=include ) assert light_profile_plotter.visuals_with_include_2d.origin == None assert light_profile_plotter.visuals_with_include_2d.mask == None assert light_profile_plotter.visuals_with_include_2d.border == None assert light_profile_plotter.visuals_with_include_2d.vector_field == 2
def visualize_image_with_positions( self, image: aa.Array2D, positions: aa.Grid2DIrregular ): """ Visualizes the positions of a model-fit, where these positions are used to resample lens models where the positions to do trace within an input threshold of one another in the source-plane. Images are output to the `image` folder of the `visualize_path` in a subfolder called `positions`. When used with a non-linear search the `visualize_path` points to the search's results folder. The visualization is an image of the strong lens with the positions overlaid. The images output by the `Visualizer` are customized using the file `config/visualize/plots.ini` under the [ray_tracing] header. Parameters ---------- imaging The imaging dataset whose image the positions are overlaid. position The 2D (y,x) arc-second positions used to resample inaccurate mass models. """ def should_plot(name): return plot_setting(section=["positions"], name=name) mat_plot_2d = self.mat_plot_2d_from(subfolders="positions") if positions is not None: visuals_2d = aplt.Visuals2D(positions=positions) image_plotter = aplt.Array2DPlotter( array=image, mat_plot_2d=mat_plot_2d, include_2d=self.include_2d, visuals_2d=visuals_2d, ) image_plotter.set_filename("image_with_positions") if should_plot("image_with_positions"): image_plotter.figure_2d()
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, )