%% Import Script for EBSD Data (Tested using MTEX 4.0.9)
%
% David Mainprice 15/01/2015
%
% Importing example EBSD dataset used in many examples of the MTEX Help
% file accessible in MATLAB menu Help -> Production Help -> MTEX Toolbox
%
% Reference for EBSD dataset used in this example
%
% Andrea Tommasi, Alain Vauchez, Dmitri A. Ionov (2008)
% Deformation, static recrystallization, and reactive melt transport in shallow
% subcontinental mantle xenoliths (Tok Cenozoic volcanic field, SE Siberia)
% Earth and Planetary Science Letters 272 (2008) 65-77.
%
% Sample
%*****************************************************************************************
% 9510-16-map-stitch-pscleaned.ctf
%*****************************************************************************************
%
% Worked MTEX4/MatLab examples for the seismic properties from EBSD
% 
% A) Import of Oxford/HKL *.ctf (ASCII) file
%
% Uses *.ctf data file at pname = '/MatLab_Programs/MTEX_Workshop_Distibution';
%
% B) Area fractions of all indexed phases
%
% C) Example of editing EBSD Phase colors in RGB Red Green Blue values
%   (activate by removing % at the beginning of the line)
%
% D) Create simplified "Crystal Symmetry variables" for all phases
%
% E) Create list of pole figures with hkls 100,010,001 for Forsterite
%    Exercise :  create a list for Enstatite and Diopside
%
% F) Calculate the ODF of Forsterite and the Texture Index (= J-index)
%    Exercise :  Vary the hafwidth of ODF from 5 to 20, what effect does
%                it have on texture index and pole figures ?
%                Create an ODF for Enstatite and Diopside and calculate
%
% G) Calculate pole figures of Forsterite
%    Exercise :  Try to plot the polefigures using ODFs of differnt half-width.
%                Try different pole figure options 'contourf', 'antipodal'
%                colorbar % remove colorbars
%                CLim(gcm,'equal');
%                colorbar % add a single colorbar
%
% H) Plot EBSD maps based on orientations (EBSD pixels), this the RAW data.
%
%
% I) Correcting EBSD data use mad
%
% K) Modelling grains using segmentation angle and
%    the 'keepNotIndexed' options
%
% L) Removing small grains - not representative small grains, may be errors
%
% M) Plot EBSD maps based grains and their properties like area and
%    misorientation
%
%
%% clear memory and close plots - for new analysis of EBSD data
clear all
close all
%% Specify Crystal and Specimen Symmetries

% crystal symmetry
CS = {... 
  'notIndexed',...
  crystalSymmetry('mmm', [4.756 10.207 5.98], 'mineral', 'Forsterite', 'color', 'dark green'),...
  crystalSymmetry('mmm', [18.2406 8.8302 5.1852], 'mineral', 'Enstatite', 'color', 'light red'),...
  crystalSymmetry('12/m1', [9.746 8.99 5.251], [90,105.63,90]*degree, 'X||a*', 'Y||b*', 'Z||c', 'mineral', 'Diopside', 'color', 'dark blue'),...
  crystalSymmetry('m-3m', [5.431 5.431 5.431], 'mineral', 'Silicon', 'color', 'cyan')};

% specimen symmetry : the MTEX4 default is triclinic so do not need this line
SS = specimenSymmetry('triclinic'); 
% plotting convention
setMTEXpref('xAxisDirection','east');
setMTEXpref('zAxisDirection','outOfPlane');

%% Specify File Names

% path to files
pname = '/MatLab_Programs/MTEX_Workshop_Distibution';

% which files to be imported
fname = [pname '/9510-16-map-stitch-pscleaned.ctf'];
%% Import the Data

% create an EBSD variable containing the data
ebsd = loadEBSD(fname,CS,'interface','ctf',...
  'convertSpatial2EulerReferenceFrame', 'wizard')
%% Example of editing RGB Red Green Blue values (tested with MTEX4)
% Find the RGB values for mineral colour on EBSD phase map
% RGB_Forsterite = ebsd('Forsterite').color;
% Replace with new RGB values,  the R,G and B Have values between zero and one,
% they can be fraction like 0.25
% Set [R G B] to [0 1 1] R=0 G=1 B=1 this gives 'cyan'
% ebsd('Forsterite').color = [0 1 1];

%%
%***********************************************************************
% Set up area fractions                            (tested with MTEX4)
%***********************************************************************
% list of phase names
Phase_names = ebsd.mineralList;
% zero area fractions
Area_Fractions = zeros(numel(Phase_names));
% number of measurement points in the map
Map_points = length(ebsd);
% default first phase is indexed the perfect sample !
N_first_indexed_phase = 1;
% remove 'nonIndexed' points from total
% if 'notIndexed' is present
if(strcmp(Phase_names(1),'notIndexed'))
    N_first_indexed_phase = 2;
end
%**************************************************************************
% Area fractions for all phases in the EBSD object including non-indexed
%**************************************************************************
% print results to screen
fprintf(' \n')
fprintf(' Area fractions for all phases in the EBSD object \n')
fprintf(' \n')
fprintf('   #      Phase       Points  Area fraction \n')
for i=1:numel(Phase_names);
% indexed point for mineral
N_Points = length(ebsd(Phase_names(i)));
   if(N_Points > 0)
% area fraction for mineral
Area_Fractions(i) = N_Points/Map_points;
% retain first part of mineral name
P_Name = strtok(char(Phase_names{i}),' ');
      fprintf(' %3i %12s %10i %11.4f \n',...
      i,P_Name,N_Points,Area_Fractions(i))
   end
end
AF_total = sum(sum(Area_Fractions));
fprintf(' \n')
fprintf(' Total area fraction = %8.4f \n',AF_total)
fprintf(' \n')

% total number of indexed points in map without 'notIndexed' phase
Indexed_map_points = sum(length(ebsd(Phase_names(N_first_indexed_phase:numel(Phase_names)))));
% percentage of indexed point in map
Percent_indexed = 100*Indexed_map_points/Map_points;
% print to screen
fprintf(' \n')
fprintf(' Percentage indexed points in map = %5.1f \n',Percent_indexed)
fprintf(' \n')
%**************************************************************************
% Area fractions based on minerals with EBSD indexed points only
%**************************************************************************
% print results to screen
fprintf(' \n')
fprintf(' Area fractions based on minerals with EBSD indexed points only \n')
fprintf(' \n')
fprintf('   #      Phase       Points  Area fraction \n')
for i=N_first_indexed_phase:numel(Phase_names);
% indexed point for mineral
N_Points = length(ebsd(Phase_names(i)));
   if(N_Points > 0)
% area fraction for mineral
Area_Fractions(i) = N_Points/Indexed_map_points;
% retain first part of mineral name
P_Name = strtok(char(Phase_names{i}),' ');
      fprintf(' %3i %12s %10i %11.4f \n',...
      i,P_Name,N_Points,Area_Fractions(i))
   end
end
AF_total = sum((Area_Fractions(N_first_indexed_phase:numel(Phase_names))));
fprintf(' \n')
fprintf(' Total area fraction = %8.4f \n',AF_total)
fprintf(' \n')

%% Generate simple Crystal Symmetry variables for all phases (tested with MTEX4)
fprintf(' \n');
fprintf(' Crystal Symmetry (CS) : names of variables \n');
fprintf(' \n');
% phase names
Phase_names = ebsd.mineralList;
for i=1:length(CS)
% indexed point for mineral
     N_Points = length(ebsd(Phase_names(i)));
% print only indexed phases
    if((~strcmpi(Phase_names{i},'notIndexed')) && (N_Points > 0))
% retain first part of mineral name
      P_Name = strtok(char(Phase_names{i}),' ');
% make variables for CS with mineral names
      myvariable = strcat(P_Name,'_CS');
      datavalues = CS{i};
% print variable names for CS
      eval([sprintf(myvariable) ' = CS{i};'])
      fprintf(' %s %s \n','Variable name =',myvariable);
    end
end
disp(' ')
disp(' Use mineral_CS to defined your CS in m-file ')
disp(' ')
%% Calculate an ODF (tested with MTEX4)
%odf_Forsterite = calcODF(ebsd('Forsterite').orientations,'halfwidth',20*degree)
odf_Forsterite = calcODF(ebsd('Forsterite').orientations)
% Texture index
Jindex_Forsterite = textureindex(odf_Forsterite)
%%
%**************************************************************************
% Create list of pole figures with hkls 100,010,001     (tested with MTEX4)
%**************************************************************************
% MTEX cannot mix hkls and uvws
% pole to planes can be specified by the option 'pole' or 'hkl' 
% directions are specified by the option 'uvw' 
%
PFs_Forsterite_hkl = [ ...
    Miller(1,0,0,Forsterite_CS,'hkl','phase','Forsterite'), ...
    Miller(0,1,0,Forsterite_CS,'hkl','phase','Forsterite'), ...
    Miller(0,0,1,Forsterite_CS,'hkl','phase','Forsterite'), ...
    ]
PFs_Forsterite_uvw = [ ...
    Miller(1,0,0,Forsterite_CS,'uvw','phase','Forsterite'), ...
    Miller(0,1,0,Forsterite_CS,'uvw','phase','Forsterite'), ...
    Miller(0,0,1,Forsterite_CS,'uvw','phase','Forsterite'), ...
    ]
%%
%**************************************************************************
% Plot Forsterite (100) Pole Figure (PF) in Sample co-ordinates (X,Y,Z)
% As 3D object
%**************************************************************************
figure
setMTEXpref('FontSize',25)
plotPDF(odf_Forsterite,Miller(1,0,0,Forsterite_CS,'hkl','phase','Forsterite'),'antipodal','resolution',5*degree,'3d');
colorbar
% add labels for X,Y and Z sample directions on PFs
annotate([xvector,yvector,-zvector],'label',{'X','Y','Z'},'backgroundcolor','w','MarkerSize',15,'FontSize',20)
% gray for publications
%colormap(white2blackColorMap)
% file name
saveFigure('/MatLab_Programs/PFs_contour_hkls_Forsterite_colorbar_for_each_default_3D.pdf')

%%
%**************************************************************************
% Plot Forsterite Pole Figures (PFs)  in Sample co-ordinates (X,Y,Z) (tested with MTEX4)
% Colorbar for each pole figure (default)
%**************************************************************************
figure
setMTEXpref('FontSize',25)
plotPDF(odf_Forsterite,PFs_Forsterite_hkl,'antipodal','resolution',5*degree);
colorbar
% add labels for X,Y and Z sample directions on PFs
annotate([xvector,yvector,-zvector],'label',{'X','Y','Z'},'backgroundcolor','w','MarkerSize',15,'FontSize',20)
% gray for publications
%colormap(white2blackColorMap)
% file name
saveFigure('/MatLab_Programs/PFs_contour_hkls_Forsterite_colorbar_for_each_default.pdf')
%%
%**************************************************************************
% Plot Forsterite Pole Figures (PFs)  in Sample co-ordinates (X,Y,Z) (tested with MTEX4)
% Colorbar for each pole figure (default)
%**************************************************************************
figure
setMTEXpref('FontSize',25)
plotPDF(odf_Forsterite,PFs_Forsterite_hkl,'antipodal','resolution',5*degree,'contourf');
colorbar
% add labels for X,Y and Z sample directions on PFs
annotate([xvector,yvector,-zvector],'label',{'X','Y','Z'},'backgroundcolor','w','MarkerSize',15,'FontSize',20)
% gray for publications
%colormap(white2blackColorMap)
% file name
saveFigure('/MatLab_Programs/PFs_contour_hkls_Forsterite_colorbar_for_each_contourf.pdf')
%%
%**************************************************************************
% Plot Forsterite Pole Figures (PFs)  in Sample co-ordinates (X,Y,Z) (tested with MTEX4)
% One colorbar for all pole figures : use CLim(gcm,'equal')
%**************************************************************************
figure
setMTEXpref('FontSize',25)
plotPDF(odf_Forsterite,PFs_Forsterite_uvw,'antipodal','resolution',5*degree,'contourf');
% add single colorbar for all pole figures
CLim(gcm,'equal');
% single colorbar for all pole figures
colorbar 
% add labels for X,Y and Z sample directions on PFs
annotate([xvector,yvector,-zvector],'label',{'X','Y','Z'},'backgroundcolor','w','MarkerSize',20,'FontSize',20)
% gray for publications
%colormap(white2blackColorMap)
% file name
saveFigure('/MatLab_Programs/PFs_contour_hkls_Forsterite_one_colorbar_for_all.pdf')
%%
%**************************************************************************
% EBSD Maps
%**************************************************************************
%% Default map is the phase map you can chose the size 'small', 'normal' or 'large' (tested with MTEX4)
% By default MTEX plots a phase map for EBSD data
close all
figure
plot(ebsd,'figSize','small')
%%
close all
figure
plot(ebsd,'figSize','medium')
%%
close all
figure
plot(ebsd,'figSize','large')
%% plot an EBSD property  - Properties: bands, bc, bs, error, mad, x, y (tested with MTEX4)
% like mean angular deviation (mad)
close all
figure
plot(ebsd,ebsd.mad,'figSize','large')
colorbar
%% plot an EBSD property - band contrast (bc) (tested with MTEX4)
close all
figure
plot(ebsd,ebsd.bc,'figSize','large')
% you can select the colormap to suit you requirements
% 'gray' scale from black (0) to white (255)
%colormap gray
% or 'white2black' black (255) to white (0)
mtexColorMap white2black
colorbar
%% orientation map using the rotation angle in specimen coordinates to define the colormap (tested with MTEX4)
% The default reference is reference orientation in Bunge Euler angles (0,0,0) degrees
plot(ebsd('Forsterite'),ebsd('Forsterite').orientations.angle./degree,'figSize','large')
colorbar
%% orientation map using the rotation angle in specimen coordinates to define the colormap (tested with MTEX4)
% User defined REFERENCE ORIENTATION Bunge Euler angles (166,147,72) degrees (long blue NS grain in map)
reference_o = orientation('Euler',166*degree,147*degree,72*degree,ebsd('Forsterite').CS)
plot(ebsd('Forsterite'),angle(ebsd('Forsterite').orientations,reference_o)./degree,'figSize','large')
colorbar
%% orientation map one mineral with Euler RGB colormap: uses colours in ODF sections(tested with MTEX4)
close all
figure
% define the RGB to Bunge Euler angles to RGB orientation colormap
oM = BungeRGBOrientationMapping(ebsd('Forsterite'))
plot(ebsd('Forsterite'),oM.orientation2color(ebsd('Forsterite').orientations),'figSize','large')
% Orientation colour bar plot - euler angle ODF sections (tested with MTEX4)
figure
plot(oM)
%% orientation map one mineral with IPF colorbar for r = xvector (tested with MTEX4)
close all
figure
% select IPF colorbar for specific mineral (a,b,c,alpha,beta,gamma) and symmetry
oM = ipdfHSVOrientationMapping(ebsd('Forsterite'))
% define the SPECIMEN DIRECTION (r) for IPF orientation colormap
oM.inversePoleFigureDirection = yvector;
plot(ebsd('Forsterite'),oM.orientation2color(ebsd('Forsterite').orientations),'figSize','large')
% The 'notindexed' phase are by default plotted as white, you can change it to black 
hold on
plot(ebsd('notIndexed'),'FaceColor','black','figSize','large')
hold off
% Orientation IPF colourbar plot - Orthorhombic with Forsterite symmetry and r = x = 1,0,0 (tested with MTEX4)
figure
plot(oM)
%% orientation map with colourbar with restricted symmetry (tested with MTEX4)
close all
figure
color = oM.orientation2color(ebsd('Forsterite').orientations);
plot(ebsd('Forsterite'),color,'figSize','large')
%% orientation map with colourbar with all ebsd data (*** does not work bcause multi-phase **)
figure
oM = ipdfHSVOrientationMapping(ebsd('Forsterite'));
plot(ebsd('Forsterite'),oM.orientation2color(ebsd('Forsterite').orientations),'figSize','large')
%% Orientation colourbar with restricted symmetry RGB mix vs number of orientations
close all
figure
plot(color)
%**************************************************************************
%% Correcting EBSD data use mad (tested with MTEX4)
%**************************************************************************
close all
figure
plot(ebsd,ebsd.mad)
colorbar
%% plot a histogram
close all
figure
hist(ebsd.mad)
%%
% take only those measurements with MAD smaller then 1.3
ebsd_corrected = ebsd(ebsd.mad<1.3)
close all
figure
hist(ebsd_corrected.mad)
%%
close all
figure
plot(ebsd_corrected,ebsd_corrected.mad)
colorbar
%**************************************************************************
%% Grain modelling  (tested with MTEX4)
%**************************************************************************
%
% You can loop over this cell changing segmentation angle and the
% the 'keepNotIndexed' options
% You should compared the resulting grain map with EBSD (pixel) phase
% or orientation (pixel) map or Band Contrast map
%**************************************************************************
%
%%
disp(' ')
disp(' Grain segmentation angle option ')
disp(' Choose a high angle typically between 15 to 10 degrees for geological samples')
disp(' OR choose low angle of 2 degrees if you want to detect sub-grains')
segmentation_angle = input('The segmentation angle (e.g. 2-15):');
segAngle = segmentation_angle*degree;
%
disp(' ')
disp(' Keep non-indexed points option ')
disp('*1= Scientifically correct, not extrapolating raw indexed data')
disp('    model grains BUT keep non-index points : Default in MTEX 4')
disp(' 2= May be more geologically correct in some cases, use with care')
disp('    model grains AND include non-index points within grains boundaries')
disp('    N.B. this option does NOT ADD map pixels with neighbouring ORIENTATIONS')
non_indexed_option = input('Option an integer  (1-2):');
%
% keep non-indexed in now default in MTEX4
if(non_indexed_option == 1)
    [grains,ebsd.grainId,ebsd.mis2mean] = calcGrains(ebsd,'angle',segAngle)
end
% remove non-indexed points, restrict to indexed points only
if(non_indexed_option == 2)
    [grains,ebsd.grainId,ebsd.mis2mean] = calcGrains(ebsd('indexed'),'angle',segAngle)
end
% number of grains all phases 
number_of_calcGrains = grains.length
% plot 'grain' phase map
figure
% Correct MatLab problem with colour buffer
set(gcf,'renderer','zbuffer')
% Default phase map
plot(grains,'figSize','large')
%
%**************************************************************************
%% Removing small grains - not representative small grains, may be errors
%**************************************************************************
%
% You can loop over this cell changing number of indexed points per grain
% You should compared the resulting grain map with EBSD (pixel) phase
% or orientation (pixel) map
%**************************************************************************
%
disp(' ')
disp(' Small grains option ')
disp(' Remove small grains containing less than a critical')
disp(' number of indexed points as they error prone or ')
disp(' If you require an accurate grain size and shape analysis')
disp(' the recommended minimum number indexed points per grain size is 10')
disp(' You can decide to keep all grain by accepting all grains with 0')
small_grains_option = input('Indexed points per grain an integer (e.g. 0-10):');
%
% remove grains containing less than critical number of indexed points, 
selected_grains = grains(grains.grainSize > small_grains_option);
% number of small grains removed from all phase
number_of_small_grains_removed = number_of_calcGrains - selected_grains.length
%n_Forsterite_grains = selected_grains('Forsterite').length
figure
% Correct MatLab problem with colour buffer
set(gcf,'renderer','zbuffer')
% MTEX 4 default map is phase map
plot(selected_grains,'figSize','large')
%% Orientation from reference (ebsd orientations plus grain boundaries)
plot(ebsd('Forsterite'),ebsd('Forsterite').orientations.angle./degree,'figSize','large')
colorbar
hold on
% plot grain boundaries
plot(grains.boundary,'position','large','linewidth',1,'figSize','large')
%%
%**************************************************************************
% Size and shape of grains : area,grainSize,perimeter,
% equivalent radius & perimeter,aspectRatio,shapeFactor
% all phases
%**************************************************************************
%% Forsterite grains coloured by area (tested with MTEX4)
plot(grains,grains.area,'figSize','large')
colorbar
%% Forsterite grains coloured by grainSize (tested with MTEX4)
plot(grains,grains.grainSize,'figSize','large')
colorbar
%% Forsterite grains coloured by perimeter (tested with MTEX4)
plot(grains,grains.perimeter,'figSize','large')
colorbar
%% Forsterite grains coloured by equivalentPerimeter (tested with MTEX4)
plot(grains,grains.equivalentPerimeter,'figSize','large')
colorbar
%% Forsterite grains coloured by equivalentRadius (tested with MTEX4)
plot(grains,grains.equivalentRadius,'figSize','large')
colorbar
%% Forsterite grains coloured by aspect ratio (tested with MTEX4)
figure
plot(grains,grains.aspectRatio,'figSize','large')
colorbar
%% Forsterite grains coloured by shape factor (tested with MTEX4)
figure
plot(grains,grains.shapeFactor,'figSize','large')
colorbar
%**************************************************************************
% Size and shape of grains : area,grainSize,perimeter,
% equivalent radius & perimeter,aspectRatio,shapeFactor
% selected phase NOT Working grains('Forsterite')
%**************************************************************************
%% Forsterite grains coloured by area (tested with MTEX4)
plot(grains('Forsterite'),grains('Forsterite').area,'figSize','large')
colorbar
%% Forsterite grains coloured by grainSize (tested with MTEX4)
plot(grains('Forsterite'),grains('Forsterite').grainSize,'figSize','large')
colorbar
%% Forsterite grains coloured by perimeter (tested with MTEX4)
plot(grains('Forsterite'),grains('Forsterite').perimeter,'figSize','large')
colorbar
%% Forsterite grains coloured by equivalentPerimeter (tested with MTEX4)
plot(grains('Forsterite'),grains('Forsterite').equivalentPerimeter,'figSize','large')
colorbar
%% Forsterite grains coloured by equivalentRadius (tested with MTEX4)
plot(grains('Forsterite'),grains('Forsterite').equivalentRadius,'figSize','large')
colorbar
%% Forsterite grains coloured by aspect ratio (tested with MTEX4)
figure
plot(grains('Forsterite'),grains('Forsterite').aspectRatio,'figSize','large')
colorbar
%% Forsterite grains coloured by shape factor (tested with MTEX4)
figure
plot(grains('Forsterite'),grains('Forsterite').shapeFactor,'figSize','large')
colorbar
%**************************************************************************
% Orientation, misorientation of grains : meanOrientation,KAM,GOS,Angle,Axis
%**************************************************************************
%% Forsterite grains coloured by mean grain orientation (tested with MTEX4)
% default specimen direction (r = z = 0,0,1) for IPF orientation colormap
color = oM.orientation2color(ebsd('Forsterite').orientations);
plot(grains('Forsterite'),grains('Forsterite').meanOrientation,color,'figSize','large')
colorbar
%% Forsterite grains coloured by mean grain orientation (tested with MTEX4)
% select IPF colorbar for specific mineral (a,b,c,alpha,beta,gamma) and symmetry
oM = ipdfHSVOrientationMapping(ebsd('Forsterite'))
% define the specimen direction (r = x = 1,0,0) for IPF orientation colormap
oM.inversePoleFigureDirection = xvector;
plot(grains('Forsterite'),oM.orientation2color(grains('Forsterite').meanOrientation),'figSize','large')
%% Forsterite grains coloured by Grain Orienation Spread (GOS) (tested with MTEX4)
plot(grains('Forsterite'),grains('Forsterite').GOS,'figSize','large')
colorbar
%% Forsterite grains coloured by Kernel Average Misorientation (KAM)(tested with MTEX4)
% Note KAM is defined using EBSD data, it is the kernel average
% misorientation for each EBSD measurement
% options : 'threshold',10*degree and 'secondOrder'
% Kernels for square EBSD grids
% $ = center point *= points used for Kernel
% 1st order KAM (default)    2nd order KAM (option 'secondOrder')
%                                      *
%           *                         ***
%          *$*                       **$**
%           *                         ***
%                                      *
plot(ebsd('Forsterite'),KAM(ebsd('Forsterite'),'secondOrder','threshold',15*degree)./degree,'figSize','large')
colorbar
%% Rotation ANGLE of mean orientation of each grain from reference orientation (tested with MTEX4)
% Uniform colour for each grain mean orientation
% get all rotations of mean rotation from the reference orientation
% using all ebsd indexed points inside grains
Mean_rotations = grains('Forsterite').meanRotation;
figure
plot(grains('Forsterite'),angle(Mean_rotations)/degree,'figSize','large')
% colorbar
colorbar
%% Misorientation ANGLE from mean within a grain (tested with MTEX4)
% get all misorientations from the mean orientation
% using all ebsd indexed points inside grains
% error message non-existent field 'mis2meanRotation' if you have not used
% new syntax [grains ebsd] = calcGrains(ebsd)
figure
plot(ebsd('Forsterite'),ebsd('Forsterite').mis2mean.angle./degree,'figSize','large')
% caxis - allows you focus the scale of the angle range of interest
% example 0 to 5 degrees
caxis([0 5])
%% Misorientation AXIS from mean within a grain (tested with MTEX4 scale 0-1 is this normal ?)
% get all misorientations from the mean orientation
% using all ebsd indexed points inside grains
% colourmap
oM = ipdfHSVOrientationMapping(ebsd('Forsterite'))
% plot
figure
plot(ebsd('Forsterite'),oM.Miller2color(ebsd('Forsterite').mis2mean.axis),'figSize','large')
colorbar
% caxis - allows you focus the scale of the range of interest
% does not work with this plot, must be normalied colour scale ...
%caxis([0 30])

