def set_config_path(): conf.instance = conf.Config(path.join(directory, "files/plotter"), path.join(directory, "output"))
from autofit import conf from autofit.optimize import non_linear as nl from autolens.data import ccd from autolens.model.galaxy import galaxy, galaxy_model as gm from autolens.pipeline import phase as ph from autolens.pipeline import pipeline as pl from autolens.model.profiles import light_profiles as lp, mass_profiles as mp from test.integration import tools test_type = 'model_mapper' test_name = "align_phi" path = '{}/../../'.format(os.path.dirname(os.path.realpath(__file__))) output_path = path + 'output/' + test_type config_path = path + 'config' conf.instance = conf.Config(config_path=config_path, output_path=output_path) def pipeline(): 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.reset_paths(test_name=test_name, output_path=output_path) tools.simulate_integration_image(test_name=test_name,
# However, it comes with risks, and its important you develop an intuition for how this black magic works, so that you # know when it is and isn't appropriate to use it. # But, before we think about that, lets run two phase's - one without black magic, and one with black magic. These runs # will use the same prior config files (see 'chapter_2_lens_modeling/configs/7_multnest_black_magic'), thus any speed # up in our phase's is not due to prior tuning. # If you are using Docker, the paths to the chapter is as follows (e.g. comment out this line)! # path = '/home/user/workspace/howtolens/chapter_2_lens_modeling' # If you arn't using docker, you need to change the path below to the chapter 2 directory and uncomment it # path = '/path/to/user/workspace/howtolens/chapter_2_lens_modeling' path = '/home/jammy/PyCharm/Projects/AutoLens/workspace/howtolens/chapter_2_lens_modeling' conf.instance = conf.Config(config_path=path + '/configs/7_multinest_black_magic', output_path=path + "/output") # This function simulates the image we'll fit in this tutorial - which unlike previous tutorial images, also includes # the light-profile of the lens galaxy. 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.1, pixel_scale=0.1)
from autofit import conf import os path = '{}/../../'.format(os.path.dirname(os.path.realpath(__file__))) conf.instance = conf.Config(config_path=path + 'config', output_path=path + 'output') import autolens as al import pandas as pd import numpy as np from astropy import cosmology import matplotlib.pyplot as plt from pathlib import Path M_o = 1.989e30 cosmo = cosmology.FlatLambdaCDM(H0=70, Om0=0.3) slacs_path = '{}/../../dataset/slacs_data_table.xlsx'.format( os.path.dirname(os.path.realpath(__file__))) data_path = '{}/../../../../output/slacs'.format( os.path.dirname(os.path.realpath(__file__))) pipeline = '/pipeline_power_law_hyper__lens_bulge_disk_power_law__source_inversion__const' \ '/pipeline_tag__fix_lens_light__pix_voro_image__reg_adapt_bright__bd_align_centre__disk_sersic/'\ 'phase_1__lens_bulge_disk_power_law__source_inversion/'\ 'phase_tag__sub_2__pos_0.50/model.results' fig_path = '/Users/dgmt59/Documents/Plots/error_analysis/PL/shu_v_david_'
def set_config_path(): conf.instance = conf.Config(path.join(directory, "config"), path.join(directory, "output"))
# we're going to relax these assumptions and get back our more realistic lens model. The beauty is that, by running # the first phase, we can use its results to tune the priors of our second phase. For example: # 1) The first phase should give us a pretty good idea of the lens galaxy's light and mass profiles, for example its # intensity, effective radius and einstein radius. # 2) It should also give us a pretty good fit to the lensed source galaxy. This means we'll already know where in # source-plane its is located and what its intensity and effective are. # If you are using Docker, the paths to the chapter is as follows (e.g. comment out this line)! # path = '/home/user/workspace/howtolens/chapter_2_lens_modeling' # If you arn't using docker, you need to change the path below to the chapter 2 directory and uncomment it # path = '/path/to/user/workspace/howtolens/chapter_2_lens_modeling' path = '/home/jammy/PyCharm/Projects/AutoLens/workspace/howtolens/chapter_2_lens_modeling' conf.instance = conf.Config(config_path=path+'/configs/5_linking_phases', output_path=path+"/output") # Another simulate image function, for the same image again. 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=(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))
# [EllipticalSersic] # These are the priors used for an EllipticalSersic profile. # intensity=u,0.0,1.0 # Its intensity uses a UniformPrior with lower_limit=0.0, upper_limit=1.0 # effective_radius=u,0.0,2.0 # Its effective radius uses a UniformPrior with lower_limit=0.0, upper_limit=2.0 # sersic_index=g,4.0,2.0 # Its Sersic index uses a GaussianPrior with mean=4.0 and sigma=2.0 # Lets again setup the paths and config-overrides for this chapter, so the non-linear search runs fast. # If you are using Docker, the paths to the chapter is as follows (e.g. comment out this line)! # path = '/home/user/workspace/howtolens/chapter_2_lens_modeling' # If you arn't using docker, you need to change the path below to the chapter 2 directory and uncomment it # path = '/path/to/user/workspace/howtolens/chapter_2_lens_modeling' path = '/home/jammy/PyCharm/Projects/AutoLens/workspace/howtolens/chapter_2_lens_modeling' conf.instance = conf.Config(config_path=path + '/configs/2_parameter_space_and_priors', output_path=path + "/output") # This function simulates the image we'll fit in this tutorial - which is identical to the previous tutorial. 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.1, pixel_scale=0.1) image_plane_grid_stack = grids.GridStack.grid_stack_for_simulation(
def do_something(): print("{}/config/".format(directory)) conf.instance = conf.Config("{}/config/".format(directory))
def do_something(): conf.instance = conf.Config( "{}/../../test_files/configs/galaxy_model".format( os.path.dirname(os.path.realpath(__file__))))
def set_config_path(): conf.instance = conf.Config(path.join(directory, "config"), path.join(directory, "pipeline", "output")) return conf.instance
import os from autofit import conf from autofit.mapper import model_mapper as mm from autofit.mapper import prior from autofit.optimize import non_linear as nl from autolens.data import ccd from autolens.model.galaxy import galaxy, galaxy_model as gm from autolens.model.profiles import light_profiles as lp from autolens.pipeline import phase as ph from test.integration import tools dirpath = os.path.dirname(os.path.realpath(__file__)) conf.instance = conf.Config("{}/config".format(dirpath), "{}/output/".format(dirpath)) dirpath = os.path.dirname(dirpath) output_path = '{}/output'.format(dirpath) test_name = "test" class TestPhaseModelMapper(object): def test_pairing_works(self): test_name = 'pair_floats' tools.reset_paths(test_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)
# 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 even more complex models, with some 20-30+ non-linear parameters. # The goal of this, rather short, exercise, is to fit this 'realistic' model to a simulated image, where the lens's # light is visible and mass is elliptical. What could go wrong? # If you are using Docker, the paths to the chapter is as follows (e.g. comment out this line)! # path = '/home/user/workspace/howtolens/chapter_2_lens_modeling' # If you arn't using docker, you need to change the path below to the chapter 2 directory and uncomment it # path = '/path/to/user/workspace/howtolens/chapter_2_lens_modeling' path = '/home/jammy/PyCharm/Projects/AutoLens/workspace/howtolens/chapter_2_lens_modeling' conf.instance = conf.Config(config_path=path + '/configs/3_realism_and_complexity', output_path=path + "/output") # Another simulate image function, albeit it generates a new image 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=(130, 130), pixel_scale=0.1, psf_shape=(11, 11))
def do_something(): conf.instance = conf.Config( '{}/../test_files/configs/phase'.format(directory))
from autolens.model.profiles import light_profiles as lp from autolens.model.profiles import mass_profiles as mp from autolens.lens.plotters import lens_fit_plotters # We finished the last tutorial on a sour note. Our non-linear search failed miserably, and we were unable to infer a # lens model which fitted our realistic data-set well. In this tutorial, we're going to right our past wrongs and infer # the correct model - not just once, but three times! # If you are using Docker, the paths to the chapter is as follows (e.g. comment out this line)! # path = '/home/user/workspace/howtolens/chapter_2_lens_modeling' # If you arn't using docker, you need to change the path below to the chapter 2 directory and uncomment it # path = '/path/to/user/workspace/howtolens/chapter_2_lens_modeling' path = '/home/jammy/PyCharm/Projects/AutoLens/workspace/howtolens/chapter_2_lens_modeling' conf.instance = conf.Config(config_path=path + '/configs/4_dealing_with_failure', output_path=path + "/output") # Even with my custom config files - the non-linear searches will take a bit of time to run in this tutorial. Whilst you # are waiting, I would skip ahead to the cells ahead of the phase-run cells, and sit back and think about the comments, # there's a lot to take in in this tutorial so don't feel that you're in a rush! # Alternatively, set these running and come back in 10 minutes or so - MultiNest resumes from the existing results on # your hard-disk, so you can rerun things to get the results instantly! # Another simulate image function, albeit it generates a new image def simulate(): from autolens.data.array import grids from autolens.model.galaxy import galaxy as g
# This line overrides the configuration of the non-linear search such that it computes the solution really fast. To # do this, I've 'cheated' - I've computed the solution myself and then input it into the config. Nevertheless, it means # things will run fast for you, meaning you won't suffer long delays doing the tutorials. # # This will all become clear at the end of the chapter, so for now just bare in mind that we are taking a short-cut # to get our non-linear search to run fast! # If you are using Docker, the paths to the chapter is as follows (e.g. comment out this line)! # path = '/home/user/workspace/howtolens/chapter_2_lens_modeling' # If you arn't using docker, you need to change the path below to the chapter 2 directory and uncomment it # path = '/path/to/workspace/howtolens/chapter_2_lens_modeling' path = '/home/jammy/PyCharm/Projects/AutoLens/workspace/howtolens/chapter_2_lens_modeling' conf.instance = conf.Config(config_path=path + '/configs/1_non_linear_search', output_path=path + "/output") # This function simulates the image we'll fit in this tutorial. 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.1, pixel_scale=0.1) image_plane_grid_stack = grids.GridStack.grid_stack_for_simulation( shape=(130, 130), pixel_scale=0.1, psf_shape=(11, 11))