Example #1
0
def test__image_and_mapper_subplot_is_output_for_all_mappers(
        imaging_7x7, rectangular_mapper_7x7_3x3, voronoi_mapper_9_3x3,
        plot_path, plot_patch):
    aplt.mapper.subplot_image_and_mapper(
        image=imaging_7x7.image,
        mapper=rectangular_mapper_7x7_3x3,
        include=aplt.Include(inversion_pixelization_grid=True,
                             inversion_grid=True,
                             inversion_border=True),
        image_pixel_indexes=[[0, 1, 2], [3]],
        source_pixel_indexes=[[1, 2], [0]],
        sub_plotter=aplt.SubPlotter(
            output=aplt.Output(path=plot_path, format="png")),
    )
    assert plot_path + "subplot_image_and_mapper.png" in plot_patch.paths

    aplt.mapper.subplot_image_and_mapper(
        image=imaging_7x7.image,
        mapper=voronoi_mapper_9_3x3,
        include=aplt.Include(inversion_pixelization_grid=True,
                             inversion_grid=True,
                             inversion_border=True),
        image_pixel_indexes=[[0, 1, 2], [3]],
        source_pixel_indexes=[[1, 2], [0]],
        sub_plotter=aplt.SubPlotter(
            output=aplt.Output(path=plot_path, format="png")),
    )
    assert plot_path + "subplot_image_and_mapper.png" in plot_patch.paths
Example #2
0
def test__individual_attributes_are_output(imaging_7x7, positions_7x7,
                                           mask_7x7, plot_path, plot_patch):

    aplt.imaging.image(
        imaging=imaging_7x7,
        positions=positions_7x7,
        mask=mask_7x7,
        include=aplt.Include(mask=True),
        plotter=aplt.Plotter(output=aplt.Output(plot_path, format="png")),
    )

    assert plot_path + "image.png" in plot_patch.paths

    aplt.imaging.noise_map(
        imaging=imaging_7x7,
        mask=mask_7x7,
        plotter=aplt.Plotter(output=aplt.Output(plot_path, format="png")),
    )

    assert plot_path + "noise_map.png" in plot_patch.paths

    aplt.imaging.psf(
        imaging=imaging_7x7,
        plotter=aplt.Plotter(output=aplt.Output(plot_path, format="png")),
    )

    assert plot_path + "psf.png" in plot_patch.paths

    aplt.imaging.signal_to_noise_map(
        imaging=imaging_7x7,
        mask=mask_7x7,
        plotter=aplt.Plotter(output=aplt.Output(plot_path, format="png")),
    )

    assert plot_path + "signal_to_noise_map.png" in plot_patch.paths
Example #3
0
    def test__plot_array__works_with_all_extras_included(
            self, plot_path, plot_patch):

        array = aa.array.ones(shape_2d=(31, 31),
                              pixel_scales=(1.0, 1.0),
                              sub_size=2)

        mask = aa.mask.circular(
            shape_2d=array.shape_2d,
            pixel_scales=array.pixel_scales,
            radius=5.0,
            centre=(2.0, 2.0),
        )

        grid = aa.grid.uniform(shape_2d=(11, 11), pixel_scales=0.5)

        plotter = aplt.Plotter(output=aplt.Output(
            path=plot_path, filename="array1", format="png"))

        plotter.plot_array(
            array=array,
            mask=mask,
            grid=grid,
            positions=[(-1.0, -1.0)],
            lines=[(1.0, 1.0), (2.0, 2.0)],
            include_origin=True,
            include_border=True,
        )

        assert plot_path + "array1.png" in plot_patch.paths

        plotter = aplt.Plotter(output=aplt.Output(
            path=plot_path, filename="array2", format="png"))

        plotter.plot_array(
            array=array,
            mask=mask,
            grid=grid,
            positions=[[(1.0, 1.0), (2.0, 2.0)], [(-1.0, -1.0)]],
            lines=[[(1.0, 1.0), (2.0, 2.0)], [(2.0, 4.0), (5.0, 6.0)]],
            include_origin=True,
            include_border=True,
        )

        assert plot_path + "array2.png" in plot_patch.paths

        aplt.array(
            array=array,
            mask=mask,
            grid=grid,
            positions=[(-1.0, -1.0)],
            lines=[(1.0, 1.0), (2.0, 2.0)],
            include=aplt.Include(origin=True, border=True),
            plotter=aplt.Plotter(output=aplt.Output(
                path=plot_path, filename="array3", format="png")),
        )

        assert plot_path + "array3.png" in plot_patch.paths
def test__fit_sub_plot(fit_imaging_7x7, plot_path, plot_patch):

    aplt.fit_imaging.subplot_fit_imaging(
        fit=fit_imaging_7x7,
        include=aplt.Include(mask=True),
        sub_plotter=aplt.SubPlotter(
            output=aplt.Output(path=plot_path, format="png")),
    )

    assert plot_path + "subplot_fit_imaging.png" in plot_patch.paths
def test__fit_quantities_are_output(fit_imaging_7x7, plot_path, plot_patch):

    aplt.fit_imaging.image(
        fit=fit_imaging_7x7,
        include=aplt.Include(mask=True),
        plotter=aplt.Plotter(output=aplt.Output(path=plot_path, format="png")),
    )

    assert plot_path + "image.png" in plot_patch.paths

    aplt.fit_imaging.noise_map(
        fit=fit_imaging_7x7,
        include=aplt.Include(mask=True),
        plotter=aplt.Plotter(output=aplt.Output(path=plot_path, format="png")),
    )

    assert plot_path + "noise_map.png" in plot_patch.paths

    aplt.fit_imaging.signal_to_noise_map(
        fit=fit_imaging_7x7,
        include=aplt.Include(mask=True),
        plotter=aplt.Plotter(output=aplt.Output(path=plot_path, format="png")),
    )

    assert plot_path + "signal_to_noise_map.png" in plot_patch.paths

    aplt.fit_imaging.model_image(
        fit=fit_imaging_7x7,
        include=aplt.Include(mask=True),
        plotter=aplt.Plotter(output=aplt.Output(path=plot_path, format="png")),
    )

    assert plot_path + "model_image.png" in plot_patch.paths

    aplt.fit_imaging.residual_map(
        fit=fit_imaging_7x7,
        include=aplt.Include(mask=True),
        plotter=aplt.Plotter(output=aplt.Output(path=plot_path, format="png")),
    )

    assert plot_path + "residual_map.png" in plot_patch.paths

    aplt.fit_imaging.normalized_residual_map(
        fit=fit_imaging_7x7,
        include=aplt.Include(mask=True),
        plotter=aplt.Plotter(output=aplt.Output(path=plot_path, format="png")),
    )

    assert plot_path + "normalized_residual_map.png" in plot_patch.paths

    aplt.fit_imaging.chi_squared_map(
        fit=fit_imaging_7x7,
        include=aplt.Include(mask=True),
        plotter=aplt.Plotter(output=aplt.Output(path=plot_path, format="png")),
    )

    assert plot_path + "chi_squared_map.png" in plot_patch.paths
def test__fit_individuals__source_and_lens__depedent_on_input(
        fit_imaging_7x7, plot_path, plot_patch):

    aplt.fit_imaging.individuals(
        fit=fit_imaging_7x7,
        include=aplt.Include(mask=True),
        plot_image=True,
        plot_noise_map=False,
        plot_signal_to_noise_map=False,
        plot_model_image=True,
        plot_chi_squared_map=True,
        plotter=aplt.Plotter(output=aplt.Output(path=plot_path, format="png")),
    )

    assert plot_path + "image.png" in plot_patch.paths

    assert plot_path + "noise_map.png" not in plot_patch.paths

    assert plot_path + "signal_to_noise_map.png" not in plot_patch.paths

    assert plot_path + "model_image.png" in plot_patch.paths

    assert plot_path + "residual_map.png" not in plot_patch.paths

    assert plot_path + "normalized_residual_map.png" not in plot_patch.paths

    assert plot_path + "chi_squared_map.png" in plot_patch.paths

    aplt.fit_imaging.individuals(
        fit=fit_imaging_7x7,
        plot_image=True,
        plot_noise_map=False,
        plot_signal_to_noise_map=False,
        plot_model_image=True,
        plot_chi_squared_map=True,
        plotter=aplt.Plotter(output=aplt.Output(path=plot_path, format="png")),
    )

    assert plot_path + "image.png" in plot_patch.paths

    assert plot_path + "noise_map.png" not in plot_patch.paths

    assert plot_path + "signal_to_noise_map.png" not in plot_patch.paths

    assert plot_path + "model_image.png" in plot_patch.paths

    assert plot_path + "residual_map.png" not in plot_patch.paths

    assert plot_path + "normalized_residual_map.png" not in plot_patch.paths

    assert plot_path + "chi_squared_map.png" in plot_patch.paths
def test__output_as_fits__correct_output_format(fit_imaging_7x7, positions_7x7,
                                                mask_7x7, plot_path,
                                                plot_patch):

    aplt.fit_imaging.individuals(
        fit=fit_imaging_7x7,
        include=aplt.Include(mask=True),
        plot_image=True,
        plotter=aplt.Plotter(
            output=aplt.Output(path=plot_path, format="fits")),
    )

    image_from_plot = aa.util.array.numpy_array_2d_from_fits(
        file_path=plot_path + "image.fits", hdu=0)

    assert image_from_plot.shape == (5, 5)
Example #8
0
    def test__plot_voronoi_mapper__works_with_all_extras_included(
            self, voronoi_mapper_9_3x3, plot_path, plot_patch):

        plotter = aplt.Plotter(output=aplt.Output(
            path=plot_path, filename="mapper1", format="png"))

        plotter.plot_voronoi_mapper(
            mapper=voronoi_mapper_9_3x3,
            include_pixelization_grid=True,
            include_grid=True,
            include_border=True,
            image_pixel_indexes=[[(0, 0), (0, 1)], [(1, 2)]],
            source_pixel_indexes=[[0, 1], [2]],
        )

        assert plot_path + "mapper1.png" in plot_patch.paths

        plotter = aplt.Plotter(output=aplt.Output(
            path=plot_path, filename="mapper2", format="png"))

        plotter.plot_voronoi_mapper(
            mapper=voronoi_mapper_9_3x3,
            include_pixelization_grid=True,
            include_grid=True,
            include_border=True,
            image_pixel_indexes=[[(0, 0), (0, 1)], [(1, 2)]],
            source_pixel_indexes=[[0, 1], [2]],
        )

        assert plot_path + "mapper2.png" in plot_patch.paths

        aplt.mapper_obj(
            mapper=voronoi_mapper_9_3x3,
            include=aplt.Include(
                inversion_pixelization_grid=True,
                inversion_grid=True,
                inversion_border=True,
            ),
            image_pixel_indexes=[[(0, 0), (0, 1)], [(1, 2)]],
            source_pixel_indexes=[[0, 1], [2]],
            plotter=aplt.Plotter(output=aplt.Output(
                path=plot_path, filename="mapper3", format="png")),
        )

        assert plot_path + "mapper3.png" in plot_patch.paths
Example #9
0
sub_plotter = aplt.SubPlotter(
    figure=aplt.Figure.sub(figsize=(7, 7)),
    ticks=aplt.Ticks.sub(ysize=8, xsize=8),
    labels=aplt.Labels.sub(ysize=6, xsize=6, titlesize=12),
)

aplt.imaging.subplot_imaging(imaging=imaging, sub_plotter=sub_plotter)

# Again, you can customize the default appearance of subplots by editing the config file
# autolens_workspace/config/visualize/subplots.ini'.

# The other thing we can do with figures is choose what we include in the plot. For example, we can choose whether to
# include the origin of the coordinate system on our plot of the image:

aplt.imaging.image(imaging=imaging,
                   plotter=plotter,
                   include=aplt.Include(origin=True))

aplt.imaging.image(imaging=imaging,
                   plotter=plotter,
                   include=aplt.Include(origin=False))

# Throughout the HowToArray lecture series you'll see lots more objects that can include on figures.

# Just like the matplotlib setup, you can customize what does and does not appear on figures by default using the
# config file 'autolens_workspace/config/visualize/general.ini'

# Great! Hopefully, visualization in PyAutoArray is displaying nicely for us to get on with the HowToArray lecture
# series.
Example #10
0
import autoarray as aa
import autoarray.plot as aplt

grid_7x7 = aa.grid.uniform(shape_2d=(7, 7), pixel_scales=1.0)
rectangular_grid = aa.grid_rectangular.overlay_grid(grid=grid_7x7, shape_2d=(3, 3))
rectangular_mapper = aa.mapper(grid=grid_7x7, pixelization_grid=rectangular_grid)

image = aa.array.ones(shape_2d=(7, 7), pixel_scales=1.0)
image[0:4] = 5.0
noise_map = aa.array.ones(shape_2d=(7, 7), pixel_scales=1.0)
imaging = aa.imaging(image=image, noise_map=noise_map)

aplt.mapper.subplot_image_and_mapper(
    image=imaging,
    mapper=rectangular_mapper,
    include=aplt.Include(
        inversion_grid=False, inversion_border=True, inversion_pixelization_grid=False
    ),
    image_pixel_indexes=[0, 1, 2, 3],
    source_pixel_indexes=[[3, 4], [5]],
)