NeuralEnsemble / python-neo

Neo is a package for representing electrophysiology data in Python, together with support for reading a wide range of neurophysiology file formats
http://neo.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
325 stars 248 forks source link

Refactor plexon rawio to have same ids as plexon2 #1547

Closed h-mayorquin closed 2 months ago

h-mayorquin commented 2 months ago

After #1541 Plexon2 ended up with the meaningful but unique stream_ids:

        stream_id_to_stream_name = {
            "WB": "WB-Wideband",
            "FP": "FPl-Low Pass Filtered",
            "SP": "SPKC-High Pass Filtered",
            "AI": "AI-Auxiliary Input",
        }

But in Plexon 1 we are using numbers instead: "1", "2", ...

This PR unifies them so they have the same stream_ids

zm711 commented 2 months ago

https://github.com/NeuralEnsemble/python-neo/actions/runs/10776574774/job/29883638305?pr=1547

I just want to save this failed attempt with 15 times. This is good to know since I haven't seen the runner fail since you implemented the 10 retries. This is interesting.

h-mayorquin commented 2 months ago

https://github.com/NeuralEnsemble/python-neo/actions/runs/10776574774/job/29883638305?pr=1547

I just want to save this failed attempt with 15 times. This is good to know since I haven't seen the runner fail since you implemented the 10 retries. This is interesting.

Oh, what a pain : /

zm711 commented 2 months ago

Agreed. I think explicitly setting this is probably a better idea rather than setting trying until success. So I don't know, if we set something big like 100 I don't want to slow down the test suite. Maybe we hive off plexon2 as a conditional test--only when baserawio, toml, or plexon2 changes. Any opinions?

h-mayorquin commented 2 months ago

Let's measure how much time it takes.

h-mayorquin commented 2 months ago

@zm711 This is ready.

I measured the opening on my computer for a file of around 2 GiB and it took around two milliseconds:

2.46 ms ± 58.6 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)

import platform
from urllib.request import urlopen
import pathlib 

architecture = platform.architecture()[0]
if architecture == "64bit" and platform.system() in ["Windows", "Darwin"]:
    file_name = "PL2FileReader64.dll"
else:  # Apparently wine uses the 32 bit version in linux
    file_name = "PL2FileReader.dll"
pl2_dll_folder = pathlib.Path.home() / ".plexon_dlls_for_neo"
pl2_dll_folder.mkdir(exist_ok=True)
pl2_dll_file_path = pl2_dll_folder / file_name

if not pl2_dll_file_path.exists():
    url = f"https://raw.githubusercontent.com/Neuralensemble/pypl2/master/bin/{file_name}"
    dist = urlopen(url=url)

    with open(pl2_dll_file_path, "wb") as f:
        print(f"dll file does not exist, downloading plexon dll to {pl2_dll_file_path}")
        f.write(dist.read())

from neo.rawio.plexon2rawio.pypl2.pypl2lib import PyPL2FileReader

pl2reader = PyPL2FileReader(pl2_dll_file_path=pl2_dll_file_path)from pathlib import Path

file_path = Path("/home/heberto/Downloads/1_conspecific_vocalization_block_10.16.23.pl2")
assert file_path.exists()   
filename = str(file_path)

# In another cell
%%timeit
pl2reader.pl2_open_file(filename)
zm711 commented 2 months ago

Cool, But seems like you didn't change the open tries for plexon2? I'm just wondering if we should change that (in a new PR?). Let me double check this PR one last time after my morning meeting and then we can merge. I'm just going to update the branch first.

h-mayorquin commented 2 months ago

I just changed them.

h-mayorquin commented 2 months ago

OK.