Skip to content

Commit

Permalink
Merge pull request #436 from hakonanes/main-into-develop-post-0.11.1-…
Browse files Browse the repository at this point in the history
…release

Bring changes in main into develop after 0.11.1 release
  • Loading branch information
hakonanes committed Mar 14, 2023
2 parents e3e10a4 + bd61098 commit b0226d2
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 12 deletions.
26 changes: 26 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -6,6 +6,32 @@ All user facing changes to this project are documented in this file. The format
on `Keep a Changelog <https://keepachangelog.com/en/1.0.0/>`__, and this project tries
its best to adhere to `Semantic Versioning <https://semver.org/spec/v2.0.0.html>`__.

Unreleased
==========

Added
-----

Changed
-------

Deprecated
----------

Removed
-------

Fixed
-----

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
===========================

Expand Down
2 changes: 1 addition & 1 deletion orix/__init__.py
@@ -1,5 +1,5 @@
__name__ = "orix"
__version__ = "0.11.0"
__version__ = "0.12.dev0"
__author__ = "orix developers"
__author_email__ = "pyxem.team@gmail.com"
__description__ = "orix is an open-source Python library for handling crystal orientation mapping data."
Expand Down
25 changes: 15 additions & 10 deletions orix/crystal_map/crystal_map.py
Expand Up @@ -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


Expand Down Expand Up @@ -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:
Expand All @@ -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()))
Expand Down
25 changes: 25 additions & 0 deletions orix/tests/test_crystal_map.py
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -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",
Expand Down

0 comments on commit b0226d2

Please sign in to comment.