{ "cells": [ { "cell_type": "markdown", "id": "77b3226f", "metadata": {}, "source": [ "# Example of using library code\n", "\n", "So far, we only provide channelmap editing for the Neuropixels probe family, and only the 4-shank Neuropixels probe is tested, so the following example codes use the 4-shank Neuropixels probe as the targeting probe." ] }, { "cell_type": "markdown", "id": "d3f35f70", "metadata": {}, "source": [ "## Basic" ] }, { "cell_type": "code", "execution_count": null, "id": "52efba29", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "\n", "from neurocarto.probe_npx import *" ] }, { "cell_type": "markdown", "id": "17d2228a", "metadata": {}, "source": [ "### Create an empty channelmap" ] }, { "cell_type": "code", "execution_count": null, "id": "65fa672d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "ChannelMap[4,2,640,384,0]" ] }, "execution_count": null, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s = ChannelMap(24)\n", "s" ] }, { "cell_type": "markdown", "id": "2c547cd9", "metadata": {}, "source": [ "The above output printed the information of channelmap `s`, in the format `ChannelMap[S,C,R,H,E]`, where `S` is the number of total shanks, `C` is the number of total columns in a shank, `R` is the number of total rows in a shank, `H` is the number of total channels, and `E` is the number of selected electrodes.\n", "\n", "For a valid channelmap, `H` and `E` should be equal." ] }, { "cell_type": "markdown", "id": "54e08ea1", "metadata": {}, "source": [ "### Load/Save a channelmap" ] }, { "cell_type": "markdown", "id": "d20f22b2", "metadata": {}, "source": [ "`*.imro` (**im**ec **r**ead-**o**ut file) is the format of the Neuropixels channelmap used by \n", "[SpikeGLX](https://billkarsh.github.io/SpikeGLX/). \n", "[detail](https://billkarsh.github.io/SpikeGLX/help/imroTables/)" ] }, { "cell_type": "code", "execution_count": null, "id": "6ef54597", "metadata": {}, "outputs": [], "source": [ "# load channelmap from file\n", "s = ChannelMap.from_imro('channelmap.imro')" ] }, { "cell_type": "code", "execution_count": null, "id": "6f9e1dcc", "metadata": {}, "outputs": [], "source": [ "# save channelmap to file\n", "s.save_imro('channelmap.imro')" ] }, { "cell_type": "markdown", "id": "4d15d8a2-5adc-48d7-ba06-f2d906601663", "metadata": {}, "source": [ "Note that if `s` is incompleted, which means the number of selected electrodes `E` is not equals to the total channel number `H`, `save_imro` will raise an error." ] }, { "cell_type": "markdown", "id": "7f6914d6", "metadata": {}, "source": [ "We support read channelmap from different file format." ] }, { "cell_type": "code", "execution_count": null, "id": "c49592c4", "metadata": {}, "outputs": [], "source": [ "_ = ChannelMap.from_meta('channelmap.meta') # from meta file from Spike outputs\n", "_ = ChannelMap.parse('(24,384)(...)') # from raw imro table format" ] }, { "cell_type": "markdown", "id": "47b8da33", "metadata": {}, "source": [ "We support other output formats. The following code requires to install extra library (as optional dependency)." ] }, { "cell_type": "code", "execution_count": null, "id": "3bf988e2", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Probe - IMEC - Neuropixels 2.0 - Four Shank - Prototype - 384ch - 1shanks" ] }, "execution_count": null, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#!pip install probeinterface\n", "p = s.to_probe() # type: Probe\n", "s = ChannelMap.from_probe(p)\n", "p" ] }, { "cell_type": "markdown", "id": "7019a395", "metadata": {}, "source": [ "Or other channelmap data output formats." ] }, { "cell_type": "code", "execution_count": null, "id": "63d3249c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | shank | \n", "column | \n", "row | \n", "in_used | \n", "x | \n", "y | \n", "
|---|---|---|---|---|---|---|
| channel | \n", "\n", " | \n", " | \n", " | \n", " | \n", " | \n", " |
| 0 | \n", "0 | \n", "0 | \n", "0 | \n", "True | \n", "0 | \n", "0 | \n", "
| 1 | \n", "0 | \n", "1 | \n", "0 | \n", "True | \n", "32 | \n", "0 | \n", "
| 2 | \n", "0 | \n", "0 | \n", "1 | \n", "True | \n", "0 | \n", "15 | \n", "
| 3 | \n", "0 | \n", "1 | \n", "1 | \n", "True | \n", "32 | \n", "15 | \n", "
| 4 | \n", "0 | \n", "0 | \n", "2 | \n", "True | \n", "0 | \n", "30 | \n", "
| ... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
| 379 | \n", "0 | \n", "1 | \n", "141 | \n", "True | \n", "32 | \n", "2115 | \n", "
| 380 | \n", "0 | \n", "0 | \n", "142 | \n", "True | \n", "0 | \n", "2130 | \n", "
| 381 | \n", "0 | \n", "1 | \n", "142 | \n", "True | \n", "32 | \n", "2130 | \n", "
| 382 | \n", "0 | \n", "0 | \n", "143 | \n", "True | \n", "0 | \n", "2145 | \n", "
| 383 | \n", "0 | \n", "1 | \n", "143 | \n", "True | \n", "32 | \n", "2145 | \n", "
384 rows × 6 columns
\n", "| channel | shank | column | row | in_used | x | y |
|---|---|---|---|---|---|---|
| i64 | i64 | i64 | i64 | bool | i64 | i64 |
| 0 | 0 | 0 | 0 | true | 0 | 0 |
| 1 | 0 | 1 | 0 | true | 32 | 0 |
| 2 | 0 | 0 | 1 | true | 0 | 15 |
| 3 | 0 | 1 | 1 | true | 32 | 15 |
| 4 | 0 | 0 | 2 | true | 0 | 30 |
| 5 | 0 | 1 | 2 | true | 32 | 30 |
| 6 | 0 | 0 | 3 | true | 0 | 45 |
| 7 | 0 | 1 | 3 | true | 32 | 45 |
| 8 | 0 | 0 | 4 | true | 0 | 60 |
| 9 | 0 | 1 | 4 | true | 32 | 60 |
| 10 | 0 | 0 | 5 | true | 0 | 75 |
| 11 | 0 | 1 | 5 | true | 32 | 75 |
| … | … | … | … | … | … | … |
| 372 | 0 | 0 | 138 | true | 0 | 2070 |
| 373 | 0 | 1 | 138 | true | 32 | 2070 |
| 374 | 0 | 0 | 139 | true | 0 | 2085 |
| 375 | 0 | 1 | 139 | true | 32 | 2085 |
| 376 | 0 | 0 | 140 | true | 0 | 2100 |
| 377 | 0 | 1 | 140 | true | 32 | 2100 |
| 378 | 0 | 0 | 141 | true | 0 | 2115 |
| 379 | 0 | 1 | 141 | true | 32 | 2115 |
| 380 | 0 | 0 | 142 | true | 0 | 2130 |
| 381 | 0 | 1 | 142 | true | 32 | 2130 |
| 382 | 0 | 0 | 143 | true | 0 | 2145 |
| 383 | 0 | 1 | 143 | true | 32 | 2145 |