Can not extract event from .nev file

Hi,
I am trying import data from blackrock data into brainstorm, but I can not find any trigger I send to the recording system. Seem the code use wrong logic (Use digitial IO section of in_fopen_blackrock.m) to handle the event in my data.

Can you please share an example file?
Zip it, upload it somewhere, and post the download link here.

Please describe what you would like to have access to from Brainstorm.

1 Like

As my plan, I want to import the blackrock .ns data directly. But the event info is totally wrong.

Hi, I modified some code of in_fopen_blackrock.m, skip the import of spike channel. Now, I can get my trigger correctly.

   if ~isempty(nev.Data.SerialDigitalIO.TimeStamp)
        eventCodes     = double(nev.Data.SerialDigitalIO.UnparsedData);
        nev.Data.SerialDigitalIO.Value = eventCodes - min(eventCodes);
        nev.Data.SerialDigitalIO.Type = repmat(1,size(nev.Data.SerialDigitalIO.Value));
        allTypes = [nev.Data.SerialDigitalIO.Type,nev.Data.SerialDigitalIO.Value];
        allTypes(find(allTypes(:,2)==0),:)=[];
        uniqueType = unique(allTypes, 'rows');
        
        for i = 1:size(uniqueType,1)
            iEvt = length(events) + 1;
            iOcc = ((allTypes(:,1) == uniqueType(i,1)) & (allTypes(:,2) == uniqueType(i,2)));
            events(iEvt).label      = sprintf('%d', uniqueType(i,2));
            events(iEvt).color      = [];
            events(iEvt).reactTimes = [];
            events(iEvt).select     = 1;
            events(iEvt).times      = FixSamples(hdr, round((double(nev.Data.SerialDigitalIO.TimeStamp(iOcc)) - 1) * tFactorNev)) ./ sFile.prop.sfreq;
            events(iEvt).epochs     = ones(1, 1);
            events(iEvt).channels   = cell(1, size(events(iEvt).times, 2));
            events(iEvt).notes      = cell(1, size(events(iEvt).times, 2));
        end
    end

Thank you for the example file.

With this example, I finally decided to get rid of the mandatory channels and notes fields. It was causing the "Link to raw file" to occupy several Gb on the hard drive, and taking forever to load.
Now these fields are allowed to be empty:
https://github.com/brainstorm-tools/brainstorm3/commit/427b8d952f36b7a67a80f7ec3bf4b5f212255a26

More along your direct interest, I adapted your suggestion to keep both the Spike events and the IO events:

Simply update Brainstorm to get these fixes.
Please let me know if this solves your problems.

1 Like

Thank you for your update.

I just be curious why you set eventCode to nev.Data.SerialDigitalIO.Type. My understanding is that this value seems to be the value of nev.Data.SerialDigitalIO.Value.

This change may cause a compatibility issue.
When this data is exported to EEGLAB format, its event may be processed by some plug-ins in an unpredictable way.
The screenshot shows the strange operation result of ERPLAB when dealing with Event in the form of 11-1. Left: just import to EEGLAB, Right: in ERPLAB, after convert string to number.
Screenshot 2023-03-16 at 09.48.58

You are right, it does not make much sense to map "Unparsed" values to the same logic as the missing "Type-Value" format.
In the commit below, I suggest using only "D" followed by the UnparsedValue. The letter is added mostly to avoid that it overlaps with other events in the file (D for digital).
Does it make sense?

image

This change may cause a compatibility issue.
When this data is exported to EEGLAB format, its event may be processed by some plug-ins in an unpredictable way.

I'm not sure I understand this part.
How do you export this file to EEGLAB format?

The screenshot shows the strange operation result of ERPLAB when dealing with Event in the form of 11-1. Left: just import to EEGLAB, Right: in ERPLAB, after convert string to number.

Unfortunately, I won't be able to help you with fixing the behavior of ERPLAB.
If you find bugs in that software, you could report them as a GitHub issue on the ERPLAB repository:

1 Like

Yes. Thank you for your commit.

I'm not sure I understand this part.
How do you export this file to EEGLAB format?

Export as EDF files. Finally I find the reason that causes this problem. The ERPLAB do a auto conversion from string to value.

Export as EDF files.

I recommend you don't use EDF as an exchange format between programs. It forces a conversion from double floating point precision data to int16, which may cause a loss of precision in the recordings.
If EEGLAB supports the BrainVision format, use this one (this is the recommended format for EEG data in the BIDS specification).

1 Like

Thank you.

Hi, I just notice some thing were miss here. The time stamp should also be modified. Sorry for that.

eventCodes     = double(nev.Data.SerialDigitalIO.UnparsedData);
nev.Data.SerialDigitalIO.Type = eventCodes - min(eventCodes);
nev.Data.SerialDigitalIO.Value = repmat(1,size(nev.Data.SerialDigitalIO.Value));
allTypes = [nev.Data.SerialDigitalIO.Type,nev.Data.SerialDigitalIO.Value];
nev.Data.SerialDigitalIO.TimeStamp(find(allTypes(:,2)==0) = [];
allTypes(find(allTypes(:,2)==0),:)=[];
uniqueType = unique(allTypes, 'rows');

Implemented here: https://github.com/brainstorm-tools/brainstorm3/commit/81dadb37eadf384e140757b517f7a0b23304c7f8

Does it work correctly now?

Thank you for your contribution.