Exemplo n.º 1
0
    def pc_as_markers(self, **kwargs) -> list:
        """Return a list of projection center point markers.

        Parameters
        ----------
        kwargs
            Keyword arguments passed to
            :func:`~kikuchipy.draw.markers.get_point_list`.

        Returns
        -------
        list
        """
        pcxy = self.detector.pc[..., :2]
        nrows, ncols = self.detector.shape
        x_scale = ncols - 1 if ncols > 1 else 1
        y_scale = nrows - 1 if nrows > 1 else 1
        pcxy[..., 0] *= x_scale
        pcxy[..., 1] *= y_scale
        return get_point_list(
            points=pcxy,
            size=kwargs.pop("size", 150),
            marker=kwargs.pop("marker", "*"),
            facecolor=kwargs.pop("facolor", "C1"),
            edgecolor=kwargs.pop("edgecolor", "k"),
            zorder=kwargs.pop("zorder", 6),
        )
Exemplo n.º 2
0
    def test_get_point_list0d(self, n_points):
        """Points in 0D () navigation space."""
        nav_shape = ()
        size = int(np.prod(nav_shape) * n_points * 2)
        points = np.random.random(size=size).reshape(nav_shape + (n_points, 2))
        kwargs = dict(
            s=40, marker="o", facecolor="w", edgecolor="k", zorder=5, alpha=1
        )
        point_markers = get_point_list(list(points), **kwargs)

        # Number of markers
        assert isinstance(point_markers, list)
        assert len(point_markers) == n_points
        assert isinstance(point_markers[0], point)

        # Coordinates, data shape and marker properties
        for i, marker in zip(points, point_markers):
            assert np.allclose(
                [
                    marker.get_data_position("x1"),
                    marker.get_data_position("y1"),
                ],
                i,
            )
            assert marker._get_data_shape() == nav_shape
            for k, v in kwargs.items():
                assert marker.marker_properties[k] == v
Exemplo n.º 3
0
    def zone_axes_as_markers(self, **kwargs) -> list:
        """Return a list of zone axes point markers.

        Parameters
        ----------
        kwargs
            Keyword arguments passed to
            :func:`~kikuchipy.draw.markers.get_point_list`.

        Returns
        -------
        list
            List with point markers.
        """
        # TODO: Give them some descriptive colors (facecolor)!
        # TODO: Marker style based on symmetry (2, 3, 4 and 6-fold):
        #  https://matplotlib.org/3.3.2/api/markers_api.html#module-matplotlib.markers
        return get_point_list(
            points=self.zone_axes_detector_coordinates,
            size=kwargs.pop("size", 40),
            marker=kwargs.pop("marker", "o"),
            facecolor=kwargs.pop("facecolor", "w"),
            edgecolor=kwargs.pop("edgecolor", "k"),
            zorder=kwargs.pop("zorder", 5),
            alpha=kwargs.pop("alpha", 1),
            **kwargs,
        )
Exemplo n.º 4
0
    def test_get_point_list0d_2(self):
        """One point in 0d but no (1,) navigation shape."""
        points = np.random.random(size=2).reshape((2,))
        point_marker = get_point_list(points)

        assert len(point_marker) == 1
        assert np.allclose(
            [
                point_marker[0].get_data_position("x1"),
                point_marker[0].get_data_position("y1"),
            ],
            points,
        )
Exemplo n.º 5
0
    def test_get_point_list2d(self):
        """Points in 2D (2, 3) navigation space."""
        nav_shape = (2, 3)
        n_points = 3
        size = int(np.prod(nav_shape) * n_points * 2)
        points = np.random.random(size=size).reshape(nav_shape + (n_points, 2))
        point_markers = get_point_list(points)

        assert len(point_markers) == n_points

        # Iterate over points
        for i in range(n_points):
            assert point_markers[i]._get_data_shape() == nav_shape
            assert np.allclose(np.dstack(point_markers[i].data.tolist()[:2]),
                               points[:, :, i])
Exemplo n.º 6
0
    def zone_axes_as_markers(self, **kwargs) -> list:
        """Return a list of zone axes point markers.

        Parameters
        ----------
        kwargs
            Keyword arguments passed to
            :func:`~kikuchipy.draw.markers.get_point_list`.

        Returns
        -------
        list
        """
        return get_point_list(
            points=self.zone_axes_detector_coordinates,
            size=kwargs.pop("size", 40),
            marker=kwargs.pop("marker", "o"),
            facecolor=kwargs.pop("facecolor", "w"),
            edgecolor=kwargs.pop("edgecolor", "k"),
            zorder=kwargs.pop("zorder", 5),
            alpha=kwargs.pop("alpha", 0.7),
            **kwargs,
        )
Exemplo n.º 7
0
    def pc_as_markers(self, **kwargs) -> list:
        """Return a list of projection center point markers.

        Parameters
        ----------
        kwargs
            Keyword arguments passed to
            :func:`~kikuchipy.draw.markers.get_point_list`.

        Returns
        -------
        list
            List of point markers.
        """
        # Set up (x, y) detector coordinate array of final shape
        # nav_shape + (n_patterns, 2)
        nav_shape = self.bands.navigation_shape
        n = int(np.prod(nav_shape))  # Number of patterns
        pcxy = np.ones((n, n, 2)) * np.nan
        i = np.arange(n)
        pcxy[i, i, :2] = self.detector.pc[..., :2].reshape((n, 2))
        pcxy = pcxy.reshape(nav_shape + (n, 2))

        nrows, ncols = self.detector.shape
        x_scale = ncols - 1 if ncols > 1 else 1
        y_scale = nrows - 1 if nrows > 1 else 1
        pcxy[..., 0] *= x_scale
        pcxy[..., 1] *= y_scale
        return get_point_list(
            points=pcxy,
            size=kwargs.pop("size", 300),
            marker=kwargs.pop("marker", "*"),
            facecolor=kwargs.pop("facecolor", "gold"),
            edgecolor=kwargs.pop("edgecolor", "k"),
            zorder=kwargs.pop("zorder", 6),
        )
Exemplo n.º 8
0
 def test_get_point_list_nans(self):
     points = np.ones((2, 3, 2)) * np.nan
     assert len(get_point_list(points)) == 0