def zone_axes_labels_as_markers(self, **kwargs) -> list: """Return a list of zone axes label text markers. Parameters ---------- kwargs Keyword arguments passed to :func:`~kikuchipy.draw.markers.get_text_list`. Returns ------- list """ zone_axes = self.zone_axes[self.zone_axes.within_gnomonic_radius] return get_text_list( texts=sub("[][ ]", "", str(zone_axes._hkldata)).split("\n"), coordinates=self.zone_axes_label_detector_coordinates, color=kwargs.pop("color", "k"), zorder=kwargs.pop("zorder", 5), ha=kwargs.pop("ha", "center"), bbox=kwargs.pop( "bbox", dict( facecolor="w", edgecolor="k", boxstyle="round, rounding_size=0.2", pad=0.1, alpha=0.7, ), ), )
def zone_axes_labels_as_markers(self, **kwargs) -> list: """Return a list of zone axes label text markers. Parameters ---------- kwargs Keyword arguments passed to :func:`~kikuchipy.draw.markers.get_text_list`. Returns ------- list List of text markers. """ za = self.zone_axes.hkl.data array_str = np.array2string(za, threshold=za.size) return get_text_list( texts=sub("[][ ]", "", array_str).split("\n"), coordinates=self.zone_axes_label_detector_coordinates, color=kwargs.pop("color", "k"), zorder=kwargs.pop("zorder", 5), ha=kwargs.pop("ha", "center"), bbox=kwargs.pop( "bbox", dict( facecolor="w", edgecolor="k", boxstyle="round, rounding_size=0.2", pad=0.1, alpha=1, ), ), )
def test_get_text_list_nans(self): """Returns""" text_coords = np.ones((2, 3, 2)) * np.nan assert ( len( get_text_list( texts=["111", "200", "220"], coordinates=text_coords ) ) == 0 )
def test_get_text_list0d_2(self): """One text label in 0d but no (1,) navigation shape.""" text_coords = np.random.random(size=2).reshape((2,)) texts = ["123"] text_markers = get_text_list(texts=texts, coordinates=text_coords) assert len(text_markers) == 1 assert np.allclose( [ text_markers[0].get_data_position("x1"), text_markers[0].get_data_position("y1"), ], text_coords, ) assert text_markers[0].get_data_position("text") == texts[0]
def test_get_text_list2d(self): """Text labels in 2D (2, 3) navigation space.""" nav_shape = (2, 3) n_labels = 3 size = int(np.prod(nav_shape) * n_labels * 2) texts = ["111", "-2-20", "311"] text_coords = np.random.random(size=size).reshape(nav_shape + (n_labels, 2)) text_markers = get_text_list(texts=texts, coordinates=text_coords) assert len(text_markers) == n_labels # Iterate over text labels for i in range(n_labels): assert text_markers[i]._get_data_shape() == nav_shape assert np.allclose(np.dstack(text_markers[i].data.tolist()[:2]), text_coords[:, :, i]) assert text_markers[i].data["text"] == texts[i]
def test_get_text_list0d(self, n_labels): """Text labels in 0D () navigation space.""" nav_shape = () size = int(np.prod(nav_shape) * n_labels * 2) texts = ["111", "220", "-220"][:n_labels] text_coords = np.random.random(size=size).reshape( nav_shape + (n_labels, 2) ) kwargs = dict( color="k", zorder=5, ha="center", bbox=dict( facecolor="w", edgecolor="k", boxstyle="round, rounding_size=0.2", pad=0.1, alpha=0.1, ), ) text_markers = get_text_list( texts=texts, coordinates=list(text_coords), **kwargs ) # Number of markers assert isinstance(text_markers, list) assert len(text_markers) == n_labels assert isinstance(text_markers[0], text) # Coordinates, data shape and marker properties for i, (t, marker) in enumerate(zip(text_coords, text_markers)): assert np.allclose( [ marker.get_data_position("x1"), marker.get_data_position("y1"), ], t, ) assert marker.get_data_position("text") == texts[i] assert marker._get_data_shape() == nav_shape for k, v in kwargs.items(): assert marker.marker_properties[k] == v