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