1- %% Questions
2- % There appears to be something wrong in the network level power
3- % calculations - edge level and whole brain are fine
4- % I likely made an error in the atlas
5- % Cluster has network-based stats not edge
6- % Found it - Likely problem in edge groups!
7- %
8- %% Potential fix - More resonable results!
9- % Used tril mask on extract_atlas_related_parameters for edge groups
10- % Removed atlas reordering in setupbenchmarking
11-
12- % Initial setup
1+ %% Initial setup
132scriptDir = fileparts(mfilename(' fullpath' ));
143addpath(genpath(scriptDir ));
154cd(scriptDir );
16- vars = who ; % Get a list of all variable names in the workspace
17- vars(strcmp(vars , ' RepData' )) = []; % Remove the variable you want to keep from the list
18- vars(strcmp(vars , ' GtData' )) = [];
19- clear(vars{: }); % Clear all other variables
5+ clearvars - except RepData GtData ;
206clc ;
217
22- %% Directory to save and find rep data - TODO add them all
8+ %% Directory to save and find rep data
239Params = setparams();
2410
25- %% Create storage directory - only if it does not exist
26- if ~exist(Params . save_directory , ' dir ' ) % Check if the directory does not exist
27- mkdir (Params .save_directory ); % Create the directory
11+ % Load dataset information
12+ if ~exist(' Dataset ' , ' var ' )
13+ Study_Info = load (Params .data_dir , ' study_info ' );
2814end
15+ [Params .data_set , ~ , ~ ] = get_data_set_name(Study_Info );
16+
17+ %% Process each repetition file one by one to reduce memory usage
18+ rep_files = dir(fullfile(Params .save_directory , Params .data_set , ' *.mat' ));
2919
30- if ~exist(' RepData' , ' var' ) || ~exist(' GtData' , ' var' )
31- [GtData , RepData ] = load_rep_and_gt_results(Params , ' gt_origin' , Params .gt_origin );
32- end
20+ %% Create output directory (only if it doesn't exist)
21+ Params = create_power_output_directory(Params );
3322
34- power_calculation_tprs = @(x ) summarize_tprs(' calculate_tpr' , x , GtData , ...
35- ' save_directory' , Params .save_directory );
36- dfs_struct(power_calculation_tprs , RepData );
23+ for i = 1 : length(rep_files )
24+ % Load a single repetition data file
25+ rep_file_path = fullfile(rep_files(i ).folder, rep_files(i ).name);
26+ rep_data = load(rep_file_path );
27+
28+ % Extract metadata to find corresponding GT file
29+ if isfield(rep_data , ' meta_data' ) && isfield(rep_data .meta_data , ' test_components' )
30+ gt_filename = construct_gt_filename(rep_data .meta_data );
31+ gt_file_path = [Params .gt_data_dir , Params .data_set , ' /' , gt_filename ];
32+
33+ % Load only the necessary GT data
34+ if exist(gt_file_path , ' file' )
35+ gt_data = load(gt_file_path );
36+ else
37+ warning(' GT file %s not found. Skipping...' , gt_filename );
38+ continue ;
39+ end
3740
41+ % Compute power using the extracted repetition and GT data
42+ summarize_tprs(' calculate_tpr' , rep_data , gt_data , ' save_directory' , Params .save_directory );
43+ else
44+ warning(' Metadata missing in %s , skipping...' , rep_files(i ).name);
45+ end
46+
47+ % Free memory before next iteration
48+ clear rep_data gt_data ;
49+ end
0 commit comments