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

Expose reading attempts in Plexon2 #3401

Merged
merged 9 commits into from
Oct 18, 2024
28 changes: 25 additions & 3 deletions src/spikeinterface/extractors/neoextractors/plexon2.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class Plexon2RecordingExtractor(NeoBaseRecordingExtractor):
ids: ["source3.1" , "source3.2", "source3.3", "source3.4"]
all_annotations : bool, default: False
Load exhaustively all annotations from neo.
reading_attempts : int, default: 25
Number of attempts to read the file before raising an error
This opening process is somewhat unreliable and might fail occasionally. Adjust this higher
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to highlight that this is more common on Linux.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You think that would be helpful? if so, yes, by all means, can you make a suggestion?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I guess not. Since we are already forcing the tries (once Neo > 0.13.3 is out) then explaining when the failures occurs doesn't actually affect the user. Other than they could turn it down to 1, but it automatically only uses what it needs. So I changed my mind. I think this is good as is.

if you encounter problems in opening the file.

Examples
--------
Expand All @@ -37,8 +41,16 @@ class Plexon2RecordingExtractor(NeoBaseRecordingExtractor):

NeoRawIOClass = "Plexon2RawIO"

def __init__(self, file_path, stream_id=None, stream_name=None, use_names_as_ids=True, all_annotations=False):
neo_kwargs = self.map_to_neo_kwargs(file_path)
def __init__(
self,
file_path,
stream_id=None,
stream_name=None,
use_names_as_ids=True,
all_annotations=False,
reading_attempts: int = 25,
):
neo_kwargs = self.map_to_neo_kwargs(file_path, reading_attempts=reading_attempts)
NeoBaseRecordingExtractor.__init__(
self,
stream_id=stream_id,
Expand All @@ -50,8 +62,18 @@ def __init__(self, file_path, stream_id=None, stream_name=None, use_names_as_ids
self._kwargs.update({"file_path": str(file_path)})

@classmethod
def map_to_neo_kwargs(cls, file_path):
def map_to_neo_kwargs(cls, file_path, reading_attempts: int = 25):

neo_kwargs = {"filename": str(file_path)}

from packaging.version import Version
import neo

neo_version = Version(neo.__version__)

if neo_version > Version("0.13.3"):
neo_kwargs["reading_attempts"] = reading_attempts

return neo_kwargs


Expand Down
2 changes: 1 addition & 1 deletion src/spikeinterface/extractors/tests/test_neoextractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ class Plexon2RecordingTest(RecordingCommonTestSuite, unittest.TestCase):
ExtractorClass = Plexon2RecordingExtractor
downloads = ["plexon"]
entities = [
("plexon/4chDemoPL2.pl2", {"stream_id": "3"}),
("plexon/4chDemoPL2.pl2", {"stream_name": "WB-Wideband"}),
]


Expand Down
Loading