def test__positions_found_for_simple_mass_profiles(self): grid = al.Grid.uniform(shape_2d=(100, 100), pixel_scales=0.05) sis = al.mp.SphericalIsothermal(centre=(0.0, 0.0), einstein_radius=1.0) solver = al.PositionsFinder(grid=grid, pixel_scale_precision=0.01) positions = solver.solve(lensing_obj=sis, source_plane_coordinate=(0.0, 0.11)) assert positions[0] == pytest.approx(np.array([0.003125, -0.89062]), 1.0e-4) assert positions[1] == pytest.approx(np.array([-0.003125, -0.89062]), 1.0e-4) grid = al.Grid.uniform(shape_2d=(100, 100), pixel_scales=0.05, sub_size=1) g0 = al.Galaxy( redshift=0.5, mass=al.mp.EllipticalIsothermal( centre=(0.001, 0.001), einstein_radius=1.0, elliptical_comps=(0.0, 0.111111), ), ) g1 = al.Galaxy(redshift=1.0) tracer = al.Tracer.from_galaxies(galaxies=[g0, g1]) solver = pos.PositionsFinder(grid=grid, pixel_scale_precision=0.01) coordinates = solver.solve(lensing_obj=tracer, source_plane_coordinate=(0.0, 0.0)) assert coordinates.in_grouped_list[0][0] == pytest.approx( (1.028125, -0.003125), 1.0e-4) assert coordinates.in_grouped_list[0][1] == pytest.approx( (0.009375, -0.95312), 1.0e-4) assert coordinates.in_grouped_list[0][2] == pytest.approx( (0.009375, 0.95312), 1.0e-4) assert coordinates.in_grouped_list[0][3] == pytest.approx( (-1.028125, -0.003125), 1.0e-4)
path = "{}".format(os.path.dirname(os.path.realpath(__file__))) pickle_path = f"{path}/pickles" # %% """The initial grid for position solver which is upscaled iteratively by the solver.""" # %% grid = al.Grid.uniform( shape_2d=(200, 200), pixel_scales= 0.05, # <- The pixel-scale describes the conversion from pixel units to arc-seconds. ) """Use a _PositionsSolver_ which uses grid upscaling.""" solver = al.PositionsFinder(grid=grid, pixel_scale_precision=0.01, upscale_factor=3) iters = 50 for i in range(iters): tracer = al.Tracer.load(file_path=pickle_path, filename=f"tracer_{str(i)}") positions = solver.solve( lensing_obj=tracer, source_plane_coordinate=tracer.source_plane.galaxies[0].light.centre, ) positions_true = al.GridCoordinates.load(file_path=pickle_path, filename=f"positions_{str(i)}")
# %% """The initial grid for position solver which is upscaled iteratively by the solver.""" # %% grid = al.Grid.uniform( shape_2d=(2000, 2000), pixel_scales= 0.005, # <- The pixel-scale describes the conversion from pixel units to arc-seconds. ) """Use a `PositionsSolver` which uses grid upscaling.""" solver = al.PositionsFinder( grid=grid, use_upscaling=True, pixel_scale_precision=0.0000001, upscale_factor=2, distance_from_source_centre=0.1, ) iters = 50 for i in range(40, 41): tracer = al.Tracer.load(file_path=pickle_path, filename=f"tracer_{str(i)}") positions = solver.solve( lensing_obj=tracer, source_plane_coordinate=tracer.source_plane.galaxies[0].light.centre, )
def test__max_log_likelihood_tracer__multiple_image_positions_of_source_plane_centres_and_separations( self, imaging_7x7, mask_7x7): lens = al.Galaxy( redshift=0.5, mass=al.mp.EllipticalIsothermal( centre=(0.001, 0.001), einstein_radius=1.0, elliptical_comps=(0.0, 0.111111), ), ) source = al.Galaxy( redshift=1.0, light=al.lp.SphericalSersic(centre=(0.0, 0.0), intensity=2.0), light1=al.lp.SphericalSersic(centre=(0.0, 0.1), intensity=2.0), pixelization=al.pix.Rectangular((3, 3)), regularization=al.reg.Constant(coefficient=1.0), ) tracer = al.Tracer.from_galaxies(galaxies=[lens, source]) samples = mock.MockSamples(max_log_likelihood_instance=tracer) phase_dataset_7x7 = al.PhaseImaging( search=mock.MockSearch("test_phase_2", samples=samples)) result = phase_dataset_7x7.run(dataset=imaging_7x7, mask=mask_7x7, results=mock.MockResults()) mask = al.Mask2D.unmasked(shape_2d=(100, 100), pixel_scales=0.05, sub_size=1) result.analysis.masked_dataset.mask = mask multiple_images = ( result.image_plane_multiple_image_positions_of_source_plane_centres ) grid = al.Grid.from_mask(mask=mask) solver = al.PositionsFinder(grid=grid, pixel_scale_precision=0.001) multiple_images_manual_0 = solver.solve(lensing_obj=tracer, source_plane_coordinate=(0.0, 0.0)) multiple_images_manual_1 = solver.solve(lensing_obj=tracer, source_plane_coordinate=(0.0, 0.1)) multiple_images_manual_2 = solver.solve( lensing_obj=tracer, source_plane_coordinate=result.source_plane_inversion_centres[0], ) assert (multiple_images.in_grouped_list[0] == multiple_images_manual_0.in_grouped_list[0]) assert (multiple_images.in_grouped_list[1] == multiple_images_manual_1.in_grouped_list[0]) assert (multiple_images.in_grouped_list[2] == multiple_images_manual_2.in_grouped_list[0])
# %% mass_profile_model = af.PriorModel(al.mp.EllipticalIsothermal) mass_profile_model.centre.centre_0 = 0.0 mass_profile_model.centre.centre_1 = 0.0 mass_profile_model.elliptical_comps.ellipitical_comps_0 = af.UniformPrior( lower_limit=-1.0, upper_limit=1.0) mass_profile_model.elliptical_comps.ellipitical_comps_1 = af.UniformPrior( lower_limit=-1.0, upper_limit=1.0) mass_profile_model.centre.einstein_radius = af.UniformPrior(lower_limit=0.3, upper_limit=2.0) iters = 50 """Use a _PositionsSolver_ which does not use grid upscaling.""" solver = al.PositionsFinder(grid=grid, use_upscaling=True, upscale_factor=2) for i in range(iters): """Make a random _MassProfile_ instance from the priors defined above.""" mass_profile = mass_profile_model.random_instance() """ Only the _LightProfile_ centre is used by the position solver, but a light profile is used to visalize the lensed source. """ exponential_light_profile = al.lp.EllipticalExponential( centre=(0.0, 0.0), elliptical_comps=(0.2, 0.0), intensity=0.05, effective_radius=0.2,
light_profile_model = af.PriorModel(al.lp.EllipticalExponential) light_profile_model.centre.centre_0 = af.UniformPrior(lower_limit=-1.0, upper_limit=1.0) light_profile_model.centre.centre_1 = af.UniformPrior(lower_limit=-1.0, upper_limit=1.0) light_profile_model.elliptical_comps.elliptical_comps_0 = 0.2 light_profile_model.elliptical_comps.elliptical_comps_1 = 0.0 light_profile_model.intensity = 0.05 light_profile_model.effective_radius = 0.2 iters = 50 """Use a `PositionsSolver` which does not use grid upscaling.""" solver = al.PositionsFinder(grid=grid, use_upscaling=True, pixel_scale_precision=0.0001, upscale_factor=2) for i in range(iters): """Make a random `MassProfile` instance from the priors defined above.""" mass_profile = mass_profile_model.random_instance() """ Only the `LightProfile` centre is used by the position solver, but a light profile is used to visalize the lensed source. """ light_profile = light_profile_model.random_instance() """Setup the lens, source and _Tracer_.""" lens_galaxy = al.Galaxy(redshift=0.5, mass=mass_profile)