Skip to content

Commit a98629b

Browse files
committed
Clean up docs and add list_all_probes function
1 parent 9f0f893 commit a98629b

File tree

4 files changed

+125
-28
lines changed

4 files changed

+125
-28
lines changed

doc/library.rst

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,58 @@
11
Probeinterface public library
22
=============================
33

4-
Probeinterface also handles a collection of probe descriptions on the
5-
`GitHub platform <https://github.com/SpikeInterface/probeinterface_library>`_
4+
Probeinterface also handles a collection of probe descriptions in the
5+
`ProbeInterface library <https://github.com/SpikeInterface/probeinterface_library>`_
66

7-
The python module has a simple function to download and cache locally by using `get_probe(...)` ::
7+
The python module has a simple function to download and cache locally by using ``get_probe(...)``:
8+
9+
10+
.. code-block:: python
811
912
from probeinterface import get_probe
10-
probe = get_probe(manufacturer='neuronexus',
11-
probe_name='A1x32-Poly3-10mm-50-177')
13+
probe = get_probe(
14+
manufacturer='neuronexus',
15+
probe_name='A1x32-Poly3-10mm-50-177'
16+
)
17+
18+
19+
Once a probe is downloaded, it is cached locally for future use.
20+
21+
There are several helper functions to explore the library:
22+
23+
.. code-block:: python
24+
25+
from probeinterface.library import (
26+
list_manufacturers,
27+
list_probes_by_manufacturer,
28+
list_all_probes
29+
)
30+
31+
# List all manufacturers
32+
manufacturers = list_manufacturers()
33+
34+
# List all probes for a given manufacturer
35+
probes = list_probes_by_manufacturer('neuronexus')
36+
37+
# List all probes in the library
38+
all_probes = list_all_probes()
39+
40+
# Cache all probes locally
41+
cache_full_library()
42+
1243
44+
Each function has an optional ``tag`` argument to specify a git tag/branch/commit to get a specific version of the library.
1345

14-
We expect to build rapidly commonly used probes in this public repository.
1546

16-
How to contribute
17-
-----------------
47+
How to contribute to the library
48+
--------------------------------
1849

19-
TODO: explain with more details
50+
Each probe in the library is represented by a JSON file and an image.
51+
To contribute a new probe to the library, follow these steps:
2052

21-
1. Generate the JSON file with probeinterface (or directly
22-
with another language)
53+
1. Generate the JSON file with probeinterface (or directly with another language)
2354
2. Generate an image of the probe with the `plot_probe` function in probeinterface
2455
3. Clone the `probeinterface_library repo <https://github.com/SpikeInterface/probeinterface_library>`_
25-
4. Put the JSON file and image into the correct folder or make a new folder (following the format of the repo)
56+
4. Put the JSON file and image into the correct folder: ``probeinterface_library/<manufacturer>/<model_name>/```
2657
5. Push to one of your branches with a git client
2758
6. Make a pull request to the main repo

src/probeinterface/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@
4141
)
4242
from .library import (
4343
get_probe,
44-
list_manufacturers_in_library,
45-
list_probes_in_library,
44+
list_manufacturers,
45+
list_probes_by_manufacturer,
46+
list_all_probes,
4647
get_tags_in_library,
4748
cache_full_library,
49+
clear_cache
4850
)
4951
from .wiring import get_available_pathways

src/probeinterface/library.py

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,22 +146,44 @@ def get_probe(
146146
return probe
147147

148148

149-
def cache_full_library(tag=None) -> None:
149+
def cache_full_library(tag=None) -> None: # pragma: no cover
150150
"""
151151
Download all probes from the library to the cache directory.
152152
"""
153-
manufacturers = list_manufacturers_in_library(tag=tag)
153+
manufacturers = list_manufacturers(tag=tag)
154154

155155
for manufacturer in manufacturers:
156-
probes = list_probes_in_library(manufacturer, tag=tag)
156+
probes = list_probes_by_manufacturer(manufacturer, tag=tag)
157157
for probe_name in probes:
158158
try:
159159
download_probeinterface_file(manufacturer, probe_name, tag=tag)
160160
except Exception as e:
161161
warnings.warn(f"Could not download {manufacturer}/{probe_name} (tag: {tag}): {e}")
162162

163163

164-
def list_manufacturers_in_library(tag=None) -> list[str]:
164+
def clear_cache(tag=None) -> None: # pragma: no cover
165+
"""
166+
Clear the cache folder for probeinterface library files.
167+
168+
Parameters
169+
----------
170+
tag : str | None, default: None
171+
Optional tag for the probe
172+
"""
173+
cache_folder = get_cache_folder()
174+
if tag is not None:
175+
cache_folder_tag = cache_folder / tag
176+
if cache_folder_tag.is_dir():
177+
import shutil
178+
179+
shutil.rmtree(cache_folder_tag)
180+
else:
181+
import shutil
182+
183+
shutil.rmtree(cache_folder)
184+
185+
186+
def list_manufacturers(tag=None) -> list[str]:
165187
"""
166188
Get the list of available manufacturers in the library
167189
@@ -173,7 +195,7 @@ def list_manufacturers_in_library(tag=None) -> list[str]:
173195
return list_github_folders("SpikeInterface", "probeinterface_library", ref=tag)
174196

175197

176-
def list_probes_in_library(manufacturer: str, tag=None) -> list[str]:
198+
def list_probes_by_manufacturer(manufacturer: str, tag=None) -> list[str]:
177199
"""
178200
Get the list of available probes for a given manufacturer
179201
@@ -190,6 +212,23 @@ def list_probes_in_library(manufacturer: str, tag=None) -> list[str]:
190212
return list_github_folders("SpikeInterface", "probeinterface_library", path=manufacturer, ref=tag)
191213

192214

215+
def list_all_probes(tag=None) -> dict[str, list[str]]:
216+
"""
217+
Get the list of all available probes in the library
218+
219+
Returns
220+
-------
221+
all_probes : dict
222+
Dictionary with manufacturers as keys and list of probes as values
223+
"""
224+
all_probes = {}
225+
manufacturers = list_manufacturers(tag=tag)
226+
for manufacturer in manufacturers:
227+
probes = list_probes_by_manufacturer(manufacturer, tag=tag)
228+
all_probes[manufacturer] = probes
229+
return all_probes
230+
231+
193232
def get_tags_in_library() -> list[str]:
194233
"""
195234
Get the list of available tags in the library

tests/test_library.py

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import os
2+
import pytest
3+
24
from probeinterface import Probe
35
from probeinterface.library import (
46
download_probeinterface_file,
57
get_from_cache,
68
get_probe,
79
get_tags_in_library,
8-
list_manufacturers_in_library,
9-
list_probes_in_library,
10+
list_manufacturers,
11+
list_probes_by_manufacturer,
12+
list_all_probes,
1013
get_cache_folder,
14+
cache_full_library,
15+
clear_cache
1116
)
1217

1318

@@ -77,24 +82,44 @@ def test_available_tags():
7782
assert len(tag) > 0
7883

7984

80-
def test_list_manufacturers_in_library():
81-
manufacturers = list_manufacturers_in_library()
85+
def test_list_manufacturers():
86+
manufacturers = list_manufacturers()
8287
assert isinstance(manufacturers, list)
8388
assert "neuronexus" in manufacturers
8489
assert "imec" in manufacturers
8590

8691

87-
def test_list_probes_in_library():
88-
manufacturers = list_manufacturers_in_library()
92+
def test_list_probes():
93+
manufacturers = list_all_probes()
8994
for manufacturer in manufacturers:
90-
probes = list_probes_in_library(manufacturer)
95+
probes = list_probes_by_manufacturer(manufacturer)
9196
assert isinstance(probes, list)
9297
assert len(probes) > 0
9398

9499

100+
@pytest.mark.skip(reason="long test that downloads the full library")
101+
def test_cache_full_library():
102+
tag = get_tags_in_library()[0] if len(get_tags_in_library()) > 0 else None
103+
print(tag)
104+
cache_full_library(tag=tag)
105+
all_probes = list_all_probes(tag=tag)
106+
# spot check that a known probe is in the cache
107+
for manufacturer, probes in all_probes.items():
108+
for probe_name in probes:
109+
probe = get_from_cache(manufacturer, probe_name, tag=tag)
110+
assert isinstance(probe, Probe)
111+
112+
clear_cache(tag=tag)
113+
for manufacturer, probes in all_probes.items():
114+
for probe_name in probes:
115+
probe = get_from_cache(manufacturer, probe_name, tag=tag)
116+
assert probe is None
117+
118+
95119
if __name__ == "__main__":
96120
test_download_probeinterface_file()
97121
test_get_from_cache()
98122
test_get_probe()
99-
test_list_manufacturers_in_library()
100-
test_list_probes_in_library()
123+
test_list_manufacturers()
124+
test_list_probes()
125+
test_cache_full_library()

0 commit comments

Comments
 (0)