-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcalibrateEn.m
More file actions
70 lines (58 loc) · 2 KB
/
Copy pathcalibrateEn.m
File metadata and controls
70 lines (58 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
function [ en ] = calibrateEn( si, dispersion, en_idx, en_val )
%calibrateEn Return energy vector for EELS spectra
% Calculates the energy vector either from function arguments or from
% user input based on selecting a spectrum feature
% inputs:
% si -- the 3D spectrum image, ordered [x,y,en]
% dispersion -- energy interval per pixel
% en_idx -- (enter if known) vector index in en of known feature
% en_val -- (enter if known) energy value of known feature
% outputs:
% en -- a vector of energy values corresponding to the energy axis.
%
%This function is part of the CSILAB Package written by the Muller Group
%at Cornell University
%Contributors include: Elliot Padgett, Megan Holtz, Paul Cueva, Julia
% Mundy, Huolin Xin, Peter Ercius, David Muller
%assume last non-singleton dimension is energy
NN=size(si); NN=NN(NN~=1); Ne=NN(end);
if nargin<3
%User has not input specific values. Show them the spectrum for them
%to pick a known point
%make a 1D spectrum to plot
if length(size(si)) == 3
meanspec = squeeze(mean(mean(si,1),2));
elseif length(NN) ==1
meanspec = si;
else
meanspec = mean(si,1);
end
%plot spectrum
f = figure;
plot(meanspec)
title('Click on known energy position');
[en_idx,~] = ginput(1);
en_idx = round(en_idx);
close(f)
%ask for known energy value
prompt = {'What is the known energy?'};
name = 'Energy';
numlines = 1;
n = inputdlg(prompt,name,numlines,{''},'on');
en_val = str2num(n{1});
end
if nargin<2
%user did not enter a dispersion
prompt = {'What is the dispersion?'};
name = 'Dispersion';
numlines = 1;
n = inputdlg(prompt,name,numlines,{''},'on');
dispersion = str2num(n{1});
end
%Calculate energy vector
en=calculateEn(dispersion,en_idx,en_val,Ne);
end
function [ en ] = calculateEn( dispersion, en_idx, en_val, N )
en = 1:N;
en = (en-en(en_idx))*dispersion+en_val;
end