Beispiel #1
0
    def visuals_with_include_2d(self) -> lensing_visuals.Visuals2D:
        """
        Extracts from the `LightProfile` attributes that can be plotted and return them in a `Visuals2D` object.

        Only attributes with `True` entries in the `Include` object are extracted for plotting.

        From a `LightProfilePlotter` the following 2D attributes can be extracted for plotting:

        - origin: the (y,x) origin of the structure's coordinate system.
        - mask: the mask of the structure.
        - border: the border of the structure's mask.

        Returns
        -------
        vis.Visuals2D
            The collection of attributes that can be plotted by a `Plotter2D` object.
        """

        return self.visuals_2d + self.visuals_2d.__class__(
            origin=self.extract_2d(
                "origin",
                value=grid_2d_irregular.Grid2DIrregular(
                    grid=[self.grid.origin]),
            ),
            mask=self.extract_2d("mask", value=self.grid.mask),
            border=self.extract_2d(
                "border", value=self.grid.mask.border_grid_sub_1.binned),
            light_profile_centres=self.extract_2d(
                "light_profile_centres",
                grid_2d_irregular.Grid2DIrregular(
                    grid=[self.light_profile.centre]),
            ),
        )
Beispiel #2
0
    def solve(self, lensing_obj, source_plane_coordinate):

        coordinates_list = self.grid_peaks_from(
            lensing_obj=lensing_obj,
            grid=self.grid,
            source_plane_coordinate=source_plane_coordinate,
        )

        coordinates_list = self.grid_with_coordinates_from_mass_profile_centre_removed(
            lensing_obj=lensing_obj, grid=coordinates_list)

        coordinates_list = self.grid_with_points_below_magnification_threshold_removed(
            lensing_obj=lensing_obj, grid=coordinates_list)

        if not self.use_upscaling:

            return grid_2d_irregular.Grid2DIrregular(grid=coordinates_list)

        pixel_scale = self.grid.pixel_scale

        while pixel_scale > self.pixel_scale_precision:

            refined_coordinates_list = []

            for coordinate in coordinates_list:

                refined_coordinates = self.refined_coordinates_from_coordinate(
                    coordinate=coordinate,
                    pixel_scale=pixel_scale,
                    lensing_obj=lensing_obj,
                    source_plane_coordinate=source_plane_coordinate,
                )

                if refined_coordinates is not None:
                    refined_coordinates_list += refined_coordinates

            refined_coordinates_list = grid_remove_duplicates(
                grid=np.asarray(refined_coordinates_list))

            pixel_scale = pixel_scale / self.upscale_factor

            coordinates_list = refined_coordinates_list

        coordinates_list = self.grid_within_distance_of_source_plane_centre(
            lensing_obj=lensing_obj,
            grid=grid_2d_irregular.Grid2DIrregularUniform(
                grid=coordinates_list,
                pixel_scales=(pixel_scale, pixel_scale)),
            source_plane_coordinate=source_plane_coordinate,
            distance=self.distance_from_source_centre,
        )

        coordinates_list = self.grid_with_points_below_magnification_threshold_removed(
            lensing_obj=lensing_obj, grid=coordinates_list)

        return grid_2d_irregular.Grid2DIrregular(grid=coordinates_list)
    def vectors_within_annulus(
        self,
        inner_radius: float,
        outer_radius: float,
        centre: typing.Tuple[float, float] = (0.0, 0.0),
    ) -> "VectorField2DIrregular":
        """
        Returns a new `VectorFieldIrregular` object which has had all vectors outside of a circle of input radius
        around an  input (y,x) centre removed.

        Parameters
        ----------
        radius : float
            The radius of the circle outside of which vectors are removed.
        centre : float
            The centre of the circle outside of which vectors are removed.

        Returns
        -------
        VectorFieldIrregular
            The vector field where all vectors outside of the input radius are removed.

        """
        squared_distances = self.grid.distances_from_coordinate(
            coordinate=centre)
        mask = (inner_radius < squared_distances) & (squared_distances <
                                                     outer_radius)

        if np.all(mask == False):
            raise exc.VectorFieldException(
                "The input radius removed all vectors / points on the grid.")

        return VectorField2DIrregular(vectors=self[mask],
                                      grid=grid_2d_irregular.Grid2DIrregular(
                                          self.grid[mask]))
    def project_to_radial_grid_2d(self,
                                  angle: float = 0.0
                                  ) -> grid_2d_irregular.Grid2DIrregular:
        """
        Project the 1D grid of (y,x) coordinates to an irregular 2d grid of (y,x) coordinates. The projection works
        as follows:

        1) Map the 1D (x) coordinates to 2D along the x-axis, such that the x value of every 2D coordinate is the
        corresponding (x) value in the 1D grid, and every y value is 0.0.

        2) Rotate this projected 2D grid clockwise by the input angle.

        Parameters
        ----------
        angle
            The angle with which the project 2D grid of coordinates is rotated clockwise.

        Returns
        -------
        grid_2d_irregular.Grid2DIrregular
            The projected and rotated 2D grid of (y,x) coordinates.
        """
        grid = np.zeros((self.sub_shape_slim, 2))

        grid[:, 1] = self.slim

        grid = geometry_util.transform_grid_2d_to_reference_frame(grid_2d=grid,
                                                                  centre=(0.0,
                                                                          0.0),
                                                                  angle=angle)

        return grid_2d_irregular.Grid2DIrregular(grid=grid)
    def extract_attribute(self, cls, attr_name):
        """
        Returns an attribute of a class and its children profiles in the the galaxy as a `ValueIrregular`
        or `Grid2DIrregular` object.

        For example, if a galaxy has two light profiles and we want the `LightProfile` axis-ratios, the following:

        `galaxy.extract_attribute(cls=LightProfile, name="axis_ratio"`

        would return:

        ValuesIrregular(values=[axis_ratio_0, axis_ratio_1])

        If a galaxy has three mass profiles and we want the `MassProfile` centres, the following:

        `galaxy.extract_attribute(cls=MassProfile, name="centres"`

         would return:

        GridIrregular2D(grid=[(centre_y_0, centre_x_0), (centre_y_1, centre_x_1), (centre_y_2, centre_x_2)])

        This is used for visualization, for example plotting the centres of all light profiles colored by their profile.
        """

        if isinstance(self, cls):
            if hasattr(self, attr_name):

                attribute = getattr(self, attr_name)

                if isinstance(attribute, float):
                    return values.ValuesIrregular(values=[attribute])
                if isinstance(attribute, tuple):
                    return grid_2d_irregular.Grid2DIrregular(grid=[attribute])
Beispiel #6
0
    def visuals_with_include_2d(self):
        """
        Extracts from an `Array2D` attributes that can be plotted and returns them in a `Visuals` object.

        Only attributes already in `self.visuals_2d` or with `True` entries in the `Include` object are extracted
        for plotting.

        From an `Array2D` the following attributes can be extracted for plotting:

        - origin: the (y,x) origin of the structure's coordinate system.
        - mask: the mask of the structure.
        - border: the border of the structure's mask.

        Parameters
        ----------
        array : array_2d.Array2D
            The array whose attributes are extracted for plotting.

        Returns
        -------
        vis.Visuals2D
            The collection of attributes that can be plotted by a `Plotter2D` object.
        """
        return self.visuals_2d + self.visuals_2d.__class__(
            origin=self.extract_2d(
                "origin",
                grid_2d_irregular.Grid2DIrregular(grid=[self.array.origin])),
            mask=self.extract_2d("mask", self.array.mask),
            border=self.extract_2d("border",
                                   self.array.mask.border_grid_sub_1.binned),
        )
Beispiel #7
0
    def visuals_with_include_2d(self):
        """
        Extracts from a `Grid2D` attributes that can be plotted and return them in a `Visuals` object.

        Only attributes with `True` entries in the `Include` object are extracted for plotting.

        From a `Grid2D` the following attributes can be extracted for plotting:

        - origin: the (y,x) origin of the grid's coordinate system.
        - mask: the mask of the grid.
        - border: the border of the grid's mask.

        Parameters
        ----------
        grid : abstract_grid_2d.AbstractGrid2D
            The grid whose attributes are extracted for plotting.

        Returns
        -------
        vis.Visuals2D
            The collection of attributes that can be plotted by a `Plotter2D` object.
        """
        if not isinstance(self.grid, grid_2d.Grid2D):
            return self.visuals_2d

        return self.visuals_2d + self.visuals_2d.__class__(
            origin=self.extract_2d(
                "origin",
                grid_2d_irregular.Grid2DIrregular(grid=[self.grid.origin])))
 def brightest_reconstruction_pixel_centre(self):
     return grid_2d_irregular.Grid2DIrregular(
         grid=[
             self.mapper.source_pixelization_grid[
                 self.brightest_reconstruction_pixel
             ]
         ]
     )
    def visuals_with_include_2d(self):

        return self.visuals_2d + self.visuals_2d.__class__(
            origin=self.extract_2d(
                "origin",
                grid_2d_irregular.Grid2DIrregular(
                    grid=[self.fit.mask.origin])),
            mask=self.extract_2d("mask", self.fit.mask),
            border=self.extract_2d("border",
                                   self.fit.mask.border_grid_sub_1.binned),
        )
Beispiel #10
0
    def grid_from_grid_slim(self, grid_slim):
        """Create a `Grid2DIrregular` object from a 2D ndarray array of values of shape [total_values, 2].

        The `Grid2DIrregular` are structured following this *ValuesIrregular* instance.

        Parameters
        ----------
        grid_slim : np.ndarray
            The 2d array (shape [total_coordinates, 2]) of (y,x) coordinates that are mapped to a `Grid2DIrregular`
            object."""
        return grid_2d_irregular.Grid2DIrregular(grid=grid_slim)
Beispiel #11
0
    def source_plane_light_profile_centre(self) -> grid_2d_irregular.Grid2DIrregular:
        """
        Return a light profile centres of a galaxy in the most-likely tracer's source-plane. If there are multiple
        light profiles, the first light profile's centre is returned.

        These centres are used by automatic position updating to determine the best-fit lens model's image-plane
        multiple-image positions.
        """
        centre = self.max_log_likelihood_tracer.source_plane.extract_attribute(
            cls=lp.LightProfile, name="centre"
        )
        if centre is not None:
            return grid_2d_irregular.Grid2DIrregular(grid=[np.asarray(centre[0])])
Beispiel #12
0
    def caustics_from_grid(self, grid, pixel_scale=0.05):

        try:
            return grid_2d_irregular.Grid2DIrregular(
                [
                    self.tangential_caustic_from_grid(
                        grid=grid, pixel_scale=pixel_scale
                    ),
                    self.radial_caustic_from_grid(grid=grid, pixel_scale=pixel_scale),
                ]
            )
        except (IndexError, ValueError):
            return []
    def visuals_with_include_2d_real_space(self):

        return self.visuals_2d + self.visuals_2d.__class__(
            origin=self.extract_2d(
                "origin",
                grid_2d_irregular.Grid2DIrregular(
                    grid=[self.interferometer.real_space_mask.origin]),
            ),
            mask=self.extract_2d("mask", self.interferometer.real_space_mask),
            border=self.extract_2d(
                "border",
                self.interferometer.real_space_mask.border_grid_sub_1.binned),
        )
Beispiel #14
0
    def extract_attribute(self, cls, attr_name):
        """
        Returns an attribute of a class in the tracer as a `ValueIrregular` or `Grid2DIrregular` object.

        For example, if a tracer has an image-plane with a galaxy with two light profiles, the following:

        `tracer.extract_attribute(cls=LightProfile, name="axis_ratio")`

        would return:

        ValuesIrregular(values=[axis_ratio_0, axis_ratio_1])

        If the image plane has has two galaxies with two mass profiles and the source plane another galaxy with a
        mass profile, the following:

        `tracer.extract_attribute(cls=MassProfile, name="centre")`

        would return:

        GridIrregular2D(grid=[(centre_y_0, centre_x_0), (centre_y_1, centre_x_1), (centre_y_2, centre_x_2)])

        This is used for visualization, for example plotting the centres of all mass profiles colored by their profile.
        """

        def extract(value, name):

            try:
                return getattr(value, name)
            except (AttributeError, IndexError):
                return None

        attributes = [
            extract(value, attr_name)
            for galaxy in self.galaxies
            for value in galaxy.__dict__.values()
            if isinstance(value, cls)
        ]

        if attributes == []:
            return None
        elif isinstance(attributes[0], float):
            return values.ValuesIrregular(values=attributes)
        elif isinstance(attributes[0], tuple):
            return grid_2d_irregular.Grid2DIrregular(grid=attributes)
Beispiel #15
0
    def extract_attribute(self, cls, attr_name):
        """
        Returns an attribute of a class and its children profiles in the the galaxy as a `ValueIrregular`
        or `Grid2DIrregular` object.

        For example, if a galaxy has two light profiles and we want the `LightProfile` axis-ratios, the following:

        `galaxy.extract_attribute(cls=LightProfile, name="axis_ratio"`

        would return:

        ValuesIrregular(values=[axis_ratio_0, axis_ratio_1])

        If a galaxy has three mass profiles and we want the `MassProfile` centres, the following:

        `galaxy.extract_attribute(cls=MassProfile, name="centres"`

         would return:

        GridIrregular2D(grid=[(centre_y_0, centre_x_0), (centre_y_1, centre_x_1), (centre_y_2, centre_x_2)])

        This is used for visualization, for example plotting the centres of all light profiles colored by their profile.
        """
        def extract(value, name):

            try:
                return getattr(value, name)
            except (AttributeError, IndexError):
                return None

        attributes = [
            extract(value, attr_name) for value in self.__dict__.values()
            if isinstance(value, cls)
        ]

        attributes = list(filter(None, attributes))

        if attributes == []:
            return None
        elif isinstance(attributes[0], float):
            return values.ValuesIrregular(values=attributes)
        elif isinstance(attributes[0], tuple):
            return grid_2d_irregular.Grid2DIrregular(grid=attributes)
Beispiel #16
0
    def plot_via_plotter(self, plotter, grid_indexes=None, mapper=None):

        if self.origin is not None:
            plotter.origin_scatter.scatter_grid(
                grid=grid_2d_irregular.Grid2DIrregular(grid=self.origin))

        if self.mask is not None:
            plotter.mask_scatter.scatter_grid(
                grid=self.mask.edge_grid_sub_1.binned)

        if self.border is not None:
            plotter.border_scatter.scatter_grid(grid=self.border)

        if self.grid is not None:
            plotter.grid_scatter.scatter_grid(grid=self.grid)

        if self.pixelization_grid is not None:
            plotter.pixelization_grid_scatter.scatter_grid(
                grid=self.pixelization_grid)

        if self.positions is not None:
            plotter.positions_scatter.scatter_grid(grid=self.positions)

        if self.vector_field is not None:
            plotter.vector_field_quiver.quiver_vector_field(
                vector_field=self.vector_field)

        if self.patches is not None:
            plotter.patch_overlay.overlay_patches(patches=self.patches)

        if self.lines is not None:
            plotter.grid_plot.plot_grid(grid=self.lines)

        if self.indexes is not None:
            plotter.index_scatter.scatter_grid_indexes(grid=grid_indexes,
                                                       indexes=self.indexes)

        if self.pixelization_indexes is not None and mapper is not None:
            indexes = mapper.slim_indexes_from_pixelization_indexes(
                pixelization_indexes=self.pixelization_indexes)

            plotter.index_scatter.scatter_grid_indexes(
                grid=mapper.source_grid_slim, indexes=indexes)
Beispiel #17
0
    def radial_critical_curve_from_grid(self, grid, pixel_scale=0.05):

        radial_eigen_values = self.radial_eigen_value_from_grid(grid=grid)

        radial_critical_curve_indices = measure.find_contours(
            radial_eigen_values.native, 0
        )

        if len(radial_critical_curve_indices) == 0:
            return []

        radial_critical_curve = grid.mask.grid_scaled_from_grid_pixels_1d_for_marching_squares(
            grid_pixels_1d=radial_critical_curve_indices[0],
            shape_native=radial_eigen_values.sub_shape_native,
        )

        try:
            return grid_2d_irregular.Grid2DIrregular(radial_critical_curve)
        except IndexError:
            return []
Beispiel #18
0
    def visuals_source_with_include_2d(self):
        """
        Extracts from a `Mapper` attributes that can be plotted for figures in its source-plane (e.g. the reconstruction
        and return them in a `Visuals` object.

        Only attributes with `True` entries in the `Include` object are extracted for plotting.

        From a `Mapper` the following attributes can be extracted for plotting in the source-plane:

        - origin: the (y,x) origin of the coordinate system in the source plane.
        - mapper_source_pixelization_grid: the `Mapper`'s pixelization grid in the source-plane.
        - mapper_source_grid_slim: the `Mapper`'s full grid in the source-plane.
        - mapper_border_grid: the border of the `Mapper`'s full grid in the data-plane.

        Parameters
        ----------
        mapper : mappers.Mapper
            The mapper whose source-plane attributes are extracted for plotting.

        Returns
        -------
        vis.Visuals2D
            The collection of attributes that can be plotted by a `Plotter2D` object.
        """

        return self.visuals_2d + self.visuals_2d.__class__(
            origin=self.extract_2d(
                "origin",
                grid_2d_irregular.Grid2DIrregular(
                    grid=[self.mapper.source_pixelization_grid.origin]),
            ),
            grid=self.extract_2d("grid", self.mapper.source_grid_slim,
                                 "mapper_source_grid_slim"),
            border=self.extract_2d(
                "border", self.mapper.source_grid_slim.sub_border_grid),
            pixelization_grid=self.extract_2d(
                "pixelization_grid",
                self.mapper.source_pixelization_grid,
                "mapper_source_pixelization_grid",
            ),
        )
    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 __new__(
        cls,
        vectors: np.ndarray or [(float, float)],
        grid: grid_2d_irregular.Grid2DIrregular or list,
    ):
        """
        A collection of (y,x) vectors which are located on an irregular grid of (y,x) coordinates.

        The (y,x) vectors are stored as a 2D NumPy array of shape [total_vectors, 2]. This array can be mapped to a
        list of tuples structure.

        Calculations should use the NumPy array structure wherever possible for efficient calculations.

        The vectors input to this function can have any of the following forms (they will be converted to the 1D NumPy
        array structure and can be converted back using the object's properties):

        [[vector_0_y, vector_0_x], [vector_1_y, vector_1_x]]
        [(vector_0_y, vector_0_x), (vector_1_y, vector_1_x)]

        If your vector field lies on a 2D uniform grid of data the `VectorField` data structure should be used.

        Parameters
        ----------
        vectors : np.ndarray or [(float, float)]
            The 2D (y,x) vectors on an irregular grid that represent the vector-field.
        grid : grid_2d_irregular.Grid2DIrregular
            The irregular grid of (y,x) coordinates where each vector is located.
        """

        if len(vectors) == 0:
            return []

        if type(vectors) is list:
            vectors = np.asarray(vectors)

        obj = vectors.view(cls)
        obj.grid = grid_2d_irregular.Grid2DIrregular(grid=grid)

        return obj
Beispiel #21
0
    def from_dict(cls, dict_: dict) -> "PointSourceDataset":
        """
        Create a point source dataset from a dictionary representation.

        Parameters
        ----------
        dict_
            A dictionary. Arrays are represented as lists or lists of lists.

        Returns
        -------
        An instance
        """
        return cls(
            name=dict_["name"],
            positions=grid_2d_irregular.Grid2DIrregular(dict_["positions"]),
            positions_noise_map=values.ValuesIrregular(
                dict_["positions_noise_map"]),
            fluxes=values.ValuesIrregular(dict_["fluxes"])
            if dict_["fluxes"] is not None else None,
            fluxes_noise_map=values.ValuesIrregular(dict_["fluxes_noise_map"])
            if dict_["fluxes_noise_map"] is not None else None,
        )
    def visuals_with_include_2d_of_plane(
            self, plane_index) -> lensing_visuals.Visuals2D:
        """
        Extracts from a `Structure` attributes that can be plotted and return them in a `Visuals` object.

        Only attributes with `True` entries in the `Include` object are extracted for plotting.

        From an `AbstractStructure` the following attributes can be extracted for plotting:

        - origin: the (y,x) origin of the structure's coordinate system.
        - mask: the mask of the structure.
        - border: the border of the structure's mask.

        Parameters
        ----------
        structure : abstract_structure.AbstractStructure
            The structure whose attributes are extracted for plotting.

        Returns
        -------
        vis.Visuals2D
            The collection of attributes that can be plotted by a `Plotter2D` object.
        """

        border = self.extract_2d("border",
                                 value=self.grid.mask.border_grid_sub_1.binned)

        if border is not None:
            if plane_index > 0:
                border = self.tracer.traced_grids_of_planes_from_grid(
                    grid=border)[plane_index]

        if plane_index == 0:
            critical_curves = self.extract_2d(
                "critical_curves",
                self.tracer.critical_curves_from_grid(grid=self.grid),
                "critical_curves",
            )
        else:
            critical_curves = None

        if plane_index == 1:
            caustics = self.extract_2d(
                "caustics", self.tracer.caustics_from_grid(grid=self.grid),
                "caustics")
        else:
            caustics = None

        return self.visuals_2d + self.visuals_2d.__class__(
            origin=self.extract_2d(
                "origin",
                value=grid_2d_irregular.Grid2DIrregular(
                    grid=[self.grid.origin]),
            ),
            border=border,
            light_profile_centres=self.extract_2d(
                "light_profile_centres",
                self.tracer.planes[plane_index].extract_attribute(
                    cls=light_profiles.LightProfile, attr_name="centre"),
            ),
            mass_profile_centres=self.extract_2d(
                "mass_profile_centres",
                self.tracer.planes[plane_index].extract_attribute(
                    cls=mass_profiles.MassProfile, attr_name="centre"),
            ),
            critical_curves=critical_curves,
            caustics=caustics,
        )
Beispiel #23
0
    def solve(self,
              lensing_obj,
              source_plane_coordinate,
              upper_plane_index=None):

        if upper_plane_index is None:
            deflections_func = lensing_obj.deflections_2d_from_grid
        else:
            deflections_func = partial(
                lensing_obj.deflections_between_planes_from_grid,
                plane_i=0,
                plane_j=upper_plane_index,
            )

        coordinates_list = self.grid_peaks_from(
            grid=self.grid,
            source_plane_coordinate=source_plane_coordinate,
            deflections_func=deflections_func,
        )

        coordinates_list = self.grid_with_coordinates_from_mass_profile_centre_removed(
            lensing_obj=lensing_obj, grid=coordinates_list)

        coordinates_list = self.grid_with_points_below_magnification_threshold_removed(
            lensing_obj=lensing_obj,
            deflections_func=deflections_func,
            grid=coordinates_list,
        )

        if not self.use_upscaling:

            coordinates_list = self.grid_within_distance_of_source_plane_centre(
                deflection_func=deflections_func,
                grid=grid_2d_irregular.Grid2DIrregularUniform(
                    grid=coordinates_list,
                    pixel_scales=self.grid.pixel_scales),
                source_plane_coordinate=source_plane_coordinate,
                distance=self.distance_from_source_centre,
            )

            return grid_2d_irregular.Grid2DIrregular(grid=coordinates_list)

        pixel_scale = self.grid.pixel_scale

        while pixel_scale > self.pixel_scale_precision:

            refined_coordinates_list = []

            for coordinate in coordinates_list:

                refined_coordinates = self.refined_coordinates_from_coordinate(
                    deflections_func=deflections_func,
                    coordinate=coordinate,
                    pixel_scale=pixel_scale,
                    source_plane_coordinate=source_plane_coordinate,
                )

                if refined_coordinates is not None:
                    refined_coordinates_list += refined_coordinates

            refined_coordinates_list = grid_remove_duplicates(
                grid=np.asarray(refined_coordinates_list))

            pixel_scale = pixel_scale / self.upscale_factor

            coordinates_list = refined_coordinates_list

        coordinates_list = self.grid_within_distance_of_source_plane_centre(
            deflection_func=deflections_func,
            grid=grid_2d_irregular.Grid2DIrregularUniform(
                grid=coordinates_list,
                pixel_scales=(pixel_scale, pixel_scale)),
            source_plane_coordinate=source_plane_coordinate,
            distance=self.distance_from_source_centre,
        )

        coordinates_list = self.grid_with_points_below_magnification_threshold_removed(
            lensing_obj=lensing_obj,
            deflections_func=deflections_func,
            grid=coordinates_list,
        )

        return grid_2d_irregular.Grid2DIrregular(grid=coordinates_list)
Beispiel #24
0
def make_grid_2d_irregular_7x7_list():
    return [
        grid_2d_irregular.Grid2DIrregular(grid=[(0.1, 0.1), (0.2, 0.2)]),
        grid_2d_irregular.Grid2DIrregular(grid=[(0.3, 0.3)]),
    ]
Beispiel #25
0
def make_grid_2d_irregular_7x7():
    return grid_2d_irregular.Grid2DIrregular(grid=[(0.1, 0.1), (0.2, 0.2)])
Beispiel #26
0
    def grid_2d_radial_projected_from(
            self,
            centre=(0.0, 0.0),
            angle: float = 0.0) -> grid_2d_irregular.Grid2DIrregular:
        """
        Determine a projected radial grid of points from a 2D region of coordinates defined by an
        extent [xmin, xmax, ymin, ymax] and with a (y,x) centre. This functions operates as follows:

        1) Given the region defined by the extent [xmin, xmax, ymin, ymax], the algorithm finds the longest 1D distance
        of the 4 paths from the (y,x) centre to the edge of the region (e.g. following the positive / negative y and
        x axes).

        2) Use the pixel-scale corresponding to the direction chosen (e.g. if the positive x-axis was the longest, the
        pixel_scale in the x dimension is used).

        3) Determine the number of pixels between the centre and the edge of the region using the longest path between
        the two chosen above.

        4) Create a (y,x) grid of radial points where all points are at the centre's y value = 0.0 and the x values
        iterate from the centre in increasing steps of the pixel-scale.

        5) Rotate these radial coordinates by the input `angle` clockwise.

        A schematic is shown below:

        -------------------
        |                 |
        |<- - -  - ->x    | x = centre
        |                 | <-> = longest radial path from centre to extent edge
        |                 |
        -------------------

        4) Create a (y,x) grid of radial points where all points are at the centre's y value = 0.0 and the x values
        iterate from the centre in increasing steps of the pixel-scale.

        5) Rotate these radial coordinates by the input `angle` clockwise.

        Parameters
        ----------
        extent : np.ndarray
            The extent of the grid the radii grid is computed using, with format [xmin, xmax, ymin, ymax]
        centre : (float, flloat)
            The (y,x) central coordinate which the radial grid is traced outwards from.
        pixel_scales : (float, float)
            The (y,x) scaled units to pixel units conversion factor of the 2D mask array.
        sub_size : int
            The size of the sub-grid that each pixel of the 2D mask array is divided into.
        angle : float
            The angle with which the radial coordinates are rotated clockwise.

        Returns
        -------
        grid_2d_irregular.Grid2DIrregular
            A radial set of points sampling the longest distance from the centre to the edge of the extent in along the
            positive x-axis.
        """
        grid_radial_projected_2d = grid_2d_util.grid_scaled_2d_slim_radial_projected_from(
            extent=self.extent,
            centre=centre,
            pixel_scales=self.pixel_scales,
            sub_size=self.sub_size,
        )

        grid_radial_projected_2d = geometry_util.transform_grid_2d_to_reference_frame(
            grid_2d=grid_radial_projected_2d, centre=centre, angle=angle)

        grid_radial_projected_2d = geometry_util.transform_grid_2d_from_reference_frame(
            grid_2d=grid_radial_projected_2d, centre=centre, angle=0.0)

        return grid_2d_irregular.Grid2DIrregular(grid=grid_radial_projected_2d)
Beispiel #27
0
 def in_grid(self):
     """Returns the 1D complex NumPy array of values as an irregular grid."""
     return grid_2d_irregular.Grid2DIrregular(grid=self.in_array)