%==========================================================================
%==========================================================================
%__                        
%                                                |  \                       
%                     ______    ______   ______   \$$ _______               
%                    /      \  /      \ |      \ |  \|       \              
%                   |  $$$$$$\|  $$$$$$\ \$$$$$$\| $$| $$$$$$$\             
%                   | $$  | $$| $$   \$$/      $$| $$| $$  | $$             
%                   | $$__| $$| $$     |  $$$$$$$| $$| $$  | $$             
%                    \$$    $$| $$      \$$    $$| $$| $$  | $$             
%                    _\$$$$$$$ \$$       \$$$$$$$ \$$ \$$   \$$             
%                   |  \__| $$                                              
%                    \$$    $$                                              
%                     \$$$$$$                                               
%                                                    __                     
%                                                   |  \                    
%  ______   __    __   ______    ______    _______  \$$  _______   ______  
% /      \ |  \  /  \ /      \  /      \  /       \|  \ /       \ /      \ 
%|  $$$$$$\ \$$\/  $$|  $$$$$$\|  $$$$$$\|  $$$$$$$| $$|  $$$$$$$|  $$$$$$\
%| $$    $$  >$$  $$ | $$    $$| $$   \$$| $$      | $$ \$$    \ | $$    $$
%| $$$$$$$$ /  $$$$\ | $$$$$$$$| $$      | $$_____ | $$ _\$$$$$$\| $$$$$$$$
% \$$     \|  $$ \$$\ \$$     \| $$       \$$     \| $$|       $$ \$$     \
%  \$$$$$$$ \$$   \$$  \$$$$$$$ \$$        \$$$$$$$ \$$ \$$$$$$$   \$$$$$$$
%                                                                           
%                                                                           
%                                                                           
%                     ______    ______    ______     __                     
%                    /      \  /      \  /      \  _/  \                    
%                   |  $$$$$$\|  $$$$$$\|  $$$$$$\|   $$                    
%                    \$$__| $$| $$$\| $$ \$$__| $$ \$$$$                    
%                    /      $$| $$$$\ $$ /      $$  | $$                    
%                   |  $$$$$$ | $$\$$\$$|  $$$$$$   | $$                    
%                   | $$_____ | $$_\$$$$| $$_____  _| $$_                   
%                   | $$     \ \$$  \$$$| $$     \|   $$ \                  
%                    \$$$$$$$$  \$$$$$$  \$$$$$$$$ \$$$$$$                  
%                                                                           
%
%==========================================================================
%==========================================================================
%% import a simple ebsd dataset using the import_wizard

% data from Giulia degli Alessandrini MSc thesis,
% "THE EITA SHEAR ZONE; Val Grosina (N Italy), 2013
% supervised by Neil Mancktelow, Eric Reusser
% data by Karsten Kunze, ETHZ

% use sample40.ang
import_wizard('EBSD')

%% we can put the output of import_wizard here
% 
% % create an EBSD variable containing the data
% ebsd = EBSD.load(fname,CS,'interface','ang',...
%   'convertEuler2SpatialReferenceFrame','setting 2');

% note that when we use the import_wizard the "setting" option form OIM is 
% not set, meaning 'setting 1' by default (for historic reasons). However, 
% 'setting 2' seems to be the default in many cases as is also the case here.
%% 1) compute grains and do an ipf colorcoding
% useful command: calcGrains, ipfHSVKey




%% 2) colorcode the c-axis direction of grains and compute grains 
% based on c-axis direction
% Do you observe a difference to the IPF mapping? Which one?

% useful command: calcGrains, HSVDirectionKey







%% 3) overcome a twin related problem
% if we inspect the orientation maps (c-axis and ipf colorcoding) 
% we observe many mottled grains which relate to a twinning related problem
% -> quartz has a popular twinning law which is a 60 degree rotation
% around the c-axis (Dauphiné law).

% How can we get around this and compute grains with a meaningful mean
% orientation which ignore those twins WITHOUT using merge (because the 
% solution is more elegant and we do not know about boundaries yet)

% What symmetry operation would correspond to the Dauphiné twinning?

% useful hint: we can change the crystal symmetry of ebsd and grain
% objects but we must take care to use unique names 
% CStemporary = crystalSymmetry(something,'mineral','Kryptonite'
% ebsd('Uranium').CS = CStemporary;
% and in reverse of course!




% 3b) delete all grains <=5 pixels (let's asume they are bad measurements)
% and recalculate grains



%% 4) compute grain properties
% a) Plot a map of the GOS and map of grain size. Is there any correlation
% between those?




%% 5) Is there a relation of texture and grain size?
% a) Create two groups, one with the 100 largest grains



% b) plot polefigures for each class



% c) estimate two odfs and plot PDFs from those
% note that the polulations have hugely different sizes
% useful commands: calcKernel, calcDensity

% Do the different options of kernel width estimators have an influence on
% your conclusion?





%% 7) Do equiaxed, small grains have a different texture than 
% elongated, small grains
% Fit an ellipse to grains and inspect the results
% We should probably cut away grains at the boundaries.
% useful commands: isBoundary, principalComponents,smooth





%% 8) What can we say about the preferred shape fabric of small grains
% plot a length and area weighted histograms of grain long axes
% useful commands: longAxis, paror





%% 9) Question session: What else would you want to do with grains?





