python-neo icon indicating copy to clipboard operation
python-neo copied to clipboard

Issue with reading .pl2 files

Open Bosswang12138 opened this issue 1 year ago • 9 comments

Describe the bug I encountered an issue while attempting to read a .pl2 file using the Plexon2RawIO from the neo library. Here's the snippet I used:

import neo.rawio from pathlib import Path

folderPath = Path(r"D:\PROGRAM") filename = Path("16ch1.pl2") fullfilename = folderPath.joinpath(filename)

r = neo.rawio.Plexon2RawIO(filename=fullfilename) r.parse_header()

The demo pl2 file were downloaded from Plexon, https://plexon.com/wp-content/uploads/2017/08/4chDemoPL2.pl2 I received the following error traceback:

File [d:\Anaconda\envs\si_env\lib\site-packages\neo\rawio\baserawio.py:178](file:///D:/Anaconda/envs/si_env/lib/site-packages/neo/rawio/baserawio.py:178), in BaseRawIO.parse_header(self)
    [165](file:///D:/Anaconda/envs/si_env/lib/site-packages/neo/rawio/baserawio.py:165) def parse_header(self):
    [166](file:///D:/Anaconda/envs/si_env/lib/site-packages/neo/rawio/baserawio.py:166)     """
    [167](file:///D:/Anaconda/envs/si_env/lib/site-packages/neo/rawio/baserawio.py:167)     This must parse the file header to get all stuff for fast use later on.
    [168](file:///D:/Anaconda/envs/si_env/lib/site-packages/neo/rawio/baserawio.py:168) 
   (...)
    [176](file:///D:/Anaconda/envs/si_env/lib/site-packages/neo/rawio/baserawio.py:176) 
    [177](file:///D:/Anaconda/envs/si_env/lib/site-packages/neo/rawio/baserawio.py:177)     """
--> [178](file:///D:/Anaconda/envs/si_env/lib/site-packages/neo/rawio/baserawio.py:178)     self._parse_header()
    [179](file:///D:/Anaconda/envs/si_env/lib/site-packages/neo/rawio/baserawio.py:179)     self._check_stream_signal_channel_characteristics()

File [d:\Anaconda\envs\si_env\lib\site-packages\neo\rawio\plexon2rawio\plexon2rawio.py:239](file:///D:/Anaconda/envs/si_env/lib/site-packages/neo/rawio/plexon2rawio/plexon2rawio.py:239), in Plexon2RawIO._parse_header(self)
    [237](file:///D:/Anaconda/envs/si_env/lib/site-packages/neo/rawio/plexon2rawio/plexon2rawio.py:237) for spike_channel_idx, spike_header in enumerate(self.header['spike_channels']):
    [238](file:///D:/Anaconda/envs/si_env/lib/site-packages/neo/rawio/plexon2rawio/plexon2rawio.py:238)     schannel_name = spike_header['name'].split('.')[0]
--> [239](file:///D:/Anaconda/envs/si_env/lib/site-packages/neo/rawio/plexon2rawio/plexon2rawio.py:239)     schannel_info = self.pl2reader.pl2_get_spike_channel_info_by_name(schannel_name)
    [241](file:///D:/Anaconda/envs/si_env/lib/site-packages/neo/rawio/plexon2rawio/plexon2rawio.py:241)     spiketrain_an = seg_ann['spikes'][spike_channel_idx]
    [242](file:///D:/Anaconda/envs/si_env/lib/site-packages/neo/rawio/plexon2rawio/plexon2rawio.py:242)     for key in spike_annotation_keys:

File [d:\Anaconda\envs\si_env\lib\site-packages\neo\rawio\plexon2rawio\pypl2\pypl2lib.py:651](file:///D:/Anaconda/envs/si_env/lib/site-packages/neo/rawio/plexon2rawio/pypl2/pypl2lib.py:651), in PyPL2FileReader.pl2_get_spike_channel_info_by_name(self, channel_name)
    [642](file:///D:/Anaconda/envs/si_env/lib/site-packages/neo/rawio/plexon2rawio/pypl2/pypl2lib.py:642) self.pl2_dll.PL2_GetSpikeChannelInfoByName.memsync = [
    [643](file:///D:/Anaconda/envs/si_env/lib/site-packages/neo/rawio/plexon2rawio/pypl2/pypl2lib.py:643)     {
    [644](file:///D:/Anaconda/envs/si_env/lib/site-packages/neo/rawio/plexon2rawio/pypl2/pypl2lib.py:644)         'p': [1],
    [645](file:///D:/Anaconda/envs/si_env/lib/site-packages/neo/rawio/plexon2rawio/pypl2/pypl2lib.py:645)         'n': True,  # null-terminated string flag
    [646](file:///D:/Anaconda/envs/si_env/lib/site-packages/neo/rawio/plexon2rawio/pypl2/pypl2lib.py:646)     }
    [647](file:///D:/Anaconda/envs/si_env/lib/site-packages/neo/rawio/plexon2rawio/pypl2/pypl2lib.py:647) ]
    [649](file:///D:/Anaconda/envs/si_env/lib/site-packages/neo/rawio/plexon2rawio/pypl2/pypl2lib.py:649) pl2_spike_channel_info = PL2SpikeChannelInfo()
--> [651](file:///D:/Anaconda/envs/si_env/lib/site-packages/neo/rawio/plexon2rawio/pypl2/pypl2lib.py:651) result = self.pl2_dll.PL2_GetSpikeChannelInfoByName(self._file_handle,
    [652](file:///D:/Anaconda/envs/si_env/lib/site-packages/neo/rawio/plexon2rawio/pypl2/pypl2lib.py:652)                                                     channel_name,
    [653](file:///D:/Anaconda/envs/si_env/lib/site-packages/neo/rawio/plexon2rawio/pypl2/pypl2lib.py:653)                                                     ctypes.byref(pl2_spike_channel_info))
    [655](file:///D:/Anaconda/envs/si_env/lib/site-packages/neo/rawio/plexon2rawio/pypl2/pypl2lib.py:655) if not result:
    [656](file:///D:/Anaconda/envs/si_env/lib/site-packages/neo/rawio/plexon2rawio/pypl2/pypl2lib.py:656)     self._print_error()

ArgumentError: argument 2: TypeError: expected c_char_Array_5 instance instead of bytes

Environment:

  • OS: [Windows]
  • Python version: 3.10
  • Neo version: 0.13.0.dev0
  • NumPy version: 1.26.0

Could you please provide guidance or assistance regarding this error? Thank you for your support.

Bosswang12138 avatar Nov 16 '23 12:11 Bosswang12138

Can you give more details about your platform, what is your architecture?

can you run?

import platform

platform.architecture()

h-mayorquin avatar Nov 17 '23 16:11 h-mayorquin

Can you give more details about your platform, what is your architecture?

can you run?

import platform

platform.architecture()

Hi, the output of platform.architecture() is ('64bit', 'WindowsPE')

Bosswang12138 avatar Nov 18 '23 08:11 Bosswang12138

Can you try this branch? https://github.com/NeuralEnsemble/python-neo/pulls

h-mayorquin avatar Nov 18 '23 09:11 h-mayorquin

@h-mayorquin Are you referring to this branch(https://github.com/NeuralEnsemble/python-neo/pull/1350)? I've attempted to use this branch just now, but unfortunately encountered the same error. I've previously encountered the issue you raised in this PR. However, I vaguely recall manually copying the 64-bit .dll file to the .plexon_dlls_for_neo folder, so it's unlikely the error is caused by conflicts between 64-bit and 32-bit .dll files.

Additionally, in this commit(https://github.com/NeuralEnsemble/pypl2/commit/2b25881e56cac6ad76ce23245ed211c701be8b5e), @JuliaSprenger committed changes stating "also accept bytes as channel names," which seems related to the error I'm experiencing. I'm not an expert in programming, could you please take a look?

Bosswang12138 avatar Nov 18 '23 11:11 Bosswang12138

Hi all,

I am getting the same error and at the same point as Bosswang12138 when trying to use neo to read pl2 files.

output: result = self.pl2_dll.PL2_GetSpikeChannelInfoByName(self._file_handle, ctypes.ArgumentError: argument 2: TypeError: expected c_char_Array_5 instance instead of bytes

I have tried to implement the commit (https://github.com/NeuralEnsemble/pypl2/commit/2b25881e56cac6ad76ce23245ed211c701be8b5e), but am still getting the same error.

For reference, I am also running 64bit Windows PE, Python 3.10, neo 13.0, and numpy 1.26.4, and also utilizing neo via SpikeInterface, just as Bosswang12138 is.

Thank you!

jklembcz avatar Feb 23 '24 18:02 jklembcz

I will give it a try next week when I get into a windows machine.

h-mayorquin avatar Feb 23 '24 19:02 h-mayorquin

Hi all,

I did some digging into the data that I was trying to access, and I found that all of the .pl2 files that NEO errors when trying to read had a column of a unit that was sorted during recording, labeled as "Unit a". I'm not entirely sure how this causes the error.

@Bosswang12138, not sure if this is still relevant to you, but using Plexon's batch processing to remove all sorted units from all channels allows my files to be read by NEO.

jklembcz avatar Feb 28 '24 16:02 jklembcz

Hey all,

I am currently attempting to use Spikeinterface and thus Neo to read some very recent pl2 files, and I am getting the exact same TypeError. These files do not have any units sorted during recording, or even any thresholded spikes that would appear on an SPK channel, so I'm not exactly sure how to approach this.

jklembcz avatar Mar 25 '24 13:03 jklembcz

Sorry guys, I just have not had the time. Plexon does not make it easier by having a close format however.

Please complain about it to Plexon or whowever makes the decision to buy the system if you ever get the chance.

h-mayorquin avatar Mar 25 '24 16:03 h-mayorquin

cc @yerbamati

bendichter avatar Jun 21 '24 19:06 bendichter

@samuelgarcia , could you please take a look at this? I have a file that reproduces the error I can send you

bendichter avatar Jun 21 '24 19:06 bendichter

Coincidentally I looked at this myself this past week and just submitted PR #1495 that I believe fixes it. Open to thoughts.

cheydrick avatar Jun 22 '24 00:06 cheydrick

Hi, @cheydrick, I will test this against the three OSs on neuroconv: https://github.com/catalystneuro/neuroconv/pull/918

I thought that the problem is that the ddls expect a different input in linux and windows but in your PR the test pass so gingers crossed. [EDIT] I see that the test have not run in your PR.

h-mayorquin avatar Jun 22 '24 15:06 h-mayorquin

Could people test this out so we can confirm this can be closed? We've merged the two PRs associated with this so getting confirmation this works for people's problems would be great!

zm711 avatar Jun 28 '24 17:06 zm711

@zm711 it seems this has been addressed. I think it would be reasonable to close this issue and reopen if the problem reappears.

bendichter avatar Jul 01 '24 13:07 bendichter

That sounds good to me. :)

zm711 avatar Jul 01 '24 13:07 zm711