{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "from pathlib import Path\n", "from collections import namedtuple\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "from matplotlib.patches import Rectangle\n", "import pandas as pd\n", "import scipy.stats as sstats\n", "\n", "import datareader as reader\n", "import epoch_analysis, kw_dunn" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Trial number" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "dataset_root = \"../01_data/04_formatted\"\n", "figdir = Path(\"../05_figures/01_asymmetry\")\n", "saved = False" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "alltrials = reader.load_trials(dataset_root)\n", "trials = [trial for trial in alltrials if trial.has_eyedata()]" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "def get_info(trials):\n", " sessions = set((trial.subject, trial.session) for trial in trials)\n", " subjects = set(trial.subject for trial in trials)\n", " epochs = sum(trial.states.shape[0] for trial in trials)\n", " return f\"{len(trials)} trials out of {len(sessions)} sessions from {len(subjects)} subjects ({epochs} epochs)\"" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "## Number of trials/epochs used for analysis\n", "\n", "- all annotated trials: 113 trials out of 21 sessions from 4 subjects (876 epochs)\n", "- trials with eye positions: 91 trials out of 17 sessions from 4 subjects (728 epochs)\n" ] } ], "source": [ "print(\"## Number of trials/epochs used for analysis\\n\")\n", "print(f\"- all annotated trials: {get_info(alltrials)}\")\n", "print(f\"- trials with eye positions: {get_info(trials)}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Average-trace figure" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Baseline subtraction\n", "\n", "Adjust so that the range of values will be normalized to 1." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "def normalize(vec, subtract_min=True):\n", " m = np.nanmin(vec)\n", " M = np.nanmax(vec)\n", " den = vec - m if subtract_min == True else vec\n", " return den / (M - m)\n", "\n", "for trial in trials:\n", " for side in (\"left\", \"right\"):\n", " trial.tracking[f\"{side}_whisker_normalized\"] = normalize(trial.tracking[f\"{side}_whisker_angle_deg\"], subtract_min=False)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | time | \n", "left_whisker_angle_deg | \n", "left_whisker_radius_px | \n", "left_pupil_normalized_position | \n", "left_pupil_normalized_diameter | \n", "right_whisker_angle_deg | \n", "right_whisker_radius_px | \n", "right_pupil_normalized_position | \n", "right_pupil_normalized_diameter | \n", "left_whisker_normalized | \n", "right_whisker_normalized | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "0.000 | \n", "3.513870 | \n", "271.151556 | \n", "0.048674 | \n", "0.086702 | \n", "13.644373 | \n", "243.731827 | \n", "0.056916 | \n", "0.097801 | \n", "0.026068 | \n", "0.093315 | \n", "
1 | \n", "0.005 | \n", "4.533231 | \n", "272.785300 | \n", "0.048674 | \n", "0.086702 | \n", "14.096692 | \n", "247.667480 | \n", "0.056916 | \n", "0.097801 | \n", "0.033631 | \n", "0.096408 | \n", "
2 | \n", "0.010 | \n", "5.875672 | \n", "273.417605 | \n", "0.048674 | \n", "0.086702 | \n", "15.003054 | \n", "248.133120 | \n", "0.056916 | \n", "0.097801 | \n", "0.043590 | \n", "0.102607 | \n", "
3 | \n", "0.015 | \n", "6.574637 | \n", "271.189545 | \n", "0.048674 | \n", "0.086702 | \n", "15.494432 | \n", "246.543158 | \n", "0.056916 | \n", "0.097801 | \n", "0.048775 | \n", "0.105968 | \n", "
4 | \n", "0.020 | \n", "6.493624 | \n", "271.002909 | \n", "0.048674 | \n", "0.086702 | \n", "15.364230 | \n", "246.802274 | \n", "0.056916 | \n", "0.097801 | \n", "0.048174 | \n", "0.105077 | \n", "