def test__solver_for_tracer_method__multiple_source_planes_or_galaxies(self): grid = al.Grid.uniform(shape_2d=(50, 50), pixel_scales=0.05, sub_size=4) g0 = al.Galaxy( redshift=0.5, mass=al.mp.EllipticalIsothermal( centre=(0.0, 0.0), einstein_radius=1.0, elliptical_comps=(0.0, 0.055555) ), ) g1 = al.Galaxy( redshift=1.0, light_0=al.lp.EllipticalLightProfile(centre=(0.0, 0.0)), light_1=al.lp.EllipticalLightProfile(centre=(0.1, 0.1)), ) tracer = al.Tracer.from_galaxies(galaxies=[g0, g1]) solver = pos.PositionsSolver(grid=grid, pixel_scale_precision=0.01) position_manual_0 = solver.solve( lensing_obj=tracer, source_plane_coordinate=(0.0, 0.0) ) position_manual_1 = solver.solve( lensing_obj=tracer, source_plane_coordinate=(0.1, 0.1) ) positions = solver.solve_from_tracer(tracer=tracer) assert position_manual_0.in_grouped_list[0] == positions.in_grouped_list[0] assert position_manual_1.in_grouped_list[0] == positions.in_grouped_list[1] g2 = al.Galaxy( redshift=1.0, light=al.lp.EllipticalLightProfile(centre=(0.0, 0.0)) ) g3 = al.Galaxy( redshift=1.0, light=al.lp.EllipticalLightProfile(centre=(0.1, 0.1)) ) tracer = al.Tracer.from_galaxies(galaxies=[g0, g2, g3]) solver = pos.PositionsSolver(grid=grid, pixel_scale_precision=0.01) positions = solver.solve_from_tracer(tracer=tracer) assert position_manual_0.in_grouped_list[0] == positions.in_grouped_list[0] assert position_manual_1.in_grouped_list[0] == positions.in_grouped_list[1]
def test__same_as_above_using_solver_for_tracer_method(self): 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, light=al.lp.EllipticalLightProfile(centre=(0.0, 0.0)) ) tracer = al.Tracer.from_galaxies(galaxies=[g0, g1]) solver = pos.PositionsSolver(grid=grid, pixel_scale_precision=0.01) coordinates = solver.solve_from_tracer(tracer=tracer) 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 )
def test__positions_found_for_multi_plane_tracer(self): grid = al.Grid2D.uniform(shape_native=(100, 100), pixel_scales=0.05, sub_size=1) g0 = al.Galaxy( redshift=0.5, mass=al.mp.EllIsothermal( centre=(0.001, 0.001), einstein_radius=1.0, elliptical_comps=(0.0, 0.111111), ), ) g1 = al.Galaxy(redshift=1.0) g2 = al.Galaxy(redshift=2.0) tracer = al.Tracer.from_galaxies(galaxies=[g0, g1, g2]) solver = pos.PositionsSolver(grid=grid, pixel_scale_precision=0.01) coordinates_to_plane_2 = solver.solve(lensing_obj=tracer, source_plane_coordinate=(0.0, 0.0)) coordinates_to_plane_1 = solver.solve(lensing_obj=tracer, source_plane_coordinate=(0.0, 0.0), upper_plane_index=1) assert coordinates_to_plane_1[0][0] != coordinates_to_plane_2[0][0] scaling_factor = al.util.cosmology.scaling_factor_between_redshifts_from( redshift_0=0.5, redshift_1=1.0, redshift_final=2.0, cosmology=tracer.cosmology, ) assert coordinates_to_plane_1[0][0] == pytest.approx( coordinates_to_plane_2[0][0] * scaling_factor, 1.0e-1) coordinates_to_plane_2_with_index = solver.solve( lensing_obj=tracer, source_plane_coordinate=(0.0, 0.0), upper_plane_index=2) assert coordinates_to_plane_2[0][ 0] == coordinates_to_plane_2_with_index[0][0]
def test__positions_found_for_simple_mass_profiles(self): grid = al.Grid2D.uniform(shape_native=(100, 100), pixel_scales=0.05) sis = al.mp.SphIsothermal(centre=(0.0, 0.0), einstein_radius=1.0) solver = al.PositionsSolver(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.890625]), 1.0e-4) assert positions[3] == pytest.approx(np.array([-0.003125, 1.109375]), 1.0e-4) grid = al.Grid2D.uniform(shape_native=(100, 100), pixel_scales=0.05, sub_size=1) g0 = al.Galaxy( redshift=0.5, mass=al.mp.EllIsothermal( 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.PositionsSolver(grid=grid, pixel_scale_precision=0.01) coordinates = solver.solve(lensing_obj=tracer, source_plane_coordinate=(0.0, 0.0)) assert coordinates.in_list[0] == pytest.approx((1.028125, -0.003125), 1.0e-4) assert coordinates.in_list[1] == pytest.approx((0.009375, -0.95312), 1.0e-4) assert coordinates.in_list[2] == pytest.approx((0.009375, 0.95312), 1.0e-4) assert coordinates.in_list[3] == pytest.approx((-1.028125, -0.003125), 1.0e-4)
def image_plane_multiple_image_positions( self, ) -> grid_2d_irregular.Grid2DIrregular: """ Backwards ray-trace the source-plane centres (see above) to the image-plane via the mass model, to determine the multiple image position of the source(s) in the image-plane. These image-plane positions are used by the next search in a pipeline if automatic position updating is turned on.""" # TODO : In the future, the multiple image positions functioon wil use an in-built adaptive grid. grid = self.analysis.dataset.mask.unmasked_grid_sub_1 solver = pos.PositionsSolver(grid=grid, pixel_scale_precision=0.001) multiple_images = solver.solve( lensing_obj=self.max_log_likelihood_tracer, source_plane_coordinate=self.source_plane_centre.in_list[0], ) return grid_2d_irregular.Grid2DIrregular(grid=multiple_images)
def image_plane_multiple_image_positions_of_source_plane_centres( self, ) -> grids.GridIrregularGrouped: """Backwards ray-trace the source-plane centres (see above) to the image-plane via the mass model, to determine the multiple image position of the source(s) in the image-plane.. These image-plane positions are used by the next phase in a pipeline if automatic position updating is turned on.""" # TODO : In the future, the multiple image positions functioon wil use an in-built adaptive grid. grid = self.analysis.masked_dataset.mask.geometry.unmasked_grid_sub_1 solver = pos.PositionsSolver(grid=grid, pixel_scale_precision=0.001) try: multiple_images = [ solver.solve( lensing_obj=self.max_log_likelihood_tracer, source_plane_coordinate=centre, ) for centre in self.source_plane_centres.in_grouped_list[0] ] return grids.GridIrregularGrouped(grid=multiple_images) except IndexError: return None