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 = PointSolver(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]
示例#2
0
    def __init__(
        self,
        name: str,
        positions: aa.Grid2DIrregular,
        noise_map: aa.ValuesIrregular,
        tracer: Tracer,
        point_solver: PointSolver,
        point_profile: Optional[ag.ps.Point] = None,
    ):
        """
        A lens position fitter, which takes a set of positions (e.g. from a plane in the tracer) and computes \
        their maximum separation, such that points which tracer closer to one another have a higher log_likelihood.

        Parameters
        -----------
        positions : Grid2DIrregular
            The (y,x) arc-second coordinates of positions which the maximum distance and log_likelihood is computed using.
        noise_value
            The noise-value assumed when computing the log likelihood.
        """

        self.name = name

        if point_profile is None:
            point_profile = tracer.extract_profile(profile_name=name)

        self.point_profile = point_profile

        self.point_solver = point_solver

        if self.point_profile is None:
            raise exc.PointExtractionException(
                f"For the point-source named {name} there was no matching point source profile "
                f"in the tracer (make sure your tracer's point source name is the same the dataset name."
            )

        self.source_plane_coordinate = self.point_profile.centre

        if len(tracer.planes) > 2:
            upper_plane_index = tracer.extract_plane_index_of_profile(
                profile_name=name)
        else:
            upper_plane_index = None

        model_positions = point_solver.solve(
            lensing_obj=tracer,
            source_plane_coordinate=self.source_plane_coordinate,
            upper_plane_index=upper_plane_index,
        )

        model_positions = model_positions.grid_of_closest_from(
            grid_pair=positions)

        super().__init__(
            data=positions,
            noise_map=noise_map,
            model_data=model_positions,
            mask=None,
            inversion=None,
        )
    def test__positions_found_for_simple_mass_profile_list(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.PointSolver(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 = PointSolver(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)
示例#4
0
    def image_plane_multiple_image_positions(self) -> aa.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 = PointSolver(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 aa.Grid2DIrregular(grid=multiple_images)