{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "14:34:31 [I] klustakwik KlustaKwik2 version 0.2.6\n" ] } ], "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.analysis.data_processing as dp\n", "from septum_mec.analysis.registration import store_notebook\n", "import head_direction.head as head\n", "import spatial_maps as sp\n", "import pnnmec.registration\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 pnnmec\n", "import scipy.ndimage.measurements\n", "import quantities as pq\n", "import exdir\n", "from tqdm import tqdm_notebook as tqdm\n", "from septum_mec.analysis.trackunitmulticomparison import TrackMultipleSessions\n", "import networkx as nx\n", "from nxpd import draw\n", "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": 307, "metadata": {}, "outputs": [], "source": [ "project_path = dp.project_path()\n", "\n", "project = expipe.get_project(project_path)\n", "actions = project.actions" ] }, { "cell_type": "code", "execution_count": 308, "metadata": {}, "outputs": [], "source": [ "identify_neurons = project.require_action('identify-neurons')" ] }, { "cell_type": "code", "execution_count": 309, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'users': ['Charlotte'],\n", " 'tags': ['11hz', 'open-ephys', 'septum'],\n", " 'datetime': '2019-07-01T12:54:49',\n", " 'type': 'Recording',\n", " 'registered': '2019-07-02T14:53:28',\n", " 'data': {'main': 'main.exdir'},\n", " 'location': 'IMB',\n", " 'entities': ['1833']}" ] }, "execution_count": 309, "metadata": {}, "output_type": "execute_result" } ], "source": [ "actions['1833-010719-2'].attributes" ] }, { "cell_type": "code", "execution_count": 310, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'users': ['Charlotte'],\n", " 'tags': ['baseline I', 'open-ephys', 'septum'],\n", " 'datetime': '2019-07-01T12:25:01',\n", " 'type': 'Recording',\n", " 'registered': '2019-07-02T14:53:03',\n", " 'data': {'main': 'main.exdir'},\n", " 'location': 'IMB',\n", " 'entities': ['1833']}" ] }, "execution_count": 310, "metadata": {}, "output_type": "execute_result" } ], "source": [ "actions['1833-010719-1'].attributes" ] }, { "cell_type": "code", "execution_count": 311, "metadata": {}, "outputs": [], "source": [ "data_loader = dp.Data()" ] }, { "cell_type": "code", "execution_count": 313, "metadata": {}, "outputs": [], "source": [ "sessions = []\n", "for action in actions.values():\n", " if action.type != 'Recording':\n", " continue\n", " action_data_path = pathlib.Path(action.data_path('main'))\n", " processing = exdir.File(action_data_path)['processing']\n", " if not 'electrophysiology' in processing:\n", " continue\n", " elphys = processing['electrophysiology']\n", " if 'spikesorting' not in elphys:\n", " continue\n", " tags = [t.lower() for t in action.tags]\n", " \n", " freq = np.nan\n", " stimulated = False\n", " control = False\n", " \n", " stim_times = data_loader.stim_times(action.id)\n", " if stim_times is not None:\n", " stimulated = True\n", " freq = round(1 / np.mean(np.diff(stim_times)))\n", " \n", " \n", " tag = \"\"\n", " stim_location = \"\"\n", " tag_i = [i for i, t in enumerate(tags) if 'baseline' in t or 'stim' in t]\n", " if len(tag_i) == 1:\n", " tag = tags[tag_i[0]]\n", " if 'stim' in tag:\n", " stim_location = tag.split('-')[-1]\n", " elif 'baseline' in tag:\n", " control = True\n", " \n", " \n", "\n", " sessions.append({\n", " 'tag': tag,\n", " 'action': action.id,\n", " 'stimulated': stimulated,\n", " 'control': control,\n", " 'frequency': freq,\n", " 'session': int(action.id.split('-')[-1]),\n", " 'stim_location': stim_location,\n", " 'entity': int(action.entities[0]),\n", "\n", " })\n", "sessions = pd.DataFrame(sessions)" ] }, { "cell_type": "code", "execution_count": 316, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | action | \n", "control | \n", "entity | \n", "frequency | \n", "session | \n", "stim_location | \n", "stimulated | \n", "tag | \n", "
---|---|---|---|---|---|---|---|---|
1 | \n", "1839-120619-4 | \n", "False | \n", "1839 | \n", "30.0 Hz | \n", "4 | \n", "\n", " | True | \n", "\n", " |
3 | \n", "1839-060619-3 | \n", "False | \n", "1839 | \n", "11.0 Hz | \n", "3 | \n", "\n", " | True | \n", "\n", " |
5 | \n", "1834-120319-4 | \n", "False | \n", "1834 | \n", "30.0 Hz | \n", "4 | \n", "\n", " | True | \n", "\n", " |
6 | \n", "1849-280219-4 | \n", "False | \n", "1849 | \n", "30.0 Hz | \n", "4 | \n", "ms | \n", "True | \n", "stim-ms | \n", "
7 | \n", "1849-110319-2 | \n", "False | \n", "1849 | \n", "11.0 Hz | \n", "2 | \n", "\n", " | True | \n", "\n", " |
9 | \n", "1834-220319-2 | \n", "False | \n", "1834 | \n", "11.0 Hz | \n", "2 | \n", "\n", " | True | \n", "\n", " |
11 | \n", "1833-020719-4 | \n", "False | \n", "1833 | \n", "30.0 Hz | \n", "4 | \n", "\n", " | True | \n", "\n", " |
12 | \n", "1834-120319-2 | \n", "False | \n", "1834 | \n", "11.0 Hz | \n", "2 | \n", "\n", " | True | \n", "\n", " |
15 | \n", "1834-150319-4 | \n", "False | \n", "1834 | \n", "30.0 Hz | \n", "4 | \n", "\n", " | True | \n", "\n", " |
16 | \n", "1834-220319-4 | \n", "False | \n", "1834 | \n", "30.0 Hz | \n", "4 | \n", "\n", " | True | \n", "\n", " |
19 | \n", "1833-260619-2 | \n", "False | \n", "1833 | \n", "11.0 Hz | \n", "2 | \n", "\n", " | True | \n", "\n", " |
20 | \n", "1849-010319-4 | \n", "False | \n", "1849 | \n", "11.0 Hz | \n", "4 | \n", "mecr | \n", "True | \n", "stim-mecr | \n", "
22 | \n", "1833-200619-4 | \n", "False | \n", "1833 | \n", "30.0 Hz | \n", "4 | \n", "\n", " | True | \n", "\n", " |
23 | \n", "1849-220319-3 | \n", "False | \n", "1849 | \n", "11.0 Hz | \n", "3 | \n", "\n", " | True | \n", "\n", " |
28 | \n", "1834-150319-2 | \n", "False | \n", "1834 | \n", "11.0 Hz | \n", "2 | \n", "\n", " | True | \n", "\n", " |
30 | \n", "1839-290519-2 | \n", "False | \n", "1839 | \n", "11.0 Hz | \n", "2 | \n", "\n", " | True | \n", "\n", " |
32 | \n", "1834-010319-5 | \n", "False | \n", "1834 | \n", "30.0 Hz | \n", "5 | \n", "ms | \n", "True | \n", "stim-ms | \n", "
37 | \n", "1849-150319-2 | \n", "False | \n", "1849 | \n", "11.0 Hz | \n", "2 | \n", "\n", " | True | \n", "\n", " |
38 | \n", "1849-280219-2 | \n", "False | \n", "1849 | \n", "11.0 Hz | \n", "2 | \n", "ms | \n", "True | \n", "stim-ms | \n", "
43 | \n", "1849-060319-4 | \n", "False | \n", "1849 | \n", "30.0 Hz | \n", "4 | \n", "ms | \n", "True | \n", "stim-ms | \n", "
44 | \n", "1834-010319-3 | \n", "False | \n", "1834 | \n", "11.0 Hz | \n", "3 | \n", "ms | \n", "True | \n", "stim-ms | \n", "
45 | \n", "1833-050619-2 | \n", "False | \n", "1833 | \n", "11.0 Hz | \n", "2 | \n", "\n", " | True | \n", "\n", " |
47 | \n", "1833-120619-2 | \n", "False | \n", "1833 | \n", "11.0 Hz | \n", "2 | \n", "\n", " | True | \n", "\n", " |
50 | \n", "1849-010319-5 | \n", "False | \n", "1849 | \n", "11.0 Hz | \n", "5 | \n", "mecl | \n", "True | \n", "stim-mecl | \n", "
51 | \n", "1849-150319-4 | \n", "False | \n", "1849 | \n", "30.0 Hz | \n", "4 | \n", "\n", " | True | \n", "\n", " |
52 | \n", "1834-060319-4 | \n", "False | \n", "1834 | \n", "30.0 Hz | \n", "4 | \n", "ms | \n", "True | \n", "stim-ms | \n", "
53 | \n", "1834-060319-2 | \n", "False | \n", "1834 | \n", "11.0 Hz | \n", "2 | \n", "ms | \n", "True | \n", "stim-ms | \n", "
56 | \n", "1849-060319-2 | \n", "False | \n", "1849 | \n", "11.0 Hz | \n", "2 | \n", "ms | \n", "True | \n", "stim-ms | \n", "
60 | \n", "1834-110319-2 | \n", "False | \n", "1834 | \n", "11.0 Hz | \n", "2 | \n", "\n", " | True | \n", "\n", " |
61 | \n", "1833-020719-2 | \n", "False | \n", "1833 | \n", "11.0 Hz | \n", "2 | \n", "\n", " | True | \n", "\n", " |
63 | \n", "1833-050619-4 | \n", "False | \n", "1833 | \n", "30.0 Hz | \n", "4 | \n", "\n", " | True | \n", "\n", " |
64 | \n", "1833-260619-4 | \n", "False | \n", "1833 | \n", "30.0 Hz | \n", "4 | \n", "\n", " | True | \n", "\n", " |
65 | \n", "1833-200619-2 | \n", "False | \n", "1833 | \n", "11.0 Hz | \n", "2 | \n", "\n", " | True | \n", "\n", " |
67 | \n", "1833-120619-4 | \n", "False | \n", "1833 | \n", "30.0 Hz | \n", "4 | \n", "\n", " | True | \n", "\n", " |
68 | \n", "1833-290519-4 | \n", "False | \n", "1833 | \n", "30.0 Hz | \n", "4 | \n", "\n", " | True | \n", "\n", " |
70 | \n", "1839-060619-5 | \n", "False | \n", "1839 | \n", "30.0 Hz | \n", "5 | \n", "\n", " | True | \n", "\n", " |
74 | \n", "1833-290519-2 | \n", "False | \n", "1833 | \n", "11.0 Hz | \n", "2 | \n", "\n", " | True | \n", "\n", " |
75 | \n", "1833-060619-2 | \n", "False | \n", "1833 | \n", "30.0 Hz | \n", "2 | \n", "\n", " | True | \n", "\n", " |
76 | \n", "1839-120619-2 | \n", "False | \n", "1839 | \n", "11.0 Hz | \n", "2 | \n", "\n", " | True | \n", "\n", " |
77 | \n", "1849-220319-5 | \n", "False | \n", "1849 | \n", "30.0 Hz | \n", "5 | \n", "\n", " | True | \n", "\n", " |
81 | \n", "1834-110319-5 | \n", "False | \n", "1834 | \n", "11.0 Hz | \n", "5 | \n", "\n", " | True | \n", "\n", " |
82 | \n", "1839-200619-2 | \n", "False | \n", "1839 | \n", "11.0 Hz | \n", "2 | \n", "\n", " | True | \n", "\n", " |
86 | \n", "1833-010719-2 | \n", "False | \n", "1833 | \n", "11.0 Hz | \n", "2 | \n", "\n", " | True | \n", "\n", " |