def _get_colors_for_allowed_bands( phase: Phase, highest_hkl: Union[List[int], np.ndarray, None] = None, color_cycle: Optional[List[str]] = None, ): """Return an array of Miller indices of allowed Kikuchi bands for a point group and a corresponding color. The idea with this function is to always get the same color for the same band in the same point group. Parameters ---------- phase A phase container with a space and point group describing the allowed symmetry operations. highest_hkl Highest Miller indices to consider. If None (default), [9, 9, 9] is used. color_cycle A list of color names recognized by Matplotlib. If None (default), a color palette based on EDAX TSL's coloring of bands is cycled through. Returns ------- hkl_color Array with Miller indices and corresponding colors of shape (nhkl, 2, 3), with hkl and color in index 0 and 1 along axis=1, respectively. """ if highest_hkl is None: highest_hkl = [9, 9, 9] rlp = ReciprocalLatticePoint.from_highest_hkl( phase=phase, highest_hkl=highest_hkl, ) rlp2 = rlp[rlp.allowed] # TODO: Replace this ordering with future ordering method in # diffsims g_order = np.argsort(rlp2.gspacing) new_hkl = np.atleast_2d(rlp2.hkl.data)[g_order] rlp3 = ReciprocalLatticePoint(phase=rlp.phase, hkl=new_hkl) hkl = np.atleast_2d(rlp3.hkl.data) families, families_idx = _get_hkl_family(hkl=hkl, reduce=True) if color_cycle is None: color_cycle = TSL_COLORS n_families = len(families) n_times = int(np.ceil(n_families / len(color_cycle))) colors = (color_cycle * n_times)[:n_families] colors = [mcolors.to_rgb(i) for i in colors] hkl_colors = np.zeros(shape=(rlp3.size, 2, 3)) for hkl_idx, color in zip(families_idx.values(), colors): hkl_colors[hkl_idx, 0] = hkl[hkl_idx] hkl_colors[hkl_idx, 1] = color return hkl_colors
def test_init_from_highest_hkl( self, silicon_carbide_phase, highest_hkl, desired_highest_hkl, desired_lowest_hkl, desired_size, ): rlp = ReciprocalLatticePoint.from_highest_hkl( phase=silicon_carbide_phase, highest_hkl=highest_hkl ) assert np.allclose(rlp[0].hkl.data, desired_highest_hkl) assert np.allclose(rlp[-1].hkl.data, desired_lowest_hkl) assert rlp.size == desired_size