|
| 1 | +import shutil |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | +import numpy as np |
| 5 | +import matplotlib.pyplot as plt |
| 6 | + |
| 7 | +from probeinterface.neuropixels_tools import npx_descriptions, probe_part_number_to_probe_type, _make_npx_probe_from_description |
| 8 | +from probeinterface.plotting import plot_probe |
| 9 | +from probeinterface import write_probeinterface |
| 10 | + |
| 11 | + |
| 12 | +base_folder = Path("./neuropixels_library_generated") |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +def generate_all_npx(): |
| 17 | + |
| 18 | + # if not base_folder.exists(): |
| 19 | + base_folder.mkdir(exist_ok=True) |
| 20 | + |
| 21 | + |
| 22 | + for probe_number, probe_type in probe_part_number_to_probe_type.items(): |
| 23 | + |
| 24 | + if probe_number is None: |
| 25 | + continue |
| 26 | + |
| 27 | + if probe_number == "1110": |
| 28 | + # the formula by the imrow table is wrong and more complicated |
| 29 | + continue |
| 30 | + |
| 31 | + probe_folder = base_folder / probe_number |
| 32 | + probe_folder.mkdir(exist_ok=True) |
| 33 | + |
| 34 | + print(probe_number, probe_type) |
| 35 | + |
| 36 | + probe_description = npx_descriptions[probe_type] |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + num_shank = probe_description["shank_number"] |
| 41 | + contact_per_shank = probe_description["ncols_per_shank"] * probe_description["nrows_per_shank"] |
| 42 | + if num_shank == 1: |
| 43 | + elec_ids = np.arange(contact_per_shank) |
| 44 | + shank_ids = None |
| 45 | + else: |
| 46 | + elec_ids = np.concatenate([np.arange(contact_per_shank) for i in range(num_shank)]) |
| 47 | + shank_ids = np.concatenate([np.zeros(contact_per_shank) + i for i in range(num_shank)]) |
| 48 | + |
| 49 | + probe = _make_npx_probe_from_description(probe_description, elec_ids, shank_ids) |
| 50 | + |
| 51 | + # ploting |
| 52 | + fig, axs = plt.subplots(ncols=2) |
| 53 | + |
| 54 | + ax = axs[0] |
| 55 | + plot_probe(probe, ax=ax) |
| 56 | + ax.set_title("") |
| 57 | + |
| 58 | + ax.xaxis.set_visible(False) |
| 59 | + ax.spines["top"].set_visible(False) |
| 60 | + ax.spines["right"].set_visible(False) |
| 61 | + ax.spines["bottom"].set_visible(False) |
| 62 | + |
| 63 | + ax = axs[1] |
| 64 | + |
| 65 | + |
| 66 | + # plot_probe(probe, ax=ax, text_on_contact=probe._contact_ids) |
| 67 | + plot_probe(probe, ax=ax) |
| 68 | + ax.set_title("") |
| 69 | + |
| 70 | + yp = probe_description["y_pitch"] |
| 71 | + ax.set_ylim(-yp*8, yp*13) |
| 72 | + ax.yaxis.set_visible(False) |
| 73 | + ax.spines["top"].set_visible(False) |
| 74 | + ax.spines["right"].set_visible(False) |
| 75 | + ax.spines["left"].set_visible(False) |
| 76 | + |
| 77 | + n = probe.get_contact_count() |
| 78 | + |
| 79 | + title = probe_number |
| 80 | + title += f"\n{probe.manufacturer} - {probe.model_name}" |
| 81 | + title += f"\n {n}ch" |
| 82 | + if probe.shank_ids is not None: |
| 83 | + num_shank = probe.get_shank_count() |
| 84 | + title += f" - {num_shank}shanks" |
| 85 | + |
| 86 | + |
| 87 | + fig.suptitle(title) |
| 88 | + |
| 89 | + # plt.show() |
| 90 | + |
| 91 | + fig.savefig(probe_folder / f"{probe_number}.png") |
| 92 | + |
| 93 | + write_probeinterface(probe_folder / f"{probe_number}.json", probe) |
| 94 | + |
| 95 | + plt.close(fig) |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | + |
| 100 | + |
| 101 | + |
| 102 | + |
| 103 | + |
| 104 | + |
| 105 | +if __name__ == "__main__": |
| 106 | + generate_all_npx() |
0 commit comments