Exemplo n.º 1
0
    def test__visualize_fit_interferometer__uses_configs(
        self,
        masked_interferometer_7,
        masked_interferometer_fit_x2_plane_inversion_7x7,
        include_2d_all,
        plot_path,
        plot_patch,
    ):
        visualizer = vis.Visualizer(visualize_path=plot_path)

        visualizer.visualize_fit_interferometer(
            fit=masked_interferometer_fit_x2_plane_inversion_7x7,
            during_analysis=True)

        plot_path = path.join(plot_path, "fit_interferometer")

        assert (path.join(plot_path, "subplot_fit_interferometer.png")
                in plot_patch.paths)
        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")
                in plot_patch.paths)
        assert (path.join(plot_path,
                          "real_chi_squared_map_vs_uv_distances.png")
                in plot_patch.paths)
Exemplo n.º 2
0
    def save_stochastic_outputs(self, paths: af.Paths,
                                samples: af.OptimizerSamples):

        stochastic_log_evidences_json_file = path.join(
            paths.output_path, "stochastic_log_evidences.json")
        stochastic_log_evidences_pickle_file = path.join(
            paths.pickle_path, "stochastic_log_evidences.pickle")

        try:
            with open(stochastic_log_evidences_json_file, "r") as f:
                stochastic_log_evidences = np.asarray(json.load(f))
        except FileNotFoundError:
            instance = samples.max_log_likelihood_instance
            stochastic_log_evidences = self.stochastic_log_evidences_for_instance(
                instance=instance)

        if stochastic_log_evidences is None:
            return

        with open(stochastic_log_evidences_json_file, "w") as outfile:
            json.dump(
                [float(evidence) for evidence in stochastic_log_evidences],
                outfile)

        with open(stochastic_log_evidences_pickle_file, "wb") as f:
            pickle.dump(stochastic_log_evidences, f)

        visualizer = vis.Visualizer(visualize_path=paths.image_path)

        visualizer.visualize_stochastic_histogram(
            log_evidences=stochastic_log_evidences,
            max_log_evidence=np.max(samples.log_likelihoods),
            histogram_bins=self.settings.settings_lens.
            stochastic_histogram_bins,
        )
Exemplo n.º 3
0
    def test__visualize_stochastic_histogram(self, masked_imaging_7x7,
                                             plot_path, plot_patch):

        visualizer = vis.Visualizer(visualize_path=plot_path)

        visualizer.visualize_stochastic_histogram(
            log_evidences=[1.0, 2.0, 1.0, 2.0, 3.0, 2.5], max_log_evidence=3.0)
        assert (path.join(plot_path, "other", "stochastic_histogram.png")
                in plot_patch.paths)
Exemplo n.º 4
0
    def test__visualizes_fit_imaging__uses_configs(
        self,
        masked_imaging_7x7,
        masked_imaging_fit_x2_plane_inversion_7x7,
        include_2d_all,
        plot_path,
        plot_patch,
    ):

        if os.path.exists(plot_path):
            shutil.rmtree(plot_path)

        visualizer = vis.Visualizer(visualize_path=plot_path)

        visualizer.visualize_fit_imaging(
            fit=masked_imaging_fit_x2_plane_inversion_7x7,
            during_analysis=False)

        plot_path = path.join(plot_path, "fit_imaging")

        assert path.join(plot_path,
                         "subplot_fit_imaging.png") in plot_patch.paths
        assert path.join(plot_path, "image.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_image.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") in plot_patch.paths
        assert path.join(plot_path, "chi_squared_map.png") in plot_patch.paths
        assert (path.join(plot_path, "subtracted_image_of_plane_0.png")
                in plot_patch.paths)
        assert (path.join(plot_path, "subtracted_image_of_plane_1.png")
                in plot_patch.paths)
        assert (path.join(plot_path, "model_image_of_plane_0.png")
                not in plot_patch.paths)
        assert (path.join(plot_path, "model_image_of_plane_1.png")
                not in plot_patch.paths)
        assert path.join(plot_path,
                         "plane_image_of_plane_0.png") in plot_patch.paths
        assert path.join(plot_path, "reconstruction.png") in plot_patch.paths

        image = al.util.array.numpy_array_2d_from_fits(file_path=path.join(
            plot_path, "fits", "image.fits"),
                                                       hdu=0)

        assert image.shape == (5, 5)
Exemplo n.º 5
0
    def visualize(self, paths: af.Paths, instance, during_analysis):

        instance = self.associate_hyper_images(instance=instance)
        tracer = self.tracer_for_instance(instance=instance)
        hyper_image_sky = self.hyper_image_sky_for_instance(instance=instance)
        hyper_background_noise = self.hyper_background_noise_for_instance(
            instance=instance
        )

        fit = self.masked_imaging_fit_for_tracer(
            tracer=tracer,
            hyper_image_sky=hyper_image_sky,
            hyper_background_noise=hyper_background_noise,
        )

        visualizer = vis.Visualizer(visualize_path=paths.image_path)

        visualizer.visualize_imaging(imaging=self.masked_imaging.imaging)
        visualizer.visualize_fit_imaging(fit=fit, during_analysis=during_analysis)
        visualizer.visualize_tracer(
            tracer=fit.tracer, grid=fit.grid, during_analysis=during_analysis
        )
        if fit.inversion is not None:
            visualizer.visualize_inversion(
                inversion=fit.inversion, during_analysis=during_analysis
            )

        visualizer.visualize_hyper_images(
            hyper_galaxy_image_path_dict=self.hyper_galaxy_image_path_dict,
            hyper_model_image=self.hyper_model_image,
            tracer=tracer,
        )

        if visualizer.plot_fit_no_hyper:

            fit = self.masked_imaging_fit_for_tracer(
                tracer=tracer,
                hyper_image_sky=None,
                hyper_background_noise=None,
                use_hyper_scalings=False,
            )

            visualizer.visualize_fit_imaging(
                fit=fit, during_analysis=during_analysis, subfolders="fit_no_hyper"
            )
Exemplo n.º 6
0
    def test__visualizes_ray_tracing__uses_configs(
        self,
        masked_imaging_7x7,
        tracer_x2_plane_7x7,
        include_2d_all,
        plot_path,
        plot_patch,
    ):

        if os.path.exists(plot_path):
            shutil.rmtree(plot_path)

        visualizer = vis.Visualizer(visualize_path=plot_path)

        visualizer.visualize_tracer(
            tracer=tracer_x2_plane_7x7,
            grid=masked_imaging_7x7.grid,
            during_analysis=False,
        )

        plot_path = path.join(plot_path, "ray_tracing")

        assert path.join(plot_path, "subplot_tracer.png") in plot_patch.paths
        assert path.join(plot_path, "image.png") in plot_patch.paths
        assert path.join(plot_path,
                         "plane_image_of_plane_1.png") in plot_patch.paths
        assert path.join(plot_path, "convergence.png") in plot_patch.paths
        assert path.join(plot_path, "potential.png") not in plot_patch.paths
        assert path.join(plot_path,
                         "deflections_y.png") not in plot_patch.paths
        assert path.join(plot_path,
                         "deflections_x.png") not in plot_patch.paths
        assert path.join(plot_path, "magnification.png") in plot_patch.paths

        convergence = al.util.array.numpy_array_2d_from_fits(
            file_path=path.join(plot_path, "fits", "convergence.fits"), hdu=0)

        assert convergence.shape == (5, 5)
Exemplo n.º 7
0
    def visualize(self, paths, instance, during_analysis):

        tracer = self.tracer_for_instance(instance=instance)

        visualizer = vis.Visualizer(visualize_path=paths.image_path)