Exemple #1
0
    def visualize_multiple_fit_cis_subplots_1d_lines(self, fit, line_region):
        def should_plot(name):
            return plot_setting(section="fit", name=name)

        mat_plot_1d = self.mat_plot_1d_from(
            subfolders=f"multiple_fit_cis_1d_line_{line_region}"
        )

        fit_ci_plotter_list = [
            aplt.FitImagingCIPlotter(fit=fit, mat_plot_1d=mat_plot_1d) for fit in fit
        ]
        multi_plotter = MultiFigurePlotter(plotter_list=fit_ci_plotter_list)

        if should_plot("subplot_residual_maps"):
            multi_plotter.subplot_of_figure(
                func_name="figures_1d_ci_line_region",
                figure_name="residual_map",
                line_region=line_region,
            )

        if should_plot("subplot_normalized_residual_maps"):
            multi_plotter.subplot_of_figure(
                func_name="figures_1d_ci_line_region",
                figure_name="normalized_residual_map",
                line_region=line_region,
            )

        if should_plot("subplot_chi_squared_maps"):
            multi_plotter.subplot_of_figure(
                func_name="figures_1d_ci_line_region",
                figure_name="chi_squared_map",
                line_region=line_region,
            )
Exemple #2
0
def test__individual_attribute_plots__all_plot_correctly(
        fit_ci_7x7, plot_path, plot_patch):

    fit_ci_plotter = aplt.FitImagingCIPlotter(
        fit=fit_ci_7x7,
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(plot_path, format="png")),
        mat_plot_1d=aplt.MatPlot1D(
            output=aplt.Output(plot_path, format="png")),
    )

    fit_ci_plotter.figures_2d(
        image=True,
        noise_map=True,
        signal_to_noise_map=True,
        pre_cti_data=True,
        post_cti_data=True,
        residual_map=True,
        normalized_residual_map=True,
        chi_squared_map=True,
    )

    assert path.join(plot_path, "image_2d.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, "pre_cti_data.png") in plot_patch.paths
    assert path.join(plot_path, "post_cti_data.png") in plot_patch.paths
    assert path.join(plot_path, "residual_map.png") 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

    plot_patch.paths = []

    fit_ci_plotter.figures_2d(
        image=True,
        noise_map=False,
        signal_to_noise_map=False,
        pre_cti_data=True,
        post_cti_data=True,
        chi_squared_map=True,
    )

    assert path.join(plot_path, "image_2d.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, "pre_cti_data.png") in plot_patch.paths
    assert path.join(plot_path, "post_cti_data.png") in plot_patch.paths
    assert path.join(plot_path, "residual_map.png") not in plot_patch.paths
    assert path.join(plot_path, "chi_squared_map.png") in plot_patch.paths
Exemple #3
0
    def visualize_fit_in_fits(self, fit):

        mat_plot_2d = self.mat_plot_2d_from(subfolders="fit_imaging/fit", format="fit")

        fit_ci_plotter = aplt.FitImagingCIPlotter(
            fit=fit, mat_plot_2d=mat_plot_2d, include_2d=self.include_2d
        )

        fit_ci_plotter.figures_2d(
            image=True,
            noise_map=True,
            signal_to_noise_map=True,
            pre_cti_data=True,
            post_cti_data=True,
            residual_map=True,
            normalized_residual_map=True,
            chi_squared_map=True,
        )
Exemple #4
0
    def visualize_fit_ci(self, fit, during_analysis):
        def should_plot(name):
            return plot_setting(section="fit", name=name)

        mat_plot_2d = self.mat_plot_2d_from(subfolders=f"fit_imaging_ci")

        fit_ci_plotter = aplt.FitImagingCIPlotter(
            fit=fit, mat_plot_2d=mat_plot_2d, include_2d=self.include_2d
        )

        fit_ci_plotter.figures_2d(
            image=should_plot("data"),
            noise_map=should_plot("noise_map"),
            signal_to_noise_map=should_plot("signal_to_noise_map"),
            pre_cti_data=should_plot("pre_cti_data"),
            post_cti_data=should_plot("post_cti_data"),
            residual_map=should_plot("residual_map"),
            normalized_residual_map=should_plot("normalized_residual_map"),
            chi_squared_map=should_plot("chi_squared_map"),
        )

        if not during_analysis:

            if should_plot("all_at_end_png"):

                fit_ci_plotter.figures_2d(
                    image=True,
                    noise_map=True,
                    signal_to_noise_map=True,
                    pre_cti_data=True,
                    post_cti_data=True,
                    residual_map=True,
                    normalized_residual_map=True,
                    chi_squared_map=True,
                )

            if should_plot("all_at_end_fits"):

                self.visualize_fit_in_fits(fit=fit)

        if should_plot("subplot_fit"):
            fit_ci_plotter.subplot_fit_ci()
Exemple #5
0
def test__fit_ci_subplots_are_output(fit_ci_7x7, plot_path, plot_patch):

    fit_ci_plotter = aplt.FitImagingCIPlotter(
        fit=fit_ci_7x7,
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(plot_path, format="png")),
        mat_plot_1d=aplt.MatPlot1D(
            output=aplt.Output(plot_path, format="png")),
    )

    fit_ci_plotter.subplot_fit_ci()
    assert path.join(plot_path, "subplot_fit_ci.png") in plot_patch.paths

    fit_ci_plotter.subplot_1d_ci_line_region(line_region="parallel_front_edge")
    assert (path.join(plot_path, "subplot_1d_fit_ci_parallel_front_edge.png")
            in plot_patch.paths)

    fit_ci_plotter.subplot_noise_scaling_map_list()
    assert (path.join(plot_path, "subplot_noise_scaling_map_list.png")
            in plot_patch.paths)
Exemple #6
0
analysis = analysis_list[0] + analysis_list[1] + analysis_list[2] + analysis_list[3]

"""
__Model-Fit__

We can now begin the model-fit by passing the model and analysis object to the search, which performs a non-linear
search to find which models fit the data with the highest likelihood.

Checkout the folder `autocti_workspace/output/imaging_ci/parallel[x2]` for live outputs 
of the results of the fit, including on-the-fly visualization of the best fit model!
"""
result_list = search.fit(model=model, analysis=analysis)

"""
__Result__

The search returns a result object, which includes: 

 - The charge injection fit corresponding to the maximum log likelihood solution in parameter space.
"""
print(result_list[0].max_log_likelihood_instance.cti.parallel_traps[0].density)
print(result_list[0].max_log_likelihood_instance.cti.parallel_ccd.well_fill_power)

for result in result_list:

    fit_plotter = aplt.FitImagingCIPlotter(fit=result.max_log_likelihood_fit)
    fit_plotter.subplot_fit_ci()
"""
Checkout `autocti_workspace/notebooks/imaging_ci/modeling/results.py` for a full description of the result object.
"""
Exemple #7
0
    for masked_line, post_cti_data in zip(masked_line_list, post_cti_data_list)
]

"""
The fit creates the following:

 - The residual-map: The model-image subtracted from the observed dataset`s image.
 - The normalized residual-map: The residual-map divided by the noise-map.
 - The chi-squared-map: The normalized residual-map squared.

we'll plot all 3 of these, alongside a subplot containing them all.

For a good lens model where the model image and tracer are representative of the strong lens system the
residuals, normalized residuals and chi-squareds are minimized:
"""
fit_ci_plotter = aplt.FitImagingCIPlotter(fit=fit_list[0])
fit_ci_plotter.figures_2d(
    residual_map=True, normalized_residual_map=True, chi_squared_map=True
)

print(sum([fit.log_likelihood for fit in fit_list]))

"""
In contrast, a bad CTI model will show features in the residual-map and chi-squareds.

We can produce such an image by creating a CTI model with different `trap_list` and / or `CCD` volumen filling.. In the 
example below, we divide the density of each trap of by 2, which leads to residuals appearing in the fit.
"""
trap_0 = ac.TrapInstantCapture(density=0.0442 / 2.0, release_timescale=0.8)
trap_1 = ac.TrapInstantCapture(density=0.1326 / 2.0, release_timescale=4.0)
trap_2 = ac.TrapInstantCapture(density=3.9782 / 2.0, release_timescale=20.0)
Exemple #8
0
def test__individual_line_attriutes_plot__all_plot_correctly_output(
        fit_ci_7x7, plot_path, plot_patch):

    fit_ci_plotter = aplt.FitImagingCIPlotter(
        fit=fit_ci_7x7,
        mat_plot_2d=aplt.MatPlot2D(
            output=aplt.Output(plot_path, format="png")),
        mat_plot_1d=aplt.MatPlot1D(
            output=aplt.Output(plot_path, format="png")),
    )

    fit_ci_plotter.figures_1d_ci_line_region(
        line_region="parallel_front_edge",
        image=True,
        noise_map=True,
        signal_to_noise_map=True,
        pre_cti_data=True,
        post_cti_data=True,
        residual_map=True,
        normalized_residual_map=True,
        chi_squared_map=True,
    )

    assert path.join(plot_path,
                     "image_parallel_front_edge.png") in plot_patch.paths
    assert path.join(plot_path,
                     "noise_map_parallel_front_edge.png") in plot_patch.paths
    assert (path.join(plot_path, "signal_to_noise_map_parallel_front_edge.png")
            in plot_patch.paths)
    assert (path.join(plot_path, "pre_cti_data_parallel_front_edge.png")
            in plot_patch.paths)
    assert (path.join(plot_path, "post_cti_data_parallel_front_edge.png")
            in plot_patch.paths)
    assert (path.join(plot_path, "residual_map_parallel_front_edge.png")
            in plot_patch.paths)
    assert (path.join(plot_path,
                      "normalized_residual_map_parallel_front_edge.png")
            in plot_patch.paths)
    assert (path.join(plot_path, "chi_squared_map_parallel_front_edge.png")
            in plot_patch.paths)

    plot_patch.paths = []

    fit_ci_plotter.figures_1d_ci_line_region(
        line_region="parallel_front_edge",
        image=True,
        noise_map=False,
        signal_to_noise_map=False,
        pre_cti_data=True,
        post_cti_data=True,
        chi_squared_map=True,
    )

    assert path.join(plot_path,
                     "image_parallel_front_edge.png") in plot_patch.paths
    assert (path.join(plot_path, "noise_map_parallel_front_edge.png")
            not in plot_patch.paths)
    assert (path.join(plot_path, "signal_to_noise_map_parallel_front_edge.png")
            not in plot_patch.paths)
    assert (path.join(plot_path, "pre_cti_data_parallel_front_edge.png")
            in plot_patch.paths)
    assert (path.join(plot_path, "post_cti_data_parallel_front_edge.png")
            in plot_patch.paths)
    assert (path.join(plot_path, "residual_map_parallel_front_edge.png")
            not in plot_patch.paths)
    assert (path.join(plot_path, "chi_squared_map_parallel_front_edge.png")
            in plot_patch.paths)
        data=imaging_ci.pre_cti_data,
        parallel_trap_list=[parallel_trap_0, parallel_trap_1],
        parallel_ccd=parallel_ccd,
    ) for imaging_ci in imaging_ci_list
]
"""
We now perform the fit.
"""
fit_ci_list = [
    ac.ci.FitImagingCI(imaging=imaging_ci, post_cti_data=post_cti_data)
    for imaging_ci, post_cti_data in zip(imaging_ci_list, post_cti_data_list)
]
"""
We now pass the `FitImagingCI` and call various `figure_*` methods to plot different attributes.
"""
fit_ci_plotter = aplt.FitImagingCIPlotter(fit=fit_ci_list[0])
fit_ci_plotter.figures_2d(
    image=True,
    noise_map=True,
    pre_cti_data=True,
    residual_map=True,
    normalized_residual_map=True,
    chi_squared_map=True,
)
"""
The `FitImagingCIPlotter` may also plot a subplot of these attributes.
"""
fit_ci_plotter.subplot_fit_ci()
"""
We can also call `figures_1d_*` methods which create 1D plots of regions of the fit binned over the parallel or
serial direction.