Skip to content

Commit

Permalink
Refactor neuropixel in a separate file and generate the NP library. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelgarcia authored Jan 27, 2025
1 parent 9776684 commit abf0cf0
Show file tree
Hide file tree
Showing 6 changed files with 1,492 additions and 1,124 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ dev_*
.coverage
cov.xml
.DS_Store


neuropixel_library_generated/*
106 changes: 106 additions & 0 deletions resources/generate_neuropixels_library.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import shutil
from pathlib import Path

import numpy as np
import matplotlib.pyplot as plt

from probeinterface.neuropixels_tools import npx_descriptions, probe_part_number_to_probe_type, _make_npx_probe_from_description
from probeinterface.plotting import plot_probe
from probeinterface import write_probeinterface


base_folder = Path("./neuropixels_library_generated")



def generate_all_npx():

# if not base_folder.exists():
base_folder.mkdir(exist_ok=True)


for probe_number, probe_type in probe_part_number_to_probe_type.items():

if probe_number is None:
continue

if probe_number == "1110":
# the formula by the imrow table is wrong and more complicated
continue

probe_folder = base_folder / probe_number
probe_folder.mkdir(exist_ok=True)

print(probe_number, probe_type)

probe_description = npx_descriptions[probe_type]



num_shank = probe_description["shank_number"]
contact_per_shank = probe_description["ncols_per_shank"] * probe_description["nrows_per_shank"]
if num_shank == 1:
elec_ids = np.arange(contact_per_shank)
shank_ids = None
else:
elec_ids = np.concatenate([np.arange(contact_per_shank) for i in range(num_shank)])
shank_ids = np.concatenate([np.zeros(contact_per_shank) + i for i in range(num_shank)])

probe = _make_npx_probe_from_description(probe_description, elec_ids, shank_ids)

# ploting
fig, axs = plt.subplots(ncols=2)

ax = axs[0]
plot_probe(probe, ax=ax)
ax.set_title("")

ax.xaxis.set_visible(False)
ax.spines["top"].set_visible(False)
ax.spines["right"].set_visible(False)
ax.spines["bottom"].set_visible(False)

ax = axs[1]


# plot_probe(probe, ax=ax, text_on_contact=probe._contact_ids)
plot_probe(probe, ax=ax)
ax.set_title("")

yp = probe_description["y_pitch"]
ax.set_ylim(-yp*8, yp*13)
ax.yaxis.set_visible(False)
ax.spines["top"].set_visible(False)
ax.spines["right"].set_visible(False)
ax.spines["left"].set_visible(False)

n = probe.get_contact_count()

title = probe_number
title += f"\n{probe.manufacturer} - {probe.model_name}"
title += f"\n {n}ch"
if probe.shank_ids is not None:
num_shank = probe.get_shank_count()
title += f" - {num_shank}shanks"


fig.suptitle(title)

# plt.show()

fig.savefig(probe_folder / f"{probe_number}.png")

write_probeinterface(probe_folder / f"{probe_number}.json", probe)

plt.close(fig)









if __name__ == "__main__":
generate_all_npx()
15 changes: 9 additions & 6 deletions src/probeinterface/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,23 @@
write_prb,
read_csv,
write_csv,
read_imro,
write_imro,
read_BIDS_probe,
write_BIDS_probe,
read_spikegadgets,
read_mearec,
read_nwb,
read_maxwell,
read_3brain,
)
from .neuropixels_tools import (
read_imro,
write_imro,
read_spikeglx,
parse_spikeglx_meta,
parse_spikeglx_snsGeomMap,
get_saved_channel_indices_from_spikeglx_meta,
read_openephys,
get_saved_channel_indices_from_openephys_settings,
read_mearec,
read_nwb,
read_maxwell,
read_3brain,
)
from .utils import combine_probes
from .generator import (
Expand Down
Loading

0 comments on commit abf0cf0

Please sign in to comment.