{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Experiment: Flashed gratings" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Initialization" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Imports" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import pandas as pd\n", "import scipy\n", "import scipy.stats as sts\n", "import pickle as pkl\n", "import ipywidgets as widgets\n", "from mpl_toolkits import mplot3d\n", "from mpl_toolkits.mplot3d import Axes3D\n", "from scipy import sparse\n", "from matplotlib import cm\n", "\n", "# color maps\n", "cmap_hot = cm.get_cmap('hot')\n", "cmap_viridis = cm.get_cmap('viridis')\n", "cmap_jet = cm.get_cmap('jet')" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "\n", "data_folder = \"../data/\"\n", "stim_file = \"Stiminfo_PVCre_2021_0012_s06_e14.csv\"\n", "spike_times_file = \"Spiketimes_PVCre_2021_0012_s06_e14.npy\"\n", "\n", "key_symbol = {'pair':'$(\\\\theta,\\phi)$', 'orientation':'$\\\\theta$', 'phase':'$\\phi$'}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Load the stimulus data\n", "**Stimulus data layout:**\n", "```\n", "stim_val = {'pair': [(or1, ph1), (or2, ph2), ...], 'orientation': [...], 'phase': [...]}\n", "stim_id_trial = {'pair': [id1, id2, ...], 'phase': [..], ...} # corresponding trials\n", "pair_trial_id[orientation_id][phase_id] = [Trial ids]\n", "```" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# Stimulus DataFrame\n", "stim = pd.read_csv(data_folder + stim_file)\n", "num_trial = len(stim)\n", "stim_val = {}\n", "trial_stim_id = {}\n", "# 50 trials per orientation-phase pair\n", "stim_val['pair'], trial_stim_id['pair'] = np.unique(stim[['grat_orientation', 'grat_phase']], return_inverse=True, axis=0) \n", "# 1000 trials per orientation\n", "stim_val['orientation'], trial_stim_id['orientation'] = np.unique(stim['grat_orientation'], return_inverse=True) \n", "# 1000 trials per phase\n", "stim_val['phase'], trial_stim_id['phase'] = np.unique(stim['grat_phase'], return_inverse=True) \n", "key_list = ['pair', 'orientation', 'phase']\n", "stim_id_trial = {}\n", "num_stim = {}\n", "for key in key_list:\n", " stim_id_trial[key] = [np.where(trial_stim_id[key] == i)[0] for i in range(len(stim_val[key]))]\n", " num_stim[key] = len(stim_val[key])\n", "\n", "def pair_id(i):\n", " return (int(i//num_stim['orientation']), i%num_stim['orientation'])\n", "\n", "trial_pair_id = np.array([pair_id(i) for i in trial_stim_id['pair']], dtype=object)\n", "pair_val = stim_val['pair'].reshape(num_stim['orientation'], num_stim['phase'],2)\n", "\n", "# for each (orientation_id = i, phase_id = j) find the trial indices\n", "pair_trial_id = np.ndarray((num_stim['orientation'], num_stim['phase']), dtype=object)\n", "for i in range(num_stim['pair']):\n", " pair_trial_id[pair_id(i)] = stim_id_trial['pair'][i]" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | Unnamed: 0 | \n", "grat_orientation | \n", "grat_phase | \n", "stimvals | \n", "stim_ontime | \n", "stim_offtime | \n", "
---|---|---|---|---|---|---|
0 | \n", "0 | \n", "45.0 | \n", "36.0 | \n", "102 | \n", "2.5005 | \n", "2.5839 | \n", "
1 | \n", "1 | \n", "0.0 | \n", "18.0 | \n", "1 | \n", "2.6195 | \n", "2.7028 | \n", "
2 | \n", "2 | \n", "162.0 | \n", "288.0 | \n", "376 | \n", "2.7030 | \n", "2.7863 | \n", "
3 | \n", "3 | \n", "0.0 | \n", "54.0 | \n", "3 | \n", "2.7865 | \n", "2.8699 | \n", "
4 | \n", "4 | \n", "108.0 | \n", "36.0 | \n", "242 | \n", "2.8700 | \n", "2.9534 | \n", "