Save kernels for source analysis with different names

Hello,

I'm applying inverse solutions to my data and I want to try different parameters (regularize noise covariance, use median eigenvalue, etc.). In doing so, there is an option to set a comment to give different names to the different files generated (kernels). However, despite the names provided in the comment section can be seen in the GUI, in my data folder these tags are not present (like 'source_option_eigenvalue'). Intead, if I am not using the gui I can only distinguish these files by their date.

I tried with 'set name' and 'add tag' options and the results are the same, the tags can be seen in the gui but are not present in the actual files, which makes it difficult to call them with code. Any suggestions?

Many thanks in advance,

Fran

Use the process "Add tad" with the option "Add to file path".

image

Hi Francois,

Unfortunatelty, this is an option I already tried. And I get the following error.

Add_tag_kernel

Indeed, there was a bug when renaming the source links or shared inverse kernels.
I tried to fix this issue with this commit: https://github.com/brainstorm-tools/brainstorm3/commit/bd6b5084c82558501a1b6d34a61a4692c5bb680a

Please update Brainstorm and try again

1 Like

Hello,
I would like to do exactly the same kind of pipeline as Fran using a script to loop over subjects: computing different kernels and name them accordingy in the database (for example: constrained, unconstrained, etc... rather than having the date), and I was trying to rename the files using the process_add_tag after having called process_inverse_2018 :

%this is my script:
 sFiles_constr =  bst_process('CallProcess', 'process_inverse_2018', sFiles, [], ...
        'output',  1, ...  % Kernel only: shared
        'inverse', struct(...
        'Comment',        'MN: MEG ALL', ...
        'InverseMethod',  'minnorm', ...
        'InverseMeasure', 'amplitude', ...
        'SourceOrient',   {{'fixed'}}, ...
        'Loose',          0.2, ...
        'UseDepth',       1, ...
        'WeightExp',      0.5, ...
        'WeightLimit',    10, ...
        'NoiseMethod',    'reg', ...
        'NoiseReg',       0.1, ...
        'SnrMethod',      'fixed', ...
        'SnrRms',         1e-06, ...
        'SnrFixed',       3, ...
        'ComputeKernel',  1, ...
        'DataTypes',      {{'MEG GRAD', 'MEG MAG'}}));
    
    % Process: Add tag: _constr
    bst_process('CallProcess', 'process_add_tag', sFiles_constr, [], ...
        'tag',           '_constr', ...
        'output',        2);  % Add to file path

but I get following error:

Dot indexing is not supported for variables of this type.

Error in bst_process>Run (line 285)
allStudies = bst_get('Study', unique([sInputs.iStudy]));

Error in bst_process>CallProcess (line 2305)
OutputFiles = Run(sProcess, sInputs, sInputs2, 0);

Error in bst_process (line 38)
eval(macro_method);

Error in MYSCRIPT (line 48)
bst_process('CallProcess', 'process_add_tag', sFiles_constr, , ...

After what, the gui is seemingly unresponsive (turning wheel), and I cannot access File>View File Contents because I get this error:

Error using load

Unable to read file 'MYPATH/results_MN_MEG_GRAD_MEG_MAG_KERNEL_230427_0954.mat'. No such file or directory.

Error in view_struct (line 36)
MatContents = load(filename);

Error in tree_callbacks>@(h,ev)view_struct(filenameFull) (line 2403)
gui_component('MenuItem', jMenuFile, , 'View file contents', IconLoader.ICON_MATLAB, , @(h,ev)view_struct(filenameFull));

Which is indeed correct because the file HAS BEEN renamed in brainstorm_db with the tag _constr but somehow something is blocking the update...

Maybe relevant information: I am doing that at the Subject level and it appears under Common files because I have one headmodel per participant that I chose to share accross runs.

Thank you!
Julie

Hi Julie,

Thank you for provided detailed information. This was the issue, the process_add_tag did not handle properly kernel files that were shared (per Subject, or across Subjects). This is corrected now in commit 19c19ef.

Please update your Brainstorm instance and try again.

Best,
Raymundo

Hello Raymundo,
thanks! it works like a charm now!
Julie

Hello again!
It is somehow not always working: from the example I wrote before it works well: giving the output of process_inverse_2018 to the process_add_tag gave the expected result: adding the _constr tag to the file in @default_study folder of my subject.
But now I would like to rename something I just added to the @default_study folder (a decoding cortical activation matrix with ImageGridAmp filled) through db_add which I want to rename in the database:

[~, iStudy] = bst_get('Study',sprintf('%s/%s/@default_study/brainstormstudy.mat',bst_path,SubjectName));

OutputFile = db_add(iStudy,zdecoding);
 
% Process: Add tag: _MYTAG
bst_process('CallProcess', 'process_add_tag', OutputFile, [], ...
            'tag',           'MYTAG', ...
            'output',        2);  % Add to file path

and I get the same error as previously:

Dot indexing is not supported for variables of this type.

Error in bst_process>Run (line 285)
allStudies = bst_get('Study', unique([sInputs.iStudy]));

Error in bst_process>CallProcess (line 2305)
OutputFiles = Run(sProcess, sInputs, sInputs2, 0);

Error in bst_process (line 38)
eval(macro_method);

Error in MYSCRIPT_import_zdec (line 40)
bst_process('CallProcess', 'process_add_tag', OutputFile, , ...

the .mat file I am importing is imported without problem and actually renamed in the database folder @default_study.

Am I doing something wrong?

Thanks!

No, your code is correct.

At fixing process_add_tag for shared kernels I broke it for other non-kernel files.
This is now fixed at: commit 1a63c9a. Just update your Brainstorm instance to see this change.

Thank you for the detailed bug reporting!

it works! thank you!!