Removing trials from script

Hello Francois,

I made a script to do block averaging. I first import the block in the database and mark the trial as bad depending on some criteria I have. This is working. However, when I then call baseline normalization. it's also considering the bad trials and not only the good ones. Is there something I am missing?

sTrials = bst_process('CallProcess', 'process_import_data_event', files, , ...
'subjectname', sub_name{:}, ...
'condition', '', ...
'eventname', 'Hard, Easy', ...
'timewindow', , ...
'epochtime', t_windows, ...
'createcond', 0, ...
'ignoreshort', 0, ...
'usectfcomp', 0, ...
'usessp', 0, ...
'freq', , ...
'baseline', );

for iTrial = 1:length(sTrials)
        process_detectbad('SetTrialStatus', sTrials(iTrial).FileName, ~trial_status(iTrial));
end   

% Process: DC offset correction: [-10.000s,0.000s]
sTrialsNorm = bst_process('CallProcess', 'process_baseline_norm', sTrials, [], ...
    'baseline',    t_baseline, ...
    'sensortypes', 'NIRS', ...
    'method',      'bl', ...  % DC offset correction:    x_std = x - μ
    'overwrite',   0);

% here sTrialsNorm also contains bad trials

Regards,
Edouard

The bad trials are excluded from the trial selection, not from bst_process('CallProcess',...).
It means that you'd need to use another search or select process to grab again the files from the database:
https://neuroimage.usc.edu/brainstorm/Tutorials/Scripting#Starting_a_new_script
https://neuroimage.usc.edu/brainstorm/Tutorials/PipelineEditor#Search_Database

It's probably easier to call the process process_baseline_norm with only the trials you want: sTrials(trial_status)

1 Like

thanks. it's working :slight_smile:

You may also find this useful for interfacing to mark bad trials: https://github.com/nichrishayes/ArtifactScanTool

@Nichrishayes Wouldn't you be interested in implementing this as a Brainstorm process? :slight_smile: https://neuroimage.usc.edu/brainstorm/Tutorials/TutUserProcess

@Francois, briefly yes :blush:. That'd probably be a good end solution. Not sure I'll be able to get to it in the near-term :frowning_face:. @aiwiesman may be working on that end already

Let me know if you need help with further integration, new features and new contributors are always welcome!

Hi Nick and Francois,

Yes indeed, developing a semi-automated approach to bad epoch/trial identification is on my to-do list, with help from @Raymundo.Cassani, but has unfortunately gotten a bit buried by other commitments. I'll revisit with Raymundo et al. soon and update here when we have a plan in place.

Alex