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

Issue with reading .pl2 files #1349

Closed
Bosswang12138 opened this issue Nov 16, 2023 · 16 comments
Closed

Issue with reading .pl2 files #1349

Bosswang12138 opened this issue Nov 16, 2023 · 16 comments
Assignees
Labels
Milestone

Comments

@Bosswang12138
Copy link

Bosswang12138 commented Nov 16, 2023

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.

@h-mayorquin
Copy link
Contributor

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

can you run?

import platform

platform.architecture()

@Bosswang12138
Copy link
Author

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')

@h-mayorquin
Copy link
Contributor

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

@Bosswang12138
Copy link
Author

@h-mayorquin Are you referring to this branch(#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(NeuralEnsemble/pypl2@2b25881), @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?

@apdavison apdavison added this to the 0.14.0 milestone Feb 23, 2024
@jklembcz
Copy link

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 (NeuralEnsemble/pypl2@2b25881), 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!

@h-mayorquin
Copy link
Contributor

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

@jklembcz
Copy link

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
Copy link

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.

@h-mayorquin
Copy link
Contributor

h-mayorquin commented Mar 25, 2024

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.

@bendichter
Copy link
Contributor

cc @yerbamati

@bendichter
Copy link
Contributor

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

@cheydrick
Copy link
Contributor

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

@h-mayorquin
Copy link
Contributor

h-mayorquin commented Jun 22, 2024

Hi, @cheydrick, I will test this against the three OSs on neuroconv:
catalystneuro/neuroconv#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.

samuelgarcia added a commit that referenced this issue Jun 28, 2024
Patch for issue #1349 Issue with reading .pl2 files
@zm711
Copy link
Contributor

zm711 commented Jun 28, 2024

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!

@bendichter
Copy link
Contributor

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

@zm711
Copy link
Contributor

zm711 commented Jul 1, 2024

That sounds good to me. :)

@zm711 zm711 closed this as completed Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants