Skip to content

Fix get_map_data() and slicing for crystal maps whose coordinates do not start at zero - #694

Open
aaronkanzer wants to merge 1 commit into
pyxem:developfrom
aaronkanzer:fix/crystal-map-nonzero-origin
Open

aaronkanzer wants to merge 1 commit into
pyxem:developfrom
aaronkanzer:fix/crystal-map-nonzero-origin

Conversation

@aaronkanzer

Copy link
Copy Markdown

CrystalMap.get_map_data() and slicing assume the map's x and y coordinates start at 0. If they start anywhere else, columns or rows are silently dropped, or the result is an empty array. This happens with an .ang file exported for a region of interest that keeps its original coordinates, or with a map built from stage coordinates.

import numpy as np
from orix.crystal_map import CrystalMap
from orix.quaternion import Rotation

y, x = np.indices((3, 4))
xmap = CrystalMap(Rotation.identity(12), x=x.ravel() + 1.0, y=y.ravel())
print(xmap.shape)
print(xmap.get_map_data("x"))

Observed on 0.15.0 and develop:

(3, 4)
[[2. 3. 4.]
 [2. 3. 4.]
 [2. 3. 4.]]

Expected: a (3, 4) array whose rows are all [1. 2. 3. 4.].

With an x origin of 10 and a step of 0.5, get_map_data() returns shape (3, 0). Slicing (xmap[:2]) raises ValueError: could not broadcast input array from shape (3,4) into shape (3,0). The same happens after orix.io.load() of an .ang file whose x column starts at 10.

Cause: CrystalMap._data_slices_from_coordinates() turns coordinates into array indices with round(c / step). Those indices are then used on arrays of the original map shape, so they are only correct when the smallest coordinate is 0.

Fix: make the slices relative to the first point of the full map. Maps that start at 0 are unchanged. A regression test covers get_map_data() and slicing on a map with an offset origin.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant