Importing events from Intan (.rhd) recordings and saving them to brainvision core data format/edf

Hi,

We have iEEG data acquired using Intan. All of the data was saved in a .rhd file. When I read the rhd file using Intan's functions, I see the events/pulse signal saved as a board digital inputs channels (DIN-001). However, when trying to detect it in brainstorm, it shows me an error. It seems like brainstorm is only detecting the amplifier channels. Is there a way to also read the DIN channels?

We're also trying to save these files into either brainvision core format or edf. Is there any format that you recommend over the other? I'm assuming that each condition and subject need to be saved as an individual file, right?

Thanks!

Can you please share a short example file, for us to try and reproduce this issue?
(upload the file somewhere and post the download link here)

@mpompolas Do you know what this is about?

We're also trying to save these files into either brainvision core format or edf. Is there any format that you recommend over the other?

The two formats are supported in the BIDS specification, therefore most programs will hopefully in the future support the two: Redirecting...

I'd recommend using the BrainVision format: it offers more flexibility in terms of events/triggers, and can store data of various data types while the EDF format is limited to int16.
The only reason for which you'd prefer EDF over the BrainVision format is if you needed to import these files in a software that supports EDF only.

Hi Francois,

Thank you for your help, here's the link with the data B2-3Hz_210827_155257.rhd - Google Drive

Best,
Amada

Thanks for the example file.
Unfortunately, I am not familiar enough with this format to understand clearly what you're expecting to find in this file.

Could you run the following comment from the Matlab command window:
newHeader = read_Intan_RHS2000_file(path_to_rhd,1,1,1,100);
And let me know which information described in the header you think is missing in the Brainstorm displays?

If you are comfortable enough with Matlab coding:
Can you try to figure out how to call read_Intan_RHS2000_file in order to get the data you want to see displayed?

As an example, it is called for reading the amplifier channels here:

Hi Francis,

Thank you your answer. After reviewing the in_fread_intan function I can see the problem now, and I will try to explain it below for whomever has the same question as me.

Our electrode data is saved in the amplifiers_channels. As mentioned earlier the events are saved in board_dig_in_channels (this is how we configured our task). The in_fread_intan function ONLY reads the amplifiers_channels, and not the other ones. I'll add a line at the end that reads our pulse signal in board_dig_in_channels

Hi @Francois and @amadaabrego ,

I'm taking a look at your file and I see that the importer is getting values on newHeader.board_dig_in_data within in_fopen_intan, but they are all set to zero. (The length of this vector might also be problematic since nSamples=6000480 and the board_dig_in_data is 6000540x1)

The way that the events are assigned, are by detecting peaks on the board_dig_in_data vector, but since everything is zero, no events are detected.

Can you please send the Matlab command you use to detect your events in general outside of brainstorm?

I'm seeing that too! When you use directly Intan's function you do get the pulse signal that we use to separate it into individual trials.

This is the code that reads an intan file in your folder, identifies your pulse signal, neural data and time vectors. You do require more functions all found in the data-analysis folder.

Unfortunately the link does not work.

If I understand whats going on correctly, the older version that Brainstorm is based on, is returning a zeroed vector for the events, whereas yours is returning non-zero values.

I'll try an updated version of the loader from Intan's website and get back to you.

This one in particular:
https://intantech.com/files/RHD_MATLAB_functions.zip

I'm sorry, I accidentally sent you the code from our private repo and not the public one. This is the correct one.

Yes, you've summarized it well: it's returning a zeroed vector for events instead of non-zero values. It's a pulse signal that goes from 0 to 1 whenever there is being a stimulation.

I've found the problem and posting it here in case someone has this error.

In the read_Intan_RHD2000_file function, we are trying to detect how many digital channels there are in the .rhd file we're saving. The board_dig_in_raw created by this function is very different than the one the provided intan function yields. Comparing both codes side by side, I noticed that there is a ismember if statement that the original intan doesn't have. So, I commented lines 450, 452-454 and now the digital channels are correctly being read and recognized as events by brainstorm

Hi @amadaabrego ,

thanks for checking this out.
The reader for Intan was modified to accommodate efficient loading of the raw signals on the Brainstorm distribution.

It searches for the blocks that contain the data from the time bounds requested from the user. This greatly improves performance in large datasets.

I am able to detect the digital signals from with read_Inan_RHD2000 from Intan's website.

I will change the importer to convert data first to an efficient file format and post a message here once this is done

Added the new converter here:

You can test it straight from the pull request, or wait for @Francois to merge it to the main branch.

Here is a screenshot of the event detection:

The PR is merged, you can update Brainstorm and try again.

Thank you!

Hi Francois,

I just updated the code and tried uploading an Intan rhd file and get the following error:

BST> Emptying temporary directory...
Found 128 amplifier channels.
Found 6 auxiliary input channels.
Found 2 supply voltage channels.
Found 0 board ADC channels.
Found 1 board digital input channel.
Found 0 board digital output channels.
Found 0 temperature sensor channels.

No missing timestamps in data.
Applying notch filter...
Found 128 amplifier channels.
Found 6 auxiliary input channels.
Found 2 supply voltage channels.
Found 0 board ADC channels.
Found 1 board digital input channel.
Found 0 board digital output channels.
Found 0 temperature sensor channels.

No missing timestamps in data.
Applying notch filter...


** Error: Line 217: load
** File name is empty.
**
** Call stack:
** >in_fread.m at 217
** >in_data.m at 327
** >import_data.m at 200
** >bst_call.m at 28
** >tree_callbacks.m>@(h,ev)bst_call(@import_data,[],[],[],iStudy,iSubject) at 662
**


Hi @amadaabrego ,

I am not able to reproduce this error.
However, the problem seems to be on the Brainstorm side, since the Intan reader gets the header information.

Can you please describe the steps you followed after you imported the link to raw file?

I'm not sure what you're asking. I got this error when I wanted to import a new EEG intan data file

weird. it seems to be working with the other .rhd files that I tried.

Just to make sure, when you start Brainstorm, Matlab displays: Version: 28-Mar-2022

Correct?

If it does, do you mind sharing this file with me?

This is what I get:

Starting Brainstorm:
BST> =================================
BST> Version: 28-Mar-2022
BST> Compiling main interface files...
BST> Deleting old process reports...
BST> Loading configuration file...
BST> Checking internet connectivity... ok
BST> Initializing user interface...
BST> Starting OpenGL engine... hardware
BST> Reading process folder...
BST> Loading current protocol...
BST> =================================

BST> Emptying temporary directory...
BRAINAMP> Warning: Could not open VMRK markers file.

And this is the process I follow to import the data
• Import MEG/EEG
• Choose file B2-3Hz_210827_155257.rhd
• Import full time window (0 to 300s) and events, and resample at 2,000 Hz

Right click on your subject and then: "Review raw file", not "import MEG/EEG"