Ver código fonte

Added hands-on day 3, 3

Michael Denker 2 anos atrás
pai
commit
e60ab91919
2 arquivos alterados com 676 adições e 0 exclusões
  1. 244 0
      day_3/hands_on_3.ipynb
  2. 432 0
      day_3/hands_on_3_solution.ipynb

+ 244 - 0
day_3/hands_on_3.ipynb

@@ -0,0 +1,244 @@
+{
+ "cells": [
+  {
+   "cell_type": "markdown",
+   "id": "503cb687",
+   "metadata": {},
+   "source": [
+    "# Hands-on session 3: Elephant\n",
+    "\n",
+    "These exercises build on concepts introduced in Tutorial 3\n",
+    "\n",
+    "In this exercise, we will use the SPADE method of Elephant to find recurring patterns in the spike data of trial 1.\n",
+    "\n",
+    "\n",
+    "## Imports and Preparation"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "2fc1d993",
+   "metadata": {
+    "pycharm": {
+     "name": "#%%\n"
+    }
+   },
+   "outputs": [],
+   "source": [
+    "import quantities as pq\n",
+    "import neo.utils\n",
+    "import elephant\n",
+    "import viziphant"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "fb0d97b0",
+   "metadata": {
+    "pycharm": {
+     "name": "#%% md\n"
+    }
+   },
+   "source": [
+    "On Linux you can download the compiled nix file via the command below. On other systems, please download the file manually from here and save it in the same folder as this notebook."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "619675c9",
+   "metadata": {
+    "pycharm": {
+     "name": "#%%\n"
+    }
+   },
+   "outputs": [],
+   "source": [
+    "!wget -O i140703-001.nix https://gin.g-node.org/sprenger/multielectrode_grasp/raw/dataset_nix/datasets_nix/i140703-001_cut_74sec.nix"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "4d1cd9a4",
+   "metadata": {},
+   "source": [
+    "## Data preparation\n",
+    "\n",
+    "\n",
+    "1. Load the data `i140703-001.nix` file using the `neo.io.NixIO` into a neo Block."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "d2e41fc5",
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  },
+  {
+   "cell_type": "markdown",
+   "id": "bb1229d4",
+   "metadata": {},
+   "source": [
+    "2. In close analogy to the beginning of tutorial 3, prepare a Neo `Block`, containing one `Segment` of SGHF data of the first correct trial. Name this `Segement` by the variable `trial`, as in tutorial 3.  In contrast to the lecture, we will cut data from the trial start `TS-ON` to reward administration indicated by event `RW-ON`. To this end, first find also the `RW-ON` events similar to how we found `TS-ON` in tutorial 3. Then, in the call to `neo.utils.add_epoch()`, supply these as a second event `event2=` *instead* of giving `t_pre=0` and `t_post=2*pq.s`. This will cut from event 1 to event 2, instead of a fixed amount of 2 s around event 1 (as in tutorial 3)."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "55270d93",
+   "metadata": {
+    "pycharm": {
+     "name": "#%%\n"
+    }
+   },
+   "outputs": [],
+   "source": []
+  },
+  {
+   "cell_type": "markdown",
+   "id": "7564a093",
+   "metadata": {},
+   "source": [
+    "## SPADE analysis\n",
+    "\n",
+    "Note that patterns in this data are not easily to spot by eye in the rasterplot we developed in tutorial 3.\n",
+    "We use SPADE as a technique that does that for us by finding all patterns and checking for each pattern if it\n",
+    "occurs more often than expected given its complexity (number of neurons participating) and frequency.\n",
+    "Before going directly to the analysis we briefly explain SPADE's most important parameters:\n",
+    "\n",
+    "- `binsize`: temporal precision of the method. The smaller the binsize is, the more precisely we expect each single pattern to repeat. This raises an important question: which is the temporal precision that are you interested in? It depends on the scientific question! We often use 5ms, based on a number of studies on the minimal neuronal temporal precision.\n",
+    "- `winlen`: window length, or maximal length allowed to each pattern, expressed in bin units. SPADE will detect patterns with a temporal duration up to the window length. If winlen=1, then only synchronous patterns are detected. Are you interested in synchronous higher-order correlations? Are you interested in patterns with delays? Note: the higher the winlen parameter is, the more expensive (memory and time) the pattern search is!\n",
+    "- `min_spikes` and `min_neu`: minimum number of spikes and minimum number of neurons allowed in a pattern. These parameters are important, too. Do you want to look for pattern with a particular size? Are you interested in patterns with multiple spikes coming from the same neuron?\n",
+    "- `n_surr`: number of surrogates used for the statistical testing. If the number of surrogates is set to zero, then all patterns are retrieved by SPADE without further testing. If, instead, the number of surrogates is different from zero (typically we suggest to use a large number - the more the better!) then only the significant patterns are retrieved from the analysis. For simplicity, we will set this parameter to `n_surr=0` in the following.\n",
+    "\n",
+    "Next steps:\n",
+    "3. As in tutorial 3, select only good quality neurons using the annotations (i.e., SUA units, more than 10000 spikes,...)"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "10d32abe",
+   "metadata": {
+    "pycharm": {
+     "name": "#%% md\n"
+    }
+   },
+   "source": [
+    "4. Run the SPADE analysis by executing the code given below:"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "23263b16",
+   "metadata": {
+    "pycharm": {
+     "name": "#%%\n"
+    }
+   },
+   "outputs": [],
+   "source": [
+    "# Fix parameters for SPADE\n",
+    "binsize = 5 * pq.ms\n",
+    "winlen = 1\n",
+    "min_spikes = 2\n",
+    "n_surr = 0\n",
+    "min_neu = 2\n",
+    "min_occ = 2"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "23f7d6b4",
+   "metadata": {
+    "pycharm": {
+     "name": "#%%\n"
+    }
+   },
+   "outputs": [],
+   "source": [
+    "result = elephant.spade.spade(\n",
+    "        spiketrains=spiketrains, binsize=binsize, winlen=winlen,\n",
+    "        min_spikes=min_spikes, n_surr=n_surr, min_neu=min_neu, min_occ=min_occ)\n",
+    "patterns = result['patterns']"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "1c3d05a6",
+   "metadata": {},
+   "source": [
+    "6. Let's look at the output in `patterns`. How many patterns were found? How does one pattern look as an output?"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "11523576",
+   "metadata": {},
+   "source": [
+    "7. Display five detected patterns in the data and their statistics by executing the Viziphant function calls given below"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "345f862e",
+   "metadata": {
+    "pycharm": {
+     "name": "#%%\n"
+    }
+   },
+   "outputs": [],
+   "source": [
+    "viziphant.spade.plot_patterns(spiketrains, patterns[:5], circle_sizes=(1, 50, 70))\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "cc8eedf4",
+   "metadata": {
+    "pycharm": {
+     "name": "#%%\n"
+    }
+   },
+   "outputs": [],
+   "source": [
+    "viziphant.spade.plot_patterns_statistics(patterns)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "d2b28248",
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  }
+ ],
+ "metadata": {
+  "kernelspec": {
+   "display_name": "Python 3 (ipykernel)",
+   "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.0"
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5
+}

Diferenças do arquivo suprimidas por serem muito extensas
+ 432 - 0
day_3/hands_on_3_solution.ipynb