Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def set_config_path():
conf.instance = conf.Config(
path.join(directory, "files/plotter"), path.join(directory, "output")
)
def do_something():
af.conf.instance = af.conf.Config(
"{}/../test_files/config/phase_imaging_7x7".format(directory)
)
def do_something():
af.conf.instance = af.conf.Config(
config_path="{}/../../test_files/config/radial_min".format(directory)
)
# create multiple galaxies which each contribute to the strong lensing. Multi-galaxy systems are challenging to
# model, because you're adding an extra 5-10 parameters to the non-linear search and, more problematically, the
# degeneracies between the mass-profiles of the two galaxies can be severe.
# However, we can nevertheless break the analysis down using a pipeline and give ourselves a shot at getting a good
# lens model. The approach we're going to take is we're going to fit as much about each individual lens galaxy
# first, before fitting them simultaneously.
# Up to now, I've put a focus on pipelines being generalizeable. The pipeline we write in this example is going to be
# the opposite - specific to the image we're modeling. Fitting multiple lens galaxies is really difficult and
# writing a pipeline that we can generalize to many lenses isn't currently possible with PyAutoLens.
# To setup the config and output paths without docker, you need to uncomment and run the command below. If you are
# using Docker, you don't need to do anything so leave this uncommented!
path = '{}/../../'.format(os.path.dirname(os.path.realpath(__file__)))
conf.instance = conf.Config(config_path=path+'config', output_path=path+'output')
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=(180, 180), pixel_scale=0.05, psf_shape=(11, 11))
lens_galaxy_0 = g.Galaxy(light=lp.EllipticalSersic(centre=(0.0, -1.0), axis_ratio=0.8, phi=55.0, intensity=0.1,
effective_radius=0.8, sersic_index=2.5),
mass=mp.EllipticalIsothermal(centre=(1.0, 0.0), axis_ratio=0.7, phi=45.0,
einstein_radius=1.0))
# Up to now, all of the image that we fitted had only one lens galaxy. However, we saw in chapter 1 that we can
# create multiple galaxies which each contribute to the strong lensing. Multi-galaxy systems are challenging to
# model, because you're adding an extra 5-10 parameters to the non-linear search and, more problematically, the
# degeneracies between the mass-profiles of the two galaxies can be severe.
# However, we can nevertheless break the analysis down using a pipeline and give ourselves a shot at getting a good
# lens model. The approach we're going to take is we're going to fit as much about each individual lens galaxy
# first, before fitting them simultaneously.
# Up to now, I've put a focus on pipelines being general. The pipeline we write in this example is going to be
# the opposite - specific to the image we're modeling. Fitting multiple lens galaxies is really difficult and
# writing a pipeline that we can generalize to many lenses isn't currently possible with PyAutoLens.
# Lets setup the path to the workspace, config and output folders, as per usual.
path = '{}/../../../'.format(os.path.dirname(os.path.realpath(__file__)))
conf.instance = conf.Config(config_path=path+'config', output_path=path+'output')
# This rather long simulate function generates an image with two strong lens galaxies.
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=(180, 180), pixel_scale=0.05,
psf_shape=(11, 11))
lens_galaxy_0 = g.Galaxy(light=lp.EllipticalSersic(centre=(0.0, -1.0), axis_ratio=0.8, phi=55.0, intensity=0.1,
effective_radius=0.8, sersic_index=2.5),
mass=mp.EllipticalIsothermal(centre=(1.0, 0.0), axis_ratio=0.7, phi=45.0,
# pipelines that come distributed with PyAutoLens.
# The runner is supplied as both this Python script and a Juypter notebook. Its up to you which you use - I personally
# prefer the python script as provided you keep it relatively small, its quick and easy to comment out different lens
# names and pipelines to set off different analyses. However, notebooks are a tidier way to manage visualization - so
# feel free to use notebooks. Or, use both for a bit, and decide your favourite!
# The pipeline runner is fairly self explanatory. Make sure to checkout the pipelines in the
# _workspace/pipelines/examples/_ folder - they come with detailed descriptions of what they do! I hope that you'll
# expand on them for your own personal scientific needs
# Get the relative path to the config files and output folder in our workspace.
path = '{}/../'.format(os.path.dirname(os.path.realpath(__file__)))
# Use this path to explicitly set the config path and output path.
conf.instance = conf.Config(config_path=path+'config', output_path=path+'output')
# It is convenient to specify the lens name as a string, so that if the pipeline is applied to multiple images we \
# don't have to change all of the path entries in the load_ccd_data_from_fits function below.
lens_name = 'no_lens_light_and_x2_source' # An example simulated image with lens light emission and a source galaxy.
pixel_scale = 0.1
ccd_data = ccd.load_ccd_data_from_fits(image_path=path + '/data/example/' + lens_name + '/image.fits',
psf_path=path+'/data/example/'+lens_name+'/psf.fits',
noise_map_path=path+'/data/example/'+lens_name+'/noise_map.fits',
pixel_scale=pixel_scale)
ccd_plotters.plot_ccd_subplot(ccd_data=ccd_data)
# Running a pipeline is easy, we simply import it from the pipelines folder and pass the lens data to its run function.
# Below, we'll' use a 3 phase example pipeline to fit the data with a parametric lens light, mass and source light
# 1) An elliptical Sersic light-profile for the lens model_galaxy's light.
# 2) A singular isothermal ellipsoid (SIE) mass-profile for the lens model_galaxy's mass.
# 3) An elliptical exponential light-profile for the source model_galaxy's light (to be honest, even this is a gross
# over-simplification, but lets worry about that later).
# This has a total of 18 non-linear parameters, which is over double the number of parameters we've fitted up to now.
# In future exercises, we'll fit_normal even more complex models, with some 20-30+ non-linear parameters.
# The goal of this, rather short, exercise, is to fit_normal this 'realistic' model to a simulated regular, where the lens's
# light is visible and mass is elliptical. What could go wrong?
#Setup the path for this run
path = '{}/../'.format(os.path.dirname(os.path.realpath(__file__)))
# Setup the config to this tutorial, so the non-linear sea
conf.instance = conf.Config(config_path=path+'/configs/3_realism_and_complexity', output_path=path+"output")
# Another simulate regular function, albeit it generates a new regular
def simulate():
from autolens.data.array import grids
from autolens.model.galaxy import galaxy as g
from autolens.lensing import ray_tracing
psf = im.PSF.simulate_as_gaussian(shape=(11, 11), sigma=0.05, pixel_scale=0.05)
image_plane_grids = grids.DataGrids.grids_for_simulation(shape=(130, 130), pixel_scale=0.1, psf_shape=(11, 11))
lens_galaxy = g.Galaxy(light=lp.EllipticalSersic(centre=(0.0, 0.0), axis_ratio=0.9, phi=45.0, intensity=0.04,
effective_radius=0.5, sersic_index=3.5),
mass=mp.EllipticalIsothermal(centre=(0.0, 0.0), axis_ratio=0.8, phi=45.0, einstein_radius=0.8))
source_galaxy = g.Galaxy(light=lp.EllipticalSersic(centre=(0.0, 0.0), axis_ratio=0.5, phi=90.0, intensity=0.03,
from autolens.model.profiles import light_profiles as lp
from autolens.model.profiles import mass_profiles as mp
from autolens.model.galaxy import galaxy as g
from autolens.pipeline import phase as ph
from autolens.data.ccd.plotters import imaging_plotters
import os
# Now that we've learnt all the tools that we need to model strong lenses, I'm going to quickly cover how you should
# choose your masks and show you a neat trick to improve the speed and accuracy of your non-linear search. We'll skip
# running non-linear searches this tutorial - you've spent long enough waiting for non-linear searches to run
# (of course, you can run them yourself if you're really keen)!
# This path isn't really necessary, but it stops the tutorial polluting your workspace/output folder.
path = '{}/../'.format(os.path.dirname(os.path.realpath(__file__)))
conf.instance = conf.Config(config_path=conf.CONFIG_PATH, output_path=path+"output")
# Lets simulate the simple regular we've used throughout this chapter again.
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])
import os
# In this example, we'll generate a phase which fits a simple lens + source plane system. Whilst I would generally
# recommend that you write pipelines when using PyAutoLens, it can be convenient to sometimes perform non-linear
# searches in one phase to get results quickly.
# Get the relative path to the config files and output folder in our workspace.
path = '{}/../../'.format(os.path.dirname(os.path.realpath(__file__)))
# There is a x2 '/../../' because we are in the 'workspace/scripts/examples' folder. If you write your own script \
# in the 'workspace/script' folder you should remove one '../', as shown below.
# path = '{}/../'.format(os.path.dirname(os.path.realpath(__file__)))
# Use this path to explicitly set the config path and output papth
conf.instance = conf.Config(config_path=path+'config', output_path=path+'output')
# It is convinient to specify the lens name as a string, so that if the pipeline is applied to multiple images we \
# don't have to change all of the path entries in the load_ccd_data_from_fits function below.
lens_name = 'lens_light_and_x1_source'
ccd_data = ccd.load_ccd_data_from_fits(image_path=path + '/data/example/' + lens_name + '/image.fits', pixel_scale=0.1,
psf_path=path+'/data/example/'+lens_name+'/psf.fits',
noise_map_path=path+'/data/example/'+lens_name+'/noise_map.fits')
# The phase can be passed a mask, which we setup below as a 3.0" circle.
mask = msk.Mask.circular(shape=ccd_data.shape, pixel_scale=ccd_data.pixel_scale, radius_arcsec=3.0)
# We can also specify a set of positions, which must be traced within a threshold value or else the mass model is
positions = ccd.load_positions(positions_path=path + '/data/example/' + lens_name + '/positions.dat')
# resampled (see howtolens/chapter_2_lens_modeling/tutorial_7_masking_and_positions.ipynb)