def test_duplication(self): phase = ph.LensSourcePlanePhase(lens_galaxies=[gm.GalaxyModel()], source_galaxies=[gm.GalaxyModel()], phase_name='test_phase') ph.LensSourcePlanePhase(phase_name='test_phase') assert phase.lens_galaxies is not None assert phase.source_galaxies is not None
def make_pipeline(test_name): phase1 = ph.LensSourcePlanePhase(lens_galaxies=dict(lens=gm.GalaxyModel(mass=mp.EllipticalIsothermal)), source_galaxies=dict(source_0=gm.GalaxyModel(sersic=lp.EllipticalSersic)), optimizer_class=nl.MultiNest, phase_name="{}/phase1".format(test_name)) phase1.optimizer.const_efficiency_mode = True phase1.optimizer.n_live_points = 60 phase1.optimizer.sampling_efficiency = 0.7 class AddSourceGalaxyPhase(ph.LensSourcePlanePhase): def pass_priors(self, previous_results): self.lens_galaxies_lens = previous_results[0].variable.lens self.source_galaxies_source_0 = previous_results[0].variable.source_0 phase2 = AddSourceGalaxyPhase(lens_galaxies=dict(lens=gm.GalaxyModel(mass=mp.EllipticalIsothermal)), source_galaxies=dict(source_0=gm.GalaxyModel(sersic=lp.EllipticalSersic), source_1=gm.GalaxyModel(sersic=lp.EllipticalSersic)), optimizer_class=nl.MultiNest, phase_name="{}/phase2".format(test_name)) phase2.optimizer.const_efficiency_mode = True phase2.optimizer.n_live_points = 60 phase2.optimizer.sampling_efficiency = 0.7 return pl.PipelineImaging(test_name, phase1, phase2)
def test_fit(self, ccd_data): clean_images() phase = ph.LensSourcePlanePhase( optimizer_class=NLO, lens_galaxies=[gm.GalaxyModel(light=lp.EllipticalSersic)], source_galaxies=[gm.GalaxyModel(light=lp.EllipticalSersic)], phase_name='test_phase') result = phase.run(data=ccd_data) assert isinstance(result.constant.lens_galaxies[0], g.Galaxy) assert isinstance(result.constant.source_galaxies[0], g.Galaxy)
def test__tracer_for_instance__includes_cosmology(self, ccd_data): lens_galaxy = g.Galaxy() source_galaxy = g.Galaxy() phase = ph.LensPlanePhase(lens_galaxies=[lens_galaxy], cosmology=cosmo.FLRW, phase_name='test_phase') analysis = phase.make_analysis(ccd_data) instance = phase.constant tracer = analysis.tracer_for_instance(instance) padded_tracer = analysis.padded_tracer_for_instance(instance) assert tracer.image_plane.galaxies[0] == lens_galaxy assert tracer.cosmology == cosmo.FLRW assert padded_tracer.image_plane.galaxies[0] == lens_galaxy assert padded_tracer.cosmology == cosmo.FLRW phase = ph.LensSourcePlanePhase(lens_galaxies=[lens_galaxy], source_galaxies=[source_galaxy], cosmology=cosmo.FLRW, phase_name='test_phase') analysis = phase.make_analysis(ccd_data) instance = phase.constant tracer = analysis.tracer_for_instance(instance) padded_tracer = analysis.padded_tracer_for_instance(instance) assert tracer.image_plane.galaxies[0] == lens_galaxy assert tracer.source_plane.galaxies[0] == source_galaxy assert tracer.cosmology == cosmo.FLRW assert padded_tracer.image_plane.galaxies[0] == lens_galaxy assert padded_tracer.source_plane.galaxies[0] == source_galaxy assert padded_tracer.cosmology == cosmo.FLRW galaxy_0 = g.Galaxy(redshift=0.1) galaxy_1 = g.Galaxy(redshift=0.2) galaxy_2 = g.Galaxy(redshift=0.3) phase = ph.MultiPlanePhase(galaxies=[galaxy_0, galaxy_1, galaxy_2], cosmology=cosmo.WMAP7, phase_name='test_phase') analysis = phase.make_analysis(ccd_data) instance = phase.constant tracer = analysis.tracer_for_instance(instance) padded_tracer = analysis.padded_tracer_for_instance(instance) assert tracer.planes[0].galaxies[0] == galaxy_0 assert tracer.planes[1].galaxies[0] == galaxy_1 assert tracer.planes[2].galaxies[0] == galaxy_2 assert tracer.cosmology == cosmo.WMAP7 assert padded_tracer.planes[0].galaxies[0] == galaxy_0 assert padded_tracer.planes[1].galaxies[0] == galaxy_1 assert padded_tracer.planes[2].galaxies[0] == galaxy_2 assert padded_tracer.cosmology == cosmo.WMAP7
def make_pipeline(test_name): phase1 = ph.LensSourcePlanePhase( lens_galaxies=dict(lens=gm.GalaxyModel(mass=mp.EllipticalIsothermal)), source_galaxies=dict(source=gm.GalaxyModel(light=lp.EllipticalSersic)), optimizer_class=nl.MultiNest, phase_name="{}/phase1".format(test_name)) phase1.optimizer.const_efficiency_mode = True phase1.optimizer.n_live_points = 60 phase1.optimizer.sampling_efficiency = 0.8 return pl.PipelineImaging(test_name, phase1)
def make_pipeline(pipeline_name): # This is the same phase 1 as the complex source pipeline, which we saw gave a good fit to the overall # structure of the lensed source and provided an accurate lens mass model. phase1 = ph.LensSourcePlanePhase( lens_galaxies=dict(lens=gm.GalaxyModel(mass=mp.EllipticalIsothermal)), source_galaxies=dict(source=gm.GalaxyModel(light=lp.EllipticalSersic)), optimizer_class=nl.MultiNest, phase_name=pipeline_name + '/phase_1_initialize') phase1.optimizer.sampling_efficiency = 0.3 phase1.optimizer.const_efficiency_mode = True # Now, in phase 2, lets use the lens mass model to fit the source with an inversion. class InversionPhase(ph.LensSourcePlanePhase): def pass_priors(self, previous_results): # We can customize the inversion's priors like we do our light and mass profiles. self.lens_galaxies.lens = previous_results[0].variable.lens self.source_galaxies.source.pixelization.shape_0 = mm.UniformPrior( lower_limit=20.0, upper_limit=40.0) self.source_galaxies.source.pixelization.shape_1 = mm.UniformPrior( lower_limit=20.0, upper_limit=40.0) # The expected value of the regularization coefficient depends on the details of the data reduction and # source galaxy. A broad log-uniform prior is thus an appropriate way to sample the large range of # possible values. self.source_galaxies.source.regularization.coefficients_0 = mm.LogUniformPrior( lower_limit=1.0e-6, upper_limit=10000.0) phase2 = InversionPhase( lens_galaxies=dict(lens=gm.GalaxyModel(mass=mp.EllipticalIsothermal)), source_galaxies=dict(source=gm.GalaxyModel( pixelization=pix.Rectangular, regularization=reg.Constant)), optimizer_class=nl.MultiNest, phase_name=pipeline_name + '/phase_2_inversion') phase2.optimizer.sampling_efficiency = 0.3 phase2.optimizer.const_efficiency_mode = True return pipeline.PipelineImaging(pipeline_name, phase1, phase2)
def test__fit_figure_of_merit__matches_correct_fit_given_galaxy_profiles( self, ccd_data): lens_galaxy = g.Galaxy(light=lp.EllipticalSersic(intensity=0.1)) source_galaxy = g.Galaxy( pixelization=pix.Rectangular(shape=(4, 4)), regularization=reg.Constant(coefficients=(1.0, ))) phase = ph.LensPlanePhase(lens_galaxies=[lens_galaxy], mask_function=ph.default_mask_function, cosmology=cosmo.FLRW, phase_name='test_phase') analysis = phase.make_analysis(data=ccd_data) instance = phase.constant fit_figure_of_merit = analysis.fit(instance=instance) mask = phase.mask_function(image=ccd_data.image) lens_data = li.LensData(ccd_data=ccd_data, mask=mask) tracer = analysis.tracer_for_instance(instance=instance) fit = lens_fit.LensProfileFit(lens_data=lens_data, tracer=tracer) assert fit.likelihood == fit_figure_of_merit phase = ph.LensSourcePlanePhase(lens_galaxies=[lens_galaxy], source_galaxies=[source_galaxy], mask_function=ph.default_mask_function, cosmology=cosmo.FLRW, phase_name='test_phase') analysis = phase.make_analysis(data=ccd_data) instance = phase.constant fit_figure_of_merit = analysis.fit(instance=instance) mask = phase.mask_function(image=ccd_data.image) lens_data = li.LensData(ccd_data=ccd_data, mask=mask) tracer = analysis.tracer_for_instance(instance=instance) fit = lens_fit.LensProfileInversionFit(lens_data=lens_data, tracer=tracer) assert fit.evidence == fit_figure_of_merit
def make_pipeline(test_name): phase1 = ph.LensSourcePlanePhase( lens_galaxies=[gm.GalaxyModel(sie=mp.EllipticalIsothermal)], source_galaxies=[gm.GalaxyModel(sersic=lp.EllipticalSersic)], optimizer_class=nl.MultiNest, phase_name="{}/phase1".format(test_name)) phase1.optimizer.const_efficiency_mode = True phase1.optimizer.n_live_points = 60 phase1.optimizer.sampling_efficiency = 0.8 phase1h = ph.LensMassAndSourceProfileHyperOnlyPhase( optimizer_class=nl.MultiNest, phase_name="{}/phase1h".format(test_name)) class SourceHyperPhase(ph.LensSourcePlaneHyperPhase): def pass_priors(self, previous_results): phase1_results = previous_results[-1] phase1h_results = previous_results[-1].hyper # self.lens_galaxies[0] = previous_results[-1].variable.lens_galaxies[0] self.source_galaxies = phase1_results.variable.source_galaxies self.source_galaxies[ 0].hyper_galaxy = phase1h_results.constant.source_galaxies[ 0].hyper_galaxy phase2 = SourceHyperPhase( lens_galaxies=dict(lens=gm.GalaxyModel(mass=mp.EllipticalIsothermal)), source_galaxies=dict(source=gm.GalaxyModel(light=lp.EllipticalSersic)), optimizer_class=nl.MultiNest, phase_name="{}/phase2".format(test_name)) phase2.optimizer.const_efficiency_mode = True phase2.optimizer.n_live_points = 40 phase2.optimizer.sampling_efficiency = 0.8 return pl.PipelineImaging(test_name, phase1, phase1h, phase2)
def make_pipeline(test_name): phase1 = ph.LensSourcePlanePhase( lens_galaxies=dict(lens=gm.GalaxyModel(mass=mp.EllipticalIsothermal)), source_galaxies=dict(source_0=gm.GalaxyModel( sersic=lp.EllipticalSersic)), optimizer_class=nl.MultiNest, phase_name="{}/phase1".format(test_name)) phase1.optimizer.const_efficiency_mode = True phase1.optimizer.n_live_points = 60 phase1.optimizer.sampling_efficiency = 0.7 phase1h = ph.LensMassAndSourceProfileHyperOnlyPhase( optimizer_class=nl.MultiNest, phase_name="{}/phase1h".format(test_name)) class AddSourceGalaxyPhase(ph.LensSourcePlaneHyperPhase): def pass_priors(self, previous_results): phase1_results = previous_results[-1] phase1h_results = previous_results[-1].hyper self.lens_galaxies.lens = phase1_results.variable.lens self.source_galaxies.source_0 = phase1_results.variable.source_0 self.source_galaxies.source_0.hyper_galaxy = phase1h_results.constant.source_0.hyper_galaxy phase2 = AddSourceGalaxyPhase( lens_galaxies=dict(lens=gm.GalaxyModel(mass=mp.EllipticalIsothermal)), source_galaxies=dict( source_0=gm.GalaxyModel(sersic=lp.EllipticalSersic), source_1=gm.GalaxyModel(sersic=lp.EllipticalSersic)), optimizer_class=nl.MultiNest, phase_name="{}/phase2".format(test_name)) phase2.optimizer.const_efficiency_mode = True phase2.optimizer.n_live_points = 60 phase2.optimizer.sampling_efficiency = 0.7 phase2h = ph.LensMassAndSourceProfileHyperOnlyPhase( optimizer_class=nl.MultiNest, phase_name="{}/phase1h".format(test_name)) class BothSourceGalaxiesPhase(ph.LensSourcePlaneHyperPhase): def pass_priors(self, previous_results): phase2_results = previous_results[1] phase2h_results = previous_results[1].hyper self.lens_galaxies.lens = phase2_results.variable.lens self.source_galaxies.source_0 = phase2_results.variable.source_0 self.source_galaxies.source_1 = phase2_results.variable.source_1 self.source_galaxies.source_0.hyper_galaxy = phase2h_results.constant.source_0.hyper_galaxy self.source_galaxies.source_1.hyper_galaxy = phase2h_results.constant.source_1.hyper_galaxy phase3 = BothSourceGalaxiesPhase( lens_galaxies=dict(lens=gm.GalaxyModel(mass=mp.EllipticalIsothermal)), source_galaxies=dict( source_0=gm.GalaxyModel(sersic=lp.EllipticalSersic), source_1=gm.GalaxyModel(sersic=lp.EllipticalSersic)), optimizer_class=nl.MultiNest, phase_name="{}/phase3".format(test_name)) return pl.PipelineImaging(test_name, phase1, phase1h, phase2, phase2h, phase3)
extract_array_from_mask=True, zoom_around_mask=True) # When we run the phase, we don't pass it the mask as an array. Instead, we pass it the mask as a function. The reason # for this will become clear in the next chapter, but for now I would say you just accept this syntax. def mask_function(): return msk.Mask.circular_annular(shape=ccd_data.shape, pixel_scale=ccd_data.pixel_scale, inner_radius_arcsec=0.6, outer_radius_arcsec=2.4) phase_with_custom_mask = ph.LensSourcePlanePhase( lens_galaxies=dict(lens=gm.GalaxyModel()), source_galaxies=dict(source=gm.GalaxyModel()), mask_function=mask_function, # <- We input the mask function here optimizer_class=nl.MultiNest, phase_name='phase') # So, our mask encompasses the lensed source galaxy. However, is this really the right sized mask? Do we actually want # a bigger mask? a smaller mask? # When it comes to masking, we are essentially balancing run-speed and accuracy. If speed wasn't a consideration, # bigger masks would *always* be better, for two reasons: # 1) The lensed source galaxy may have very faint emission that when you look at the plot above you don't notice. # Overly aggressive masking risks you masking out some of that light - data which would better constrain your # lens model! # 2) When you fit an image with a model image, the fit is performed only within the masked region. Outside of the # masked region it is possible that the model image produces some source-galaxy light in a region of the image
# When we plot it, the lens light's is clealy visible in the centre of the image ccd_plotters.plot_ccd_subplot(ccd_data=ccd_data) # Now lets fit it using a phase, noting that indeed the galaxy-model corresponds to the one above. # Because we now have 18 non-linear parameters, the non-linear search takes a lot longer to run. On my laptop, this # phase took around an hour, which is a bit too long for you to wait if you want to go through these tutorials quickly. # Therefore, as discussed before, I've included the results of this non-linear search already, allowing you to # go through the tutorial as if you had actually run them. # Nevertheless, you could try running it yourself (maybe over your lunch break?). All you need to do is change the # phase_name below, maybe to something like 'howtolens/3_realism_and_complexity_rerun' phase = ph.LensSourcePlanePhase( lens_galaxies=dict(lens_galaxy=gm.GalaxyModel( light=lp.EllipticalSersic, mass=mp.EllipticalIsothermal)), source_galaxies=dict(source_galaxy=gm.GalaxyModel( light=lp.EllipticalExponential)), optimizer_class=nl.MultiNest, phase_name='3_realism_and_complexity') # Lets run the phase. print( 'MultiNest has begun running - checkout the workspace/howtolens/chapter_2_lens_modeling/output/3_realism_and_complexity' 'folder for live output of the results, images and lens model.' 'This Jupyter notebook cell with progress once MultiNest has completed - this could take some time!' ) results = phase.run(data=ccd_data) print('MultiNest has finished run - you may now continue the notebook.') # And lets look at the image. lens_fit_plotters.plot_fit_subplot(fit=results.most_likely_fit,
# We're going to model our lens galaxy using a light profile (an elliptical Sersic) and mass profile # (a singular isothermal ellipsoid). We load these profiles from the 'light_profiles (lp)' and 'mass_profiles (mp)'. # To setup our model galaxies, we use the 'galaxy_model' module and GalaxyModel class. # A GalaxyModel represents a galaxy where the parameters of its associated profiles are # variable and fitted for by the analysis. lens_galaxy_model = gm.GalaxyModel(light=lp.EllipticalSersic, mass=mp.EllipticalIsothermal) source_galaxy_model = gm.GalaxyModel(light=lp.EllipticalSersic) # To perform the analysis, we set up a phase using the 'phase' module (imported as 'ph'). # A phase takes our galaxy models and fits their parameters using a non-linear search (in this case, MultiNest). phase = ph.LensSourcePlanePhase( lens_galaxies=dict(lens=gm.GalaxyModel(light=lp.EllipticalSersic, mass=mp.EllipticalIsothermal, shear=mp.ExternalShear)), source_galaxies=dict(source=gm.GalaxyModel(light=lp.EllipticalSersic)), optimizer_class=nl.MultiNest, phase_name='example/phase_non_pipeline') # You'll see these lines throughout all of the example pipelines. They are used to make MultiNest sample the \ # non-linear parameter space faster (if you haven't already, checkout the tutorial '' in howtolens/chapter_2). phase.optimizer.const_efficiency_mode = True phase.optimizer.n_live_points = 50 phase.optimizer.sampling_efficiency = 0.5 # We run the phase on the image, print the results and plot the fit. result = phase.run(data=ccd_data) lens_fit_plotters.plot_fit_subplot(fit=result.most_likely_fit)
# In approaches 1 and 2, we extended our non-linear search an olive branch and generously helped it find the highest # likelihood regions of parameter space. In approach 3 ,we're going to be stern with our non-linear search, and tell it # 'look harder'. # Basically, every non-linear search algorithm has a set of parameters that govern how thoroughly it searches parameter # space. The more thoroughly it looks, the more likely it is that it'll find the global maximum lens model. However, # the search will also take longer - and we don't want it to take too long to get some results. # Lets setup a phase, and overwrite some of the non-linear search's parameters from the defaults it assumes in the # 'config/non_linear.ini' config file: custom_non_linear_phase = ph.LensSourcePlanePhase( lens_galaxies=dict(lens=gm.GalaxyModel(light=lp.EllipticalSersic, mass=mp.EllipticalIsothermal)), source_galaxies=dict(source=gm.GalaxyModel( light=lp.EllipticalExponential)), optimizer_class=nl.MultiNest, phase_name='4_custom_non_linear') # The 'optimizer' below is MultiNest, the non-linear search we're using. # When MultiNest searches non-linear parameter space, it places down a set of 'live-points', each of which corresponds # to a particular lens model (set of parameters) and each has an associted likelihood. If it guesses a new lens model with a # higher likelihood than any of the currently active live points, this new lens model will become an active point. As a # result, the active point with the lowest likelihood is discarded. # The more live points MultiNest uses, the more thoroughly it will sample parameter space. Lets increase the number of # points from the default value (50) to 100. custom_non_linear_phase.optimizer.n_live_points = 100
# Lets model the source galaxy with a spherical exponential light profile (again, what it was simulated with). source_galaxy_model = gm.GalaxyModel(light=lp.SphericalExponential) # A phase takes our galaxy models and fits their parameters via a non-linear search (in this case, MultiNest). In this # example, we have a lens-plane and source-plane, so we use a LensSourcePlanePhase. # (Just like we could give profiles descriptive names, like 'light', 'bulge' and 'disk', we can do the exact same # thing with galaxies. This is very good practise - as once we start using complex lens models, you could potentially # have a lot of galaxies - and this is the best way to keep track of them!) # (also, just ignore the 'dict' - its necessary syntax but not something you need to concern yourself with) phase = ph.LensSourcePlanePhase( lens_galaxies=dict(lens_galaxy=lens_galaxy_model), source_galaxies=dict(source_galaxy=source_galaxy_model), optimizer_class=non_linear.MultiNest, phase_name='1_non_linear_search') # To run the phase, we simply pass it the image data we want to fit, and the non-linear search begins! As the phase # runs, a logger will show you the parameters of the best-fit model. print( 'MultiNest has begun running - checkout the workspace/howtolens/chapter_2_lens_modeling/output/1_non_linear_search' 'folder for live output of the results, images and lens model.' 'This Jupyter notebook cell with progress once MultiNest has completed - this could take some time!' ) results = phase.run(data=ccd_data) print('MultiNest has finished run - you may now continue the notebook.') # Now this has run you should checkout the 'AutoLens/workspace/howtolens/chapter_2_lens_modeling/output' folder. # This is where the results of the phase are written to your hard-disk (in the '1_non_linear_search' folder).
def make_pipeline(pipeline_path=''): pipeline_name = 'pipeline_complex_source' pipeline_path = pipeline_path + pipeline_name # To begin, we need to initialize the lens's mass model. We should be able to do this by using a simple source # model. It won't fit the complicated structure of the source, but it'll give us a reasonable estimate of the # einstein radius and the other lens-mass parameters. # This should run fine without any prior-passes. In general, a thick, giant ring of source light is something we # can be confident MultiNest will fit without much issue, especially when the lens galaxy's light isn't included # such that the parameter space is just 12 parameters. phase1 = ph.LensSourcePlanePhase( lens_galaxies=dict(lens=gm.GalaxyModel(mass=mp.EllipticalIsothermal)), source_galaxies=dict(source=gm.GalaxyModel( light_0=lp.EllipticalSersic)), optimizer_class=nl.MultiNest, phase_name=pipeline_path + '/phase_1_simple_source') phase1.optimizer.const_efficiency_mode = True phase1.optimizer.n_live_points = 40 phase1.optimizer.sampling_efficiency = 0.5 # Now lets add another source component, using the previous model as the initialization on the lens / source # parameters. We'll vary the parameters of the lens mass model and first source galaxy component during the fit. class X2SourcePhase(ph.LensSourcePlanePhase): def pass_priors(self, previous_results): self.lens_galaxies.lens = previous_results[0].variable.lens self.source_galaxies.source.light_0 = previous_results[ 0].variable.source.light_0 # You'll notice I've stop writing 'phase_1_results = previous_results[0]' - we know how # the previous results are structured now so lets not clutter our code! phase2 = X2SourcePhase( lens_galaxies=dict(lens=gm.GalaxyModel(mass=mp.EllipticalIsothermal)), source_galaxies=dict(source=gm.GalaxyModel( light_0=lp.EllipticalExponential, light_1=lp.EllipticalSersic)), optimizer_class=nl.MultiNest, phase_name=pipeline_path + '/phase_2_x2_source') phase2.optimizer.const_efficiency_mode = True phase2.optimizer.n_live_points = 40 phase2.optimizer.sampling_efficiency = 0.5 # Now lets do the same again, but with 3 source galaxy components. class X3SourcePhase(ph.LensSourcePlanePhase): def pass_priors(self, previous_results): self.lens_galaxies.lens = previous_results[1].variable.lens self.source_galaxies.source.light_0 = previous_results[ 1].variable.source.light_0 self.source_galaxies.source.light_1 = previous_results[ 1].variable.source.light_1 phase3 = X3SourcePhase( lens_galaxies=dict(lens=gm.GalaxyModel(mass=mp.EllipticalIsothermal)), source_galaxies=dict( source=gm.GalaxyModel(light_0=lp.EllipticalExponential, light_1=lp.EllipticalSersic, light_2=lp.EllipticalSersic)), optimizer_class=nl.MultiNest, phase_name=pipeline_path + '/phase_3_x3_source') phase3.optimizer.const_efficiency_mode = True phase3.optimizer.n_live_points = 50 phase3.optimizer.sampling_efficiency = 0.5 # And one more for luck! class X4SourcePhase(ph.LensSourcePlanePhase): def pass_priors(self, previous_results): self.lens_galaxies.lens = previous_results[2].variable.lens self.source_galaxies.source.light_0 = previous_results[ 2].variable.source.light_0 self.source_galaxies.source.light_1 = previous_results[ 2].variable.source.light_1 self.source_galaxies.source.light_2 = previous_results[ 2].variable.source.light_2 phase4 = X4SourcePhase( lens_galaxies=dict(lens=gm.GalaxyModel(mass=mp.EllipticalIsothermal)), source_galaxies=dict( source=gm.GalaxyModel(light_0=lp.EllipticalExponential, light_1=lp.EllipticalSersic, light_2=lp.EllipticalSersic, light_3=lp.EllipticalSersic)), optimizer_class=nl.MultiNest, phase_name=pipeline_path + '/phase_4_x4_source') phase4.optimizer.const_efficiency_mode = True phase4.optimizer.n_live_points = 50 phase4.optimizer.sampling_efficiency = 0.5 return pipeline.PipelineImaging(pipeline_path, phase1, phase2, phase3, phase4)
return ccd_simulated # Simulate the image and set it up. ccd_data = simulate() ccd_plotters.plot_ccd_subplot(ccd_data=ccd_data) # Lets first run the phase without black magic, which is performed using the standard lines of code we're used to. # A word of warning, this phase takes >1 hour to run... so if you get bored, skip the run cell below continue to the # phase with black magic (afterall, the whole point of this tutorial is how slow MultiNest can run, so theres no harm # if the slow run speed bores you to tears :P). phase_normal = ph.LensSourcePlanePhase( lens_galaxies=dict(lens=gm.GalaxyModel(light=lp.EllipticalSersic, mass=mp.EllipticalIsothermal)), source_galaxies=dict(source=gm.GalaxyModel(light=lp.EllipticalSersic)), optimizer_class=nl.MultiNest, phase_name='7_no_black_magic') # We're going to use the time module to time how long each MultiNest run takes. However, if you resume the MultiNest # run from a previous job, this time won't be accurate. Fortunately, if you look in the folder # 'howtolens/chapter_2_lens_modeling/output/7_no_black_magic') you'll find a file 'run_time' which gives the overall # run-time including any resumes. start = time.time() # Lets run the phase - the run-time will be output to the output/7_multinest_black_magic/ print( 'MultiNest has begun running - checkout the workspace/howtolens/chapter_2_lens_modeling/output/7_multinest_black_magic' ' folder for live output of the results, images and lens model.' ' This Jupyter notebook cell with progress once MultiNest has completed - this could take some time!'
def make_phase(): return ph.LensSourcePlanePhase(optimizer_class=NLO, mask_function=ph.default_mask_function, phase_name='test_phase')