[Eeglablist] Epochs rejection by script
Tarik S Bel-Bahar
tarikbelbahar at gmail.com
Wed Jul 19 15:24:59 PDT 2017
Hi Antonio, yes, here's a solution below, plz give it a try and let me
know. It will be nice if you can include your working updated code so other
eeglabers can easily learn from your experience. Cheers.
*******BEGIN
The code line example below should throw up the same window that gets
thrown up when going from the GUI (Tools>Reject Data Epochs and
clicking/using the Find Abnormal Trends), which, upon running from the gui,
displays a plot of the epochs, including previously marked epochs. After
getting the correct plot window which showed epochs and showed pre-selected
epochs and allowed me to change which epochs were selected, I then typed
eegh to get the function and settings that were run to throw up the proper
window. I then modified the pop_rejtrend settings so that no epochs are
selected by the function (setting a high threshold and low R), and so that
it shows a plot of previously marked epochs, and allows updating of the
epochs by changing/adding/removing marks on epochs. You may need to modify
settings slightly. There are otherways to get the data and previously
selected epochs plotted, but this should work for you for now until you
become an expert! Code lines below, and extra notes further below.
*************run these three llines instead of the 2 old eegplot lines in
Step 2 that I previously emailed you.
numberofsamples=EEG.srate * EEG.xmax; thecurrentchannels = 1:(EEG.nbchan);
% gets samples per epoch and channel numbers
EEG = pop_rejtrend(EEG,1,thecurrentchannels
,numberofsamples,1000000,0,2,0); %opens epoch window with marks, R set to 0)
[ALLEEG EEG CURRENTSET] = eeg_store(ALLEEG, EEG, CURRENTSET); %updates
eeglab
*************
Additional notes for Antonio:
Note that you'll have two buttons to press after making your changes. The
Update Marks button, and the ok button in the reminder window that pops up
after.
Review closely the pop_rejtrend documentation for more info. Also checkout
the eegplot documentation for other ways to show similar information.
Whenever possible, remember to test via the gui steps and eegh, and one can
usually find a solution and the correct function/settings. If you can do it
in the gui, you can do it via code, usually :) In other words, if you can
do it via the gui, you're a few steps away from doing it via code (but not
vice versa!). In particular, beginners doing eeglab coding are best off
mimicking eegh output closely
Also, for any functions you might want to use (and the ones used most by
eeglab), take time to review the documentation (help nameOfFunction, or doc
nameOfFunction).
*remember to adequately update/save your marked epochs (and eeglab
structure) before showing/viewing existing selection. For example, after
each step of artifactual epoch detection.
*I think I have the R setting correct in the code line, at 0, but you may
need to reverse it to 1.
The "update marks" button can be changed to Reject if one modifies the
pop_rejtrend settings. This would reject from gui rather than in code as in
example in previous email
*************END
On Wed, Jul 19, 2017 at 6:43 AM, Antonio Maffei <antonio.maffei at phd.unipd.it
> wrote:
> Hello Tarik,
>
> thank you for the reply.
>
> I tried your code but the problem remains since, when the data are
> plotted, the epochs marked for rejection are not highlighted in the plot,
> so it is not possible to visually confirm the goodness of the rejection
> procedure.
>
> Do you have any further suggestion to solve this issue?
>
> Antonio
>
> Antonio Maffei, Ph.D. Student
>
> Department of General Psychology (DPG)
> University of Padova
> Via Venezia 8 - 35131
> Padova, Italy
>
> email: antonio.maffei at phd.unipd.it
> office: 049 8277424
>
>
Hello Antonio,
Try something like the below within your script loop, which throws up a
gui, and then computes epochs-to-remove and then removes them.
The following might also be helpful: Reviewing the eeglab scripting online
tutorials, and the eeg.reject structure in your eeglab files. The
documentation within functions is also useful.
Does the below work for you?
.......
1.Run various artifact-epoch detection methods
then
[ALLEEG EEG CURRENTSET] = eeg_store(ALLEEG, EEG, CURRENTSET);
2. Then, within code, run the function command for showing eegplot of the
epochs.
pop_eegplot( EEG, 1, 1, 1);
3. The user should then be able to walk through the epochs, see the ones
that have been selected and those that have not been, make changes if
necessary, and then should close the gui, and then the code should keep
running the following:
[ALLEEG EEG CURRENTSET] = eeg_store(ALLEEG, EEG, CURRENTSET);
EEG = eeg_rejsuperpose( EEG, 1, 1, 1, 1, 1, 1, 1, 1); %gives a variable
named as follows with all epochs to reject: EEG.reject.rejglobal
[ALLEEG EEG CURRENTSET] = eeg_store(ALLEEG, EEG, CURRENTSET);
5. run epoch rejection using that list of epochs
for example, as follows
EEG = pop_rejepoch( EEG, EEG.reject.rejglobal ,0);
[ALLEEG EEG CURRENTSET] = eeg_store(ALLEEG, EEG, CURRENTSET);
........
Dear EEGLab users,
I have a problem in the scripting of a pipeline for semi-automated epoch
rejection.
The step I would like to accomplish are:
1) Importing the dataset
2) Performing epoch rejection based on amplitude
3) Performing epoch rejection based on linear trends
4) Review the epochs visually
5) Confirm rejection
My attempt is the following:
for i = 1:length(filenames)
% Import EEG data
dataset_name = filenames_epochs{i};
EEG = pop_loadset('filename', dataset_name, 'filepath', dirpath);
% Reject on amplitude threshold
EEG = pop_eegthresh(EEG, 1, [1:32], -100, 100, 0, 2.0391, 1, 0);
% Reject trends
EEG = pop_rejtrend(EEG, 1, [1:32], 262, 0.5, 0.3, 1, 0, 0);
% Review visually the marked epochs and confirm rejection
???????????????????????????????????
% Store the dataset
[ALLEEG, EEG, CURRENTSET] = eeg_store(ALLEEG, EEG);
end
I know how to achieve this by GUI but, as you can see, I fail to understand
how to review the marked epochs visually within the script.
Thank you for the help,
Antonio
Antonio Maffei, Ph.D. Student
Department of General Psychology (DPG)
University of Padova
Via Venezia 8 - 35131
Padova, Italy
email: antonio.maffei at phd.unipd.it
office: 049 8277424
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://sccn.ucsd.edu/pipermail/eeglablist/attachments/20170719/a59c36f5/attachment.html>
More information about the eeglablist
mailing list