-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathebsd_plot_orientation_maps.m
154 lines (141 loc) · 4.52 KB
/
ebsd_plot_orientation_maps.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
function ebsd_plot_orientation_maps(ebsd, out_path, varargin)
% EBSD_PLOT_ORIENTATION_MAPS Plot orientation maps and/or inverse pole figure
% density plots from EBSD data and write them to file.
%
% Input
% ebsd - @EBSD object
% out_path - path to output directory
%
% Options
% save - bool, if 1 (default), write figures to file.
% mode - string, {'x' (default), 'om', 'ipf', 'all'}.
% to_plot - bool, if 1 (default), show plots and not just save them.
% scalebar - bool, if 1 (default), show a scalebar.
%
% Uses the global reference frame set by the user by for example:
% setMTEXpref('xAxisDirection', 'east')
% setMTEXpref('zAxisDirection', 'intoPlane')
%
% Assumes not indexed pixels are labeled 'notIndexed'.
%
% Requires the export_fig package
% (https://se.mathworks.com/matlabcentral/fileexchange/23629-export_fig).
%
% Created by Håkon Wiik Ånes ([email protected]), 2019-02-25
% Set default values
save = 1;
mode = 'x';
to_plot = 1;
scalebar = 1;
% Override default values if passed to function
if check_option(varargin, 'save')
save = get_option(varargin, 'save');
end
if check_option(varargin, 'mode')
mode = get_option(varargin, 'mode');
end
if check_option(varargin, 'to_plot')
to_plot = get_option(varargin, 'to_plot');
end
if check_option(varargin, 'scalebar')
scalebar = get_option(varargin, 'scalebar');
end
% To show figures or not. Get current setting to revert at the end.
figure_visible = get(0, 'DefaultFigureVisible');
set(0, 'DefaultFigureVisible', 'on')
if ~to_plot
set(0, 'DefaultFigureVisible', 'off')
end
% Image resolution
res = '-r200';
% Delete possible 'notIndexed' entry in crystal symmetry cell array
cs = ebsd.CSList;
if isa(cs, 'cell')
for i=1:length(cs)
if strcmpi(cs{i}, 'notindexed')
cs(i) = [];
break
end
end
else % Make the single crystalSymmetry object into a cell to enable iteration
cs = {cs};
end
% Get inverse pole figure (IPF) keys
oMs = cell(length(cs));
for i=1:length(cs) % Iterate over crystal symmetries
oM = ipfHSVKey(ebsd(cs{i}.mineral));
oM.inversePoleFigureDirection = xvector;
oMs{i} = oM;
end
% Plot orientation map with respect to (wrt.) crystal reference frame
% direction Xc (or RD in TSL)
if ismember(mode, {'x', 'om', 'all'})
for i=1:length(cs) % Iterate over crystal symmetries
figure
mineral = cs{i}.mineral;
oM = oMs{i};
[~, mP] = plot(ebsd(mineral),...
oM.orientation2color(ebsd(mineral).orientations));
if ~scalebar
mP.micronBar.visible = 'off';
end
if save
export_fig(fullfile(out_path, ['omxc_' lower(mineral) '.png']), res)
end
end
end
% Plot remaining orientation maps
if ismember(mode, {'om', 'all'})
for i=1:length(cs) % Iterate over crystal symmetries
mineral = cs{i}.mineral;
oM = oMs{i};
% OM wrt. crystal reference frame direction Yc (or TD in TSL)
oM.inversePoleFigureDirection = yvector;
figure
[~, mP] = plot(ebsd(mineral),...
oM.orientation2color(ebsd(mineral).orientations));
if ~scalebar
mP.micronBar.visible = 'off';
end
if save
export_fig(fullfile(out_path, ['omyc_' lower(mineral) '.png']), res)
end
% OM wrt. crystal reference frame direction Zc (or ND in TSL)
oM.inversePoleFigureDirection = zvector;
figure
[~, mP] = plot(ebsd(mineral),...
oM.orientation2color(ebsd(mineral).orientations));
if ~scalebar
mP.micronBar.visible = 'off';
end
if save
export_fig(fullfile(out_path, ['omzc_' lower(mineral) '.png']), res)
end
end
end
% Plot IPFs
if strcmp(mode, 'ipf') || strcmp(mode, 'all')
directions = {xvector, yvector, zvector};
fnames = {'xc', 'yc', 'zc'};
for i=1:length(cs) % Iterate over crystal symmetries
oM = oMs{i};
mineral = cs{i}.mineral;
for j=1:length(directions)
oM.inversePoleFigureDirection = directions{j};
figure
plot(oM)
hold on
plotIPDF(ebsd(mineral).orientations,...
oM.inversePoleFigureDirection, 'markersize', 3,...
'markerfacecolor', 'none', 'markeredgecolor', 'k')
hold off
if save
export_fig(fullfile(out_path,...
['om_ipf' fnames{j} '_' lower(mineral) '.png']), res)
end
end
end
end
% Revert change
set(0, 'DefaultFigureVisible', figure_visible)
end