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
292 stars 186 forks source link

Duplicating EBSD object yields different matrix size #294

Closed gilgannonj closed 6 years ago

gilgannonj commented 6 years ago

Hello all,

Problem: While going about identifying twin boundaries and merging them into grains I duplicate my EBSD data set in order to update the grainIds to the parentIds. The code looks like this:

%% Merge twinned grains

% get the grain boundaries
gb_cal = grains.boundary('c','c');
%define a rotation
rot = rotation('axis',Miller(0,0,0,1,ebsd('c').CS),'angle',60*degree);
% calculates the angle between two trotations - the misorientation and the twinning rotation
ang_r = angle(gb_cal('c','c').misorientation,rot);
% condition/index all angles below a certain threshold
ind = ang_r < 5.*degree;
%select the boundaries based on this condition
twinBoundary = gb_cal(ind);
% merge grains connected with that twin boundary
[grains_merged,parentID_grains]= merge(grains,twinBoundary);
% make a copy of the ebsd dataset
ebsd_merged = ebsd;
% update the grainIds to the parentIds
ebsd_merged.grainId  = parentID_grains(ebsd_smoothed.grainId);

The problem is that I can not perform the line:

ebsd_merged.grainId  = parentID_grains(ebsd_smoothed.grainId);

because the matrix sizes don't match.

When I check the difference between the properties and size of the objects, ebsd and ebsd_merged, I get:

ebsd.prop 
size ebsd
ans = 

            ci: [243343x1 double]
            iq: [243343x1 double]
    sem_signal: [243343x1 double]
             x: [243343x1 double]
             y: [243343x1 double]
       grainId: [243343x1 double]
      mis2mean: [243343x1 rotation]

ans =

     1    13
ebsd_merged.prop 
size ebsd_merged
ans = 

            ci: [243343x1 double]
            iq: [243343x1 double]
    sem_signal: [243343x1 double]
             x: [243343x1 double]
             y: [243343x1 double]
       grainId: [243343x1 double]
      mis2mean: [243343x1 rotation]

ans =

     1    11

So I have the same set of properties but somehow I have lost two columns. Have I done something silly or is this a bug associated with duplicating an object?

Best,

James

kilir commented 6 years ago

Hi James, just wondering, is in your case ebsd_smoothed (the one your refer to when updating the grainId) the same as ebsd_merged? Cheers, Rüdiger

gilgannonj commented 6 years ago

Sorry that was a typo on my part when transferring the code for this post. I was using a smoothed EBSD data set and changed the code to make it simpler for posting here. The last two lines of the twinning code should have read as:

% make a copy of the ebsd dataset
ebsd_merged = ebsd;
% update the grainIds to the parentIds
ebsd_merged.grainId  = parentID_grains(ebsd.grainId);

I also checked to see if the matrix size was preserved if I just duplicated the the unsmoothed ebsd data set and the matrix size changed there as well.

kilir commented 6 years ago

O, the result that you see with size ebsd_merged has actually nothign to do with the ebsd_merged and is a 1-by-11 string (number of characters in ebsd_merged). Use size(ebsd_merged) or ebsd.size, but apart from that can you share the error that you get? Unrelated: using orientation('axis',Miller(0,0,0,1,ebsd('c').CS),'angle',60*degree,ebsd('c').CS,ebsd('c'),CS); may be better that rotation('axis',...

gilgannonj commented 6 years ago

Ah I feel silly about that, thanks for pointing it out. When I use ebsd.size and ebsd_merged.size I get:

ans =

      243343           1

ans =

      243343           1

But this confuses me because when I run the full %% Merge twinned grains that I posted above I get the error: Index exceeds matrix dimensions. . If I comment out the last line, %ebsd_merged.grainId = parentID_grains(ebsd.grainId);, then the script runs with out error.

Also thanks fo the advice on using rotation('axis',...

kilir commented 6 years ago

ok, and the last time you did a calcGrains in your script was after using a filter (smooth(ebsd,F)) and just before the merging, right? and you called it also with [grains,ebsd.grainId]=calcgrains(ebsd,'angle','...)?

gilgannonj commented 6 years ago

Yes. In order I am:

defining ebsd object smoothing ebsd calculating grains with new smoothed ebsd And then moving through the %% Merge twinned grains script section

kilir commented 6 years ago

In that case, I do not really see why this should happen.What's the output of sum(isnan(ebsd('indexed').grainId))?

gilgannonj commented 6 years ago

The return of sum(isnan(ebsd('indexed').grainId))

ans =

     0
gilgannonj commented 6 years ago

Ok issue fixed! :) Rüdiger and I discussed it outside of this thread. This issue is that I was using calcGrains twice in the same step, like this:

%% Grains and subgrains
[grains,ebsd.grainId,ebsd.mis2mean] = calcGrains(ebsd,'angle',10*degree);
[subgrains,ebsd.grainId,ebsd.mis2mean] = calcGrains(ebsd,'angle',0.5*degree);

which meant that that I was overwriting the grainId. The fix either is to calcGrains in two steps:

%% Grains
[grains,ebsd.grainId,ebsd.mis2mean] = calcGrains(ebsd,'angle',10*degree);
%% Subgrains
[subgrains,ebsd.grainId,ebsd.mis2mean] = calcGrains(ebsd,'angle',0.5*degree);

Or to replicate the ebsd to something where you can refer to specifically for the subgrains calculation.

Otherwise a mismatch is transferred across to my matrix sizes and doesn't let me merge at the step:

% update the grainIds to the parentIds
ebsd_merged.grainId  = parentID_grains(ebsd.grainId);

Thanks for all the help Rüdiger :) it is much appreciated!