{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [], "source": [ "import os\n", "import expipe\n", "import pathlib\n", "import numpy as np\n", "import septum_mec.analysis.data_processing as dp\n", "from septum_mec.analysis.registration import store_notebook\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 quantities as pq\n", "import exdir\n", "from distutils.dir_util import copy_tree\n", "from datetime import timedelta\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": 3, "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": 4, "metadata": {}, "outputs": [], "source": [ "output = pathlib.Path('output/identify_neurons')" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "identify_neurons = project.require_action('identify-neurons')" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'users': ['Mikkel Lepperød'],\n", " 'tags': ['11hz', 'stim-ms', 'stim i', 'septum', 'open-ephys'],\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": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "actions['1833-010719-2'].attributes" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "data_loader = dp.Data()" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "skip_actions = [\n", " '1849-270219-1', \n", " '1849-260219-2', \n", " '1834-250219-1',\n", " '1834-230219-1'\n", "]" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "sessions = []\n", "for action in actions.values():\n", " if action.id in skip_actions:\n", " continue\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", "\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", " baseline = False\n", " is_i = False\n", " is_ii = False\n", " tag = None\n", " stim_location = None\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.median(np.diff(stim_times)))\n", " \n", " \n", " \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", " what, how = tag.split(' ')\n", " if what == 'stim':\n", " where = [t for t in tags if 'stim-' in t]\n", " assert len(where) == 1\n", " stim_location = where[0].split('-')[-1]\n", " assert stimulated\n", " elif what == 'baseline':\n", " baseline = True\n", " assert not stimulated\n", " else:\n", " raise Exception(f'Found {tag}, what to do?')\n", " if how == 'i':\n", " is_i = True\n", " elif how == 'ii':\n", " is_ii = True\n", " else:\n", " raise Exception(f'Found {tag}, what to do?')\n", " elif len(tag_i) > 1:\n", " print(action.id, [tags[i] for i in tag_i])\n", " \n", " \n", "\n", " sessions.append({\n", " 'tag': tag,\n", " 'action': action.id,\n", " 'stimulated': stimulated,\n", " 'baseline': baseline,\n", " 'i': is_i,\n", " 'ii': is_ii,\n", " 'frequency': float(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": 10, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | action | \n", "baseline | \n", "entity | \n", "frequency | \n", "i | \n", "ii | \n", "session | \n", "stim_location | \n", "stimulated | \n", "tag | \n", "
---|---|---|---|---|---|---|---|---|---|---|
3 | \n", "1839-060619-3 | \n", "False | \n", "1839 | \n", "11.0 | \n", "True | \n", "False | \n", "3 | \n", "ms | \n", "True | \n", "stim i | \n", "
7 | \n", "1849-110319-2 | \n", "False | \n", "1849 | \n", "11.0 | \n", "True | \n", "False | \n", "2 | \n", "ms | \n", "True | \n", "stim i | \n", "
9 | \n", "1834-220319-2 | \n", "False | \n", "1834 | \n", "11.0 | \n", "True | \n", "False | \n", "2 | \n", "ms | \n", "True | \n", "stim i | \n", "
12 | \n", "1834-120319-2 | \n", "False | \n", "1834 | \n", "11.0 | \n", "True | \n", "False | \n", "2 | \n", "ms | \n", "True | \n", "stim i | \n", "
19 | \n", "1833-260619-2 | \n", "False | \n", "1833 | \n", "11.0 | \n", "True | \n", "False | \n", "2 | \n", "ms | \n", "True | \n", "stim i | \n", "
20 | \n", "1849-010319-4 | \n", "False | \n", "1849 | \n", "11.0 | \n", "True | \n", "False | \n", "4 | \n", "mecr | \n", "True | \n", "stim i | \n", "
23 | \n", "1849-220319-3 | \n", "False | \n", "1849 | \n", "11.0 | \n", "True | \n", "False | \n", "3 | \n", "ms | \n", "True | \n", "stim i | \n", "
28 | \n", "1834-150319-2 | \n", "False | \n", "1834 | \n", "11.0 | \n", "True | \n", "False | \n", "2 | \n", "ms | \n", "True | \n", "stim i | \n", "
30 | \n", "1839-290519-2 | \n", "False | \n", "1839 | \n", "11.0 | \n", "True | \n", "False | \n", "2 | \n", "ms | \n", "True | \n", "stim i | \n", "
37 | \n", "1849-150319-2 | \n", "False | \n", "1849 | \n", "11.0 | \n", "True | \n", "False | \n", "2 | \n", "ms | \n", "True | \n", "stim i | \n", "
38 | \n", "1849-280219-2 | \n", "False | \n", "1849 | \n", "11.0 | \n", "True | \n", "False | \n", "2 | \n", "ms | \n", "True | \n", "stim i | \n", "
44 | \n", "1834-010319-3 | \n", "False | \n", "1834 | \n", "11.0 | \n", "True | \n", "False | \n", "3 | \n", "ms | \n", "True | \n", "stim i | \n", "
45 | \n", "1833-050619-2 | \n", "False | \n", "1833 | \n", "11.0 | \n", "True | \n", "False | \n", "2 | \n", "ms | \n", "True | \n", "stim i | \n", "
47 | \n", "1833-120619-2 | \n", "False | \n", "1833 | \n", "11.0 | \n", "True | \n", "False | \n", "2 | \n", "ms | \n", "True | \n", "stim i | \n", "
50 | \n", "1849-010319-5 | \n", "False | \n", "1849 | \n", "11.0 | \n", "True | \n", "False | \n", "5 | \n", "mecl | \n", "True | \n", "stim i | \n", "
53 | \n", "1834-060319-2 | \n", "False | \n", "1834 | \n", "11.0 | \n", "True | \n", "False | \n", "2 | \n", "ms | \n", "True | \n", "stim i | \n", "
55 | \n", "1834-110319-6 | \n", "False | \n", "1834 | \n", "11.0 | \n", "True | \n", "False | \n", "6 | \n", "mecr | \n", "True | \n", "stim i | \n", "
57 | \n", "1849-060319-2 | \n", "False | \n", "1849 | \n", "11.0 | \n", "True | \n", "False | \n", "2 | \n", "ms | \n", "True | \n", "stim i | \n", "
61 | \n", "1834-110319-2 | \n", "False | \n", "1834 | \n", "11.0 | \n", "True | \n", "False | \n", "2 | \n", "ms | \n", "True | \n", "stim i | \n", "
62 | \n", "1833-020719-2 | \n", "False | \n", "1833 | \n", "11.0 | \n", "True | \n", "False | \n", "2 | \n", "ms | \n", "True | \n", "stim i | \n", "
66 | \n", "1833-200619-2 | \n", "False | \n", "1833 | \n", "11.0 | \n", "True | \n", "False | \n", "2 | \n", "ms | \n", "True | \n", "stim i | \n", "
75 | \n", "1833-290519-2 | \n", "False | \n", "1833 | \n", "11.0 | \n", "True | \n", "False | \n", "2 | \n", "ms | \n", "True | \n", "stim i | \n", "
77 | \n", "1839-120619-2 | \n", "False | \n", "1839 | \n", "11.0 | \n", "True | \n", "False | \n", "2 | \n", "ms | \n", "True | \n", "stim i | \n", "
82 | \n", "1834-110319-5 | \n", "False | \n", "1834 | \n", "11.0 | \n", "True | \n", "False | \n", "5 | \n", "mecl | \n", "True | \n", "stim i | \n", "
83 | \n", "1839-200619-2 | \n", "False | \n", "1839 | \n", "11.0 | \n", "True | \n", "False | \n", "2 | \n", "ms | \n", "True | \n", "stim i | \n", "
87 | \n", "1833-010719-2 | \n", "False | \n", "1833 | \n", "11.0 | \n", "True | \n", "False | \n", "2 | \n", "ms | \n", "True | \n", "stim i | \n", "