示例#1
0
    def bands_as_markers(self, **kwargs) -> list:
        """Return a list of Kikuchi band line segment markers.

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

        Returns
        -------
        list
        """
        if self.bands.navigation_shape == (1, ):
            lines = np.squeeze(self.bands_detector_coordinates)
        else:
            lines = self.bands_detector_coordinates
        return get_line_segment_list(
            lines=lines,
            linewidth=kwargs.pop("linewidth", 2),
            color=kwargs.pop("color", "lime"),
            alpha=kwargs.pop("alpha", 0.7),
            zorder=kwargs.pop("zorder", 1),
            **kwargs,
        )
示例#2
0
    def test_get_line_segment_list0d(self, n_lines):
        """Lines in 0D () navigation space."""
        nav_shape = ()
        size = int(np.prod(nav_shape) * n_lines * 4)
        lines = np.random.random(size=size).reshape(nav_shape + (n_lines, 4))
        kwargs = dict(linewidth=1, color="red", alpha=1, zorder=1)
        line_markers = get_line_segment_list(list(lines), **kwargs)

        # Number of markers
        assert isinstance(line_markers, list)
        assert len(line_markers) == n_lines
        assert isinstance(line_markers[0], line_segment)

        # Coordinates, data shape and marker properties
        for line, marker in zip(lines, line_markers):
            assert np.allclose(
                [
                    marker.get_data_position("x1"),
                    marker.get_data_position("y1"),
                    marker.get_data_position("x2"),
                    marker.get_data_position("y2"),
                ],
                line,
            )
            assert marker._get_data_shape() == nav_shape
            for k, v in kwargs.items():
                assert marker.marker_properties[k] == v
示例#3
0
    def bands_as_markers(
        self, family_colors: Optional[List[str]] = None, **kwargs
    ) -> list:
        """Return a list of Kikuchi band line segment markers.

        Parameters
        ----------
        family_colors
            A list of at least as many colors as unique HKL families,
            either as RGB iterables or colors recognizable by
            Matplotlib, used to color each unique family of bands. If
            None (default), this is determined from a list similar to
            the one used in EDAX TSL's software.
        kwargs
            Keyword arguments passed to
            :func:`~kikuchipy.draw.markers.get_line_segment_list`.

        Returns
        -------
        list
            List with line segment markers.
        """
        if self.bands.navigation_shape == (1,):
            lines = np.squeeze(self.bands_detector_coordinates)
        else:
            lines = self.bands_detector_coordinates

        # Get dictionaries of families and in which a band belongs
        families, families_idx = _get_hkl_family(self.bands.hkl.data)

        # Get family colors
        # TODO: Perhaps move this outside this function (might be useful
        #  elsewhere)
        if family_colors is None:
            family_colors = []
            colors = _get_colors_for_allowed_bands(
                phase=self.bands.phase,
                highest_hkl=np.max(np.abs(self.bands.hkl.data), axis=0),
            )
            for hkl in families.keys():
                for table_hkl, color in colors:
                    if _is_equivalent(hkl, table_hkl):
                        family_colors.append(color)
                        break
                else:  # A non-allowed band is passed
                    family_colors.append([1, 1, 1])

        # Append list of markers per family (colors changing with
        # family)
        marker_list = []
        for i, idx in enumerate(families_idx.values()):
            marker_list += get_line_segment_list(
                lines=lines[..., idx, :],
                linewidth=kwargs.pop("linewidth", 1),
                color=family_colors[i],
                alpha=kwargs.pop("alpha", 1),
                zorder=kwargs.pop("zorder", 1),
                **kwargs,
            )
        return marker_list
示例#4
0
    def test_get_line_segment_0d_2(self):
        """A line in 0d but no (1,) navigation shape."""
        lines = np.random.random(size=4).reshape((4,))
        line_markers = get_line_segment_list(lines)

        assert len(line_markers) == 1
        assert np.allclose(
            [
                line_markers[0].get_data_position("x1"),
                line_markers[0].get_data_position("y1"),
                line_markers[0].get_data_position("x2"),
                line_markers[0].get_data_position("y2"),
            ],
            lines,
        )
示例#5
0
    def test_get_line_segment_list2d(self):
        """Lines in 2D (2, 3) navigation space."""
        nav_shape = (2, 3)
        n_lines = 3
        size = int(np.prod(nav_shape) * n_lines * 4)
        lines = np.random.random(size=size).reshape(nav_shape + (n_lines, 4))
        line_markers = get_line_segment_list(lines)

        assert len(line_markers) == n_lines

        # Iterate over lines
        for i in range(n_lines):
            assert line_markers[i]._get_data_shape() == nav_shape
            assert np.allclose(np.dstack(line_markers[i].data.tolist()[:4]),
                               lines[:, :, i])
示例#6
0
 def test_get_line_segment_list_nans(self):
     lines = np.ones((2, 3, 4)) * np.nan
     assert len(get_line_segment_list(lines)) == 0