About plexon LFP

Dear Francois,

I'm sorry to bother you. Recently, I was learning how to use brainstorm to process the EEG signals collected by Plexon. Unfortunately, I encountered some problems, so I took the liberty to write to you and hope to get your help.

When I record the RAW data collected by Plexon, it can be imported into brainstrom to work normally, but the sampling rate of the RAW data is 30000. If I want to record for a long time, the amount of data is too large. Therefore, I choose to record LFP ( Raw data is upsampled, and the sampling rate becomes 1000).

However, when I import the recorded LFP data, brainstorm cannot work normally, that is, the EEG data will be lost. The error is as follows:


** Error: Line 265: 数组索引必须为正整数或逻辑值(Array index must be a positive integer or logical value)。
**
** Call stack:
** >panel_time.m>GetTimeUnit at 265
** >panel_time.m>UpdatePanel at 146
** >panel_time.m at 31
** >bst_memory.m>LoadDataFile at 811
** >bst_memory.m at 72
** >view_timeseries.m at 107
** >tree_callbacks.m at 250
** >bst_call.m at 28
** >panel_protocols.m>CreatePanel/protocolTreeClicked_Callback at 123
** >bst_call.m at 28
** >panel_protocols.m>@(h,ev)bst_call(@protocolTreeClicked_Callback,h,ev) at 73
**

I also uploaded the data. The first one is the raw data. Importing it into brainstrom can work normally. The second is to downsample the data to 1000 Hz. Importing it into brainstorm can not work normally.

You can download it at the following link:

https://drive.google.com/drive/folders/1rMFjRuuI82qXafMVHlPGZAIIXGq_gnUs?usp=sharing

Thanks for all your help.

Best,

Zhang maojie

Dear Francois,
In order to make you observe the data more intuitively, I also exported the PLX file as a mat file and uploaded it again. You can download these data at the following link.
https://drive.google.com/drive/folders/1rMFjRuuI82qXafMVHlPGZAIIXGq_gnUs?usp=sharing
Looking forward to your reply.
Best,
Zhang maojie

The links you shared are not public, we can't download them.

Dear Francois,
I am so sorry for my mistake.
I have changed the permissions for the link. You can download the data at the following link:
https://drive.google.com/drive/folders/1rMFjRuuI82qXafMVHlPGZAIIXGq_gnUs?usp=sharing
Looking forward to your reply.
Best,
Zhang maojie

The function we use for reading the older .plx files is readPLXFileC, which has not been updated since 2013: https://www.mathworks.com/matlabcentral/fileexchange/42160-readplxfilec

With the short file uploaded here, this reader returns an empty list of values for all the continuous channels.
In in_fopen_plexon.m, line 92: one_channel.ContinuousChannels(CHANNELS_SELECTED(1)).Values is empty. Therefore, the file is considered empty and no data can be read from it.

@maojie Could it be that this downsampled file contains only some waveform and spike information, and no continuous data?

The Plexon SDK also allows reading the .plx files: https://neuroimage.usc.edu/brainstorm/e-phys/Introduction#Importing_PL2_Plexon_files
In Brainstorm, this library is used for reading the newer .pl2 files only, but not the .plx files.
However, it seems to be working for this short .plx file, or at least, the output file is not empty:

> [n, npw, ts, wave] = plx_waves('02LFP.plx',1,0);
> size(wave)

I'm not sure what this means, or why this choice of not using the PlexonSDK for both file formats was initially made.
Rewriting the Brainstorm .plx reader using the PlexonSDK might be possible, but would require recoding everything because the structures of the two readers are very different. Additionally, this would not be possible without a proper set of test files.

@mpompolas @MartinC @Sylvain
Could you please shed some light on this topic?

Dear Francois,
I'm not sure about the answer to this question, but when I use NeuroExplorer to convert PLX files to mat format, there is data in it.
What puzzles me more is that I re collected raw data today. When I imported it into brainstorm, I found that the data was also lost. But my import process is as like as last time, it is really confusing.
Could you please help me? I upload the data collected today to the cloud disk. You can download it at the following link:
https://drive.google.com/drive/folders/1HWljybxajIpZzPfn9o1iHRgssDTgr2is?usp=sharing
Looking forward to your reply.
Best,
Zhang maojie

Thanks for the example file.
We could work on adding the support for the .plx file format using the PlexonSDK.

However I was hoping to hear back from @mpompolas @MartinC @Sylvain before trying this, as it might be detrimental to their work...

Hi all,

I will start working on this project again and take care of the invasive neurophysiology issues. @francois feel free to tag me on them.

Initially (2016?) we supported only .plx. Maybe the PlexonSDK was not freely available back then. But honestly, I can't really remember why we did this. Might be worth rewriting the .plx/.pl2 for the PlexonSDK.

I'll look into it and also check @maojie 's dataset

Dear mpompolas,
Thank you for all your help. If you have any questions about the dataset, please do not hesitate to contact me immediately.
Best,
Zhang maojie

Hi @maojie,

I updated the plexon importer.
Done here:

@mpompolas
I added the Plexon SDK as a Brainstorm plugin: https://github.com/brainstorm-tools/brainstorm3/commit/2e9da84f0753498ba90eccc9b029e9ea993e18a0

Please note that your recent updates do not allow loading the .plx files that have been posted on this page.
The error is the following:

** Error: Line 117: Index exceeds the number of array elements. Index must not exceed 0.
** 
** Call stack:
** >in_fopen_plexon.m at 117
** >in_fopen.m at 155
** >import_raw.m at 126
** >bst_call.m at 28
** >tree_callbacks.m>@(h,ev)bst_call(@import_raw,[],[],iSubject) at 660

That's very weird. I tested it on this exact file.

I'll update and try again

I was able to replicate your issue.

It is related to mexPlex within plx_info.m.

There are 2 options for loading a .plx file:

fullread - if 0, reads only the file header
%              if 1, reads the entire file

This function needs at least once to be called with a full read option (fullread =1) after a Matlab restart.
I guess while I tested the functions to build the importers I tried that option!

Every subsequent call can be done with the parameter set to 0 for reading just the header as was done on the commit..

For small example files it's ok to go with either 0 or 1.

However, since in invasive neurophysiology the data we encounter can be very big files I am very hesitant to enable a full file read by default.

We have three options:

  1. introduce a tiny .plx file with the Brainstorm distribution (just a few samples). This would allow the importer to do a full load of this tiny file in order for the mex file to get initialized (someone needs to provide this file).
  2. do a try/catch to try the first time for the importer to load the entire file after a restart, and every subsequent loading will be done with just the header (if the first file to be loaded is huge, this means trouble).
  3. Try to find a way to initialize the mexPlex without a full load.

Thanks for this starting point for the debugging.

I think this is even more complicated than what you described: there is something wrong with the mex-file mexPlex. With fullread=0, the output depends on the previous call to mexPlex with fullread=1.

Example below, based only on the example files from the Plexon SDK.
This shows the contents of variable evcounts for the first file 16sp_lfp_with_2coords.plx, read with fullread=0. Before, another file is read with fullread=1.

PlexonSdkDir = 'C:\Users\franc\.brainstorm\plugins\plexon\Matlab Offline Files SDK';
PlxFiles = {...
    [PlexonSdkDir '\mexPlex\tests\16sp_lfp_with_2coords.plx'], ...
    [PlexonSdkDir '\mexPlex\tests\opx141ch1to3analogOnly003.plx'], ...
    [PlexonSdkDir '\mexPlex\tests\opx141spkOnly004.plx'], ...
    [PlexonSdkDir '\mexPlex\tests\waveform_freq_zero.plx']};

for iPrevious = 1:length(PlxFiles)
    [a,b,c,d] = mexPlex(4, PlxFiles{iPrevious}, 1);
    [spikes_tscounts, wfcounts, evcounts, contcounts] = mexPlex(4, PlxFiles{1}, 0);
    disp([sprintf('%d ', evcounts) 10]);
end

Error: the output is not consistent, which does not seem to make much sense:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1924 1 1 

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 

I will send an email to the Plexon customer support.
In the meantime, you might need to consider ALWAYS using fullread =1...

Nice catch Francois.

Given our options, I will change it to fullread=1 until the plexon side figures it out.