def make_fit_lens_only(lens_data, galaxy_light): tracer = ray_tracing.TracerImagePlane( lens_galaxies=[galaxy_light], image_plane_grid_stack=lens_data.grid_stack, cosmology=cosmo.Planck15) return lens_fit.fit_lens_data_with_tracer(lens_data=lens_data, tracer=tracer)
def make_fit(lens_data, galaxy_light, galaxy_mass): tracer = ray_tracing.TracerImageSourcePlanes( lens_galaxies=[galaxy_mass], source_galaxies=[galaxy_light], image_plane_grid_stack=lens_data.grid_stack, cosmology=cosmo.Planck15) return lens_fit.fit_lens_data_with_tracer(lens_data=lens_data, tracer=tracer)
def perform_fit_with_lens_and_source_galaxy(lens_galaxy, source_galaxy): ccd_data = simulate() mask = msk.Mask.circular_annular(shape=ccd_data.shape, pixel_scale=ccd_data.pixel_scale, inner_radius_arcsec=0.5, outer_radius_arcsec=2.2) lens_data = ld.LensData(ccd_data=ccd_data, mask=mask) tracer = ray_tracing.TracerImageSourcePlanes( lens_galaxies=[lens_galaxy], source_galaxies=[source_galaxy], image_plane_grid_stack=lens_data.grid_stack, border=lens_data.border) return lens_fit.fit_lens_data_with_tracer(lens_data=lens_data, tracer=tracer)
def perform_fit_with_source_galaxy(source_galaxy): ccd_data = simulate() mask = msk.Mask.circular_annular(shape=ccd_data.shape, pixel_scale=ccd_data.pixel_scale, inner_radius_arcsec=0.5, outer_radius_arcsec=2.2) lens_data = ld.LensData(ccd_data=ccd_data, mask=mask) lens_galaxy = g.Galaxy(mass=mp.EllipticalIsothermal( centre=(0.0, 0.0), axis_ratio=0.8, phi=135.0, einstein_radius=1.6)) tracer = ray_tracing.TracerImageSourcePlanes( lens_galaxies=[lens_galaxy], source_galaxies=[source_galaxy], image_plane_grid_stack=lens_data.grid_stack, border=lens_data.border) return lens_fit.fit_lens_data_with_tracer(lens_data=lens_data, tracer=tracer)
def perform_fit_with_source_galaxy_mask_and_border(source_galaxy, mask, use_border): ccd_data = simulate() lens_data = ld.LensData(ccd_data=ccd_data, mask=mask) lens_galaxy = g.Galaxy(mass=mp.EllipticalIsothermal( centre=(0.0, 0.0), axis_ratio=0.8, phi=135.0, einstein_radius=1.6)) if use_border: border = lens_data.border else: border = None tracer = ray_tracing.TracerImageSourcePlanes( lens_galaxies=[lens_galaxy], source_galaxies=[source_galaxy], image_plane_grid_stack=lens_data.grid_stack, border=border) return lens_fit.fit_lens_data_with_tracer(lens_data=lens_data, tracer=tracer)
def perform_fit_x2_lenses_with_source_galaxy_mask_and_border( source_galaxy, mask, use_border): simulate_image_x2_lenses() lens_data = ld.LensData(ccd_data=ccd_data, mask=mask) lens_galaxy_0 = g.Galaxy(mass=mp.EllipticalIsothermal( centre=(1.1, 0.51), axis_ratio=0.9, phi=110.0, einstein_radius=1.07)) lens_galaxy_1 = g.Galaxy(mass=mp.EllipticalIsothermal( centre=(-0.20, -0.35), axis_ratio=0.56, phi=16.0, einstein_radius=0.71)) if use_border: border = lens_data.border else: border = None tracer = ray_tracing.TracerImageSourcePlanes( lens_galaxies=[lens_galaxy_0, lens_galaxy_1], source_galaxies=[source_galaxy], image_plane_grid_stack=lens_data.grid_stack, border=border) return lens_fit.fit_lens_data_with_tracer(lens_data=lens_data, tracer=tracer)
intensity=0.03, effective_radius=0.3, sersic_index=3.5)) source_galaxy_3 = g.Galaxy(light=lp.EllipticalSersic(centre=(-0.05, -0.0), axis_ratio=0.9, phi=140.0, intensity=0.03, effective_radius=0.1, sersic_index=4.0)) tracer = ray_tracing.TracerImageSourcePlanes( lens_galaxies=[lens_galaxy], source_galaxies=[ source_galaxy_0, source_galaxy_1, source_galaxy_2, source_galaxy_3 ], image_plane_grid_stack=lens_data.grid_stack) true_fit = lens_fit.fit_lens_data_with_tracer(lens_data=lens_data, tracer=tracer) lens_fit_plotters.plot_fit_subplot(fit=true_fit) # And indeed, we see far improved residuals, chi-squareds, etc. # The morale of this story is that, if the source morphology is complex, there is no way we can build a pipeline to # fit it. For this tutorial, this was true even though our source model could actually fit the data perfectly. For # real lenses, the source will be *even more complex* and there is even less hope of getting a good fit :( # But fear not, PyAutoLens has you covered. In chapter 4, we'll introduce a completely new way to model the source # galaxy, which addresses the problem faced here. But before that, in the next tutorial we'll discuss how we actually # pass priors in a pipeline.
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, effective_radius=0.3, sersic_index=3.0)) tracer = ray_tracing.TracerImageSourcePlanes( lens_galaxies=[lens_galaxy], source_galaxies=[source_galaxy], image_plane_grid_stack=lens_data.grid_stack) # Now, lets fit the lensing image with the tracer and plot the fit. It looks a lot better than above, doesn't it? correct_fit = lens_fit.fit_lens_data_with_tracer(lens_data=lens_data, tracer=tracer) lens_fit_plotters.plot_fit_subplot(fit=correct_fit, should_plot_mask=True, extract_array_from_mask=True, zoom_around_mask=True) # Finally, just to be sure, lets compare the two likelihoods print('Likelihood of Non-linear Search:') print(results.most_likely_fit.likelihood) print('Likelihood of Correct Model:') print(correct_fit.likelihood) # Well, there we have it, the input model has a much higher likelihood than the one our non-linear search inferred. # Clearly, our non-linear search failed. So, what happened? Where did it all go wrong?