Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load discontinuous Neuralynx data as epochs #1155

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ludovicbellier
Copy link
Contributor

Hi there,

As discussed on issue #1128, here's a way to automatically load discontinuous Neuralynx data as epochs (and to avoid getting repeated, artifactual samples in our data due to the pause/stop built-in feature).

Best,
Ludovic

trl(i,1) = (i-1)*hdr.nSamples + 1;
trl(i,2) = (i )*hdr.nSamples ;
trl(i,3) = -hdr.nSamplesPre;
if isfield(hdr, 'trl')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you cannot suddenly add a field to the output of ft_read_header and start using that here. That breaks the API, which is shared with EEGLAB, SPM and other software. See http://www.fieldtriptoolbox.org/development/module/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok good to know. Thanks to your suggestion I created ft_trialfun_neuralynx.m, and besides the fact that I now have to add a few lines before my call to ft_preprocessing, this is indeed way cleaner!

% construct the header that applies to all channels combined
hdr.nChans = length(label);
hdr.label = label;
hdr.filename = fname;
hdr.nTrials = 1; % it is continuous
hdr.nTrials = nTrials;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is fine if all trials have the same length.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please note that hdr.nSamples*hdr.nTrials should correspond to the total number of samples in the file.

hdr.nSamplesPre = 0; % it is continuous

hdr.nSamplesPre = 0;
hdr.trl = trl;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you cannot add fields to the hdr structure.

@robertoostenveld
Copy link
Contributor

One solution would be an implementation similar to https://github.com/fieldtrip/fieldtrip/blob/master/trialfun/ft_trialfun_brainvision_segmented.m
which is also a file format that can have segments of different length.

But I believe best would be to use the existing ft_read_event output and add the segments as "events" (with the appropriate event.duration). That should allow you to do something similar to

cfg = [];
cfg.dataset = xxx
cfg.trialfun = 'ft_trialfun_general';
cfg.trialdef.eventtype = 'segment';
cfg = ft_definetrial(cfg)  % this adds cfg.trl, only for the segments

data = ft_preprocessing(cfg); % this reads the segments

This is also how "trial" events are being read from some files, such as the CTF format. E.g. look at Subject01.ds, which has 3-second (900 sample) segments.

Copy link
Contributor Author

@ludovicbellier ludovicbellier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Robert,

Thanks for your comments!

I first explored your second (best) suggestion, but it bugged at line 1732 of ft_read_event while trying to load an event (.nev) file that in my case doesn't exist (my cfg.dataset is a directory which only contains .ncs files).

So I switched to your first suggestion and created ft_trialfun_neuralynx.m, basically with the code I previously inserted in fileio/private/read_neuralynx_ds.m, and it works great. However, we should remove the two previously modified files (ft_preprocessing.m and fileio/private/read_neuralynx_ds.m) from this pull request; could you please take care of this, as I am not sure how to do it without messing around with the master branch?

Please let me know if you think we should make any other changes.
Best,
Ludovic

trl(i,1) = (i-1)*hdr.nSamples + 1;
trl(i,2) = (i )*hdr.nSamples ;
trl(i,3) = -hdr.nSamplesPre;
if isfield(hdr, 'trl')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok good to know. Thanks to your suggestion I created ft_trialfun_neuralynx.m, and besides the fact that I now have to add a few lines before my call to ft_preprocessing, this is indeed way cleaner!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants