diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 80e5129f..c175fb4e 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -6,6 +6,14 @@ All user facing changes to this project are documented in this file. The format
on `Keep a Changelog `__, and this project tries
its best to adhere to `Semantic Versioning `__.
+2023-03-14 - version 0.11.1
+===========================
+
+Fixed
+-----
+- Initialization of a crystal map with a phase list with fewer phases than in the phase
+ ID array given returns a map with a new phase list with correct phase IDs.
+
2023-02-09 - version 0.11.0
===========================
diff --git a/orix/__init__.py b/orix/__init__.py
index 6794c8ab..c915050c 100644
--- a/orix/__init__.py
+++ b/orix/__init__.py
@@ -1,5 +1,5 @@
__name__ = "orix"
-__version__ = "0.11.0"
+__version__ = "0.11.1"
__author__ = "orix developers"
__author_email__ = "pyxem.team@gmail.com"
__description__ = "orix is an open-source Python library for handling crystal orientation mapping data."
diff --git a/orix/crystal_map/crystal_map.py b/orix/crystal_map/crystal_map.py
index 87fdee5a..07f60c92 100644
--- a/orix/crystal_map/crystal_map.py
+++ b/orix/crystal_map/crystal_map.py
@@ -23,7 +23,7 @@
import numpy as np
from orix.crystal_map.crystal_map_properties import CrystalMapProperties
-from orix.crystal_map.phase_list import Phase, PhaseList
+from orix.crystal_map.phase_list import ALL_COLORS, Phase, PhaseList
from orix.quaternion import Orientation, Rotation
@@ -251,7 +251,7 @@ def __init__(
if phase_list is None:
self._phases = PhaseList(ids=unique_phase_ids)
else:
- phase_list = copy.deepcopy(phase_list)
+ phase_list = phase_list.deepcopy()
phase_ids = phase_list.ids
n_different = len(phase_ids) - len(unique_phase_ids)
if n_different > 0:
@@ -265,15 +265,20 @@ def __init__(
break
elif n_different < 0:
# Create new phase list adding the missing phases with
- # default initial values
- phase_list = PhaseList(
- names=phase_list.names,
- space_groups=phase_list.space_groups,
- point_groups=phase_list.point_groups,
- colors=phase_list.colors,
- structures=phase_list.structures,
- ids=unique_phase_ids,
+ # default initial values (but unique colors)
+ phase_dict = {}
+ all_colors = list(ALL_COLORS.keys())
+ all_unique_colors = np.delete(
+ all_colors, np.isin(all_colors, phase_list.colors)
)
+ ci = 0
+ for i in unique_phase_ids:
+ if i in phase_ids:
+ phase_dict[i] = phase_list[i]
+ else:
+ phase_dict[i] = Phase(color=all_unique_colors[ci])
+ ci += 1
+ phase_list = PhaseList(phase_dict)
# Ensure phase list IDs correspond to IDs in phase_id array
new_ids = list(unique_phase_ids.astype(int))
phase_list._dict = dict(zip(new_ids, phase_list._dict.values()))
diff --git a/orix/tests/test_crystal_map.py b/orix/tests/test_crystal_map.py
index 6a5dbf9a..b3764424 100644
--- a/orix/tests/test_crystal_map.py
+++ b/orix/tests/test_crystal_map.py
@@ -166,6 +166,31 @@ def test_init_with_phase_list(self, crystal_map_input, expected_presence):
unique_phase_ids = list(np.unique(crystal_map_input["phase_id"]).astype(int))
assert xmap.phases.ids == unique_phase_ids
+ def test_init_with_sparse_phase_list(self):
+ """Initialize a map with a sparse phase list only containing one
+ of the phase IDs passed in the phase list.
+ """
+ pl = PhaseList(ids=[1], names=["b"], space_groups=[225])
+ phase_id = np.array([0, 0, 1, 1, 1, 3])
+ xmap = CrystalMap(
+ rotations=Rotation.identity(phase_id.size),
+ is_in_data=phase_id == 1,
+ phase_list=pl,
+ phase_id=phase_id,
+ )
+ for i, name, color, sg_name in zip(
+ [0, 1, 3],
+ ["", "b", ""],
+ ["tab:orange", "tab:blue", "tab:green"],
+ [None, "Fm-3m", None],
+ ):
+ assert xmap.phases[i].name == name
+ assert xmap.phases[i].color == color
+ if sg_name is None:
+ assert xmap.phases[i].space_group is None
+ else:
+ assert xmap.phases[i].space_group.short_name == sg_name
+
def test_init_with_single_point_group(self, crystal_map_input):
point_group = O
phase_list = PhaseList(point_groups=point_group)
diff --git a/setup.py b/setup.py
index c28128aa..68b0ac95 100644
--- a/setup.py
+++ b/setup.py
@@ -20,7 +20,7 @@
"sphinx-design",
"sphinx-gallery < 0.11",
"sphinx-last-updated-by-git",
- "pydata-sphinx-theme",
+ "pydata-sphinx-theme >= 0.13.1",
"sphinxcontrib-bibtex >= 1.0",
"scikit-image",
"scikit-learn",