{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Handling probe information\n\nIn order to properly spike sort, you may need to load information related to the probe you are using.\n\nSpikeInterface internally uses :probeinterface:`ProbeInterface <>` to handle probe or probe groups for recordings.\n\nDepending on the dataset, the :py:class:`~probeinterface.Probe` object can be already included or needs to be set\nmanually.\n\nHere's how!\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\nimport spikeinterface.extractors as se"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "First, let's create a toy example:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "recording, sorting_true = se.toy_example(duration=10, num_channels=32, seed=0, num_segments=2)\nprint(recording)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "This generator already contain a probe object that you can retrieve\ndirectly an plot:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "probe = recording.get_probe()\nprint(probe)\n\nfrom probeinterface.plotting import plot_probe\n\nplot_probe(probe)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "You can also overwrite the probe. In that case you need to manually make\nthe wiring (e.g. virtually connect each electrode to the recording device).\nLet's use a probe from Cambridge Neurotech with 32 channels:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from probeinterface import get_probe\n\nother_probe = get_probe('cambridgeneurotech', 'ASSY-37-E-1')\nprint(other_probe)\n\nother_probe.set_device_channel_indices(np.arange(32))\nrecording_2_shanks = recording.set_probe(other_probe, group_mode='by_shank')\nplot_probe(recording_2_shanks.get_probe())"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Now let's check what we have loaded. The `group_mode='by_shank'` automatically\nset the 'group' property depending on the shank id.\nWe can use this information to split the recording in two sub recordings:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "print(recording_2_shanks)\nprint(recording_2_shanks.get_property('group'))\n\nrec0, rec1 = recording_2_shanks.split_by(property='group')\nprint(rec0)\nprint(rec1)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Note that some formats (MEArec, SpikeGLX) automatically handle the probe\ngeometry. For almost all other formats the probe and the wiring have\nto be set manually using the :code:`probeinterface` library.\n\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.8.13"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}