How to use the autolens.model.profiles.light_profiles function in autolens

To help you get started, we’ve selected a few autolens examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Jammy2211 / PyAutoLens / test / profiling / simulate_image.py View on Github external
pixel_scale = 0.03

lens_name = 'AO/'
pixel_scale = 0.01

psf = image.PSF.from_fits_with_scale(file_path=path + '../profiling/datas/psf', hdu=3, pixel_scale=pixel_scale)
psf = psf.resized_scaled_array_from_array(psf_size)
ma = mask.Mask.padded_mask_unmasked_psf_edges(shape_arc_seconds=(15.0, 15.0), pixel_scale=pixel_scale,
                                              pad_size=psf_size)

image_plane_grids = mask.GridCollection.grids_from_mask_sub_grid_size_and_psf_shape(mask=ma, sub_grid_size=4,
                                                                                    psf_shape=psf_size)

### Setup the ray tracing model, and use to generate the 2D model_galaxy image_coords ###

sersic = lp.EllipticalSersic(centre=(0.0, 0.0), axis_ratio=0.8, phi=90.0, intensity=0.5, effective_radius=1.3,
                             sersic_index=3.0)
isothermal = mp.EllipticalIsothermal(centre=(0.0, 0.0), axis_ratio=0.8, phi=90.0, einstein_radius=1.4)

lens_galaxy = galaxy.Galaxy(light_profile=sersic, mass_profile=isothermal)
source_galaxy = galaxy.Galaxy(light_profile=sersic)

ray_trace = ray_tracing.TracerImagePlane(lens_galaxies=[lens_galaxy], source_galaxies=[source_galaxy],
                                         image_plane_grids=image_plane_grids)

galaxy_image_1d = ray_trace.galaxy_light_profiles_image_from_planes()
galaxy_image_2d = ma.map_to_2d_keep_padded(galaxy_image_1d)

plt.imshow(galaxy_image_2d)
plt.show()

### Setup as a simulated image_coords and output as a fits for an lensing ###
github Jammy2211 / PyAutoLens / test / profiling / imaging / convolution / image / jitted_1.py View on Github external
frame_kernels = blurring_frame_kernels[image_index]
            frame_length = blurring_frame_lengths[image_index]
            value = blurring_array[image_index]

            for kernel_index in range(frame_length):
                vector_index = frame_indexes[kernel_index]
                kernel = frame_kernels[kernel_index]
                new_array[vector_index] += value * kernel

        return new_array


sub_grid_size = 4
psf_shape = (21, 21)
# psf_shape = (41, 41)
sersic = light_profiles.EllipticalSersic(centre=(0.0, 0.0), axis_ratio=0.8, phi=90.0, intensity=0.1,
                                         effective_radius=0.8, sersic_index=4.0)

lsst = profiling_data.setup_class(name='LSST', pixel_scale=0.2, sub_grid_size=sub_grid_size, psf_shape=psf_shape)
euclid = profiling_data.setup_class(name='Euclid', pixel_scale=0.1, sub_grid_size=sub_grid_size, psf_shape=psf_shape)
hst = profiling_data.setup_class(name='HST', pixel_scale=0.05, sub_grid_size=sub_grid_size, psf_shape=psf_shape)
hst_up = profiling_data.setup_class(name='HSTup', pixel_scale=0.03, sub_grid_size=sub_grid_size, psf_shape=psf_shape)
ao = profiling_data.setup_class(name='AO', pixel_scale=0.01, sub_grid_size=sub_grid_size, psf_shape=psf_shape)

lsst_image = sersic.intensities_from_grid(grid=lsst.grids.image_plane_images_)
lsst_blurring_image = sersic.intensities_from_grid(grid=lsst.grids.blurring)
assert lsst.masked_image.convolver_image.convolve_image(lsst_image, lsst_blurring_image) == \
       pytest.approx(lsst.masked_image.convolver_image.convolve_image(lsst_image, lsst_blurring_image), 1e-4)

euclid_image = sersic.intensities_from_grid(grid=euclid.grids.image_plane_images_)
euclid_blurring_image = sersic.intensities_from_grid(grid=euclid.grids.blurring)
hst_image = sersic.intensities_from_grid(grid=hst.grids.image_plane_images_)
github Jammy2211 / PyAutoLens / test / profiling / imaging / convolution / setup / jitted.py View on Github external
x = coords[0] - half_x + i
                y = coords[1] - half_y + j
                if 0 <= x < mask_index_array.shape[0] and 0 <= y < mask_index_array.shape[1]:
                    value = mask_index_array[x, y]
                    if value >= 0 and not mask[x, y]:
                        frame[count] = value
                        kernel_frame[count] = kernel[i, j]
                        count += 1

        return frame[0:count], kernel_frame[0:count]


sub_grid_size = 4
# psf_shape = (21, 21)
psf_shape = (41, 41)
sersic = light_profiles.EllipticalSersic(centre=(0.0, 0.0), axis_ratio=0.8, phi=90.0, intensity=0.1,
                                         effective_radius=0.8, sersic_index=4.0)

lsst = profiling_data.setup_class(name='LSST', pixel_scale=0.2, sub_grid_size=sub_grid_size, psf_shape=psf_shape)

lsst_convolver = Convolver(mask=lsst.mask, blurring_mask=lsst.masked_image.blurring_mask,
                           kernel=lsst.image_plane_images_.psf.resized_scaled_array_from_array(psf_shape))

assert lsst.masked_image.convolver.frame_array[0] == pytest.approx(lsst_convolver.frame_array[0], 1e-2)
assert lsst.masked_image.convolver.frame_array[1] == pytest.approx(lsst_convolver.frame_array[1], 1e-2)
assert lsst.masked_image.convolver.frame_kernel_array[1] == pytest.approx(lsst_convolver.frame_kernel_array[1], 1e-2)
assert lsst.masked_image.convolver.blurring_frame_array[0] == pytest.approx(lsst_convolver.blurring_frame_array[0],
                                                                            1e-2)
assert lsst.masked_image.convolver.blurring_frame_array[1] == pytest.approx(lsst_convolver.blurring_frame_array[1],
                                                                            1e-2)
assert lsst.masked_image.convolver.blurring_frame_kernel_array[1] == pytest.approx(
    lsst_convolver.blurring_frame_kernel_array[1], 1e-2)
github Jammy2211 / PyAutoLens / test / unit / lens / plotters / test_lens_fit_hyper_plotters.py View on Github external
def make_galaxy_light():
    return g.Galaxy(light=lp.EllipticalSersic(intensity=1.0), redshift=2.0)
github Jammy2211 / PyAutoLens / test / lensing / test_lensing_fitting.py View on Github external
def test___of_galaxies__x2_galaxies__3x3_padded_image__asymetric_psf_blurring(self):
        psf = image.PSF(array=(np.array([[0.0, 0.0, 0.0],
                                         [0.0, 1.0, 0.0],
                                         [0.0, 0.0, 0.0]])), pixel_scale=1.0)
        im = image.Image(array=np.ones((3, 3)), pixel_scale=1.0, psf=psf, noise_map=np.ones((3, 3)))

        ma = mask.Mask(array=np.array([[True, True, True],
                                       [True, False, True],
                                       [True, True, True]]), pixel_scale=1.0)
        li = lensing_image.LensingImage(im, ma, sub_grid_size=1)

        g0 = g.Galaxy(light_profile=lp.EllipticalSersic(intensity=0.1))
        g1 = g.Galaxy(light_profile=lp.EllipticalSersic(intensity=0.2))

        tracer = ray_tracing.TracerImagePlane(lens_galaxies=[g0, g1], image_plane_grids=[li.padded_grids])

        manual_model_image_0 = tracer.image_plane.grids[0].regular.map_to_2d_keep_padded(
            tracer.image_plane.image_plane_images_of_galaxies_[0][0])
        manual_model_image_0 = psf.convolve(manual_model_image_0)

        manual_model_image_1 = tracer.image_plane.grids[0].regular.map_to_2d_keep_padded(
            tracer.image_plane.image_plane_images_of_galaxies_[0][1])
        manual_model_image_1 = psf.convolve(manual_model_image_1)

        padded_model_images = lensing_fitting.unmasked_model_images_of_galaxies_from_lensing_image_and_tracer(
            lensing_image=li, tracer=tracer, image_index=0)

        assert (manual_model_image_0[1:4, 1:4] == padded_model_images[0][0]).all()
github Jammy2211 / PyAutoLens / test / lens / util / test_lens_fit_util.py View on Github external
psf = im.PSF(array=(np.array([[0.0, 3.0, 0.0],
                                      [0.0, 1.0, 2.0],
                                      [0.0, 0.0, 0.0]])), pixel_scale=1.0)

        mask = msk.Mask(array=np.array([[True, True, True],
                                        [True, False, True],
                                        [True, True, True]]), pixel_scale=1.0)

        padded_grid_stack = grids.GridStack.padded_grid_stack_from_mask_sub_grid_size_and_psf_shape(mask=mask,
                                                                                                    sub_grid_size=1,
                                                                                                    psf_shape=(3, 3))

        g0 = g.Galaxy(light_profile=lp.EllipticalSersic(intensity=0.1))
        g1 = g.Galaxy(light_profile=lp.EllipticalSersic(intensity=0.2))
        g2 = g.Galaxy(light_profile=lp.EllipticalSersic(intensity=0.3))
        g3 = g.Galaxy(light_profile=lp.EllipticalSersic(intensity=0.4))

        tracer = ray_tracing.TracerImageSourcePlanes(lens_galaxies=[g0, g1], source_galaxies=[g2, g3],
                                                     image_plane_grid_stack=padded_grid_stack)

        manual_blurred_image_0 = tracer.image_plane.image_plane_image_1d_of_galaxies[0]
        manual_blurred_image_0 = padded_grid_stack.regular.map_to_2d_keep_padded(padded_array_1d=manual_blurred_image_0)
        manual_blurred_image_0 = psf.convolve(array=manual_blurred_image_0)

        manual_blurred_image_1 = tracer.image_plane.image_plane_image_1d_of_galaxies[1]
        manual_blurred_image_1 = padded_grid_stack.regular.map_to_2d_keep_padded(padded_array_1d=manual_blurred_image_1)
        manual_blurred_image_1 = psf.convolve(array=manual_blurred_image_1)

        manual_blurred_image_2 = tracer.source_plane.image_plane_image_1d_of_galaxies[0]
        manual_blurred_image_2 = padded_grid_stack.regular.map_to_2d_keep_padded(padded_array_1d=manual_blurred_image_2)
        manual_blurred_image_2 = psf.convolve(array=manual_blurred_image_2)
github Jammy2211 / PyAutoLens / workspace / howtolens / chapter_2_lens_modeling / scripts / tutorial_7_masking_and_positions.py View on Github external
def simulate():

    from autolens.data.array import grids
    from autolens.model.galaxy import galaxy as g
    from autolens.lens import ray_tracing

    psf = im.PSF.simulate_as_gaussian(shape=(11, 11), sigma=0.1, pixel_scale=0.1)

    image_plane_grids = grids.GridStack.grid_stack_for_simulation(shape=(130, 130), pixel_scale=0.1, psf_shape=(11, 11))

    lens_galaxy = g.Galaxy(mass=mp.SphericalIsothermal(centre=(0.0, 0.0), einstein_radius=1.6))
    source_galaxy = g.Galaxy(light=lp.SphericalExponential(centre=(0.0, 0.0), intensity=0.2, effective_radius=0.2))
    tracer = ray_tracing.TracerImageSourcePlanes(lens_galaxies=[lens_galaxy], source_galaxies=[source_galaxy],
                                                 image_plane_grid_stack=[image_plane_grids])

    image_simulated = im.CCD.simulate(array=tracer.image_plane_image_for_simulation, pixel_scale=0.1,
                                      exposure_time=300.0, psf=psf, background_sky_level=0.1, add_noise=True)

    return image_simulated
github Jammy2211 / PyAutoLens / autolens / model / galaxy / galaxy_model.py View on Github external
def is_light_profile_class(cls):
    """
    Parameters
    ----------
    cls
        Some object

    Returns
    -------
    bool: is_light_profile_class
        True if cls is a class that inherits from light profile
    """
    return inspect.isclass(cls) and issubclass(cls, light_profiles.LightProfile)
github Jammy2211 / PyAutoLens / workspace / howtolens / chapter_4_inversions / scripts / tutorial_7_adaptive_pixelization.py View on Github external
def simulate():

    from autolens.data.array import grids
    from autolens.model.galaxy import galaxy as g
    from autolens.lens import ray_tracing

    psf = ccd.PSF.simulate_as_gaussian(shape=(11, 11), sigma=0.05, pixel_scale=0.05)

    image_plane_grid_stack = grids.GridStack.grid_stack_for_simulation(shape=(150, 150), pixel_scale=0.05,
                                                                       psf_shape=(11, 11))

    lens_galaxy = g.Galaxy(mass=mp.EllipticalIsothermal(centre=(0.0, 0.0), axis_ratio=0.8, phi=45.0,
                                                        einstein_radius=1.6))
    source_galaxy = g.Galaxy(light=lp.EllipticalSersic(centre=(0.0, 0.0), axis_ratio=0.7, phi=135.0, intensity=0.2,
                                                       effective_radius=0.2, sersic_index=2.5))
    tracer = ray_tracing.TracerImageSourcePlanes(lens_galaxies=[lens_galaxy], source_galaxies=[source_galaxy],
                                                 image_plane_grid_stack=image_plane_grid_stack)

    return ccd.CCDData.simulate(array=tracer.image_plane_image_for_simulation, pixel_scale=0.05,
                                        exposure_time=300.0, psf=psf, background_sky_level=0.1, add_noise=True)
github Jammy2211 / PyAutoLens / workspace / howtolens / chapter_1_introduction / scripts / tutorial_9_summary.py View on Github external
# 6) The Universe's cosmology can be input into this tracer_without_subhalo to convert units to physical values.
# 7) The tracer_without_subhalo's regular-plane regular can be used to simulate strong lens ccd observed on a real telescope.
# 8) That this regular can be fitted, so to as quantify how well a model strong lens system represents the observed regular.

# In this summary, we'll consider how flexible the tools PyAutoLens gives you are to study every aspect of a strong
# lens system. Lets get a 'fit_normal' to a strong lens, by setting up an regular, masks, tracer_without_subhalo, etc.

path = 'path/to/AutoLens/howtolens/chapter_1_introduction' # Unfortunately, in a Jupyter notebook you have to manually specify the path to PyAutoLens and this tutorial.
path = '/home/jammy/PyCharm/Projects/AutoLens/workspace/howtolens/chapter_1_introduction'
image = im.load_ccd_data_from_fits(image_path=path + '/datas/regular.fits',
                                   noise_map_path=path+'/datas/noise_maps.fits',
                                   psf_path=path + '/datas/psf.fits', pixel_scale=0.1)
mask = ma.Mask.circular(shape=image.shape, pixel_scale=image.pixel_scale, radius_arcsec=3.0)
lensing_image = li.LensData(ccd_data=image, mask=mask)
lens_galaxy = g.Galaxy(mass=mp.EllipticalIsothermal(centre=(0.0, 0.0), einstein_radius=1.6, axis_ratio=0.7, phi=45.0))
source_galaxy = g.Galaxy(bulge=lp.EllipticalSersic(centre=(0.1, 0.1), axis_ratio=0.8, phi=45.0,
                                                  intensity=1.0, effective_radius=1.0, sersic_index=4.0),
                         disk=lp.EllipticalSersic(centre=(0.1, 0.1), axis_ratio=0.8, phi=45.0,
                                                  intensity=1.0, effective_radius=1.0, sersic_index=1.0))
tracer = ray_tracing.TracerImageSourcePlanes(lens_galaxies=[lens_galaxy], source_galaxies=[source_galaxy],
                                             image_plane_grid_stack=[lensing_image.grid_stack])
fit = lens_fit.fit_lens_image_with_tracer(lens_image=lensing_image, tracer=tracer)

# The fit_normal contains our tracer_without_subhalo, which contains our planes, which contain our grid_stacks and galaxies, which contain our
# profiles:
print(fit)
print()
print(fit.tracer)
print()
print(fit.tracer.image_plane)
print()
print(fit.tracer.source_plane)