[FieldTrip] re-referencing using neuralynx.csc channels
Peter Kaskan
peter.kaskan at einsteinmed.edu
Tue Apr 25 23:06:13 CEST 2023
Thanks for your help Jan-Matijs,
I implemented your corrected loop and I am now reading in multiple .csc channels using
alldata = ft_appenddata([], data{:});
I think I read somewhere that one should define re-referencing before running ft_preprocessing. However, ft_preprocessing occurs within this loop:
for k = 1:numel(channellist)
cfg.dataset = sprintf('%s.ncs',channellist{k});
data{k} = ft_preprocessing(cfg);
end
It seems like I should insert this in the loop (above, before ft_preprocessing), because I want to use channel 84 as a reference for each channel.
cfg.reref = 'yes';
cfg.refchannel = 'CSC84.ncs';
But this construction throws errors:
Error using preproc (line 279)
reference channel was not found
Error in ft_preprocessing (line 599)
[cutdat{i}, label, time{i}, cfg] = preproc(dat, hdr.label(rawindx),
tim, cfg, begpadding, endpadding);
Any guidance you can provide?
Thank you!
------------------------------
Message: 2
Date: Tue, 11 Apr 2023 20:30:18 +0000
From: Peter Kaskan <peter.kaskan at einsteinmed.edu>
To: "fieldtrip at science.ru.nl" <fieldtrip at science.ru.nl>
Subject: Re: [FieldTrip] fieldtrip Digest, Vol 148, Issue 24
Hello Jan-Mathijs,
Thanks for the reply; I was traveling and just got back to this...
In my initial, very rudimentary preprocessing script, cfg.dataset will take a single neuralynx file:
cfg.dataset = 'CSC4.ncs';
cfg.continuous = 'yes';
highpass, lowlass, demean, detrend etc..
filtContData = ft_preprocessing(cfg);
But the question was how to reference one channel with another.
I have been trying to implement your channellist and appenddata suggestion as you describe (below) using channellist = {'CSC1.ncs'; 'CSC2.ncs'; 'CSC3.ncs'} and the subsequent data loop.
However, my initial attempt left some errors related to
Error using ft_checkconfig (line 163)
The field cfg.datafile is required
The field cfg.headerfile is required
Error in ft_preprocessing (line 385)
cfg = ft_checkconfig(cfg, 'required', {'headerfile', 'datafile'});
After digging a little further in ft_preprocessing lines 446-447
% translate the channel groups (like 'all' and 'MEG') into real labels
cfg.channel = ft_channelselection(cfg.channel, hdr);
assert(~isempty(cfg.channel), 'the selection of channels is empty');
... we rescued the error by resetting
cfg.channel = CSC1.ncs;
Do you know what is happening? If we use: channellist = {'CSC1.ncs'; 'CSC2.ncs'; 'CSC3.ncs'}
does the cfg.datafile and cfg.headerfile need to be defined some other way?
Thanks, Peter
________________________________
From: fieldtrip <fieldtrip-bounces at science.ru.nl> on behalf of fieldtrip-request at science.ru.nl <fieldtrip-request at science.ru.nl>
Sent: Monday, March 27, 2023 6:00 AM
Hi Peter,
ft_read_data is a so-called ‘intermediate’ level fieldtrip function and not typically called directly by the casual user.
I think your use case calls for the following strategy:
channellist = {‘channel1’;’channel2’;…’channelN’};
for k = 1:numel(channellist)
cfg.channel = channellist{k}; % or something equivalent, at least instructing the reading function to grab a channel specific file
data{k} = ft_preprocessing(cfg);
end
alldata = ft_appenddata([], data{:});
Once you have the alldata object, you can apply re-referencing. Perhaps indeed this is best done by creating a ‘montage’, and apply it to the data.
Best wishes,
Jan-Mathijs
On 23 Mar 2023, at 22:12, Peter Kaskan via fieldtrip <fieldtrip at science.ru.nl<mailto:fieldtrip at science.ru.nl>> wrote:
Hello,
I am writing a ft_preprocessing script; I can give it channel1.csc and proceed with filtering, defining trials etc.
...but, how do I re-reference to another channel?
Is there a way to use ft_read_data to create a structure with all channels, and then tell it what channel I want to use as a reference?
Or do I need to create a montage, and how do I do that with n #s of separate neuralynx.csc channels?
Thanks - Peter
------------------------------
Message: 3
Date: Wed, 12 Apr 2023 06:30:21 +0000
From: "Schoffelen, J.M. (Jan Mathijs)"
<janmathijs.schoffelen at donders.ru.nl>
Hi Peter,
Apologies, I was a bit sloppy in my earlier code snippet. I think it should have read something like this
channellist = {‘channel1’;’channel2’;…’channelN’};
cfg = [];
cfg.<someoptionsfor filtering etc>
for k = 1:numel(channellist)
%% NOT THIS: cfg.channel = channellist{k}; % or something equivalent, at least instructing the reading function to grab a channel specific file
cfg.dataset = sprintf(‘%s.ncs’,channellist{k});
data{k} = ft_preprocessing(cfg);
end
If each channel is represented as a single file, ft_preprocessing needs to be instructed in each iteration of the loop with a fresh cfg.dataset
Once you have ‘appended’ the channels through ft_appenddata (note that this requires each of the channels' data structures to have the same number of samples) , you should be able to re-reference.
I hope that this helps to get you on your way.
Good luck,
Jan-Mathijs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20230425/98867c03/attachment.htm>
More information about the fieldtrip
mailing list