def __init__(self, lens_data, tracer_normal, tracer_sensitive): """Evaluate the sensitivity of a profile fit to a specific component of a lens model and tracer. This is \ performed by evaluating the likelihood of a fit to an image using two tracers: 1) A 'normal tracer', which uses the same lens model as a the simulated lens data. This gives a baseline \ value of the likelihood we can expect when we fit the model to itself. 2) A 'sensitive tracer', which uses the same lens model as the simulated lens data, but also includes the \ additional model components (e.g. a mass clump 'subhalo') which we are testing our sensitivity to. The difference in likelihood of these two fits informs us of how sensitive we are to the component in the \ second tracer. For example, if the difference in likelihood is neglible, it means the model component had no \ impact on our fit, meaning we are not sensitive to its properties. Parameters ---------- lens_data: lens_data.LensData A simulated lens data which is used to determine our sensitiivity to specific model components. tracer_normal : ray_tracing.Tracer A tracer whose galaxies have the same model components (e.g. light profiles, mass profiles) as the \ lens data that we are fitting. tracer_sensitive : ray_tracing.AbstractTracerNonStack A tracer whose galaxies have the same model components (e.g. light profiles, mass profiles) as the \ lens data that we are fitting, but also addition components (e.g. mass clumps) which we measure \ how sensitive we are too. """ AbstractSensitivityFit.__init__(self=self, tracer_normal=tracer_normal, tracer_sensitive=tracer_sensitive) self.fit_normal = lens_fit.LensProfileFit(lens_data=lens_data, tracer=tracer_normal) self.fit_sensitive = lens_fit.LensProfileFit(lens_data=lens_data, tracer=tracer_sensitive)
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
convolver=lens_data.convolver_image) blurred_profile_image = lens_data.map_to_scaled_array( array_1d=blurred_profile_image_1d) diff = time.time() - start print("Time to perform PSF convolution = {}".format(diff / repeats)) start = time.time() for i in range(repeats): lens_fit.LensDataFit(image=lens_data.image_1d, noise_map=lens_data.noise_map_1d, mask=lens_data.mask_1d, model_image=blurred_profile_image_1d) diff = time.time() - start print("Time to perform fit (1D) = {}".format(diff / repeats)) start = time.time() for i in range(repeats): lens_fit.LensDataFit(image=lens_data.image, noise_map=lens_data.noise_map, mask=lens_data.mask, model_image=blurred_profile_image) diff = time.time() - start print("Time to perform fit (2D) = {}".format(diff / repeats)) start = time.time() for i in range(repeats): lens_fit.LensProfileFit(lens_data=lens_data, tracer=tracer) diff = time.time() - start print("Time to perform complete fit = {}".format(diff / repeats)) print()
def test__simulate_lensed_source_and_fit__include_psf_blurring__chi_squared_is_0__noise_normalization_correct( ): psf = ccd.PSF.simulate_as_gaussian(shape=(3, 3), pixel_scale=0.2, sigma=0.75) grid_stack = grids.GridStack.grid_stack_for_simulation(shape=(11, 11), pixel_scale=0.2, psf_shape=psf.shape, sub_grid_size=1) lens_galaxy = g.Galaxy(light=lp.EllipticalSersic(centre=(0.1, 0.1), intensity=0.1), mass=mp.EllipticalIsothermal(centre=(0.1, 0.1), einstein_radius=1.8)) source_galaxy = g.Galaxy( light=lp.EllipticalExponential(centre=(0.1, 0.1), intensity=0.5)) tracer = ray_tracing.TracerImageSourcePlanes( lens_galaxies=[lens_galaxy], source_galaxies=[source_galaxy], image_plane_grid_stack=grid_stack) ccd_simulated = ccd.CCDData.simulate( array=tracer.image_plane_image_for_simulation, pixel_scale=0.2, exposure_time=300.0, psf=psf, background_sky_level=None, add_noise=False) ccd_simulated.noise_map = np.ones(ccd_simulated.image.shape) path = "{}/data/simulate_and_fit".format( os.path.dirname(os.path.realpath( __file__))) # Setup path so we can output the simulated image. try: shutil.rmtree(path) except FileNotFoundError: pass if os.path.exists(path) == False: os.makedirs(path) array_util.numpy_array_to_fits(array=ccd_simulated.image, file_path=path + '/image.fits') array_util.numpy_array_to_fits(array=ccd_simulated.noise_map, file_path=path + '/noise_map.fits') array_util.numpy_array_to_fits(array=psf, file_path=path + '/psf.fits') ccd_data = ccd.load_ccd_data_from_fits(image_path=path + '/image.fits', noise_map_path=path + '/noise_map.fits', psf_path=path + '/psf.fits', pixel_scale=0.2) mask = msk.Mask.circular(shape=ccd_data.image.shape, pixel_scale=0.2, radius_arcsec=0.8) lens_data = ld.LensData(ccd_data=ccd_data, mask=mask, sub_grid_size=1) tracer = ray_tracing.TracerImageSourcePlanes( lens_galaxies=[lens_galaxy], source_galaxies=[source_galaxy], image_plane_grid_stack=lens_data.grid_stack) fitter = lens_fit.LensProfileFit(lens_data=lens_data, tracer=tracer) assert fitter.chi_squared == pytest.approx(0.0, 1e-4)