Major refactor - generic model architecture with full Shirley background support

BREAKING CHANGES:
- Single-spectrum fitting only (enforces exactly one row selected)
- Gauss fitting now uses FWHM parameter instead of Gaussian width sigma
- Removed multi-row batch processing capability

NEW FEATURES:
- Generic model architecture: arbitrary number of peaks (determined by length of FitParameter.peakArea)
- Full Shirley background support for both Gaussian and Pseudo-Voigt peak shapes
- Comprehensive parameter validation system with detailed error messages
- Support for shared vs per-peak Shirley K parameters
- New fitting modes: 'positionShirley', 'widthShirley', 'widthPositionShirley'
- New custom mode: 'TwoSpinOrbitDoubletPseudoVoigtShirley'
- Automatic field name typo correction ('Bond' → 'Bound')
- Enhanced results export: now includes peakEta and peakShirleyK columns

REFACTORING:
- Centralized peak and background equations in helper functions
  - gaussPeak(), lorentzPeak(), pseudoVoigtPeak()
  - linearBackground(), activeShirleyBackgroundFwhm()
  - fwhm2w() conversion utility
- Extracted model generation to genericModelGenerator()
- Modular validation helpers: checkFieldDimension(), checkBoundsPair()
- Standardized parameter vector layouts documented for all mode/background/peak-type combinations
- Improved column resizing logic with resizeColumnHelper()
- Enhanced plotting integration with nappPlot.m and nappAddFitToPlot.m

ARCHITECTURE:
- Unified parameter extraction for all fitting modes in centralized switch-case structure
- Consistent FWHM-based width parameterization across all peak types
- Mode-specific Shirley K sizing (scalar for shared modes, array for per-peak modes)
- Comprehensive inline documentation of parameter vector layouts (50+ combinations)

IMPROVEMENTS:
- Backward compatibility for 'gauss' width mode (auto-converts to FWHM)
- Robust bounds checking with detailed diagnostic messages
- Enhanced figure generation: residuals plot + fit visualization in tiledlayout
- Better error handling for empty/malformed data structures
- NaN-padded result arrays for variable peak counts

FILE SIZE: ~73KB → ~152KB (107% increase due to comprehensive documentation and generic architecture)
This commit is contained in:
bartels-rausch committed 2026-01-23 08:02:53 +01:00
1 parent 7d37326785
commit 484c84e5f0
8 files changed
+3613 -1827

No files matched your search

@@ -302,4 +302,11 @@ tmpDataSelection = month(FileList.lastModifiedDatenum) == 11 ...
FileList = nappGenerateSpectra(FileList,tmpDataSelection);
nappPlot(FileList,tmpDataSelection,'tableVariable','spectrum_countsPerSecond','mode','AllInOne');
disp(FileList(tmpDataSelection,{'name','lastModifiedDatestr','scientaRegionIterations','scientaSequenceIterations','scientaDwellTime_ms','scientaPassEnergy_eV'}))
end
%% helper functions
% Check if the environment is MATLAB or Octave
if exist('OCTAVE_VERSION', 'builtin')
% Anonymous function mimicking contains
contains = @(str, pattern) ~cellfun('isempty', strfind(str, pattern));
end