mtex-toolbox / mtex

MTEX is a free Matlab toolbox for quantitative texture analysis. Homepage:
http://mtex-toolbox.github.io/
GNU General Public License v2.0
274 stars 182 forks source link

reduce() command does not work correctly for hexagonal grid following 90 degree rotation #2074

Closed Tom-G-Uni-Vienna closed 4 months ago

Tom-G-Uni-Vienna commented 5 months ago

Hello, I have discovered that reduce() does not work on hexagonal grids after a 90 degree rotation, at least for OIM data. After a 90 degree rotation of the dataset about the map normal (zvector), the reduce command gives either a dataset with no points, or reduces by far too many points.

Why this is a problem: in order to align the map coordinates and sample reference axes for my OIM maps, I need to carry out a 90 degree rotation, which puts them in the orientation where reduce() does not work. As a workaround, I can just rotate my map by 90 degrees, reduce, and flip back when I am done, but this is obviously not the most elegant solution.

At first, I thought it had to do with the orientation of hexagons ("vertical" or "horizontal"), but it turns out that importing the same map with x oriented to north or east has no impact on whether it is in the "correct" orientation for reduce() to work or not.

Please find attached some code to illustrate the issue, I also attached a .ang file. In the case of my (OIM) data, the error shows up after carrying out the 90 degree rotation.

The issue is clearly being caused by the second part of line 43 in the reduce command (the last part in the following code block, where ix is added to iy) - in some cases the result of summing ix and iy is entirely odd numbers, which leads to no data being extracted into the reduced variable, in some cases only a small number of points fulfil this criteria (as occurs in the attached example).

    % generate regular grid
    ext = ebsd.extent;
    dx = max(ebsd.unitCell(:,1))-min(ebsd.unitCell(:,1));
    dy = max(ebsd.unitCell(:,2))-min(ebsd.unitCell(:,2));

    % detect position within grid
    iy = round((ebsd.prop.y - ext(3))/dy*4/3);
    ix = round((ebsd.prop.x - ext(1))/dx*2);

    ebsd = ebsd.subSet(~mod(iy,fak) & ~mod(ix+iy,2*fak));

(fak is a variable telling is to take every nth pixel, default fak=2)

best regards, Tom Griffiths hex_error.zip

ralfHielscher commented 4 months ago

Hi Thomas, thank you for reporting this issue. I hope I could fix it. Ralf.