Getting process_source_flat.m results on the Matlab's workspace

Hi everyone!

First, I want to give thanks to the Brainstorm team, it has helped me tremendously with my master's research project, and I'm always learning how flexible it is.

For my project I'm working with the unconstrained to flat map results, I did some scripting helped by the process box to obtain said results, I save them, analyze them with my own tools, and delete them from the hard drive at the end, keeping only the recordings and kernel. I do this because I'm working with a lot of data, and it quickly consumes a lot of space.

I'm trying to skip the whole save to disk and then load them onto the workspace to optimize my pipeline (because sometimes it takes days due to the sheer amount of data). Furthermore, I already located the script that produces said results (process_source_flat if I'm not mistaken), but every time I try to mess with it to have the results saved in another variable it gets deleted at the end of the unconstrained to flat map process. So how can I have those results saved to the workspace?

This is the relevant portion of my code for reference.

    % Process: Unconstrained to flat map
    sFiles = bst_process('CallProcess', 'process_source_flat', sFiles, [], ...
        'method', 1);  % Norm: sqrt(x^2+y^2+z^2)

    % Local Maxima
    
    folder = ['/home/matlabuser/brainstorm_db/',cfolder,'/data/'];

    filepattern = fullfile(folder, '**/results_norm*.mat');

    fs = dir(filepattern);
    trial = 1;

%Here goes a lot of code and then

    % Process: Delete selected files
    sFiles = bst_process('CallProcess', 'process_delete', sFiles, [], ...
        'target', 1);  % Delete selected files 

The script computes the flat maps; searches for them on the disk to be loaded and processed by the rest of the code. I also want to point out that I do have enough RAM to handle the data loaded onto the workspace instead of saving it on the hard drive.

If your goal is to compute the norm of the three orientations (X,Y,Z) and then immediately run your own computations on the "flat" values, you can skip the file saving and call manually the computation yourself. Maybe something like this:

ResultsMat = in_bst_results(sFiles(i).FileName, 1);
ResultsMat = process_source_flat('Compute', ResultsMat, 'rms');

Does it help?

Thanks @Francois! A process just finished a few minutes ago, I'll try your suggestion with the next batch.

That worked perfectly! It significantly reduced the time by a wide margin, I'm even able to cram a few more recordings without too much impact on the computation time.

Thanks!