Exemplo n.º 1
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
    def test_get_hkl_family(self, hkl, desired_family_keys,
                            desired_family_values, desired_indices, reduce):
        """Desired sets of families and indices."""
        families, families_idx = _get_hkl_family(hkl, reduce=reduce)

        for i, (k, v) in enumerate(families.items()):
            assert np.allclose(k, desired_family_keys[i])
            assert np.allclose(v, desired_family_values[i])
            assert np.allclose(families_idx[k], desired_indices[i])