forked from LightForm-group/phase-field-pre-processor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsegment_slice.m
176 lines (130 loc) · 5.39 KB
/
segment_slice.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
function [grainIDs] = segment_slice_new(argsJSONPath)
close all;
allArgs = jsondecode(fileread(argsJSONPath));
SS = {specimenSymmetry(allArgs.specimen_symmetry)};
CS = cell(length(allArgs.crystal_symmetries));
phaseNames = cell(length(allArgs.crystal_symmetries));
for CSIdx = 1:length(allArgs.crystal_symmetries)
CSData = allArgs.crystal_symmetries(CSIdx);
phaseNames{CSIdx} = CSData.mineral;
alignment = {};
if isfield(CSData.unit_cell_alignment, 'x')
alignment{end + 1} = sprintf('X||%s', CSData.unit_cell_alignment.x);
end
if isfield(CSData.unit_cell_alignment, 'y')
alignment{end + 1} = sprintf('Y||%s', CSData.unit_cell_alignment.y);
end
if isfield(CSData.unit_cell_alignment, 'z')
alignment{end + 1} = sprintf('Z||%s', CSData.unit_cell_alignment.z);
end
CS{CSIdx} = crystalSymmetry(CSData.symmetry, 'mineral', CSData.mineral, alignment{:});
end
ebsd = EBSD.load( ...
allArgs.orientations_data_path, ...
'CS', CS, ...
'SS', SS, ...
'ColumnNames', {'Phase', 'x', 'y', 'Euler1', 'Euler2', 'Euler3'}, ...
'Bunge' ...
);
grains = calcGrains(ebsd, 'FMC', allArgs.C_Maha);
grains_smooth = smooth(grains, allArgs.smoothing);
ebsdsq = gridify(ebsd);
grainIDs = zeros(size(ebsdsq), 'int32');
for xIdx = 1:size(ebsdsq.x, 1)
for yIdx = 1:size(ebsdsq.x, 2)
xCoord = ebsdsq.x(xIdx, yIdx);
yCoord = ebsdsq.y(xIdx, yIdx);
point = [xCoord, yCoord];
grainID = findByLocation(grains_smooth, point);
if numel(grainID) == 1
grainIDs(xIdx, yIdx) = grainID;
end
end
end
save('grainIDs.mat', 'grainIDs');
figure();
h = heatmap(grainIDs);
h.GridVisible = "off";
colormap default
exportgraphics(gcf, 'grainIDs.png');
colours = cell(length(phaseNames));
for phaseIdx = 1:length(phaseNames)
phaseName = phaseNames{phaseIdx};
colourMap = ones(grains_smooth(phaseName).length, 3) .* grains_smooth(phaseName).id / grains_smooth.length;
colourMap(1:end, 1:2) = 0; % assign blue channel only
colours{phaseIdx} = colourMap;
end
% These preferences then coincide with viewing the grain assignment in a
% Python figure:
setMTEXpref('xAxisDirection', 'east');
setMTEXpref('zAxisDirection', 'intoPlane');
% Show grain boundaries of clustered grains, overlayed on IPF map
figure();
for phaseIdx = 1:length(phaseNames)
phaseName = phaseNames{phaseIdx};
plot(ebsd(phaseName), ebsd(phaseName).orientations, 'micronbar', 'off');
hold on;
end
plot(grains.boundary);
hold off;
set(gcf, 'graphicssmoothing', 'off')
exportgraphics(gca, 'clustered_grains_original.png', 'Resolution', allArgs.fig_resolution);
% Show *smoothed* grain boundaries of clustered grains, overlayed on IPF map
figure();
for phaseIdx = 1:length(phaseNames)
phaseName = phaseNames{phaseIdx};
plot(ebsd(phaseName), ebsd(phaseName).orientations, 'micronbar', 'off');
hold on;
end
plot(grains_smooth.boundary);
hold off;
set(gcf, 'graphicssmoothing', 'off')
exportgraphics(gca, 'clustered_grains_smoothed.png', 'Resolution', allArgs.fig_resolution);
% Show mean orientation of clustered grains and grain boundaries
figure();
ipfKeys = cell(length(phaseNames));
for phaseIdx = 1:length(phaseNames)
phaseName = phaseNames{phaseIdx};
ipfKey = ipfColorKey(ebsd(phaseName));
ipfKeys{phaseIdx} = ipfKey;
mean_ori_colors = ipfKey.orientation2color(grains(phaseName).meanOrientation);
plot(grains_smooth(phaseName), mean_ori_colors, 'micronbar');
hold on;
end
hold off;
set(gcf, 'graphicssmoothing', 'off')
exportgraphics(gca, 'clustered_grains_mean_ori.png', 'Resolution', allArgs.fig_resolution);
% Save IPF keys
for phaseIdx = 1:length(ipfKeys)
phaseName = phaseNames{phaseIdx};
figure();
plot(ipfKeys{phaseIdx});
exportgraphics(gca, sprintf('IPF_key_%s.png', phaseName), 'Resolution', allArgs.fig_resolution);
end
% Show grain boundary misorientation distribution
figure();
for phaseIdx_1 = 1:length(phaseNames)
for phaseIdx_2 = phaseIdx_1:length(phaseNames)
phaseName_1 = phaseNames{phaseIdx_1};
phaseName_2 = phaseNames{phaseIdx_2};
GB = grains.boundary(phaseName_1, phaseName_2);
if ~isempty(GB)
plotAngleDistribution(GB.misorientation);
exportgraphics(gca, sprintf('misori_dist_%s_%s.png', phaseName_1, phaseName_2), 'Resolution', allArgs.fig_resolution);
end
end
end
% Show (smoothed) grain boundary misorientation distribution
figure();
for phaseIdx_1 = 1:length(phaseNames)
for phaseIdx_2 = phaseIdx_1:length(phaseNames)
phaseName_1 = phaseNames{phaseIdx_1};
phaseName_2 = phaseNames{phaseIdx_2};
GB = grains_smooth.boundary(phaseName_1, phaseName_2);
if ~isempty(GB)
plotAngleDistribution(GB.misorientation);
exportgraphics(gca, sprintf('misori_dist_smooth_%s_%s.png', phaseName_1, phaseName_2), 'Resolution', allArgs.fig_resolution);
end
end
end
end