asobolev 11 месяцев назад
Родитель
Сommit
6b7f8c6863

Разница между файлами не показана из-за своего большого размера
+ 769 - 0
analysis/AEPs/AEP_MoSeq_Neuro.ipynb


Разница между файлами не показана из-за своего большого размера
+ 183 - 102
analysis/AEPs/preprocessing.ipynb


Разница между файлами не показана из-за своего большого размера
+ 54 - 82
analysis/AEPs/visualizing.ipynb


+ 91 - 26
analysis/CCR.ipynb

@@ -2,7 +2,7 @@
  "cells": [
   {
    "cell_type": "code",
-   "execution_count": 1,
+   "execution_count": 4,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -16,7 +16,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 2,
+   "execution_count": 5,
    "metadata": {},
    "outputs": [
     {
@@ -43,7 +43,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 3,
+   "execution_count": 10,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -54,23 +54,25 @@
     "#session, = '008229_hippoSIT_2022-05-16_20-36-44', None\n",
     "#session, = '008229_hippoSIT_2022-05-20_15-54-39', None\n",
     "#session, = '008229_hippoSIT_2022-05-18_14-36-18', None\n",
-    "session, pellet_unit = '009265_hippoSIT_2023-03-05_11-52-17', '4-2'\n",
-    "session, pellet_unit = '009266_hippoSIT_2023-04-24_16-56-55', '1-2'\n",
+    "#session, pellet_unit = '009265_hippoSIT_2023-03-05_11-52-17', '4-2'\n",
+    "#session, pellet_unit = '009266_hippoSIT_2023-04-24_16-56-55', '1-2'\n",
+    "session, pellet_unit = '009266_hippoSIT_2023-04-17_09-06-10', None\n",
     "\n",
-    "animal  = session.split('_')[0]\n",
+    "animal      = session.split('_')[0]\n",
     "sessionpath = os.path.join(source, animal, session)\n",
-    "h5name  = os.path.join(source, animal, session, session + '.h5')"
+    "h5_file     = os.path.join(source, animal, session, session + '.h5')\n",
+    "aeps_file   = os.path.join(source, animal, session, 'aeps.h5')"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 4,
+   "execution_count": 11,
    "metadata": {},
    "outputs": [],
    "source": [
     "s_rate = 100 # Hz\n",
     "\n",
-    "with h5py.File(h5name, 'r') as f:\n",
+    "with h5py.File(h5_file, 'r') as f:\n",
     "    tl = np.array(f['processed']['timeline'])  # time, X, Y, speed, etc.\n",
     "    trials = np.array(f['processed']['trial_idxs'])  # t_start_idx, t_end_idx, x_tgt, y_tgt, r_tgt, result"
    ]
@@ -84,7 +86,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 5,
+   "execution_count": 12,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -140,7 +142,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 6,
+   "execution_count": 15,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -160,31 +162,28 @@
     "    \n",
     "    for idx in idxs_pel_start:\n",
     "        pellet_ev[idx:idx + 1*s_rate] = 1  # pellet chewing will be 1 second\n",
-    "    pellet_onset[idxs_pel_start] = 1"
+    "    pellet_onset[idxs_pel_start] = 1\n",
+    "    \n",
+    "    print('Detected %s pellet events for %s successful trials' % (idxs_pel_start.shape[0], idxs_reward.shape[0]))"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 7,
+   "execution_count": null,
    "metadata": {},
-   "outputs": [
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "Detected 69 pellet events for 21 successful trials\n"
-     ]
-    }
-   ],
+   "outputs": [],
    "source": [
-    "print('Detected %s pellet events for %s successful trials' % (idxs_pel_start.shape[0], idxs_reward.shape[0]))"
+    "# AEP events\n",
+    "with h5py.File(aeps_file, 'r') as f:\n",
+    "    aeps = np.array(f['aeps'])\n",
+    "    aeps_events = np.array(f['aeps_events'])"
    ]
   },
   {
    "cell_type": "markdown",
    "metadata": {},
    "source": [
-    "## Read neuronal data"
+    "## Read assembly data"
    ]
   },
   {
@@ -236,6 +235,13 @@
     "assembly_weights"
    ]
   },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "## Read units"
+   ]
+  },
   {
    "cell_type": "code",
    "execution_count": 24,
@@ -299,14 +305,15 @@
     "#to_plot = {key: assembly_activity[key] for key in (1, 3, 4, 6, 5)}\n",
     "to_plot = single_units\n",
     "\n",
-    "titles = ['Background', 'Noise', 'Target', 'Reward', 'Pellet']"
+    "#titles = ['Background', 'Noise', 'Target', 'Reward', 'Pellet']\n",
+    "titles = ['Background', 'Noise', 'Target', 'Reward']"
    ]
   },
   {
    "cell_type": "code",
    "execution_count": 27,
    "metadata": {
-    "scrolled": true
+    "scrolled": false
    },
    "outputs": [
     {
@@ -368,6 +375,64 @@
     "fig.tight_layout()"
    ]
   },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "## Cross-AEPs"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "fig = plt.figure(figsize=(14, 3*len(to_plot)))\n",
+    "\n",
+    "t_lag  = 30  # seconds\n",
+    "j = 0\n",
+    "\n",
+    "for ass_id, i_rate in to_plot.items():\n",
+    "    for i, var_all in enumerate([\n",
+    "            (sound_bg, backgr_onset), \n",
+    "            (sound_ns, noise_onset), \n",
+    "            (sound_tg, target_onset), \n",
+    "            (reward_tl, reward_onset),\n",
+    "            (pellet_ev, pellet_ev)\n",
+    "        ]):\n",
+    "        ax = fig.add_subplot(len(to_plot), 5, i+1 + 5*j)\n",
+    "\n",
+    "        for k, var_tl in enumerate(var_all[1:2]):\n",
+    "            corr = signal.correlate(i_rate, var_tl)\n",
+    "            lags = signal.correlation_lags(len(var_tl), len(i_rate))\n",
+    "\n",
+    "            idx_l, idx_r = int(len(lags)/2) - t_lag*s_rate, int(len(lags)/2) + t_lag*s_rate\n",
+    "            y_min = 0.8*corr[idx_l:idx_r].min()\n",
+    "            y_max = 1.2*corr[idx_l:idx_r].max()\n",
+    "\n",
+    "            ax.plot(lags[idx_l:idx_r]/100, corr[idx_l:idx_r], color='blue' if k==0 else 'orange')\n",
+    "\n",
+    "        if i == 0:\n",
+    "            ax.set_ylabel(ass_id, fontsize=14)\n",
+    "        if i == 2:\n",
+    "            ax.axvline(5, color='green', ls='--')\n",
+    "        if i == 3:\n",
+    "            ax.axvline(-5, color='green', ls='--')\n",
+    "\n",
+    "        ax.axvline(0, color='black')\n",
+    "        ax.set_xlim(-t_lag, t_lag)\n",
+    "        ax.set_ylim(y_min, y_max)\n",
+    "        if j == 0:\n",
+    "            ax.set_title(titles[i], fontsize=14)\n",
+    "        if j == len(to_plot) - 1:\n",
+    "            ax.set_xlabel('Time, sec', fontsize=14)\n",
+    "        ax.grid()\n",
+    "    j += 1\n",
+    "    \n",
+    "fig.tight_layout()"
+   ]
+  },
   {
    "cell_type": "markdown",
    "metadata": {},

Разница между файлами не показана из-за своего большого размера
+ 68 - 43
postprocessing/MoSeq.ipynb


+ 370 - 10
postprocessing/execute.ipynb

@@ -2,7 +2,7 @@
  "cells": [
   {
    "cell_type": "code",
-   "execution_count": 6,
+   "execution_count": 17,
    "id": "c37dce82",
    "metadata": {
     "scrolled": true
@@ -39,7 +39,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 7,
+   "execution_count": 18,
    "id": "a8ea2991",
    "metadata": {},
    "outputs": [
@@ -75,7 +75,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 8,
+   "execution_count": 27,
    "id": "3891b792",
    "metadata": {},
    "outputs": [],
@@ -100,7 +100,12 @@
     "#sessions = [filebase]\n",
     "#sessions = processed_008229\n",
     "sessions = [\n",
-    "    '009266_hippoSIT_2023-04-24_16-56-55',\n",
+    "'009266_hippoSIT_2023-04-13_08-57-46',\n",
+    "'009266_hippoSIT_2023-04-14_09-17-34',\n",
+    "'009266_hippoSIT_2023-04-17_09-06-10',\n",
+    "'009266_hippoSIT_2023-04-17_17-04-17',\n",
+    "'009266_hippoSIT_2023-04-19_10-33-51',\n",
+    "'009266_hippoSIT_2023-04-20_08-57-39',\n",
     "]\n",
     "\n",
     "# FIXME move occupancy outside units\n",
@@ -117,7 +122,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 4,
+   "execution_count": 21,
    "id": "347fcf3d",
    "metadata": {},
    "outputs": [
@@ -129,7 +134,7 @@
        " '009266_hippoSIT_2023-03-06_15-10-36']"
       ]
      },
-     "execution_count": 4,
+     "execution_count": 21,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -140,7 +145,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 9,
+   "execution_count": 28,
    "id": "24cd2f6e",
    "metadata": {},
    "outputs": [
@@ -148,7 +153,12 @@
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "session 009266_hippoSIT_2023-04-24_16-56-55 done\n"
+      "session 009266_hippoSIT_2023-04-13_08-57-46 done\n",
+      "session 009266_hippoSIT_2023-04-14_09-17-34 done\n",
+      "session 009266_hippoSIT_2023-04-17_09-06-10 done\n",
+      "session 009266_hippoSIT_2023-04-17_17-04-17 done\n",
+      "session 009266_hippoSIT_2023-04-19_10-33-51 done\n",
+      "session 009266_hippoSIT_2023-04-20_08-57-39 done\n"
      ]
     }
    ],
@@ -234,7 +244,9 @@
    "cell_type": "code",
    "execution_count": 8,
    "id": "b4be27ef",
-   "metadata": {},
+   "metadata": {
+    "scrolled": true
+   },
    "outputs": [
     {
      "data": {
@@ -552,12 +564,360 @@
     "df.head()"
    ]
   },
+  {
+   "cell_type": "markdown",
+   "id": "7f0d30bb",
+   "metadata": {},
+   "source": [
+    "## Read unit names from H5"
+   ]
+  },
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 34,
+   "id": "bb04623f",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "0 009266_hippoSIT_2023-02-28_19-53-56\n",
+      "1 009266_hippoSIT_2023-03-01_17-53-11\n",
+      "2 009266_hippoSIT_2023-03-06_15-10-36\n",
+      "3 009266_hippoSIT_2023-03-06_20-43-19\n",
+      "4 009266_hippoSIT_2023-03-08_17-06-45\n",
+      "5 009266_hippoSIT_2023-03-09_09-37-07\n",
+      "6 009266_hippoSIT_2023-03-09_19-12-22\n",
+      "7 009266_hippoSIT_2023-04-12_15-49-49\n",
+      "8 009266_hippoSIT_2023-04-13_08-57-46\n",
+      "9 009266_hippoSIT_2023-04-14_09-17-34\n",
+      "10 009266_hippoSIT_2023-04-17_09-06-10\n",
+      "11 009266_hippoSIT_2023-04-17_17-04-17\n",
+      "12 009266_hippoSIT_2023-04-18_10-10-37\n",
+      "13 009266_hippoSIT_2023-04-18_17-03-10\n",
+      "14 009266_hippoSIT_2023-04-19_10-33-51\n",
+      "15 009266_hippoSIT_2023-04-19_11-21-37\n",
+      "16 009266_hippoSIT_2023-04-19_17-12-48\n",
+      "17 009266_hippoSIT_2023-04-20_08-57-39\n",
+      "18 009266_hippoSIT_2023-04-20_15-24-14\n",
+      "19 009266_hippoSIT_2023-04-21_08-43-00\n",
+      "20 009266_hippoSIT_2023-04-21_13-12-31\n",
+      "21 009266_hippoSIT_2023-04-24_10-08-11\n",
+      "22 009266_hippoSIT_2023-04-24_16-56-55\n",
+      "23 009266_hippoSIT_2023-04-25_09-02-56\n",
+      "24 009266_hippoSIT_2023-04-25_17-27-51\n",
+      "25 009266_hippoSIT_2023-04-26_08-20-17\n",
+      "26 009266_hippoSIT_2023-04-27_08-50-53\n",
+      "27 009266_hippoSIT_2023-04-27_21-04-41\n",
+      "28 009266_hippoSIT_2023-04-28_09-04-09\n",
+      "29 009266_hippoSIT_2023-04-28_16-40-08\n",
+      "30 009266_hippoSIT_2023-05-02_12-22-14\n",
+      "31 009266_hippoSIT_2023-05-02_17-20-39\n",
+      "32 009266_hippoSIT_2023-05-03_08-22-14\n",
+      "33 009266_hippoSIT_2023-05-04_09-11-06\n",
+      "34 009266_hippoSIT_2023-05-04_19-47-15\n",
+      "35 009266_hippoSIT_2023-05-05_08-32-22\n",
+      "36 009266_hippoSIT_2023-05-05_15-06-54\n",
+      "37 009266_hippoSIT_2023-05-18_16-22-42\n",
+      "38 009266_hippoSIT_2023-05-19_10-22-53\n",
+      "39 009266_hippoSIT_2023-05-21_10-56-38\n",
+      "40 009266_hippoSIT_2023-05-22_09-27-22\n",
+      "41 009266_hippoSIT_2023-05-22_21-54-39\n",
+      "42 009266_hippoSIT_2023-05-23_09-18-05\n",
+      "43 009266_hippoSIT_2023-05-23_17-48-12\n",
+      "44 009266_hippoSIT_2023-05-25_09-56-32\n",
+      "45 009266_hippoSIT_2023-05-25_15-55-57\n",
+      "46 009266_hippoSIT_2023-06-13_08-49-11\n",
+      "47 009266_hippoSIT_2023-06-14_08-21-23\n",
+      "48 009266_hippoSIT_2023-06-15_09-25-15\n",
+      "49 009266_hippoSIT_2023-06-15_17-30-45\n",
+      "50 009266_hippoSIT_2023-06-16_08-49-13\n",
+      "51 009266_hippoSIT_2023-06-19_08-58-35\n",
+      "52 009266_hippoSIT_2023-06-20_08-26-29\n",
+      "53 009266_hippoSIT_2023-06-21_08-15-10\n",
+      "54 009266_hippoSIT_2023-06-21_20-39-34\n"
+     ]
+    }
+   ],
+   "source": [
+    "source = '/home/sobolev/nevermind/Andrey/data'\n",
+    "animal = '009266'\n",
+    "\n",
+    "sessions = get_sessions_list(os.path.join(source, animal), animal)\n",
+    "for i, session in enumerate(sessions):\n",
+    "    print(i, session)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 44,
    "id": "46e18f9a",
    "metadata": {},
    "outputs": [],
+   "source": [
+    "session = sessions[8]\n",
+    "session = '009266_hippoSIT_2023-05-04_19-47-15'\n",
+    "sessionpath = os.path.join(source, animal, session)\n",
+    "h5_file = os.path.join(sessionpath, '%s.h5' % session)\n",
+    "\n",
+    "with h5py.File(h5_file, 'r') as f:\n",
+    "    if 'units' in f:\n",
+    "        units = [unit_name for unit_name in f['units']]\n",
+    "    else:\n",
+    "        units = []"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 45,
+   "id": "e10c7239",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "['1-10',\n",
+       " '1-11',\n",
+       " '1-12',\n",
+       " '1-13',\n",
+       " '1-14',\n",
+       " '1-15',\n",
+       " '1-16',\n",
+       " '1-17',\n",
+       " '1-18',\n",
+       " '1-19',\n",
+       " '1-2',\n",
+       " '1-20',\n",
+       " '1-21',\n",
+       " '1-22',\n",
+       " '1-23',\n",
+       " '1-24',\n",
+       " '1-25',\n",
+       " '1-26',\n",
+       " '1-27',\n",
+       " '1-28',\n",
+       " '1-29',\n",
+       " '1-3',\n",
+       " '1-30',\n",
+       " '1-31',\n",
+       " '1-32',\n",
+       " '1-33',\n",
+       " '1-34',\n",
+       " '1-35',\n",
+       " '1-36',\n",
+       " '1-37',\n",
+       " '1-38',\n",
+       " '1-39',\n",
+       " '1-4',\n",
+       " '1-40',\n",
+       " '1-41',\n",
+       " '1-42',\n",
+       " '1-43',\n",
+       " '1-44',\n",
+       " '1-45',\n",
+       " '1-46',\n",
+       " '1-47',\n",
+       " '1-48',\n",
+       " '1-49',\n",
+       " '1-5',\n",
+       " '1-6',\n",
+       " '1-7',\n",
+       " '1-8',\n",
+       " '1-9',\n",
+       " '2-10',\n",
+       " '2-11',\n",
+       " '2-12',\n",
+       " '2-13',\n",
+       " '2-14',\n",
+       " '2-15',\n",
+       " '2-16',\n",
+       " '2-17',\n",
+       " '2-18',\n",
+       " '2-19',\n",
+       " '2-2',\n",
+       " '2-20',\n",
+       " '2-21',\n",
+       " '2-22',\n",
+       " '2-23',\n",
+       " '2-24',\n",
+       " '2-25',\n",
+       " '2-26',\n",
+       " '2-27',\n",
+       " '2-28',\n",
+       " '2-29',\n",
+       " '2-3',\n",
+       " '2-30',\n",
+       " '2-31',\n",
+       " '2-32',\n",
+       " '2-33',\n",
+       " '2-34',\n",
+       " '2-35',\n",
+       " '2-36',\n",
+       " '2-37',\n",
+       " '2-38',\n",
+       " '2-39',\n",
+       " '2-4',\n",
+       " '2-40',\n",
+       " '2-41',\n",
+       " '2-42',\n",
+       " '2-43',\n",
+       " '2-44',\n",
+       " '2-45',\n",
+       " '2-46',\n",
+       " '2-47',\n",
+       " '2-48',\n",
+       " '2-49',\n",
+       " '2-5',\n",
+       " '2-50',\n",
+       " '2-51',\n",
+       " '2-52',\n",
+       " '2-53',\n",
+       " '2-54',\n",
+       " '2-55',\n",
+       " '2-56',\n",
+       " '2-57',\n",
+       " '2-58',\n",
+       " '2-59',\n",
+       " '2-6',\n",
+       " '2-60',\n",
+       " '2-61',\n",
+       " '2-62',\n",
+       " '2-63',\n",
+       " '2-64',\n",
+       " '2-65',\n",
+       " '2-66',\n",
+       " '2-67',\n",
+       " '2-68',\n",
+       " '2-7',\n",
+       " '2-8',\n",
+       " '2-9',\n",
+       " '3-10',\n",
+       " '3-11',\n",
+       " '3-12',\n",
+       " '3-13',\n",
+       " '3-14',\n",
+       " '3-15',\n",
+       " '3-16',\n",
+       " '3-17',\n",
+       " '3-18',\n",
+       " '3-19',\n",
+       " '3-2',\n",
+       " '3-20',\n",
+       " '3-21',\n",
+       " '3-22',\n",
+       " '3-23',\n",
+       " '3-24',\n",
+       " '3-25',\n",
+       " '3-26',\n",
+       " '3-27',\n",
+       " '3-28',\n",
+       " '3-29',\n",
+       " '3-3',\n",
+       " '3-30',\n",
+       " '3-31',\n",
+       " '3-32',\n",
+       " '3-33',\n",
+       " '3-34',\n",
+       " '3-35',\n",
+       " '3-4',\n",
+       " '3-5',\n",
+       " '3-6',\n",
+       " '3-7',\n",
+       " '3-8',\n",
+       " '3-9',\n",
+       " '4-10',\n",
+       " '4-11',\n",
+       " '4-12',\n",
+       " '4-13',\n",
+       " '4-14',\n",
+       " '4-15',\n",
+       " '4-16',\n",
+       " '4-17',\n",
+       " '4-18',\n",
+       " '4-19',\n",
+       " '4-2',\n",
+       " '4-20',\n",
+       " '4-21',\n",
+       " '4-22',\n",
+       " '4-23',\n",
+       " '4-3',\n",
+       " '4-4',\n",
+       " '4-5',\n",
+       " '4-6',\n",
+       " '4-7',\n",
+       " '4-8',\n",
+       " '4-9',\n",
+       " '5-10',\n",
+       " '5-11',\n",
+       " '5-12',\n",
+       " '5-13',\n",
+       " '5-14',\n",
+       " '5-15',\n",
+       " '5-16',\n",
+       " '5-17',\n",
+       " '5-18',\n",
+       " '5-19',\n",
+       " '5-2',\n",
+       " '5-20',\n",
+       " '5-21',\n",
+       " '5-22',\n",
+       " '5-23',\n",
+       " '5-24',\n",
+       " '5-25',\n",
+       " '5-26',\n",
+       " '5-27',\n",
+       " '5-28',\n",
+       " '5-29',\n",
+       " '5-3',\n",
+       " '5-30',\n",
+       " '5-4',\n",
+       " '5-5',\n",
+       " '5-6',\n",
+       " '5-7',\n",
+       " '5-8',\n",
+       " '5-9',\n",
+       " '6-10',\n",
+       " '6-11',\n",
+       " '6-12',\n",
+       " '6-13',\n",
+       " '6-14',\n",
+       " '6-15',\n",
+       " '6-16',\n",
+       " '6-17',\n",
+       " '6-18',\n",
+       " '6-19',\n",
+       " '6-2',\n",
+       " '6-20',\n",
+       " '6-21',\n",
+       " '6-22',\n",
+       " '6-23',\n",
+       " '6-24',\n",
+       " '6-25',\n",
+       " '6-3',\n",
+       " '6-4',\n",
+       " '6-5',\n",
+       " '6-6',\n",
+       " '6-7',\n",
+       " '6-8',\n",
+       " '6-9']"
+      ]
+     },
+     "execution_count": 45,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "units"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "6f5d5ba7",
+   "metadata": {},
+   "outputs": [],
    "source": []
   }
  ],

Разница между файлами не показана из-за своего большого размера
+ 36316 - 37045
sorting/ss-neurosuite.ipynb