def test__subhalo_detection_sub_plot(
    masked_imaging_fit_x2_plane_7x7,
    masked_imaging_fit_x2_plane_inversion_7x7,
    include_all,
    plot_path,
    plot_patch,
):
    arr = al.Array.manual_2d(array=[[1.0, 2.0], [3.0, 4.0]], pixel_scales=1.0)

    aplt.Subhalo.subplot_detection_imaging(
        fit_imaging_detect=masked_imaging_fit_x2_plane_7x7,
        detection_array=arr,
        mass_array=arr,
        include=include_all,
        sub_plotter=aplt.SubPlotter(
            output=aplt.Output(path=plot_path, format="png")),
    )

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

    aplt.Subhalo.subplot_detection_imaging(
        fit_imaging_detect=masked_imaging_fit_x2_plane_inversion_7x7,
        detection_array=arr,
        mass_array=arr,
        include=include_all,
        sub_plotter=aplt.SubPlotter(
            output=aplt.Output(path=plot_path, format="png")),
    )

    assert path.join(plot_path,
                     "subplot_detection_imaging.png") in plot_patch.paths
def test__subhalo_detection_fits(
    masked_imaging_fit_x2_plane_7x7,
    masked_imaging_fit_x2_plane_inversion_7x7,
    include_all,
    plot_path,
    plot_patch,
):
    aplt.Subhalo.subplot_detection_fits(
        fit_imaging_before=masked_imaging_fit_x2_plane_7x7,
        fit_imaging_detect=masked_imaging_fit_x2_plane_7x7,
        include=include_all,
        sub_plotter=aplt.SubPlotter(
            output=aplt.Output(path=plot_path, format="png")),
    )

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

    aplt.Subhalo.subplot_detection_fits(
        fit_imaging_before=masked_imaging_fit_x2_plane_inversion_7x7,
        fit_imaging_detect=masked_imaging_fit_x2_plane_inversion_7x7,
        include=include_all,
        sub_plotter=aplt.SubPlotter(
            output=aplt.Output(path=plot_path, format="png")),
    )

    assert path.join(plot_path,
                     "subplot_detection_fits.png") in plot_patch.paths
Пример #3
0
def test__subplot_of_plane(
    masked_imaging_fit_x1_plane_7x7,
    masked_imaging_fit_x2_plane_7x7,
    include_all,
    plot_path,
    plot_patch,
):

    aplt.FitImaging.subplot_of_plane(
        fit=masked_imaging_fit_x1_plane_7x7,
        plane_index=0,
        include=include_all,
        sub_plotter=aplt.SubPlotter(
            output=aplt.Output(plot_path, format="png")),
    )

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

    aplt.FitImaging.subplot_of_plane(
        fit=masked_imaging_fit_x2_plane_7x7,
        plane_index=0,
        include=include_all,
        sub_plotter=aplt.SubPlotter(
            output=aplt.Output(plot_path, format="png")),
    )

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

    aplt.FitImaging.subplot_of_plane(
        fit=masked_imaging_fit_x2_plane_7x7,
        plane_index=1,
        include=include_all,
        sub_plotter=aplt.SubPlotter(
            output=aplt.Output(plot_path, format="png")),
    )

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

    aplt.FitImaging.subplots_of_all_planes(
        fit=masked_imaging_fit_x1_plane_7x7,
        include=include_all,
        sub_plotter=aplt.SubPlotter(
            output=aplt.Output(plot_path, format="png")),
    )

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

    aplt.FitImaging.subplots_of_all_planes(
        fit=masked_imaging_fit_x2_plane_7x7,
        include=include_all,
        sub_plotter=aplt.SubPlotter(
            output=aplt.Output(plot_path, format="png")),
    )

    assert plot_path + "subplot_of_plane_0.png" in plot_patch.paths
    assert plot_path + "subplot_of_plane_1.png" in plot_patch.paths
Пример #4
0
def simulate_imaging_from_instrument(instrument, dataset_name, galaxies):

    # Simulate the imaging data, remembering that we use a special image which ensures edge-effects don't
    # degrade our modeling of the telescope optics (e.al. the PSF convolution).

    grid = instrument_util.grid_from_instrument(instrument=instrument)

    simulator = simulator_from_instrument(instrument=instrument)

    # Use the input galaxies to setup a tracer, which will generate the image for the simulated imaging data.
    tracer = al.Tracer.from_galaxies(galaxies=galaxies)

    imaging = simulator.from_tracer_and_grid(tracer=tracer, grid=grid)

    # Now, lets output this simulated imaging-data to the test_autoarray/simulator folder.
    test_path = path.join("{}".format(path.dirname(path.realpath(__file__))),
                          "..", "..")

    dataset_path = path.join(test_path, "dataset", "imaging", dataset_name,
                             instrument)

    imaging.output_to_fits(
        image_path=path.join(dataset_path, "image.fits"),
        psf_path=path.join(dataset_path, "psf.fits"),
        noise_map_path=path.join(dataset_path, "noise_map.fits"),
        overwrite=True,
    )

    plotter = aplt.Plotter(output=aplt.Output(path=dataset_path, format="png"))
    sub_plotter = aplt.SubPlotter(
        output=aplt.Output(path=dataset_path, format="png"))

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

    aplt.Imaging.individual(
        imaging=imaging,
        plot_image=True,
        plot_noise_map=True,
        plot_psf=True,
        plot_signal_to_noise_map=True,
        plotter=plotter,
    )

    aplt.Tracer.subplot_tracer(tracer=tracer,
                               grid=grid,
                               sub_plotter=sub_plotter)

    aplt.Tracer.individual(
        tracer=tracer,
        grid=grid,
        plot_image=True,
        plot_source_plane=True,
        plot_convergence=True,
        plot_potential=True,
        plot_deflections=True,
        plotter=plotter,
    )
Пример #5
0
def test__fit_sub_plot(
    masked_imaging_fit_x2_plane_7x7, include_all, plot_path, plot_patch
):
    aplt.FitImaging.subplot_fit_imaging(
        fit=masked_imaging_fit_x2_plane_7x7,
        include=include_all,
        sub_plotter=aplt.SubPlotter(output=aplt.Output(path=plot_path, format="png")),
    )

    assert path.join(plot_path, "subplot_fit_imaging.png") in plot_patch.paths
Пример #6
0
def test__tracer_sub_plot_output(tracer_x2_plane_7x7, sub_grid_7x7,
                                 include_all, plot_path, plot_patch):
    aplt.Tracer.subplot_tracer(
        tracer=tracer_x2_plane_7x7,
        grid=sub_grid_7x7,
        include=include_all,
        sub_plotter=aplt.SubPlotter(
            output=aplt.Output(plot_path, format="png")),
    )

    assert path.join(plot_path, "subplot_tracer.png") in plot_patch.paths
Пример #7
0
def test__fit_sub_plot(masked_interferometer_fit_x2_plane_7x7, include_all,
                       plot_path, plot_patch):

    aplt.FitInterferometer.subplot_fit_interferometer(
        fit=masked_interferometer_fit_x2_plane_7x7,
        include=include_all,
        sub_plotter=aplt.SubPlotter(
            output=aplt.Output(plot_path, format="png")),
    )

    assert plot_path + "subplot_fit_interferometer.png" in plot_patch.paths
Пример #8
0
def test__plot_hyper_galaxy_images(hyper_galaxy_image_path_dict_7x7, mask_7x7,
                                   include_all, plot_path, plot_patch):

    aplt.hyper.subplot_hyper_galaxy_images(
        hyper_galaxy_image_path_dict=hyper_galaxy_image_path_dict_7x7,
        mask=mask_7x7,
        include=include_all,
        sub_plotter=aplt.SubPlotter(
            output=aplt.Output(plot_path, format="png")),
    )

    assert plot_path + "subplot_hyper_galaxy_images.png" in plot_patch.paths
Пример #9
0
def test__tracer_sub_plot_output(tracer_x2_plane_7x7, sub_grid_7x7,
                                 include_all, ray_tracing_plotter_path,
                                 plot_patch):
    aplt.tracer.subplot_tracer(
        tracer=tracer_x2_plane_7x7,
        grid=sub_grid_7x7,
        include=include_all,
        sub_plotter=aplt.SubPlotter(
            output=aplt.Output(ray_tracing_plotter_path, format="png")),
    )

    assert ray_tracing_plotter_path + "subplot_tracer.png" in plot_patch.paths
Пример #10
0
def simulate_interferometer_from_instrument(instrument, data_name, galaxies):

    # Simulate the imaging data, remembering that we use a special image which ensures edge-effects don't
    # degrade our modeling of the telescope optics (e.al. the PSF convolution).

    grid = instrument_util.grid_from_instrument(instrument=instrument)

    simulator = simulator_from_instrument(instrument=instrument)

    # Use the input galaxies to setup a tracer, which will generate the image for the simulated imaging data.
    tracer = al.Tracer.from_galaxies(galaxies=galaxies)

    interferometer = simulator.from_tracer_and_grid(tracer=tracer, grid=grid)

    # Now, lets output this simulated interferometer-simulator to the test_autoarray/simulator folder.
    test_path = "{}/../../".format(os.path.dirname(os.path.realpath(__file__)))

    dataset_path = af.util.create_path(
        path=test_path, folders=["dataset", "interferometer", data_name, instrument]
    )

    interferometer.output_to_fits(
        visibilities_path=f"{dataset_path}/visibilities.fits",
        noise_map_path=f"{dataset_path}/noise_map.fits",
        uv_wavelengths_path=f"{dataset_path}/uv_wavelengths.fits",
        overwrite=True,
    )

    plotter = aplt.Plotter(output=aplt.Output(path=dataset_path, format="png"))
    sub_plotter = aplt.SubPlotter(output=aplt.Output(path=dataset_path, format="png"))

    aplt.Interferometer.subplot_interferometer(
        interferometer=interferometer, sub_plotter=sub_plotter
    )

    aplt.Interferometer.individual(
        interferometer=interferometer, plot_visibilities=True, plotter=plotter
    )

    aplt.Tracer.subplot_tracer(tracer=tracer, grid=grid, sub_plotter=sub_plotter)

    aplt.Tracer.individual(
        tracer=tracer,
        grid=grid,
        plot_image=True,
        plot_source_plane=True,
        plot_convergence=True,
        plot_potential=True,
        plot_deflections=True,
        plotter=plotter,
    )
Пример #11
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):

    critical_curves = [(0.0, 0.0), (0.1, 0.1)]
    caustics = [(0.0, 0.0), (0.1, 0.1)]

    aplt.mapper.subplot_image_and_mapper(
        image=imaging_7x7.image,
        mapper=rectangular_mapper_7x7_3x3,
        critical_curves=critical_curves,
        caustics=caustics,
        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,
        critical_curves=critical_curves,
        caustics=caustics,
        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
Пример #12
0
def test__inversion_subplot_is_output_for_all_inversions(
    imaging_7x7,
    rectangular_inversion_7x7_3x3,
    voronoi_inversion_9_3x3,
    plot_path,
    plot_patch,
):
    aplt.inversion.subplot_inversion(
        inversion=rectangular_inversion_7x7_3x3,
        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_inversion.png" in plot_patch.paths

    aplt.inversion.subplot_inversion(
        inversion=voronoi_inversion_9_3x3,
        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_inversion.png" in plot_patch.paths
Пример #13
0
def test__plot_subplot_of_hyper_galaxy(
    hyper_galaxy_image_0_7x7,
    contribution_map_7x7,
    masked_imaging_fit_x2_plane_7x7,
    include_all,
    plot_path,
    plot_patch,
):
    aplt.hyper.subplot_fit_hyper_galaxy(
        fit=masked_imaging_fit_x2_plane_7x7,
        hyper_fit=masked_imaging_fit_x2_plane_7x7,
        galaxy_image=hyper_galaxy_image_0_7x7,
        contribution_map_in=contribution_map_7x7,
        include=include_all,
        sub_plotter=aplt.SubPlotter(output=aplt.Output(plot_path, format="png")),
    )

    assert plot_path + "subplot_fit_hyper_galaxy.png" in plot_patch.paths
Пример #14
0
import autolens as al
import autolens.plot as aplt

plotter = aplt.Plotter()
sub_plotter = aplt.SubPlotter()

grid = al.Grid.uniform(shape_2d=(100, 100), pixel_scales=0.05, sub_size=2)

lens_galaxy = al.Galaxy(
    redshift=0.5,
    mass=al.mp.EllipticalIsothermal(centre=(0.0, 0.0),
                                    einstein_radius=1.0,
                                    elliptical_comps=(0.1, 0.1)),
)

source_galaxy = al.Galaxy(
    redshift=1.0,
    light=al.lp.EllipticalExponential(centre=(0.02, 0.01),
                                      intensity=1.0,
                                      effective_radius=0.5),
)

tracer = al.Tracer.from_galaxies(galaxies=[lens_galaxy, source_galaxy])

aplt.Tracer.image(
    tracer=tracer,
    grid=grid,
    include=aplt.Include(critical_curves=True),
    plotter=plotter,
)
# %%
aplt.Plane.plane_grid(
    plane=tracer.source_plane,
    grid=traced_grids[1],
    axis_limits=[-0.2, 0.2, -0.2, 0.2],
    plotter=aplt.Plotter(labels=aplt.Labels(title="Source-plane Grid")),
)

# %%
"""
Lets plot the lensing quantities again. Note that, because we supplied our galaxies with redshifts and our `Tracer` with 
a cosmology, our unit can be converted to kiloparsecs! (This cell can take a bit of time to run)
"""

# %%
sub_plotter = aplt.SubPlotter(units=aplt.Units(in_kpc=True))
aplt.Tracer.subplot_tracer(tracer=tracer, grid=grid, sub_plotter=sub_plotter)

# %%
"""
In the previous example, we saw that the `Tracer` had attributes we plotted (e.g. convergence, potential, etc.). Now 
we've input an **AstroPy** cosmology and galaxy redshifts, the `Tracer` has attributes associated with its cosmology.

We can use the `cosmology_util` module in **PyAutoLens** to compute quantities associated with this cosmology.
"""

# %%

cosmology = tracer.cosmology

print("Image-plane arcsec-per-kpc:")
Пример #16
0
def simulate_imaging_from_galaxies_and_output_to_fits(
    data_type, data_resolution, galaxies, sub_size=4
):

    # Simulate the imaging data, remembering that we use a special image which ensures edge-effects don't
    # degrade our modeling of the telescope optics (e.al. the PSF convolution).

    simulator = simulator_from_data_resolution(
        data_resolution=data_resolution, sub_size=sub_size
    )

    # Use the input galaxies to setup a tracer, which will generate the image for the simulated imaging data.
    tracer = al.Tracer.from_galaxies(galaxies=galaxies)

    imaging = simulator.from_tracer(tracer=tracer)

    # Now, lets output this simulated imaging-data to the test_autoarray/dataset folder.
    imaging_path = "{}/../".format(os.path.dirname(os.path.realpath(__file__)))

    dataset_path = af.path_util.make_and_return_path_from_path_and_folder_names(
        path=imaging_path, folder_names=["dataset", data_type, data_resolution]
    )

    imaging.output_to_fits(
        image_path=dataset_path + "image.fits",
        psf_path=dataset_path + "psf.fits",
        noise_map_path=dataset_path + "noise_map.fits",
        overwrite=True,
    )

    aplt.imaging.subplot_imaging(
        imaging=imaging,
        sub_plotter=aplt.SubPlotter(
            output=aplt.Output(filename="imaging", path=dataset_path, format="png")
        ),
    )

    aplt.imaging.individual(
        imaging=imaging,
        plot_image=True,
        plot_noise_map=True,
        plot_psf=True,
        plot_signal_to_noise_map=True,
        plotter=aplt.Plotter(output=aplt.Output(path=dataset_path, format="png")),
    )

    aplt.tracer.subplot_tracer(
        tracer=tracer,
        grid=simulator.grid,
        sub_plotter=aplt.SubPlotter(
            output=aplt.Output(filename="tracer", path=dataset_path, format="png")
        ),
    )

    aplt.tracer.individual(
        tracer=tracer,
        grid=simulator.grid,
        plot_profile_image=True,
        plot_source_plane=True,
        plot_convergence=True,
        plot_potential=True,
        plot_deflections=True,
        plotter=aplt.Plotter(output=aplt.Output(path=dataset_path, format="png")),
    )
Пример #17
0
aplt.array(array=image, plotter=plotter)

psf_path = workspace_path + "/dataset/slacs/" + dataset_name + "/psf.fits"
noise_map_path = workspace_path + "/dataset/slacs/" + dataset_name + "/noise_map.fits"

imaging = al.imaging.from_fits(
    image_path=image_path,
    psf_path=psf_path,
    noise_map_path=noise_map_path,
    pixel_scales=0.03,
)

# These plotters can be customized using the exact same functions as above.

plotter = aplt.Plotter(
    labels=aplt.Labels(title="SLACS1430+4105 Noise Map"),
    cmap=aplt.ColorMap(norm="linear"),
)

aplt.imaging.noise_map(imaging=imaging, plotter=plotter)

# Of course, as we've seen in many other examples, a sub-plotters of the imaging dataset_label can be plotted. This can also take the
# customization inputs above, but it should be noted that the options are applied to all images, and thus will most
# likely degrade a number of the sub-plotters images.

sub_plotter = aplt.SubPlotter(
    cmap=aplt.ColorMap.sub(norm="symmetric_log", linthresh=0.05, linscale=0.02)
)

aplt.imaging.subplot_imaging(imaging=imaging, sub_plotter=sub_plotter)
Пример #18
0
phase_1 = al.PhaseImaging(
    phase_name="phase_1",
    settings=settings,
    galaxies=dict(lens_model_1=lens_model_1, source_model_1=source_model_1),
    search=af.DynestyStatic(n_live_points=50, evidence_tolerance=5.0),
)

print(f"\n{dataset_name} running phase 1 at {datetime.datetime.now()}")

phase_1_result = phase_1.run(dataset=imaging,
                             mask=mask,
                             info=info,
                             pickle_files=pickle_files)

phase_1_sub_plotter = aplt.SubPlotter(
    output=aplt.Output(path=output_path, filename="Phase1", format="png"))
aplt.FitImaging.subplot_fit_imaging(fit=phase_1_result.max_log_likelihood_fit,
                                    sub_plotter=phase_1_sub_plotter)

# Second phase
print(f"\n{dataset_name} creating phase 2 at {datetime.datetime.now()}")

lens_model_2 = al.GalaxyModel(
    redshift=0.5,
    mass=af.PriorModel(al.mp.EllipticalPowerLaw),
)
lens_model_2.mass.elliptical_comps = (
    phase_1_result.model.galaxies.lens_model_1.mass.elliptical_comps)
lens_model_2.mass.einstein_radius = (
    phase_1_result.model.galaxies.lens_model_1.mass.einstein_radius)
"""

# %%
aplt.Imaging.subplot_imaging(imaging=imaging)

# %%
"""
Again, we can customize this subplot using a SubPlotter.

(The `.sub` ensures we load the setting values from the config file `autolens_workspace/config/visualize/subplots.ini`
"""

# %%
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:
"""

# %%