[FieldTrip] marking artifacts by channel + trial

Tim Meehan timeehan at gmail.com
Thu Mar 9 16:37:02 CET 2017


So far I've just been using ft_databrowser in the same way you mention to
look for artifacts that affect most or all channels. But I think I will
need to also visually check each channel for bad trials. Since I'm working
with iEEG, these will be mainly those picking up any epileptic discharges.
Of course the channels around the seizure foci I will throw out entirely.

I'm a bit daunted by how much work it will be to do a channel x trial
visual rejection since I have ~1700 trials and ~ 100 channels for our one
subject so far. In fact just typing those numbers makes me think it may not
be feasible. Do you find the automated rejection works satisfactorily for
you?

On Wed, Mar 8, 2017 at 3:35 PM, Teresa Madsen <braingirl at gmail.com> wrote:

> I actually do a mix of approaches:  a quick look using ft_databrowser with
> all channels for irregular artifacts like disconnection events, then a
> channel-by-channel search for large z-value artifacts and clipping
> artifacts, then I remove all those and do one last ft_databrowser review of
> all channels together.  I'll attach the function I was working on, but it's
> more complex than you originally asked for and not fully tested yet, so use
> at your own risk.
>
> Do you use ft_databrowser or ft_rejectvisual for visual artifact rejection?
>
> ~Teresa
>
>
> On Wed, Mar 8, 2017 at 12:04 PM, Tim Meehan <timeehan at gmail.com> wrote:
>
>> Thanks for sharing! I'm just taking a look now. It looks like you're
>> doing mostly automated rejection. Or are you also doing visual rejection
>> along with the z-value thresholding?
>>
>> Thanks again,
>> Tim
>>
>> On Fri, Mar 3, 2017 at 5:31 PM, Teresa Madsen <braingirl at gmail.com>
>> wrote:
>>
>>> Here's a rough sketch of my approach, with one custom function
>>> attached.  If you or others find it useful, maybe we can think about ways
>>> to incorporate it into the FieldTrip code.  I've been working mostly with
>>> scripts, but you've inspired me to work on functionizing the rest of it so
>>> it's more shareable.
>>>
>>> So, assuming raw multichannel data has been loaded into FieldTrip
>>> structure 'data' with unique trial identifiers in data.trialinfo...
>>>
>>> for ch = 1:numel(data.label)
>>>   %% pull out one channel at a time
>>>   cfg = [];
>>>   cfg.channel = data.label{ch};
>>>
>>>   datch{ch} = ft_selectdata(cfg, data);
>>>
>>>   %% identify large z-value artifacts and/or whatever else you might
>>> want
>>>
>>>   cfg = [];
>>>   cfg.artfctdef.zvalue.channel        = 'all';
>>>   cfg.artfctdef.zvalue.cutoff         = 15;
>>>   cfg.artfctdef.zvalue.trlpadding     = 0;
>>>   cfg.artfctdef.zvalue.fltpadding     = 0;
>>>   cfg.artfctdef.zvalue.artpadding     = 0.1;
>>>   cfg.artfctdef.zvalue.rectify        = 'yes';
>>>
>>>   [~, artifact.zvalue] = ft_artifact_zvalue([], datch{ch});
>>>
>>>   %% replace artifacts with NaNs
>>>   cfg = [];
>>>   cfg.artfctdef.zvalue.artifact = artifact.zvalue;
>>>   cfg.artfctdef.reject          = 'nan';
>>>
>>>   datch{ch} = ft_rejectartifact(cfg,datch{ch});
>>> end
>>>
>>> %% re-merge channels
>>> data = ft_appenddata([],datch);
>>>
>>> %% mark uniform NaNs as artifacts when they occur across all channels
>>> % and replace non-uniform NaNs (on some but not all channels) with
>>> zeroes, saving times
>>> [artifact,data,times] = artifact_nan2zero_TEM(data) % custom function,
>>> see attached
>>>
>>> %% reject artifacts by breaking into sub-trials
>>> cfg = [];
>>> cfg.artfctdef.nan2zero.artifact = artifact;
>>> cfg.artfctdef.reject            = 'partial';
>>>
>>> data = ft_rejectartifact(cfg,data);
>>>
>>> %% identify real trials
>>> trlinfo = unique(data.trialinfo,'rows','stable');
>>>
>>> for tr = 1:size(trlinfo,1)
>>>
>>>   %% calculate trial spectrogram
>>>
>>>   cfg = [];
>>>
>>>   cfg.trials = ismember(data.trialinfo, trlinfo(tr,:), 'rows');
>>>   cfg.keeptrials = 'no';             % refers to sub-trials
>>>
>>>   cfg.method     = 'mtmconvol';
>>>
>>>   cfg.output     = 'powandcsd';
>>>
>>>   cfg.foi = 2.^(0:0.1:log2(300));    % 83 freqs, log2 spaced, 1-300 Hz
>>>   cfg.tapsmofrq  = cfg.foi/10;       % smooth by 10%
>>>   cfg.t_ftimwin  = 2./cfg.tapsmofrq; % for 3 tapers (K=3), T=2/W
>>>   cfg.toi        = '50%';
>>>   cfg.pad        = 'nextpow2';
>>>
>>>
>>>   freq = ft_freqanalysis(cfg,data);
>>>
>>>   %% replace powspctrm & crsspctrum values with NaNs
>>>   % where t_ftimwin (or wavlen for wavelets) overlaps with artifact
>>>   for ch = 1:numel(freq.label)
>>>     badt = [times{tr,ch}];
>>>     if ~isempty(badt) && any(...
>>>         badt > (min(freq.time) - max(freq.cfg.t_ftimwin)) & ...
>>>         badt < (max(freq.time) + max(freq.cfg.t_ftimwin)))
>>>       ci = find(any(strcmp(freq.label{ch}, freq.labelcmb)));
>>>       for t = 1:numel(freq.time)
>>>         for f = 1:numel(freq.freq)
>>>           mint = freq.time(t) - freq.cfg.t_ftimwin(f);
>>>           maxt = freq.time(t) + freq.cfg.t_ftimwin(f);
>>>           if any(badt > mint & badt < maxt)
>>>             freq.powspctrm(ch,f,t) = NaN;
>>>             freq.crsspctrm(ci,f,t) = NaN;
>>>           end
>>>         end
>>>       end
>>>     end
>>>   end
>>>
>>>   %% save corrected output
>>>
>>>   save(['trial' num2str(tr) 'mtmconvolTFA.mat'], 'freq', '-v7.3');
>>> end
>>>
>>>
>>>
>>> On Thu, Mar 2, 2017 at 9:55 AM, Tim Meehan <timeehan at gmail.com> wrote:
>>>
>>>> Hi Teresa,
>>>>
>>>> Thanks for the reply. I'll take a look at your example if you don't
>>>> mind sharing. Thanks!
>>>>
>>>> Tim
>>>>
>>>> On Thu, Mar 2, 2017 at 9:53 AM, Teresa Madsen <braingirl at gmail.com>
>>>> wrote:
>>>>
>>>>> No, not really.  The only way I've found to do that is to loop through
>>>>> my artifact rejection process on each trial individually, then merge them
>>>>> back together with NaNs filling in where there are artifacts, but then that
>>>>> breaks every form of analysis I want to do.  :-P
>>>>>
>>>>> I wonder if it would work to fill in the artifacts with 0s instead of
>>>>> NaNs....I might play with that.  Let me know if you're interested in some
>>>>> example code.
>>>>>
>>>>> ~Teresa
>>>>>
>>>>>
>>>>> On Wed, Mar 1, 2017 at 3:55 PM, Tim Meehan <timeehan at gmail.com> wrote:
>>>>>
>>>>>> Hello All,
>>>>>>
>>>>>> When performing visual artifact rejection, I want to be able to mark
>>>>>> artifacts that occur during some specific trials and only on some specific
>>>>>> channels. In the tutorials I see only ways to mark bad channels (i.e.
>>>>>> across all trials) or bad trials (i.e. across all channels). Does FieldTrip
>>>>>> handle marking artifacts restricted to some channel/trial combination?
>>>>>>
>>>>>> Thanks,
>>>>>> Tim
>>>>>>
>>>>>> _______________________________________________
>>>>>> fieldtrip mailing list
>>>>>> fieldtrip at donders.ru.nl
>>>>>> https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Teresa E. Madsen, PhD
>>>>> Research Technical Specialist:  *in vivo *electrophysiology & data
>>>>> analysis
>>>>> Division of Behavioral Neuroscience and Psychiatric Disorders
>>>>> Yerkes National Primate Research Center
>>>>> Emory University
>>>>> Rainnie Lab, NSB 5233
>>>>> 954 Gatewood Rd. NE
>>>>> Atlanta, GA 30329
>>>>> (770) 296-9119
>>>>> braingirl at gmail.com
>>>>> https://www.linkedin.com/in/temadsen
>>>>>
>>>>> _______________________________________________
>>>>> fieldtrip mailing list
>>>>> fieldtrip at donders.ru.nl
>>>>> https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> fieldtrip mailing list
>>>> fieldtrip at donders.ru.nl
>>>> https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>>>>
>>>
>>>
>>>
>>> --
>>> Teresa E. Madsen, PhD
>>> Research Technical Specialist:  *in vivo *electrophysiology & data
>>> analysis
>>> Division of Behavioral Neuroscience and Psychiatric Disorders
>>> Yerkes National Primate Research Center
>>> Emory University
>>> Rainnie Lab, NSB 5233
>>> 954 Gatewood Rd. NE
>>> Atlanta, GA 30329
>>> (770) 296-9119
>>> braingirl at gmail.com
>>> https://www.linkedin.com/in/temadsen
>>>
>>> _______________________________________________
>>> fieldtrip mailing list
>>> fieldtrip at donders.ru.nl
>>> https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>>>
>>
>>
>> _______________________________________________
>> fieldtrip mailing list
>> fieldtrip at donders.ru.nl
>> https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>>
>
>
>
> --
> Teresa E. Madsen, PhD
> Research Technical Specialist:  *in vivo *electrophysiology & data
> analysis
> Division of Behavioral Neuroscience and Psychiatric Disorders
> Yerkes National Primate Research Center
> Emory University
> Rainnie Lab, NSB 5233
> 954 Gatewood Rd. NE
> Atlanta, GA 30329
> (770) 296-9119
> braingirl at gmail.com
> https://www.linkedin.com/in/temadsen
>
> _______________________________________________
> fieldtrip mailing list
> fieldtrip at donders.ru.nl
> https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20170309/fa0369fd/attachment.html>


More information about the fieldtrip mailing list