def test__fit_sub_plot_real_space( fit_interferometer_x2_plane_7x7, fit_interferometer_x2_plane_inversion_7x7, include_2d_all, plot_path, plot_patch, ): fit_interferometer_plotter = aplt.FitInterferometerPlotter( fit=fit_interferometer_x2_plane_7x7, include_2d=include_2d_all, mat_plot_1d=aplt.MatPlot1D(output=aplt.Output(plot_path, format="png")), mat_plot_2d=aplt.MatPlot2D(output=aplt.Output(plot_path, format="png")), ) fit_interferometer_plotter.subplot_fit_real_space() assert path.join(plot_path, "subplot_fit_real_space.png") in plot_patch.paths plot_patch.paths = [] fit_interferometer_plotter = aplt.FitInterferometerPlotter( fit=fit_interferometer_x2_plane_inversion_7x7, include_2d=include_2d_all, mat_plot_1d=aplt.MatPlot1D(output=aplt.Output(plot_path, format="png")), mat_plot_2d=aplt.MatPlot2D(output=aplt.Output(plot_path, format="png")), ) fit_interferometer_plotter.subplot_fit_real_space() assert path.join(plot_path, "subplot_fit_real_space.png") in plot_patch.paths
def test__subplot_fit_point(fit_point_dataset_x2_plane, include_2d_all, plot_path, plot_patch): fit_point_plotter = aplt.FitPointDatasetPlotter( fit=fit_point_dataset_x2_plane, include_2d=include_2d_all, 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_point_plotter.subplot_fit_point() assert path.join(plot_path, "subplot_fit_point.png") in plot_patch.paths
def test__subplot_point_dataset(point_dataset, include_2d_all, plot_path, plot_patch): point_dataset_plotter = aplt.PointDatasetPlotter( point_dataset=point_dataset, include_2d=include_2d_all, 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")), ) point_dataset_plotter.subplot_point_dataset() assert path.join(plot_path, "subplot_point_dataset.png") in plot_patch.paths
def test__fit_point_quantities_are_output(fit_point_dataset_x2_plane, include_2d_all, plot_path, plot_patch): fit_point_plotter = aplt.FitPointDatasetPlotter( fit=fit_point_dataset_x2_plane, include_2d=include_2d_all, 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_point_plotter.figures_2d(positions=True, fluxes=True) assert path.join(plot_path, "fit_point_dataset_positions.png") in plot_patch.paths assert path.join(plot_path, "fit_point_dataset_fluxes.png") in plot_patch.paths plot_patch.paths = [] fit_point_plotter.figures_2d(positions=True, fluxes=False) assert path.join(plot_path, "fit_point_dataset_positions.png") in plot_patch.paths assert path.join(plot_path, "fit_point_dataset_fluxes.png") not in plot_patch.paths plot_patch.paths = [] fit_point_dataset_x2_plane.point_dataset.fluxes = None fit_point_plotter = aplt.FitPointDatasetPlotter( fit=fit_point_dataset_x2_plane, include_2d=include_2d_all, mat_plot_2d=aplt.MatPlot2D( output=aplt.Output(path=plot_path, format="png")), ) fit_point_plotter.figures_2d(positions=True, fluxes=True) assert path.join(plot_path, "fit_point_dataset_positions.png") in plot_patch.paths assert path.join(plot_path, "fit_point_dataset_fluxes.png") not in plot_patch.paths
def test__subplot_point_dict(point_dict, include_2d_all, plot_path, plot_patch): point_dict_plotter = aplt.PointDictPlotter( point_dict=point_dict, include_2d=include_2d_all, 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")), ) point_dict_plotter.subplot_positions() assert path.join(plot_path, "subplot_point_dict_positions.png") in plot_patch.paths point_dict_plotter.subplot_fluxes() assert path.join(plot_path, "subplot_point_dict_fluxes.png") in plot_patch.paths
yx_plotter = aplt.YX1DPlotter(y=y, x=x) yx_plotter.figure_1d() """ We can fill between two lines line on the y vs x plot using the `FillBetween` matplotlib wrapper object which wraps the following method(s): plt.fill_between: https://matplotlib.org/3.3.2/api/_as_gen/matplotlib.pyplot.fill_between.html The input`match_color_to_yx=True` ensures the filled area is the same as the line that is plotted, as opposed to a different color. This ensures that shaded regions can easily be paired in color to the plot when it is appropriate (e.g. plotted the errors of the line). """ y1 = al.Array1D.manual_native(array=[0.5, 1.5, 2.5, 3.5, 4.5], pixel_scales=1.0) y2 = al.Array1D.manual_native(array=[1.5, 2.5, 3.5, 4.5, 5.5], pixel_scales=1.0) mat_plot_1d = aplt.MatPlot1D( fill_between=aplt.FillBetween(match_color_to_yx=True, alpha=0.3)) visuals_1d = aplt.Visuals1D(shaded_region=[y1, y2]) yx_plotter = aplt.YX1DPlotter(y=y, x=x, mat_plot_1d=mat_plot_1d, visuals_1d=visuals_1d) yx_plotter.figure_1d() """ Finish. """
value=grid.pixel_scale), fluxes=fluxes_1, fluxes_noise_map=al.ValuesIrregular(values=[1.0, 1.0, 1.0, 1.0]), ) point_dict = al.PointDict( point_dataset_list=[point_dataset_0, point_dataset_1]) point_dict.output_to_json(file_path=path.join(dataset_path, "point_dict.json"), overwrite=True) """ __Visualize__ Output a subplot of the simulated point source dictionary and the tracer's quantities to the dataset path as .png files. """ mat_plot_1d = aplt.MatPlot1D( output=aplt.Output(path=dataset_path, format="png")) mat_plot_2d = aplt.MatPlot2D( output=aplt.Output(path=dataset_path, format="png")) point_dict_plotter = aplt.PointDictPlotter(point_dict=point_dict, mat_plot_1d=mat_plot_1d, mat_plot_2d=mat_plot_2d) point_dict_plotter.subplot_positions() point_dict_plotter.subplot_fluxes() tracer_plotter = aplt.TracerPlotter(tracer=tracer, grid=grid, mat_plot_2d=mat_plot_2d) tracer_plotter.subplot_tracer() tracer_plotter.subplot_plane_images() """
def test__fit_quantities_are_output( fit_interferometer_x2_plane_7x7, plot_path, plot_patch ): fit_interferometer_plotter = aplt.FitInterferometerPlotter( fit=fit_interferometer_x2_plane_7x7, 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, image=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_residual_map_vs_uv_distances.png") in plot_patch.paths ) assert ( path.join(plot_path, "imag_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, "image_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, "real_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_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, "imag_chi_squared_map_vs_uv_distances.png") in plot_patch.paths )
mass_1 = al.mp.EllPowerLaw( centre=(0.0, 0.0), einstein_radius=1.0, elliptical_comps=al.convert.elliptical_comps_from(axis_ratio=0.7, angle=45.0), slope=2.1, ) """ We also need the 2D grid the `MassProfile`'s are evaluated on. """ grid = al.Grid2D.uniform(shape_native=(100, 100), pixel_scales=0.05) """ We now pass the mass profiles and grid to a `MassProfilePlotter` and create a `MultiYX1DPlotter` which will be used to plot both of their convergences in 1D on the same figure. """ mat_plot_1d = aplt.MatPlot1D(yx_plot=aplt.YXPlot(plot_axis_type="semilogy")) mass_profile_plotter_0 = aplt.MassProfilePlotter(mass_profile=mass_0, grid=grid, mat_plot_1d=mat_plot_1d) mass_profile_plotter_1 = aplt.MassProfilePlotter(mass_profile=mass_1, grid=grid, mat_plot_1d=mat_plot_1d) """ We use these plotters to create a `MultiYX1DPlotter` which plot both of their convergences in 1D on the same figure. """ multi_plotter = aplt.MultiYX1DPlotter( plotter_list=[mass_profile_plotter_0, mass_profile_plotter_1]) """ We now use the multi plotter to plot the convergences, where:
mass_profile_plotter = aplt.MassProfilePlotter(mass_profile=mass, grid=grid, include_1d=include_1d) mass_profile_plotter.figures_1d(convergence=True) """ The appearance of the einstein radius is customized using a `EinsteinRadiusAXVLine` object. To plot the einstein radius as a vertical line this wraps the following matplotlib method: plt.axvline: https://matplotlib.org/3.3.2/api/_as_gen/matplotlib.pyplot.axvline.html """ einstein_radius_axvline = aplt.EinsteinRadiusAXVLine(linestyle="-.", c="r", linewidth=20) mat_plot_1d = aplt.MatPlot1D(einstein_radius_axvline=einstein_radius_axvline) mass_profile_plotter = aplt.MassProfilePlotter(mass_profile=mass, grid=grid, mat_plot_1d=mat_plot_1d, include_1d=include_1d) mass_profile_plotter.figures_1d(convergence=True) """ To plot the einstein radius manually, we can pass it into a` Visuals1D` object. """ visuals_1d = aplt.Visuals1D(einstein_radius=mass.einstein_radius_from_grid( grid=grid)) mass_profile_plotter = aplt.MassProfilePlotter(mass_profile=mass, grid=grid, visuals_1d=visuals_1d)
light_profile=bulge, grid=grid, include_1d=include_1d ) light_profile_plotter.figures_1d(image=True) """ The appearance of the half-light radius is customized using a `HalfLightRadiusAXVLine` object. To plot the half-light radius as a vertical line this wraps the following matplotlib method: plt.axvline: https://matplotlib.org/3.3.2/api/_as_gen/matplotlib.pyplot.axvline.html """ half_light_radius_axvline = aplt.HalfLightRadiusAXVLine( linestyle="-.", c="r", linewidth=20 ) mat_plot_1d = aplt.MatPlot1D(half_light_radius_axvline=half_light_radius_axvline) light_profile_plotter = aplt.LightProfilePlotter( light_profile=bulge, grid=grid, mat_plot_1d=mat_plot_1d, include_1d=include_1d ) light_profile_plotter.figures_1d(image=True) """ To plot the half-light radius manually, we can pass it into a` Visuals1D` object. """ visuals_1d = aplt.Visuals1D(half_light_radius=bulge.half_light_radius) light_profile_plotter = aplt.LightProfilePlotter( light_profile=bulge, grid=grid, visuals_1d=visuals_1d ) light_profile_plotter.figures_1d(image=True)