{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import os\n", "import expipe\n", "import pathlib\n", "import numpy as np\n", "import spatial_maps.stats as stats\n", "import septum_mec\n", "import septum_mec.analysis.data_processing as dp\n", "import septum_mec.analysis.registration\n", "import head_direction.head as head\n", "import spatial_maps as sp\n", "import speed_cells.speed as spd\n", "import re\n", "import joblib\n", "import multiprocessing\n", "import shutil\n", "import psutil\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "import matplotlib\n", "import seaborn as sns\n", "from distutils.dir_util import copy_tree\n", "from neo import SpikeTrain\n", "import scipy\n", "from functools import reduce\n", "from tqdm.notebook import tqdm_notebook as tqdm\n", "tqdm.pandas()\n", "\n", "from spikewaveform.core import calculate_waveform_features_from_template, cluster_waveform_features\n", "\n", "from septum_mec.analysis.plotting import violinplot, despine\n", "\n", "from septum_mec.analysis.statistics import load_data_frames, make_paired_tables, make_statistics_table" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## chose where to sample LFP" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "#################################################\n", "\n", "# lfp_location = ''\n", "# lfp_location = '-other-tetrode'\n", "lfp_location = '-other-drive'\n", "\n", "##################################################" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "plt.rc('axes', titlesize=12)\n", "plt.rcParams.update({\n", " 'font.size': 12, \n", " 'figure.figsize': (6, 4), \n", " 'figure.dpi': 150\n", "})\n", "\n", "output_path = pathlib.Path(\"output\") / (\"stimulus-spike-lfp-response\" + lfp_location)\n", "(output_path / \"statistics\").mkdir(exist_ok=True, parents=True)\n", "(output_path / \"figures\").mkdir(exist_ok=True, parents=True)\n", "output_path.mkdir(exist_ok=True)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "project_path = dp.project_path()\n", "project = expipe.get_project(project_path)\n", "actions = project.actions" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of sessions above threshold 194\n", "Number of animals 4\n", "Number of individual gridcells 139\n", "Number of gridcell recordings 230\n" ] } ], "source": [ "data, labels, colors, queries = load_data_frames()" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "lfp_action = actions['stimulus-spike-lfp-response' + lfp_location]\n", "lfp_results = pd.read_csv(lfp_action.data_path('results'))" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "# lfp_results has old unit id's but correct on (action, unit_name, channel_group)\n", "lfp_results = lfp_results.drop('unit_id', axis=1)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "data = data.merge(lfp_results, how='left')" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "data['stim_strength'] = data.stim_p_max / data.theta_peak" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "keys = [\n", " 'theta_energy',\n", " 'theta_peak',\n", " 'theta_freq',\n", " 'theta_half_width',\n", " 'theta_vec_len',\n", " 'theta_ang',\n", " 'stim_energy',\n", " 'stim_half_width',\n", " 'stim_p_max',\n", " 'stim_strength',\n", " 'stim_vec_len',\n", " 'stim_ang'\n", "]" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "results, labels = make_paired_tables(data, keys)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | entity | \n", "unit_idnum | \n", "channel_group | \n", "date | \n", "Baseline I | \n", "11 Hz | \n", "Baseline II | \n", "30 Hz | \n", "
---|---|---|---|---|---|---|---|---|
51 | \n", "1833 | \n", "8 | \n", "0 | \n", "20719 | \n", "0.214949 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
85 | \n", "1833 | \n", "13 | \n", "0 | \n", "20719 | \n", "NaN | \n", "0.052683 | \n", "0.291401 | \n", "0.055222 | \n", "
86 | \n", "1833 | \n", "14 | \n", "0 | \n", "20719 | \n", "NaN | \n", "0.025182 | \n", "0.451846 | \n", "NaN | \n", "
58 | \n", "1833 | \n", "23 | \n", "0 | \n", "200619 | \n", "0.233113 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
127 | \n", "1833 | \n", "26 | \n", "0 | \n", "200619 | \n", "NaN | \n", "NaN | \n", "0.202562 | \n", "0.049574 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
139 | \n", "1849 | \n", "835 | \n", "4 | \n", "150319 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "0.027863 | \n", "
43 | \n", "1849 | \n", "851 | \n", "5 | \n", "60319 | \n", "0.040082 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
65 | \n", "1849 | \n", "932 | \n", "7 | \n", "280219 | \n", "0.025449 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
74 | \n", "1849 | \n", "937 | \n", "7 | \n", "280219 | \n", "NaN | \n", "0.135503 | \n", "NaN | \n", "NaN | \n", "
105 | \n", "1849 | \n", "939 | \n", "7 | \n", "280219 | \n", "NaN | \n", "NaN | \n", "0.435251 | \n", "NaN | \n", "
137 rows × 8 columns
\n", "\n", " | Theta energy | \n", "Theta peak | \n", "Theta freq | \n", "Theta half width | \n", "Theta vec len | \n", "Theta ang | \n", "Stim energy | \n", "Stim half width | \n", "Stim p max | \n", "Stim strength | \n", "Stim vec len | \n", "Stim ang | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|
Baseline I | \n", "2.0e-01 ± 2.6e-02 (63) | \n", "1.7e-01 ± 1.9e-02 (63) | \n", "7.7e+00 ± 7.5e-02 (63) | \n", "6.4e-01 ± 3.8e-02 (63) | \n", "2.0e-01 ± 1.5e-02 (63) | \n", "3.7e+00 ± 1.0e-01 (63) | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
11 Hz | \n", "9.7e-02 ± 1.6e-02 (56) | \n", "6.9e-02 ± 7.0e-03 (56) | \n", "7.8e+00 ± 1.3e-01 (56) | \n", "4.3e-01 ± 7.6e-02 (56) | \n", "4.0e-02 ± 4.6e-03 (56) | \n", "3.3e+00 ± 2.7e-01 (56) | \n", "8.8e-02 ± 9.1e-03 (58) | \n", "2.2e-01 ± 6.8e-03 (58) | \n", "4.5e-01 ± 3.1e-02 (58) | \n", "9.0e+00 ± 8.9e-01 (58) | \n", "2.2e-01 ± 1.6e-02 (58) | \n", "2.9e+00 ± 2.6e-01 (58) | \n", "
Baseline II | \n", "3.3e-01 ± 4.2e-02 (46) | \n", "2.5e-01 ± 2.5e-02 (46) | \n", "8.1e+00 ± 4.4e-02 (46) | \n", "8.2e-01 ± 6.4e-02 (46) | \n", "2.3e-01 ± 1.9e-02 (46) | \n", "4.0e+00 ± 1.1e-01 (46) | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
30 Hz | \n", "4.3e-02 ± 4.8e-03 (35) | \n", "4.2e-02 ± 4.7e-03 (35) | \n", "7.9e+00 ± 2.0e-01 (35) | \n", "3.0e-01 ± 2.7e-02 (35) | \n", "1.8e-02 ± 2.6e-03 (35) | \n", "3.8e+00 ± 3.1e-01 (35) | \n", "9.1e-02 ± 8.8e-03 (33) | \n", "2.5e-01 ± 4.0e-03 (33) | \n", "3.9e-01 ± 3.3e-02 (33) | \n", "1.3e+01 ± 1.5e+00 (33) | \n", "2.5e-01 ± 1.5e-02 (33) | \n", "2.6e+00 ± 2.4e-01 (33) | \n", "
LMM Baseline I - 11 Hz | \n", "1.1e-01, 1.3e-01 | \n", "5.3e-03, 1.2e-01 | \n", "9.8e-01, -7.5e-03 | \n", "7.8e-02, 2.7e-01 | \n", "1.6e-03, 1.5e-01 | \n", "2.0e-02, 4.3e-01 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
LMM Baseline I - Baseline II | \n", "1.9e-01, -5.3e-02 | \n", "1.2e-01, -4.2e-02 | \n", "7.6e-02, 2.2e-01 | \n", "6.6e-01, -3.6e-02 | \n", "2.6e-01, -3.2e-02 | \n", "6.9e-01, 1.4e-01 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
LMM Baseline I - 30 Hz | \n", "5.5e-02, 1.6e-01 | \n", "1.8e-02, 1.4e-01 | \n", "3.7e-01, -2.3e-01 | \n", "1.1e-11, 3.8e-01 | \n", "9.7e-04, 1.8e-01 | \n", "4.7e-01, 3.5e-01 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
LMM 11 Hz - Baseline II | \n", "1.2e-02, 2.3e-01 | \n", "1.1e-02, 1.7e-01 | \n", "7.1e-01, 1.4e-01 | \n", "1.4e-12, 4.2e-01 | \n", "6.3e-04, 1.6e-01 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
LMM 11 Hz - 30 Hz | \n", "5.2e-02, -6.2e-02 | \n", "4.5e-02, -3.2e-02 | \n", "5.5e-01, 2.8e-01 | \n", "3.3e-01, -1.3e-01 | \n", "1.6e-02, -2.7e-02 | \n", "4.0e-01, 2.8e-01 | \n", "8.7e-01, 6.2e-03 | \n", "2.7e-01, 2.8e-02 | \n", "7.5e-01, -3.0e-02 | \n", "1.1e-01, 4.5e+00 | \n", "6.8e-01, 3.0e-02 | \n", "4.9e-01, -4.2e-01 | \n", "
LMM Baseline II - 30 Hz | \n", "1.9e-02, 2.7e-01 | \n", "2.5e-02, 1.9e-01 | \n", "8.3e-01, 7.0e-02 | \n", "6.4e-04, 4.8e-01 | \n", "4.9e-04, 2.0e-01 | \n", "6.1e-01, 3.0e-01 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "