Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_pipeline():
pipeline_name = "l2g_hyp"
data_name = '/l2g_hyp'
tools.reset_paths(data_name, pipeline_name, output_path)
bulge_0 = lp.EllipticalSersic(centre=(-1.0, -1.0), axis_ratio=0.9, phi=90.0, intensity=1.0,
effective_radius=1.0, sersic_index=4.0)
disk_0 = lp.EllipticalSersic(centre=(-1.0, -1.0), axis_ratio=0.6, phi=90.0, intensity=20.0,
effective_radius=2.5, sersic_index=1.0)
bulge_1 = lp.EllipticalSersic(centre=(1.0, 1.0), axis_ratio=0.9, phi=90.0, intensity=1.0,
effective_radius=1.0, sersic_index=4.0)
disk_1 = lp.EllipticalSersic(centre=(1.0, 1.0), axis_ratio=0.6, phi=90.0, intensity=20.0,
effective_radius=2.5, sersic_index=1.0)
lens_galaxy_0 = galaxy.Galaxy(bulge=bulge_0, disk=disk_0)
lens_galaxy_1 = galaxy.Galaxy(bulge=bulge_1, disk=disk_1)
tools.simulate_integration_image(data_name=data_name, pixel_scale=0.2, lens_galaxies=[lens_galaxy_0, lens_galaxy_1],
source_galaxies=[], target_signal_to_noise=50.0)
pipeline = make_pipeline(pipeline_name=pipeline_name)
image = tools.load_image(data_name=data_name, pixel_scale=0.2)
results = pipeline.run(image=image)
for result in results:
print(result)
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)
def pipeline():
pipeline_name = "l1_s1_pos"
data_name = '/l1_s1_pos'
tools.reset_paths(data_name, pipeline_name, output_path)
lens_mass = mp.SphericalIsothermal(centre=(0.01, 0.01), einstein_radius=1.0)
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_pipeline(pipeline_name=pipeline_name)
def make_pipeline(pipeline_name):
class MMPhase(ph.LensPlanePhase):
def pass_priors(self, previous_results):
self.lens_galaxies[0].sersic.axis_ratio = 0.2
self.lens_galaxies[0].sersic.phi = 90.0
self.lens_galaxies[0].sersic.centre_0 = 1.0
self.lens_galaxies[0].sersic.centre_1 = 2.0
phase1 = MMPhase(lens_galaxies=[gm.GalaxyModel(sersic=lp.EllipticalSersic)],
optimizer_class=nl.MultiNest, phase_name="{}/phase1".format(pipeline_name))
phase1.optimizer.n_live_points = 20
phase1.optimizer.sampling_efficiency = 0.8
return pl.PipelineImaging(pipeline_name, phase1)
def pass_priors(self, previous_results):
self.lens_galaxies[0].sersic.axis_ratio = 0.2
self.lens_galaxies[0].sersic.phi = 90.0
phase1 = MMPhase(lens_galaxies=[gm.GalaxyModel(sersic=lp.EllipticalSersic)],
optimizer_class=nl.MultiNest, phase_name="{}/phase1".format(pipeline_name))
phase1.optimizer.n_live_points = 20
phase1.optimizer.sampling_efficiency = 0.8
class MMPhase2(ph.LensPlanePhase):
def pass_priors(self, previous_results):
self.lens_galaxies = previous_results[0].variable.lens_galaxies
phase2 = MMPhase2(lens_galaxies=[gm.GalaxyModel(sersic=lp.EllipticalSersic)],
optimizer_class=nl.MultiNest, phase_name="{}/phase2".format(pipeline_name))
phase2.optimizer.n_live_points = 20
phase2.optimizer.sampling_efficiency = 0.8
return pl.PipelineImaging(pipeline_name, phase1, phase2)
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)
def pipeline():
pipeline_name = "link_variable_with_constants_to_tuples"
data_name = '/link_variable_constants_to_tuples'
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)
def make_pipeline(pipeline_name):
def modify_mask_function(img):
return msk.Mask.circular(shape=img.shape, pixel_scale=img.pixel_scale, radius_mask_arcsec=5.)
class LensPlaneGalaxy0Phase(ph.LensPlanePhase):
def pass_priors(self, previous_results):
self.lens_galaxies[0].sersic.centre_0 = -1.0
self.lens_galaxies[0].sersic.centre_1 = -1.0
phase1 = LensPlaneGalaxy0Phase(lens_galaxies=[gm.GalaxyModel(sersic=lp.EllipticalSersic)],
mask_function=modify_mask_function, optimizer_class=nl.MultiNest,
phase_name="{}/phase1".format(pipeline_name))
phase1.optimizer.n_live_points = 40
phase1.optimizer.sampling_efficiency = 0.8
class LensPlaneGalaxy1Phase(ph.LensPlanePhase):
def pass_priors(self, previous_results):
self.lens_galaxies[0] = previous_results[0].constant.lens_galaxies[0]
self.lens_galaxies[1].sersic.centre_0 = 1.0
self.lens_galaxies[1].sersic.centre_1 = 1.0
phase2 = LensPlaneGalaxy1Phase(lens_galaxies=[gm.GalaxyModel(sersic=lp.EllipticalSersic),
gm.GalaxyModel(sersic=lp.EllipticalSersic)],
mask_function=modify_mask_function, optimizer_class=nl.MultiNest,
phase_name="{}/phase2".format(pipeline_name))
# with AutoLens (see the phase/basic.py example).
# First, lets setup the PSF we are going to blur our simulated image with, using a Gaussian profile on an 11x11 grid.
psf = image.PSF.simulate_as_gaussian(shape=(11, 11), sigma=0.75)
# plt.imshow(psf)
# plt.show()
# We need to set up the grids of Cartesian coordinates we will use to perform ray-tracing. The function below
# sets these grids up using the shape and pixel-scale of the image we will ultimately simulate. The PSF shape is
# required to ensure that edge-effects do not impact PSF blurring later in the simulation.
lensing_grids = grids.LensingGrids.padded_grids_for_simulation(shape=(100, 100), pixel_scale=0.07, psf_shape=psf.shape)
# Use the 'galaxy' module (imported as 'g'), 'light_profiles' module (imported as 'lp') and 'mass profiles' module
# (imported as 'mp') to setup the lens galaxy. The lens below has an elliptical Sersic light profile and singular
# isothermal ellipsoid (SIE) mass profile.
lens_galaxy = g.Galaxy(light=lp.EllipticalSersic(centre=(0.0, 0.0), axis_ratio=0.9, phi=45.0, intensity=0.1,
effective_radius=0.8, sersic_index=3.0),
mass=mp.EllipticalIsothermal(centre=(0.0, 0.0), axis_ratio=0.8, phi=40.0, einstein_radius=1.8))
# Use the above modules to setup the source galaxy, which in this example has an elliptical Exponential profile.
source_galaxy = g.Galaxy(light=lp.EllipticalExponential(centre=(0.0, 0.0), axis_ratio=0.9, phi=90.0, intensity=0.5,
effective_radius=0.3))
# Pass these galaxies into the 'ray_tracing' module, in this particular case a tracer which has both an image and source
# plane. Using the lens galaxy's mass profile(s), deflection-angle and ray-tracing calculations are performed to
# setup the source-plane.
tracer = ray_tracing.TracerImageSourcePlanes(lens_galaxies=[lens_galaxy], source_galaxies=[source_galaxy],
image_grids=lensing_grids)
# The tracer class has lots of in-built properties for extracting different images in our lensing system. In this case,
# we want to extract the image-plane image of our lens and source galaxies - lets have a look at what it looks like.
class CustomPhase(ph.LensSourcePlanePhase):
def pass_priors(self, previous_results):
self.lens_galaxies[0].mass.centre_0 = 0.1
self.lens_galaxies[0].mass.centre_1 = 0.1
self.lens_galaxies[0].mass.einstein_radius = model_mapper.UniformPrior(lower_limit=1.4, upper_limit=1.8)
def mask_function(img):
return mask.Mask.annular(img.shape, pixel_scale=img.pixel_scale, inner_radius_arcsec=0.4,
outer_radius_arcsec=2.8)
phase = CustomPhase(lens_galaxies=[gm.GalaxyModel(light=lp.EllipticalSersic, mass=mp.EllipticalIsothermal)],
source_galaxies=[gm.GalaxyModel(light=lp.EllipticalSersic)],
optimizer_class=non_linear.MultiNest, phase_name='phase0')
results = phase.run(image)
fitting_plotters.plot_fitting(fit=results.fit)
# If a phase has already begun running at its specified path, the analysis resumes from where it was terminated.
# The folder must be manually deleted to start from scratch. So, if you run this script again, you'll notice the
# results appear immediately!
results_1 = phase.run(image)
print(results_1) # NOTE - this isn't working yet, need to sort out.
fitting_plotters.plot_fitting(fit=results_1.fit)