From db298413d127141aa3ae99c0c833992534dfb547 Mon Sep 17 00:00:00 2001 From: Karthik Chandrashekara Date: Sat, 23 Aug 2025 18:30:07 +0200 Subject: [PATCH] Modified to save analysis data that once done does not need to be redone if it needs to be plotted again or differently. --- Data-Analyzer/+Analyzer/performAnalysis.m | 2 + Data-Analyzer/+Helper/batchAnalyze.m | 41 ++++++++++++++++++- Data-Analyzer/+Helper/collectODImages.m | 4 +- .../+Scripts/BECToDroplets/plotImages.m | 2 + .../+Scripts/BECToDroplets/runFullAnalysis.m | 4 +- 5 files changed, 47 insertions(+), 6 deletions(-) diff --git a/Data-Analyzer/+Analyzer/performAnalysis.m b/Data-Analyzer/+Analyzer/performAnalysis.m index e526572..5b64cc4 100644 --- a/Data-Analyzer/+Analyzer/performAnalysis.m +++ b/Data-Analyzer/+Analyzer/performAnalysis.m @@ -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 diff --git a/Data-Analyzer/+Helper/batchAnalyze.m b/Data-Analyzer/+Helper/batchAnalyze.m index 5d983a2..ad446a7 100644 --- a/Data-Analyzer/+Helper/batchAnalyze.m +++ b/Data-Analyzer/+Helper/batchAnalyze.m @@ -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 \ No newline at end of file +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 diff --git a/Data-Analyzer/+Helper/collectODImages.m b/Data-Analyzer/+Helper/collectODImages.m index f6fed8f..d4a3c4e 100644 --- a/Data-Analyzer/+Helper/collectODImages.m +++ b/Data-Analyzer/+Helper/collectODImages.m @@ -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 diff --git a/Data-Analyzer/+Scripts/BECToDroplets/plotImages.m b/Data-Analyzer/+Scripts/BECToDroplets/plotImages.m index 80ce67f..d3bb31b 100644 --- a/Data-Analyzer/+Scripts/BECToDroplets/plotImages.m +++ b/Data-Analyzer/+Scripts/BECToDroplets/plotImages.m @@ -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; diff --git a/Data-Analyzer/+Scripts/BECToDroplets/runFullAnalysis.m b/Data-Analyzer/+Scripts/BECToDroplets/runFullAnalysis.m index 3f04f86..2d10bc0 100644 --- a/Data-Analyzer/+Scripts/BECToDroplets/runFullAnalysis.m +++ b/Data-Analyzer/+Scripts/BECToDroplets/runFullAnalysis.m @@ -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); \ No newline at end of file