Skip to content

Instantly share code, notes, and snippets.

@kilir
kilir / saveFigureMP.m
Last active May 25, 2018 15:46
modfied saveFigure in such a way that ebsd map plots won't be antialiased - no new colors to be created #mtexScript
function saveFigure(fname,varargin)
% save figure as graphics file
%
% Description
% This function is supposed to produce cropped, publication ready image
% files from your plots. The format of the file is determined by the
% extension of the filename.
%
% Syntax
% saveFigure(fname)
@kilir
kilir / broad_profile.m
Last active March 3, 2020 03:45
make a EBSD spatialProfile that averages over n pixels from both sides of the profile #mtexScript #EBSD
%% select profile
lineX = ginput(2) % select a line
[ebsd_lineX, dist ]= spatialProfile(ebsd,lineX); %extract orientations
%% average orientations perpendicular to profile and plot things along line
clear meanO
% average along line (put 0 if you want no averaging)
%//////////////////////////////////////////////////////
av_width = 8 %number of pixels to average perp to line (towards both sides
% use 0 to use only ebsd_lineX
@kilir
kilir / gKAM.m
Last active June 22, 2019 19:09
calculate the grain averaged KAM (gKAM) for each grain #mtexScript
function [gkam, gid, kam] = gKAM(ebsd,varargin)
% calculate grain average misorientation angle from KAM
% input:
% ebsd (with grainID)
%
% options:
% threshold: angles to ignore (upper limit) in radian
% lowlim: angles to ignore: (lower limit) in radian
% order: 1st,2nd etc. neighbourhood around each point
%
@kilir
kilir / crystal_shape_demo.m
Last active May 25, 2018 15:49
demo to plot crystal shapes at user defined positions in a map #mtexScript
% crystal shape demo
% needs @crystalShape avaiable in mtex 4.5.3
% script plots a map and the user can select points where a little crystal shape
% will be dispalyed -crystal will be cc according to the map
mtexdata titanium
[grains,ebsd.grainId]=calcGrains(ebsd,'angle',5*degree);
% plot something
cs=ebsd('t').CS;
f=newMtexFigure;
@kilir
kilir / BinghamSphericalFunction.m
Created February 10, 2018 12:43
Some experiment with S2FunctionHarminc to create a Bingham distribution #mtexScript
function SF = BinghamSphericalFunction(r,Z,varargin)
% define a Bingham Distribution on a sphere
%
% Input
% r - @ rotation
% Z - 3-by-1 smoothing parameter with Z(1)>=Z(2)>=Z(3), Z3<0
% or diagonal matrix with Z1, Z2 ,Z3
% Z1=Z2 rotationally symmetric unimodal distribution
% Z1<<Z2 (partial girdle distribution
%
@kilir
kilir / loadPhaseMap.m
Last active March 27, 2024 10:19
Create fake ebsd from a grain boundary, particle and/or phase map to use @grain2d functionalities from mtex on those #mtexScript
function [ebsd, grains]=loadPhaseMap(varargin)
% Load a phase map and create "ebsd" which can be used with some
% of the avaiable tools for grain/grainboundary analysis
%
% Three cases are be distinguished.
%
% 1) Single phase,tightly packed no matrix ('single')
% input: boundary map - binary image ("white" boundaries, value should be 255)!
% output: ebsd with grains of distinct, nonsense orientation and notIndexed
% at the boundaries
@kilir
kilir / misor_boundary_colorcoding_demo.m
Last active June 22, 2019 18:56
demo on a single olivine grain to show a possible option to color misorientation axes #mtexScript
% import demo data
mtexdata forsterite
% prepare some data that might look interesting
[grains, ebsd.grainId, ebsd.mis2mean]=calcGrains(ebsd);
ebsd=ebsd(grains(grains.grainSize>100 & grains.phase==1)); %discard all small grains and non-forsterite grains before labeling
[grains, ebsd.grainId, ebsd.mis2mean]=calcGrains(ebsd,'unitcell');
% plot grains and find an interesting one
om=ipfHSVKey(ebsd('f').CS,ebsd('f').CS);
om.maxAngle=10*degree;
@kilir
kilir / pfIntensity.m
Last active August 9, 2023 07:50
calculate pfJ using S2Fun or manual calulation #mtexScript
function [pfTindex, m, pfg_max] = pfIntensity(odf,h)
% calculate pfJ using S2Fun
% input:
% odf - odf
% h - Miller
% output:
% pfTindex - pole figure J index
% m - multiplicity (needs to be considered when comparing pfJ of different h)
% pfmax - max of pf
@kilir
kilir / calcTDF.m
Last active June 22, 2019 19:01
working with boundary trend (= direction in a plane) distributions #mtexScript
function [totfreq, bc, azi]=calcTDF(g,varargin)
% calc circular axis/ trend distribution function of grain long axes
% OR grain boundary segments or from a list of angles for axial data (0:pi)
%
% Syntax:
% [freq,bc] = calcTDF(smoothgrains.boundary('indexed'))
% or
% [freq,bc] = calcTDF(smoothgrains('indexed'))
%
@kilir
kilir / ellipse.m
Created October 2, 2018 17:54
Annotate an ellipse #mtexScript
function h = ellipse(r,a,b,varargin)
% annotate an ellipse
%
% Input
% r - @rotation specifying the ellipse position
% a,b - long/short half axes of ellipse in radian
%
h = [];
rho=(0:1:360)*degree;