clear
close all
%
%% Import Script for EBSD Data
%
% This script was automatically created by the import wizard. You should
% run the whoole script or parts of it in order to import your data. There
% is no problem in making any changes to this script.
%% Specify Crystal and Specimen Symmetries
% crystal symmetry
CS = {...
'notIndexed',...
crystalSymmetry('-1', [8.1796 12.8747 14.172], [93.13,115.89,91.24]*degree, 'X||a*', 'Z||c', 'mineral', 'Anorthite', 'color', 'blue'),...
crystalSymmetry('321', [4.913 4.913 5.504], 'X||a*', 'Y||b', 'Z||c', 'mineral', 'Quartz-new', 'color', 'light blue'),...
crystalSymmetry('m-3m', [11.531 11.531 11.531], 'mineral', 'Almandine', 'color', 'red'),...
crystalSymmetry('12/m1', [9.794 8.906 5.319], [90,105.9,90]*degree, 'X||a*', 'Y||b', 'Z||c', 'mineral', 'Clinopyroxene', 'color', 'green'),...
crystalSymmetry('mmm', [18.316 8.907 5.218], 'mineral', 'Orthopyroxene', 'color', 'magenta'),...
crystalSymmetry('12/m1', [9.967 18.269 5.347], [90,104.97,90]*degree, 'X||a*', 'Y||b', 'Z||c', 'mineral', 'Hastingsite', 'color', 'yellow'),...
crystalSymmetry('m-3m', [8.3958 8.3958 8.3958], 'mineral', 'Magnetite', 'color', 'cyan'),...
crystalSymmetry('-3', [5.1412 5.1412 14.225], 'X||a*', 'Y||b', 'Z||c', 'mineral', 'Ilmenite', 'color', 'light red')};
% plotting convention
setMTEXpref('xAxisDirection','east');
setMTEXpref('zAxisDirection','IntoPlane');
%% Specify File Names
% path to files
pname = 'C:\Users\Mahanaxar\Documents\MATLAB\Samples\Cora Lake shear zone\02M-140a\Prior Protocol';
% which files to be imported
fname = [pname '\02M140A_Prior_map.cpr'];
%% Import the Data
% create an EBSD variable containing the data
ebsd = loadEBSD(fname,CS,'interface','crc',...
'convertEuler2SpatialReferenceFrame');
%% Make some general cosmetic changes
%minimum number of pixels per grain, check step size of map to determine
%best number here
minimum_grainsize = 3
% Manually define phase colors so that all maps match each other
ebsd('Anorthite').color = [65/255 105/255 225/255];
%ebsd('Albite - mon').color = [65/255 105/255 225/255];
ebsd('Clinopyroxene').color = [0/255 128/255 0/255];
ebsd('Orthopyroxene').color = [238/255 130/255 238/255];
ebsd('Almandine').color = [255/255 0/255 0/255];
ebsd('Ilmenite').color = [192/255 192/255 192/255];
ebsd('Magnetite').color = [128/255 128/255 128/255];
ebsd('Quartz-new').color = [255/255 255/255 0/255];
%ebsd('Quartz').color = [255/255 255/255 0/255];
ebsd('Hastingsite').color = [128/255 128/255 0/255];
%ebsd('Diopside').color = [0/255 128/255 0/255];
%ebsd('Pyrope').color = [255/255 0/255 0/255];
%ebsd('Sillimanite').color = [0/255 255/255 0/255];
%ebsd('Biotite').color = [218/255 165/255 32/255];
%ebsd('Orthoclase').color = [128/255 0/255 128/255];
%ebsd('Muscovite').color = [255/255 0/255 255/255];
diary('O2M140A_WSPP raw EBSD map properties.txt')
ebsd
diary off
save('O2M140A_WSPP_ebsd','ebsd');
setMTEXpref('defaultColorMap',hot)
% 15 degree boundaries
%
%load 'O2M140A_WSPP_ebsd.mat'
F = splineFilter;
% smooth the data
ebsd_smoothed = smooth(ebsd,F);
save('O2M140A_WSPP_ebsd_smoothed','ebsd_smoothed');
oM = ipdfHSVOrientationMapping(ebsd_smoothed('Anorthite'));
% the smoothing parameter determined during smoothing is
F.alpha
%
minimum_grainsize = 3;
% Let's remove the unindexed stuff and then reconstruct the grains
% perform grain reconstruction
[grains, ebsd_smoothed.grainId] = calcGrains(ebsd_smoothed,'angle',15*degree,'boundary','tight');
%then reassign the unindexed areas to not be filled in
notIndexed = grains('notIndexed');
% the "not indexed grains" we want to remove
toRemove = notIndexed(notIndexed.grainSize ./ notIndexed.boundarySize<0.8);
% now we remove the corresponding EBSD measurements
ebsd_smoothed(toRemove) = [];
% Then get rid of those pissant little grains that are probably just errors
% remove all grains with less than 3 measurements
large_grains = grains(grains.grainSize >= minimum_grainsize);
%// perform new grain reconstruction
ebsd_cleaned = ebsd_smoothed(large_grains);
[grains_cleaned, ebsd_cleaned.grainId, ebsd_cleaned.mis2mean] = calcGrains(ebsd_cleaned,'angle',15*degree,'boundary','tight');
% And now we can get rid of some of that nasty staircasing effect on the grain boundaries
grains_smoothed = smooth(grains_cleaned);
save('O2M140A_WSPP_grains_smoothed','grains_smoothed');
save('O2M140A_WSPP_ebsd_cleaned','ebsd_cleaned');
%
clear
minimum_grainsize = 3;
load('O2M140A_WSPP_ebsd_smoothed','ebsd_smoothed');
% Let's remove the unindexed stuff and then reconstruct the grains
% perform grain reconstruction
[subgrains, ebsd_smoothed.grainId] = calcGrains(ebsd_smoothed,'angle',2*degree,'boundary','tight');
%then reassign the unindexed areas to not be filled in
notIndexed = subgrains('notIndexed');
% the "not indexed grains" we want to remove
toRemove = notIndexed(notIndexed.grainSize ./ notIndexed.boundarySize<0.8);
% now we remove the corresponding EBSD measurements
ebsd_smoothed(toRemove) = [];
% Then get rid of those pissant little grains that are probably just errors
% remove all grains with less than 3 measurements
large_subgrains = subgrains(subgrains.grainSize >= minimum_grainsize);
%// perform new grain reconstruction
ebsd_subgrains_cleaned = ebsd_smoothed(large_subgrains);
[subgrains_cleaned, ebsd_subgrains_cleaned.grainId, ebsd_subgrains_cleaned.mis2mean] = calcGrains(ebsd_subgrains_cleaned,'angle',2*degree,'boundary','tight');
% And now we can get rid of some of that nasty staircasing effect on the grain boundaries
subgrains_smoothed = smooth(subgrains_cleaned);%%
close all
%small_subgrains = subgrains(subgrains.grainSize <= 10);
save('O2M140A_WSPP_subgrains','subgrains_smoothed');
% Figures
load('O2M140A_WSPP_grains_smoothed','grains_smoothed');
load('O2M140A_WSPP_ebsd_cleaned','ebsd_cleaned');
figure
plot(subgrains_smoothed('Anorthite'),'micronbar','off')
export_fig 'O2M140A_WSPP Anorthite subgrains.jpg' -m1
figure
plot(grains_smoothed('Anorthite'),'micronbar','off')
export_fig 'O2M140A_WSPP Anorthite grains.jpg' -m1
figure
plot(ebsd_cleaned('Anorthite'),'micronbar','off')
hold on
plot(subgrains_smoothed('Anorthite').boundary,'linecolor','r','linewidth',1)
plot(grains_smoothed('Anorthite').boundary,'linewidth',2)
export_fig 'O2M140A_WSPP Anorthite grains and subgrains.jpg' -m1