{ "cells": [ { "cell_type": "code", "execution_count": null, "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.251582 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
85 | \n", "1833 | \n", "13 | \n", "0 | \n", "20719 | \n", "NaN | \n", "0.057134 | \n", "0.194778 | \n", "0.042542 | \n", "
86 | \n", "1833 | \n", "14 | \n", "0 | \n", "20719 | \n", "NaN | \n", "0.049972 | \n", "0.129583 | \n", "NaN | \n", "
58 | \n", "1833 | \n", "23 | \n", "0 | \n", "200619 | \n", "0.247097 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
127 | \n", "1833 | \n", "26 | \n", "0 | \n", "200619 | \n", "NaN | \n", "NaN | \n", "0.179928 | \n", "0.034969 | \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.023559 | \n", "
43 | \n", "1849 | \n", "851 | \n", "5 | \n", "60319 | \n", "0.665441 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
65 | \n", "1849 | \n", "932 | \n", "7 | \n", "280219 | \n", "0.034074 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
74 | \n", "1849 | \n", "937 | \n", "7 | \n", "280219 | \n", "NaN | \n", "0.126604 | \n", "NaN | \n", "NaN | \n", "
105 | \n", "1849 | \n", "939 | \n", "7 | \n", "280219 | \n", "NaN | \n", "NaN | \n", "0.246451 | \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.5e-01 ± 3.3e-02 (63) | \n", "2.2e-01 ± 2.5e-02 (63) | \n", "7.6e+00 ± 9.6e-02 (63) | \n", "7.2e-01 ± 3.4e-02 (63) | \n", "2.1e-01 ± 1.2e-02 (63) | \n", "3.9e+00 ± 1.3e-01 (63) | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
11 Hz | \n", "1.1e-01 ± 1.6e-02 (56) | \n", "8.0e-02 ± 7.9e-03 (56) | \n", "7.7e+00 ± 1.2e-01 (56) | \n", "4.6e-01 ± 7.6e-02 (56) | \n", "4.8e-02 ± 7.3e-03 (56) | \n", "3.5e+00 ± 2.7e-01 (56) | \n", "9.7e-02 ± 1.0e-02 (58) | \n", "3.0e-01 ± 5.1e-02 (58) | \n", "4.5e-01 ± 3.5e-02 (58) | \n", "8.2e+00 ± 9.1e-01 (58) | \n", "2.3e-01 ± 1.5e-02 (58) | \n", "3.1e+00 ± 2.6e-01 (58) | \n", "
Baseline II | \n", "2.7e-01 ± 3.2e-02 (46) | \n", "2.0e-01 ± 2.1e-02 (46) | \n", "8.2e+00 ± 7.7e-02 (46) | \n", "7.8e-01 ± 5.9e-02 (46) | \n", "2.0e-01 ± 1.2e-02 (46) | \n", "3.6e+00 ± 1.3e-01 (46) | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
30 Hz | \n", "3.7e-02 ± 1.5e-03 (35) | \n", "3.5e-02 ± 2.1e-03 (35) | \n", "8.8e+00 ± 1.6e-01 (35) | \n", "2.7e-01 ± 2.9e-02 (35) | \n", "1.7e-02 ± 2.3e-03 (35) | \n", "3.3e+00 ± 3.8e-01 (35) | \n", "1.0e-01 ± 1.0e-02 (33) | \n", "2.6e-01 ± 5.1e-03 (33) | \n", "4.3e-01 ± 3.7e-02 (33) | \n", "1.3e+01 ± 1.1e+00 (33) | \n", "2.7e-01 ± 1.5e-02 (33) | \n", "3.0e+00 ± 2.5e-01 (33) | \n", "
LMM Baseline I - 11 Hz | \n", "NaN | \n", "1.5e-13, 1.4e-01 | \n", "9.3e-01, -2.9e-02 | \n", "1.5e-03, 2.8e-01 | \n", "NaN | \n", "6.2e-01, 2.9e-01 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
LMM Baseline I - Baseline II | \n", "9.8e-01, -1.1e-03 | \n", "3.7e-01, -2.8e-02 | \n", "3.7e-02, 3.2e-01 | \n", "9.7e-01, -5.1e-03 | \n", "NaN | \n", "7.5e-01, -1.2e-01 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
LMM Baseline I - 30 Hz | \n", "1.1e-35, 1.9e-01 | \n", "2.7e-09, 1.7e-01 | \n", "1.4e-02, -9.9e-01 | \n", "1.3e-09, 4.5e-01 | \n", "2.6e-12, 1.8e-01 | \n", "1.3e-01, 7.9e-01 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
LMM 11 Hz - Baseline II | \n", "3.3e-02, 1.7e-01 | \n", "1.1e-01, 1.2e-01 | \n", "1.7e-01, 4.6e-01 | \n", "7.4e-03, 3.3e-01 | \n", "1.6e-03, 1.3e-01 | \n", "7.9e-01, -1.7e-01 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
LMM 11 Hz - 30 Hz | \n", "1.4e-02, -6.8e-02 | \n", "NaN | \n", "1.5e-04, 8.8e-01 | \n", "2.1e-03, -1.8e-01 | \n", "7.2e-02, -3.8e-02 | \n", "7.6e-01, -2.3e-01 | \n", "9.9e-01, 5.8e-04 | \n", "5.9e-01, -5.3e-02 | \n", "9.7e-01, 3.0e-03 | \n", "1.4e-01, 5.0e+00 | \n", "3.5e-01, 4.6e-02 | \n", "4.9e-01, -4.2e-01 | \n", "
LMM Baseline II - 30 Hz | \n", "1.5e-02, 2.1e-01 | \n", "3.6e-02, 1.5e-01 | \n", "1.4e-01, -4.8e-01 | \n", "1.1e-02, 4.7e-01 | \n", "1.2e-13, 1.7e-01 | \n", "4.1e-01, 6.0e-01 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "