Exemplo n.º 1
0
reconstructed fluxes of every source-pixel pair multiplied by the regularization_coefficient. By setting the 
regularization coefficient to zero, we set this penalty term to zero, meaning that `Regularization`.s omitted.

Why do we need to regularize our solution? Well, we just saw why - if we don't apply this smoothing, we `over-fit` 
the image. More specifically, we over-fit the noise in the image, which is what the large flux values located at
the exteriors of the source reconstruction are doing. Think about it, if your sole aim is to maximize the log 
likelihood, the best way to do this is to fit *everything* accurately, including the noise.

If we change the `normalization` variables of the `Plotter` such that the color-map is restricted to a narrower range of 
values, we can see that even without `Regularization`.e are still reconstructing the actual source galaxy.
"""

# %%
aplt.Inversion.reconstruction(
    inversion=no_regularization_fit.inversion,
    plotter=aplt.Plotter(cmap=aplt.ColorMap(norm_max=0.5, norm_min=-0.5)),
)

# %%
"""
Over-fitting is why `Regularization`.s necessary. Solutions like this completely ruin our attempts to model a strong 
lens. By smoothing our source reconstruction we ensure it doesn`t fit the noise in the image. If we set a really high 
regularization coefficient we completely remove over-fitting at the expense of also fitting the image less accurately.
"""

# %%
source_galaxy = al.Galaxy(
    redshift=1.0,
    pixelization=al.pix.Rectangular(shape=(40, 40)),
    regularization=al.reg.Constant(coefficient=100.0),
)
Exemplo n.º 2
0
# Now, lets load this image as a hyper arrays. A hyper arrays is an ordinary NumPy arrays, but it also includes a pixel
# scale which allows us to convert the axes of the image to arc-second coordinates.
residual_map = al.array.from_fits(file_path=residual_map_path, hdu=0, pixel_scales=0.03)

# We can now use an arrays plotter to plotters the residual map.

plotter = aplt.Plotter(labels=aplt.Labels(title="SLACS1430+4105 Residual Map"))

aplt.array(array=residual_map, plotter=plotter)

# A useful way to really dig into the residuals is to set upper and lower limits on the normalization of the colorbar.

plotter = aplt.Plotter(
    labels=aplt.Labels(title="SLACS1430+4105 Residual Map"),
    cmap=aplt.ColorMap(norm_min=-0.02, norm_max=0.02),
)

aplt.array(array=residual_map, plotter=plotter)

# Or, alternatively, use a symmetric logarithmic colormap

plotter = aplt.Plotter(
    labels=aplt.Labels(title="SLACS1430+4105 Residual Map"),
    cmap=aplt.ColorMap(norm="symmetric_log", linthresh=0.02, linscale=0.02),
)

aplt.array(array=residual_map, plotter=plotter)

# These tools are equally powerful ways to inspect the chi-squared map of a fit.
chi_squared_map = al.array.from_fits(
Exemplo n.º 3
0
import autolens as al
import autolens.plot as aplt
from test_autolens.simulators.imaging import instrument_util
import numpy as np

imaging = instrument_util.load_test_imaging(
    dataset_name="light_sersic__source_sersic", instrument="vro")

array = imaging.image

plotter = aplt.Plotter(
    figure=aplt.Figure(figsize=(10, 10)),
    cmap=aplt.ColorMap(cmap="gray",
                       norm="symmetric_log",
                       norm_min=-0.13,
                       norm_max=20,
                       linthresh=0.02),
    grid_scatterer=aplt.GridScatterer(marker="+", colors="cyan", size=450),
)

grid = al.GridIrregular(grid=[[1.0, 1.0], [2.0, 2.0], [3.0, 3.0]])

print(grid)

vector_field = al.VectorFieldIrregular(vectors=[(1.0, 2.0), (2.0, 1.0)],
                                       grid=[(-1.0, 0.0), (-2.0, 0.0)])

aplt.Array(
    array=array.in_2d,
    grid=grid,
    positions=al.GridIrregularGrouped([(0.0, 1.0), (0.0, 2.0)]),
Exemplo n.º 4
0
dataset_path = af.path_util.make_and_return_path_from_path_and_folder_names(
    path=workspace_path, folder_names=["dataset", dataset_label, dataset_name]
)

# If you use this tool for your own dataset, you *must* double check this pixel scale is correct!
pixel_scales = 0.1

# First, load the imaging dataset, so that the location of galaxies is clear when scaling the noise-map.
image = al.array.from_fits(
    file_path=dataset_path + "image.fits", pixel_scales=pixel_scales
)

cmap = aplt.ColorMap(
    norm="log",
    norm_min=1.0e-4,
    norm_max=0.4 * np.max(image),
    linthresh=0.05,
    linscale=0.1,
)

scribbler = scribbler.Scribbler(image=image.in_2d, cmap=cmap)
mask = scribbler.show_mask()
mask = al.mask.manual(mask_2d=mask, pixel_scales=pixel_scales)

# Next, load the imaging noise-map, which we will use the scale the noise-map.
noise_map = al.array.from_fits(
    file_path=dataset_path + "noise_map.fits", pixel_scales=pixel_scales
)

# Now lets plotters the image and mask, so we can check that the mask includes the regions of the image we want.
# data_plotters.plot_signal_to_noise_map(signal_to_noise_map=image / noise_map)
fits = [
    al.fit(masked_dataset=masked_imaging, tracer=tracer)
    for masked_imaging, tracer in zip(masked_imagings, tracers)
]

[aplt.fit_imaging.subplot_fit_imaging(fit=fit) for fit in fits]

# The benefit of inspecting fits using the aggregator, rather than the files outputs to the hard-disk, is that
# we can customize the plots using the PyAutoLens plotters.

plotter = aplt.Plotter(
    figure=aplt.Figure(figsize=(12, 12)),
    labels=aplt.Labels(title="Custom Image", titlesize=24, ysize=24, xsize=24),
    ticks=aplt.Ticks(ysize=24, xsize=24),
    cmap=aplt.ColorMap(norm="log", norm_max=1.0, norm_min=1.0),
    cb=aplt.ColorBar(ticksize=20),
    units=aplt.Units(in_kpc=True),
)

[
    aplt.fit_imaging.normalized_residual_map(fit=fit, plotter=plotter)
    for fit in fits
]

# Making this plot for a paper? You can output it to hard disk.

plotter = aplt.Plotter(output=aplt.Output(
    path=workspace_path + "/output/path/of/file/",
    filename="publication",
    format="png",
Exemplo n.º 6
0
# 1) We make the arrays's figure size bigger than the default size (7,7).

# 2) Because the figure is bigger, we increase the size of the title, x and y labels / ticks from their default size of
#    16 to 24.

# 3) For the same reason, we increase the size of the colorbar ticks from the default value 10 to 20.

plotter = aplt.Plotter(
    figure=aplt.Figure(figsize=(12, 12)),
    labels=aplt.Labels(title="SLACS1430+4105 Image",
                       titlesize=24,
                       ysize=24,
                       xsize=24),
    ticks=aplt.Ticks(ysize=24, xsize=24),
    cmap=aplt.ColorMap(norm="cold", norm_max=0.8),
    cb=aplt.ColorBar(ticksize=20),
)

aplt.array(array=image, plotter=plotter)

# The colormap of the arrays can be changed to any of the standard matplotlib colormaps.

plotter = aplt.Plotter(labels=aplt.Labels(title="SLACS1430+4105 Image"),
                       cmap=aplt.ColorMap(cmap="spring"))

aplt.array(array=image, plotter=plotter)

# We can change the x / y axis unit_label from arc-seconds to kiloparsec, by inputting a kiloparsec to arcsecond conversion
# factor (for SLACS1430+4105, the lens galaxy is at redshift 0.285, corresponding to the conversion factor below).
Exemplo n.º 7
0
image_path = dataset_path + "image.fits"

# Now, lets load this arrays as a hyper arrays. A hyper arrays is an ordinary NumPy arrays, but it also includes a pixel
# scale which allows us to convert the axes of the arrays to arc-second coordinates.
image = al.array.from_fits(file_path=image_path, hdu=0, pixel_scales=0.03)

# We can now use an arrays plotter to plotters the image. Lets first plotters it using the default PyAutoLens setup.
plotter = aplt.Plotter(labels=aplt.Labels(title="SLACS1430+4105 Image"))
aplt.array(array=image, plotter=plotter)

# For a lens like SLACS1430+4105, the lens galaxy's light outshines the background source, making it appear faint.
# we can use a symmetric logarithmic colorbar normalization to better reveal the source galaxy (due to negative values
# in the image, we cannot use a logirithmic colorbar normalization).
plotter = aplt.Plotter(
    labels=aplt.Labels(title="SLACS1430+4105 Image"),
    cmap=aplt.ColorMap(norm="symmetric_log", linthresh=0.05, linscale=0.02),
)
aplt.array(array=image, plotter=plotter)

# Alternatively, we can use the default linear colorbar normalization and customize the limits over which the colormap
# spans its dynamic range.
plotter = aplt.Plotter(
    labels=aplt.Labels(title="SLACS1430+4105 Image"),
    cmap=aplt.ColorMap(norm="linear", norm_min=0.0, norm_max=0.3),
)
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(