% Orientation_Tensor_Example_Plag_plot.m
%
% Test with MTEX 4.0.9
%
% Uses *.ctf data file at pname = '/MatLab_Programs/MTEX_Workshop_Distibution';
%
% An example using the Func_Orientation_Tensor.m
% to calculate an orientation tensor and eigen-analysis
% for pole figure data in the form of scatter or axial data (vectors)
% in specimen co-ordinates.
%
% Orientation Tensor for axial data is calculated using very efficient
% numerical method of Bachmann et al. (2010) using the multiplication
% of the column vector by a row vector of the scatter data (equation 12)
% to form the covariance matrix known as the Orientation Tensor.
%
% Bachmann,F., Hielscher,R., Jupp,P.E., Pantleon,W., Schaeben,H., Wegert,E.
% (2010) Inferential statistics of electron backscatter diffraction data
% from within individual crystalline grains.
% Journal of Applied Crystallography, 43, 1338?1355.
% 
% Application : the eigen-values of the (010) and [001] pole figures
% LS-index is calculated for plagioclase.
% LS_index plagioclase
%
% magmatic type ?
% "apparent" slip direction [100] and slip plane (010) ; range (0-1)
% 0 = S-type [100] girdle ; (010) point maxima
% 1 = L-type [100] point maxima ; (010) girdle 
%
% plastic type ?
% "apparent" slip direction [001] and slip plane (010) ; range (0-1)
% 0 = S-type [001] girdle ; (010) point maxima
% 1 = L-type [001] point maxima ; (010) girdle 
%
% See Ulrich, S. and Mainprice, D., (2005) Does cation ordering in
% omphacites influence the development of lattice-preferred orientation ?
% Journal of Structural Geology 27, 419-431.
%
% and
%
% Vollmer, F.W., (1990) An application of eigenvalue methods to structural
% domain analysis. Geological Society of America Bulletin 102,786-791.
%
%
% By David Mainprice  last revised 14/01/2015
%
%% clear memory and close all plots
clear all
close all
%
% Specify Crystal and Specimen Symmetries
%
% crystal symmetry syntax has changed from symmetry to crystalSymmetry in MTEX 4
%% Specify Crystal and Specimen Symmetries

% crystal symmetry
CS = {... 
  'notIndexed',...
  crystalSymmetry('mmm', [4.756 10.207 5.98], 'mineral', 'Forsterite', 'color', 'light blue'),...
  crystalSymmetry('-1', [8.178 12.87 14.187], [93.5,115.9,90.65]*degree, 'X||a*', 'Z||c', 'mineral', 'BYTOWNITE An', 'color', 'light green'),...
  crystalSymmetry('12/m1', [9.746 8.99 5.251], [90,105.63,90]*degree, 'X||a*', 'Y||b*', 'Z||c', 'mineral', 'Diopside   CaMgSi2O6', 'color', 'light red'),...
  crystalSymmetry('mmm', [18.2406 8.8302 5.1852], 'mineral', 'Enstatite  Opx AV77', 'color', 'cyan'),...
  crystalSymmetry('12/m1', [9.87 18.058 5.307], [90,105.2,90]*degree, 'X||a*', 'Y||b*', 'Z||c', 'mineral', 'Hornblende  C2/m', 'color', 'magenta')};
% extract Bytownite plagioclase CS for later use or use CS{3}
CS_plag = crystalSymmetry('-1', [8.178 12.87 14.187], [93.5,115.9,90.65]*degree, 'X||a*', 'Z||c', 'mineral', 'BYTOWNITE An', 'color', 'light green');
% plotting convention
setMTEXpref('xAxisDirection','east');
setMTEXpref('zAxisDirection','outOfPlane');
% N.B.
% You do not need to specify triclinic ('-1') specimen symmetry in MTEX 4
% as it is the default specimen symmetry
% specimen symmetry , syntax is 
SS = specimenSymmetry('-1');

% N.B. you can confirm or change the plotting convention X-axis
% plotting convention
plotx2east
%
%**************************************************************************
% Specify File path and Name
%**************************************************************************
%
% *** PLEASE NOTE *** : You will need to change the path name to correspond
% to the position of the file on your computer!!!
%
%% Specify File Names

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

% which files to be imported
fname = [pname '/735B-B1-92-2_1ppg.ctf'];

%% Import the Data

% create an EBSD variable containing the data
ebsd = loadEBSD(fname,CS,'interface','ctf',...
  'convertSpatial2EulerReferenceFrame')
%
% Individual Orientation data Pole Figure orientation matrix
%%
%********************************************************
% Extract individual orientations from ebsd object
%********************************************************
o = ebsd('BYTOWNITE').orientations
%********************************************************
% vectors of [100] directions in specimen co-ordinates
%********************************************************
v = o * Miller(1,0,0,CS_plag,'BYTOWNITE','uvw')
%%
%********************************************************
% orientation tensor and eigenvalue analysis
%********************************************************
[~,value,vec1,vec2,vec3] = Func_Orientation_Tensor_MTEX4(v);
% convert to eigen-vector to MTEX vector3d
E1_100 = vector3d(vec1);
E2_100 = vector3d(vec2);
E3_100 = vector3d(vec3);
%********************************************************
% Vollmer, F.W., 1990. An application of eigenvalue methods to structural
% domain analysis. Geological Society of America Bulletin 102,786-791.
% Eigen-Analysis
%********************************************************
NORM=value(1)+value(2)+value(3);
% Point maximum
P100=(value(1)-value(2))/NORM
% Girdle
G100=(2.0*(value(2)-value(3)))/NORM
%%
%********************************************************
% vectors of (010) poles in specimen co-ordinates
%********************************************************
v = o * Miller(0,1,0,CS_plag,'hkl');
%********************************************************
% orientation tensor and eigen-analysis
%********************************************************
[~,value,vec1,vec2,vec3] = Func_Orientation_Tensor_MTEX4(v);
% convert to eigen-vector to MTEX vector3d
E1_010 = vector3d(vec1(1),vec1(2),vec1(3));
E2_010 = vector3d(vec2(1),vec2(2),vec2(3));
E3_010 = vector3d(vec3(1),vec3(2),vec3(3));
%********************************************************
% Vollmer, F.W., 1990. An application of eigenvalue methods to structural
% domain analysis. Geological Society of America Bulletin 102,786-791.
% Eigen-Analysis
%********************************************************
NORM=value(1)+value(2)+value(3);
% Point maximum
P010=(value(1)-value(2))/NORM
% Girdle
G010=(2.0*(value(2)-value(3)))/NORM
%%
%********************************************************
% vectors of [001] directions in specimen co-ordinates
%********************************************************
v = o * Miller(0,0,1,CS_plag,'uvw');
%********************************************************
% orientation tensor and eigenvalue analysis
%********************************************************
[OT,value,vec1,vec2,vec3] = Func_Orientation_Tensor_MTEX4(v);
% convert to eigen-vector to MTEX vector3d
E1_001 = vector3d(vec1(1),vec1(2),vec1(3));
E2_001 = vector3d(vec2(1),vec2(2),vec2(3));
E3_001 = vector3d(vec3(1),vec3(2),vec3(3));
%********************************************************
% Vollmer, F.W., 1990. An application of eigenvalue methods to structural
% domain analysis. Geological Society of America Bulletin 102,786-791.
% Eigen-Analysis
%********************************************************
NORM=value(1)+value(2)+value(3);
% Point maximum
P001=(value(1)-value(2))/NORM
% Girdle
G001=(2.0*(value(2)-value(3)))/NORM

%%
%*********************************************************
% Plot pole figure and Eigen-vectors
%*********************************************************
% reset default fontsize for all plots
%setMTEXpref('FontSize',15)
figure
plotPDF(o,Miller(1,0,0,CS_plag,'uvw'),'antipodal','figSize','large','FontSize',20)
% plot Eigen-vectors
annotate([E1_100,E2_100,E3_100],'label',{'E1','E2','E3'},...
  'BackgroundColor','w','markersize',10,'FontSize',20);
set(gcf,'renderer','painters')
%set(gcf,'renderer','zBuffer')
saveFigure('/MatLab_Programs/Plag_100_eigen_plot.png');
%%
figure
plotPDF(o,Miller(0,1,0,CS_plag,'hkl'),'antipodal','figSize','large','FontSize',20)
% plot Eigen-vectors
annotate([E1_010,E2_010,E3_010],'label',{'E1','E2','E3'},...
  'BackgroundColor','w','markersize',10);
saveFigure('/MatLab_Programs/Plag_010_eigen_plot.png');
%%
figure
plotPDF(o,Miller(0,0,1,CS_plag,'uvw'),'antipodal','figSize','large','FontSize',20)
% plot Eigen-vectors
annotate([E1_001,E2_001,E3_001],'label',{'E1','E2','E3'},...
  'BackgroundColor','w','markersize',10);
saveFigure('/MatLab_Programs/Plag_001_eigen_plot.png');
%%
%*********************************************************
% LS_indices plagioclase
%*********************************************************
% "magmatic" type a-b ?
% "apparent" slip direction [100] and slip plane (010) range (0-1)
% 0 = S-type  [100] girdle       ; (010) point maxima
% 1 = L-type  [100] point maxima ; (010) girdle
LS_Index_a_b = 0.5*(2.0-(P010/(G010+P010))-(G100/(G100+P100)))
% "plastic" type c-b ?
% "apparent" slip direction [001] and slip plane (010) range (0-1)
% 0 = S-type  [001] girdle       ; (010) point maxima
% 1 = L-type  [001] point maxima ; (010) girdle
LS_Index_c_b = 0.5*(2.0-(P010/(G010+P010))-(G001/(G001+P001)))
%