{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "12:05:23 [I] klustakwik KlustaKwik2 version 0.2.6\n", "/home/mikkel/.virtualenvs/expipe/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility. Expected 192 from C header, got 216 from PyObject\n", " return f(*args, **kwds)\n", "/home/mikkel/.virtualenvs/expipe/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility. Expected 192 from C header, got 216 from PyObject\n", " return f(*args, **kwds)\n" ] } ], "source": [ "import os\n", "import pathlib\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import re\n", "import shutil\n", "import pandas as pd\n", "import scipy.stats\n", "\n", "import exdir\n", "import expipe\n", "from distutils.dir_util import copy_tree\n", "import septum_mec\n", "import spatial_maps as sp\n", "import head_direction.head as head\n", "import septum_mec.analysis.data_processing as dp\n", "import septum_mec.analysis.registration\n", "from septum_mec.analysis.plotting import violinplot\n", "\n", "from spike_statistics.core import permutation_resampling" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "project_path = dp.project_path()\n", "project = expipe.get_project(project_path)\n", "actions = project.actions\n", "\n", "output_path = pathlib.Path(\"output\") / \"comparisons-gridcells\"\n", "(output_path / \"statistics\").mkdir(exist_ok=True, parents=True)\n", "(output_path / \"figures\").mkdir(exist_ok=True, parents=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Load cell statistics and shuffling quantiles" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
actionbaselineentityfrequencyiiisessionstim_locationstimulatedtag...burst_event_ratiobursty_spike_ratiogridnessborder_scoreinformation_rateinformation_specificityhead_mean_anghead_mean_vec_lenspacingorientation
01849-060319-3True1849NaNFalseTrue3NaNFalsebaseline ii...0.3982300.678064-0.4669230.0293281.0092150.3172565.4380330.0408740.62878420.224859
11849-060319-3True1849NaNFalseTrue3NaNFalsebaseline ii...0.1380140.263173-0.6667920.3081460.1925240.0334471.9517400.0172890.78938827.897271
21849-060319-3True1849NaNFalseTrue3NaNFalsebaseline ii...0.3739860.659259-0.5725660.1432524.7458360.3937044.4397210.1247310.55540228.810794
31849-060319-3True1849NaNFalseTrue3NaNFalsebaseline ii...0.0874130.179245-0.4374920.2689480.1573940.0735536.2151950.1019110.4922509.462322
41849-060319-3True1849NaNFalseTrue3NaNFalsebaseline ii...0.2487710.463596-0.0859380.2187440.5191530.0326831.5314810.0538100.5599050.000000
\n", "

5 rows × 39 columns

\n", "
" ], "text/plain": [ " action baseline entity frequency i ii session \\\n", "0 1849-060319-3 True 1849 NaN False True 3 \n", "1 1849-060319-3 True 1849 NaN False True 3 \n", "2 1849-060319-3 True 1849 NaN False True 3 \n", "3 1849-060319-3 True 1849 NaN False True 3 \n", "4 1849-060319-3 True 1849 NaN False True 3 \n", "\n", " stim_location stimulated tag ... burst_event_ratio \\\n", "0 NaN False baseline ii ... 0.398230 \n", "1 NaN False baseline ii ... 0.138014 \n", "2 NaN False baseline ii ... 0.373986 \n", "3 NaN False baseline ii ... 0.087413 \n", "4 NaN False baseline ii ... 0.248771 \n", "\n", " bursty_spike_ratio gridness border_score information_rate \\\n", "0 0.678064 -0.466923 0.029328 1.009215 \n", "1 0.263173 -0.666792 0.308146 0.192524 \n", "2 0.659259 -0.572566 0.143252 4.745836 \n", "3 0.179245 -0.437492 0.268948 0.157394 \n", "4 0.463596 -0.085938 0.218744 0.519153 \n", "\n", " information_specificity head_mean_ang head_mean_vec_len spacing \\\n", "0 0.317256 5.438033 0.040874 0.628784 \n", "1 0.033447 1.951740 0.017289 0.789388 \n", "2 0.393704 4.439721 0.124731 0.555402 \n", "3 0.073553 6.215195 0.101911 0.492250 \n", "4 0.032683 1.531481 0.053810 0.559905 \n", "\n", " orientation \n", "0 20.224859 \n", "1 27.897271 \n", "2 28.810794 \n", "3 9.462322 \n", "4 0.000000 \n", "\n", "[5 rows x 39 columns]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "statistics_action = actions['calculate-statistics']\n", "identification_action = actions['identify-neurons']\n", "sessions = pd.read_csv(identification_action.data_path('sessions'))\n", "units = pd.read_csv(identification_action.data_path('units'))\n", "session_units = pd.merge(sessions, units, on='action')\n", "statistics_results = pd.read_csv(statistics_action.data_path('results'))\n", "statistics = pd.merge(session_units, statistics_results, how='left')\n", "statistics.head()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
border_scoregridnesshead_mean_anghead_mean_vec_leninformation_ratespeed_scoreactionchannel_groupunit_name
00.3480230.2751093.0126890.0867920.7071970.1490711833-010719-10.0127.0
10.3623800.1664753.1331380.0372710.4824860.1322121833-010719-10.0161.0
20.3674980.2668655.5863950.1828430.2711880.0628211833-010719-10.0191.0
30.3319420.3121555.9557670.0907860.3540180.0520091833-010719-10.0223.0
40.3258420.1804955.2627210.1035840.2104270.0940411833-010719-10.0225.0
\n", "
" ], "text/plain": [ " border_score gridness head_mean_ang head_mean_vec_len information_rate \\\n", "0 0.348023 0.275109 3.012689 0.086792 0.707197 \n", "1 0.362380 0.166475 3.133138 0.037271 0.482486 \n", "2 0.367498 0.266865 5.586395 0.182843 0.271188 \n", "3 0.331942 0.312155 5.955767 0.090786 0.354018 \n", "4 0.325842 0.180495 5.262721 0.103584 0.210427 \n", "\n", " speed_score action channel_group unit_name \n", "0 0.149071 1833-010719-1 0.0 127.0 \n", "1 0.132212 1833-010719-1 0.0 161.0 \n", "2 0.062821 1833-010719-1 0.0 191.0 \n", "3 0.052009 1833-010719-1 0.0 223.0 \n", "4 0.094041 1833-010719-1 0.0 225.0 " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "shuffling = actions['shuffling']\n", "quantiles_95 = pd.read_csv(shuffling.data_path('quantiles_95'))\n", "quantiles_95.head()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
actionbaselineentityfrequencyiiisessionstim_locationstimulatedtag...head_mean_vec_lenspacingorientationborder_score_thresholdgridness_thresholdhead_mean_ang_thresholdhead_mean_vec_len_thresholdinformation_rate_thresholdspeed_score_thresholdspecificity
01849-060319-3True1849NaNFalseTrue3NaNFalsebaseline ii...0.0408740.62878420.2248590.3325480.2290736.0294310.2053621.1158250.0667360.451741
11849-060319-3True1849NaNFalseTrue3NaNFalsebaseline ii...0.0172890.78938827.8972710.3548300.0893336.1200550.0735660.2232370.0525940.098517
21849-060319-3True1849NaNFalseTrue3NaNFalsebaseline ii...0.1247310.55540228.8107940.264610-0.1210815.7594060.1508274.9649840.0271200.400770
31849-060319-3True1849NaNFalseTrue3NaNFalsebaseline ii...0.1019110.4922509.4623220.3442800.2158296.0333640.1104950.2399960.0540740.269461
41849-060319-3True1849NaNFalseTrue3NaNFalsebaseline ii...0.0538100.5599050.0000000.3427990.2189675.7681700.0547620.5249900.1447020.133410
\n", "

5 rows × 46 columns

\n", "
" ], "text/plain": [ " action baseline entity frequency i ii session \\\n", "0 1849-060319-3 True 1849 NaN False True 3 \n", "1 1849-060319-3 True 1849 NaN False True 3 \n", "2 1849-060319-3 True 1849 NaN False True 3 \n", "3 1849-060319-3 True 1849 NaN False True 3 \n", "4 1849-060319-3 True 1849 NaN False True 3 \n", "\n", " stim_location stimulated tag ... head_mean_vec_len spacing \\\n", "0 NaN False baseline ii ... 0.040874 0.628784 \n", "1 NaN False baseline ii ... 0.017289 0.789388 \n", "2 NaN False baseline ii ... 0.124731 0.555402 \n", "3 NaN False baseline ii ... 0.101911 0.492250 \n", "4 NaN False baseline ii ... 0.053810 0.559905 \n", "\n", " orientation border_score_threshold gridness_threshold \\\n", "0 20.224859 0.332548 0.229073 \n", "1 27.897271 0.354830 0.089333 \n", "2 28.810794 0.264610 -0.121081 \n", "3 9.462322 0.344280 0.215829 \n", "4 0.000000 0.342799 0.218967 \n", "\n", " head_mean_ang_threshold head_mean_vec_len_threshold \\\n", "0 6.029431 0.205362 \n", "1 6.120055 0.073566 \n", "2 5.759406 0.150827 \n", "3 6.033364 0.110495 \n", "4 5.768170 0.054762 \n", "\n", " information_rate_threshold speed_score_threshold specificity \n", "0 1.115825 0.066736 0.451741 \n", "1 0.223237 0.052594 0.098517 \n", "2 4.964984 0.027120 0.400770 \n", "3 0.239996 0.054074 0.269461 \n", "4 0.524990 0.144702 0.133410 \n", "\n", "[5 rows x 46 columns]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "action_columns = ['action', 'channel_group', 'unit_name']\n", "data = pd.merge(statistics, quantiles_95, on=action_columns, suffixes=(\"\", \"_threshold\"))\n", "\n", "data['specificity'] = np.log10(data['in_field_mean_rate'] / data['out_field_mean_rate'])\n", "\n", "data.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Statistics about all cell-sessions" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "stimulated\n", "False 624\n", "True 660\n", "Name: action, dtype: int64" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data.groupby('stimulated').count()['action']" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "data['unit_day'] = data.apply(lambda x: str(x.unit_idnum) + '_' + x.action.split('-')[1], axis=1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Find all cells with gridness above threshold" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of sessions above threshold 194\n", "Number of animals 4\n" ] } ], "source": [ "query = (\n", " 'gridness > gridness_threshold and '\n", " 'information_rate > information_rate_threshold and '\n", " 'gridness > .2 and '\n", " 'average_rate < 25'\n", ")\n", "sessions_above_threshold = data.query(query)\n", "print(\"Number of sessions above threshold\", len(sessions_above_threshold))\n", "print(\"Number of animals\", len(sessions_above_threshold.groupby(['entity'])))" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "gridcell_sessions = data[data.unit_day.isin(sessions_above_threshold.unit_day.values)]" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of gridcells 139\n", "Number of gridcell recordings 231\n", "Number of animals 4\n" ] } ], "source": [ "print(\"Number of gridcells\", gridcell_sessions.unit_idnum.nunique())\n", "print(\"Number of gridcell recordings\", len(gridcell_sessions))\n", "print(\"Number of animals\", len(gridcell_sessions.groupby(['entity'])))" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of gridcells in baseline i sessions 66\n", "Number of gridcells in stimulated 11Hz ms sessions 61\n", "Number of gridcells in baseline ii sessions 56\n", "Number of gridcells in stimulated 30Hz ms sessions 40\n" ] } ], "source": [ "baseline_i = gridcell_sessions.query('baseline and Hz11')\n", "stimulated_11 = gridcell_sessions.query('frequency==11 and stim_location==\"ms\"')\n", "\n", "baseline_ii = gridcell_sessions.query('baseline and Hz30')\n", "stimulated_30 = gridcell_sessions.query('frequency==30 and stim_location==\"ms\"')\n", "\n", "print(\"Number of gridcells in baseline i sessions\", len(baseline_i))\n", "print(\"Number of gridcells in stimulated 11Hz ms sessions\", len(stimulated_11))\n", "\n", "print(\"Number of gridcells in baseline ii sessions\", len(baseline_ii))\n", "print(\"Number of gridcells in stimulated 30Hz ms sessions\", len(stimulated_30))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# slice unique units" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "baseline_i = baseline_i.drop_duplicates('unit_id')\n", "stimulated_11 = stimulated_11.drop_duplicates('unit_id')\n", "baseline_ii = baseline_ii.drop_duplicates('unit_id')\n", "stimulated_30 = stimulated_30.drop_duplicates('unit_id')" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of gridcells in baseline i sessions 63\n", "Number of gridcells in stimulated 11Hz ms sessions 58\n", "Number of gridcells in baseline ii sessions 52\n", "Number of gridcells in stimulated 30Hz ms sessions 38\n" ] } ], "source": [ "print(\"Number of gridcells in baseline i sessions\", len(baseline_i))\n", "print(\"Number of gridcells in stimulated 11Hz ms sessions\", len(stimulated_11))\n", "\n", "print(\"Number of gridcells in baseline ii sessions\", len(baseline_ii))\n", "print(\"Number of gridcells in stimulated 30Hz ms sessions\", len(stimulated_30))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Calculate statistics" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "columns = [\n", " 'average_rate', 'gridness', 'sparsity', 'selectivity', 'information_specificity',\n", " 'max_rate', 'information_rate', 'interspike_interval_cv', \n", " 'in_field_mean_rate', 'out_field_mean_rate', \n", " 'burst_event_ratio', 'specificity', 'speed_score'\n", "]" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
average_rategridnesssparsityselectivityinformation_specificitymax_rateinformation_rateinterspike_interval_cvin_field_mean_rateout_field_mean_rateburst_event_ratiospecificityspeed_score
stimulated
False8.9045010.5213710.6183845.9345390.23463237.4378081.2465462.40464714.7176356.3468750.2118400.4787750.135495
True8.3922520.4402960.6556985.9774080.21573633.7164780.9647872.22363612.9360216.1222280.1972640.4558780.104697
\n", "
" ], "text/plain": [ " average_rate gridness sparsity selectivity \\\n", "stimulated \n", "False 8.904501 0.521371 0.618384 5.934539 \n", "True 8.392252 0.440296 0.655698 5.977408 \n", "\n", " information_specificity max_rate information_rate \\\n", "stimulated \n", "False 0.234632 37.437808 1.246546 \n", "True 0.215736 33.716478 0.964787 \n", "\n", " interspike_interval_cv in_field_mean_rate out_field_mean_rate \\\n", "stimulated \n", "False 2.404647 14.717635 6.346875 \n", "True 2.223636 12.936021 6.122228 \n", "\n", " burst_event_ratio specificity speed_score \n", "stimulated \n", "False 0.211840 0.478775 0.135495 \n", "True 0.197264 0.455878 0.104697 " ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gridcell_sessions.groupby('stimulated')[columns].mean()" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
average_rategridnesssparsityselectivityinformation_specificitymax_rateinformation_rateinterspike_interval_cvin_field_mean_rateout_field_mean_rateburst_event_ratiospecificityspeed_score
count129.000000129.000000129.000000129.000000129.000000129.000000129.000000129.000000129.000000129.000000129.000000129.000000129.000000
mean8.9045010.5213710.6183845.9345390.23463237.4378081.2465462.40464714.7176356.3468750.2118400.4787750.135495
std7.6055980.3376070.1879343.2173660.20072616.3001170.6059710.7564079.2675226.8054990.0801430.2095310.072831
min0.478349-0.6849240.2000661.5332160.0078073.3460270.1176381.3043870.9240660.1590760.0250000.071681-0.025629
25%3.5183920.3163260.4374993.7298630.09325226.9488430.7867531.8729917.7011561.6698440.1607950.3108220.084280
50%6.4568820.5292430.6421674.7949700.18028635.0649911.1560872.22118512.2122894.3149130.2102400.4363400.128603
75%12.7217550.7836820.7580977.4394640.31248744.3248731.5929482.77062420.9740269.1215050.2675680.6248340.188948
max59.3653121.1489790.97615718.9758751.24330790.1601583.4567965.67136266.35075456.2555440.3933061.0663910.297548
\n", "
" ], "text/plain": [ " average_rate gridness sparsity selectivity \\\n", "count 129.000000 129.000000 129.000000 129.000000 \n", "mean 8.904501 0.521371 0.618384 5.934539 \n", "std 7.605598 0.337607 0.187934 3.217366 \n", "min 0.478349 -0.684924 0.200066 1.533216 \n", "25% 3.518392 0.316326 0.437499 3.729863 \n", "50% 6.456882 0.529243 0.642167 4.794970 \n", "75% 12.721755 0.783682 0.758097 7.439464 \n", "max 59.365312 1.148979 0.976157 18.975875 \n", "\n", " information_specificity max_rate information_rate \\\n", "count 129.000000 129.000000 129.000000 \n", "mean 0.234632 37.437808 1.246546 \n", "std 0.200726 16.300117 0.605971 \n", "min 0.007807 3.346027 0.117638 \n", "25% 0.093252 26.948843 0.786753 \n", "50% 0.180286 35.064991 1.156087 \n", "75% 0.312487 44.324873 1.592948 \n", "max 1.243307 90.160158 3.456796 \n", "\n", " interspike_interval_cv in_field_mean_rate out_field_mean_rate \\\n", "count 129.000000 129.000000 129.000000 \n", "mean 2.404647 14.717635 6.346875 \n", "std 0.756407 9.267522 6.805499 \n", "min 1.304387 0.924066 0.159076 \n", "25% 1.872991 7.701156 1.669844 \n", "50% 2.221185 12.212289 4.314913 \n", "75% 2.770624 20.974026 9.121505 \n", "max 5.671362 66.350754 56.255544 \n", "\n", " burst_event_ratio specificity speed_score \n", "count 129.000000 129.000000 129.000000 \n", "mean 0.211840 0.478775 0.135495 \n", "std 0.080143 0.209531 0.072831 \n", "min 0.025000 0.071681 -0.025629 \n", "25% 0.160795 0.310822 0.084280 \n", "50% 0.210240 0.436340 0.128603 \n", "75% 0.267568 0.624834 0.188948 \n", "max 0.393306 1.066391 0.297548 " ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gridcell_sessions.query('baseline')[columns].describe()" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
average_rategridnesssparsityselectivityinformation_specificitymax_rateinformation_rateinterspike_interval_cvin_field_mean_rateout_field_mean_rateburst_event_ratiospecificityspeed_score
count102.000000102.000000102.000000102.000000102.000000102.000000102.000000102.000000102.000000102.000000102.000000102.000000102.000000
mean8.3922520.4402960.6556985.9774080.21573633.7164780.9647872.22363612.9360216.1222280.1972640.4558780.104697
std6.0570010.3570380.2117043.7024000.23591613.2493120.5729720.8197347.2118955.3663320.0821640.2367770.081989
min0.198337-0.5169140.1726841.9300260.0130882.8462810.0631731.1106720.5246390.0990600.0084750.097718-0.138128
25%3.5791840.2659490.4584933.0443030.06665625.5551100.5642791.6204727.5557601.7336240.1467550.2480570.056903
50%6.8385610.3990530.6995614.8918550.12856231.4025580.8624132.08402011.4515604.2348710.1929480.3761430.106314
75%11.9345990.7495610.8423328.0015870.30071342.3347861.1903242.67399117.3353568.5834150.2474050.6846230.149313
max24.8587381.1551230.96700319.9114771.35916465.9907933.1822856.52696034.48991321.6962650.3930371.0910640.390079
\n", "
" ], "text/plain": [ " average_rate gridness sparsity selectivity \\\n", "count 102.000000 102.000000 102.000000 102.000000 \n", "mean 8.392252 0.440296 0.655698 5.977408 \n", "std 6.057001 0.357038 0.211704 3.702400 \n", "min 0.198337 -0.516914 0.172684 1.930026 \n", "25% 3.579184 0.265949 0.458493 3.044303 \n", "50% 6.838561 0.399053 0.699561 4.891855 \n", "75% 11.934599 0.749561 0.842332 8.001587 \n", "max 24.858738 1.155123 0.967003 19.911477 \n", "\n", " information_specificity max_rate information_rate \\\n", "count 102.000000 102.000000 102.000000 \n", "mean 0.215736 33.716478 0.964787 \n", "std 0.235916 13.249312 0.572972 \n", "min 0.013088 2.846281 0.063173 \n", "25% 0.066656 25.555110 0.564279 \n", "50% 0.128562 31.402558 0.862413 \n", "75% 0.300713 42.334786 1.190324 \n", "max 1.359164 65.990793 3.182285 \n", "\n", " interspike_interval_cv in_field_mean_rate out_field_mean_rate \\\n", "count 102.000000 102.000000 102.000000 \n", "mean 2.223636 12.936021 6.122228 \n", "std 0.819734 7.211895 5.366332 \n", "min 1.110672 0.524639 0.099060 \n", "25% 1.620472 7.555760 1.733624 \n", "50% 2.084020 11.451560 4.234871 \n", "75% 2.673991 17.335356 8.583415 \n", "max 6.526960 34.489913 21.696265 \n", "\n", " burst_event_ratio specificity speed_score \n", "count 102.000000 102.000000 102.000000 \n", "mean 0.197264 0.455878 0.104697 \n", "std 0.082164 0.236777 0.081989 \n", "min 0.008475 0.097718 -0.138128 \n", "25% 0.146755 0.248057 0.056903 \n", "50% 0.192948 0.376143 0.106314 \n", "75% 0.247405 0.684623 0.149313 \n", "max 0.393037 1.091064 0.390079 " ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gridcell_sessions.query(\"stimulated\")[columns].describe()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Create nice table" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [], "source": [ "def summarize(data):\n", " return \"{:.2f} ± {:.2f} ({})\".format(data.mean(), data.sem(), sum(~np.isnan(data)))\n", "\n", "\n", "def MWU(column, stim, base):\n", " '''\n", " Mann Whitney U\n", " '''\n", " Uvalue, pvalue = scipy.stats.mannwhitneyu(\n", " stim[column].dropna(), \n", " base[column].dropna(),\n", " alternative='two-sided')\n", "\n", " return \"{:.2f}, {:.3f}\".format(Uvalue, pvalue)\n", "\n", "\n", "def PRS(column, stim, base):\n", " '''\n", " Permutation ReSampling\n", " '''\n", " pvalue, observed_diff, diffs = permutation_resampling(\n", " stim[column].dropna(), \n", " base[column].dropna(), statistic=np.median)\n", "\n", " return \"{:.2f}, {:.3f}\".format(observed_diff, pvalue)\n", "\n", "\n", "def rename(name):\n", " return name.replace(\"_field\", \"-field\").replace(\"_\", \" \").capitalize()" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
BaselineStimulatedMWUPRS
Average rate8.90 ± 0.67 (129)8.39 ± 0.60 (102)6514.00, 0.8980.38, 0.786
Gridness0.52 ± 0.03 (129)0.44 ± 0.04 (102)5681.00, 0.0750.13, 0.065
Sparsity0.62 ± 0.02 (129)0.66 ± 0.02 (102)7486.00, 0.0720.06, 0.124
Selectivity5.93 ± 0.28 (129)5.98 ± 0.37 (102)6254.00, 0.5200.10, 0.803
Information specificity0.23 ± 0.02 (129)0.22 ± 0.02 (102)5573.00, 0.0460.05, 0.031
Max rate37.44 ± 1.44 (129)33.72 ± 1.31 (102)5851.00, 0.1493.66, 0.072
Information rate1.25 ± 0.05 (129)0.96 ± 0.06 (102)4646.00, 0.0000.29, 0.001
Interspike interval cv2.40 ± 0.07 (129)2.22 ± 0.08 (102)5516.00, 0.0350.14, 0.270
In-field mean rate14.72 ± 0.82 (129)12.94 ± 0.71 (102)6026.00, 0.2730.76, 0.414
Out-field mean rate6.35 ± 0.60 (129)6.12 ± 0.53 (102)6535.00, 0.9310.08, 0.921
Burst event ratio0.21 ± 0.01 (129)0.20 ± 0.01 (102)5792.00, 0.1190.02, 0.071
Specificity0.48 ± 0.02 (129)0.46 ± 0.02 (102)5962.00, 0.2220.06, 0.181
Speed score0.14 ± 0.01 (129)0.10 ± 0.01 (102)5128.00, 0.0040.02, 0.008
\n", "
" ], "text/plain": [ " Baseline Stimulated \\\n", "Average rate 8.90 ± 0.67 (129) 8.39 ± 0.60 (102) \n", "Gridness 0.52 ± 0.03 (129) 0.44 ± 0.04 (102) \n", "Sparsity 0.62 ± 0.02 (129) 0.66 ± 0.02 (102) \n", "Selectivity 5.93 ± 0.28 (129) 5.98 ± 0.37 (102) \n", "Information specificity 0.23 ± 0.02 (129) 0.22 ± 0.02 (102) \n", "Max rate 37.44 ± 1.44 (129) 33.72 ± 1.31 (102) \n", "Information rate 1.25 ± 0.05 (129) 0.96 ± 0.06 (102) \n", "Interspike interval cv 2.40 ± 0.07 (129) 2.22 ± 0.08 (102) \n", "In-field mean rate 14.72 ± 0.82 (129) 12.94 ± 0.71 (102) \n", "Out-field mean rate 6.35 ± 0.60 (129) 6.12 ± 0.53 (102) \n", "Burst event ratio 0.21 ± 0.01 (129) 0.20 ± 0.01 (102) \n", "Specificity 0.48 ± 0.02 (129) 0.46 ± 0.02 (102) \n", "Speed score 0.14 ± 0.01 (129) 0.10 ± 0.01 (102) \n", "\n", " MWU PRS \n", "Average rate 6514.00, 0.898 0.38, 0.786 \n", "Gridness 5681.00, 0.075 0.13, 0.065 \n", "Sparsity 7486.00, 0.072 0.06, 0.124 \n", "Selectivity 6254.00, 0.520 0.10, 0.803 \n", "Information specificity 5573.00, 0.046 0.05, 0.031 \n", "Max rate 5851.00, 0.149 3.66, 0.072 \n", "Information rate 4646.00, 0.000 0.29, 0.001 \n", "Interspike interval cv 5516.00, 0.035 0.14, 0.270 \n", "In-field mean rate 6026.00, 0.273 0.76, 0.414 \n", "Out-field mean rate 6535.00, 0.931 0.08, 0.921 \n", "Burst event ratio 5792.00, 0.119 0.02, 0.071 \n", "Specificity 5962.00, 0.222 0.06, 0.181 \n", "Speed score 5128.00, 0.004 0.02, 0.008 " ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "_stim_data = gridcell_sessions.query('stimulated')\n", "_base_data = gridcell_sessions.query('baseline')\n", "\n", "result = pd.DataFrame()\n", "\n", "result['Baseline'] = _base_data[columns].agg(summarize)\n", "result['Stimulated'] = _stim_data[columns].agg(summarize)\n", "\n", "\n", "result.index = map(rename, result.index)\n", "\n", "result['MWU'] = list(map(lambda x: MWU(x, _stim_data, _base_data), columns))\n", "result['PRS'] = list(map(lambda x: PRS(x, _stim_data, _base_data), columns))\n", "\n", "result.to_latex(output_path / \"statistics\" / \"statistics.tex\")\n", "result.to_latex(output_path / \"statistics\" / \"statistics.csv\")\n", "result" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Baseline11 HzMWUPRS
Average rate8.96 ± 0.80 (63)8.80 ± 0.85 (58)1781.00, 0.8130.04, 0.969
Gridness0.53 ± 0.05 (63)0.41 ± 0.05 (58)1459.00, 0.0570.21, 0.038
Sparsity0.63 ± 0.02 (63)0.67 ± 0.03 (58)2138.00, 0.1070.07, 0.126
Selectivity5.76 ± 0.40 (63)5.69 ± 0.50 (58)1687.00, 0.4690.00, 0.981
Information specificity0.24 ± 0.03 (63)0.21 ± 0.03 (58)1452.00, 0.0520.06, 0.031
Max rate37.39 ± 1.91 (63)33.11 ± 1.85 (58)1538.00, 0.1344.06, 0.128
Information rate1.31 ± 0.08 (63)0.94 ± 0.08 (58)1143.00, 0.0000.32, 0.003
Interspike interval cv2.39 ± 0.10 (63)2.19 ± 0.12 (58)1462.00, 0.0590.18, 0.135
In-field mean rate14.88 ± 1.05 (63)13.27 ± 1.04 (58)1633.00, 0.3150.77, 0.683
Out-field mean rate6.37 ± 0.67 (63)6.57 ± 0.77 (58)1795.00, 0.8700.47, 0.719
Burst event ratio0.22 ± 0.01 (63)0.22 ± 0.01 (58)1897.00, 0.7180.00, 0.824
Specificity0.47 ± 0.03 (63)0.44 ± 0.03 (58)1605.00, 0.2500.06, 0.398
Speed score0.14 ± 0.01 (63)0.11 ± 0.01 (58)1378.00, 0.0200.04, 0.023
\n", "
" ], "text/plain": [ " Baseline 11 Hz MWU \\\n", "Average rate 8.96 ± 0.80 (63) 8.80 ± 0.85 (58) 1781.00, 0.813 \n", "Gridness 0.53 ± 0.05 (63) 0.41 ± 0.05 (58) 1459.00, 0.057 \n", "Sparsity 0.63 ± 0.02 (63) 0.67 ± 0.03 (58) 2138.00, 0.107 \n", "Selectivity 5.76 ± 0.40 (63) 5.69 ± 0.50 (58) 1687.00, 0.469 \n", "Information specificity 0.24 ± 0.03 (63) 0.21 ± 0.03 (58) 1452.00, 0.052 \n", "Max rate 37.39 ± 1.91 (63) 33.11 ± 1.85 (58) 1538.00, 0.134 \n", "Information rate 1.31 ± 0.08 (63) 0.94 ± 0.08 (58) 1143.00, 0.000 \n", "Interspike interval cv 2.39 ± 0.10 (63) 2.19 ± 0.12 (58) 1462.00, 0.059 \n", "In-field mean rate 14.88 ± 1.05 (63) 13.27 ± 1.04 (58) 1633.00, 0.315 \n", "Out-field mean rate 6.37 ± 0.67 (63) 6.57 ± 0.77 (58) 1795.00, 0.870 \n", "Burst event ratio 0.22 ± 0.01 (63) 0.22 ± 0.01 (58) 1897.00, 0.718 \n", "Specificity 0.47 ± 0.03 (63) 0.44 ± 0.03 (58) 1605.00, 0.250 \n", "Speed score 0.14 ± 0.01 (63) 0.11 ± 0.01 (58) 1378.00, 0.020 \n", "\n", " PRS \n", "Average rate 0.04, 0.969 \n", "Gridness 0.21, 0.038 \n", "Sparsity 0.07, 0.126 \n", "Selectivity 0.00, 0.981 \n", "Information specificity 0.06, 0.031 \n", "Max rate 4.06, 0.128 \n", "Information rate 0.32, 0.003 \n", "Interspike interval cv 0.18, 0.135 \n", "In-field mean rate 0.77, 0.683 \n", "Out-field mean rate 0.47, 0.719 \n", "Burst event ratio 0.00, 0.824 \n", "Specificity 0.06, 0.398 \n", "Speed score 0.04, 0.023 " ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "_stim_data = stimulated_11\n", "_base_data = baseline_i\n", "\n", "result = pd.DataFrame()\n", "\n", "result['Baseline'] = _base_data[columns].agg(summarize)\n", "result['11 Hz'] = _stim_data[columns].agg(summarize)\n", "\n", "\n", "result.index = map(rename, result.index)\n", "\n", "result['MWU'] = list(map(lambda x: MWU(x, _stim_data, _base_data), columns))\n", "result['PRS'] = list(map(lambda x: PRS(x, _stim_data, _base_data), columns))\n", "\n", "\n", "result.to_latex(output_path / \"statistics\" / \"statistics_11.tex\")\n", "result.to_latex(output_path / \"statistics\" / \"statistics_11.csv\")\n", "result" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Baseline30 HzMWUPRS
Average rate8.29 ± 0.87 (52)7.61 ± 0.87 (38)958.00, 0.8100.27, 0.805
Gridness0.54 ± 0.04 (52)0.48 ± 0.06 (38)914.00, 0.5480.04, 0.608
Sparsity0.63 ± 0.03 (52)0.64 ± 0.03 (38)1040.00, 0.6740.06, 0.401
Selectivity5.96 ± 0.46 (52)6.42 ± 0.60 (38)1019.00, 0.8030.20, 0.850
Information specificity0.21 ± 0.02 (52)0.22 ± 0.03 (38)950.00, 0.7590.04, 0.505
Max rate36.27 ± 2.34 (52)33.49 ± 1.89 (38)943.00, 0.7162.90, 0.558
Information rate1.13 ± 0.08 (52)0.98 ± 0.09 (38)827.00, 0.1900.07, 0.332
Interspike interval cv2.37 ± 0.09 (52)2.23 ± 0.11 (38)869.00, 0.3330.17, 0.470
In-field mean rate13.79 ± 1.12 (52)12.21 ± 0.98 (38)912.00, 0.5371.06, 0.452
Out-field mean rate5.80 ± 0.72 (52)5.36 ± 0.73 (38)959.00, 0.8160.13, 0.916
Burst event ratio0.20 ± 0.01 (52)0.16 ± 0.01 (38)676.00, 0.0110.05, 0.007
Specificity0.47 ± 0.03 (52)0.48 ± 0.04 (38)976.00, 0.9250.00, 0.985
Speed score0.12 ± 0.01 (52)0.11 ± 0.01 (38)784.00, 0.0960.01, 0.241
\n", "
" ], "text/plain": [ " Baseline 30 Hz MWU \\\n", "Average rate 8.29 ± 0.87 (52) 7.61 ± 0.87 (38) 958.00, 0.810 \n", "Gridness 0.54 ± 0.04 (52) 0.48 ± 0.06 (38) 914.00, 0.548 \n", "Sparsity 0.63 ± 0.03 (52) 0.64 ± 0.03 (38) 1040.00, 0.674 \n", "Selectivity 5.96 ± 0.46 (52) 6.42 ± 0.60 (38) 1019.00, 0.803 \n", "Information specificity 0.21 ± 0.02 (52) 0.22 ± 0.03 (38) 950.00, 0.759 \n", "Max rate 36.27 ± 2.34 (52) 33.49 ± 1.89 (38) 943.00, 0.716 \n", "Information rate 1.13 ± 0.08 (52) 0.98 ± 0.09 (38) 827.00, 0.190 \n", "Interspike interval cv 2.37 ± 0.09 (52) 2.23 ± 0.11 (38) 869.00, 0.333 \n", "In-field mean rate 13.79 ± 1.12 (52) 12.21 ± 0.98 (38) 912.00, 0.537 \n", "Out-field mean rate 5.80 ± 0.72 (52) 5.36 ± 0.73 (38) 959.00, 0.816 \n", "Burst event ratio 0.20 ± 0.01 (52) 0.16 ± 0.01 (38) 676.00, 0.011 \n", "Specificity 0.47 ± 0.03 (52) 0.48 ± 0.04 (38) 976.00, 0.925 \n", "Speed score 0.12 ± 0.01 (52) 0.11 ± 0.01 (38) 784.00, 0.096 \n", "\n", " PRS \n", "Average rate 0.27, 0.805 \n", "Gridness 0.04, 0.608 \n", "Sparsity 0.06, 0.401 \n", "Selectivity 0.20, 0.850 \n", "Information specificity 0.04, 0.505 \n", "Max rate 2.90, 0.558 \n", "Information rate 0.07, 0.332 \n", "Interspike interval cv 0.17, 0.470 \n", "In-field mean rate 1.06, 0.452 \n", "Out-field mean rate 0.13, 0.916 \n", "Burst event ratio 0.05, 0.007 \n", "Specificity 0.00, 0.985 \n", "Speed score 0.01, 0.241 " ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "_stim_data = stimulated_30\n", "_base_data = baseline_ii\n", "\n", "result = pd.DataFrame()\n", "\n", "result['Baseline'] = _base_data[columns].agg(summarize)\n", "result['30 Hz'] = _stim_data[columns].agg(summarize)\n", "\n", "result.index = map(rename, result.index)\n", "\n", "result['MWU'] = list(map(lambda x: MWU(x, _stim_data, _base_data), columns))\n", "result['PRS'] = list(map(lambda x: PRS(x, _stim_data, _base_data), columns))\n", "\n", "\n", "result.to_latex(output_path / \"statistics\" / \"statistics_30.tex\")\n", "result.to_latex(output_path / \"statistics\" / \"statistics_30.csv\")\n", "result" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Baseline I30 HzMWUPRS
Average rate8.96 ± 0.80 (63)7.61 ± 0.87 (38)1081.00, 0.4180.27, 0.803
Gridness0.53 ± 0.05 (63)0.48 ± 0.06 (38)1094.00, 0.4720.08, 0.363
Sparsity0.63 ± 0.02 (63)0.64 ± 0.03 (38)1261.00, 0.6560.03, 0.641
Selectivity5.76 ± 0.40 (63)6.42 ± 0.60 (38)1276.00, 0.5820.86, 0.283
Information specificity0.24 ± 0.03 (63)0.22 ± 0.03 (38)1076.00, 0.3980.05, 0.161
Max rate37.39 ± 1.91 (63)33.49 ± 1.89 (38)1027.00, 0.2353.99, 0.182
Information rate1.31 ± 0.08 (63)0.98 ± 0.09 (38)797.00, 0.0050.32, 0.045
Interspike interval cv2.39 ± 0.10 (63)2.23 ± 0.11 (38)1100.00, 0.4990.01, 0.993
In-field mean rate14.88 ± 1.05 (63)12.21 ± 0.98 (38)1018.00, 0.2111.74, 0.272
Out-field mean rate6.37 ± 0.67 (63)5.36 ± 0.73 (38)1079.00, 0.4100.51, 0.644
Burst event ratio0.22 ± 0.01 (63)0.16 ± 0.01 (38)675.00, 0.0000.05, 0.006
Specificity0.47 ± 0.03 (63)0.48 ± 0.04 (38)1206.00, 0.9520.01, 0.869
Speed score0.14 ± 0.01 (63)0.11 ± 0.01 (38)835.00, 0.0110.06, 0.005
\n", "
" ], "text/plain": [ " Baseline I 30 Hz MWU \\\n", "Average rate 8.96 ± 0.80 (63) 7.61 ± 0.87 (38) 1081.00, 0.418 \n", "Gridness 0.53 ± 0.05 (63) 0.48 ± 0.06 (38) 1094.00, 0.472 \n", "Sparsity 0.63 ± 0.02 (63) 0.64 ± 0.03 (38) 1261.00, 0.656 \n", "Selectivity 5.76 ± 0.40 (63) 6.42 ± 0.60 (38) 1276.00, 0.582 \n", "Information specificity 0.24 ± 0.03 (63) 0.22 ± 0.03 (38) 1076.00, 0.398 \n", "Max rate 37.39 ± 1.91 (63) 33.49 ± 1.89 (38) 1027.00, 0.235 \n", "Information rate 1.31 ± 0.08 (63) 0.98 ± 0.09 (38) 797.00, 0.005 \n", "Interspike interval cv 2.39 ± 0.10 (63) 2.23 ± 0.11 (38) 1100.00, 0.499 \n", "In-field mean rate 14.88 ± 1.05 (63) 12.21 ± 0.98 (38) 1018.00, 0.211 \n", "Out-field mean rate 6.37 ± 0.67 (63) 5.36 ± 0.73 (38) 1079.00, 0.410 \n", "Burst event ratio 0.22 ± 0.01 (63) 0.16 ± 0.01 (38) 675.00, 0.000 \n", "Specificity 0.47 ± 0.03 (63) 0.48 ± 0.04 (38) 1206.00, 0.952 \n", "Speed score 0.14 ± 0.01 (63) 0.11 ± 0.01 (38) 835.00, 0.011 \n", "\n", " PRS \n", "Average rate 0.27, 0.803 \n", "Gridness 0.08, 0.363 \n", "Sparsity 0.03, 0.641 \n", "Selectivity 0.86, 0.283 \n", "Information specificity 0.05, 0.161 \n", "Max rate 3.99, 0.182 \n", "Information rate 0.32, 0.045 \n", "Interspike interval cv 0.01, 0.993 \n", "In-field mean rate 1.74, 0.272 \n", "Out-field mean rate 0.51, 0.644 \n", "Burst event ratio 0.05, 0.006 \n", "Specificity 0.01, 0.869 \n", "Speed score 0.06, 0.005 " ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "_stim_data = stimulated_30\n", "_base_data = baseline_i\n", "\n", "result = pd.DataFrame()\n", "\n", "result['Baseline I'] = _base_data[columns].agg(summarize)\n", "result['30 Hz'] = _stim_data[columns].agg(summarize)\n", "\n", "result.index = map(rename, result.index)\n", "\n", "result['MWU'] = list(map(lambda x: MWU(x, _stim_data, _base_data), columns))\n", "result['PRS'] = list(map(lambda x: PRS(x, _stim_data, _base_data), columns))\n", "\n", "\n", "result.to_latex(output_path / \"statistics\" / \"statistics_b_i_30.tex\")\n", "result.to_latex(output_path / \"statistics\" / \"statistics_b_i_30.csv\")\n", "result" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "_stim_data = stimulated_30\n", "_base_data = stimulated_11\n", "\n", "result = pd.DataFrame()\n", "\n", "result['11 Hz'] = _base_data[columns].agg(summarize)\n", "result['30 Hz'] = _stim_data[columns].agg(summarize)\n", "\n", "\n", "result.index = map(rename, result.index)\n", "\n", "result['MWU'] = list(map(lambda x: MWU(x, _stim_data, _base_data), columns))\n", "result['PRS'] = list(map(lambda x: PRS(x, _stim_data, _base_data), columns))\n", "\n", "\n", "result.to_latex(output_path / \"statistics\" / \"statistics_11_vs_30.tex\")\n", "result.to_latex(output_path / \"statistics\" / \"statistics_11_vs_30.csv\")\n", "result" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "_stim_data = baseline_i\n", "_base_data = baseline_ii\n", "\n", "result = pd.DataFrame()\n", "\n", "result['Baseline I'] = _stim_data[columns].agg(summarize)\n", "result['Baseline II'] = _base_data[columns].agg(summarize)\n", "\n", "result.index = map(rename, result.index)\n", "\n", "result['MWU'] = list(map(lambda x: MWU(x, _stim_data, _base_data), columns))\n", "result['PRS'] = list(map(lambda x: PRS(x, _stim_data, _base_data), columns))\n", "\n", "\n", "result.to_latex(output_path / \"statistics\" / \"statistics_base_i_vs_base_ii.tex\")\n", "result.to_latex(output_path / \"statistics\" / \"statistics_base_i_vs_base_ii.csv\")\n", "result" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Violinplot" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "plt.rc('axes', titlesize=12)\n", "plt.rcParams.update({\n", " 'font.size': 12, \n", " 'figure.figsize': (1.7, 3), \n", " 'figure.dpi': 150\n", "})" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# colors = ['#1b9e77','#d95f02','#7570b3','#e7298a']\n", "# labels = ['Baseline I', '11 Hz', 'Baseline II', '30 Hz']\n", "\n", "stuff = {\n", " '': {\n", " 'base': gridcell_sessions.query('baseline'),\n", " 'stim': gridcell_sessions.query('stimulated')\n", " },\n", " '_11': {\n", " 'base': baseline_i,\n", " 'stim': stimulated_11\n", " },\n", " '_30': {\n", " 'base': baseline_ii,\n", " 'stim': stimulated_30\n", " }\n", "}\n", "\n", "label = {\n", " '': ['Baseline ', ' Stimulated'],\n", " '_11': ['Baseline I ', ' 11 Hz'],\n", " '_30': ['Baseline II ', ' 30 Hz']\n", "}\n", "\n", "colors = {\n", " '': None,\n", " '_11': ['#1b9e77', '#d95f02'],\n", " '_30': ['#7570b3', '#e7298a']\n", "}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Information rate" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for key, data in stuff.items():\n", " baseline = data['base']['information_specificity'].to_numpy()\n", " stimulated = data['stim']['information_specificity'].to_numpy()\n", " print(key)\n", " plt.figure()\n", " violinplot(baseline, stimulated, xticks=label[key], colors=colors[key])\n", " plt.title(\"Spatial information specificity\")\n", " plt.ylabel(\"bits/spike\")\n", " plt.ylim(-0.2, 1.6)\n", "\n", " plt.savefig(output_path / \"figures\" / f\"information_specificity{key}.svg\", bbox_inches=\"tight\")\n", " plt.savefig(output_path / \"figures\" / f\"information_specificity{key}.png\", dpi=600, bbox_inches=\"tight\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "for key, data in stuff.items():\n", " baseline = data['base']['information_rate'].to_numpy()\n", " stimulated = data['stim']['information_rate'].to_numpy()\n", " print(key)\n", " plt.figure()\n", " violinplot(baseline, stimulated, xticks=label[key], colors=colors[key])\n", " plt.title(\"Spatial information\")\n", " plt.ylabel(\"bits/s\")\n", " plt.ylim(-0.2, 4)\n", "\n", " plt.savefig(output_path / \"figures\" / f\"spatial_information{key}.svg\", bbox_inches=\"tight\")\n", " plt.savefig(output_path / \"figures\" / f\"spatial_information{key}.png\", dpi=600, bbox_inches=\"tight\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for key, data in stuff.items():\n", " baseline = data['base']['specificity'].to_numpy()\n", " stimulated = data['stim']['specificity'].to_numpy()\n", " plt.figure()\n", " violinplot(baseline, stimulated, xticks=label[key], colors=colors[key])\n", " plt.title(\"Spatial specificity\")\n", " plt.ylabel(\"\")\n", " plt.ylim(-0.02, 1.25)\n", " plt.savefig(output_path / \"figures\" / f\"specificity{key}.svg\", bbox_inches=\"tight\")\n", " plt.savefig(output_path / \"figures\" / f\"specificity{key}.png\", dpi=600, bbox_inches=\"tight\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": false }, "outputs": [], "source": [ "\n", "for key, data in stuff.items():\n", " baseline = data['base']['average_rate'].to_numpy()\n", " stimulated = data['stim']['average_rate'].to_numpy()\n", " plt.figure()\n", " violinplot(baseline, stimulated, xticks=label[key], colors=colors[key])\n", " plt.title(\"Average rate\")\n", " plt.ylabel(\"spikes/s\")\n", " plt.ylim(-0.2, 40)\n", "\n", " plt.savefig(output_path / \"figures\" / f\"average_rate{key}.svg\", bbox_inches=\"tight\")\n", " plt.savefig(output_path / \"figures\" / f\"average_rate{key}.png\", dpi=600, bbox_inches=\"tight\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": false }, "outputs": [], "source": [ "for key, data in stuff.items():\n", " baseline = data['base']['max_rate'].to_numpy()\n", " stimulated = data['stim']['max_rate'].to_numpy()\n", " plt.figure()\n", " violinplot(baseline, stimulated, xticks=label[key], colors=colors[key])\n", " plt.title(\"Max rate\")\n", " plt.ylabel(\"spikes/s\")\n", " # plt.ylim(-0.2, 45)\n", "\n", " plt.savefig(output_path / \"figures\" / f\"max_rate{key}.svg\", bbox_inches=\"tight\")\n", " plt.savefig(output_path / \"figures\" / f\"max_rate{key}.png\", dpi=600, bbox_inches=\"tight\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "for key, data in stuff.items():\n", " baseline = data['base']['interspike_interval_cv'].to_numpy()\n", " stimulated = data['stim']['interspike_interval_cv'].to_numpy()\n", " plt.figure()\n", " violinplot(baseline, stimulated, xticks=label[key], colors=colors[key])\n", " plt.title(\"ISI CV\")\n", " plt.ylabel(\"Coefficient of variation\")\n", " # plt.ylim(0.9, 5)\n", "\n", " plt.savefig(output_path / \"figures\" / f\"isi_cv{key}.svg\", bbox_inches=\"tight\")\n", " plt.savefig(output_path / \"figures\" / f\"isi_cv{key}.png\", dpi=600, bbox_inches=\"tight\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "for key, data in stuff.items():\n", " baseline = data['base']['in_field_mean_rate'].to_numpy()\n", " stimulated = data['stim']['in_field_mean_rate'].to_numpy()\n", " plt.figure()\n", " violinplot(baseline, stimulated, xticks=label[key], colors=colors[key])\n", " plt.title(\"In-field rate\")\n", " plt.ylabel(\"spikes/s\")\n", " # plt.ylim(-0.1, 18)\n", "\n", " plt.savefig(output_path / \"figures\" / f\"in_field_mean_rate{key}.svg\", bbox_inches=\"tight\")\n", " plt.savefig(output_path / \"figures\" / f\"in_field_mean_rate{key}.png\", dpi=600, bbox_inches=\"tight\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "for key, data in stuff.items():\n", " baseline = data['base']['out_field_mean_rate'].to_numpy()\n", " stimulated = data['stim']['out_field_mean_rate'].to_numpy()\n", " plt.figure()\n", " violinplot(baseline, stimulated, xticks=label[key], colors=colors[key])\n", " plt.title(\"Out-of-field rate\")\n", " plt.ylabel(\"spikes/s\")\n", " # plt.ylim(-0.2, 8)\n", "\n", " plt.savefig(output_path / \"figures\" / f\"out_field_mean_rate{key}.svg\", bbox_inches=\"tight\")\n", " plt.savefig(output_path / \"figures\" / f\"out_field_mean_rate{key}.png\", dpi=600, bbox_inches=\"tight\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for key, data in stuff.items():\n", " baseline = data['base']['burst_event_ratio'].to_numpy()\n", " stimulated = data['stim']['burst_event_ratio'].to_numpy()\n", " plt.figure()\n", " violinplot(baseline, stimulated, xticks=label[key], colors=colors[key])\n", " plt.title(\"Bursting ratio\")\n", " plt.ylabel(\"\")\n", " # plt.ylim(-0.02, 0.60)\n", "\n", " plt.savefig(output_path / \"figures\" / f\"burst_event_ratio{key}.svg\", bbox_inches=\"tight\")\n", " plt.savefig(output_path / \"figures\" / f\"burst_event_ratio{key}.png\", dpi=600, bbox_inches=\"tight\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for key, data in stuff.items():\n", " baseline = data['base']['max_field_mean_rate'].to_numpy()\n", " stimulated = data['stim']['max_field_mean_rate'].to_numpy()\n", " plt.figure()\n", " violinplot(baseline, stimulated, xticks=label[key], colors=colors[key])\n", " plt.title(\"Mean rate of max field\")\n", " plt.ylabel(\"(spikes/s)\")\n", " # plt.ylim(-0.5,25)\n", "\n", " plt.savefig(output_path / \"figures\" / f\"max_field_mean_rate{key}.svg\", bbox_inches=\"tight\")\n", " plt.savefig(output_path / \"figures\" / f\"max_field_mean_rate{key}.png\", dpi=600, bbox_inches=\"tight\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for key, data in stuff.items():\n", " baseline = data['base']['bursty_spike_ratio'].to_numpy()\n", " stimulated = data['stim']['bursty_spike_ratio'].to_numpy()\n", " plt.figure()\n", " violinplot(baseline, stimulated, xticks=label[key], colors=colors[key])\n", " plt.title(\"ratio of spikes per burst\")\n", " plt.ylabel(\"\")\n", " # plt.ylim(-0.03,0.9)\n", "\n", " plt.savefig(output_path / \"figures\" / f\"bursty_spike_ratio{key}.svg\", bbox_inches=\"tight\")\n", " plt.savefig(output_path / \"figures\" / f\"bursty_spike_ratio{key}.png\", dpi=600, bbox_inches=\"tight\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "for key, data in stuff.items():\n", " baseline = data['base']['gridness'].to_numpy()\n", " stimulated = data['stim']['gridness'].to_numpy()\n", " plt.figure()\n", " violinplot(baseline, stimulated, xticks=label[key], colors=colors[key])\n", " plt.title(\"Gridness\")\n", " plt.ylabel(\"Gridness\")\n", " plt.ylim(-0.6, 1.5)\n", "\n", " plt.savefig(output_path / \"figures\" / f\"gridness{key}.svg\", bbox_inches=\"tight\")\n", " plt.savefig(output_path / \"figures\" / f\"gridness{key}.png\", dpi=600, bbox_inches=\"tight\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for key, data in stuff.items(): #TODO narrow broad spiking\n", " baseline = data['base']['speed_score'].to_numpy()\n", " stimulated = data['stim']['speed_score'].to_numpy()\n", " plt.figure()\n", " violinplot(baseline, stimulated, xticks=label[key], colors=colors[key])\n", " plt.title(\"Speed score\")\n", " plt.ylabel(\"Speed score\")\n", " # plt.ylim(-0.1, 0.5)\n", "\n", " plt.savefig(output_path / \"figures\" / f\"speed_score{key}.svg\", bbox_inches=\"tight\")\n", " plt.savefig(output_path / \"figures\" / f\"speed_score{key}.png\", dpi=600, bbox_inches=\"tight\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": false }, "outputs": [], "source": [ "# fig, (ax1, ax2) = plt.subplots(2,1, figsize=(6,6), sharey=True)\n", "# for key, data in stuff.items():\n", "# ax1.set_title('Baseline')\n", "# peak_rate = data['base']['max_rate'].to_numpy()\n", "# spacing = data['base']['spacing'].to_numpy()\n", "# ax1.scatter(spacing, peak_rate)\n", " \n", "# ax2.set_title('Stim')\n", "# peak_rate = data['stim']['max_rate'].to_numpy()\n", "# spacing = data['stim']['spacing'].to_numpy()\n", "# ax2.scatter(spacing, peak_rate, label=key)\n", " \n", "# ax2.legend()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Register in Expipe" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "action = project.require_action(\"comparisons-gridcells\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "copy_tree(output_path, str(action.data_path()))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "septum_mec.analysis.registration.store_notebook(action, \"20_comparisons_gridcells.ipynb\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.6.8" } }, "nbformat": 4, "nbformat_minor": 2 }