stim response
This commit is contained in:
parent
a15c1396c6
commit
7f044e9b5b
|
@ -1,7 +1,7 @@
|
||||||
registered: '2019-10-03T08:37:34'
|
registered: '2019-10-03T08:37:34'
|
||||||
data:
|
data:
|
||||||
figures: figures
|
figures: figures
|
||||||
statistics: statistics
|
statistics: statistics
|
||||||
notebook: 10-calculate-stimulus-response.ipynb
|
notebook: 10-calculate-stimulus-response.ipynb
|
||||||
html: 10-calculate-stimulus-response.html
|
html: 10-calculate-stimulus-response.html
|
||||||
results: results.csv
|
results: results.csv
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,280 +1,274 @@
|
||||||
{
|
{
|
||||||
"cells": [
|
"cells": [
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 1,
|
"execution_count": 1,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%load_ext autoreload\n",
|
"%load_ext autoreload\n",
|
||||||
"%autoreload 2"
|
"%autoreload 2"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 2,
|
"execution_count": 2,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stderr",
|
"name": "stderr",
|
||||||
"output_type": "stream",
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"08:31:41 [I] klustakwik KlustaKwik2 version 0.2.6\n"
|
"11:36:02 [I] klustakwik KlustaKwik2 version 0.2.6\n"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"import matplotlib.pyplot as plt\n",
|
"import matplotlib.pyplot as plt\n",
|
||||||
"%matplotlib inline\n",
|
"%matplotlib inline\n",
|
||||||
"import spatial_maps as sp\n",
|
"import spatial_maps as sp\n",
|
||||||
"import septum_mec.analysis.data_processing as dp\n",
|
"import septum_mec.analysis.data_processing as dp\n",
|
||||||
"import septum_mec.analysis.registration\n",
|
"import septum_mec.analysis.registration\n",
|
||||||
"import expipe\n",
|
"import expipe\n",
|
||||||
"import os\n",
|
"import os\n",
|
||||||
"import pathlib\n",
|
"import pathlib\n",
|
||||||
"import numpy as np\n",
|
"import numpy as np\n",
|
||||||
"import exdir\n",
|
"import exdir\n",
|
||||||
"import pandas as pd\n",
|
"import pandas as pd\n",
|
||||||
"import optogenetics as og\n",
|
"import optogenetics as og\n",
|
||||||
"import quantities as pq\n",
|
"import quantities as pq\n",
|
||||||
"import shutil\n",
|
"import shutil\n",
|
||||||
"from distutils.dir_util import copy_tree\n",
|
"from distutils.dir_util import copy_tree\n",
|
||||||
"\n",
|
"\n",
|
||||||
"from septum_mec.analysis.stimulus_response import stimulus_response_latency, compute_response\n",
|
"from septum_mec.analysis.stimulus_response import stimulus_response_latency, compute_response\n",
|
||||||
"\n",
|
"\n",
|
||||||
"from tqdm import tqdm_notebook as tqdm\n",
|
"from tqdm import tqdm_notebook as tqdm\n",
|
||||||
"from tqdm._tqdm_notebook import tqdm_notebook\n",
|
"from tqdm._tqdm_notebook import tqdm_notebook\n",
|
||||||
"tqdm_notebook.pandas()"
|
"tqdm_notebook.pandas()"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": 3,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"std_gaussian_kde = 0.04\n",
|
"std_gaussian_kde = 0.04\n",
|
||||||
"window_size = 0.03"
|
"window_size = 0.03"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 4,
|
"execution_count": 4,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"data_loader = dp.Data()\n",
|
"data_loader = dp.Data()\n",
|
||||||
"actions = data_loader.actions\n",
|
"actions = data_loader.actions\n",
|
||||||
"project = data_loader.project"
|
"project = data_loader.project"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 5,
|
"execution_count": 5,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"output = pathlib.Path('output/stimulus-response')\n",
|
"output = pathlib.Path('output/stimulus-response')\n",
|
||||||
"(output / 'figures').mkdir(parents=True, exist_ok=True)"
|
"(output / 'figures').mkdir(parents=True, exist_ok=True)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 6,
|
"execution_count": 6,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"identify_neurons = actions['identify-neurons']\n",
|
"identify_neurons = actions['identify-neurons']\n",
|
||||||
"units = pd.read_csv(identify_neurons.data_path('units'))"
|
"units = pd.read_csv(identify_neurons.data_path('units'))"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 7,
|
"execution_count": 7,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"scrolled": false
|
"scrolled": false
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"def process(row):\n",
|
"def process(row):\n",
|
||||||
" \n",
|
" \n",
|
||||||
" action_id = row['action']\n",
|
" action_id = row['action']\n",
|
||||||
" channel_id = int(row['channel_group'])\n",
|
" channel_id = int(row['channel_group'])\n",
|
||||||
" unit_id = int(row['unit_name']) \n",
|
" unit_id = int(row['unit_name']) \n",
|
||||||
" \n",
|
" \n",
|
||||||
" spike_times = data_loader.spike_train(action_id, channel_id, unit_id)\n",
|
" spike_times = data_loader.spike_train(action_id, channel_id, unit_id)\n",
|
||||||
" \n",
|
" \n",
|
||||||
" spike_times = np.array(spike_times)\n",
|
" spike_times = np.array(spike_times)\n",
|
||||||
" \n",
|
" \n",
|
||||||
" stim_times = data_loader.stim_times(action_id)\n",
|
" stim_times = data_loader.stim_times(action_id)\n",
|
||||||
" \n",
|
" \n",
|
||||||
" nan_series = pd.Series({\n",
|
" nan_series = pd.Series({\n",
|
||||||
" 't_e_peak': np.nan,\n",
|
" 't_e_peak': np.nan,\n",
|
||||||
" 'p_e_peak': np.nan,\n",
|
" 'p_e_peak': np.nan,\n",
|
||||||
" 't_i_peak': np.nan,\n",
|
" 't_i_peak': np.nan,\n",
|
||||||
" 'p_i_peak': np.nan\n",
|
" 'p_i_peak': np.nan\n",
|
||||||
" })\n",
|
" })\n",
|
||||||
" \n",
|
" \n",
|
||||||
" if stim_times is None:\n",
|
" if stim_times is None:\n",
|
||||||
" return nan_series\n",
|
" return nan_series\n",
|
||||||
" \n",
|
" \n",
|
||||||
" stim_times = np.array(stim_times)\n",
|
" stim_times = np.array(stim_times)\n",
|
||||||
" \n",
|
" \n",
|
||||||
" times, spikes, kernel, p_e, p_i = stimulus_response_latency(\n",
|
" times, spikes, kernel, p_e, p_i = stimulus_response_latency(\n",
|
||||||
" spike_times, stim_times, window_size, std_gaussian_kde)\n",
|
" spike_times, stim_times, window_size, std_gaussian_kde)\n",
|
||||||
" \n",
|
" \n",
|
||||||
" # if no spikes detected after stimulus nan is returned\n",
|
" # if no spikes detected after stimulus nan is returned\n",
|
||||||
" if all(np.isnan([p_e, p_i])):\n",
|
" if all(np.isnan([p_e, p_i])):\n",
|
||||||
" return nan_series\n",
|
" return nan_series\n",
|
||||||
" \n",
|
" \n",
|
||||||
" t_e_peak, p_e_peak, t_i_peak, p_i_peak = compute_response(\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",
|
" spike_times, stim_times, times, kernel, p_e, p_i)\n",
|
||||||
"\n",
|
"\n",
|
||||||
" return pd.Series({\n",
|
" return pd.Series({\n",
|
||||||
" 't_e_peak': t_e_peak,\n",
|
" 't_e_peak': t_e_peak,\n",
|
||||||
" 'p_e_peak': p_e_peak,\n",
|
" 'p_e_peak': p_e_peak,\n",
|
||||||
" 't_i_peak': t_i_peak,\n",
|
" 't_i_peak': t_i_peak,\n",
|
||||||
" 'p_i_peak': p_i_peak\n",
|
" 'p_i_peak': p_i_peak\n",
|
||||||
" })\n",
|
" })\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n"
|
"\n"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"application/vnd.jupyter.widget-view+json": {
|
"application/vnd.jupyter.widget-view+json": {
|
||||||
"model_id": "d3f0400c75c745c789907bd763bf2833",
|
"model_id": "476c31da67274b2396ed3f2ec54a8344",
|
||||||
"version_major": 2,
|
"version_major": 2,
|
||||||
"version_minor": 0
|
"version_minor": 0
|
||||||
},
|
},
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"HBox(children=(IntProgress(value=0, max=1281), HTML(value='')))"
|
"HBox(children=(IntProgress(value=0, max=1298), HTML(value='')))"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "display_data"
|
"output_type": "display_data"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "stderr",
|
"name": "stderr",
|
||||||
"output_type": "stream",
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"/home/mikkel/apps/expipe-project/septum-mec/septum_mec/analysis/stimulus_response.py:33: RuntimeWarning: invalid value encountered in less\n",
|
"/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"
|
" if any(times[idxs_i] < te_peak):\n"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"results = units.merge(\n",
|
"results = units.merge(\n",
|
||||||
" units.progress_apply(process, axis=1), \n",
|
" units.progress_apply(process, axis=1), \n",
|
||||||
" left_index=True, right_index=True)"
|
" left_index=True, right_index=True)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"scrolled": false
|
"scrolled": false
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"results.loc[:, ['t_e_peak', 't_i_peak', 'p_e_peak', 'p_i_peak']].hist()\n",
|
"results.loc[:, ['t_e_peak', 't_i_peak', 'p_e_peak', 'p_i_peak']].hist()\n",
|
||||||
"plt.gcf().savefig(output / 'figures' / 'summary_histogram.png')"
|
"plt.gcf().savefig(output / 'figures' / 'summary_histogram.png')"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"# Save to expipe"
|
"# Save to expipe"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"action = project.require_action(\"stimulus-response\")"
|
"action = project.require_action(\"stimulus-response\")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"action.modules['parameters'] = {\n",
|
"action.modules['parameters'] = {\n",
|
||||||
" 'window_size': window_size,\n",
|
" 'window_size': window_size,\n",
|
||||||
" 'std_gaussian_kde': std_gaussian_kde\n",
|
" 'std_gaussian_kde': std_gaussian_kde\n",
|
||||||
"}"
|
"}"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"action.data['results'] = 'results.csv'\n",
|
"action.data['results'] = 'results.csv'\n",
|
||||||
"results.to_csv(action.data_path('results'), index=False)"
|
"results.to_csv(action.data_path('results'), index=False)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"stuff = {\n",
|
"copy_tree(output, str(action.data_path()))"
|
||||||
" \"figures\": \"figures\",\n",
|
]
|
||||||
"# \"statistics\": \"statistics\"\n",
|
},
|
||||||
"}\n",
|
{
|
||||||
"\n",
|
"cell_type": "code",
|
||||||
"for key, value in stuff.items():\n",
|
"execution_count": null,
|
||||||
" action.data[key] = value\n",
|
"metadata": {},
|
||||||
" data_path = action.data_path(key)\n",
|
"outputs": [],
|
||||||
" data_path.parent.mkdir(exist_ok=True, parents=True)\n",
|
"source": [
|
||||||
" source = output / value\n",
|
"septum_mec.analysis.registration.store_notebook(action, \"10-calculate-stimulus-response.ipynb\")"
|
||||||
" if source.is_file():\n",
|
]
|
||||||
" shutil.copy(source, data_path)\n",
|
},
|
||||||
" else:\n",
|
{
|
||||||
" copy_tree(str(source), str(data_path))"
|
"cell_type": "code",
|
||||||
]
|
"execution_count": null,
|
||||||
},
|
"metadata": {},
|
||||||
{
|
"outputs": [],
|
||||||
"cell_type": "code",
|
"source": []
|
||||||
"execution_count": null,
|
}
|
||||||
"metadata": {},
|
],
|
||||||
"outputs": [],
|
"metadata": {
|
||||||
"source": [
|
"kernelspec": {
|
||||||
"septum_mec.analysis.registration.store_notebook(action, \"10-calculate-stimulus-response.ipynb\")"
|
"display_name": "Python 3",
|
||||||
]
|
"language": "python",
|
||||||
}
|
"name": "python3"
|
||||||
],
|
},
|
||||||
"metadata": {
|
"language_info": {
|
||||||
"kernelspec": {
|
"codemirror_mode": {
|
||||||
"display_name": "Python 3",
|
"name": "ipython",
|
||||||
"language": "python",
|
"version": 3
|
||||||
"name": "python3"
|
},
|
||||||
},
|
"file_extension": ".py",
|
||||||
"language_info": {
|
"mimetype": "text/x-python",
|
||||||
"codemirror_mode": {
|
"name": "python",
|
||||||
"name": "ipython",
|
"nbconvert_exporter": "python",
|
||||||
"version": 3
|
"pygments_lexer": "ipython3",
|
||||||
},
|
"version": "3.6.8"
|
||||||
"file_extension": ".py",
|
}
|
||||||
"mimetype": "text/x-python",
|
},
|
||||||
"name": "python",
|
"nbformat": 4,
|
||||||
"nbconvert_exporter": "python",
|
"nbformat_minor": 2
|
||||||
"pygments_lexer": "ipython3",
|
}
|
||||||
"version": "3.6.8"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nbformat": 4,
|
|
||||||
"nbformat_minor": 2
|
|
||||||
}
|
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
File diff suppressed because it is too large
Load Diff
|
@ -1,2 +1,2 @@
|
||||||
window_size: 0.03
|
window_size: 0.03
|
||||||
std_gaussian_kde: 0.04
|
std_gaussian_kde: 0.04
|
||||||
|
|
Loading…
Reference in New Issue