-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviewGrains.m
344 lines (289 loc) · 10.6 KB
/
viewGrains.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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
function out = viewGrains( sid, rid, region, ebsd, tasks, varargin ) %#ok<INUSL>
% View information about grain structure of EBSD.
% View information about grain structure of EBSD.
%
% Syntax
% out = viewGrains( sid, rid, region, ebsd, tasks, varargin)
%
% Output
% out - not used
%
% Input
% sid - sample id: 's01', 's02', 's03', 's04', 't01', 'p01', 'p02'
% rid - region id
% region - region coordinate
% ebsd - EBSD (all phases) data if 0, try load useing function "[sid '_load']"
% tasks - list of tasks
%
% History
% 01.12.12 Add 'tasklist'.
% 06.12.12 Add 'epsilon'.
% 28.12.12 Replace 'mgs' to 'thr' in 'plotBndRange'.
% 06.03.13 Move to MTEX 3.3.2: replace 'color' to 'linecolor'.
% 19.03.13 Remove 'plotAngDist' to separate file.
% 20.03.13 Add 'ext' and 'sub' boundary for 'doHistAllBndMis' and 'doHistAllBndMisSmall'.
% 21.03.13 Add Japanese style variants spectrum for 'doHistNearKOG'.
% 27.03.13 Add comments for 'doHistNearKOG'.
% 14.04.13 Add saveing of comment.
% 16.04.13 Separate degree and radian 'thr'.
% 26.04.14 New input system. 'THRD', 'MGS', 'EPSD' - from 'varargin'.
% 05.04.14 New output system. Replace 'best_OR' to 'optOR'.
% 22.09.14 Add 'getRegionParam' for 'optOR'.
out = {};
% Check vars
if check_option(varargin, 'mgs')
mgs = get_option(varargin, 'mgs');
end
if check_option(varargin, 'thrd')
thrd = get_option(varargin, 'thrd');
end
if check_option(varargin, 'epsd')
epsd = get_option(varargin, 'epsd');
end
saveres = getpref('ebsdam','saveResult');
% Convert to radian
thr = thrd*degree;
% eps = epsd*degree;
%% Settings
% Angle limit in degree
lmt = 62;
small_lmt = 12;
hi = 40;
% Best OR, 0 - to find optimal
optOR = get_option(varargin, 'optOR', 'KS');
if isa(optOR, 'cell')
optOR = getRegionParams(sid, rid, optOR, 'singleArray' );
end
% % Sample information
% sinfo = ['\fontsize{8}Sample:"' sid '".'...
% 'Params: thr=' num2str(thr) '^\circ, mgs=' num2str(mgs)];
%% Tasklist
% Grains map
doGrainsMap = get_option(tasks,'doGrainsMap', 0);
doGrainsMapAll = get_option(tasks,'doGrainsMapAll', 0);
doGrainsMapLrg = get_option(tasks,'doGrainsMapLrg', 0);
% Boundary map
doBndHighOnly = get_option(tasks,'doBndHighOnly', 0);
doBndHighAngle = get_option(tasks,'doBndHighAngle', 0);
doBndKOG = get_option(tasks,'doBndKOG', 0);
doBndKOGPkg = get_option(tasks,'doBndKOGPkg', 0);
doBndKOGBain = get_option(tasks,'doBndKOGBain', 0);
doBndIntFull = get_option(tasks,'doBndIntFull', 0);
doBndInt = get_option(tasks,'doBndInt', 0);
doBndExtRange = get_option(tasks,'doBndExtRange', 0);
doBndAllRange = get_option(tasks,'doBndAllRange', 0);
doBndAngle = get_option(tasks,'doBndAngle', 0);
% Misoreintation distribution
doHistMis2Mean = get_option(tasks,'doHistMis2Mean', 0);
doHistAllBndMis = get_option(tasks,'doHistAllBndMis', 0);
doHistAllBndMisSmall= get_option(tasks,'doHistAllBndMisSmall', 0);
doHistMis = get_option(tasks,'doHistMis', 0);
doHistMeanMis = get_option(tasks,'doHistMeanMis', 0);
doHistMeanMisSmall = get_option(tasks,'doHistMeanMisSmall', 0);
doHistNearKOG = get_option(tasks,'doHistNearKOG', 0);
doHistNearKOGAll = get_option(tasks,'doHistNearKOGAll', 0);
% Others
doPlotKAM = get_option(tasks,'doPlotKAM', 0);
doPlotTwin = get_option(tasks,'doPlotTwin', 0);
%% Preparation
% File name prefix
prefixg = [sid '_' rid '_grn_' num2str(thrd) '_' num2str(mgs)];
prefixb = [sid '_' rid '_bnd_' num2str(thrd) '_' num2str(mgs)];
prefixk = [sid '_' rid '_kog_' num2str(thrd) '_' num2str(mgs) '_' num2str(epsd)];
% Get output directory
OutDir = checkDir(sid, 'grains', saveres);
comment = getComment();
% Get EBSD data (ebsd_all need for SEM map)
ebsd_all = checkEBSD(sid, ebsd, 0);
ebsd = ebsd_all('Fe');
% Get grains
[grains, grains_full] = getGrains(ebsd, thr, mgs);
if (get_option(varargin,'SmoothGrain', 0) == 1)
grains = smooth(grains,1);
end
% Find optimal orientation relationship
if (isa(optOR, 'double') && numel(optOR) == 1 && optOR == 0)
optOR = optimizeOR( sid, part, ebsd, grains, saveres, thrd, mgs, epsd );
disp(['Best OR = ' optOR]);
end
optORn = nameOR(optOR);
%% Plotting grains
% Plot grains map
if doGrainsMap
figure();
plot(grains,'antipodal',1);
saveimg( saveres, 1, OutDir, prefixg, 'map', 'png', comment);
end
% Plot all grains map
if doGrainsMapAll
if (mgs > 0)
figure();
plot(grains_full,'antipodal',1);
saveimg( saveres, 1, OutDir, prefixg, 'map_all', 'png', comment);
end
end
% Plot big grains map
if doGrainsMapLrg
if (mgs > 0) %#ok<ALIGN>
large_grains = grains_full(grainSize(grains_full) >= mgs);
figure();
plot(large_grains,'antipodal',1);
saveimg( saveres, 1, OutDir, prefixg, 'map_lrg', 'png', comment);
end
end
%% Plotting boundary map
% Plot high angle boundary only
if doBndHighOnly
figure();
plotBoundary(grains,'property',[hi 70]*degree,'linecolor','k','linewidth',0.8);
saveimg( saveres, 1, OutDir, prefixg, 'map_hi_only', 'png', comment);
end
% Plot high angle boundary on IQ
if doBndHighAngle
if (any(cellfun(@(x) strcmpi(x, 'IQ'), get(ebsd_all))))
figure();
plot(ebsd_all, 'property', 'IQ');
colormap(gray);
% hold on
% plotBoundary(grains,'linecolor','w','linewidth',1);
hold on
plotBoundary(grains,'property',[hi 70]*degree,'linecolor','k','linewidth',1);
saveimg( saveres, 1, OutDir, prefixg, 'map_hi', 'png', comment);
end
end
% Plot KOG
if doBndKOG
figure();
paint_boundary3(grains,optOR,epsd,'ext','hi-lo','del');
saveimg( saveres, 1, OutDir, prefixk, ['a_' optORn '_del'], 'png', comment);
end
% Plot KOG - Packages
if doBndKOGPkg
figure();
paint_boundary3(grains,optOR,epsd,'ext','pkg','gray');
saveimg( saveres, 1, OutDir, prefixk, ['a_' optORn '_p_gray'], 'png', comment);
end
% Plot KOG - Bain groups
if doBndKOGBain
figure();
paint_boundary3(grains,optOR,epsd,'ext','bain','gray');
saveimg( saveres, 1, OutDir, prefixk, ['a_' optORn '_b_gray'], 'png', comment);
end
% Plot internal boundary for all grains
if doBndIntFull
figure();
plotBoundary(grains_full,'external')
hold on, plotBoundary(grains_full,'internal','linecolor', 'r')
saveimg( saveres, 1, OutDir, prefixb, 'internal_full', 'png', comment);
end
% Plot internal boundary
if doBndInt
figure();
plotBoundary(grains,'external')
hold on, plotBoundary(grains,'internal','linecolor', 'r')
saveimg( saveres, 1, OutDir, prefixb, 'internal', 'png', comment);
end
% Plot ext boundary colored by mis-angle range
if doBndExtRange
plotBndRange( grains, thr, saveres, 1, OutDir, prefixb, 'ext', [ 2 5 15], [0.8 0.8 0.8; 0.5 0.5 0.5; 0 0 0], 'GridOff');
end
% Plot all boundary colored by mis-angle range
if doBndAllRange
plotBndRange( grains, thr, saveres, 1, OutDir, prefixb, 'allbnd', [ 2 5 15], [0.8 0.8 0.8; 0.5 0.5 0.5; 0 0 0], 'GridOff');
end
% Plot boundary colored by mis-angle
if doBndAngle
figure();
plotBoundary(grains, 'property', 'angle', 'extern', 'linewidth',1);
saveimg( saveres, 1, OutDir, prefixb, 'angle', 'png', comment);
end
%% Plotting misoreintation distribution
% Plot mis2mean
if doHistMis2Mean
fname = 'mis2mean';
title1 = 'Misorientation inside grains';
figure();
% get the misorientations to mean
mori = get(grains,'mis2mean');
plotAngDist(mori, small_lmt, saveres, OutDir, prefixb, fname, title1 );
end
% Plot all boundary misorientation angle
if doHistAllBndMis
fname = 'angdist_bnd_all';
title1 = 'All boundary misorientation';
mori = calcBoundaryMisorientation(grains);
plotAngDist(mori, lmt, saveres, OutDir, prefixb, fname, title1 );
% TESTING 'calcBoundaryMisorientation' for 'sub' and 'ext'
fname = 'angdist_bnd_sub';
title1 = 'Sub boundary misorientation';
mori = calcBoundaryMisorientation(grains, 'sub');
plotAngDist(mori, lmt, saveres, OutDir, prefixb, fname, title1 );
fname = 'angdist_bnd_ext';
title1 = 'Ext boundary misorientation';
mori = calcBoundaryMisorientation(grains, 'ext');
plotAngDist(mori, lmt, saveres, OutDir, prefixb, fname, title1 );
end
%% Plot all boundary misorientation angle for small angle
if doHistAllBndMisSmall
fname = 'angdist_bnd_all_small';
title1 = 'All boundary misorientation for small angles';
mori = calcBoundaryMisorientation(grains);
plotAngDist(mori, small_lmt, saveres, OutDir, prefixb, fname, title1 );
% TESTING 'calcBoundaryMisorientation' for 'sub' and 'ext'
fname = 'angdist_bnd_sub_small';
title1 = 'Sub boundary misorientation';
mori = calcBoundaryMisorientation(grains, 'sub');
plotAngDist(mori, small_lmt, saveres, OutDir, prefixb, fname, title1 );
fname = 'angdist_bnd_ext_small';
title1 = 'Ext boundary misorientation';
mori = calcBoundaryMisorientation(grains, 'ext');
plotAngDist(mori, small_lmt, saveres, OutDir, prefixb, fname, title1 );
end
%% Plot neightbored measurment misorientation
if doHistMis
fname = 'angdist';
title1 = 'Misorientation between neightbored measurments';
mori = calcMisorientation(grains, 'uncorrelated');
plotAngDist(mori, lmt, saveres, OutDir, prefixb, fname, title1 );
end
%% Plot mean grains' orientation misoreintation
if doHistMeanMis
fname = 'angdist_mean';
title1 = 'Misoreantion between mean grains'' orientation';
mori = getMeanMis(grains);
plotAngDist(mori, lmt, saveres, OutDir, prefixb, fname, title1 );
end
%% Plot mean grains' orientation misoreintation for small angle
if doHistMeanMisSmall
fname = 'angdist_mean_small';
title1 = 'Misoreantion between mean grains'' orientation for small angle';
mori = getMeanMis(grains);
plotAngDist(mori, small_lmt, saveres, OutDir, prefixb, fname, title1 );
end
% Plot KOG fraction
if doHistNearKOG
HistNearKOG(grains, epsd, optOR, 0, saveres, OutDir, prefixk, 'fKOG', comment)
end
% Plot KOG fraction for All boundary
if doHistNearKOGAll
HistNearKOG(grains, epsd, optOR, 1, saveres, OutDir, prefixk, 'fKOGa', comment)
end
% Plot KAM
if doPlotKAM
plotKAM(grains);
saveimg( saveres, 1, OutDir, prefixg, 'KAM', 'png', comment);
end
% Plot twin boundary
if doPlotTwin
plotBoundary(grains1,'color','k');
hold on, plotBoundary(grains1,'property',CSL(3),'delta',2*degree,...
'linecolor','b','linewidth',2);
hold off;
saveimg( saveres, 1, OutDir, prefixg, 'twin', 'png', comment);
end
%
% figure();
% f = fracKOG(grains, epsd, 'KS');
% bar(f);
% saveimg( saveres, 1, OutDir, prefixb, 'fKOG_KS', 'png', comment);
end