-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExample_Deck_OI_TwoPhase.m
279 lines (218 loc) · 9.13 KB
/
Example_Deck_OI_TwoPhase.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
clear;
home;
close all;
%% The h5 file location
file1_folder='C:\Users\benja\OneDrive\Documents\GitHub\MTEX_Workshop\Data'; %location where the data is stored
file1_name='Ti6246 Post_PECS Site 2 Map Data 4'; %should be a h5oina file, do not add in the .h5oina file extension
% file1_folder='/MATLAB Drive/MTEX_Workshop/Data/';
% file1_name='Mg_Pecs1 Specimen 1 Site 1 Map Data 1'; %should be a h5oina file, do not add in the .h5oina file extension
file_dset='1'; %data set number of interest in the h5 file
mb_length = 20; %micro bar length for plots - if you want to override, you can comment this out/clear this variable and the override will not happen
%% Load MTEX
%location of MTEX 5.10.2
%if MTEX loaded this doesn't matter
%if MTEX is not loaded, then this will be used to start MTEX up
mtex_location='C:\Users\benja\OneDrive\Documents\MATLAB\mtex-5.10.2';
% mtex_location='/MATLAB Drive/mtex-5.10.2';
%start mtex if needed
try EBSD;
catch
run(fullfile(mtex_location,"startup.m"));
end
%create a results folder
file1_name_us=file1_name;
file1_name_us(strfind(file1_name_us,' '))='_';
resultsdir=fullfile(cd,'results',file1_name_us);
if isdir(resultsdir) == 0; mkdir(resultsdir); end
%% Read the h5oina data into Matlab
%Make this a full file name
file1_full=fullfile(file1_folder,[file1_name '.h5oina']);
%read the H5OINA EBSD Data - this will return two structures, with the data
%contained per layer/slice in the file, and also a contents file if you
%need to load anything else
[ebsd_data,header_data,h5oina_contents]=H5OINA_Read(file1_full);
phase_names={'Ti Alpha','Ti Beta'}; %overwrite the phase names
phase_colors={'R','B'}; %overwrite the colors
%convert into a MTEX container
[ebsd] = H5OINA_Convert(ebsd_data,header_data,file_dset,phase_names,phase_colors);
%% Set the plotting preferences - this has to be validated for your instrument
%this is set up for the pFIB and Oxford Insturments systems at UBC
setMTEXpref('xAxisDirection','east'); %aztec
setMTEXpref('zAxisDirection','outofPlane'); %aztec
%font size and overwrite the scale bar if you want
setMTEXpref('FontSize',12)
%% Now do some plots
%band contrast
figure;
plot(ebsd,ebsd.prop.Band_Contrast); colormap('gray');
if exist('mb_length','var'); mp = MTEX_mb_fix(mb_length); end %change the micronbar length to make it prettier/easier to read
%% Plot the map of phases/indexed data
figure;
plot(ebsd');
%overlay with Band Contrast
figure;
plot(ebsd,ebsd.prop.Band_Contrast); colormap('gray');
hold on;
plot(ebsd,'FaceAlpha','0.3');
hold on;
if exist('mb_length','var'); mp = MTEX_mb_fix(mb_length); end %change the micronbar length to make it prettier/easier to read
%% IPF-x, y and z
% compute the colors
ipfKey1 = ipfTSLKey(ebsd(phase_names{1}));
ipfKey2 = ipfTSLKey(ebsd(phase_names{2}).CS);
%plot the key
f1=figure;
plot(ipfKey1)
nextAxis
plot(ipfKey2)
% now generate the IPF colour maps
ipfKey1.inversePoleFigureDirection = vector3d.X;
colors_X1 = ipfKey1.orientation2color(ebsd(phase_names{1}).orientations);
ipfKey1.inversePoleFigureDirection = vector3d.Y;
colors_Y1 = ipfKey1.orientation2color(ebsd(phase_names{1}).orientations);
ipfKey1.inversePoleFigureDirection = vector3d.Z;
colors_Z1 = ipfKey1.orientation2color(ebsd(phase_names{1}).orientations);
ipfKey2.inversePoleFigureDirection = vector3d.X;
colors_X2 = ipfKey2.orientation2color(ebsd(phase_names{2}).orientations);
ipfKey2.inversePoleFigureDirection = vector3d.Y;
colors_Y2 = ipfKey2.orientation2color(ebsd(phase_names{2}).orientations);
ipfKey2.inversePoleFigureDirection = vector3d.Z;
colors_Z2 = ipfKey2.orientation2color(ebsd(phase_names{2}).orientations);
%now plot the three IPF coloured maps
f2=figure;
plot(ebsd,'micronbar','off');
title('Phases')
nextAxis
plot(ebsd(phase_names{1}),colors_X1,'micronbar','off'); title('alpha IPF-X')
nextAxis
plot(ebsd(phase_names{1}),colors_Y1,'micronbar','off'); title('alpha IPF-Y')
nextAxis
plot(ebsd(phase_names{1}),colors_Z1,'micronbar','on'); title('alpha IPF-Z')
nextAxis
plot(ebsd(phase_names{2}),colors_X2,'micronbar','off'); title('beta IPF-X')
nextAxis
plot(ebsd(phase_names{2}),colors_Y2,'micronbar','off'); title('beta IPF-Y')
nextAxis
plot(ebsd(phase_names{2}),colors_Z2,'micronbar','on'); title('beta IPF-Z')
nextAxis
plot(ebsd(phase_names{1}),colors_X1,'micronbar','off'); hold on
plot(ebsd(phase_names{2}),colors_X2,'micronbar','off'); title('dual IPF-X')
nextAxis
plot(ebsd(phase_names{1}),colors_Y1,'micronbar','off'); hold on
plot(ebsd(phase_names{2}),colors_Y2,'micronbar','off'); title('dual IPF-Y')
nextAxis
plot(ebsd(phase_names{1}),colors_Z1,'micronbar','on'); hold on
plot(ebsd(phase_names{2}),colors_Y2,'micronbar','off'); title('dual IPF-Z')
if exist('mb_length','var'); mp = MTEX_mb_fix(mb_length); end %change the micronbar length to make it prettier/easier to read
%save the figures;
drawnow(); %updates the graphics engine to make sure it saves things properly
% print(f1,fullfile(resultsdir,'Map_IPFkey.png'),'-dpng','-r600');
% print(f2,fullfile(resultsdir,'Map_IPF.png'),'-dpng','-r600');
%% Plot the PF - scatter
%plot planes as spots, and use a subset
figure
plotPDF(ebsd(phase_names{1}).orientations,[Miller(0,0,1,ebsd(phase_names{1}).CS) Miller(1,1,0,ebsd(phase_names{1}).CS)])
nextAxis
plotPDF(ebsd(phase_names{2}).orientations,[Miller(0,1,1,ebsd(phase_names{2}).CS) Miller(1,1,1,ebsd(phase_names{2}).CS)])
%% Construct the ODF
%suggested reading:
%https://mtex-toolbox.github.io/ODFTutorial.html
%https://mtex-toolbox.github.io/PoleFigure2ODF.html
% compute the ODF
odf1 = calcDensity(ebsd(phase_names{1}).orientations);
odf2 = calcDensity(ebsd(phase_names{2}).orientations);
% You could also change/fix the half width - compare this different ODF
% odf = calcDensity(ebsd(mineral_name).orientations,'halfwidth',2*degree);
figure
plotPDF(odf1,[Miller(0,0,1,ebsd(phase_names{1}).CS) Miller(1,1,0,ebsd(phase_names{1}).CS)])
mtexColorbar('location','southoutside')
mtexColorMap blue2red
nextAxis
plotPDF(odf2,[Miller(0,1,1,ebsd(phase_names{2}).CS) Miller(1,1,1,ebsd(phase_names{2}).CS)])
mtexColorbar('location','southoutside')
mtexColorMap blue2red
%% Plot the KAM
%see https://mtex-toolbox.github.io/EBSDKAM.html for more detail
% it is important to read this carefully, the KAM can be calculated in lots
% of different ways
ebsd=gridify(ebsd); %gridify the data
[grains,ebsd.grainId] = calcGrains(ebsd,'angle',10*degree);
%smooth the grains to be prettier
grains_pretty = smooth(grains,5);
kam_alpha = ebsd(phase_names{1}).KAM / degree;
kam_beta = ebsd(phase_names{2}).KAM / degree;
%plot the spatial map
f1=figure;
s1=subplot(1,2,1); %create a subplot axis
plot(ebsd(phase_names{1}),kam_alpha,'parent',s1);
hold on;
plot(ebsd(phase_names{2}),kam_beta,'parent',s1);
clim([0,15])
mtexColorbar
mtexColorMap LaboTeX
plot(grains_pretty.boundary,'lineWidth',0.5,'parent',s1)
hold off
%note that using subplot removes the micronbar!!!
KAM_bins=linspace(0,15,31); %use half degree bins - 31 between 0 and 15
s2=subplot(1,2,2);
histogram(kam_alpha,KAM_bins,'Parent',s2);
hold on
histogram(kam_beta,KAM_bins,'Parent',s2);
legend({'KAM $$\alpha$$','KAM $$\beta$$'},'interpreter','latex')
ylabel('Frequency')
xlabel('KAM $$^{\circ}$$','interpreter','latex')
% as we can see that this graph has a different color range - rescale
% figure 1 color axis
s1.CLim=[0 5];
%% Now we can play with KAM this metric has some nuance
% see https://mtex-toolbox.github.io/EBSDKAM.html for a full explore
kam_alpha = ebsd(phase_names{1}).KAM / degree;
kam_alpha_3 = ebsd(phase_names{1}).KAM('threshold',3*degree) / degree;
kam_alpha_3_5neigh=ebsd.KAM('threshold',2.5*degree,'order',5) / degree;
KAM_bins=linspace(0,15,61); %use 0.25 degree bins - 61 between 0 and 15
figure;
histogram(kam_alpha,KAM_bins);
hold on
histogram(kam_alpha_3,KAM_bins);
histogram(kam_alpha_3_5neigh,KAM_bins);
legend({'KAM $$\alpha$$','KAM $$\alpha$$ 2.5 limit','KAM $$\alpha$$ 2.5 limit 5 neighbours'},'interpreter','latex')
%% We can also test if this data fits a distribution
%use prob plot to test a few potential distribution types
%
% look at prob plot for what you can try
figure;
subplot(2,2,1);
probplot('lognormal',kam_alpha);
subplot(2,2,2);
probplot('normal',kam_alpha);
subplot(2,2,3);
probplot('rayleigh',kam_alpha);
subplot(2,2,4);
probplot('half normal',kam_alpha);
% if the measured data (blue) fits on the model data (dashed line), then
% this distribution could be a reasonable approximation for the data type
%
% there are quite a few theories about what this distribution *should* be
%
% see work by Wolfgang Pantleon, as well as work by Jiang, Britton &
% Wilkinson
%% Further ideas
%you could extract one or more grains from the alpha phase and look at the
%orientations of the nearby beta
%you could measure the grain size or aspect ratio
%you could estimate the volume fraction
%
%you could estimate the volume fraction and consider that unindexed points
%are sysemtically more likley to be one phase or another
%
%you could estimate volume fraction after a clean up routine
%% copy this m file over, for archival purposes
mf_long=mfilename('fullpath');
[f1,f2,f3]=fileparts(mf_long);
mf_start=[mf_long '.m'];
mf_end=fullfile(resultsdir,[f2 '.m']);
try
copyfile(mf_start,mf_end)
catch
warning('m file not saved, likely due to spaces in the file name');
end