Skip to content

Commit b9a65fc

Browse files
samuelgarciapre-commit-ci[bot]alejoe91chrishalcrow
authored
Generate recording with probe from library (#4568)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Alessio Buccino <alejoe9187@gmail.com> Co-authored-by: Chris Halcrow <57948917+chrishalcrow@users.noreply.github.com>
1 parent 8fc75ba commit b9a65fc

2 files changed

Lines changed: 75 additions & 53 deletions

File tree

src/spikeinterface/generation/drifting_generator.py

Lines changed: 56 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import numpy as np
1212

13-
from probeinterface import generate_multi_columns_probe
13+
from probeinterface import generate_multi_columns_probe, get_probe, generate_tetrode
1414

1515
from spikeinterface import Templates
1616
from spikeinterface.core import ms_to_samples
@@ -24,52 +24,56 @@
2424
from .drift_tools import DriftingTemplates, make_linear_displacement, InjectDriftingTemplatesRecording
2525
from .noise_tools import generate_noise
2626

27-
# this should be moved in probeinterface but later
28-
_toy_probes = {
29-
"Neuropixels1-384": dict(
30-
num_columns=4,
31-
num_contact_per_column=[96] * 4,
32-
xpitch=16,
33-
ypitch=40,
34-
y_shift_per_column=[20, 0, 20, 0],
35-
contact_shapes="square",
36-
contact_shape_params={"width": 12},
37-
),
38-
"Neuropixels2-384": dict(
39-
num_columns=2,
40-
num_contact_per_column=[192] * 2,
41-
xpitch=32,
42-
ypitch=15,
43-
contact_shapes="square",
44-
contact_shape_params={"width": 12},
45-
),
46-
"Neuropixels2-128": dict(
47-
num_columns=2,
48-
num_contact_per_column=[64] * 2,
49-
xpitch=32,
50-
ypitch=15,
51-
contact_shapes="square",
52-
contact_shape_params={"width": 12},
53-
),
54-
"Neuropixels1-128": dict(
55-
num_columns=4,
56-
num_contact_per_column=[32] * 4,
57-
xpitch=16,
58-
ypitch=40,
59-
y_shift_per_column=[20, 0, 20, 0],
60-
contact_shapes="square",
61-
contact_shape_params={"width": 12},
62-
),
63-
"Neuronexus-32": dict(
64-
num_columns=3,
65-
num_contact_per_column=[10, 12, 10],
66-
xpitch=30,
67-
ypitch=30,
68-
y_shift_per_column=[0, -15, 0],
69-
contact_shapes="circle",
70-
contact_shape_params={"radius": 8},
71-
),
72-
}
27+
28+
def _make_probe_by_name(probe_name: str):
29+
"""
30+
Generates a probe from probeinterface library, using the manufacturer name combined with the probe name, e.g.
31+
- 'cambridgeneurotech/ASSY-37-H7b'
32+
- 'cambridgeneurotech#ASSY-37-H7b'
33+
- 'imec#NP1000"
34+
35+
This function replace the old `_toy_probes` dict that generate probe using `generate_multi_columns_probe()`
36+
"""
37+
if probe_name == "Neuropixels1-384":
38+
probe = get_probe("imec", "NP1000")
39+
probe = probe.get_slice(np.arange(384))
40+
elif probe_name == "Neuropixels1-128":
41+
probe = get_probe("imec", "NP1000")
42+
probe = probe.get_slice(np.arange(128))
43+
elif probe_name == "Neuropixels2-384":
44+
probe = get_probe("imec", "NP2000")
45+
probe = probe.get_slice(np.arange(384))
46+
elif probe_name == "Neuropixels2-128":
47+
probe = get_probe("imec", "NP2000")
48+
probe = probe.get_slice(np.arange(128))
49+
elif probe_name == "Neuronexus-32":
50+
# this probe was not existing really, it was a 'generic' 32 channels
51+
# lets keep as before
52+
probe = generate_multi_columns_probe(
53+
num_columns=3,
54+
num_contact_per_column=[10, 12, 10],
55+
xpitch=30,
56+
ypitch=30,
57+
y_shift_per_column=[0, -15, 0],
58+
contact_shapes="circle",
59+
contact_shape_params={"radius": 8},
60+
)
61+
elif probe_name == "tetrode":
62+
probe = generate_tetrode()
63+
elif probe_name == "sinaps-128":
64+
probe = get_probe("sinaps-research-platform", "p1024s1NHP")
65+
order = np.argsort(probe.contact_ids.astype("int64"))
66+
probe = probe.get_slice(order[:128])
67+
elif "/" in probe_name:
68+
manufacturer, probe_name_ = probe_name.split("/")
69+
probe = get_probe(manufacturer, probe_name_)
70+
elif "#" in probe_name:
71+
manufacturer, probe_name_ = probe_name.split("#")
72+
probe = get_probe(manufacturer, probe_name_)
73+
else:
74+
raise ValueError("wring probe_name")
75+
76+
return probe
7377

7478

7579
def make_one_displacement_vector(
@@ -449,10 +453,11 @@ def generate_drifting_recording(
449453

450454
# probe
451455
if probe is None:
452-
if generate_probe_kwargs is None:
453-
generate_probe_kwargs = _toy_probes[probe_name]
454-
455-
probe = generate_multi_columns_probe(**generate_probe_kwargs)
456+
if generate_probe_kwargs is not None:
457+
probe = generate_multi_columns_probe(**generate_probe_kwargs)
458+
else:
459+
probe = _make_probe_by_name(probe_name)
460+
# the wiring do not matter because the traces are generated after using the channel locations
456461
num_channels = probe.get_contact_count()
457462
probe.set_device_channel_indices(np.arange(num_channels))
458463

src/spikeinterface/generation/tests/test_drifing_generator.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,23 @@ def test_generate_drifting_recording():
9595
seed=2205,
9696
)
9797

98+
static_recording, drifting_recording, sorting = generate_drifting_recording(
99+
num_units=10,
100+
probe_name="cambridgeneurotech/ASSY-1-E-1",
101+
seed=2205,
102+
)
103+
static_recording, drifting_recording, sorting = generate_drifting_recording(
104+
num_units=10,
105+
probe_name="cambridgeneurotech#ASSY-1-E-1",
106+
seed=2205,
107+
)
108+
109+
static_recording, drifting_recording, sorting = generate_drifting_recording(
110+
num_units=10,
111+
probe_name="Neuropixels2-128",
112+
seed=2205,
113+
)
114+
98115
# print(static_recording)
99116
# print(drifting_recording)
100117
# print(sorting)
@@ -104,6 +121,6 @@ def test_generate_drifting_recording():
104121

105122
if __name__ == "__main__":
106123
# test_make_one_displacement_vector()
107-
test_generate_displacement_vector()
124+
# test_generate_displacement_vector()
108125
# test_generate_noise()
109-
# test_generate_drifting_recording()
126+
test_generate_drifting_recording()

0 commit comments

Comments
 (0)