Process_notch combining 2 structs into 1

Hi,

There is something strange happening. I have tailored the general script encompassing all brainstorm tutorials to suit my own experiment protocol and analysis requirements. My tailored scripts worked well for one of my experiments. But this time in the second experiment I am using it with slight modifications (changes in file names etc.), I am facing a rather odd situation. I have 2 raw files for the experiment run and empty room that are loaded in the structs sFilesRun and sFilesNoise, respectively. Then the following code is used to apply notch filter for electrical line noise of 50 Hz.

sFilesRaw = [sFilesRun, sFilesNoise];
sFilesNotch = bst_process('CallProcess', 'process_notch', sFilesRaw, [], ...
    'sensortypes', 'MEG, EEG', ...
    'freqlist', [50, 100, 150], ...
    'cutoffW', 1, ...
    'useold', 0, ...
    'read_all', 0);

In the original brainstorm script and the previous tailored script, the output sFilesNotch was a 1x2 struct array. But here, it is only returning a 1x1 struct array. Is there an obvious mistake that can cause such an error that you can direct me to? I have spent an entire day in trying to find the cause. I tried using a new protocol, recopied the original FIF files, used the FIF files from the previous experiment this script worked upon. Astonishingly, FIF files from previous experiment, that were first working properly with this, also stopped working after a few times I passed them through this script.

Thank you!

Hello!

If you confirmed that your input to the CallProcess function (sFilesRaw) contains two input structures yet the output (sFilesNotch) only contains one, there is a high chance that one of the input file is causing an error in the notch process. Have you checked your report viewer to see if any error was returned? You can open it after your process call from File -> Report Viewer or using the following line of code: bst_report('Open', 'current');

You could also isolate the problematic file by running your process_notch on each file separately and finding which one does not an output. One potential issue I see right off that bat is that you have the read_all option disabled. This can cause issues if you have SSP projectors computed on your raw file. The report viewer will indicate if this was the issue.

Best,
Martin

Hi, Martin!

It turns out that the raw file for the experiment run (sFilesRun) is the problematic one here. After opening the BST report, process_notch returns an error "Conversion to char from cell is not possible.".

As suggested, I tried running the program enabling the 'read_all' option. This time there were no errors in the report viewer. However, there was nothing inside the raw notch folder of the experiment run. Also, when I try to display time series from the unfiltered raw folder of the experiment run, I get the following error:

Line 1242: sprintf
Function is not defined for 'cell' inputs.

Does that reveal anything?

Best,
Parth

Hi Parth,

Glad you isolated the issue to a single file. So it is not an issue with the notch process but rather a raw file. Is it possible to post the full error message including the whole stack so I can pinpoint where the error occurs? And please let me know your Brainstorm version in case it's not up to date.

In the meantime, you could try reviewing as raw the file again to see if that fixes the issue (if you can at least display its time series). If not, then something's definitely up with that raw file that we need to investigate further.

Best,
Martin

The full error:

***************************************************************************
** Error: Line 1242:  sprintf
** Function is not defined for 'cell' inputs.
** 
** Call stack:
** >panel_record.m>UpdateEventsList at 1242
** >panel_record.m>UpdatePanel at 976
** >panel_record.m>CurrentFigureChanged_Callback at 773
** >panel_record.m at 30
** >bst_figures.m>SetCurrentFigure at 1069
** >bst_figures.m at 60
** >view_timeseries.m at 254
** >tree_callbacks.m at 250
** >bst_call.m at 28
** >panel_protocols.m>CreatePanel/protocolTreeClicked_Callback at 123
** 
*************************************************************************** 

My Brainstorm version is 3.200615 (15-Jun-2020) running on MATLAB R2020a. My system specs are:
System memory size: 4GiB
CPU: Intel(R) Core(TM) i7-2670QM CPU @ 2.20GHz

If I manually review the raw file, it works correctly and I can see the time series.

Can I provide anything else? I am not too savvy with the developer community lingo.

Thank you for your time, Martin!

Thank you for the full error message. I believe the issue is with one of the event of your raw file: its label is a cell (e.g. {'myEvent'}) rather than a string (e.g. 'myEvent'). Is it possible that one of your custom processing scripts assigned an incorrect label name? If you can share your script, I could try to find where the issue might be coming from.

You can fix this on your already processed file via a script like the following:

myFile = '/path/to/data_0raw.mat'; % Change this value
sMat = in_bst_data(myFile);
for iEvent = 1:length(sMat.F.events)
    if iscell(sMat.F.events(iEvent).label)
        sMat.F.events(iEvent).label = sMat.F.events(iEvent).label{1};
    end
end
bst_save(file_fullpath(myFile), sMat, 'v6');

Let me know,
Martin

Hello Martin,
Good day to you!
Yeah, indeed it was my custom script to write brainstorm events in a mat-file that created the issue. Simply using curly braces instead of brackets solved the issue. Since loading events is not a necessary step before filtering, I did not think the problem can reside here.
Thank you for your time. :slight_smile:
Best,
Parth