Deleted nappIce. Required functions now in beamtime.
No files matched your search
|
Before Width: | Height: | Size: 333 KiB |
|
Before Width: | Height: | Size: 241 KiB |
|
Before Width: | Height: | Size: 558 KiB |
|
Before Width: | Height: | Size: 1.8 MiB |
|
Before Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 162 KiB |
|
Before Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 8.4 KiB |
|
Before Width: | Height: | Size: 49 KiB |
|
Before Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 16 KiB |
@@ -1,157 +0,0 @@
|
||||
function LabView = LabView_importData(fullFileName,varargin)
|
||||
%
|
||||
% LabView_importData reads data log ASCII files stored by LabView into
|
||||
% a Matlab time series.
|
||||
%
|
||||
% LabView = LabView_importData(A) imports file A
|
||||
% and stores its content as time series in a structure called "LabView".
|
||||
%
|
||||
% LabView = LabView_importData(A,LabView) imports file A
|
||||
% and appends its content as time series to the LabView structure.
|
||||
%
|
||||
%
|
||||
% Example
|
||||
% LabView = LabView_importData('exmpl.dat',LabView)
|
||||
%
|
||||
% Input
|
||||
% * Napp_chamber_file: Complete and absolute path to the Napp chamber log file.
|
||||
% * LabView: name of output structure. Always call this'LabView'
|
||||
%
|
||||
% Output
|
||||
% * LabView: time series, the name starting with "ts"
|
||||
% followed by date and time the recording started.
|
||||
%
|
||||
% See also LABVIEW_COMBINE, LABVIEW_PLOT, LABVIEW_CUTDATA
|
||||
%
|
||||
%% Data Structure
|
||||
%
|
||||
% Data structure before 4.3.2019
|
||||
% col 1: Date
|
||||
% col 2: Time
|
||||
% col 3: Reservoir "Pressure 1" - Unit "1 water" - mbar -> ts.Data:2
|
||||
% col 4: Reservoir "Pressure 2" - Unit "2 other" - mbar -> ts.Data:3
|
||||
% col 5: Baratron 1 - cell - 1mbar max - mbar -> ts.Data:4
|
||||
% col 6: Baratron 2 - cell - 10mbar max - mbar -> ts.Data:8
|
||||
% col 7: Baratron 3 - cell - 0.05mbar max - mbar -> ts.Data:9
|
||||
% col 8: Baratron 4 - - mbar
|
||||
% col 9: Temp.Ice Sample - °C -> ts.Data:1
|
||||
% col 10: Temp.Heated Sample
|
||||
% col 11: none
|
||||
% col 12: Temp. Reservoir "Cooler 1" - °C -> ts.Data:5
|
||||
% col 13: Temp. Reservoir "Cooler 2" - °C -> ts.Data:6
|
||||
% col 14: Flow He(cryoholder) - l/min -> ts.Data:7
|
||||
% col 15: none
|
||||
% col 16: none
|
||||
%
|
||||
% Data structure after 4.3.2019
|
||||
% col 1: Date
|
||||
% col 2: Time
|
||||
% col 3: Reservoir "Pressure 1" - Unit "1 water" - mbar -> ts.Data:2
|
||||
% col 4: Reservoir "Pressure 2" - Unit "2 other" - mbar -> ts.Data:3
|
||||
% col 5: Baratron 1 - cell - 1mbar max - mbar -> ts.Data:4
|
||||
% col 6: Baratron 2 - cell - 10mbar max - mbar -> ts.Data:8
|
||||
% col 7: Baratron 3 - cell - 0.05mbar max - mbar -> ts.Data:9
|
||||
% col 8: Baratron 4 - - mbar
|
||||
% col 9: Temp.Ice Sample - °C -> ts.Data:1
|
||||
% col 10: Temp.Heated Sample
|
||||
% col 11: Temp. Reservoir "Cooler 1" - °C -> ts.Data:5
|
||||
% col 12: Temp. Reservoir "Cooler 2" - °C -> ts.Data:6
|
||||
% col 13: Flow He(cryoholder) - l/min -> ts.Data:7
|
||||
% col 14: Flow gas 1
|
||||
% col 15: Pressure chamber - mbar
|
||||
% col 16: x-position of cryoholder - mm -> ts.Data:10
|
||||
% col 17: y-position of cryoholder - mm -> ts.Data:11
|
||||
% col 18: z-position of cryoholder - mm -> ts.Data:12
|
||||
% col 19: nothing
|
||||
% col 20: Temp.Sealing - °C -> ts.Data:13
|
||||
|
||||
|
||||
%%
|
||||
|
||||
% Create an InputParser object
|
||||
p = inputParser;
|
||||
% Add inputs to the scheme.
|
||||
defaultAppendToStructure = 0;
|
||||
addRequired(p,'fullFileName',@isfile);
|
||||
addOptional(p,'appendToStructure',defaultAppendToStructure,@isstruct);
|
||||
% Parse the inputs.
|
||||
parse(p,fullFileName,varargin{:})
|
||||
|
||||
%%
|
||||
% get filedate
|
||||
[~,name,~] = fileparts(p.Results.fullFileName);
|
||||
tmp = strsplit(name,'_PC');
|
||||
filedate = datenum(tmp{1},'yyyy-mm-dd_HH.MM.SS');
|
||||
|
||||
clearvars name tmp
|
||||
|
||||
%%
|
||||
% parse structure to append to
|
||||
|
||||
if isstruct(p.Results.appendToStructure)
|
||||
LabView = p.Results.appendToStructure;
|
||||
end
|
||||
%%
|
||||
if datenum(filedate) <= datenum('04-Mar-2019 13:30:00')
|
||||
|
||||
fid = fopen(p.Results.fullFileName);
|
||||
data = textscan(fid, ...
|
||||
'%s %s %f %f %f %f %f %f %f %f %f %f %f %f %f %f',...
|
||||
'HeaderLines',1); % data file has 2 text columns, followed by 14 numeric columns
|
||||
fclose(fid);
|
||||
% define time series
|
||||
LabView.(['ts_' datestr(datenum([char(data{1}{1}), char(data{2}{1})],'dd.mm.yyyyHH:MM:SS'),'YYYYmmdd_HHMM')]) ...
|
||||
= timeseries([data{9} data{3} data{4} data{5} data{12} ...
|
||||
data{13} data{14} data{6} data{7}] , ...
|
||||
datestr(datenum([char(data{1}), char(data{2})],...
|
||||
'dd.mm.yyyyHH:MM:SS'),0));
|
||||
LabView.(['ts_' datestr(datenum([char(data{1}{1}), char(data{2}{1})],'dd.mm.yyyyHH:MM:SS'),'YYYYmmdd_HHMM')]).Name ...
|
||||
= 'Readout Napp Chamber raw signal';
|
||||
clear fid ans formatOut nans t x
|
||||
|
||||
elseif datenum(filedate) >= datenum('15-Sep-2021 01:00:00')
|
||||
|
||||
fid = fopen(p.Results.fullFileName);
|
||||
data = textscan(fid, ...
|
||||
'%s %s %s %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f',...
|
||||
'HeaderLines',1); %
|
||||
|
||||
fclose(fid);
|
||||
% the date formating in the dat file is really messed up. Try to make
|
||||
% it consitent with MATLAB. The problem is that MATLAB does not
|
||||
% understand 1 digit month and hours.
|
||||
%
|
||||
%
|
||||
% Split the date in column 1 into year,month,day
|
||||
newDateSplit = cellfun(@(x) split(char(x),'/'),data{1},'UniformOutput', false);
|
||||
% Split the time in column 2 into hours, minutes, seconds
|
||||
newTimeSplit = cellfun(@(x) split(char(x),':'),data{2},'UniformOutput', false);
|
||||
% combine both with the am/pm string in column 3 to a new datestring
|
||||
customDateStr = cellfun(@(x,y,z) [datestr(datenum([str2double(x{3}),str2double(x{1}),str2double(x{2}),str2double(y{1}),str2double(y{2}),str2double(y{3})])), ' ', char(z)], newDateSplit,newTimeSplit,data{3}, 'uniformOutput',false) ;
|
||||
% define time series
|
||||
LabView.(['ts_' datestr(customDateStr{1},'YYYYmmdd_HHMM')]) ...
|
||||
= timeseries([data{10} data{4} data{5} data{6} data{12} ...
|
||||
data{13} data{14} data{7} data{8} data{17} data{18} data{19} data{21}], ...
|
||||
customDateStr);
|
||||
LabView.(['ts_' datestr(customDateStr{1},'YYYYmmdd_HHMM')]).Name ...
|
||||
= 'Readout Napp Chamber raw signal';
|
||||
clearvars fid ans formatOut nans t x new* custom*
|
||||
else
|
||||
fid = fopen(p.Results.fullFileName);
|
||||
data = textscan(fid, ...
|
||||
'%s %s %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f',...
|
||||
'HeaderLines',1); % data file has 2 text columns, followed by 16 numeric columns
|
||||
fclose(fid);
|
||||
% define time series
|
||||
|
||||
LabView.(['ts_' datestr(datenum([char(data{1}{1}), char(data{2}{1})],'dd.mm.yyyyHH:MM:SS'),'YYYYmmdd_HHMM')]) ...
|
||||
= timeseries([data{9} data{3} data{4} data{5} data{11} ...
|
||||
data{12} data{13} data{6} data{7} data{16} data{17} data{18} data{20}] , ...
|
||||
datestr(datenum([char(data{1}), char(data{2})],...
|
||||
'dd.mm.yyyyHH:MM:SS'),0));
|
||||
|
||||
LabView.(['ts_' datestr(datenum([char(data{1}{1}), char(data{2}{1})],'dd.mm.yyyyHH:MM:SS'),'YYYYmmdd_HHMM')]).Name ...
|
||||
= 'Readout Napp Chamber raw signal';
|
||||
clear fid ans formatOut nans t x
|
||||
end
|
||||
end
|
||||
@@ -1,38 +0,0 @@
|
||||
function relHum = Napp_RH_p(T_current,partial_pressure_water)
|
||||
%Napp_RH_p calculates the relative humidity for a given
|
||||
% temperature and water pressure.
|
||||
%
|
||||
% With the relative humidity referenced
|
||||
% to liquid water (RH_w) as opposed to ice (RH_i), the activity of water
|
||||
% is: activity_w = RH_{water}/100
|
||||
%
|
||||
%
|
||||
% * Napp_p_RH(T_current,RH)
|
||||
% * Napp_p_RH([253.15, 263.15, 273.15],[60, 80, 90])
|
||||
% * Napp_p_RH(273.15-20,80)
|
||||
%
|
||||
%
|
||||
% *input*
|
||||
% T_current in K: temperature
|
||||
% RH in %: relative humidity (RH_{water})
|
||||
%
|
||||
% *output*
|
||||
% partial pressure of water in mbar
|
||||
|
||||
%%
|
||||
%
|
||||
% *water*:
|
||||
% NIST webbook: Bridgeman and Aldrich, 1964 give parametrisation from 273
|
||||
% to 303 K in bar. log10(p) = A - B/ (T+C).
|
||||
A = 5.40221;
|
||||
B = 1838.675;
|
||||
C = -31.737;
|
||||
|
||||
p_w = 10.^(A - B./(T_current+C)) .* 1E3; % mbar
|
||||
RH = (partial_pressure_water*100)/p_w;
|
||||
relHum = RH;
|
||||
|
||||
for i = 1:length(T_current)
|
||||
fprintf('RH of %.0f percent at %.1f K (%.1f dC) and %.2f mbar .\n',RH,T_current,T_current-273.15,partial_pressure_water)
|
||||
end
|
||||
end
|
||||
@@ -1,34 +0,0 @@
|
||||
function Napp_p_RH(T_current,RH)
|
||||
%Napp_p_RH calculates the partial pressure of water for a given
|
||||
% temperature and relative humidity. With the relative humidity referenced
|
||||
% to liquid water (RH_w) as opposed to ice (RH_i), the activity of water
|
||||
% is: activity_w = RH_{water}/100
|
||||
%
|
||||
% * Napp_p_RH(T_current,RH)
|
||||
% * Napp_p_RH([253.15, 263.15, 273.15],[60, 80, 90])
|
||||
% * Napp_p_RH(273.15-20,80)
|
||||
%
|
||||
%
|
||||
% *input*
|
||||
% T_current in K: temperature
|
||||
% RH in %: relative humidity (RH_{water})
|
||||
%
|
||||
% *output*
|
||||
% partial pressure of water in mbar
|
||||
|
||||
%%
|
||||
%
|
||||
% *water*:
|
||||
% NIST webbook: Bridgeman and Aldrich, 1964 give parametrisation from 273
|
||||
% to 303 K in bar. log10(p) = A - B/ (T+C).
|
||||
A = 5.40221;
|
||||
B = 1838.675;
|
||||
C = -31.737;
|
||||
|
||||
p_w = 10.^(A - B./(T_current+C)) .* 1E3; % mbar
|
||||
|
||||
|
||||
for i = 1:length(T_current)
|
||||
fprintf('The partial pressure of water with a RH of %.0f percent at %.1f K (%.1f dC) is %.2f mbar .\n',RH(i),T_current(i),T_current(i)-273.15,p_w(i).*RH(i)./100)
|
||||
end
|
||||
end
|
||||
@@ -1,49 +0,0 @@
|
||||
function p = Napp_p_ice(T_current)
|
||||
%Napp_p_ice(T_current) plots the vapour pressure of ice between 200-270 K
|
||||
% and marks the vapour pressure of ice at a given temperature. It also
|
||||
% displays the vapour pressure at a temperature of choice in the command
|
||||
% window.
|
||||
%
|
||||
% * Napp_p_ice(T_current)
|
||||
% * p = Napp_p_ice([253.15, 263.15, 273.15])
|
||||
%
|
||||
% *input*
|
||||
% T_current in K: temperature of ice; (format: either single numbers or array)
|
||||
%
|
||||
% *output*
|
||||
% vapour pressure of ice in mbar
|
||||
|
||||
%% Water vapour pressure above the ice and in pure liquid water.
|
||||
|
||||
T = 200:0.2:273; % K, temperature range
|
||||
% Marti, J., and K. Mauersberger, Geophys. Res.Lett., 20, 363?366, 1993.
|
||||
% gives parameterization from 169 - 273K in Pa. (log10(p)= A1/T+B)
|
||||
A_1 = -2663.5;
|
||||
B_1 = 12.537;
|
||||
p_i = 10.^(A_1./T + B_1).*1E-5.*1E3; % mbar
|
||||
p = 10.^(A_1./T_current + B_1).*1E-5.*1E3; % mbar
|
||||
|
||||
% plot
|
||||
figure( 'Name', 'vapour pressure over ice')
|
||||
axes1 = axes('Parent',gcf,'XDir','reverse','FontSize',16);
|
||||
box on
|
||||
hold on
|
||||
% relative humidity above ice
|
||||
plot(p_i,T,'LineWidth',2)
|
||||
xlim([0 6.5]);
|
||||
ylim([220 275]);
|
||||
xticks(0:0.5:6.5)
|
||||
grid on
|
||||
grid minor
|
||||
title('vapour pressure over ice');
|
||||
|
||||
xlabel('p [mbar]');
|
||||
ylabel('temperature [K]');
|
||||
|
||||
%% write to command line
|
||||
for i = 1:length(T_current)
|
||||
plot(10.^(A_1./T_current(i) + B_1).*1E-5.*1E3,T_current(i),'x','MarkerSize',25,'LineWidth',3);
|
||||
text(10.^(A_1./T_current(i) + B_1).*1E-5.*1E3, T_current(i),[' <- ' num2str(T_current(i))],'FontSize',12);
|
||||
fprintf('The vapour pressure of ice at %.1f K (%.1f dC) is %.2f mbar \n',T_current(i),T_current(i)-273.15,10.^(A_1./T_current(i) + B_1).*1E-5.*1E3)
|
||||
end
|
||||
end
|
||||
@@ -1,43 +0,0 @@
|
||||
[x1, y1] = prepareCurveData(data1(:,1),data1(:,2));
|
||||
[x2, y2] = prepareCurveData(data2(:,1),data2(:,2));
|
||||
[x3, y3] = prepareCurveData(data3(:,1),data3(:,2));
|
||||
|
||||
|
||||
% Define equation to fit data
|
||||
% I use the area Gauss equations here, which I took from the OriginPro
|
||||
% documentation. https://www.originlab.com/doc/Origin-Help/Gauss-FitFunc
|
||||
%
|
||||
% Gauss = area/(width*sqrt(pi/2)) * exp(-2*(x-position)^2/width^2)
|
||||
%
|
||||
% where FWHM = width * sqrt(ln(4))
|
||||
|
||||
% Next, the data will be arranged in a matrix - where all elements need
|
||||
% to have the same length. Workaround: give both data sets same length.
|
||||
xLow = [min(x1) min(x2) min(x3)];
|
||||
xHigh = [max(x1) max(x2) max(x3)];
|
||||
x1start = find(x1 <= min(xHigh),1);
|
||||
x2start = find(x2 <= min(xHigh),1);
|
||||
x3start = find(x3 <= min(xHigh),1);
|
||||
x1end = find(x1 <= max(xLow),1);
|
||||
x2end = find(x2 <= max(xLow),1);
|
||||
x3end = find(x3 <= max(xLow),1);
|
||||
x1 = x1(x1start:x1end);
|
||||
x2 = x2(x2start:x2end);
|
||||
x3 = x3(x3start:x3end);
|
||||
y1 = y1(x1start:x1end);
|
||||
y2 = y2(x2start:x2end);
|
||||
y3 = y3(x3start:x3end);
|
||||
|
||||
% if - for any reason - the 3 vectors have different scaling, they might
|
||||
% end up with different sizes. Here is a workaround
|
||||
sizeOfX = [size(x1,1) size(x2,1) size(x3,1)]; % find size of each X
|
||||
if range(sizeOfX) ~= 0 % cut all to shortest range
|
||||
x1 = x1(1:min(sizeOfX));
|
||||
x2 = x2(1:min(sizeOfX));
|
||||
x3 = x3(1:min(sizeOfX));
|
||||
y1 = y1(1:min(sizeOfX));
|
||||
y2 = y2(1:min(sizeOfX));
|
||||
y3 = y3(1:min(sizeOfX));
|
||||
end
|
||||
clearvars sizeOfX
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
function datafile = XPS_MeanSeqIterations(selection_spectra,selection_region, datafile, numberToAverage)
|
||||
%
|
||||
% XPS_MeanSeqIterations generates a new data structure by combining and
|
||||
% averaging a fixed number or sequence interations. This is usefull if for
|
||||
% example the dwell time was too short to get spectra with a good S/N.
|
||||
%
|
||||
% THIS MODIFIES THE RAW DATA in Matlab.
|
||||
%
|
||||
%
|
||||
% XPS = XPS_MeanSeqIterations([346 347],'', XPS); processes
|
||||
% the first region of spectra 346 and 347. The number of sequence
|
||||
% iterations to average is determined automatically.
|
||||
%
|
||||
% XPS = XPS_MeanSeqIterations([346 347],'', XPS,5); processes
|
||||
% the first region of spectra 346 and 347. It averages 5 sequence
|
||||
% iterations.
|
||||
%
|
||||
%
|
||||
% Input
|
||||
% XPS_background(selection_spectra,selection_region, datafile, hPeaks,excludeBackgroundFit, findPeak,plotFigures)
|
||||
% * selection_spectra: List of PE spectra to be imported. Numeric list of
|
||||
% Spectra Number: [25 26]
|
||||
% * datafile: XPS data structure in workspace. Output from XPS_importData
|
||||
% function.
|
||||
% * numberToAverage (optional): Choose how many sequence iterations you
|
||||
% would like to average.
|
||||
%
|
||||
% Output:
|
||||
% * modified data structure y
|
||||
% * modified dwellTime meta-data
|
||||
% * modified sequenceIterations meta-data
|
||||
|
||||
if ~exist('numberToAverage','var')
|
||||
numberToAverage = 0;
|
||||
end
|
||||
|
||||
|
||||
|
||||
for s = 1:length(selection_spectra)
|
||||
%% Select spectra in data structure
|
||||
%
|
||||
|
||||
% get list of spectra in data structure
|
||||
spectraNames = fieldnames(datafile);
|
||||
% find those that match the spectrum number to be plotted
|
||||
% (contains gives a list of 0 or 1 for no match and match, resp. and
|
||||
% find list the rows of matches.)
|
||||
|
||||
|
||||
for r = 1:length(selection_region)
|
||||
|
||||
tmp = find(endsWith(spectraNames,[num2str(selection_spectra(s)) char(selection_region(r))]));
|
||||
if numberToAverage == 0
|
||||
% Get the prime factors of the data structure size in the 2nd dimension
|
||||
% (i.e. number of sequence iterations)
|
||||
tmp_avnumb = factor(size(datafile.(spectraNames{tmp}).y,2));
|
||||
% Use the first prime factor to select number of iterations to
|
||||
% be averaged.
|
||||
numberToAverage = tmp_avnumb(1);
|
||||
end
|
||||
|
||||
% Calculate mean, reshape, and re-size data structure
|
||||
RM = reshape(datafile.(spectraNames{tmp}).y,...
|
||||
size(datafile.(spectraNames{tmp}).y,1), numberToAverage, []) ; % Reshape
|
||||
datafile.(spectraNames{tmp}).y = squeeze(mean(RM,2)) ;
|
||||
datafile.(spectraNames{tmp}).y_processed = squeeze(mean(RM,2));
|
||||
|
||||
% update the meta-data
|
||||
datafile.(spectraNames{tmp}).dwellTime = datafile.(spectraNames{tmp}).dwellTime * numberToAverage;
|
||||
datafile.(spectraNames{tmp}).sequenceIterations = datafile.(spectraNames{tmp}).sequenceIterations / numberToAverage;
|
||||
end
|
||||
|
||||
end
|
||||
disp('*************************************************')
|
||||
disp('* Voila: XPS_MeanSeqIterations done ! *')
|
||||
disp('*************************************************')
|
||||
@@ -1,22 +0,0 @@
|
||||
function FileList = addPhotonEnergy(FileList,fileNumber,notesToAdd,dataMonth,dataYear)
|
||||
%addPhotonEnergy adds the beam lines photon energy to the data table
|
||||
%
|
||||
% FileList = addPhotonEnergy(FileList,[1,8:12,26],1000,2,2022);
|
||||
%
|
||||
% Input to this function are
|
||||
%
|
||||
% * the name of the data table,
|
||||
% * the file numbers of the SES scans to which the data should be added
|
||||
% * the photon energy in eV,
|
||||
% * the month and the year that the data was acquired
|
||||
|
||||
for ii = 1:length(fileNumber)
|
||||
tmpMatch = (startsWith(FileList.name, sprintf('%04.0f',fileNumber(ii)))) & ...
|
||||
(month(FileList.lastModifiedDatenum) == dataMonth) &...
|
||||
(year(FileList.lastModifiedDatenum) == dataYear) &...
|
||||
(endsWith(FileList.name, '.ibw'));
|
||||
|
||||
FileList(tmpMatch,:).xRayEkin_eV = num2cell(repmat(notesToAdd,size(FileList.xRayEkin_eV(tmpMatch),1),1));
|
||||
FileList(tmpMatch,:).xRayEkinRange_eV = repmat([min(notesToAdd) max(notesToAdd)],size(FileList.xRayEkin_eV(tmpMatch),1),1);
|
||||
end
|
||||
end
|
||||
@@ -1,52 +0,0 @@
|
||||
function DataTable = addSampleNotes(DataTable,fileNumber,notesToAdd,dataMonth,dataYear,tableSelection)
|
||||
%addSampleNotes adds a sample description to the data
|
||||
%
|
||||
% FileList = addSampleNotes(FileList,44,'Ice with N2 and phenol in Ar (bad data)',2,2022);
|
||||
%
|
||||
% Input to this function are
|
||||
%
|
||||
% * the name of the data table,
|
||||
% * the file numbers of the SES scans to which the info should be added
|
||||
% * a text string describing the sample,
|
||||
% * the month and the year that the data was aquired
|
||||
% * optional: 'XPS' or 'NEXAFS' as last input argument to limit to either XPS data or NEXAFS
|
||||
% data
|
||||
|
||||
% check if "sample" table variable (column) exist, if not add it
|
||||
existColumn = strcmp('sample',DataTable.Properties.VariableNames);
|
||||
if ~any(existColumn)
|
||||
DataTable.sample = cellstr(repmat(' ',size(DataTable,1),1));
|
||||
end
|
||||
|
||||
for ii = 1:length(fileNumber)
|
||||
if ~exist('tableSelection','var')
|
||||
% select the data
|
||||
tmpMatch = (startsWith(DataTable.name, sprintf('%04.0f',fileNumber(ii)))) & ...
|
||||
(month(DataTable.lastModifiedDatenum) == dataMonth) &...
|
||||
(year(DataTable.lastModifiedDatenum) == dataYear);
|
||||
else
|
||||
if matches(tableSelection,'XPS')
|
||||
% select the data
|
||||
tmpMatch = (startsWith(DataTable.name, sprintf('%04.0f',fileNumber(ii)))) & ...
|
||||
(month(DataTable.lastModifiedDatenum) == dataMonth) &...
|
||||
(year(DataTable.lastModifiedDatenum) == dataYear) &...
|
||||
(endsWith(DataTable.name, '.ibw'));
|
||||
elseif matches(tableSelection,'NEXAFS')
|
||||
% select the data
|
||||
tmpMatch = (startsWith(DataTable.name, sprintf('%04.0f',fileNumber(ii)))) & ...
|
||||
(month(DataTable.lastModifiedDatenum) == dataMonth) &...
|
||||
(year(DataTable.lastModifiedDatenum) == dataYear)&...
|
||||
(endsWith(DataTable.name, '.h5'));
|
||||
end
|
||||
end
|
||||
% clear existing data (to prevent 2 entries per field)
|
||||
existColumn = strcmp('sample',DataTable.Properties.VariableNames);
|
||||
if any(existColumn)
|
||||
if ~isempty(DataTable(tmpMatch,:).sample)
|
||||
DataTable(tmpMatch,:).sample = cellstr(repmat(' ',size(DataTable(tmpMatch,:),1),1));
|
||||
end
|
||||
end
|
||||
DataTable(tmpMatch,:).sample = cellstr(repmat(notesToAdd,size(DataTable(tmpMatch,:),1),1));
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
function DataTable = nappAlignImages(DataTable,varargin)
|
||||
%nappAlignImages shifts each sequence iteration to align images with a
|
||||
%drifting kinetic energy of the PE features.
|
||||
%
|
||||
% FileList = nappAlignImages(FileList,'tableSelection',tmpDataSelection,...
|
||||
% 'tableVariable','image');
|
||||
%
|
||||
%
|
||||
% *input*
|
||||
% FileList: data table
|
||||
% tableSelection (optional): logical array to filter data table
|
||||
% tableVariable: choose to process either imageRoh (default) or image data.
|
||||
%
|
||||
% *requirements*
|
||||
% nappAlignImages shifts each sequence iteration using the data given in
|
||||
% the table variable kineticEnergyShift. These shifts for each sequence
|
||||
% iteration need to be determined before running this function. Run
|
||||
% nappDetermineShiftXps first.
|
||||
%
|
||||
% *output*
|
||||
% The table variable image will be overwritten with the shifted
|
||||
% image.
|
||||
%
|
||||
% See also nappDetermineShiftXps.m
|
||||
|
||||
defaultTableVariable = 'imageRoh';
|
||||
expectedTableVariable = {'imageRoh','image'};
|
||||
defaultTableSelection = true(size(DataTable,1));
|
||||
|
||||
% Parse input
|
||||
p = inputParser;
|
||||
addRequired(p,'DataTable',@istable);
|
||||
addParameter(p,'tableSelection',defaultTableSelection,@islogical);
|
||||
addParameter(p,'tableVariable',defaultTableVariable,...
|
||||
@(x) any(validatestring(x,expectedTableVariable)));
|
||||
parse(p,DataTable,varargin{:});
|
||||
|
||||
|
||||
% check input (all elements of input variable need to have non-zero size)
|
||||
if ~all(cell2mat(cellfun(@size,p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable),'UniformOutput',false)),'all')
|
||||
disp('The table variable appears to be empty. I quit now')
|
||||
error('The table variable appears to be empty.')
|
||||
end
|
||||
|
||||
if matches(p.Results.tableVariable,'imageRoh')
|
||||
% interpolate image data
|
||||
for ii = 1:size(p.Results.DataTable(p.Results.tableSelection,:),1)
|
||||
for ij = 1:size(DataTable(p.Results.tableSelection,:).imageRoh{ii},2)
|
||||
tmp_1(:,ij)= ...
|
||||
interp1(DataTable(p.Results.tableSelection,:).scientaEkinRoh_eV{ii}(:)+...
|
||||
p.Results.DataTable(p.Results.tableSelection,:).kineticEnergyShift{ii}(ij),...
|
||||
DataTable(p.Results.tableSelection,:).imageRoh{ii}(:,ij),...
|
||||
DataTable(p.Results.tableSelection,:).scientaEkinRoh_eV{ii}(:));
|
||||
|
||||
end
|
||||
DataTable(p.Results.tableSelection,:).image{ii}=tmp_1;
|
||||
clearvars tmp_1
|
||||
|
||||
end
|
||||
else
|
||||
% interpolate image data
|
||||
for ii = 1:size(p.Results.DataTable(p.Results.tableSelection,:),1)
|
||||
for ij = 1:size(p.Results.DataTable(p.Results.tableSelection,:).image{ii},2)
|
||||
|
||||
tmp_1(:,ij)= ...
|
||||
interp1(p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii}(:)+...
|
||||
p.Results.DataTable(p.Results.tableSelection,:).kineticEnergyShift{ii}(ij),...
|
||||
p.Results.DataTable(p.Results.tableSelection,:).image{ii}(:,ij),...
|
||||
p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii}(:));
|
||||
|
||||
end
|
||||
DataTable(p.Results.tableSelection,:).image{ii}=tmp_1;
|
||||
clearvars tmp_1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
function nappAnnotateSurvey(X,Y,dataObjs,labeltext)
|
||||
% nappAnnotateSurvey adds region labels to a survey in the topmost figure.
|
||||
ha = annotation('arrow'); % store the arrow information in ha
|
||||
ha.Parent = gca; % associate the arrow the the current axes
|
||||
ha.X = [X X]; % the location in data units
|
||||
tmp.X=find(dataObjs.XData >= X,1);
|
||||
tmp.Y=dataObjs.YData(tmp.X);
|
||||
ha.Y = [tmp.Y+Y tmp.Y+(Y/10)];
|
||||
text(X,tmp.Y+Y,labeltext,'HorizontalAlignment','center')
|
||||
end
|
||||
@@ -1,187 +0,0 @@
|
||||
function DataTable = nappBackground(DataTable,varargin)
|
||||
%nappBackground determines and subtracts the background from PE or XAS spectra
|
||||
%
|
||||
% FileList = nappBackground(FileList,energyStart,energyEnd);
|
||||
%
|
||||
% FileList = nappBackground(FileList,368,370,'tableSelection',tmpDataSelection,'energyScale','kinetic',...
|
||||
% 'mode','mean','showFigures','off');
|
||||
%
|
||||
%
|
||||
% *input*
|
||||
% FileList: data table
|
||||
% energyStart: smallest value of energy range to use for background calculation
|
||||
% (can also be binding energy)
|
||||
% energyEnd: largest value of energy energy range to use for background calculation
|
||||
% (can also be binding energy)
|
||||
% tableSelection (optional): logical array to filter data table
|
||||
% tableVariable: choose to process either
|
||||
% 'spectrum_counts','spectrum_countsPerSecond' (default), or
|
||||
% 'spectrum_countsNorm'.
|
||||
% mode: mean(default) subtract the mean of the energy range from
|
||||
% spectrum; linfit subtract a linear regression through the energy range
|
||||
% from spectrum
|
||||
% showFigures, on(default): show fit in figure, off do not show fit in
|
||||
% figure
|
||||
% energyScale: kinetic(default): work with kinetic energy scale; binding
|
||||
% works with binding energy scale.
|
||||
%
|
||||
%
|
||||
% *output*
|
||||
% The table variable passed to the function as tableVariable
|
||||
% parameter will be overwritten with the background subtracted spectrum.
|
||||
%
|
||||
% The function parameters (mode, energyStart, energyEnd) are written
|
||||
% to the table as log.
|
||||
|
||||
|
||||
|
||||
% Define conditions and defaults of input
|
||||
defaultTableVariable = 'spectrum_countsPerSecond';
|
||||
expectedTableVariable = {'spectrum_counts','spectrum_countsPerSecond','spectrum_countsNorm'};
|
||||
defaultMode = 'mean';
|
||||
expectedMode = {'mean','linfit'};
|
||||
defaultTableSelection = true(size(DataTable,1),1);
|
||||
defaultShowFigures = 'on';
|
||||
expectedShowFigures = {'on','off'};
|
||||
defaultEnergyScale = 'kinetic';
|
||||
expectedEnergyScale = {'kinetic','binding','xRay'};
|
||||
|
||||
% Parse input
|
||||
p = inputParser;
|
||||
addRequired(p,'DataTable',@istable);
|
||||
addRequired(p,'energyStart',@isnumeric)
|
||||
addRequired(p,'energyEnd',@isnumeric)
|
||||
addOptional(p,'tableSelection',defaultTableSelection,@islogical);
|
||||
addParameter(p,'tableVariable',defaultTableVariable,...
|
||||
@(x) any(validatestring(x,expectedTableVariable)));
|
||||
addParameter(p,'mode',defaultMode,...
|
||||
@(x) any(validatestring(x,expectedMode)));
|
||||
addParameter(p,'showFigures',defaultShowFigures,...
|
||||
@(x) any(validatestring(x,expectedShowFigures)));
|
||||
addParameter(p,'energyScale',defaultEnergyScale,...
|
||||
@(x) any(validatestring(x,expectedEnergyScale)));
|
||||
parse(p,DataTable,varargin{:});
|
||||
|
||||
% check input (all elements of input variable need to have non-zero size)
|
||||
if ~all(cell2mat(cellfun(@size,p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable),'UniformOutput',false)),'all')
|
||||
disp('The table variable appears to be empty. I quit now')
|
||||
error('The table variable appears to be empty.')
|
||||
end
|
||||
|
||||
% add empty table variables (if they don't exist)
|
||||
existColumn = strcmp('logBackgroundRange',DataTable.Properties.VariableNames);
|
||||
if ~any(existColumn)
|
||||
DataTable.logBackgroundRange = NaN(size(DataTable,1),2);
|
||||
end
|
||||
existColumn = strcmp('logBackgroundMode',DataTable.Properties.VariableNames);
|
||||
if ~any(existColumn)
|
||||
DataTable.logBackgroundMode = cellstr(repmat(' ',size(p.Results.DataTable,1),1));
|
||||
end
|
||||
existColumn = strcmp('logBackgroundDate',DataTable.Properties.VariableNames);
|
||||
if ~any(existColumn)
|
||||
DataTable.logBackgroundDate = cellstr(repmat(' ',size(p.Results.DataTable,1),1));
|
||||
end
|
||||
|
||||
|
||||
% repeat this for all columns in input.
|
||||
for ii = 1:size(p.Results.DataTable(p.Results.tableSelection,:),1)
|
||||
if contains(p.Results.energyScale,'kinetic')
|
||||
% LINEAR FIT
|
||||
if contains(p.Results.mode,'linfit')
|
||||
disp('linfit not yet supported')
|
||||
% MEAN
|
||||
else
|
||||
b_1 = find(p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii} >= p.Results.energyStart,1);
|
||||
b_2 = find(p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii} >= p.Results.energyEnd,1);
|
||||
|
||||
if b_2 == 1
|
||||
b_2=10;
|
||||
end
|
||||
|
||||
b_mean = mean(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii}(b_1:b_2),'omitnan');
|
||||
tmp(ii,1) = cellfun(@(x) x-b_mean,p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable)(ii),'UniformOutput',false);
|
||||
|
||||
|
||||
end
|
||||
|
||||
elseif contains(p.Results.energyScale,'binding')
|
||||
if contains(p.Results.mode,'linfit')
|
||||
disp('linfit not yet supported')
|
||||
% MEAN
|
||||
else
|
||||
b_1 = find(p.Results.DataTable(p.Results.tableSelection,:).bindingEnergy_eV{ii} <= p.Results.energyStart,1);
|
||||
b_2 = find(p.Results.DataTable(p.Results.tableSelection,:).bindingEnergy_eV{ii} <= p.Results.energyEnd,1);
|
||||
|
||||
if b_2 == 1
|
||||
b_2=10;
|
||||
end
|
||||
|
||||
b_mean = mean(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii}(b_2:b_1),'omitnan');
|
||||
tmp(ii,1) = cellfun(@(x) x-b_mean,p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable)(ii),'UniformOutput',false);
|
||||
|
||||
|
||||
end
|
||||
elseif contains(p.Results.energyScale,'xRay')
|
||||
if contains(p.Results.mode,'linfit') % LINEAR FIT
|
||||
|
||||
% Fit: 'untitled fit 1'.
|
||||
[xData, yData] = prepareCurveData( p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii}, ...
|
||||
p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii});
|
||||
% Set up fittype and options.
|
||||
ft = fittype( 'poly1' );
|
||||
excludedPoints = excludedata( xData, yData, 'domain',[p.Results.energyStart p.Results.energyEnd] );
|
||||
fo = fitoptions('Exclude', excludedPoints);
|
||||
% Fit model to data.
|
||||
[fitresult, ~] = fit( xData, yData, ft, fo );
|
||||
if contains(p.Results.showFigures,'on')
|
||||
% Plot fit with data.
|
||||
figure( 'Name', 'fit pre-edge' );
|
||||
h = plot( fitresult, xData, yData, excludedPoints );
|
||||
xlabel('Photon Energy eV')
|
||||
ylabel('partial A-M.E.Y.')
|
||||
grid on
|
||||
title(p.Results.DataTable(p.Results.tableSelection,:).name{ii},'Interpreter','none')
|
||||
end
|
||||
tmp{ii,1} = p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii}-fitresult(p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii});
|
||||
|
||||
elseif contains(p.Results.mode,'mean') % mean
|
||||
|
||||
if p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii}(1) < p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii}(end)
|
||||
% prepare Data
|
||||
|
||||
[xData, yData] = prepareCurveData( p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii}, ...
|
||||
p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii});
|
||||
% MEAN
|
||||
b_1 = find(xData >= p.Results.energyStart,1);
|
||||
b_2 = find(xData >= p.Results.energyEnd,1);
|
||||
|
||||
b_mean = mean(yData(b_1:b_2));
|
||||
elseif p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii}(1) > p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii}(end)
|
||||
% prepare Data
|
||||
[xData, yData] = prepareCurveData( p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii}, ...
|
||||
p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii});
|
||||
% MEAN
|
||||
b_1 = find(xData <= p.Results.energyStart,1);
|
||||
b_2 = find(xData <= p.Results.energyEnd,1);
|
||||
|
||||
b_mean = mean(yData(b_2:b_1));
|
||||
else
|
||||
disp('Warning: Issue with NEXAFS data or energies')
|
||||
end
|
||||
|
||||
|
||||
tmp(ii,1) = cellfun(@(x) x-b_mean,p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable)(ii),'UniformOutput',false);
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
% fill selected rows
|
||||
DataTable(p.Results.tableSelection,:).(p.Results.tableVariable) = tmp;
|
||||
% write log to table
|
||||
DataTable.logBackgroundMode(p.Results.tableSelection,:) = cellstr(repmat(p.Results.mode,size(p.Results.DataTable(p.Results.tableSelection,:),1),1));
|
||||
DataTable.logBackgroundRange(p.Results.tableSelection,:) = repmat([p.Results.energyStart p.Results.energyEnd],size(p.Results.DataTable(p.Results.tableSelection,:),1),1);
|
||||
DataTable.logBackgroundDate(p.Results.tableSelection,:) = cellstr(repmat(datestr(now),size(p.Results.DataTable(p.Results.tableSelection,:),1),1));
|
||||
|
||||
end
|
||||
@@ -1,114 +0,0 @@
|
||||
function DataTable = nappBackground(DataTable,varargin)
|
||||
%nappBackground determines and subtracts the background from PE or XAS spectra
|
||||
%
|
||||
% FileList = nappBackground(FileList,energyStart,energyEnd);
|
||||
%
|
||||
% FileList = nappBackground(FileList,368,370,'tableSelection',tmpDataSelection,'energyScale','kinetic',...
|
||||
% 'mode','mean','showFigures','off');
|
||||
%
|
||||
%
|
||||
% *input*
|
||||
% FileList: data table
|
||||
% energyStart: smallest value of energy range to use for background calculation
|
||||
% (can also be binding energy)
|
||||
% energyEnd: largest value of energy energy range to use for background calculation
|
||||
% (can also be binding energy)
|
||||
% tableSelection (optional): logical array to filter data table
|
||||
% tableVariable: choose to process either
|
||||
% 'spectrum_counts','spectrum_countsPerSecond' (default), or
|
||||
% 'spectrum_countsNorm'.
|
||||
% mode: mean(default) subtract the mean of the energy range from
|
||||
% spectrum; linfit subtract a linear regression through the energy range
|
||||
% from spectrum
|
||||
% showFigures, on(default): show fit in figure, off do not show fit in
|
||||
% figure
|
||||
% energyScale: kinetic(default): work with kinetic energy scale; binding
|
||||
% works with binding energy scale.
|
||||
%
|
||||
%
|
||||
% *output*
|
||||
% The table variable passed to the function as tableVariable
|
||||
% parameter will be overwritten with the background subtracted spectrum.
|
||||
%
|
||||
% The function parameters (mode, energyStart, energyEnd) are written
|
||||
% to the table as log.
|
||||
|
||||
|
||||
|
||||
% Define conditions and defaults of input
|
||||
defaultTableVariable = 'spectrum_countsPerSecond';
|
||||
expectedTableVariable = {'spectrum_counts','spectrum_countsPerSecond','spectrum_countsNorm'};
|
||||
defaultMode = 'mean';
|
||||
expectedMode = {'mean','linfit'};
|
||||
defaultTableSelection = true(size(DataTable,1),1);
|
||||
defaultShowFigures = 'on';
|
||||
expectedShowFigures = {'on','off'};
|
||||
defaultEnergyScale = 'kinetic';
|
||||
expectedEnergyScale = {'kinetic','binding'};
|
||||
|
||||
% Parse input
|
||||
p = inputParser;
|
||||
addRequired(p,'DataTable',@istable);
|
||||
addRequired(p,'energyStart',@isnumeric)
|
||||
addRequired(p,'energyEnd',@isnumeric)
|
||||
addOptional(p,'tableSelection',defaultTableSelection,@islogical);
|
||||
addParameter(p,'tableVariable',defaultTableVariable,...
|
||||
@(x) any(validatestring(x,expectedTableVariable)));
|
||||
addParameter(p,'mode',defaultMode,...
|
||||
@(x) any(validatestring(x,expectedMode)));
|
||||
addParameter(p,'showFigures',defaultShowFigures,...
|
||||
@(x) any(validatestring(x,expectedShowFigures)));
|
||||
addParameter(p,'energyScale',defaultEnergyScale,...
|
||||
@(x) any(validatestring(x,expectedEnergyScale)));
|
||||
parse(p,DataTable,varargin{:});
|
||||
|
||||
% check input (all elements of input variable need to have non-zero size)
|
||||
if ~all(cell2mat(cellfun(@size,p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable),'UniformOutput',false)),'all')
|
||||
disp('The table variable appears to be empty. I quit now')
|
||||
error('The table variable appears to be empty.')
|
||||
end
|
||||
|
||||
% repeat this for all columns in input.
|
||||
for ii = 1:size(p.Results.DataTable(p.Results.tableSelection,:),1)
|
||||
if contains(p.Results.energyScale,'kinetic')
|
||||
% LINEAR FIT
|
||||
if contains(p.Results.mode,'linfit')
|
||||
disp('linfit not yet supported')
|
||||
% MEAN
|
||||
else
|
||||
b_1 = find(p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii} >= p.Results.energyStart,1);
|
||||
b_2 = find(p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii} >= p.Results.energyEnd,1);
|
||||
|
||||
if b_2 == 1
|
||||
b_2=10;
|
||||
end
|
||||
|
||||
b_mean = mean(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii}(b_1:b_2),'omitnan');
|
||||
tmp(ii,1) = cellfun(@(x) x-b_mean,p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable)(ii),'UniformOutput',false);
|
||||
|
||||
|
||||
end
|
||||
|
||||
elseif contains(p.Results.energyScale,'binding')
|
||||
if contains(p.Results.mode,'linfit')
|
||||
disp('linfit not yet supported')
|
||||
% MEAN
|
||||
else
|
||||
b_1 = find(p.Results.DataTable(p.Results.tableSelection,:).bindingEnergy_eV{ii} <= p.Results.energyStart,1);
|
||||
b_2 = find(p.Results.DataTable(p.Results.tableSelection,:).bindingEnergy_eV{ii} <= p.Results.energyEnd,1);
|
||||
|
||||
if b_2 == 1
|
||||
b_2=10;
|
||||
end
|
||||
|
||||
b_mean = mean(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii}(b_2:b_1),'omitnan');
|
||||
tmp(ii,1) = cellfun(@(x) x-b_mean,p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable)(ii),'UniformOutput',false);
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
% fill selected rows
|
||||
DataTable(p.Results.tableSelection,:).(p.Results.tableVariable) = tmp;
|
||||
|
||||
end
|
||||
@@ -1,69 +0,0 @@
|
||||
function DataTable = nappBindingEnergyXps(DataTable,varargin)
|
||||
%nappBindingEnergyXps calculates the binding energy scale for spectra based
|
||||
%on the binding energy shift.
|
||||
%
|
||||
% *Requirement*
|
||||
% Needs table variable bindingEnergyShift as input. Run
|
||||
% nappDetermineShiftXps.m or nappCopyShift.m first
|
||||
%
|
||||
% FileList = nappBindingEnergyXps(FileList,'tableSelection',...
|
||||
% tmpDataSelection);
|
||||
%
|
||||
%
|
||||
% *input*
|
||||
% FileList: data table
|
||||
% tableSelection (optional): logical array to filter data table
|
||||
% tableVariable: choose to process either
|
||||
% 'spectrum_counts','spectrum_countsPerSecond' (default)
|
||||
%
|
||||
%
|
||||
% *output*
|
||||
% new table variable bindingEnergy_eV holding the binding energy for
|
||||
% the data.
|
||||
%
|
||||
%
|
||||
% See also nappnappAlignImages.m nappBindingEnergyXps nappFitGaussXps.m
|
||||
% nappCopyShift.m nappDetermineShiftXps.m
|
||||
|
||||
defaultTableVariable = 'spectrum_countsPerSecond';
|
||||
expectedTableVariable = {'spectrum_counts','spectrum_countsPerSecond'};
|
||||
defaultTableSelection = true(size(DataTable,1),1);
|
||||
|
||||
% Parse input
|
||||
p = inputParser;
|
||||
addRequired(p,'DataTable',@istable);
|
||||
addParameter(p,'tableSelection',defaultTableSelection,@islogical);
|
||||
addParameter(p,'tableVariable',defaultTableVariable,...
|
||||
@(x) any(validatestring(x,expectedTableVariable)));
|
||||
parse(p,DataTable,varargin{:});
|
||||
|
||||
% check input (all elements of input variable need to have non-zero size)
|
||||
if ~all(cell2mat(cellfun(@size,p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable),'UniformOutput',false)),'all')
|
||||
disp('The table variable appears to be empty. I quit now')
|
||||
error('The table variable appears to be empty.')
|
||||
end
|
||||
|
||||
% add empty variable to table
|
||||
existColumn = strcmp('bindingEnergy_eV',DataTable.Properties.VariableNames);
|
||||
if ~any(existColumn)
|
||||
DataTable.bindingEnergy_eV = cell(size(DataTable,1),1);
|
||||
end
|
||||
|
||||
if any(isnan(cell2mat(p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV)))
|
||||
disp('Opps, X-ray energy is empty. Please add manually. Will stop now');
|
||||
return
|
||||
end
|
||||
|
||||
% repeat this for all columns in input.
|
||||
for ii = 1:size(p.Results.DataTable(p.Results.tableSelection,:),1)
|
||||
%%
|
||||
if isnan(p.Results.DataTable(p.Results.tableSelection,:).bindingEnergyShift(ii))
|
||||
tmp_2(:,1) = p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii} - p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii};
|
||||
else
|
||||
tmp_2(:,1) = p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii} - p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii} - p.Results.DataTable(p.Results.tableSelection,:).bindingEnergyShift(ii);
|
||||
end
|
||||
tmp_3{ii,1} =tmp_2;
|
||||
clearvars tmp_2
|
||||
end
|
||||
DataTable.bindingEnergy_eV(p.Results.tableSelection,:) = tmp_3;
|
||||
end
|
||||
@@ -1,100 +0,0 @@
|
||||
function combinedSpectrum = nappCombineSpectra(DataTable,varargin)
|
||||
%nappCombineSpectra combines selected PE or NEXAFS spectra into one. Data
|
||||
%are intrapolated along x-axis.
|
||||
%
|
||||
% MgO_C1s_Warm = nappCombineSpectra(FileList,'tableRow',1,...
|
||||
% 'tableSelection',tmpDataSelection,'tableVariable',...
|
||||
% 'spectrum_countsNorm','EnergyScale','binding','mode','average');
|
||||
%
|
||||
% *input*
|
||||
% FileList: data table
|
||||
% tableSelection (optional): logical array to filter data table
|
||||
% tableVariable (optional): select source: 'nexafsSpectrum','spectrum_counts','spectrum_countsPerSecond',...
|
||||
% 'spectrum_countsNorm','nexafsSpectrumPreBackground','nexafsSpectrumPreNorm',...
|
||||
% 'nexafsSpectrumPreGasPhase','nexafsSpectrumPreI0','nexafsSpectrumPreAdvCarb'
|
||||
% tableRow (optional): default 1. Defines the row in filtered table (to be
|
||||
% processed). The x-axis of that data set will be used for interpolation.
|
||||
% mode: mean (default) averages the spectra; sum adds them, subtract not
|
||||
% coded yet.
|
||||
% energyScale (optional): kinetic (default) or binding energy scale; only relevant
|
||||
% for PE spectra, not for NEXAFS
|
||||
%
|
||||
%
|
||||
% *output*
|
||||
% a matrix with energy in column 1, counts in column2, and standard
|
||||
% deviation in column 3 (only for mean).
|
||||
%
|
||||
|
||||
|
||||
expectedTableVariable = {'nexafsSpectrum','spectrum_counts','spectrum_countsPerSecond',...
|
||||
'spectrum_countsNorm','nexafsSpectrumPreBackground','nexafsSpectrumPreNorm',...
|
||||
'nexafsSpectrumPreGasPhase','nexafsSpectrumPreI0','nexafsSpectrumPreAdvCarb'};
|
||||
defaultTableSelection = true(size(DataTable,1));
|
||||
defaultTableRow = 1;
|
||||
defaultMode = 'sum';
|
||||
expectedMode = {'sum','average','subtract'};
|
||||
defaultEnergyScale = 'kinetic';
|
||||
expectedEnergyScale = {'kinetic','binding','xRay'};
|
||||
|
||||
|
||||
% Parse input
|
||||
p = inputParser;
|
||||
addRequired(p,'DataTable',@istable);
|
||||
addParameter(p,'tableSelection',defaultTableSelection,@islogical);
|
||||
addParameter(p,'tableRow',defaultTableRow,@isnumeric);
|
||||
addParameter(p,'tableVariable',...
|
||||
@(x) any(validatestring(x,expectedTableVariable)));
|
||||
addParameter(p,'mode',defaultMode,...
|
||||
@(x) any(validatestring(x,expectedMode)));
|
||||
addParameter(p,'energyScale',defaultEnergyScale,...
|
||||
@(x) any(validatestring(x,expectedEnergyScale)));
|
||||
|
||||
parse(p,DataTable,varargin{:});
|
||||
|
||||
% check input (all elements of input variable need to have non-zero size)
|
||||
if ~all(cell2mat(cellfun(@size,p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable),'UniformOutput',false)),'all')
|
||||
disp('The table variable appears to be empty. I quit now')
|
||||
error('The table variable appears to be empty.')
|
||||
end
|
||||
|
||||
if (contains(p.Results.tableVariable,'counts')) && (contains(p.Results.energyScale,'kinetic'))
|
||||
tmpX = p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV;
|
||||
elseif (contains(p.Results.tableVariable,'counts')) && (contains(p.Results.energyScale,'binding'))
|
||||
tmpX = p.Results.DataTable(p.Results.tableSelection,:).bindingEnergy_eV;
|
||||
elseif contains(p.Results.tableVariable,'counts') && (contains(p.Results.energyScale,'xRay'))
|
||||
tmpX = p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV;
|
||||
end
|
||||
|
||||
|
||||
if contains(p.Results.energyScale,'binding')
|
||||
tmpStart = min(cellfun(@(x) x(1), tmpX));
|
||||
tmpEnd = max(cellfun(@(x) x(end), tmpX));
|
||||
tmpStartIndex = find(tmpX{p.Results.tableRow} <= tmpStart,1);
|
||||
tmpEndIndex = find(tmpX{p.Results.tableRow} <= tmpEnd,1);
|
||||
else
|
||||
tmpStart = max(cellfun(@(x) x(1), tmpX));
|
||||
tmpEnd = min(cellfun(@(x) x(end), tmpX));
|
||||
tmpStartIndex = find(tmpX{p.Results.tableRow} >= tmpStart,1);
|
||||
tmpEndIndex = find(tmpX{p.Results.tableRow} >= tmpEnd,1);
|
||||
end
|
||||
|
||||
xq = tmpX{p.Results.tableRow}(tmpStartIndex:tmpEndIndex);
|
||||
% repeat this for all columns in input.
|
||||
for ii = 1:size(p.Results.DataTable(p.Results.tableSelection,:),1)
|
||||
x = tmpX{ii};
|
||||
v = p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii};
|
||||
vq(:,ii) = interp1(x,v,xq);
|
||||
end
|
||||
|
||||
|
||||
|
||||
combinedSpectrum(:,1) = xq;
|
||||
if contains(p.Results.mode,'sum')
|
||||
combinedSpectrum(:,2) = sum(vq,2);
|
||||
elseif contains(p.Results.mode,'average')
|
||||
combinedSpectrum(:,2) = mean(vq,2);
|
||||
combinedSpectrum(:,3) = std(vq,0,2);
|
||||
elseif contains(p.Results.mode,'subtract')
|
||||
disp('Not supported yet') % FIXME: subtraction is not implemented yet.
|
||||
end
|
||||
end
|
||||
@@ -1,99 +0,0 @@
|
||||
function DataTable = nappCopyShift(DataTable,varargin)
|
||||
%nappBindingEnergyXps calculates the binding energy scale for spectra based
|
||||
%on the binding energy shift.
|
||||
%
|
||||
% For each spectrum with a given file number, the function copies the shift from data of a specified
|
||||
% region to another region of choice.
|
||||
%
|
||||
% *Requirement*
|
||||
% Needs table variable bindingEnergyShift as input. Run
|
||||
% nappDetermineShiftXps.m first on selected region.
|
||||
%
|
||||
% FileList = nappCopyShift(FileList,tmpDataSelection,'energyScale','binding');
|
||||
%
|
||||
% *input*
|
||||
% FileList: data table
|
||||
% tableSelection (optional): logical array to filter data table
|
||||
% regionOld: O1s (default) or C1s - source of shift data
|
||||
% regionNew: C1s (default), N1s or O1s - shift data will be copied to this
|
||||
% region
|
||||
% energyScale: kinetic (default) or binding: process either the kinetic
|
||||
% (for images) or the binding energy shift data (for spectra)
|
||||
%
|
||||
% *output*
|
||||
% Table variable bindingEnergy_eV holding the binding energy for
|
||||
% the data.
|
||||
%
|
||||
% See also nappnappAlignImages.m nappBindingEnergyXps nappFitGaussXps.m
|
||||
% nappCopyShift.m nappDetermineShiftXps.m
|
||||
|
||||
% Define conditions and defaults of input
|
||||
% Old region must be also selected in tableSelection! it is kind like
|
||||
% double.
|
||||
defaultRegionOld = 'O1s';
|
||||
expectedRegionOld = {'O1s','C1s','N1s'};
|
||||
defaultRegionNew = 'C1s';
|
||||
expectedRegionNew = {'O1s','C1s','N1s','Cl2p'};
|
||||
defaultTableSelection = true(size(DataTable,1));
|
||||
defaultEnergyScale = 'kinetic';
|
||||
expectedEnergyScale = {'kinetic','binding'};
|
||||
|
||||
|
||||
% Parse input
|
||||
p = inputParser;
|
||||
addRequired(p,'DataTable',@istable);
|
||||
addOptional(p,'tableSelection',defaultTableSelection,@islogical);
|
||||
addParameter(p,'regionOld',defaultRegionOld,...
|
||||
@(x) any(validatestring(x,expectedRegionOld)));
|
||||
addParameter(p,'regionNew',defaultRegionNew,...
|
||||
@(x) any(validatestring(x,expectedRegionNew)));
|
||||
addParameter(p,'energyScale',defaultEnergyScale,...
|
||||
@(x) any(validatestring(x,expectedEnergyScale)));
|
||||
parse(p,DataTable,varargin{:});
|
||||
|
||||
if contains(p.Results.energyScale,'kinetic')
|
||||
% repeat this for all columns in input.
|
||||
for ii = 1:size(p.Results.DataTable(p.Results.tableSelection,:),1)
|
||||
% get name and date
|
||||
tmpName = replace(p.Results.DataTable(p.Results.tableSelection,:).name{ii}, ...
|
||||
p.Results.regionOld,p.Results.regionNew);
|
||||
tmpDate = p.Results.DataTable(p.Results.tableSelection,:).lastModifiedDatenum(ii);
|
||||
% select spectra
|
||||
tmpDataSelection = contains(p.Results.DataTable.name,tmpName)...
|
||||
& ismember(year(p.Results.DataTable.lastModifiedDatenum),year(tmpDate))...
|
||||
& ismember(month(p.Results.DataTable.lastModifiedDatenum),month(tmpDate))...
|
||||
& ismember(day(p.Results.DataTable.lastModifiedDatenum),day(tmpDate))...
|
||||
& ismember(hour(p.Results.DataTable.lastModifiedDatenum),hour(tmpDate))...
|
||||
& ismember(minute(p.Results.DataTable.lastModifiedDatenum),minute(tmpDate));
|
||||
|
||||
if ~any(tmpDataSelection) == 1
|
||||
disp('There is something wrong with the data time info')
|
||||
disp(tmpName)
|
||||
end
|
||||
% replace the region in the name and copy the data
|
||||
DataTable.kineticEnergyShift(tmpDataSelection,:) = p.Results.DataTable(p.Results.tableSelection,:).kineticEnergyShift(ii);
|
||||
end
|
||||
elseif contains(p.Results.energyScale,'binding')
|
||||
% repeat this for all columns in input.
|
||||
for ii = 1:size(p.Results.DataTable(p.Results.tableSelection,:),1)
|
||||
% get name and date
|
||||
tmpName = replace(p.Results.DataTable(p.Results.tableSelection,:).name{ii}, ...
|
||||
p.Results.regionOld,p.Results.regionNew);
|
||||
tmpDate = p.Results.DataTable(p.Results.tableSelection,:).lastModifiedDatenum(ii);
|
||||
% select spectra
|
||||
tmpDataSelection = contains(p.Results.DataTable.name,tmpName)...
|
||||
& ismember(year(p.Results.DataTable.lastModifiedDatenum),year(tmpDate))...
|
||||
& ismember(month(p.Results.DataTable.lastModifiedDatenum),month(tmpDate))...
|
||||
& ismember(day(p.Results.DataTable.lastModifiedDatenum),day(tmpDate))...
|
||||
& ismember(hour(p.Results.DataTable.lastModifiedDatenum),hour(tmpDate))...
|
||||
& ismember(minute(p.Results.DataTable.lastModifiedDatenum),minute(tmpDate));
|
||||
if ~any(tmpDataSelection) == 1
|
||||
disp('There is something wrong with the data time info')
|
||||
disp(tmpName)
|
||||
end
|
||||
% replace the region in the name and copy the data
|
||||
DataTable.bindingEnergyShift(tmpDataSelection,:) = p.Results.DataTable(p.Results.tableSelection,:).bindingEnergyShift(ii);
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,386 +0,0 @@
|
||||
function DataTable = nappDetermineShiftXps(DataTable,varargin)
|
||||
%nappDetermineShiftXps determines the relative shift of each sequence
|
||||
%iteration in images or the absolute shift of spectra to a binding energy reference
|
||||
%
|
||||
% FileList = nappDetermineShiftXps(FileList,eKinStart,eKinEnd,'tableSelection',tmpDataSelection,...
|
||||
% 'showFigures','off','tableVariable','spectrum_countsPerSecond','binEnReference',535);
|
||||
%
|
||||
% FileList = nappDetermineShiftXps(FileList,'tableSelection',tmpDataSelection,...
|
||||
% 'showFigures','on','tableVariable','image');
|
||||
%
|
||||
% *input*
|
||||
% FileList: data table
|
||||
% eKinStart (optional): smallest value of energy range to use for
|
||||
% peak fitting. Peak fitting is used to get position of peak
|
||||
% eKinEnd (optional): largest value of energy energy range to use for
|
||||
% peak fitting. Peak fitting is used to get position of peak
|
||||
% tableSelection (optional): logical array to filter data table
|
||||
% tableVariable: choose to process either
|
||||
% 'spectrum_counts','spectrum_countsPerSecond' (default), => absolute binding energy shift will be determined or
|
||||
% ,'image','imageRoh'=> relative kinetic energy shift will be determined.
|
||||
% binEnReference: Reference BE in eV for spectra energy scale
|
||||
% kinEnReference: Sequence iteration to which the image should be
|
||||
% aligned, default is 1.
|
||||
% minPeakWidth: findpeak parameter, default 0.1
|
||||
% minPeakHeight: findpeak parameter, default 0.1
|
||||
% movMeanWindow: findpeak parameter, default 1
|
||||
% showFigures, on(default): show fit in figure, off do not show fit in figure
|
||||
%
|
||||
%
|
||||
% *output*
|
||||
% new table variable kineticEnergyShift for images
|
||||
% new table variable bindingEnergyShift for spectra
|
||||
%
|
||||
%
|
||||
% *ToDo*
|
||||
%
|
||||
% FIXME: make use of O1s fit more general => use nappFitGaussXps.m function
|
||||
% FIXME: Do not use peakfind for image fit => use nappFitGaussXps.m function
|
||||
%
|
||||
%
|
||||
% See also nappnappAlignImages.m nappBindingEnergyXps nappFitGaussXps.m nappCopyShift.m
|
||||
|
||||
defaultKinEnReference = 1;
|
||||
defaultTableVariable = 'spectrum_countsPerSecond';
|
||||
expectedTableVariable = {'spectrum_counts','spectrum_countsPerSecond','image','imageRoh'};
|
||||
defaultTableSelection = true(size(DataTable,1));
|
||||
defaultMinPeakWidth = 0.1;
|
||||
defaultMinPeakHeight = 0.1;
|
||||
defaultMovMeanWindow = 1;
|
||||
defaultShowFigures = 'off';
|
||||
expectedShowFigures = {'on','off'};
|
||||
|
||||
|
||||
%%
|
||||
|
||||
% Parse input
|
||||
p = inputParser;
|
||||
addRequired(p,'DataTable',@istable);
|
||||
addOptional(p,'eKinStart',@isnumeric)
|
||||
addOptional(p,'eKinEnd',@isnumeric)
|
||||
addParameter(p,'binEnReference',@isnumeric)
|
||||
addParameter(p,'kinEnReference',defaultKinEnReference,@isnumeric)
|
||||
addParameter(p,'tableSelection',defaultTableSelection,@islogical);
|
||||
addParameter(p,'minPeakWidth',defaultMinPeakWidth,@isnumeric);
|
||||
addParameter(p,'minPeakHeight',defaultMinPeakHeight,@isnumeric);
|
||||
addParameter(p,'movMeanWindow',defaultMovMeanWindow ,@isnumeric);
|
||||
addParameter(p,'tableVariable',defaultTableVariable,...
|
||||
@(x) any(validatestring(x,expectedTableVariable)));
|
||||
addParameter(p,'showFigures',defaultShowFigures,...
|
||||
@(x) any(validatestring(x,expectedShowFigures)));
|
||||
parse(p,DataTable,varargin{:});
|
||||
|
||||
% check input (all elements of input variable need to have non-zero size)
|
||||
if ~all(cell2mat(cellfun(@size,p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable),'UniformOutput',false)),'all')
|
||||
disp('The table variable appears to be empty. I quit now')
|
||||
error('The table variable appears to be empty.')
|
||||
end
|
||||
|
||||
% add empty variable to table
|
||||
if contains(p.Results.tableVariable,'image')
|
||||
existColumn = strcmp('kineticEnergyShift',DataTable.Properties.VariableNames);
|
||||
if ~any(existColumn)
|
||||
DataTable.kineticEnergyShift = cell(size(DataTable,1),1);
|
||||
end
|
||||
else
|
||||
existColumn = strcmp('bindingEnergyShift',DataTable.Properties.VariableNames);
|
||||
if ~any(existColumn)
|
||||
DataTable.bindingEnergyShift = NaN(size(DataTable,1),1);
|
||||
end
|
||||
end
|
||||
%Colors; define PSI cooperate identity colours
|
||||
PsiFarbe.hellgrau = [226 226 226]/255;
|
||||
PsiFarbe.mittelgrau = [184 184 184]/255;
|
||||
PsiFarbe.dunkelgrau = [78 78 77]/255;
|
||||
PsiFarbe.blaugrau = [236 236 243]/255; % This is actually not a PSI colour
|
||||
PsiFarbe.gelb = [239 200 37]/255;
|
||||
PsiFarbe.hellorange = [227 164 31]/255;
|
||||
PsiFarbe.dunkelorange = [207 92 22]/255;
|
||||
PsiFarbe.hellrot = [164 36 23]/255;
|
||||
PsiFarbe.dunkelbraun = [114 85 65]/255;
|
||||
PsiFarbe.hellbraun = [127 119 47]/255;
|
||||
PsiFarbe.mittelgruen = [135 150 59]/255;
|
||||
PsiFarbe.hellgruen = [195 214 47]/255;
|
||||
PsiFarbe.dunkelgruen = [72 130 33]/255;
|
||||
PsiFarbe.dunkelrot = [104 47 86]/255;
|
||||
PsiFarbe.dunkelblau = [37 65 108]/255;
|
||||
PsiFarbe.mittelgruenblau = [61 164 168]/255;
|
||||
PsiFarbe.hellblau = [58 162 190]/255;
|
||||
PsiFarbe.mittelblau = [50 118 158]/255;
|
||||
|
||||
% confirm that X-ray energy is set
|
||||
if any(isnan(cell2mat(p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV)))
|
||||
disp('Opps, X-ray energy is empty. Please add manually. Will stop now');
|
||||
return
|
||||
end
|
||||
if matches(p.Results.tableVariable,'image')
|
||||
% repeat this for all columns in input.
|
||||
for ii = 1:size(p.Results.DataTable(p.Results.tableSelection,:),1)
|
||||
%%
|
||||
try
|
||||
if isnumeric(p.Results.eKinStart)
|
||||
start = find(p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii}...
|
||||
>= p.Results.eKinStart,1);
|
||||
stop = find(p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii}...
|
||||
>= p.Results.eKinEnd,1);
|
||||
else
|
||||
start = 1;
|
||||
stop = length(p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii});
|
||||
end
|
||||
catch
|
||||
warning('There is something wrong with the eKinStart and/or eKinEnd parameters');
|
||||
disp('There is something wrong with the eKinStart and/or eKinEnd parameters');
|
||||
end
|
||||
|
||||
for ij = 1:size(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii},2)
|
||||
[B,x1,y1] = GaussFitOnePeak([p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii}(start:stop)',...
|
||||
p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii}(start:stop,ij)]);
|
||||
tmp_1(ij) = p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii}-B(3);
|
||||
% plot result
|
||||
if matches(p.Results.showFigures,'on')
|
||||
% define equations to be plotted
|
||||
Gauss = @(x,Hgt, Pos, Wdt) Hgt./(Wdt.*sqrt(pi/2))*exp(-2.*((x - Pos).^2/Wdt.^2));
|
||||
linear = @(x,slp,intrcpt) slp*x+intrcpt;
|
||||
figure( 'Name', 'Gauss Multi Fit ')
|
||||
tiledlayout(1,1)
|
||||
nexttile;
|
||||
%Define gauss peaks with hight, position, width from fitting results
|
||||
yData_pk1= Gauss(x1 ,B(1), B(3), B(2));
|
||||
yData_pk2= Gauss(x1 ,B(4), B(6), B(5));
|
||||
bkgrd = linear(x1,B(7),B(8));
|
||||
% plot data
|
||||
plot(x1,y1,'.')
|
||||
hold on
|
||||
% plot fit
|
||||
h = plot(x1,yData_pk1+yData_pk2+bkgrd);
|
||||
h.LineWidth=2;
|
||||
h.Color = PsiFarbe.dunkelblau;
|
||||
% plot each gauss peak
|
||||
h = plot(x1,yData_pk1+bkgrd);
|
||||
h.LineWidth=1.5;
|
||||
h.Color = PsiFarbe.gelb;
|
||||
h = plot(x1,yData_pk2+bkgrd);
|
||||
h.LineWidth=1.5;
|
||||
h.Color = PsiFarbe.gelb;
|
||||
|
||||
legend OFF
|
||||
xlabel('Kinetic Energy [eV]');
|
||||
ylabel('PE intensity [-]');
|
||||
grid on
|
||||
|
||||
% List results in table
|
||||
|
||||
disp('Results');
|
||||
disp(' ' );
|
||||
disp(cell2table({sprintf('%.1f',B(3)),...
|
||||
sprintf('%.1f',B(2)*sqrt(log(4))),...
|
||||
sprintf('%.1f',B(2)),...
|
||||
sprintf('%7.0f',B(1))},...
|
||||
'VariableNames',{'position';'FWHW';'width';'area'},...
|
||||
'RowNames',{'pk 1'}));
|
||||
end
|
||||
end
|
||||
%%
|
||||
|
||||
|
||||
DataTable(p.Results.tableSelection,:).kineticEnergyShift{ii} = tmp_1-tmp_1(p.Results.kinEnReference);
|
||||
clearvars tmp_1
|
||||
fh = findobj( 'Type', 'Figure', 'Name', 'Gauss Multi Fit ');
|
||||
close(fh)
|
||||
fh = findobj( 'Type', 'Figure', 'Name', 'GlobalSearch');
|
||||
close(fh)
|
||||
end
|
||||
elseif matches(p.Results.tableVariable,'imageRoh')
|
||||
% repeat this for all columns in input.
|
||||
for ii = 1:size(p.Results.DataTable(p.Results.tableSelection,:),1)
|
||||
|
||||
%%
|
||||
try
|
||||
if isnumeric(p.Results.eKinStart) && isempty(DataTable(p.Results.tableSelection,:).scientaEkinRoh_eV{ii})
|
||||
start = find(p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii}...
|
||||
>= p.Results.eKinStart,1);
|
||||
stop = find(p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii}...
|
||||
>= p.Results.eKinEnd,1);
|
||||
elseif isnumeric(p.Results.eKinStart) && ~isempty(DataTable(p.Results.tableSelection,:).scientaEkinRoh_eV{ii})
|
||||
start = find(p.Results.DataTable(p.Results.tableSelection,:).scientaEkinRoh_eV{ii}...
|
||||
>= p.Results.eKinStart,1);
|
||||
stop = find(p.Results.DataTable(p.Results.tableSelection,:).scientaEkinRoh_eV{ii}...
|
||||
>= p.Results.eKinEnd,1);
|
||||
elseif isempty(DataTable(p.Results.tableSelection,:).scientaEkinRoh_eV{ii})
|
||||
start = 1;
|
||||
stop = length(p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii});
|
||||
else
|
||||
start = 1;
|
||||
stop = length(DataTable(p.Results.tableSelection,:).scientaEkinRoh_eV{ii});
|
||||
end
|
||||
catch
|
||||
warning('There is something wrong with the eKinStart and/or eKinEnd parameters');
|
||||
disp('There is something wrong with the eKinStart and/or eKinEnd parameters');
|
||||
end
|
||||
for ij = 1:size(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii},2)
|
||||
if isempty(DataTable(p.Results.tableSelection,:).scientaEkinRoh_eV{ii})
|
||||
[B,x1,y1] = GaussFitOnePeak([p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii}(start:stop)',...
|
||||
p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii}(start:stop,ij)]);
|
||||
else
|
||||
[B,x1,y1] = GaussFitOnePeak([DataTable(p.Results.tableSelection,:).scientaEkinRoh_eV{ii}(start:stop)',...
|
||||
p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii}(start:stop,ij)]);
|
||||
end
|
||||
|
||||
tmp_1(ij) = p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii}-B(3);
|
||||
% plot result
|
||||
if matches(p.Results.showFigures,'on')
|
||||
% define equations to be plotted
|
||||
Gauss = @(x,Hgt, Pos, Wdt) Hgt./(Wdt.*sqrt(pi/2))*exp(-2.*((x - Pos).^2/Wdt.^2));
|
||||
linear = @(x,slp,intrcpt) slp*x+intrcpt;
|
||||
figure( 'Name', 'Gauss Multi Fit ')
|
||||
tiledlayout(1,1)
|
||||
nexttile;
|
||||
%Define gauss peaks with hight, position, width from fitting results
|
||||
yData_pk1= Gauss(x1 ,B(1), B(3), B(2));
|
||||
yData_pk2= Gauss(x1 ,B(4), B(6), B(5));
|
||||
bkgrd = linear(x1,B(7),B(8));
|
||||
% plot data
|
||||
plot(x1,y1,'.')
|
||||
hold on
|
||||
% plot fit
|
||||
h = plot(x1,yData_pk1+yData_pk2+bkgrd);
|
||||
h.LineWidth=2;
|
||||
h.Color = PsiFarbe.dunkelblau;
|
||||
% plot each gauss peak
|
||||
h = plot(x1,yData_pk1+bkgrd);
|
||||
h.LineWidth=1.5;
|
||||
h.Color = PsiFarbe.gelb;
|
||||
h = plot(x1,yData_pk2+bkgrd);
|
||||
h.LineWidth=1.5;
|
||||
h.Color = PsiFarbe.gelb;
|
||||
|
||||
legend OFF
|
||||
xlabel('Kinetic Energy [eV]');
|
||||
ylabel('PE intensity [-]');
|
||||
grid on
|
||||
|
||||
% List results in table
|
||||
|
||||
disp('Results');
|
||||
disp(' ' );
|
||||
disp(cell2table({sprintf('%.1f',B(3)),...
|
||||
sprintf('%.1f',B(2)*sqrt(log(4))),...
|
||||
sprintf('%.1f',B(2)),...
|
||||
sprintf('%7.0f',B(1))},...
|
||||
'VariableNames',{'position';'FWHW';'width';'area'},...
|
||||
'RowNames',{'pk 1'}));
|
||||
end
|
||||
end
|
||||
%%
|
||||
|
||||
DataTable(p.Results.tableSelection,:).kineticEnergyShift{ii} = tmp_1-tmp_1(p.Results.kinEnReference);
|
||||
clearvars tmp_1
|
||||
fh = findobj( 'Type', 'Figure', 'Name', 'Gauss Multi Fit ');
|
||||
close(fh)
|
||||
fh = findobj( 'Type', 'Figure', 'Name', 'GlobalSearch');
|
||||
close(fh)
|
||||
end
|
||||
else
|
||||
% repeat this for all columns in input.
|
||||
for ii = 1:size(p.Results.DataTable(p.Results.tableSelection,:),1)
|
||||
%%
|
||||
try
|
||||
if isnumeric(p.Results.eKinStart)
|
||||
start = find(p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii}...
|
||||
>= p.Results.eKinStart,1);
|
||||
stop = find(p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii}...
|
||||
>= p.Results.eKinEnd,1);
|
||||
else
|
||||
start = 1;
|
||||
stop = length(p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii});
|
||||
end
|
||||
catch
|
||||
warning('There is something wrong with the eKinStart and/or eKinEnd parameters');
|
||||
disp('There is something wrong with the eKinStart and/or eKinEnd parameters');
|
||||
end
|
||||
if contains(p.Results.showFigures,'on')
|
||||
figure
|
||||
|
||||
findpeaks(movmean(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii}(start:stop),...
|
||||
p.Results.movMeanWindow),...
|
||||
p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii}(start:stop),...
|
||||
'MinPeakWidth',p.Results.minPeakWidth,'MinPeakHeight',p.Results.minPeakHeight)
|
||||
end
|
||||
[pks,locs]=findpeaks(movmean(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii}(start:stop),...
|
||||
p.Results.movMeanWindow),...
|
||||
p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii}(start:stop),...
|
||||
'MinPeakWidth',p.Results.minPeakWidth,'MinPeakHeight',p.Results.minPeakHeight);
|
||||
|
||||
%%
|
||||
|
||||
[~,I] = max(pks);
|
||||
tmp_1(ii,1) = p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii}-locs(I)-p.Results.binEnReference;
|
||||
clearvars tmp_2
|
||||
end
|
||||
|
||||
DataTable.bindingEnergyShift(p.Results.tableSelection) = tmp_1;
|
||||
end
|
||||
|
||||
end
|
||||
function [B,x1,y1] = GaussFitOnePeak(data1)
|
||||
|
||||
|
||||
[x1, y1] = prepareCurveData(data1(:,1),data1(:,2));
|
||||
|
||||
% make data slimmer so that background makes sense
|
||||
[~,I] = max(y1);
|
||||
tmp1 = find(x1>=x1(I)-5,1);
|
||||
tmp2 = find(x1>=x1(I)+5,1);
|
||||
if isempty(tmp2)
|
||||
y1 = y1(tmp1:end);
|
||||
x1 = x1(tmp1:end);
|
||||
else
|
||||
y1 = y1(tmp1:tmp2);
|
||||
x1 = x1(tmp1:tmp2);
|
||||
end
|
||||
[~,I] = max(y1);
|
||||
|
||||
% Define equation to fit data
|
||||
% I use the area Gauss equations here, which I took from the OriginPro
|
||||
% documentation. https://www.originlab.com/doc/Origin-Help/Gauss-FitFunc
|
||||
%
|
||||
% Gauss = area/(width*sqrt(pi/2)) * exp(-2*(x-position)^2/width^2)
|
||||
%
|
||||
% where FWHM = width * sqrt(ln(4))
|
||||
|
||||
% Data set 1:
|
||||
yfcn1 = @(b,x)...
|
||||
b(1)/(b(2)*sqrt(pi/2))*exp(-2.*((x(:,1) - b(3)).^2/b(2).^2)) ... % Gauss peak 1: C-H, Ac-
|
||||
+ b(4)/(b(5)*sqrt(pi/2))*exp(-2.*((x(:,1)- b(6)).^2/b(5).^2))... % Gauss peak 2: C-OOH, Ac-
|
||||
+b(7).*x(:,1)+b(8); % linear background
|
||||
|
||||
B0 = [80000 1.5 x1(I) ...
|
||||
10 1.0 x1(I)-4 ...
|
||||
0 0];
|
||||
|
||||
|
||||
% lower bonds
|
||||
lb = [1000 0.5 x1(I)-1. ...
|
||||
10 1.0 x1(I)-5 ...
|
||||
-Inf -Inf];
|
||||
|
||||
|
||||
% upper bond
|
||||
ub = [Inf 3 x1(I)+1 ...
|
||||
10 1.0 x1(I)-3 ...
|
||||
Inf Inf];
|
||||
|
||||
|
||||
% Fit equations: Gauss eq. 1 with data
|
||||
yfcn = @(b,x) yfcn1(b,x);
|
||||
% We find an optimal fit by minimising the residuals:
|
||||
fitfcnw = @(b) sum((y1 - yfcn(b,x1)).^2);
|
||||
|
||||
problem = createOptimProblem('fmincon', 'x0',B0, 'lb',lb,'ub',ub, 'objective',fitfcnw);
|
||||
gs = GlobalSearch('PlotFcns',@gsplotbestf);
|
||||
B = run(gs,problem);
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
@@ -1,522 +0,0 @@
|
||||
function DataTable = nappFitGaussXps(DataTable,~,varargin)
|
||||
%nappFitGaussXps fits PE spectra with up to 4 or 5 Gauss peaks. Different sets
|
||||
%of constrains can be used.
|
||||
%
|
||||
% FileList =
|
||||
% nappFitGaussXps(FileList,tmpFitParameters,'tableSelection',tmpDataSelection);
|
||||
%
|
||||
% *input*
|
||||
% FileList: data table tmpFitParameters: You can give settings for the 4
|
||||
% peaks (5 in some cases), use small (negligible) values if you are
|
||||
% interested in less than 4 peaks.
|
||||
%
|
||||
% % „position“ mode
|
||||
% tmpFitParameters.peakArea = [abs#1 abs#2 abs#3 abs#4];
|
||||
% tmpFitParameters.peakWidth = [abs#1 abs#2 abs#3 abs#4];
|
||||
% tmpFitParameters.peakPos = [abs#1 rel#2 rel#3 rel#4];
|
||||
%
|
||||
% tmpFitParameters.peakAreaUpperBond = [#1 #2 #3 #4];
|
||||
% tmpFitParameters.peakWidthUpperBond = [#1 #2 #3 #4];
|
||||
% tmpFitParameters.peakPosUpperBond = #1;
|
||||
% tmpFitParameters.peakAreaLowerBond = [#1 #2 #3 #4];
|
||||
% tmpFitParameters.peakWidthLowerBond = [#1 #2 #3 #4];
|
||||
% tmpFitParameters.peakPosLowerBond = #1;
|
||||
%
|
||||
%
|
||||
% % „unconstrained“ mode
|
||||
% tmpFitParameters.peakArea = [abs#1 abs#2 abs#3 abs#4];
|
||||
% tmpFitParameters.peakWidth = [abs#1 abs#2 abs#3 abs#4];
|
||||
% tmpFitParameters.peakPos = [abs#1 abs#2 abs#3 abs#4];
|
||||
%
|
||||
% tmpFitParameters.peakAreaUpperBond = [#1 #2 #3 #4];
|
||||
% tmpFitParameters.peakWidthUpperBond = [#1 #2 #3 #4];
|
||||
% tmpFitParameters.peakPosUpperBond = [#1 #2 #3 #4];
|
||||
% tmpFitParameters.peakAreaLowerBond = [#1 #2 #3 #4];
|
||||
% tmpFitParameters.peakWidthLowerBond = [#1 #2 #3 #4];
|
||||
% tmpFitParameters.peakPosLowerBond = [#1 #2 #3 #4];
|
||||
%
|
||||
%
|
||||
% % „ widthPosition“ mode
|
||||
% 1.5
|
||||
%
|
||||
% % „ width“ mode
|
||||
% tmpFitParameters.peakArea = [abs#1 abs#2 abs#3 abs#4];
|
||||
% tmpFitParameters.peakWidth = [abs#1-#4];
|
||||
% tmpFitParameters.peakPos = [abs#1 abs#2 abs#3 abs#4];
|
||||
%
|
||||
% tmpFitParameters.peakAreaUpperBond = [#1 #2 #3 #4];
|
||||
% tmpFitParameters.peakWidthUpperBond = #1-#4;
|
||||
% tmpFitParameters.peakPosUpperBond = [#1 #2 #3 #4];
|
||||
% tmpFitParameters.peakAreaLowerBond = [#1 #2 #3 #4];
|
||||
% tmpFitParameters.peakWidthLowerBond = #1-#4;
|
||||
% tmpFitParameters.peakPosLowerBond = [#1 #2 #3 #4];
|
||||
%
|
||||
%
|
||||
% % „ unconstrainedAndWidthPosition" mode (novel: rel distance fit parameter)
|
||||
% tmpFitParameters.peakArea = [abs#1 abs#2 abs#3 abs#4 abs#5];
|
||||
% tmpFitParameters.peakWidth = [abs#1,2,4,5 abs#3];
|
||||
% tmpFitParameters.peakPos = [rel#1 abs#2 abs#3 abs#4 abs#5];
|
||||
%
|
||||
% tmpFitParameters.peakAreaUpperBond = [#1 #2 #3 #4 #5];
|
||||
% tmpFitParameters.peakWidthUpperBond = [#1,2,4,5 #3];
|
||||
% tmpFitParameters.peakPosUpperBond = [#1 #2 #3 #4 #5];
|
||||
% tmpFitParameters.peakAreaLowerBond = [#1 #2 #3 #4];
|
||||
% tmpFitParameters.peakWidthLowerBond = [#1,2,4,5 #3];
|
||||
% tmpFitParameters.peakPosLowerBond = [#1 #2 #3 #4];
|
||||
%
|
||||
%
|
||||
%
|
||||
% tableSelection (optional): logical array to filter data table
|
||||
% tableVariable (optional): select source: image(default),'imageRoh'
|
||||
% mode:
|
||||
% 'unconstrained': Each gauss peak is fitted independent.
|
||||
% 'widthPosition' (Default): With of all peaks is identical. Position of peaks
|
||||
% 2-3 is set relative to peak 1.
|
||||
% 'position': Position of peaks 2-3 is set relative to peak 1.
|
||||
% 'width': all peaks have same width
|
||||
% 'unconstrainedAndWidthPosition': One unconstrained peak #3 (for gas phase
|
||||
% feature) and 4 peaks constrained in width and/or position
|
||||
% energyScale: kinetic (default) or binding
|
||||
% showFigures: on(default) or off: display Gauss fits in figure.
|
||||
%
|
||||
%
|
||||
% *output*
|
||||
% table variables peakPosition, peakFWHM, and peakArea with fit
|
||||
% results for peaks 1-4(5)
|
||||
% fit results are printed in command window and graph with fits is
|
||||
% shown.
|
||||
%
|
||||
|
||||
|
||||
|
||||
% Define conditions and defaults of input
|
||||
defaultTableVariable = 'spectrum_countsPerSecond';
|
||||
expectedTableVariable = {'spectrum_counts','spectrum_countsPerSecond','spectrum_countsNorm'};
|
||||
defaultMode = 'widthPosition';
|
||||
expectedMode = {'unconstrained','widthPosition','position','width','unconstrainedAndWidthPosition'};
|
||||
defaultTableSelection = true(size(DataTable,1),1);
|
||||
defaultShowFigures = 'on';
|
||||
expectedShowFigures = {'on','off'};
|
||||
defaultEnergyScale = 'kinetic';
|
||||
expectedEnergyScale = {'kinetic','binding'};
|
||||
|
||||
|
||||
% Parse input
|
||||
p = inputParser;
|
||||
addRequired(p,'DataTable',@istable); % TODO: allow combinedSpectrum input.
|
||||
addRequired(p,'FitParameter',@isstruct);
|
||||
addOptional(p,'tableSelection',defaultTableSelection,@islogical);
|
||||
addParameter(p,'tableVariable',defaultTableVariable,...
|
||||
@(x) any(validatestring(x,expectedTableVariable)));
|
||||
addParameter(p,'mode',defaultMode,...
|
||||
@(x) any(validatestring(x,expectedMode)));
|
||||
addParameter(p,'showFigures',defaultShowFigures,...
|
||||
@(x) any(validatestring(x,expectedShowFigures)));
|
||||
addParameter(p,'energyScale',defaultEnergyScale,...
|
||||
@(x) any(validatestring(x,expectedEnergyScale)));
|
||||
parse(p,DataTable,varargin{:});
|
||||
|
||||
if ~all(cell2mat(cellfun(@size,p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable),'UniformOutput',false)),'all')
|
||||
disp('The table variable appears to be empty. I quit now')
|
||||
error('The table variable appears to be empty.')
|
||||
end
|
||||
|
||||
% define PSI cooperate identity colours
|
||||
PsiFarbe.hellgrau = [226 226 226]/255;
|
||||
PsiFarbe.mittelgrau = [184 184 184]/255;
|
||||
PsiFarbe.dunkelgrau = [78 78 77]/255;
|
||||
PsiFarbe.blaugrau = [236 236 243]/255; % This is actually not a PSI colour
|
||||
PsiFarbe.gelb = [239 200 37]/255;
|
||||
PsiFarbe.hellorange = [227 164 31]/255;
|
||||
PsiFarbe.dunkelorange = [207 92 22]/255;
|
||||
PsiFarbe.hellrot = [164 36 23]/255;
|
||||
PsiFarbe.dunkelbraun = [114 85 65]/255;
|
||||
PsiFarbe.hellbraun = [127 119 47]/255;
|
||||
PsiFarbe.mittelgruen = [135 150 59]/255;
|
||||
PsiFarbe.hellgruen = [195 214 47]/255;
|
||||
PsiFarbe.dunkelgruen = [72 130 33]/255;
|
||||
PsiFarbe.dunkelrot = [104 47 86]/255;
|
||||
PsiFarbe.dunkelblau = [37 65 108]/255;
|
||||
PsiFarbe.mittelgruenblau = [61 164 168]/255;
|
||||
PsiFarbe.hellblau = [58 162 190]/255;
|
||||
PsiFarbe.mittelblau = [50 118 158]/255;
|
||||
|
||||
% Define equation to fit data
|
||||
% I use the area Gauss equations here, which I took from the OriginPro
|
||||
% documentation. https://www.originlab.com/doc/Origin-Help/Gauss-FitFunc
|
||||
%
|
||||
% Gauss = area/(width*sqrt(pi/2)) * exp(-2*(x-position)^2/width^2)
|
||||
%
|
||||
% where FWHM = width * sqrt(ln(4))
|
||||
|
||||
|
||||
% fitting equation
|
||||
if matches(p.Results.mode,'position')
|
||||
yfcn1 = @(tmpB,x)...
|
||||
tmpB(1)/(tmpB(2)*sqrt(pi/2))*exp(-2.*((x(:,1) - tmpB(3)).^2/tmpB(2).^2)) ... % Gauss peak 1
|
||||
+ tmpB(4)/(tmpB(5)*sqrt(pi/2))*exp(-2.*((x(:,1)- (tmpB(3)+p.Results.FitParameter.peakPos(1,2))).^2/tmpB(5).^2))... % Gauss peak 2
|
||||
+ tmpB(6)/(tmpB(7)*sqrt(pi/2))*exp(-2.*((x(:,1)- (tmpB(3)+p.Results.FitParameter.peakPos(1,3))).^2/tmpB(7).^2))... % Gauss peak 3
|
||||
+ tmpB(8)/(tmpB(9)*sqrt(pi/2))*exp(-2.*((x(:,1)- (tmpB(3)+p.Results.FitParameter.peakPos(1,4))).^2/tmpB(9).^2))... % Gauss peak 4
|
||||
+tmpB(10).*x(:,1)+tmpB(11); % linear background
|
||||
|
||||
% initial value
|
||||
B0= [p.Results.FitParameter.peakArea(1,1) p.Results.FitParameter.peakWidth(1,1) p.Results.FitParameter.peakPos(1,1)... % Gauss peak 1
|
||||
p.Results.FitParameter.peakArea(1,2) p.Results.FitParameter.peakWidth(1,2)... % Gauss peak 2
|
||||
p.Results.FitParameter.peakArea(1,3) p.Results.FitParameter.peakWidth(1,3)... % Gauss peak 3
|
||||
p.Results.FitParameter.peakArea(1,4) p.Results.FitParameter.peakWidth(1,4)... % Gauss peak 4
|
||||
0 0]; % linear background
|
||||
% lower bonds
|
||||
lb = [p.Results.FitParameter.peakAreaLowerBond(1,1) p.Results.FitParameter.peakWidthLowerBond(1,1) p.Results.FitParameter.peakPosLowerBond(1,1) ... % Gauss peak 1
|
||||
p.Results.FitParameter.peakAreaLowerBond(1,2) p.Results.FitParameter.peakWidthLowerBond(1,2) ... % Gauss peak 2
|
||||
p.Results.FitParameter.peakAreaLowerBond(1,3) p.Results.FitParameter.peakWidthLowerBond(1,3) ... % Gauss peak 3
|
||||
p.Results.FitParameter.peakAreaLowerBond(1,4) p.Results.FitParameter.peakWidthLowerBond(1,4) ... % Gauss peak 4
|
||||
0 0]; % linear background
|
||||
% upper bond
|
||||
ub = [p.Results.FitParameter.peakAreaUpperBond(1,1) p.Results.FitParameter.peakWidthUpperBond(1,1) p.Results.FitParameter.peakPosUpperBond(1,1) ... % Gauss peak 1
|
||||
p.Results.FitParameter.peakAreaUpperBond(1,2) p.Results.FitParameter.peakWidthUpperBond(1,2) ... % Gauss peak 2
|
||||
p.Results.FitParameter.peakAreaUpperBond(1,3) p.Results.FitParameter.peakWidthUpperBond(1,3) ... % Gauss peak 3
|
||||
p.Results.FitParameter.peakAreaUpperBond(1,4) p.Results.FitParameter.peakWidthUpperBond(1,4) ... % Gauss peak 4
|
||||
Inf Inf]; % linear background
|
||||
elseif matches(p.Results.mode,'unconstrained')
|
||||
yfcn1 = @(tmpB,x)...
|
||||
tmpB(1)/(tmpB(2)*sqrt(pi/2))*exp(-2.*((x(:,1) - tmpB(3)).^2/tmpB(2).^2)) ... % Gauss peak 1
|
||||
+ tmpB(4)/(tmpB(5)*sqrt(pi/2))*exp(-2.*((x(:,1)- tmpB(6)).^2/tmpB(5).^2))... % Gauss peak 2
|
||||
+ tmpB(7)/(tmpB(8)*sqrt(pi/2))*exp(-2.*((x(:,1)- tmpB(9)).^2/tmpB(8).^2))... % Gauss peak 3
|
||||
+ tmpB(10)/(tmpB(11)*sqrt(pi/2))*exp(-2.*((x(:,1)- tmpB(12)).^2/tmpB(11).^2))... % Gauss peak 4
|
||||
+tmpB(13).*x(:,1)+tmpB(14); % linear background
|
||||
|
||||
% initial value
|
||||
B0= [p.Results.FitParameter.peakArea(1,1) p.Results.FitParameter.peakWidth(1,1) p.Results.FitParameter.peakPos(1,1)... % Gauss peak 1
|
||||
p.Results.FitParameter.peakArea(1,2) p.Results.FitParameter.peakWidth(1,2) p.Results.FitParameter.peakPos(1,2)... % Gauss peak 2
|
||||
p.Results.FitParameter.peakArea(1,3) p.Results.FitParameter.peakWidth(1,3) p.Results.FitParameter.peakPos(1,3)... % Gauss peak 3
|
||||
p.Results.FitParameter.peakArea(1,4) p.Results.FitParameter.peakWidth(1,4) p.Results.FitParameter.peakPos(1,4)... % Gauss peak 4
|
||||
0 0]; % linear background
|
||||
% lower bonds
|
||||
lb = [p.Results.FitParameter.peakAreaLowerBond(1,1) p.Results.FitParameter.peakWidthLowerBond(1,1) p.Results.FitParameter.peakPosLowerBond(1,1) ... % Gauss peak 1
|
||||
p.Results.FitParameter.peakAreaLowerBond(1,2) p.Results.FitParameter.peakWidthLowerBond(1,2) p.Results.FitParameter.peakPosLowerBond(1,2)... % Gauss peak 2
|
||||
p.Results.FitParameter.peakAreaLowerBond(1,3) p.Results.FitParameter.peakWidthLowerBond(1,3) p.Results.FitParameter.peakPosLowerBond(1,3)... % Gauss peak 3
|
||||
p.Results.FitParameter.peakAreaLowerBond(1,4) p.Results.FitParameter.peakWidthLowerBond(1,4) p.Results.FitParameter.peakPosLowerBond(1,4)... % Gauss peak 4
|
||||
0 0]; % linear background
|
||||
% upper bond
|
||||
ub = [p.Results.FitParameter.peakAreaUpperBond(1,1) p.Results.FitParameter.peakWidthUpperBond(1,1) p.Results.FitParameter.peakPosUpperBond(1,1) ... % Gauss peak 1
|
||||
p.Results.FitParameter.peakAreaUpperBond(1,2) p.Results.FitParameter.peakWidthUpperBond(1,2) p.Results.FitParameter.peakPosUpperBond(1,2)... % Gauss peak 2
|
||||
p.Results.FitParameter.peakAreaUpperBond(1,3) p.Results.FitParameter.peakWidthUpperBond(1,3) p.Results.FitParameter.peakPosUpperBond(1,3)... % Gauss peak 3
|
||||
p.Results.FitParameter.peakAreaUpperBond(1,4) p.Results.FitParameter.peakWidthUpperBond(1,4) p.Results.FitParameter.peakPosUpperBond(1,4)... % Gauss peak 4
|
||||
Inf Inf]; % linear background
|
||||
elseif matches(p.Results.mode,'widthPosition')
|
||||
yfcn1 = @(tmpB,x)...
|
||||
tmpB(1)/(tmpB(2)*sqrt(pi/2))*exp(-2.*((x(:,1) - tmpB(3)).^2/tmpB(2).^2)) ... % Gauss peak 1
|
||||
+ tmpB(4)/(tmpB(2)*sqrt(pi/2))*exp(-2.*((x(:,1)- (tmpB(3)+p.Results.FitParameter.peakPos(1,2))).^2/tmpB(2).^2))... % Gauss peak 2
|
||||
+ tmpB(5)/(tmpB(2)*sqrt(pi/2))*exp(-2.*((x(:,1)- (tmpB(3)+p.Results.FitParameter.peakPos(1,3))).^2/tmpB(2).^2))... % Gauss peak 3
|
||||
+ tmpB(6)/(tmpB(2)*sqrt(pi/2))*exp(-2.*((x(:,1)- (tmpB(3)+p.Results.FitParameter.peakPos(1,4))).^2/tmpB(2).^2))... % Gauss peak 4
|
||||
+tmpB(7).*x(:,1)+tmpB(8); % linear background
|
||||
|
||||
% initial value
|
||||
B0= [p.Results.FitParameter.peakArea(1,1) p.Results.FitParameter.peakWidth(1,1) p.Results.FitParameter.peakPos(1,1)... % Gauss peak 1
|
||||
p.Results.FitParameter.peakArea(1,2) ... % Gauss peak 2
|
||||
p.Results.FitParameter.peakArea(1,3) ... % Gauss peak 3
|
||||
p.Results.FitParameter.peakArea(1,4)... % Gauss peak 4
|
||||
0 0]; % linear background
|
||||
% lower bonds
|
||||
lb = [p.Results.FitParameter.peakAreaLowerBond(1,1) p.Results.FitParameter.peakWidthLowerBond(1,1) p.Results.FitParameter.peakPosLowerBond(1,1) ... % Gauss peak 1
|
||||
p.Results.FitParameter.peakAreaLowerBond(1,2) ... % Gauss peak 2
|
||||
p.Results.FitParameter.peakAreaLowerBond(1,3) ... % Gauss peak 3
|
||||
p.Results.FitParameter.peakAreaLowerBond(1,4) ... % Gauss peak 4
|
||||
0 0]; % linear background
|
||||
% upper bond
|
||||
ub = [p.Results.FitParameter.peakAreaUpperBond(1,1) p.Results.FitParameter.peakWidthUpperBond(1,1) p.Results.FitParameter.peakPosUpperBond(1,1) ... % Gauss peak 1
|
||||
p.Results.FitParameter.peakAreaUpperBond(1,2) ... % Gauss peak 2
|
||||
p.Results.FitParameter.peakAreaUpperBond(1,3) ... % Gauss peak 3
|
||||
p.Results.FitParameter.peakAreaUpperBond(1,4) ... % Gauss peak 4
|
||||
Inf Inf]; % linear background
|
||||
elseif matches(p.Results.mode,'width')
|
||||
yfcn1 = @(tmpB,x)...
|
||||
tmpB(1)/(tmpB(2)*sqrt(pi/2))*exp(-2.*((x(:,1) - tmpB(3)).^2/tmpB(2).^2)) ... % Gauss peak 1
|
||||
+ tmpB(4)/(tmpB(2)*sqrt(pi/2))*exp(-2.*((x(:,1)- tmpB(5)).^2/tmpB(2).^2))... % Gauss peak 2
|
||||
+ tmpB(6)/(tmpB(2)*sqrt(pi/2))*exp(-2.*((x(:,1)- tmpB(7)).^2/tmpB(2).^2))... % Gauss peak 3
|
||||
+ tmpB(8)/(tmpB(2)*sqrt(pi/2))*exp(-2.*((x(:,1)- tmpB(9)).^2/tmpB(2).^2))... % Gauss peak 4
|
||||
+tmpB(10).*x(:,1)+tmpB(11); % linear background
|
||||
|
||||
% initial value
|
||||
B0= [p.Results.FitParameter.peakArea(1,1) p.Results.FitParameter.peakWidth(1,1) p.Results.FitParameter.peakPos(1,1)... % Gauss peak 1
|
||||
p.Results.FitParameter.peakArea(1,2) p.Results.FitParameter.peakPos(1,2)... % Gauss peak 2
|
||||
p.Results.FitParameter.peakArea(1,3) p.Results.FitParameter.peakPos(1,3)... % Gauss peak 3
|
||||
p.Results.FitParameter.peakArea(1,4) p.Results.FitParameter.peakPos(1,4)... % Gauss peak 4
|
||||
0 0]; % linear background
|
||||
% lower bonds
|
||||
lb = [p.Results.FitParameter.peakAreaLowerBond(1,1) p.Results.FitParameter.peakWidthLowerBond(1,1) p.Results.FitParameter.peakPosLowerBond(1,1) ... % Gauss peak 1
|
||||
p.Results.FitParameter.peakAreaLowerBond(1,2) p.Results.FitParameter.peakWidthLowerBond(1,2) ... % Gauss peak 2
|
||||
p.Results.FitParameter.peakAreaLowerBond(1,3) p.Results.FitParameter.peakWidthLowerBond(1,3) ... % Gauss peak 3
|
||||
p.Results.FitParameter.peakAreaLowerBond(1,4) p.Results.FitParameter.peakWidthLowerBond(1,4) ... % Gauss peak 4
|
||||
0 0]; % linear background
|
||||
% upper bond
|
||||
ub = [p.Results.FitParameter.peakAreaUpperBond(1,1) p.Results.FitParameter.peakWidthUpperBond(1,1) p.Results.FitParameter.peakPosUpperBond(1,1) ... % Gauss peak 1
|
||||
p.Results.FitParameter.peakAreaUpperBond(1,2) p.Results.FitParameter.peakWidthUpperBond(1,2) ... % Gauss peak 2
|
||||
p.Results.FitParameter.peakAreaUpperBond(1,3) p.Results.FitParameter.peakWidthUpperBond(1,3) ... % Gauss peak 3
|
||||
p.Results.FitParameter.peakAreaUpperBond(1,4) p.Results.FitParameter.peakWidthUpperBond(1,4) ... % Gauss peak 4
|
||||
Inf Inf]; % linear background
|
||||
|
||||
elseif matches(p.Results.mode,'unconstrainedAndWidthPosition') % Novum, also the distance between peaks is a fit parameter. [Gauss = area/(width*sqrt(pi/2)) * exp(-2*(x-position)^2/width^2)]
|
||||
yfcn1 = @(tmpB,x)...
|
||||
tmpB(1)/(tmpB(2)*sqrt(pi/2))*exp(-2.*((x(:,1) - (tmpB(3)+tmpB(14))).^2/tmpB(2).^2)) ... % Gauss peak 1: width and position
|
||||
+ tmpB(4)/(tmpB(2)*sqrt(pi/2))*exp(-2.*((x(:,1) - tmpB(3)).^2/tmpB(2).^2))... % Gauss peak 2: width and position
|
||||
+ tmpB(5)/(tmpB(6)*sqrt(pi/2))*exp(-2.*((x(:,1) - tmpB(7)).^2/tmpB(6).^2))... % Gauss peak 3: unconstrained
|
||||
+ tmpB(8)/(tmpB(2)*sqrt(pi/2))*exp(-2.*((x(:,1) - tmpB(9)).^2/tmpB(2).^2))... % Gauss peak 4: width
|
||||
+ tmpB(10)/(tmpB(2)*sqrt(pi/2))*exp(-2.*((x(:,1)- tmpB(11)).^2/tmpB(2).^2))... % Gauss peak 5: width
|
||||
+ tmpB(12).*x(:,1)+tmpB(13); % linear background
|
||||
|
||||
% initial value
|
||||
B0= [p.Results.FitParameter.peakArea(1,1) p.Results.FitParameter.peakWidth(1,1) p.Results.FitParameter.peakPos(1,2)... % Gauss peak 1
|
||||
p.Results.FitParameter.peakArea(1,2) ... % Gauss peak 2
|
||||
p.Results.FitParameter.peakArea(1,3) p.Results.FitParameter.peakWidth(1,2) p.Results.FitParameter.peakPos(1,3)... % Gauss peak 3
|
||||
p.Results.FitParameter.peakArea(1,4) p.Results.FitParameter.peakPos(1,4)... % Gauss peak 4
|
||||
p.Results.FitParameter.peakArea(1,5) p.Results.FitParameter.peakPos(1,5)... % Gauss peak 5
|
||||
0 0 ... % linear background
|
||||
p.Results.FitParameter.peakPos(1,1)];
|
||||
% lower bonds
|
||||
lb = [p.Results.FitParameter.peakAreaLowerBond(1,1) p.Results.FitParameter.peakWidthLowerBond(1,1) p.Results.FitParameter.peakPosLowerBond(1,2) ... % Gauss peak 1
|
||||
p.Results.FitParameter.peakAreaLowerBond(1,2) ... % Gauss peak 2
|
||||
p.Results.FitParameter.peakAreaLowerBond(1,3) p.Results.FitParameter.peakWidthLowerBond(1,2) p.Results.FitParameter.peakPosLowerBond(1,3) ... % Gauss peak 3
|
||||
p.Results.FitParameter.peakAreaLowerBond(1,4) p.Results.FitParameter.peakPosLowerBond(1,4) ...
|
||||
p.Results.FitParameter.peakAreaLowerBond(1,5) p.Results.FitParameter.peakPosLowerBond(1,5) ...% Gauss peak 4
|
||||
0 0 ... % linear background
|
||||
p.Results.FitParameter.peakPosLowerBond(1,1)];
|
||||
|
||||
% upper bond
|
||||
ub = [p.Results.FitParameter.peakAreaUpperBond(1,1) p.Results.FitParameter.peakWidthUpperBond(1,1) p.Results.FitParameter.peakPosUpperBond(1,2) ... % Gauss peak 1
|
||||
p.Results.FitParameter.peakAreaUpperBond(1,2) ... % Gauss peak 2
|
||||
p.Results.FitParameter.peakAreaUpperBond(1,3) p.Results.FitParameter.peakWidthUpperBond(1,2) p.Results.FitParameter.peakPosUpperBond(1,3) ... % Gauss peak 3
|
||||
p.Results.FitParameter.peakAreaUpperBond(1,4) p.Results.FitParameter.peakPosUpperBond(1,4) ...
|
||||
p.Results.FitParameter.peakAreaUpperBond(1,5) p.Results.FitParameter.peakPosUpperBond(1,5) ... % Gauss peak 4
|
||||
Inf Inf ... % linear background
|
||||
p.Results.FitParameter.peakPosUpperBond(1,1)]; % shift upper bond
|
||||
end
|
||||
|
||||
for ii = 1:size(p.Results.DataTable(p.Results.tableSelection,:),1)
|
||||
if contains(p.Results.energyScale,'kinetic')
|
||||
[x1, y1] = prepareCurveData(p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii},...
|
||||
p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii});
|
||||
% make data slimmer so that background fit improved
|
||||
if p.Results.FitParameter.peakPos(1,1) >= 10
|
||||
tmp1 = find(x1>=p.Results.FitParameter.peakPos(1,1)-p.Results.FitParameter.backgroundRange(1,1),1);
|
||||
tmp2 = find(x1>=p.Results.FitParameter.peakPos(1,1)+p.Results.FitParameter.backgroundRange(1,2),1);
|
||||
else
|
||||
tmp1 = find(x1>=p.Results.FitParameter.peakPos(1,2)-p.Results.FitParameter.backgroundRange(1,1),1);
|
||||
tmp2 = find(x1>=p.Results.FitParameter.peakPos(1,2)+p.Results.FitParameter.backgroundRange(1,2),1);
|
||||
end
|
||||
if isempty(tmp2)
|
||||
y1 = y1(tmp1:end);
|
||||
x1 = x1(tmp1:end);
|
||||
else
|
||||
y1 = y1(tmp1:tmp2);
|
||||
x1 = x1(tmp1:tmp2);
|
||||
end
|
||||
% Fit equations: Gauss eq. 1 with data
|
||||
yfcn = @(tmpB,x) yfcn1(tmpB,x);
|
||||
% We find an optimal fit by minimising the residuals:
|
||||
fitfcnw = @(tmpB) sum((y1 - yfcn(tmpB,x1)).^2);
|
||||
problem = createOptimProblem('fmincon', 'x0',B0, 'lb',lb,'ub',ub, 'objective',fitfcnw);
|
||||
gs = GlobalSearch('PlotFcns',@gsplotbestf);
|
||||
tmpB = run(gs,problem);
|
||||
elseif contains(p.Results.energyScale,'binding')
|
||||
[x1, y1] = prepareCurveData(p.Results.DataTable(p.Results.tableSelection,:).bindingEnergy_eV{ii},...
|
||||
p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii});
|
||||
% make data slimmer so that background fit improves
|
||||
if p.Results.FitParameter.peakPos(1,1) >= 10
|
||||
tmp2 = find(x1<=p.Results.FitParameter.peakPos(1,1)-p.Results.FitParameter.backgroundRange(1,1),1);
|
||||
tmp1 = find(x1<=p.Results.FitParameter.peakPos(1,1)+p.Results.FitParameter.backgroundRange(1,2),1);
|
||||
else
|
||||
tmp2 = find(x1<=p.Results.FitParameter.peakPos(1,2)-p.Results.FitParameter.backgroundRange(1,1),1);
|
||||
tmp1 = find(x1<=p.Results.FitParameter.peakPos(1,2)+p.Results.FitParameter.backgroundRange(1,2),1);
|
||||
end
|
||||
if isempty(tmp2)
|
||||
y1 = y1(tmp1:end);
|
||||
x1 = x1(tmp1:end);
|
||||
else
|
||||
y1 = y1(tmp1:tmp2);
|
||||
x1 = x1(tmp1:tmp2);
|
||||
end
|
||||
% Fit equations: Gauss eq. 1 with data
|
||||
yfcn = @(tmpB,x) yfcn1(tmpB,x);
|
||||
% We find an optimal fit by minimising the residuals:
|
||||
fitfcnw = @(tmpB) sum((y1 - yfcn(tmpB,x1)).^2);
|
||||
problem = createOptimProblem('fmincon', 'x0',B0, 'lb',lb,'ub',ub, 'objective',fitfcnw);
|
||||
gs = GlobalSearch('PlotFcns',@gsplotbestf);
|
||||
tmpB = run(gs,problem);
|
||||
end
|
||||
% compile results into variable B with same dimension for all
|
||||
% fit-types (Area Width Position):
|
||||
if matches(p.Results.mode,'position')
|
||||
B = [tmpB(1) tmpB(2) tmpB(3)...
|
||||
tmpB(4) tmpB(5) tmpB(3)+p.Results.FitParameter.peakPos(1,2) ...
|
||||
tmpB(6) tmpB(7) tmpB(3)+p.Results.FitParameter.peakPos(1,3)...
|
||||
tmpB(8) tmpB(9) tmpB(3)+p.Results.FitParameter.peakPos(1,4)...
|
||||
tmpB(10) tmpB(11)...
|
||||
NaN NaN NaN];
|
||||
elseif matches(p.Results.mode,'unconstrained')
|
||||
B = [tmpB(1) tmpB(2) tmpB(3)...
|
||||
tmpB(4) tmpB(5) tmpB(6) ...
|
||||
tmpB(7) tmpB(8) tmpB(9) ...
|
||||
tmpB(10) tmpB(11) tmpB(12) ...
|
||||
tmpB(13) tmpB(14)...
|
||||
NaN NaN NaN];
|
||||
elseif matches(p.Results.mode,'widthPosition')
|
||||
B = [tmpB(1) tmpB(2) tmpB(3)...
|
||||
tmpB(4) tmpB(2) tmpB(3)+p.Results.FitParameter.peakPos(1,2)...
|
||||
tmpB(5) tmpB(2) tmpB(3)+p.Results.FitParameter.peakPos(1,3)...
|
||||
tmpB(6) tmpB(2) tmpB(3)+p.Results.FitParameter.peakPos(1,4)...
|
||||
tmpB(7) tmpB(8)...
|
||||
NaN NaN NaN];
|
||||
elseif matches(p.Results.mode,'width')
|
||||
B = [tmpB(1) tmpB(2) tmpB(3)...
|
||||
tmpB(4) tmpB(2) tmpB(5)...
|
||||
tmpB(6) tmpB(2) tmpB(8)...
|
||||
tmpB(9) tmpB(2) tmpB(10)...
|
||||
tmpB(11) tmpB(12)...
|
||||
NaN NaN NaN];
|
||||
elseif matches(p.Results.mode,'unconstrainedAndWidthPosition')
|
||||
B = [tmpB(1) tmpB(2) tmpB(3)+tmpB(14)...
|
||||
tmpB(4) tmpB(2) tmpB(3)...
|
||||
tmpB(5) tmpB(6) tmpB(7)...
|
||||
tmpB(8) tmpB(2) tmpB(9)...
|
||||
tmpB(12) tmpB(13) ...
|
||||
tmpB(10) tmpB(2) tmpB(11)];
|
||||
end
|
||||
|
||||
% print out result table and result plots based on B. Because B has the
|
||||
% same structure for all fit types, the same code for printing and
|
||||
% plotting can be used for all fit types.
|
||||
|
||||
if matches(p.Results.showFigures,'on')
|
||||
% Display results in table
|
||||
disp(' ' );
|
||||
disp(' ' );
|
||||
disp('Fit results')
|
||||
disp(p.Results.DataTable(p.Results.tableSelection,:).name{ii});
|
||||
disp(' ' );
|
||||
disp(cell2table({sprintf('%.1f',B(3)),...
|
||||
sprintf('%.1f',B(2)*sqrt(log(4))),...
|
||||
sprintf('%.1f',B(2)),...
|
||||
sprintf('%7.0f',B(1));...
|
||||
sprintf('%.1f',B(6)),...
|
||||
sprintf('%.1f',B(5)*sqrt(log(4))),...
|
||||
sprintf('%.1f',B(5)),...
|
||||
sprintf('%7.0f',B(4));...
|
||||
sprintf('%.1f',B(9)),...
|
||||
sprintf('%.1f',B(8)*sqrt(log(4))),...
|
||||
sprintf('%.1f',B(8)),...
|
||||
sprintf('%7.0f',B(7));...
|
||||
sprintf('%.1f',B(12)),...
|
||||
sprintf('%.1f',B(11)*sqrt(log(4))),...
|
||||
sprintf('%.1f',B(11)),...
|
||||
sprintf('%7.0f',B(10)); ...
|
||||
sprintf('%.1f',B(17)),...
|
||||
sprintf('%.1f',B(16)*sqrt(log(4))),...
|
||||
sprintf('%.1f',B(16)),...
|
||||
sprintf('%7.0f',B(15))},...
|
||||
'VariableNames',{'position';'FWHW';'width';'area'},...
|
||||
'RowNames',{'peak1','peak2','peak3','peak4','peak5'})); % 'RowNames',{'peak1','peak2','peak3','peak4','peak5'}));
|
||||
|
||||
% plot result
|
||||
% eliminate NaN in B
|
||||
B(isnan(B))=0.01;
|
||||
% define equations to be plotted
|
||||
Gauss = @(x, A, Pos, Wdt) A./(Wdt.*sqrt(pi/2))*exp(-2.*((x - Pos).^2/Wdt.^2));
|
||||
linear = @(x,slp,intrcpt) slp*x+intrcpt;
|
||||
figure( 'Name', 'Gauss Multi Fit ')
|
||||
tiledlayout(1,1)
|
||||
ax(1) = nexttile;
|
||||
% define high-resolution x for plotting
|
||||
if x1(1)<= x1(end)
|
||||
xGaussPlot = x1(1):0.01:x1(end);
|
||||
else
|
||||
xGaussPlot = x1(1):-0.01:x1(end);
|
||||
end
|
||||
|
||||
%Define gauss peaks
|
||||
yData_pk1= Gauss(xGaussPlot ,B(1), B(3), B(2));
|
||||
yData_pk2= Gauss(xGaussPlot ,B(4), B(6), B(5));
|
||||
yData_pk3= Gauss(xGaussPlot ,B(7), B(9), B(8));
|
||||
yData_pk4= Gauss(xGaussPlot ,B(10), B(12), B(11));
|
||||
yData_pk5= Gauss(xGaussPlot ,B(15), B(17), B(16));
|
||||
bkgrd = linear(xGaussPlot,B(13),B(14));
|
||||
% plot data
|
||||
plot(x1,y1,'.')
|
||||
hold on
|
||||
% plot fit
|
||||
h = plot(xGaussPlot,yData_pk1+yData_pk2+yData_pk3+yData_pk4+yData_pk5+bkgrd);
|
||||
h.LineWidth=2;
|
||||
h.Color = PsiFarbe.dunkelblau;
|
||||
% plot each gauss peak
|
||||
h = plot(xGaussPlot,yData_pk1+bkgrd);
|
||||
h.LineWidth=1.5;
|
||||
h.Color = PsiFarbe.gelb;
|
||||
h = plot(xGaussPlot,yData_pk2+bkgrd);
|
||||
h.LineWidth=1.5;
|
||||
h.Color = PsiFarbe.gelb;
|
||||
h = plot(xGaussPlot,yData_pk3+bkgrd);
|
||||
h.LineWidth=1.5;
|
||||
h.Color = PsiFarbe.gelb;
|
||||
h = plot(xGaussPlot,yData_pk4+bkgrd);
|
||||
h.LineWidth=1.5;
|
||||
h.Color = PsiFarbe.gelb;
|
||||
h = plot(xGaussPlot,yData_pk5+bkgrd);
|
||||
h.LineWidth=1.5;
|
||||
h.Color = PsiFarbe.gelb;
|
||||
plot(xGaussPlot, bkgrd);
|
||||
set(ax(1),'Xdir','reverse');
|
||||
legend OFF
|
||||
xlabel('Binding Energy [eV]');
|
||||
ylabel('PE intensity [-]');
|
||||
grid on
|
||||
end
|
||||
% Write results to List, we need all fitting results
|
||||
resultsPeakPos(ii,:) = [B(3), B(6), B(9), B(12), B(16)] ; %#ok<*AGROW>
|
||||
resultsPeakFWHW(ii,:) = [B(2).*sqrt(log(4)), B(5).*sqrt(log(4)), B(8).*sqrt(log(4)), B(11).*sqrt(log(4)), B(17).*sqrt(log(4))] ;
|
||||
resultsPeakArea(ii,:) = [B(1), B(4), B(7), B(10) B(15)] ;
|
||||
% resultsBkgrd(ii,:) = [B(13), B(14)] ;
|
||||
end
|
||||
|
||||
|
||||
% write results to data table
|
||||
try
|
||||
existColumn = strcmp('peakPosition',p.Results.DataTable.Properties.VariableNames);
|
||||
if ~any(existColumn)
|
||||
DataTable.peakPosition = NaN(size(p.Results.DataTable,1),size(resultsPeakPos,2));
|
||||
end
|
||||
existColumn = strcmp('peakArea',p.Results.DataTable.Properties.VariableNames);
|
||||
if ~any(existColumn)
|
||||
DataTable.peakArea = NaN(size(p.Results.DataTable,1),size(resultsPeakArea,2));
|
||||
end
|
||||
existColumn = strcmp('peakFWHM',p.Results.DataTable.Properties.VariableNames);
|
||||
if ~any(existColumn)
|
||||
DataTable.peakFWHM = NaN(size(p.Results.DataTable,1),size(resultsPeakFWHW,2));
|
||||
end
|
||||
%if contains(p.Results.energyScale,'binding')
|
||||
DataTable(p.Results.tableSelection,:).peakPosition = resultsPeakPos(:,:);
|
||||
%end
|
||||
DataTable(p.Results.tableSelection,:).peakFWHM = resultsPeakFWHW(:,:);
|
||||
DataTable(p.Results.tableSelection,:).peakArea = resultsPeakArea(:,:);
|
||||
catch
|
||||
disp('Could not write results to table. Writing only 4 entries')
|
||||
existColumn = strcmp('peakPosition',p.Results.DataTable.Properties.VariableNames);
|
||||
if ~any(existColumn)
|
||||
DataTable.peakPosition = NaN(size(p.Results.DataTable,1),size(resultsPeakPos,2));
|
||||
end
|
||||
existColumn = strcmp('peakArea',p.Results.DataTable.Properties.VariableNames);
|
||||
if ~any(existColumn)
|
||||
DataTable.peakArea = NaN(size(p.Results.DataTable,1),size(resultsPeakArea,2));
|
||||
end
|
||||
existColumn = strcmp('peakFWHM',p.Results.DataTable.Properties.VariableNames);
|
||||
if ~any(existColumn)
|
||||
DataTable.peakFWHM = NaN(size(p.Results.DataTable,1),size(resultsPeakFWHW,2));
|
||||
end
|
||||
%if contains(p.Results.energyScale,'binding')
|
||||
DataTable(p.Results.tableSelection,:).peakPosition = resultsPeakPos(:,1:4);
|
||||
%end
|
||||
DataTable(p.Results.tableSelection,:).peakFWHM = resultsPeakFWHW(:,1:4);
|
||||
DataTable(p.Results.tableSelection,:).peakArea = resultsPeakArea(:,1:4);
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
@@ -1,126 +0,0 @@
|
||||
function DataTable = nappGenerateSpectra(DataTable,varargin)
|
||||
%nappGenerateSpectra reduces the dimension of images to generate spectra
|
||||
%
|
||||
% nappGenerateSpectra(FileList,tmpDataSelection)
|
||||
%
|
||||
% *input*
|
||||
% FileList: data table
|
||||
% tableSelection (optional): logical array to filter data table
|
||||
% tableVariable (optional): select source: image(default),'imageRoh'
|
||||
% mode: mean (default) averages the sequence iterations; sum adds them
|
||||
%
|
||||
% *output*
|
||||
% with mode mean the spectrum will be saved in the table variable spectrum_countsPerSecond
|
||||
% with mode sum the spectrum will be saved in the table variable spectrum_counts
|
||||
%
|
||||
% FIXME: spectrum_counts is not implemented yet.
|
||||
|
||||
% Define conditions and defaults of input
|
||||
defaultTableVariable = 'image';
|
||||
expectedTableVariable = {'image','imageRoh'};
|
||||
defaultMode = 'mean';
|
||||
expectedMode = {'mean','sum','trapz'};
|
||||
defaultEkinStart = 0;
|
||||
defaultEkinEnd = 0;
|
||||
defaultTableSelection = true(size(DataTable,1));
|
||||
|
||||
% Parse input
|
||||
p = inputParser;
|
||||
addRequired(p,'DataTable',@istable);
|
||||
addOptional(p,'tableSelection',defaultTableSelection,@islogical);
|
||||
addParameter(p,'tableVariable',defaultTableVariable,...
|
||||
@(x) any(validatestring(x,expectedTableVariable)));
|
||||
addParameter(p,'mode',defaultMode,...
|
||||
@(x) any(validatestring(x,expectedMode)));
|
||||
addParameter(p,'iterationRange',[0:0]);
|
||||
addParameter(p,'eKinStart',defaultEkinStart,@isnumeric)
|
||||
addParameter(p,'eKinEnd',defaultEkinEnd,@isnumeric)
|
||||
parse(p,DataTable,varargin{:});
|
||||
|
||||
% add empty variable to table
|
||||
existColumn = strcmp('spectrum_countsPerSecond',p.Results.DataTable.Properties.VariableNames);
|
||||
if ~any(existColumn)
|
||||
DataTable.spectrum_countsPerSecond = cell(size(p.Results.DataTable,1),1);
|
||||
end
|
||||
existColumn = strcmp('spectrum_counts',p.Results.DataTable.Properties.VariableNames);
|
||||
if ~any(existColumn)
|
||||
DataTable.spectrum_counts = cell(size(p.Results.DataTable,1),1);
|
||||
end
|
||||
existColumn = strcmp('logGenerateRange',p.Results.DataTable.Properties.VariableNames);
|
||||
if ~any(existColumn)
|
||||
DataTable.logGenerateRange = NaN(size(p.Results.DataTable,1),2);
|
||||
end
|
||||
existColumn = strcmp('logGenerateDate',p.Results.DataTable.Properties.VariableNames);
|
||||
if ~any(existColumn)
|
||||
DataTable.logGenerateDate = cellstr(repmat(' ',size(p.Results.DataTable,1),1));
|
||||
end
|
||||
existColumn = strcmp('logGenerateMode',p.Results.DataTable.Properties.VariableNames);
|
||||
if ~any(existColumn)
|
||||
DataTable.logGenerateDate = cellstr(repmat(' ',size(p.Results.DataTable,1),1));
|
||||
end
|
||||
|
||||
% check input (all elements of input variable need to have non-zero size)
|
||||
if ~all(cell2mat(cellfun(@size,p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable),'UniformOutput',false)),'all')
|
||||
disp('The table variable appears to be empty. I quit now')
|
||||
error('The table variable appears to be empty.')
|
||||
end
|
||||
|
||||
% create empty variables
|
||||
tmp_3 = cell(size(p.Results.DataTable(p.Results.tableSelection,:),1),1);
|
||||
tmp_6 = cell(size(p.Results.DataTable(p.Results.tableSelection,:),1),1);
|
||||
tmp_4 = NaN(size(p.Results.DataTable(p.Results.tableSelection,:),1),1);
|
||||
tmp_5 = NaN(size(p.Results.DataTable(p.Results.tableSelection,:),1),1);
|
||||
% repeat this for all columns in input.
|
||||
for ii = 1:size(p.Results.DataTable(p.Results.tableSelection,:),1)
|
||||
if endsWith(p.Results.DataTable(p.Results.tableSelection,:).name{ii},'h5') % let's do NEXAFS first.
|
||||
% Get index of EkinStart and EkinEnd
|
||||
if (p.Results.eKinStart) == 0
|
||||
tmp_1 = 1;
|
||||
else
|
||||
tmp_1 = find(p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii} >= p.Results.eKinStart,1);
|
||||
end
|
||||
if (p.Results.eKinEnd) == 0
|
||||
tmp_2 = length(p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii});
|
||||
else
|
||||
tmp_2 = find(p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii} >= p.Results.eKinEnd,1);
|
||||
end
|
||||
|
||||
if contains(p.Results.mode,'trapz')
|
||||
tmp_3(ii,1)= {trapz(p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii}(tmp_1:tmp_2),...
|
||||
p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii}(tmp_1:tmp_2,:))'};
|
||||
elseif (contains(p.Results.mode,'sum') | contains(p.Results.mode,'mean'))
|
||||
|
||||
tmp_3(ii,1) = {sum(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii}(tmp_1:tmp_2,:),1)'}; %#ok<*AGROW>
|
||||
end
|
||||
% log
|
||||
tmp_4(ii,1) = p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii}(tmp_1);
|
||||
tmp_5(ii,1) = p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii}(tmp_2);
|
||||
elseif endsWith(p.Results.DataTable(p.Results.tableSelection,:).name{ii},'ibw') % then do Igorfiles
|
||||
if p.Results.iterationRange(1) == 0
|
||||
startRange = 1;
|
||||
endRange = size(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii},2);
|
||||
else
|
||||
startRange = p.Results.iterationRange(1);
|
||||
endRange = p.Results.iterationRange(2);
|
||||
end
|
||||
|
||||
if (contains(p.Results.mode,'mean') | contains(p.Results.mode,'trapz'))
|
||||
tmp_6(ii,1)= {mean(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii}(:,startRange:endRange),2)};
|
||||
elseif contains(p.Results.mode,'sum')
|
||||
tmp_3(ii,1) = {sum(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii}(:,startRange:endRange),2)}; %#ok<*AGROW>
|
||||
end
|
||||
% log
|
||||
tmp_4(ii,1) = startRange;
|
||||
tmp_5(ii,1) = endRange;
|
||||
end
|
||||
end
|
||||
|
||||
% write results to table
|
||||
DataTable.spectrum_counts(p.Results.tableSelection) = tmp_3;
|
||||
DataTable.spectrum_countsPerSecond(p.Results.tableSelection) = tmp_6;
|
||||
% write log to table
|
||||
DataTable.logGenerateMode(p.Results.tableSelection,:) = cellstr(repmat(p.Results.mode,size(p.Results.DataTable(p.Results.tableSelection,:),1),1));
|
||||
DataTable.logGenerateRange(p.Results.tableSelection,:) = [tmp_4 tmp_5];
|
||||
DataTable.logGenerateDate(p.Results.tableSelection,:) = cellstr(repmat(datestr(now),size(p.Results.DataTable(p.Results.tableSelection,:),1),1));
|
||||
|
||||
end
|
||||
@@ -1,58 +0,0 @@
|
||||
function nappImage(DataTable,varargin)
|
||||
%
|
||||
% h_img = Napp_plotImage(StructArrayData) plots an image of the
|
||||
% NEXAFS data set in the NEXAFS data structure.
|
||||
%
|
||||
% Output: an image figure, with a handle. The handle is important to
|
||||
% select these images for XPS removal
|
||||
|
||||
% Define conditions and defaults of input
|
||||
defaultTableVariable = {'image'};
|
||||
expectedTableVariable = {'image','imageRoh'};
|
||||
defaultTableSelection = true(size(DataTable,1));
|
||||
|
||||
|
||||
% Parse input
|
||||
p = inputParser;
|
||||
addRequired(p,'DataTable',@istable);
|
||||
addOptional(p,'tableSelection',defaultTableSelection,@islogical);
|
||||
addParameter(p,'tableVariable',defaultTableVariable,...
|
||||
@(x) any(validatestring(x,expectedTableVariable)));
|
||||
parse(p,DataTable,varargin{:});
|
||||
|
||||
% check input (all elements of input variable need to have non-zero size)
|
||||
if ~all(cell2mat(cellfun(@size,p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable),'UniformOutput',false)),'all')
|
||||
disp('The table variable appears to be empty. I quit now')
|
||||
error('The table variable appears to be empty.')
|
||||
end
|
||||
|
||||
for ii = 1:size(p.Results.DataTable(p.Results.tableSelection,:),1)
|
||||
figure('Name',p.Results.DataTable(p.Results.tableSelection,:).name{ii});
|
||||
|
||||
% Create axes
|
||||
hold(gca,'on');
|
||||
% Try to plot image with x and y
|
||||
try
|
||||
image(p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii},p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii},...
|
||||
p.Results.DataTable.(p.Results.DataFieldname){ii},'Parent',gca,'CDataMapping','scaled');
|
||||
axis(gca,'ij');
|
||||
set(gca,'Layer','top');
|
||||
xlim([p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii}(1) p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii}(end)]);
|
||||
ylim([p.Results.DataTable(p.Results.tableSelection,:).scientaEkinMin_eV(ii) p.Results.DataTable(p.Results.tableSelection,:).scientaEkinMax_eV(ii)]);
|
||||
xlabel('Photon energy [eV]')
|
||||
ylabel('Auger energy [eV]')
|
||||
% if this does not work, plot without scaling (just with row and column numbers)
|
||||
catch
|
||||
image(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii},'Parent',gca,'CDataMapping','scaled');
|
||||
axis(gca,'ij');
|
||||
set(gca,'Layer','top');
|
||||
ylim([1 size(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii},1)]);
|
||||
xlim([1 size(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii},2)]);
|
||||
xlabel('# Photon energy, column number')
|
||||
ylabel('# Auger energy, column number')
|
||||
end
|
||||
|
||||
box(gca,'on');
|
||||
title(p.Results.DataTable(p.Results.tableSelection,:).name{ii},'Interpreter','none')
|
||||
end
|
||||
end
|
||||
@@ -1,551 +0,0 @@
|
||||
function hdl = nappPlot(DataTable,varargin)
|
||||
%nappPlot is the one-and-only function to plot PE spectra and images.
|
||||
%
|
||||
% nappPlotXps(FileList,tmpDataSelection)
|
||||
%
|
||||
% *input*
|
||||
% FileList: data table
|
||||
% tableSelection (optional): logical array to filter data table
|
||||
% tableVariable (optional): select what to plot: image(default),'imageRoh','spectrum_countsPerSecond','spectrum_counts','spectrum_countsNorm'
|
||||
% energyScale: kinetic (default) or binding, energy scale to be used for
|
||||
% plots.
|
||||
% mode: AllInOne (default) all spectra are plotted in one figure, images
|
||||
% are plotted in one figure each; OneEach: all spectra are plotted in one
|
||||
% figure each; iterations: each spectrum is plotted in one figure each
|
||||
% showing the individual sequence iterations.
|
||||
% plotStep, default 1: Specify the i-th iterations that should be
|
||||
% plotted.
|
||||
%
|
||||
%
|
||||
% *output*
|
||||
% just a figure, with handle.
|
||||
%% TODO
|
||||
%
|
||||
% TODO: Add averaging in image and in iteration plot
|
||||
% TODO: Make code nicer (NEXAFS plotting)
|
||||
|
||||
% Define conditions and defaults of input
|
||||
defaultTableVariable = 'image';
|
||||
expectedTableVariable = {'image','imageRoh','spectrum_countsPerSecond','spectrum_counts','spectrum_countsNorm'};
|
||||
defaultMode = 'AllInOne';
|
||||
expectedMode = {'AllInOne','OneEach','iterations'};
|
||||
defaultFigureMode = 'screen';
|
||||
expectedFigureMode = {'screen','powerpoint','word'};
|
||||
defaultEnergyScale = 'kinetic';
|
||||
expectedEnergyScale = {'kinetic','binding','xRay'};
|
||||
defaultTableSelection = true(size(DataTable,1),1);
|
||||
defaultPlotStep = 1;
|
||||
|
||||
% Parse input
|
||||
p = inputParser;
|
||||
addRequired(p,'DataTable',@istable);
|
||||
addOptional(p,'tableSelection',defaultTableSelection,@islogical);
|
||||
addParameter(p,'tableVariable',defaultTableVariable,...
|
||||
@(x) any(validatestring(x,expectedTableVariable)));
|
||||
addParameter(p,'mode',defaultMode,...
|
||||
@(x) any(validatestring(x,expectedMode)));
|
||||
addParameter(p,'figureMode',defaultFigureMode,...
|
||||
@(x) any(validatestring(x,expectedFigureMode)));
|
||||
addParameter(p,'energyScale',defaultEnergyScale,...
|
||||
@(x) any(validatestring(x,expectedEnergyScale)));
|
||||
addParameter(p,'plotStep',defaultPlotStep);
|
||||
parse(p,DataTable,varargin{:});
|
||||
|
||||
if ~all(cell2mat(cellfun(@size,p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable),'UniformOutput',false)),'all')
|
||||
disp('The table variable appears to be empty. I quit now')
|
||||
error('The table variable appears to be empty.')
|
||||
end
|
||||
|
||||
|
||||
% make figure, with options for output.
|
||||
if contains(p.Results.figureMode ,'screen') % standard
|
||||
alw = get(groot,'DefaultAxesLineWidth');
|
||||
fsz = get(groot,'DefaultAxesFontSize');
|
||||
lw = 2; %get(groot,'DefaultLineLineWidth');
|
||||
fnt = get(groot,'DefaultAxesFontName');
|
||||
loc = 'northeastoutside';
|
||||
unt = 'pixels';
|
||||
pos = [20 100 800 500];
|
||||
|
||||
elseif contains(p.Results.figureMode,'powerpoint')
|
||||
alw = 2;
|
||||
fsz = 26;
|
||||
lw = 4;
|
||||
fnt = 'Helvetica Neue';
|
||||
loc = 'northeastoutside';
|
||||
unt = 'pixels';
|
||||
pos = [300 200 1280 720];
|
||||
|
||||
elseif contains(p.Results.figureMode,'word')
|
||||
alw = 0.75;
|
||||
fsz = 10;
|
||||
lw = 0.5;
|
||||
fnt = 'Helvetica Neue';
|
||||
loc = 'southoutside';
|
||||
unt = 'centimeters';
|
||||
pos = [8 10 8 10];
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if matches(p.Results.tableVariable,'image')
|
||||
for ii = 1:size(p.Results.DataTable(p.Results.tableSelection,:),1)
|
||||
if endsWith(p.Results.DataTable(p.Results.tableSelection,:).name{ii},'h5') % let's do NEXAFS first.
|
||||
hdl = figure('Name',p.Results.DataTable(p.Results.tableSelection,:).name{ii},'units', unt,'Position',pos);
|
||||
|
||||
% Create axes
|
||||
hold(gca,'on');
|
||||
% Try to plot image with x and y
|
||||
try
|
||||
% interpolate, to have equal x spacing for image plot
|
||||
Xq = p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii}(1):0.1:p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii}(end);
|
||||
Vq = interp2(p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii},p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii},...
|
||||
p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii},Xq,p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii});
|
||||
image(Xq,p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii},...
|
||||
Vq,'Parent',gca,'CDataMapping','scaled');
|
||||
axis(gca,'ij');
|
||||
set(gca,'Layer','top');
|
||||
xlim([p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii}(1) p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii}(end)]);
|
||||
ylim([p.Results.DataTable(p.Results.tableSelection,:).scientaEkinRange_eV(ii,1) p.Results.DataTable(p.Results.tableSelection,:).scientaEkinRange_eV(ii,2)]);
|
||||
hXLabel = xlabel('Photon energy [eV]');
|
||||
hYLabel = ylabel('Auger energy [eV]');
|
||||
% if this does not work, plot without scaling (just with row and column numbers)
|
||||
catch
|
||||
image(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii},'Parent',gca,'CDataMapping','scaled');
|
||||
axis(gca,'ij');
|
||||
set(gca,'Layer','top');
|
||||
ylim([1 size(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii},1)]);
|
||||
xlim([1 size(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii},2)]);
|
||||
hXLabel = xlabel('# Photon energy, column number');
|
||||
hYLabel = ylabel('# Auger energy, column number');
|
||||
end
|
||||
|
||||
box(gca,'on');
|
||||
if ~matches(p.Results.figureMode,'word')
|
||||
title(p.Results.DataTable(p.Results.tableSelection,:).name{ii},'Interpreter','none')
|
||||
end
|
||||
set( gca, ...
|
||||
'FontName' , fnt,'FontSize' , fsz );
|
||||
set([hXLabel, hYLabel], ...
|
||||
'FontName' , fnt);
|
||||
set([hXLabel, hYLabel] , ...
|
||||
'FontSize' , 1.2*fsz );
|
||||
|
||||
set(gca, ...
|
||||
'Box' , 'off' , ...
|
||||
'TickDir' , 'out' , ...
|
||||
'TickLength' , [.02 .02] , ...
|
||||
'XMinorTick' , 'on' , ...
|
||||
'YMinorTick' , 'off' , ...
|
||||
'XGrid' , 'on' , ...
|
||||
'XColor' , [0 0 0], ...
|
||||
'YColor' , [0 0 0], ...
|
||||
'LineWidth' , alw );
|
||||
elseif endsWith(p.Results.DataTable(p.Results.tableSelection,:).name{ii},'ibw')
|
||||
|
||||
if contains(p.Results.energyScale,'kinetic')
|
||||
hdl = figure('Name',p.Results.DataTable(p.Results.tableSelection,:).name{ii},'units', unt,'Position',pos);
|
||||
|
||||
% Create axes
|
||||
hold(gca,'on');
|
||||
image(p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii},...
|
||||
1:length(1:size(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii},2)),...
|
||||
p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii}',...
|
||||
'Parent',gca,'CDataMapping','scaled');
|
||||
axis(gca,'ij');
|
||||
set(gca,'Layer','top');
|
||||
ylim([1 size(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii},2)]);
|
||||
xlim([p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii}(1) p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii}(end)]);
|
||||
hXLabel = xlabel('Electron energy [eV]');
|
||||
hYLabel = ylabel('Sequence iteration');
|
||||
elseif contains(p.Results.energyScale,'binding')
|
||||
hdl = figure('Name',p.Results.DataTable(p.Results.tableSelection,:).name{ii},'units', unt,'Position',pos);
|
||||
|
||||
% Create axes
|
||||
hold(gca,'on');
|
||||
image(p.Results.DataTable(p.Results.tableSelection,:).bindingEnergy_eV{ii},...
|
||||
1:length(1:size(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii},2)),...
|
||||
p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii}',...
|
||||
'Parent',gca,'CDataMapping','scaled');
|
||||
axis(gca,'ij');
|
||||
set(gca,'Layer','top');
|
||||
ylim([1 size(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii},2)]);
|
||||
% xlim([p.Results.DataTable(p.Results.tableSelection,:).bindingEnergy_eV(ii,1) p.Results.DataTable(p.Results.tableSelection,:).bindingEnergy_eV(ii,2)]);
|
||||
hXLabel = xlabel('Binding energy [eV]');
|
||||
hYLabel = ylabel('Sequence iteration');
|
||||
end
|
||||
box(gca,'on');
|
||||
existColumn = strcmp('sample',p.Results.DataTable.Properties.VariableNames);
|
||||
if ~matches(p.Results.figureMode,'word')
|
||||
if ~any(existColumn)
|
||||
title([{p.Results.DataTable(p.Results.tableSelection,:).name{ii} p.Results.DataTable(p.Results.tableSelection,:).lastModifiedDatestr{ii}}],'Interpreter','none')
|
||||
else
|
||||
title([{p.Results.DataTable(p.Results.tableSelection,:).name{ii} p.Results.DataTable(p.Results.tableSelection,:).sample{ii} p.Results.DataTable(p.Results.tableSelection,:).lastModifiedDatestr{ii}}] ,'Interpreter','none')
|
||||
end
|
||||
end
|
||||
set( gca, ...
|
||||
'FontName' , fnt,'FontSize' , fsz );
|
||||
set([hXLabel, hYLabel], ...
|
||||
'FontName' , fnt);
|
||||
set([hXLabel, hYLabel] , ...
|
||||
'FontSize' , 1.2*fsz );
|
||||
|
||||
set(gca, ...
|
||||
'Box' , 'off' , ...
|
||||
'TickDir' , 'out' , ...
|
||||
'TickLength' , [.02 .02] , ...
|
||||
'XMinorTick' , 'on' , ...
|
||||
'YMinorTick' , 'off' , ...
|
||||
'XGrid' , 'on' , ...
|
||||
'XColor' , [0 0 0], ...
|
||||
'YColor' , [0 0 0], ...
|
||||
'LineWidth' , alw );
|
||||
end
|
||||
end
|
||||
end
|
||||
if matches(p.Results.tableVariable,'imageRoh')
|
||||
for ii = 1:size(p.Results.DataTable(p.Results.tableSelection,:),1)
|
||||
if endsWith(p.Results.DataTable(p.Results.tableSelection,:).name{ii},'h5') % let's do NEXAFS first.
|
||||
hdl = figure('Name',p.Results.DataTable(p.Results.tableSelection,:).name{ii},'units', unt,'Position',pos);
|
||||
|
||||
% Create axes
|
||||
hold(gca,'on');
|
||||
% Try to plot image with x and y
|
||||
try
|
||||
image(p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii},p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii},...
|
||||
p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii},'Parent',gca,'CDataMapping','scaled');
|
||||
axis(gca,'ij');
|
||||
set(gca,'Layer','top');
|
||||
xlim([p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii}(1) p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii}(end)]);
|
||||
ylim([p.Results.DataTable(p.Results.tableSelection,:).scientaEkinRange_eV(ii,1) p.Results.DataTable(p.Results.tableSelection,:).scientaEkinRange_eV(ii,2)]);
|
||||
hXLabel = xlabel('Photon energy [eV]');
|
||||
hYLabel = ylabel('Auger energy [eV]');
|
||||
% if this does not work, plot without scaling (just with row and column numbers)
|
||||
catch
|
||||
image(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii},'Parent',gca,'CDataMapping','scaled');
|
||||
axis(gca,'ij');
|
||||
set(gca,'Layer','top');
|
||||
ylim([1 size(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii},1)]);
|
||||
xlim([1 size(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii},2)]);
|
||||
hXLabel = xlabel('# Photon energy, column number');
|
||||
hYLabel = ylabel('# Auger energy, column number');
|
||||
end
|
||||
|
||||
box(gca,'on');
|
||||
set( gca, ...
|
||||
'FontName' , fnt,'FontSize' , fsz );
|
||||
set([hXLabel, hYLabel], ...
|
||||
'FontName' , fnt);
|
||||
set([hXLabel, hYLabel] , ...
|
||||
'FontSize' , 1.2*fsz );
|
||||
|
||||
set(gca, ...
|
||||
'Box' , 'off' , ...
|
||||
'TickDir' , 'out' , ...
|
||||
'TickLength' , [.02 .02] , ...
|
||||
'XMinorTick' , 'on' , ...
|
||||
'YMinorTick' , 'off' , ...
|
||||
'XGrid' , 'on' , ...
|
||||
'XColor' , [0 0 0], ...
|
||||
'YColor' , [0 0 0], ...
|
||||
'LineWidth' , alw );
|
||||
elseif endsWith(p.Results.DataTable(p.Results.tableSelection,:).name{ii},'ibw')
|
||||
|
||||
if contains(p.Results.energyScale,'kinetic')
|
||||
hdl = figure('Name',p.Results.DataTable(p.Results.tableSelection,:).name{ii},'units', unt,'Position',pos);
|
||||
|
||||
% Create axes
|
||||
hold(gca,'on');
|
||||
existColumn = strcmp('scientaEkinRoh_eV',DataTable.Properties.VariableNames);
|
||||
if any(existColumn)
|
||||
image(p.Results.DataTable(p.Results.tableSelection,:).scientaEkinRoh_eV{ii},...
|
||||
1:length(1:size(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii},2)),...
|
||||
p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii}',...
|
||||
'Parent',gca,'CDataMapping','scaled');
|
||||
xlim([p.Results.DataTable(p.Results.tableSelection,:).scientaEkinRoh_eV{ii}(1) p.Results.DataTable(p.Results.tableSelection,:).scientaEkinRoh_eV{ii}(end)]);
|
||||
|
||||
else
|
||||
image(p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii},...
|
||||
1:length(1:size(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii},2)),...
|
||||
p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii}',...
|
||||
'Parent',gca,'CDataMapping','scaled');
|
||||
xlim([p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii}(1) p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii}(end)]);
|
||||
|
||||
end
|
||||
axis(gca,'ij');
|
||||
set(gca,'Layer','top');
|
||||
ylim([1 size(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii},2)]);
|
||||
hXLabel = xlabel('Electron energy [eV]');
|
||||
hYLabel = ylabel('Sequence iteration');
|
||||
elseif contains(p.Results.energyScale,'binding')
|
||||
hdl = figure('Name',p.Results.DataTable(p.Results.tableSelection,:).name{ii},'units', unt,'Position',pos);
|
||||
|
||||
% Create axes
|
||||
hold(gca,'on');
|
||||
image(p.Results.DataTable(p.Results.tableSelection,:).bindingEnergy_eV{ii},...
|
||||
1:length(1:size(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii},2)),...
|
||||
p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii}',...
|
||||
'Parent',gca,'CDataMapping','scaled');
|
||||
axis(gca,'ij');
|
||||
set(gca,'Layer','top');
|
||||
ylim([1 size(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii},2)]);
|
||||
% xlim([p.Results.DataTable(p.Results.tableSelection,:).bindingEnergy_eV(ii,1) p.Results.DataTable(p.Results.tableSelection,:).bindingEnergy_eV(ii,2)]);
|
||||
hXLabel = xlabel('Binding energy [eV]');
|
||||
hYLabel = ylabel('Sequence iteration');
|
||||
|
||||
end
|
||||
box(gca,'on');
|
||||
|
||||
existColumn = strcmp('sample',p.Results.DataTable.Properties.VariableNames);
|
||||
if ~matches(p.Results.figureMode,'word')
|
||||
if ~any(existColumn)
|
||||
title([{p.Results.DataTable(p.Results.tableSelection,:).name{ii} p.Results.DataTable(p.Results.tableSelection,:).lastModifiedDatestr{ii}}],'Interpreter','none')
|
||||
else
|
||||
title([{p.Results.DataTable(p.Results.tableSelection,:).name{ii} p.Results.DataTable(p.Results.tableSelection,:).sample{ii} p.Results.DataTable(p.Results.tableSelection,:).lastModifiedDatestr{ii}}] ,'Interpreter','none')
|
||||
end
|
||||
end
|
||||
set( gca, ...
|
||||
'FontName' , fnt,'FontSize' , fsz );
|
||||
set([hXLabel, hYLabel], ...
|
||||
'FontName' , fnt);
|
||||
set([hXLabel, hYLabel] , ...
|
||||
'FontSize' , 1.2*fsz );
|
||||
|
||||
set(gca, ...
|
||||
'Box' , 'off' , ...
|
||||
'TickDir' , 'out' , ...
|
||||
'TickLength' , [.02 .02] , ...
|
||||
'XMinorTick' , 'on' , ...
|
||||
'YMinorTick' , 'off' , ...
|
||||
'XGrid' , 'on' , ...
|
||||
'XColor' , [0 0 0], ...
|
||||
'YColor' , [0 0 0], ...
|
||||
'LineWidth' , alw );
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if contains(p.Results.tableVariable,'spectrum')
|
||||
if contains(p.Results.mode,'OneEach')
|
||||
for ii = 1:size(p.Results.DataTable(p.Results.tableSelection,:),1)
|
||||
hdl = figure('Name',p.Results.DataTable(p.Results.tableSelection,:).name{ii},'units', unt,'Position',pos);
|
||||
|
||||
% Create axes
|
||||
hold(gca,'on');
|
||||
if (contains(p.Results.energyScale,'kinetic') & endsWith(p.Results.DataTable(p.Results.tableSelection,:).name{ii},'ibw'))
|
||||
hplot = plot(p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii},...
|
||||
p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii}');
|
||||
hplot.LineWidth = lw;
|
||||
hXLabel = xlabel('Electron kinetic energy [eV]');
|
||||
xlim([p.Results.DataTable(p.Results.tableSelection,:).scientaEkinRange_eV(ii,1) p.Results.DataTable(p.Results.tableSelection,:).scientaEkinRange_eV(ii,2)]);
|
||||
|
||||
elseif (contains(p.Results.energyScale,'binding') & endsWith(p.Results.DataTable(p.Results.tableSelection,:).name{ii},'ibw'))
|
||||
hplot = plot(p.Results.DataTable(p.Results.tableSelection,:).bindingEnergy_eV{ii},...
|
||||
p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii}');
|
||||
hplot.LineWidth = lw;
|
||||
hXLabel= xlabel('Binding energy [eV]');
|
||||
xlim([min(p.Results.DataTable(p.Results.tableSelection,:).bindingEnergy{ii}) max(p.Results.DataTable(p.Results.tableSelection,:).bindingEnergy_eV{ii})]);
|
||||
|
||||
elseif (contains(p.Results.energyScale,'xRay') | endsWith(p.Results.DataTable(p.Results.tableSelection,:).name{ii},'h5'))
|
||||
hplot = plot(p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii},...
|
||||
p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii});
|
||||
hplot.LineWidth = lw;
|
||||
hXLabel = xlabel('Photon Energy eV');
|
||||
xlim([p.Results.DataTable(p.Results.tableSelection,:).xRayEkinRange_eV(ii,1) p.Results.DataTable(p.Results.tableSelection,:).xRayEkinRange_eV(ii,2)]);
|
||||
|
||||
end
|
||||
if contains(p.Results.tableVariable,'Norm')
|
||||
hYLabel = ylabel('Counts [arb. unit]');
|
||||
elseif contains(p.Results.energyScale,'xRay')
|
||||
hYLabel = ylabel('partial A-M.E.Y.');
|
||||
else
|
||||
hYLabel = ylabel('Counts per second');
|
||||
end
|
||||
|
||||
|
||||
box(gca,'on');
|
||||
existColumn = strcmp('sample',p.Results.DataTable.Properties.VariableNames);
|
||||
if ~matches(p.Results.figureMode,'word')
|
||||
if ~any(existColumn)
|
||||
title([{p.Results.DataTable(p.Results.tableSelection,:).name{ii} p.Results.DataTable(p.Results.tableSelection,:).lastModifiedDatestr{ii}}],'Interpreter','none')
|
||||
else
|
||||
title([{p.Results.DataTable(p.Results.tableSelection,:).name{ii} p.Results.DataTable(p.Results.tableSelection,:).sample{ii} p.Results.DataTable(p.Results.tableSelection,:).lastModifiedDatestr{ii}}] ,'Interpreter','none')
|
||||
end
|
||||
end
|
||||
|
||||
set( gca, ...
|
||||
'FontName' , fnt,'FontSize' , fsz );
|
||||
set([hXLabel, hYLabel], ...
|
||||
'FontName' , fnt);
|
||||
set([hXLabel, hYLabel] , ...
|
||||
'FontSize' , 1.2*fsz );
|
||||
|
||||
set(gca, ...
|
||||
'Box' , 'off' , ...
|
||||
'TickDir' , 'out' , ...
|
||||
'TickLength' , [.02 .02] , ...
|
||||
'XMinorTick' , 'on' , ...
|
||||
'YMinorTick' , 'off' , ...
|
||||
'XGrid' , 'on' , ...
|
||||
'XColor' , [0 0 0], ...
|
||||
'YColor' , [0 0 0], ...
|
||||
'LineWidth' , alw );
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
if contains(p.Results.mode,'AllInOne')
|
||||
% generate colormap
|
||||
|
||||
hdl = figure('Name','AllInOneSpectrum','units', unt,'Position',pos);
|
||||
if size(p.Results.DataTable(p.Results.tableSelection,:),1) >= 7
|
||||
tmp_color = colormap(parula(size(p.Results.DataTable(p.Results.tableSelection,:),1)));
|
||||
else
|
||||
tmp_color = colormap(lines(size(p.Results.DataTable(p.Results.tableSelection,:),1)));
|
||||
end
|
||||
if contains(p.Results.energyScale,'kinetic')
|
||||
% axes('Parent',gcf,'XDir','reverse')
|
||||
hold(gca,'on');
|
||||
for ii = 1:size(p.Results.DataTable(p.Results.tableSelection,:),1)
|
||||
if endsWith(p.Results.DataTable(p.Results.tableSelection,:).name{ii},'ibw')
|
||||
hplot = plot(p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii},...
|
||||
p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii}','DisplayName',p.Results.DataTable(p.Results.tableSelection,:).name{ii},'Color',tmp_color(ii,:));
|
||||
hplot.LineWidth = lw;
|
||||
end
|
||||
end
|
||||
hXLabel = xlabel('Electron kinetic energy [eV]');
|
||||
elseif contains(p.Results.energyScale,'binding')
|
||||
axes('Parent',gcf,'XDir','reverse')
|
||||
hold(gca,'on');
|
||||
|
||||
for ii = 1:size(p.Results.DataTable(p.Results.tableSelection,:),1)
|
||||
if endsWith(p.Results.DataTable(p.Results.tableSelection,:).name{ii},'ibw')
|
||||
hplot = plot(p.Results.DataTable(p.Results.tableSelection,:).bindingEnergy_eV{ii},...
|
||||
p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii}','DisplayName',p.Results.DataTable(p.Results.tableSelection,:).name{ii},'Color',tmp_color(ii,:));
|
||||
hplot.LineWidth = lw;
|
||||
end
|
||||
end
|
||||
hXLabel= xlabel('Binding energy [eV]');
|
||||
elseif contains(p.Results.energyScale,'xRay')
|
||||
hold(gca,'on');
|
||||
for ii = 1:size(p.Results.DataTable(p.Results.tableSelection,:),1)
|
||||
if endsWith(p.Results.DataTable(p.Results.tableSelection,:).name{ii},'h5')
|
||||
hplot = plot(p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii},...
|
||||
p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii},...
|
||||
'DisplayName',p.Results.DataTable(p.Results.tableSelection,:).name{ii},'Color',tmp_color(ii,:));
|
||||
hplot.LineWidth = lw;
|
||||
end
|
||||
end
|
||||
hXLabel = xlabel('Photon Energy eV');
|
||||
end
|
||||
if contains(p.Results.tableVariable,'Norm')
|
||||
hYLabel = ylabel('Counts [arb. unit]');
|
||||
elseif contains(p.Results.energyScale,'xRay')
|
||||
hYLabel = ylabel('partial A-M.E.Y.');
|
||||
else
|
||||
hYLabel = ylabel('Counts per second');
|
||||
end
|
||||
|
||||
|
||||
box(gca,'on');
|
||||
if ~matches(p.Results.figureMode,'word')
|
||||
title('PE Spectra','Interpreter','none')
|
||||
hlegend = legend(p.Results.DataTable(p.Results.tableSelection,:).name{:});
|
||||
hlegend.FontSize = fsz;
|
||||
hlegend.Interpreter = 'none';
|
||||
hlegend.Location = loc;
|
||||
set(legend, 'Interpreter','none')
|
||||
end
|
||||
set( gca, ...
|
||||
'FontName' , fnt,'FontSize' , fsz );
|
||||
set([hXLabel, hYLabel], ...
|
||||
'FontName' , fnt);
|
||||
set([hXLabel, hYLabel] , ...
|
||||
'FontSize' , 1.2*fsz );
|
||||
|
||||
set(gca, ...
|
||||
'Box' , 'off' , ...
|
||||
'TickDir' , 'out' , ...
|
||||
'TickLength' , [.02 .02] , ...
|
||||
'XMinorTick' , 'on' , ...
|
||||
'YMinorTick' , 'off' , ...
|
||||
'XGrid' , 'on' , ...
|
||||
'XColor' , [0 0 0], ...
|
||||
'YColor' , [0 0 0], ...
|
||||
'LineWidth' , alw );
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
if contains(p.Results.mode,'iterations')
|
||||
% generate colormap
|
||||
|
||||
for ii = 1:size(p.Results.DataTable(p.Results.tableSelection,:),1)
|
||||
if endsWith(p.Results.DataTable(p.Results.tableSelection,:).name{ii},'ibw')
|
||||
|
||||
hdl = figure('Name',p.Results.DataTable(p.Results.tableSelection,:).name{ii},'units', unt,'Position',pos);
|
||||
if size(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii},2) >= 7
|
||||
tmp_color = colormap(parula(size(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii},2)));
|
||||
else
|
||||
tmp_color = colormap(lines(size(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii},2)));
|
||||
end
|
||||
|
||||
% Create axes
|
||||
hold(gca,'on');
|
||||
|
||||
if contains(p.Results.energyScale,'kinetic')
|
||||
for ij = 1:p.Results.plotStep:size(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii},2)
|
||||
hplot= plot(p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii}',...
|
||||
p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii}(:,ij),'Color',tmp_color(ij,:));
|
||||
hplot.LineWidth = lw;
|
||||
hold on
|
||||
end
|
||||
xlabel('Electron kinetic energy [eV]')
|
||||
elseif contains(p.Results.energyScale,'binding')
|
||||
for ij = 1:p.Results.plotStep:size(p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii},2)
|
||||
hplot = plot(p.Results.DataTable(p.Results.tableSelection,:).bindingEnergy_eV{ii}',...
|
||||
p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii}(:,ij),'Color',tmp_color(ii,:));
|
||||
hplot.LineWidth = lw;
|
||||
end
|
||||
hXLabel = xlabel('Binding energy [eV]');
|
||||
end
|
||||
if contains(p.Results.tableVariable,'Norm')
|
||||
hYLabel = ylabel('Counts [arb. unit]');
|
||||
else
|
||||
hYLabel = ylabel('Counts per second');
|
||||
end
|
||||
|
||||
|
||||
box(gca,'on');
|
||||
if ~matches(p.Results.figureMode,'word')
|
||||
title([{p.Results.DataTable(p.Results.tableSelection,:).name{ii} p.Results.DataTable(p.Results.tableSelection,:).sample{ii} p.Results.DataTable(p.Results.tableSelection,:).lastModifiedDatestr{ii}}] ,'Interpreter','none')
|
||||
end
|
||||
set( gca, ...
|
||||
'FontName' , fnt,'FontSize' , fsz );
|
||||
set([hXLabel, hYLabel], ...
|
||||
'FontName' , fnt);
|
||||
set([hXLabel, hYLabel] , ...
|
||||
'FontSize' , 1.2*fsz );
|
||||
|
||||
set(gca, ...
|
||||
'Box' , 'off' , ...
|
||||
'TickDir' , 'out' , ...
|
||||
'TickLength' , [.02 .02] , ...
|
||||
'XMinorTick' , 'on' , ...
|
||||
'YMinorTick' , 'off' , ...
|
||||
'XGrid' , 'on' , ...
|
||||
'XColor' , [0 0 0], ...
|
||||
'YColor' , [0 0 0], ...
|
||||
'LineWidth' , alw );
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,193 +0,0 @@
|
||||
function DataTable = nappScale(DataTable,varargin)
|
||||
%nappScale can be used to normalise XPS spectra to the peak area. The peak
|
||||
%of the same region or of a different region with identical SES file
|
||||
%number can be used for XPS data. NEXAFS spectra can be normed to their
|
||||
%area or to the intensity at an energy range of choice.
|
||||
%
|
||||
% FileList = nappScale(FileList,tmpDataSelection,'regionOld','C1s','regionNew','O1s');
|
||||
%
|
||||
% *input*
|
||||
% FileList: data table
|
||||
% tableSelection (optional): logical array to filter data table. These
|
||||
% spectra will be normalised.
|
||||
% regionOld: C1s (default) or O1s, N1s - region spectra that will be
|
||||
% normalised. Needs to be identical to the table selection (filter).
|
||||
% regionNew: O1s (default) or C1s, N1s - peak area that will be used to normalise
|
||||
% peakNumber: Number of the feature that should be used for fitting
|
||||
% (nappFitGaussXps gives results for 4 features, default is 1)
|
||||
%
|
||||
% The region in tableSelection and regionOld MUST be identical.
|
||||
%
|
||||
%
|
||||
% *output*
|
||||
% table variable spectrum_countsNorm
|
||||
|
||||
% Define conditions and defaults of input
|
||||
defaultTableVariable = 'spectrum_countsPerSecond';
|
||||
expectedTableVariable = {'spectrum_counts','spectrum_countsPerSecond','spectrum_countsNorm'};
|
||||
defaultMode = 'area';
|
||||
expectedMode = {'intensity','area'};
|
||||
defaultRegionOld = 'C1s';
|
||||
expectedRegionOld = {'O1s','C1s','N1s','Cl2p'};
|
||||
defaultRegionNew = 'O1s';
|
||||
expectedRegionNew = {'O1s','C1s','N1s'};
|
||||
defaultPeakNumber = 1;
|
||||
defaultTableSelection = true(size(DataTable,1));
|
||||
|
||||
|
||||
% Parse input
|
||||
p = inputParser;
|
||||
addRequired(p,'DataTable',@istable);
|
||||
addOptional(p,'tableSelection',defaultTableSelection,@islogical);
|
||||
addOptional(p,'energyStart',@isnumeric)
|
||||
addOptional(p,'energyEnd',@isnumeric)
|
||||
addParameter(p,'tableVariable',defaultTableVariable,...
|
||||
@(x) any(validatestring(x,expectedTableVariable)));
|
||||
addParameter(p,'regionOld',defaultRegionOld,...
|
||||
@(x) any(validatestring(x,expectedRegionOld)));
|
||||
addParameter(p,'regionNew',defaultRegionNew,...
|
||||
@(x) any(validatestring(x,expectedRegionNew)));
|
||||
addParameter(p,'peakNumber',defaultPeakNumber);
|
||||
addParameter(p,'mode',defaultMode,...
|
||||
@(x) any(validatestring(x,expectedMode)));
|
||||
parse(p,DataTable,varargin{:});
|
||||
|
||||
% add empty variable to table
|
||||
existColumn = strcmp('spectrum_countsNorm',DataTable.Properties.VariableNames);
|
||||
if ~any(existColumn)
|
||||
DataTable.spectrum_countsNorm = cell(size(DataTable,1),1);
|
||||
end
|
||||
|
||||
existColumn = strcmp('logScaleRange',DataTable.Properties.VariableNames);
|
||||
if ~any(existColumn)
|
||||
DataTable.logBackgroundRange = NaN(size(DataTable,1),2);
|
||||
end
|
||||
existColumn = strcmp('logScaleMode',DataTable.Properties.VariableNames);
|
||||
if ~any(existColumn)
|
||||
DataTable.logBackgroundMode = cellstr(repmat(' ',size(p.Results.DataTable,1),1));
|
||||
end
|
||||
existColumn = strcmp('logScaleDate',DataTable.Properties.VariableNames);
|
||||
if ~any(existColumn)
|
||||
DataTable.logBackgroundDate = cellstr(repmat(' ',size(p.Results.DataTable,1),1));
|
||||
end
|
||||
|
||||
% check input (all elements of input variable need to have non-zero size)
|
||||
if ~all(cell2mat(cellfun(@size,p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable),'UniformOutput',false)),'all')
|
||||
disp('The table variable appears to be empty. I quit now')
|
||||
error('The table variable appears to be empty.')
|
||||
end
|
||||
|
||||
|
||||
% repeat this for all columns in input.
|
||||
for ii = 1:size(p.Results.DataTable(p.Results.tableSelection,:),1)
|
||||
if endsWith(p.Results.DataTable(p.Results.tableSelection,:).name{ii},'ibw')
|
||||
% get name and date of input file and replace old region with new
|
||||
% region. This will be the files where the peak area is taken from.
|
||||
tmpName = replace(p.Results.DataTable(p.Results.tableSelection,:).name{ii}, ...
|
||||
p.Results.regionOld,p.Results.regionNew);
|
||||
tmpDate = p.Results.DataTable(p.Results.tableSelection,:).lastModifiedDatenum(ii);
|
||||
% select spectra based on the new names and dates of original file
|
||||
tmpDataSelection = contains(p.Results.DataTable.name,tmpName)...
|
||||
& ismember(year(p.Results.DataTable.lastModifiedDatenum),year(tmpDate))...
|
||||
& ismember(month(p.Results.DataTable.lastModifiedDatenum),month(tmpDate))...
|
||||
& ismember(day(p.Results.DataTable.lastModifiedDatenum),day(tmpDate))...
|
||||
& ismember(hour(p.Results.DataTable.lastModifiedDatenum),hour(tmpDate))...
|
||||
& ismember(minute(p.Results.DataTable.lastModifiedDatenum),minute(tmpDate));
|
||||
% check peak area
|
||||
existColumn = strcmp('peakArea',DataTable.Properties.VariableNames);
|
||||
if any(existColumn)
|
||||
if isnan(DataTable( tmpDataSelection,:).peakArea(p.Results.peakNumber))
|
||||
disp('The peak area appears to be empty. I quit now')
|
||||
disp(DataTable( tmpDataSelection,:).name{ii})
|
||||
error('The peak area appears to be empty.')
|
||||
end
|
||||
else
|
||||
disp('The data table appear to have not peak area column. I quit now')
|
||||
error('No peak area column')
|
||||
end
|
||||
% do the norming
|
||||
if contains(p.Results.mode,'area')
|
||||
DataTable(p.Results.tableSelection,:).spectrum_countsNorm{ii} = ...
|
||||
DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii}...
|
||||
./ DataTable( tmpDataSelection,:).peakArea(p.Results.peakNumber);
|
||||
elseif contains(p.Results.mode,'intensity')
|
||||
disp('Intensity mode not yet programmed for XPS data')
|
||||
end
|
||||
|
||||
elseif endsWith(p.Results.DataTable(p.Results.tableSelection,:).name{ii},'h5')
|
||||
% if ~exist(p.Results.energyStart) | ~exist(p.Results.energyEnd)
|
||||
% disp('The energy region used for normalisation appears to be empty. I quit now')
|
||||
% error('The energy region used to normalise appears to be empty.')
|
||||
% end
|
||||
if contains(p.Results.mode,'intensity')
|
||||
if p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii}(1)...
|
||||
< p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii}(end)
|
||||
% prepare Data
|
||||
[xData, yData] = prepareCurveData(p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii}...
|
||||
, p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii});
|
||||
% MEAN
|
||||
b_1 = find(xData >= p.Results.energyStart,1);
|
||||
b_2 = find(xData >= p.Results.energyEnd,1);
|
||||
|
||||
b_mean = mean(yData(b_1:b_2));
|
||||
elseif p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii}(1)...
|
||||
> p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii}(end)
|
||||
% prepare Data
|
||||
[xData, yData] = prepareCurveData( p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii}...
|
||||
, p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii});
|
||||
% MEAN
|
||||
b_1 = find(xData <= p.Results.energyStart,1);
|
||||
b_2 = find(xData <= p.Results.energyEnd,1);
|
||||
|
||||
b_mean = mean(yData(b_2:b_1));
|
||||
else
|
||||
disp('Warning: Issue with NEXAFS_col_scaling')
|
||||
end
|
||||
|
||||
tmp_3(:,1) = p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii}...
|
||||
./b_mean;
|
||||
|
||||
DataTable(p.Results.tableSelection,:).spectrum_countsNorm{ii} = tmp_3;
|
||||
clearvars tmp_3
|
||||
elseif contains(p.Results.mode,'area')
|
||||
if p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii}(1)...
|
||||
< p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii}(end)
|
||||
% prepare Data
|
||||
[xData, yData] = prepareCurveData( p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii}...
|
||||
, p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii});
|
||||
% Area
|
||||
b_1 = find(xData >= p.Results.energyStart,1);
|
||||
b_2 = find(xData >= p.Results.energyEnd,1);
|
||||
|
||||
b_area = trapz(xData(b_1:b_2),yData(b_1:b_2));
|
||||
elseif p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii}(1)...
|
||||
> p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii}(end)
|
||||
% prepare Data
|
||||
[xData, yData] = prepareCurveData( p.Results.DataTable(p.Results.tableSelection,:).xRayEkin_eV{ii}...
|
||||
, p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii});
|
||||
% MEAN
|
||||
b_1 = find(xData <= p.Results.energyStart,1);
|
||||
b_2 = find(xData <= p.Results.energyEnd,1);
|
||||
|
||||
b_area = trapz(xData(b_2:b_1),yData(b_2:b_1));
|
||||
else
|
||||
disp('Warning: Issue with NEXAFS_col_scaling')
|
||||
end
|
||||
|
||||
tmp_3(:,1) = p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii}...
|
||||
./b_area;
|
||||
|
||||
DataTable(p.Results.tableSelection,:).spectrum_countsNorm{ii} = tmp_3;
|
||||
clearvars tmp_3
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
% write log to table
|
||||
DataTable.logScaleMode(p.Results.tableSelection,:) = cellstr(repmat(p.Results.mode,size(p.Results.DataTable(p.Results.tableSelection,:),1),1));
|
||||
if endsWith(p.Results.DataTable(p.Results.tableSelection,:).name{ii},'h5')
|
||||
DataTable.logScaleRange(p.Results.tableSelection,:) = repmat([p.Results.energyStart p.Results.energyEnd],size(p.Results.DataTable(p.Results.tableSelection,:),1),1);
|
||||
end
|
||||
DataTable.logScaleDate(p.Results.tableSelection,:) = cellstr(repmat(datestr(now),size(p.Results.DataTable(p.Results.tableSelection,:),1),1));
|
||||
|
||||
end
|
||||