Added possibility to exlclude peak, plus a range at end of the spectrum. Updated the documentation. Bug fixes.

This commit is contained in:
bartels-rausch committed 2026-03-05 07:32:53 +01:00
1 parent d521db8cb8
commit 3a7ae3dcbd
2 files changed
+33 -15

No files matched your search

+30 -14
View File
@@ -31,15 +31,30 @@ function DataTable = nappBackground(DataTable,varargin)
% one of the following variables: 'spectrum_counts',
% 'spectrum_countsPerSecond', or 'spectrum_countsNorm'.
%
% energyStart numeric scalar or vector
% Lower bound(s) of energy range for background calculation.
% Scalar: single energy range.
% Vector [E1, E2]: two disjoint ranges [E1, E2] to [end] and [E2, E1].
% Note: For binding energy scale, comparison direction reverses.
% energyStart — Start energies for excluded ranges
% Numeric scalar or vector.
% Defines the lower bound(s) of the data range(s) excluded from
% background fitting.
%
% energyEnd — End energies for excluded ranges
% Numeric scalar or vector.
% Defines the upper bound(s) of the data range(s) excluded from
% background fitting.
%
% If energyStart and energyEnd are scalars, the range between
% energyStart and energyEnd is excluded from the fit (for example,
% to exclude the main peak).
%
% If energyStart is a two-element vector, the range from the first
% data point to the second value of energyStart is additionally
% excluded.
% If energyEnd is a two-element vector, the range from the second
% value of energyEnd to the end of the dataset is additionally
% excluded.
%
% Specify vector values as comma-separated entries in brackets,
% for example [395, 407].
%
% energyEnd numeric scalar or vector
% Upper bound(s) of energy range for background calculation.
% See energyStart for vector behavior.
%
% NAME-VALUE PAIR ARGUMENTS (optional)
% ------------------------------------
@@ -89,11 +104,6 @@ function DataTable = nappBackground(DataTable,varargin)
% NOTES
% -----
% - Empty or missing spectra in tableVariable will trigger an error.
% - For 'mean' mode with binding energy, energy comparisons use <= operator
% (reversed compared to kinetic energy mode).
% - Exponential fits ('exp2' type) are computed via nonlinear least squares
% excluding points outside the specified energy range.
% - Generated log entries are identical for all rows in tableSelection.
%
% SEE ALSO
% --------
@@ -167,8 +177,8 @@ for ii = 1:size(p.Results.DataTable(p.Results.tableSelection,:),1)
if ~startsWith(p.Results.mode,'mean')
[xData, yData] = prepareCurveData(p.Results.DataTable(p.Results.tableSelection,:).scientaEkin_eV{ii},p.Results.DataTable(p.Results.tableSelection,:).(p.Results.tableVariable){ii});
excludedPoints = excludedata( xData, yData, 'domain',[p.Results.energyStart(1) p.Results.energyEnd(1)] );
if size(p.Results.energyStart,2) ==2 && size(p.Results.energyEnd,2) ==1
excludedPointsEins = excludedPoints;
clearvars excludedPoints
@@ -180,6 +190,12 @@ for ii = 1:size(p.Results.DataTable(p.Results.tableSelection,:),1)
excludedPointsZwei = excludedata( xData, yData, 'domain',[xData(1) p.Results.energyStart(2)] );
excludedPointsDrei = excludedata( xData, yData, 'domain',[p.Results.energyEnd(2) xData(end)] );
excludedPoints = excludedPointsEins & excludedPointsZwei & excludedPointsDrei;
elseif size(p.Results.energyStart,2) ==1 && size(p.Results.energyEnd,2) ==2
excludedPointsEins = excludedPoints;
clearvars excludedPoints
excludedPointsZwei = excludedata( xData, yData, 'domain',[p.Results.energyEnd(2) xData(end)] );
excludedPoints = excludedPointsEins & excludedPointsZwei;
end
opts = fitoptions( 'Method', 'NonlinearLeastSquares','Exclude', ~excludedPoints );
+3 -1
View File
@@ -13,7 +13,9 @@ function combinedSpectrum = nappCombineSpectra(DataTable,varargin)
% energy axis and combined spectrum plus metadata. Critically, this allows
% all existing nappXXX functions to operate directly on the combined result
% without conversion. Output table is named '<originalName>_combined.h5'
% where originalName is from the first selected row's name field.
% where originalName is from the first selected row's name field. The
% mean of pass energy, sample temperature, ice temperature, pressure
% are added to the output.
%
% SYNTAX
% ------