How to use the autolens.lensing.galaxy.Galaxy 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 / integration / lens_only / lens_x1_gal.py View on Github external
def pipeline():

    pipeline_name = "l1g"
    data_name = '/l1g'

    tools.reset_paths(data_name, pipeline_name, output_path)

    sersic = lp.EllipticalSersic(centre=(0.0, 0.0), axis_ratio=0.8, phi=90.0, intensity=1.0, effective_radius=1.3,
                                 sersic_index=3.0)

    lens_galaxy = galaxy.Galaxy(light_profile=sersic)

    tools.simulate_integration_image(data_name=data_name, pixel_scale=0.1, lens_galaxies=[lens_galaxy],
                                     source_galaxies=[], target_signal_to_noise=30.0)
    image = tools.load_image(data_name=data_name, pixel_scale=0.1)

    pipeline = make_pipeline(pipeline_name=pipeline_name)

    results = pipeline.run(image=image)
    for result in results:
        print(result)
github Jammy2211 / PyAutoLens / test / lensing / test_fitting.py View on Github external
[2.0, 5.0, 1.0],
                                             [3.0, 4.0, 0.0]])))
            im = image.Image(im, pixel_scale=1.0, psf=psf, noise=np.ones((5, 5)))
            ma = mask.Mask(array=np.array([[True, True,  True,  True,  True],
                                           [True, False, False, False, True],
                                           [True, False, False, False, True],
                                           [True, False, False, False, True],
                                           [True, True,  True,  True,  True]]), pixel_scale=1.0)
            mi = lensing_image.LensingImage(im, ma, sub_grid_size=1)

            hyper_model_image = np.array([1.0, 3.0, 5.0, 7.0, 9.0, 8.0, 6.0, 4.0, 0.0])
            hyper_galaxy_images = [np.array([1.0, 3.0, 5.0, 7.0, 9.0, 8.0, 6.0, 4.0, 0.0]),
                                   np.array([1.0, 3.0, 5.0, 7.0, 9.0, 8.0, 6.0, 4.0, 0.0])]
    
            hyper_galaxy = galaxy.HyperGalaxy(contribution_factor=4.0, noise_factor=2.0, noise_power=3.0)
            g0 = galaxy.Galaxy(light_profile=lp.EllipticalSersicLP(intensity=1.0),
                                        hyper_galaxy=hyper_galaxy)

            tracer = ray_tracing.TracerImageSourcePlanes(lens_galaxies=[g0], source_galaxies=[g0],
                                                         image_grids=mi.grids)

            fitter = fitting.HyperProfileFitter(lensing_image=mi, tracer=tracer, hyper_model_image=hyper_model_image, 
                                                hyper_galaxy_images=hyper_galaxy_images, hyper_minimum_values=[0.2, 0.8])

            image_im = tracer.image_plane_image
            blurring_im = tracer.image_plane_blurring_image
            blurred_im = mi.convolver_image.convolve_image(image_im, blurring_im)
            residuals = fitting.residuals_from_image_and_model(mi, blurred_im)
            chi_squareds = fitting.chi_squareds_from_residuals_and_noise(residuals, mi.noise)
            chi_squared_term = fitting.chi_squared_term_from_chi_squareds(chi_squareds)
            noise_term = fitting.noise_term_from_noise(mi.noise)
            likelihood = fitting.likelihood_from_chi_squared_and_noise_terms(chi_squared_term, noise_term)
github Jammy2211 / PyAutoLens / test / integration / model_mapper / align_phi.py View on Github external
def pipeline():
    pipeline_name = "align_phi"
    data_name = '/align_phi'

    tools.reset_paths(data_name, pipeline_name, output_path)

    sersic = lp.EllipticalSersic(centre=(0.0, 0.0), axis_ratio=0.8, phi=90.0, intensity=1.0, effective_radius=1.3,
                                 sersic_index=3.0)

    lens_galaxy = galaxy.Galaxy(light_profile=sersic)

    tools.simulate_integration_image(data_name=data_name, pixel_scale=0.5, lens_galaxies=[lens_galaxy],
                                     source_galaxies=[], target_signal_to_noise=10.0)
    image = tools.load_image(data_name=data_name, pixel_scale=0.5)

    pipeline = make_pipeline(pipeline_name=pipeline_name)

    results = pipeline.run(image=image)
    for result in results:
        print(result)
github Jammy2211 / PyAutoLens / test / autofit / test_model_mapper.py View on Github external
def test_instances_of_filtering(self):
        instance = model_mapper.ModelInstance()
        instance.galaxy_1 = g.Galaxy()
        instance.galaxy_2 = g.Galaxy()
        instance.other = galaxy_prior.GalaxyPrior()
        assert instance.instances_of(g.Galaxy) == [instance.galaxy_1, instance.galaxy_2]
github Jammy2211 / PyAutoLens / test / integration / lens_and_source_inversion / lens_x1_src_x1.py View on Github external
def test_lens_x1_src_x1_pix_pipeline():
    pipeline_name = "l1_s1"
    data_name = '/l1_s1'

    try:
        shutil.rmtree(dirpath + '/data' + data_name)
    except FileNotFoundError:
        pass

    lens_mass = mp.EllipticalIsothermal(centre=(0.01, 0.01), axis_ratio=0.8, phi=80.0, einstein_radius=1.6)
    source_light = lp.EllipticalSersic(centre=(-0.01, -0.01), axis_ratio=0.6, phi=90.0, intensity=1.0,
                                       effective_radius=0.5, sersic_index=1.0)

    lens_galaxy = galaxy.Galaxy(sie=lens_mass)
    source_galaxy = galaxy.Galaxy(sersic=source_light)

    tools.simulate_integration_image(data_name=data_name, pixel_scale=0.2, lens_galaxies=[lens_galaxy],
                                     source_galaxies=[source_galaxy], target_signal_to_noise=30.0)

    conf.instance.output_path = output_path

    try:
        shutil.rmtree(output_path + pipeline_name)
    except FileNotFoundError:
        pass

    pipeline = make_lens_x1_src_x1_pix_pipeline(pipeline_name=pipeline_name)
    image = tools.load_image(data_name=data_name, pixel_scale=0.2)

    results = pipeline.run(image=image)
github Jammy2211 / PyAutoLens / test / integration / lens_and_source / lens_x1_src_x1_hyper.py View on Github external
data_name = '/l1_s1_hyp'

    try:
        shutil.rmtree(dirpath + '/data' + data_name)
    except FileNotFoundError:
        pass

    lens_mass = mp.EllipticalIsothermal(centre=(0.01, 0.01), axis_ratio=0.8, phi=80.0, einstein_radius=1.6)

    source_bulge_0 = lp.EllipticalSersic(centre=(0.01, 0.01), axis_ratio=0.9, phi=90.0, intensity=1.0,
                                         effective_radius=1.0, sersic_index=4.0)

    source_bulge_1 = lp.EllipticalSersic(centre=(0.1, 0.1), axis_ratio=0.9, phi=90.0, intensity=1.0,
                                         effective_radius=1.0, sersic_index=4.0)

    lens_galaxy = galaxy.Galaxy(sie=lens_mass)
    source_galaxy = galaxy.Galaxy(bulge_0=source_bulge_0, bulge_1=source_bulge_1)

    tools.simulate_integration_image(data_name=data_name, pixel_scale=0.2, lens_galaxies=[lens_galaxy],
                                     source_galaxies=[source_galaxy], target_signal_to_noise=30.0)

    conf.instance.output_path = output_path

    try:
        shutil.rmtree(output_path + pipeline_name)
    except FileNotFoundError:
        pass

    pipeline = make_lens_x1_src_x1_profile_hyper_pipeline(pipeline_name=pipeline_name)
    image = tools.load_image(data_name=data_name, pixel_scale=0.2)

    results = pipeline.run(image=image)
github Jammy2211 / PyAutoLens / test / integration / model_mapper / pair_floats.py View on Github external
def pipeline():
    pipeline_name = "pair_floats"
    data_name = '/pair_floats'

    tools.reset_paths(data_name, pipeline_name, output_path)

    sersic = lp.EllipticalSersic(centre=(0.0, 0.0), axis_ratio=0.8, phi=90.0, intensity=1.0, effective_radius=1.3,
                                 sersic_index=3.0)

    lens_galaxy = galaxy.Galaxy(light_profile=sersic)

    tools.simulate_integration_image(data_name=data_name, pixel_scale=0.5, lens_galaxies=[lens_galaxy],
                                     source_galaxies=[], target_signal_to_noise=10.0)
    image = tools.load_image(data_name=data_name, pixel_scale=0.5)

    pf_pipeline = make_pipeline(pipeline_name=pipeline_name)

    results = pf_pipeline.run(image=image)
    for result in results:
        print(result)
github Jammy2211 / PyAutoLens / test / lensing / test_fitting.py View on Github external
def test__hyper_galaxy_adds_to_noise_term_for_scaled_noise__chi_squared_nonzero(self, no_galaxies, li_no_blur_1x1):
    
            li_no_blur_1x1[0] = 2.0
    
            g0 = galaxy.Galaxy(light_profile=MockLightProfile(value=1.0))
            g1 = galaxy.Galaxy(light_profile=MockLightProfile(value=0.0))
    
            tracer = ray_tracing.TracerImageSourcePlanes(lens_galaxies=[g0, g1], source_galaxies=no_galaxies,
                                                         image_grids=li_no_blur_1x1.grids)
    
            hyper_model_image = np.array([1.0])
            hyper_galaxy_images = [np.array([1.0]), np.array([1.0])]
    
            tracer.image_plane.galaxies[0].hyper_galaxy = MockHyperGalaxy(contribution_factor=0.0, noise_factor=1.0,
                                                                             noise_power=1.0)
            tracer.image_plane.galaxies[1].hyper_galaxy = MockHyperGalaxy(contribution_factor=0.0, noise_factor=2.0,
                                                                              noise_power=1.0)
    
            fitter = fitting.HyperProfileFitter(lensing_image=li_no_blur_1x1, tracer=tracer,
                                                hyper_model_image=hyper_model_image,
                                                hyper_galaxy_images=hyper_galaxy_images,
                                                hyper_minimum_values=[0.0, 0.0])
github Jammy2211 / PyAutoLens / test / integration / model_mapper / constant_float_then_tuple.py View on Github external
def pipeline():
    pipeline_name = "const_float_then_tuple"
    data_name = '/const_float_then_tuple'

    tools.reset_paths(data_name, pipeline_name, output_path)

    sersic = lp.EllipticalSersic(centre=(0.0, 0.0), axis_ratio=0.8, phi=90.0, intensity=1.0, effective_radius=1.3,
                                 sersic_index=3.0)

    lens_galaxy = galaxy.Galaxy(light_profile=sersic)

    tools.simulate_integration_image(data_name=data_name, pixel_scale=0.5, lens_galaxies=[lens_galaxy],
                                     source_galaxies=[], target_signal_to_noise=10.0)
    image = tools.load_image(data_name=data_name, pixel_scale=0.5)

    pipeline = make_pipeline(pipeline_name=pipeline_name)

    results = pipeline.run(image=image)
    for result in results:
        print(result)
github Jammy2211 / PyAutoLens / howtolens / 0_introduction / simulations_for_phase.py View on Github external
from autolens.lensing import galaxy as g
from autolens.lensing import ray_tracing
from autolens.imaging import image as im
from autolens.imaging import mask
from autolens.profiles import light_profiles as lp
from autolens.profiles import mass_profiles as mp
from autolens.plotting import imaging_plotters
import os

# This is the simulated image we fit in tutorial '8_phase'.

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

image_plane_grids = mask.ImagingGrids.grids_for_simulation(shape=(130, 130), pixel_scale=0.1, psf_shape=(11, 11))

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

image_simulated = im.PreparatoryImage.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)

path = "{}".format(os.path.dirname(os.path.realpath(__file__))) # Setup path so we can output the simulated data.
im.output_imaging_to_fits(image=image_simulated, image_path=path+'/data/8_phase_image.fits',
                                                 noise_map_path=path+'/data/8_phase_noise_map.fits',
                                                 psf_path=path+'/data/8_phase_psf.fits',
                          overwrite=True)

# This is the simulated image we fit in the exercise - 'compact_source'

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