Example #1
0
def _make_multidim_atom_plane_marker_list(atom_plane_zone_list,
                                          scale=1.,
                                          color='red',
                                          add_numbers=True):
    marker_list = []
    for i, atom_plane_list in enumerate(atom_plane_zone_list):
        for index_atom_plane, atom_plane in enumerate(atom_plane_list):
            for j in range(len(atom_plane.atom_list[1:])):
                x1 = [-1000] * len(atom_plane_zone_list)
                y1 = [-1000] * len(atom_plane_zone_list)
                x2 = [-1000] * len(atom_plane_zone_list)
                y2 = [-1000] * len(atom_plane_zone_list)
                x1[i] = atom_plane.atom_list[j].pixel_x * scale
                y1[i] = atom_plane.atom_list[j].pixel_y * scale
                x2[i] = atom_plane.atom_list[j + 1].pixel_x * scale
                y2[i] = atom_plane.atom_list[j + 1].pixel_y * scale
                marker = LineSegment(x1=x1, y1=y1, x2=x2, y2=y2, color=color)
                marker_list.append(marker)
            if add_numbers:
                x = [-1000] * len(atom_plane_zone_list)
                y = [-1000] * len(atom_plane_zone_list)
                x[i] = atom_plane.atom_list[0].pixel_x * scale
                y[i] = atom_plane.atom_list[0].pixel_y * scale
                marker = Text(x=x,
                              y=y,
                              text=str(index_atom_plane),
                              color=color,
                              va='top',
                              ha='right')
                marker_list.append(marker)
    return marker_list
Example #2
0
def _make_zone_vector_text_marker_list(
        zone_vector_list, x=1, y=1, scale=1., color='red'):
    number = len(zone_vector_list)
    marker_list = []
    if len(zone_vector_list) == 1:
        marker_list.append(
            Text(
                x, y,
                text=str(zone_vector_list[0]), size=20, color=color))
    else:
        for index, zone_vector in enumerate(zone_vector_list):
            xP, yP = [-1000] * number, [-1000] * number
            xP[index] = x
            yP[index] = y
            marker = Text(xP, yP, text=str(zone_vector), size=20, color=color)
            marker_list.append(marker)
    return marker_list
Example #3
0
def _make_atom_planes_marker_list(
        atom_plane_list, scale=1., add_numbers=True, color='red'):
    marker_list = []
    for i, atom_plane in enumerate(atom_plane_list):
        atom_plane_markers = _make_single_atom_plane_marker_list(
            atom_plane, scale=scale, color='red')
        marker_list.extend(atom_plane_markers)
        if add_numbers:
            marker = Text(
                x=atom_plane.start_atom.pixel_x * scale,
                y=atom_plane.start_atom.pixel_y * scale,
                text=str(i),
                color=color,
                va='top',
                ha='right')
            marker_list.append(marker)
    return marker_list
Example #4
0
def _make_atom_position_marker_list(atom_position_list,
                                    scale=1.,
                                    markersize=20,
                                    add_numbers=True,
                                    color='red'):
    marker_list = []
    for i, atom_position in enumerate(atom_position_list):
        x = atom_position.pixel_x * scale
        y = atom_position.pixel_y * scale
        marker = Point(x=x, y=y, color=color, size=markersize)
        marker_list.append(marker)
        if add_numbers:
            marker = Text(x=x,
                          y=y,
                          text=str(i),
                          color=color,
                          va='top',
                          ha='right')
            marker_list.append(marker)
    return marker_list
Example #5
0
    def plot_grid(
        self,
        pattern_idx: Optional[Tuple[int, ...]] = None,
        rgb_channels: Union[None, List[Tuple], List[List[Tuple]]] = None,
        visible_indices: bool = True,
        **kwargs,
    ) -> EBSD:
        """Plot a pattern with the detector grid superimposed,
        potentially coloring the edges of three grid tiles red, green
        and blue.

        Parameters
        ----------
        pattern_idx
            A tuple of integers defining the pattern to superimpose the
            grid on. If None (default), the first pattern is used.
        rgb_channels
            A list of tuple indices defining three or more detector grid
            tiles which edges to color red, green and blue. If None (default),
            no tiles' edges are colored.
        visible_indices
            Whether to show grid indices. Default is True.
        kwargs
            Keyword arguments passed to
            :func:`matplotlib.pyplot.axhline` and `axvline`, used by
            HyperSpy to draw lines.

        Returns
        -------
        pattern : kikuchipy.signals.EBSD
            A single pattern with the markers added.
        """
        # Get detector scales (column, row)
        axes_manager = self.signal.axes_manager
        dc, dr = [i.scale for i in axes_manager.signal_axes]

        rows = self.grid_rows
        cols = self.grid_cols

        # Set grid tile indices
        markers = []
        if visible_indices:
            color = kwargs.pop("color", "r")
            for row, col in np.ndindex(self.grid_shape):
                markers.append(
                    Text(
                        x=cols[col] * dc,
                        y=(rows[row] + (0.1 * rows[1])) * dr,
                        text=f"{row,col}",
                        color=color,
                    ))

        # Set lines
        kwargs.setdefault("color", "w")
        markers += [HorizontalLine((i - 0.5) * dr, **kwargs) for i in rows]
        markers += [VerticalLine((j - 0.5) * dc, **kwargs) for j in cols]

        # Color RGB tiles
        if rgb_channels is not None:
            for channels, color in zip(rgb_channels, ["r", "g", "b"]):
                if isinstance(channels, tuple):
                    channels = (channels, )
                for (row, col) in channels:
                    kwargs.update({
                        "color": color,
                        "zorder": 3,
                        "linewidth": 2
                    })
                    roi = self.roi_from_grid((row, col))
                    markers += [
                        Rectangle(
                            x1=(roi.left - 0.5) * dc,
                            y1=(roi.top - 0.5) * dc,
                            x2=(roi.right - 0.5) * dr,
                            y2=(roi.bottom - 0.5) * dr,
                            **kwargs,
                        )
                    ]

        # Get pattern and add list of markers
        if pattern_idx is None:
            pattern_idx = (0, ) * axes_manager.navigation_dimension
        pattern = self.signal.inav[pattern_idx]
        pattern.add_marker(markers, permanent=True)

        return pattern