Minor bugfixes.

This commit is contained in:
Karthik 2025-09-14 15:12:56 +02:00
parent 839d84035e
commit 20a0953b01
2 changed files with 63 additions and 35 deletions

View File

@ -31,32 +31,53 @@ function results = runFitProgressViewer(od_imgs, model, quantities, plotConfig,
extraParams struct = struct()
end
%% --- Default configuration ---
defaults = struct(...
'fontName', 'Bahnschrift', ...
'fontSize', 16, ...
'fontWeight', 'bold', ...
'colormapName', 'sky', ...
'scatterLineSpec', '-o', ...
'bottomRowFields', quantities, ... % <- derived from user input
'bottomRowLabels', {'Atom Number','# Condensed','Temp'}, ...
'bottomRowUnits', [1,1,1] ...
);
%% --- Robust defaults + user override ---
%% --- Merge user config with defaults ---
config = struct();
flds = fieldnames(plotConfig);
for k = 1:numel(flds)
config.(flds{k}) = plotConfig.(flds{k});
config = struct(); % start empty
% --- List of default values in a cell array ---
defaultValues = { ...
'fontName', 'Arial'; ...
'fontSize', 16; ...
'fontWeight', 'bold'; ...
'colormapName', 'turbo'; ...
'scatterLineSpec', '-o'; ...
'bottomRowFields', quantities; ...
'bottomRowLabels', {'Atom Number','# Condensed','Temp'}; ...
'bottomRowUnits', [1,1,1] ...
};
% --- Assign defaults field by field ---
for k = 1:size(defaultValues,1)
field = defaultValues{k,1};
value = defaultValues{k,2};
config.(field) = value;
end
% Ensure bottomRowFields is set from quantities if not provided
% --- Merge user config if provided ---
if exist('plotConfig','var') && isstruct(plotConfig) && ~isempty(plotConfig)
% If plotConfig is a struct array, take first element
if numel(plotConfig) > 1
warning('plotConfig is a struct array. Using the first element.');
plotConfig = plotConfig(1);
end
plotFields = fieldnames(plotConfig);
for k = 1:numel(plotFields)
f = plotFields{k};
v = plotConfig.(f);
% Only override if user provided a non-empty value
if ~isempty(v)
config.(f) = v;
end
end
end
% --- Safety fallback ---
if ~isfield(config,'bottomRowFields') || isempty(config.bottomRowFields)
config.bottomRowFields = quantities;
end
numImages = numel(od_imgs);
numImages = numel(od_imgs);
fprintf('\n[INFO] Starting processing of %d images...\n', numImages);
%% --- Preallocate results struct ---
@ -179,18 +200,29 @@ function results = runFitProgressViewer(od_imgs, model, quantities, plotConfig,
end
end
meanVal = mean(vals,'omitnan');
semVal = std(vals,'omitnan')/sqrt(sum(~isnan(vals)));
% Only keep valid entries
validVals = vals(~isnan(vals));
nVals = numel(validVals);
meanVal = mean(validVals,'omitnan');
if nVals >= 20
% Use SEM
semVal = std(validVals,'omitnan')/sqrt(nVals);
str = sprintf('Mean ± SEM: %.2e ± %.2e', meanVal, semVal);
else
% Use SD
sdVal = std(validVals,'omitnan');
str = sprintf('Mean ± SD: %.2e ± %.2e', meanVal, sdVal);
end
% Place in bottom-right corner using normalized axes coordinates
ax = axBottom(k);
str = sprintf('%.2e ± %.2e', meanVal, semVal);
text(ax, 0.98, 0.02, str, ...
'Units','normalized', ...
'HorizontalAlignment','right', 'VerticalAlignment','bottom', ...
'FontName', config.fontName, ...
'FontSize', config.fontSize, ...
'FontSize', config.fontSize-2, ...
'FontWeight', config.fontWeight, ...
'BackgroundColor', 'w', ... % white box
'Margin', 4, ... % padding inside box

View File

@ -93,25 +93,21 @@ end
%% Fit model and extract quantities
% --- Specify model and quantities to extract ---
model = FitModels.DensityProfileBEC2DModel();
quantities = {'atom_number','condensate_fraction','temperature'};
model = FitModels.DensityProfileBEC2DModel();
quantities = {'atom_number','condensate_fraction','temperature'};
% --- Optional plotting configuration ---
plotConfig = struct();
plotConfig.fontName = 'Bahnschrift';
plotConfig.fontSize = 16;
plotConfig.fontWeight = 'bold';
plotConfig.colormapName = 'sky';
plotConfig.scatterLineSpec = '-o';
plotConfig.figureTag = 'BatchBECViewer';
plotConfig.bottomRowTitles = {'Condensed Atom Number','Condensate Fraction','Temperature'};
plotConfig.bottomRowLabels = {'# (\times 10^4)','# (%)','# (nK)'};
plotConfig.bottomRowUnits = [1e-4,1e2,1e9];
plotConfig.bottomRowUnits = [1e-4, 1e2, 1e9];
% --- Extra parameters ---
extraParams = struct();
extraParams.ToF = 20e-3;
extraParams = struct();
extraParams.ToF = 20e-3;
% --- Run viewer ---
results = Analyzer.runFitProgressViewer(od_imgs, model, quantities, plotConfig, extraParams);
results = Analyzer.runFitProgressViewer(od_imgs, model, quantities, plotConfig, extraParams);