-
Notifications
You must be signed in to change notification settings - Fork 2
/
gridCVA.m
232 lines (157 loc) · 5.26 KB
/
gridCVA.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
% This function will perform principal geodesic analysis (PGA) of [3 x 3]
% kernels for a single phase. This analysis is similar to the grain-scale
% crystallographic vorticity axis (CVA) analysis, except that instead of
% using sets of orientations in whole grains, it uses a [3 x 3] window, and
% it is only applied to a single phase at a time.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% References:
% Zachary D. Michels, Seth C. Kruckenberg, Joshua R. Davis, and Basil Tikoff
% Determining vorticity axes from grain-scale dispersion of
% crystallographic orientations Geology, G36868.1, first published on July
% 17, 2015, doi:10.1130/G36868.1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% input:
% ebsd:
%
% output:
% eCVA (EBSD variable appended with PGA results, such as the
% following):
% ODT: Orientation dispersion tensor result from PGA
% eV: ODT eigenvectors as vector3d –– eV(1,:) = cva
% mags: Eigenvalues of eigenvectors –– mags(1,:) for cva's
% example usage:
% % load some data
% mtexdata forsterite
% % compute the kernel CVA analysis (use either of the following syntax)
% [eCVA,bv] = gridCVA(ebsd) % all points
% [eCVA,bv] = gridCVA(ebsd, grains) % excluding points adjacent to
% % plot results and best-fit/preferred cva vector
% figure,
% plot(eCVA.CVA,'antipodal','lower','smooth')
% hold on
% plot(bv,'antipodal','lower','Marker','^','MarkerSize',10,...
% 'MarkerFaceColor','k','MarkerEdgeColor','w')
%%
function [eCVA,bv] = gridCVA(e,varargin)
warning off
%%
narginchk(1,2)
nargin;
if nargin > 1
varargin;
grains = [varargin{1}];
% check if grainID exists
if isempty(e.grainId)
error('There is no ebsd.grainId. Run calcGrains first.')
end
% get ebsd IDs at grain on either side of grain boundaries
eIdB = grains.boundary.ebsdId(:);
% remove any zeros
eIdB(eIdB==0)=[];
% remove the identified pixels from the dataset
e('id',intersect(e.id,eIdB)) = [];
end
%%
% gridify
egrid = e('indexed').gridify;
% nan not-indexed
egrid(~(egrid.isIndexed)).phase = nan;
egrid = egrid.gridify;
% ebsd ids in grid/matrix
ids = egrid.id;
% size of matrix
[a1,b1] = size(ids);
% window width
w = 3;
inds = ids(2:a1-1,2:b1-1);
eId = egrid(inds).id;
%% initialize window
num = length(eId(:));
win1 = zeros(num,w*w);
for s = 1:num
% s = 1;
c = inds(s);
win1(s,:) = [ c-a1-1 c-1 c+a1-1 c-a1 c c+a1 c-a1+1 c+1 c+a1+1 ];
end
%% setup indexing for window
% phase IDs
pID = reshape(egrid(win1).phase,size(egrid(win1)));
% phase numbers
p = egrid('id',eId).phase;
% for logical query
pind1 = pID(:)==reshape(repmat(p,1,w*w),[w*w*num,1]);
% logical index by phase of points in the kernel window with a phase that
% matches the central point
pind = reshape(pind1,size(pID));
% ids of points in the windows
winId = egrid('id',win1).id;
% use logical index to leave only ones of same phase
winId(~pind) = 0;
%% pre-allocate variables to become properties of eCVA
eV = [vector3d.nan(1,num); vector3d.nan(1,num); vector3d.nan(1,num)];
mags = nan(3,num);
kos = nan(size(eId));
kax = vector3d.nan(1,num);
meanOrientation = orientation.nan(num,1);
T = repmat(tensor(nan(3,3),'rank',2),[num,1]);
%% analysis loop
% for keeping track of progress in for loop:
div=round(num/20);
count=div;
fprintf('\n%i kernels\n',num)
fprintf('\n%i%% done\n',0)
for n = 1:num
if sum(~isnan(egrid(winId(n,winId(n,:)>0))))>2
% orientations of same phase in the kernel
o = egrid(winId(n,winId(n,:)>0)).orientations;
if length(o)>2 && max(angle(o,mean(o)))>.01*degree
[eV(:,n),mags(:,n),T(n)] = PGA(o);
% kernel mean orientation
meanOrientation(n) = mean(o);
% kernel orientation spread (KOS - like mis2mean for kernel)
kos(n) = max(angle(o,mean(o)));
% kernel mean KOS axis
kax(n) = mean(axis(o,mean(o)));
end
end
% Keep track of for loop progress and print to consoloe screen:
perc=round(n/num*100);
if n==count
fprintf('\n%i%% done...\n',perc)
count=count+div;
end
end
% project to lower hemisphere
eV(eV.z>0)=-eV(eV.z>0);
%% append ebsd variable
eCVA = egrid(eId);
eCVA.prop.CVA = eV(1,:);
eCVA.prop.eV1 = eV(1,:);
eCVA.prop.eV2 = eV(2,:);
eCVA.prop.eV3 = eV(3,:);
eCVA.prop.mag1 = mags(1,:);
eCVA.prop.mag2 = mags(2,:);
eCVA.prop.mag3 = mags(3,:);
eCVA.prop.kos = kos;
eCVA.prop.kax = kax;
eCVA.prop.meanRotation = meanOrientation;
eCVA.prop.ODT = T;
%% Handle results
% identify null solutions
cond1 = (norm(eCVA.CVA)==0 | isnan(eCVA.mag1) | isnan(eCVA.CVA) | isnan(eCVA.kax));
% apply condition
eCVA = eCVA(~cond1);
% filter out nan
eCVA = eCVA(~isnan(eCVA.rotations));
%% Kernel Density Estimation to get a best fit "bulk" vorticity vector.
% Define a kernel density estimation with specified halfwidth. MTEX default
% uses the de la Vallee Poussin kernel:
r = plotS2Grid('resolution',0.25*degree,'antipodal');
kde = calcDensity([eCVA.CVA -eCVA.CVA],r,'antipodal','halfwidth',10*degree);
[~,I]=max(kde);
% get vector and negated vector (antipodal) of best-fit axis:
bv=[r(I),-r(I)];
bv(bv.z>0) = [];
end