septum-mec/actions/stimulus-response/data/10-calculate-stimulus-respo...

354 lines
19 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The autoreload extension is already loaded. To reload it, use:\n",
" %reload_ext autoreload\n"
]
}
],
"source": [
"%load_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"%matplotlib inline\n",
"import spatial_maps as sp\n",
"import septum_mec.analysis.data_processing as dp\n",
"import septum_mec.analysis.registration\n",
"import expipe\n",
"import os\n",
"import pathlib\n",
"import numpy as np\n",
"import exdir\n",
"import pandas as pd\n",
"import optogenetics as og\n",
"import quantities as pq\n",
"import shutil\n",
"from distutils.dir_util import copy_tree\n",
"\n",
"from septum_mec.analysis.stimulus_response import stimulus_response_latency, compute_response\n",
"\n",
"from tqdm import tqdm_notebook as tqdm\n",
"from tqdm._tqdm_notebook import tqdm_notebook\n",
"tqdm_notebook.pandas()"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"std_gaussian_kde = 0.04\n",
"window_size = 0.03"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"data_loader = dp.Data()\n",
"actions = data_loader.actions\n",
"project = data_loader.project"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"output = pathlib.Path('output/stimulus-response')\n",
"(output / 'data').mkdir(parents=True, exist_ok=True)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"identify_neurons = actions['identify-neurons']\n",
"units = pd.read_csv(identify_neurons.data_path('units'))"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"def process(row):\n",
" \n",
" action_id = row['action']\n",
" channel_id = int(row['channel_group'])\n",
" unit_id = int(row['unit_name']) \n",
" \n",
" spike_times = data_loader.spike_train(action_id, channel_id, unit_id)\n",
" \n",
" spike_times = np.array(spike_times)\n",
" \n",
" stim_times = data_loader.stim_times(action_id)\n",
" \n",
" nan_series = pd.Series({\n",
" 't_e_peak': np.nan,\n",
" 'p_e_peak': np.nan,\n",
" 't_i_peak': np.nan,\n",
" 'p_i_peak': np.nan\n",
" })\n",
" \n",
" if stim_times is None:\n",
" return nan_series\n",
" \n",
" stim_times = np.array(stim_times)\n",
" \n",
" times, spikes, kernel, p_e, p_i = stimulus_response_latency(\n",
" spike_times, stim_times, window_size, std_gaussian_kde)\n",
" \n",
" # if no spikes detected after stimulus nan is returned\n",
" if all(np.isnan([p_e, p_i])):\n",
" return nan_series\n",
" \n",
" t_e_peak, p_e_peak, t_i_peak, p_i_peak = compute_response(\n",
" spike_times, stim_times, times, kernel, p_e, p_i)\n",
"\n",
" return pd.Series({\n",
" 't_e_peak': t_e_peak,\n",
" 'p_e_peak': p_e_peak,\n",
" 't_i_peak': t_i_peak,\n",
" 'p_i_peak': p_i_peak\n",
" })\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "476c31da67274b2396ed3f2ec54a8344",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, max=1298), HTML(value='')))"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/mikkel/apps/expipe-project/septum-mec/septum_mec/analysis/stimulus_response.py:33: RuntimeWarning: invalid value encountered in less\n",
" if any(times[idxs_i] < te_peak):\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n"
]
}
],
"source": [
"results = units.merge(\n",
" units.progress_apply(process, axis=1), \n",
" left_index=True, right_index=True)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
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LfrF6/VvLoxuuryBr8E0O6gRWkId0ASNoPeDtwLLAM+KikucD7gesiYjFwB+nL6aSmz0HSHpK+CCzvRMBT5PkZfAhYHRFLgY8AHy066BIoQ9lvVq9fK3l03fVVZILfbUg3UDmk+8XApoj4Y0Q8AtwDHF65D7AeOK64cKeV5xyGgc8DFxcc63TyxP8uYHJc9mxgrLhwS6MMZb9ZvX6t5NF111eRCX4v4JGK5zslza7y2jZg7ynbJ7d1UtPnEBG/i4gNRQVYR574t0bEdkkCVgEfKCbUUilD2W9Wr18reXTd9VVkgq81pHvqa/OAh6dsn9zWSXnOoZvkil/Sy4GvAme7/T2XMpT9ZvX6tZJH111fRSb4WkO6NwOLJQ1L2hsYAbZU7gOcBGwsLtxp5TmHbtJ0/Fnhuxw4MSJ+UHTAJVGGst+sXr9W8ui666uwkawVd5gPZ9eQ7pOBeyLia9kd5nNJv3Q+EhE3SNqX1CY3D9gKnBkRfygk4GnkOYeKfd8APLdLetE08zP4MTAX+E12mIiIXrvh11FlKPvN6vVrJY9uvL48VYGZWUl5oJOZWUk5wZuZlZQTvJlZSTnBm5mVlBO8mVlJOcGbmZWUE7yZWUn9f5OXUUE7oelrAAAAAElFTkSuQmCC\n",
"text/plain": [
"<Figure size 432x288 with 4 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"results.loc[:, ['t_e_peak', 't_i_peak', 'p_e_peak', 'p_i_peak']].hist()\n",
"plt.gcf().savefig(output / 'figures' / 'summary_histogram.png')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "2ee10927bbdf456c9178b9fd5448be23",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, max=1298), HTML(value='')))"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"psth, time = {}, {}\n",
"for i, row in tqdm(units.iterrows(), total=len(units)):\n",
" action_id = row['action']\n",
" channel_group = row['channel_group']\n",
" unit_name = row['unit_name']\n",
" name = f'{action_id}_{channel_group}_{unit_name}'\n",
" spike_times = data_loader.spike_train(action_id, channel_group, unit_name)\n",
" \n",
" spike_times = np.array(spike_times)\n",
" \n",
" stim_times = data_loader.stim_times(action_id)\n",
" \n",
" if stim_times is None:\n",
" continue\n",
" \n",
" stim_times = np.array(stim_times)\n",
" \n",
" times, spikes, kernel, p_e, p_i = stimulus_response_latency(\n",
" spike_times, stim_times, window_size, std_gaussian_kde)\n",
" \n",
" if all(np.isnan([p_e, p_i])):\n",
" continue\n",
" \n",
" psth.update({name: kernel(times)})\n",
" time.update({name: times})"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pd.DataFrame(psth).to_feather(output / 'data' / 'psth.feather')\n",
"pd.DataFrame(time).to_feather(output / 'data' / 'times.feather')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Save to expipe"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"action = project.require_action(\"stimulus-response\")"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"action.modules['parameters'] = {\n",
" 'window_size': window_size,\n",
" 'std_gaussian_kde': std_gaussian_kde\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"action.data['results'] = 'results.csv'\n",
"results.to_csv(action.data_path('results'), index=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"copy_tree(output, str(action.data_path()))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"septum_mec.analysis.registration.store_notebook(action, \"10-calculate-stimulus-response.ipynb\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}