Modified to save analysis data that once done does not need to be redone if it needs to be plotted again or differently.

This commit is contained in:
Karthik 2025-08-23 18:30:07 +02:00
parent 628a29971f
commit db298413d1
5 changed files with 47 additions and 6 deletions

View File

@ -32,6 +32,8 @@ function results = performAnalysis(options)
options.skipNormalization (1,1) logical
options.skipLivePlot (1,1) logical
options.skipSaveFigures (1,1) logical
options.skipSaveData (1,1) logical
options.skipSaveOD (1,1) logical
options.showProgressBar (1,1) logical
options.measurementName (1,:) char
options.folderPath (1,:) char

View File

@ -56,7 +56,12 @@ function results_all = batchAnalyze(dataSources, options)
result.run = runID;
result.path = folderPath;
result.results = analysisResults;
% Save each dataset as its own MAT file
if ~isfield(options, 'skipSaveData') || ~options.skipSaveData
saveResultStruct(result, options.saveDirectory);
end
% Append to output
results_all{end+1,1} = result;
@ -66,4 +71,36 @@ function results_all = batchAnalyze(dataSources, options)
end
end
end
end
end
%% ---- Local function for saving results ----
function saveResultStruct(result, saveDirectory)
% Define results folder
resultsFolder = fullfile(saveDirectory, "Results", "AnalysisSavedData");
if ~exist(resultsFolder, 'dir')
mkdir(resultsFolder);
end
% Path to index file
indexFile = fullfile(resultsFolder, "datasetsIndex.mat");
% Load or initialize index
if isfile(indexFile)
S = load(indexFile, "nextIdx");
nextIdx = S.nextIdx;
else
nextIdx = 1;
end
% Variable name and file path
varName = sprintf('Dataset_%d', nextIdx);
savePath = fullfile(resultsFolder, varName + ".mat");
% Save dataset as struct inside MAT file
S.(varName) = result;
save(savePath, '-struct', 'S');
% Update index
nextIdx = nextIdx + 1;
save(indexFile, "nextIdx");
end

View File

@ -38,7 +38,7 @@ function [od_imgs, scan_parameter_values, file_list] = collectODImages(options)
file_list = evalin('base','file_list');
% --- Ensure figures exist if requested now ---
if ~options.skipSaveFigures
if ~options.skipSaveOD
saveODFigures(od_imgs, options.saveDirectory);
end
@ -200,7 +200,7 @@ function [od_imgs, scan_parameter_values, file_list] = collectODImages(options)
assignin('base', 'prior_options', options);
% --- Save OD images as figures if requested ---
if ~options.skipSaveFigures
if ~options.skipSaveOD
saveODFigures(od_imgs, options.saveDirectory);
end

View File

@ -68,6 +68,8 @@ options.skipMasking = true;
options.skipIntensityThresholding = true;
options.skipBinarization = true;
options.skipSaveFigures = true;
options.skipSaveData = false;
options.skipSaveOD = true;
options.skipLivePlot = false;
options.showProgressBar = true;

View File

@ -67,8 +67,8 @@ options.skipPreprocessing = true;
options.skipMasking = true;
options.skipIntensityThresholding = true;
options.skipBinarization = true;
options.skipMovieRender = true;
options.skipSaveFigures = true;
options.skipSaveData = false;
options.skipSaveOD = true;
options.skipLivePlot = false;
options.showProgressBar = true;
@ -77,4 +77,4 @@ options.showProgressBar = true;
options.font = 'Bahnschrift';
%% ===== Run Batch Analysis =====
results_all = Helper.batchAnalyze(dataSources, options);
results_all = Helper.batchAnalyze(dataSources, options);