spike lfp analysis

This commit is contained in:
Mikkel Elle Lepperød 2019-10-17 19:44:01 +02:00
parent dd1d57425f
commit 55f8a7de5b
44 changed files with 20123 additions and 1336 deletions

View File

@ -1,5 +1,5 @@
registered: '2019-10-15T17:17:48' registered: '2019-10-15T17:17:48'
data: data:
results: results.csv results: results.csv
notebook: 10-calculate-stimulus-spike-lfp-response.ipynb notebook: 20_stimulus-spike-lfp-response.ipynb
html: 10-calculate-stimulus-spike-lfp-response.html html: 20_stimulus-spike-lfp-response.html

View File

@ -13172,7 +13172,7 @@ div#notebook {
<div class="output_subarea output_stream output_stderr output_text"> <div class="output_subarea output_stream output_stderr output_text">
<pre>16:56:09 [I] klustakwik KlustaKwik2 version 0.2.6 <pre>10:25:26 [I] klustakwik KlustaKwik2 version 0.2.6
</pre> </pre>
</div> </div>
</div> </div>
@ -13202,7 +13202,7 @@ div#notebook {
<div class="inner_cell"> <div class="inner_cell">
<div class="input_area"> <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">output</span> <span class="o">=</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="s1">&#39;output/stimulus-spike-lfp-response&#39;</span><span class="p">)</span> <div class=" highlight hl-ipython3"><pre><span></span><span class="n">output</span> <span class="o">=</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="s1">&#39;output/stimulus-spike-lfp-response&#39;</span><span class="p">)</span>
<span class="p">(</span><span class="n">output</span> <span class="o">/</span> <span class="s1">&#39;figures&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="n">parents</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">exist_ok</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> <span class="p">(</span><span class="n">output</span> <span class="o">/</span> <span class="s1">&#39;data&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="n">parents</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">exist_ok</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div> </pre></div>
</div> </div>
@ -13268,7 +13268,7 @@ div#notebook {
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">sd</span> <span class="o">==</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">m</span> <span class="o">/</span> <span class="n">sd</span><span class="p">)</span> <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">sd</span> <span class="o">==</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">m</span> <span class="o">/</span> <span class="n">sd</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">clean_lfp</span><span class="p">(</span><span class="n">anas</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="mi">500</span><span class="p">,</span> <span class="n">threshold</span><span class="o">=</span><span class="mi">2</span><span class="p">):</span> <span class="k">def</span> <span class="nf">compute_clean_lfp</span><span class="p">(</span><span class="n">anas</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="mi">500</span><span class="p">,</span> <span class="n">threshold</span><span class="o">=</span><span class="mi">2</span><span class="p">):</span>
<span class="n">anas</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">anas</span><span class="p">)</span> <span class="n">anas</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">anas</span><span class="p">)</span>
<span class="k">for</span> <span class="n">ch</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">anas</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]):</span> <span class="k">for</span> <span class="n">ch</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">anas</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]):</span>
@ -13303,7 +13303,7 @@ div#notebook {
</div> </div>
<div class="cell border-box-sizing code_cell rendered"> <div class="cell border-box-sizing code_cell rendered">
<div class="input"> <div class="input">
<div class="prompt input_prompt">In&nbsp;[&nbsp;]:</div> <div class="prompt input_prompt">In&nbsp;[9]:</div>
<div class="inner_cell"> <div class="inner_cell">
<div class="input_area"> <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">find_theta_peak</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="n">f1</span><span class="p">,</span> <span class="n">f2</span><span class="p">):</span> <div class=" highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">find_theta_peak</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="n">f1</span><span class="p">,</span> <span class="n">f2</span><span class="p">):</span>
@ -13324,7 +13324,7 @@ div#notebook {
</div> </div>
<div class="cell border-box-sizing code_cell rendered"> <div class="cell border-box-sizing code_cell rendered">
<div class="input"> <div class="input">
<div class="prompt input_prompt">In&nbsp;[&nbsp;]:</div> <div class="prompt input_prompt">In&nbsp;[10]:</div>
<div class="inner_cell"> <div class="inner_cell">
<div class="input_area"> <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">compute_half_width</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="n">m_p</span><span class="p">,</span> <span class="n">m_f</span><span class="p">):</span> <div class=" highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">compute_half_width</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="n">m_p</span><span class="p">,</span> <span class="n">m_f</span><span class="p">):</span>
@ -13354,7 +13354,7 @@ div#notebook {
</div> </div>
<div class="cell border-box-sizing code_cell rendered"> <div class="cell border-box-sizing code_cell rendered">
<div class="input"> <div class="input">
<div class="prompt input_prompt">In&nbsp;[&nbsp;]:</div> <div class="prompt input_prompt">In&nbsp;[11]:</div>
<div class="inner_cell"> <div class="inner_cell">
<div class="input_area"> <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">compute_stim_peak</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="n">s_f</span><span class="p">):</span> <div class=" highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">compute_stim_peak</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="n">s_f</span><span class="p">):</span>
@ -13370,7 +13370,7 @@ div#notebook {
</div> </div>
<div class="cell border-box-sizing code_cell rendered"> <div class="cell border-box-sizing code_cell rendered">
<div class="input"> <div class="input">
<div class="prompt input_prompt">In&nbsp;[&nbsp;]:</div> <div class="prompt input_prompt">In&nbsp;[12]:</div>
<div class="inner_cell"> <div class="inner_cell">
<div class="input_area"> <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">compute_spike_lfp</span><span class="p">(</span><span class="n">anas</span><span class="p">,</span> <span class="n">sptr</span><span class="p">,</span> <span class="n">t_start</span><span class="p">,</span> <span class="n">t_stop</span><span class="p">,</span> <span class="n">NFFT</span><span class="p">):</span> <div class=" highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">compute_spike_lfp</span><span class="p">(</span><span class="n">anas</span><span class="p">,</span> <span class="n">sptr</span><span class="p">,</span> <span class="n">t_start</span><span class="p">,</span> <span class="n">t_stop</span><span class="p">,</span> <span class="n">NFFT</span><span class="p">):</span>
@ -13383,7 +13383,7 @@ div#notebook {
<span class="n">mask</span> <span class="o">=</span> <span class="p">(</span><span class="n">anas</span><span class="o">.</span><span class="n">times</span> <span class="o">&gt;</span> <span class="n">t_start</span><span class="p">)</span> <span class="o">&amp;</span> <span class="p">(</span><span class="n">anas</span><span class="o">.</span><span class="n">times</span> <span class="o">&lt;</span> <span class="n">t_stop</span><span class="p">)</span> <span class="n">mask</span> <span class="o">=</span> <span class="p">(</span><span class="n">anas</span><span class="o">.</span><span class="n">times</span> <span class="o">&gt;</span> <span class="n">t_start</span><span class="p">)</span> <span class="o">&amp;</span> <span class="p">(</span><span class="n">anas</span><span class="o">.</span><span class="n">times</span> <span class="o">&lt;</span> <span class="n">t_stop</span><span class="p">)</span>
<span class="n">anas</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">anas</span><span class="p">)[</span><span class="n">mask</span><span class="p">,:]</span> <span class="n">anas</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">anas</span><span class="p">)[</span><span class="n">mask</span><span class="p">,:]</span>
<span class="n">cleaned_anas</span> <span class="o">=</span> <span class="n">zscore</span><span class="p">(</span><span class="n">clean_lfp</span><span class="p">(</span><span class="n">anas</span><span class="p">))</span> <span class="n">cleaned_anas</span> <span class="o">=</span> <span class="n">zscore</span><span class="p">(</span><span class="n">compute_clean_lfp</span><span class="p">(</span><span class="n">anas</span><span class="p">))</span>
<span class="n">cleaned_anas</span> <span class="o">=</span> <span class="n">neo</span><span class="o">.</span><span class="n">AnalogSignal</span><span class="p">(</span> <span class="n">cleaned_anas</span> <span class="o">=</span> <span class="n">neo</span><span class="o">.</span><span class="n">AnalogSignal</span><span class="p">(</span>
<span class="n">signal</span><span class="o">=</span><span class="n">cleaned_anas</span> <span class="o">*</span> <span class="n">units</span><span class="p">,</span> <span class="n">sampling_rate</span><span class="o">=</span><span class="n">sampling_rate</span><span class="p">,</span> <span class="n">t_start</span><span class="o">=</span><span class="n">t_start</span> <span class="n">signal</span><span class="o">=</span><span class="n">cleaned_anas</span> <span class="o">*</span> <span class="n">units</span><span class="p">,</span> <span class="n">sampling_rate</span><span class="o">=</span><span class="n">sampling_rate</span><span class="p">,</span> <span class="n">t_start</span><span class="o">=</span><span class="n">t_start</span>
@ -13405,7 +13405,7 @@ div#notebook {
</div> </div>
<div class="cell border-box-sizing code_cell rendered"> <div class="cell border-box-sizing code_cell rendered">
<div class="input"> <div class="input">
<div class="prompt input_prompt">In&nbsp;[&nbsp;]:</div> <div class="prompt input_prompt">In&nbsp;[13]:</div>
<div class="inner_cell"> <div class="inner_cell">
<div class="input_area"> <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="c1"># action_id_0 = &#39;1833-200619-1&#39;</span> <div class=" highlight hl-ipython3"><pre><span></span><span class="c1"># action_id_0 = &#39;1833-200619-1&#39;</span>
@ -13437,7 +13437,7 @@ div#notebook {
</div> </div>
<div class="cell border-box-sizing code_cell rendered"> <div class="cell border-box-sizing code_cell rendered">
<div class="input"> <div class="input">
<div class="prompt input_prompt">In&nbsp;[&nbsp;]:</div> <div class="prompt input_prompt">In&nbsp;[14]:</div>
<div class="inner_cell"> <div class="inner_cell">
<div class="input_area"> <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">NFFT</span> <span class="o">=</span> <span class="mi">4096</span><span class="o">*</span><span class="mi">2</span> <div class=" highlight hl-ipython3"><pre><span></span><span class="n">NFFT</span> <span class="o">=</span> <span class="mi">4096</span><span class="o">*</span><span class="mi">2</span>
@ -13451,7 +13451,7 @@ div#notebook {
</div> </div>
<div class="cell border-box-sizing code_cell rendered"> <div class="cell border-box-sizing code_cell rendered">
<div class="input"> <div class="input">
<div class="prompt input_prompt">In&nbsp;[&nbsp;]:</div> <div class="prompt input_prompt">In&nbsp;[15]:</div>
<div class="inner_cell"> <div class="inner_cell">
<div class="input_area"> <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">process</span><span class="p">(</span><span class="n">row</span><span class="p">):</span> <div class=" highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">process</span><span class="p">(</span><span class="n">row</span><span class="p">):</span>
@ -13459,7 +13459,7 @@ div#notebook {
<span class="n">channel_group</span> <span class="o">=</span> <span class="n">row</span><span class="p">[</span><span class="s1">&#39;channel_group&#39;</span><span class="p">]</span> <span class="n">channel_group</span> <span class="o">=</span> <span class="n">row</span><span class="p">[</span><span class="s1">&#39;channel_group&#39;</span><span class="p">]</span>
<span class="n">unit_name</span> <span class="o">=</span> <span class="n">row</span><span class="p">[</span><span class="s1">&#39;unit_name&#39;</span><span class="p">]</span> <span class="n">unit_name</span> <span class="o">=</span> <span class="n">row</span><span class="p">[</span><span class="s1">&#39;unit_name&#39;</span><span class="p">]</span>
<span class="n">lfp</span> <span class="o">=</span> <span class="n">data_loader</span><span class="o">.</span><span class="n">lfp</span><span class="p">(</span><span class="n">action_id</span><span class="p">,</span> <span class="n">channel_group</span><span class="p">)</span> <span class="n">lfp</span> <span class="o">=</span> <span class="n">data_loader</span><span class="o">.</span><span class="n">lfp</span><span class="p">(</span><span class="n">action_id</span><span class="p">,</span> <span class="n">channel_group</span><span class="p">)</span> <span class="c1"># TODO consider choosing strongest stim response</span>
<span class="n">sptr</span> <span class="o">=</span> <span class="n">data_loader</span><span class="o">.</span><span class="n">spike_train</span><span class="p">(</span><span class="n">action_id</span><span class="p">,</span> <span class="n">channel_group</span><span class="p">,</span> <span class="n">unit_name</span><span class="p">)</span> <span class="n">sptr</span> <span class="o">=</span> <span class="n">data_loader</span><span class="o">.</span><span class="n">spike_train</span><span class="p">(</span><span class="n">action_id</span><span class="p">,</span> <span class="n">channel_group</span><span class="p">,</span> <span class="n">unit_name</span><span class="p">)</span>
@ -13470,7 +13470,8 @@ div#notebook {
<span class="n">snls</span> <span class="o">=</span> <span class="n">signaltonoise</span><span class="p">(</span><span class="n">clean_lfp</span><span class="p">)</span> <span class="n">snls</span> <span class="o">=</span> <span class="n">signaltonoise</span><span class="p">(</span><span class="n">clean_lfp</span><span class="p">)</span>
<span class="n">best_channel</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">argmax</span><span class="p">(</span><span class="n">snls</span><span class="p">)</span> <span class="n">best_channel</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">argmax</span><span class="p">(</span><span class="n">snls</span><span class="p">)</span>
<span class="n">snl</span> <span class="o">=</span> <span class="n">snls</span><span class="p">[</span><span class="n">best_channel</span><span class="p">]</span> <span class="n">snl</span> <span class="o">=</span> <span class="n">snls</span><span class="p">[</span><span class="n">best_channel</span><span class="p">]</span>
<span class="n">p_xy</span> <span class="o">=</span> <span class="n">p_xys</span><span class="p">[:,</span><span class="n">best_channel</span><span class="p">]</span> <span class="n">p_xy</span> <span class="o">=</span> <span class="n">p_xys</span><span class="p">[:,</span><span class="n">best_channel</span><span class="p">]</span><span class="o">.</span><span class="n">magnitude</span>
<span class="n">freq</span> <span class="o">=</span> <span class="n">freq</span><span class="o">.</span><span class="n">magnitude</span>
<span class="n">theta_f</span><span class="p">,</span> <span class="n">theta_p_max</span> <span class="o">=</span> <span class="n">find_theta_peak</span><span class="p">(</span><span class="n">p_xy</span><span class="p">,</span> <span class="n">freq</span><span class="p">,</span> <span class="n">theta_band_f1</span><span class="p">,</span> <span class="n">theta_band_f2</span><span class="p">)</span> <span class="n">theta_f</span><span class="p">,</span> <span class="n">theta_p_max</span> <span class="o">=</span> <span class="n">find_theta_peak</span><span class="p">(</span><span class="n">p_xy</span><span class="p">,</span> <span class="n">freq</span><span class="p">,</span> <span class="n">theta_band_f1</span><span class="p">,</span> <span class="n">theta_band_f2</span><span class="p">)</span>
@ -13520,7 +13521,7 @@ div#notebook {
</div> </div>
<div class="cell border-box-sizing code_cell rendered"> <div class="cell border-box-sizing code_cell rendered">
<div class="input"> <div class="input">
<div class="prompt input_prompt">In&nbsp;[&nbsp;]:</div> <div class="prompt input_prompt">In&nbsp;[16]:</div>
<div class="inner_cell"> <div class="inner_cell">
<div class="input_area"> <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">results</span> <span class="o">=</span> <span class="n">units</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span> <div class=" highlight hl-ipython3"><pre><span></span><span class="n">results</span> <span class="o">=</span> <span class="n">units</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span>
@ -13546,13 +13547,13 @@ div#notebook {
<div id="cbc4a88c-0fa4-49d2-ad4a-a148cc94b80e"></div> <div id="fdf01411-110c-4f09-8a74-86966ed09bad"></div>
<div class="output_subarea output_widget_view "> <div class="output_subarea output_widget_view ">
<script type="text/javascript"> <script type="text/javascript">
var element = $('#cbc4a88c-0fa4-49d2-ad4a-a148cc94b80e'); var element = $('#fdf01411-110c-4f09-8a74-86966ed09bad');
</script> </script>
<script type="application/vnd.jupyter.widget-view+json"> <script type="application/vnd.jupyter.widget-view+json">
{"model_id": "e28818ca79be42abaf9c2b6106580c75", "version_major": 2, "version_minor": 0} {"model_id": "564d1ef5339f46eebee42ec41cfcfe62", "version_major": 2, "version_minor": 0}
</script> </script>
</div> </div>
@ -13570,22 +13571,141 @@ var element = $('#cbc4a88c-0fa4-49d2-ad4a-a148cc94b80e');
</div> </div>
</div> </div>
<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>
</pre>
</div>
</div>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h1 id="plot">plot<a class="anchor-link" href="#plot">&#182;</a></h1>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In&nbsp;[17]:</div>
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">coher</span><span class="p">,</span> <span class="n">freqs</span> <span class="o">=</span> <span class="p">{},</span> <span class="p">{}</span>
<span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">tqdm</span><span class="p">(</span><span class="n">units</span><span class="o">.</span><span class="n">iterrows</span><span class="p">(),</span> <span class="n">total</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="n">units</span><span class="p">)):</span>
<span class="n">action_id</span> <span class="o">=</span> <span class="n">row</span><span class="p">[</span><span class="s1">&#39;action&#39;</span><span class="p">]</span>
<span class="n">channel_group</span> <span class="o">=</span> <span class="n">row</span><span class="p">[</span><span class="s1">&#39;channel_group&#39;</span><span class="p">]</span>
<span class="n">unit_name</span> <span class="o">=</span> <span class="n">row</span><span class="p">[</span><span class="s1">&#39;unit_name&#39;</span><span class="p">]</span>
<span class="n">name</span> <span class="o">=</span> <span class="n">f</span><span class="s1">&#39;</span><span class="si">{action_id}</span><span class="s1">_</span><span class="si">{channel_group}</span><span class="s1">_</span><span class="si">{unit_name}</span><span class="s1">&#39;</span>
<span class="n">lfp</span> <span class="o">=</span> <span class="n">data_loader</span><span class="o">.</span><span class="n">lfp</span><span class="p">(</span><span class="n">action_id</span><span class="p">,</span> <span class="n">channel_group</span><span class="p">)</span> <span class="c1"># TODO consider choosing strongest stim response</span>
<span class="n">sptr</span> <span class="o">=</span> <span class="n">data_loader</span><span class="o">.</span><span class="n">spike_train</span><span class="p">(</span><span class="n">action_id</span><span class="p">,</span> <span class="n">channel_group</span><span class="p">,</span> <span class="n">unit_name</span><span class="p">)</span>
<span class="n">lim</span> <span class="o">=</span> <span class="n">get_lim</span><span class="p">(</span><span class="n">action_id</span><span class="p">)</span>
<span class="n">p_xys</span><span class="p">,</span> <span class="n">freq</span><span class="p">,</span> <span class="n">clean_lfp</span> <span class="o">=</span> <span class="n">compute_spike_lfp</span><span class="p">(</span><span class="n">lfp</span><span class="p">,</span> <span class="n">sptr</span><span class="p">,</span> <span class="o">*</span><span class="n">lim</span><span class="p">,</span> <span class="n">NFFT</span><span class="o">=</span><span class="n">NFFT</span><span class="p">)</span>
<span class="n">snls</span> <span class="o">=</span> <span class="n">signaltonoise</span><span class="p">(</span><span class="n">clean_lfp</span><span class="p">)</span>
<span class="n">best_channel</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">argmax</span><span class="p">(</span><span class="n">snls</span><span class="p">)</span>
<span class="n">snl</span> <span class="o">=</span> <span class="n">snls</span><span class="p">[</span><span class="n">best_channel</span><span class="p">]</span>
<span class="n">p_xy</span> <span class="o">=</span> <span class="n">p_xys</span><span class="p">[:,</span><span class="n">best_channel</span><span class="p">]</span><span class="o">.</span><span class="n">magnitude</span>
<span class="n">freq</span> <span class="o">=</span> <span class="n">freq</span><span class="o">.</span><span class="n">magnitude</span>
<span class="n">coher</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="n">name</span><span class="p">:</span> <span class="n">p_xy</span><span class="p">})</span>
<span class="n">freqs</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="n">name</span><span class="p">:</span> <span class="n">freq</span><span class="p">})</span>
</pre></div>
</div>
</div>
</div>
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="prompt"></div>
<div id="0aa9c06f-773a-4f88-a2ad-e7de5c5ebe40"></div>
<div class="output_subarea output_widget_view ">
<script type="text/javascript">
var element = $('#0aa9c06f-773a-4f88-a2ad-e7de5c5ebe40');
</script>
<script type="application/vnd.jupyter.widget-view+json">
{"model_id": "b20a9a26e0864f578e1a9aa0c021999b", "version_major": 2, "version_minor": 0}
</script>
</div>
</div>
<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre>
</pre>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>
<div class="cell border-box-sizing code_cell rendered"> <div class="cell border-box-sizing code_cell rendered">
<div class="input"> <div class="input">
<div class="prompt input_prompt">In&nbsp;[&nbsp;]:</div> <div class="prompt input_prompt">In&nbsp;[18]:</div>
<div class="inner_cell"> <div class="inner_cell">
<div class="input_area"> <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">%</span><span class="k">debug</span> <div class=" highlight hl-ipython3"><pre><span></span><span class="n">coher</span><span class="o">.</span><span class="n">to_feather</span><span class="p">(</span><span class="n">output</span> <span class="o">/</span> <span class="s1">&#39;data&#39;</span> <span class="o">/</span> <span class="s1">&#39;coherence.feather&#39;</span><span class="p">)</span>
<span class="n">freqs</span><span class="o">.</span><span class="n">to_feather</span><span class="p">(</span><span class="n">output</span> <span class="o">/</span> <span class="s1">&#39;data&#39;</span> <span class="o">/</span> <span class="s1">&#39;freqs.feather&#39;</span><span class="p">)</span>
</pre></div> </pre></div>
</div> </div>
</div> </div>
</div> </div>
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_text output_error">
<pre>
<span class="ansi-red-fg">---------------------------------------------------------------------------</span>
<span class="ansi-red-fg">AttributeError</span> Traceback (most recent call last)
<span class="ansi-green-fg">&lt;ipython-input-18-bf8a91a90c5a&gt;</span> in <span class="ansi-cyan-fg">&lt;module&gt;</span>
<span class="ansi-green-fg">----&gt; 1</span><span class="ansi-red-fg"> </span>coher<span class="ansi-blue-fg">.</span>to_feather<span class="ansi-blue-fg">(</span>output <span class="ansi-blue-fg">/</span> <span class="ansi-blue-fg">&#39;data&#39;</span> <span class="ansi-blue-fg">/</span> <span class="ansi-blue-fg">&#39;coherence.feather&#39;</span><span class="ansi-blue-fg">)</span>
<span class="ansi-green-intense-fg ansi-bold"> 2</span> freqs<span class="ansi-blue-fg">.</span>to_feather<span class="ansi-blue-fg">(</span>output <span class="ansi-blue-fg">/</span> <span class="ansi-blue-fg">&#39;data&#39;</span> <span class="ansi-blue-fg">/</span> <span class="ansi-blue-fg">&#39;freqs.feather&#39;</span><span class="ansi-blue-fg">)</span>
<span class="ansi-red-fg">AttributeError</span>: &#39;dict&#39; object has no attribute &#39;to_feather&#39;</pre>
</div>
</div>
</div>
</div>
</div> </div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt"> <div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell"> </div><div class="inner_cell">

View File

@ -19,7 +19,7 @@
"name": "stderr", "name": "stderr",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"16:56:09 [I] klustakwik KlustaKwik2 version 0.2.6\n" "10:25:26 [I] klustakwik KlustaKwik2 version 0.2.6\n"
] ]
} }
], ],
@ -68,7 +68,7 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"output = pathlib.Path('output/stimulus-spike-lfp-response')\n", "output = pathlib.Path('output/stimulus-spike-lfp-response')\n",
"(output / 'figures').mkdir(parents=True, exist_ok=True)" "(output / 'data').mkdir(parents=True, exist_ok=True)"
] ]
}, },
{ {
@ -122,7 +122,7 @@
" return np.where(sd == 0, 0, m / sd)\n", " return np.where(sd == 0, 0, m / sd)\n",
"\n", "\n",
"\n", "\n",
"def clean_lfp(anas, width=500, threshold=2):\n", "def compute_clean_lfp(anas, width=500, threshold=2):\n",
" anas = np.array(anas)\n", " anas = np.array(anas)\n",
"\n", "\n",
" for ch in range(anas.shape[1]):\n", " for ch in range(anas.shape[1]):\n",
@ -148,7 +148,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 9,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -165,7 +165,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 10,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -191,7 +191,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 11,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -203,7 +203,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 12,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -217,7 +217,7 @@
" mask = (anas.times > t_start) & (anas.times < t_stop)\n", " mask = (anas.times > t_start) & (anas.times < t_stop)\n",
" anas = np.array(anas)[mask,:]\n", " anas = np.array(anas)[mask,:]\n",
"\n", "\n",
" cleaned_anas = zscore(clean_lfp(anas))\n", " cleaned_anas = zscore(compute_clean_lfp(anas))\n",
" \n", " \n",
" cleaned_anas = neo.AnalogSignal(\n", " cleaned_anas = neo.AnalogSignal(\n",
" signal=cleaned_anas * units, sampling_rate=sampling_rate, t_start=t_start\n", " signal=cleaned_anas * units, sampling_rate=sampling_rate, t_start=t_start\n",
@ -234,7 +234,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 13,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -262,7 +262,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 14,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -272,7 +272,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 15,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -281,7 +281,7 @@
" channel_group = row['channel_group']\n", " channel_group = row['channel_group']\n",
" unit_name = row['unit_name']\n", " unit_name = row['unit_name']\n",
" \n", " \n",
" lfp = data_loader.lfp(action_id, channel_group)\n", " lfp = data_loader.lfp(action_id, channel_group) # TODO consider choosing strongest stim response\n",
" \n", " \n",
" sptr = data_loader.spike_train(action_id, channel_group, unit_name)\n", " sptr = data_loader.spike_train(action_id, channel_group, unit_name)\n",
" \n", " \n",
@ -292,7 +292,8 @@
" snls = signaltonoise(clean_lfp)\n", " snls = signaltonoise(clean_lfp)\n",
" best_channel = np.argmax(snls)\n", " best_channel = np.argmax(snls)\n",
" snl = snls[best_channel]\n", " snl = snls[best_channel]\n",
" p_xy = p_xys[:,best_channel]\n", " p_xy = p_xys[:,best_channel].magnitude\n",
" freq = freq.magnitude\n",
" \n", " \n",
" theta_f, theta_p_max = find_theta_peak(p_xy, freq, theta_band_f1, theta_band_f2)\n", " theta_f, theta_p_max = find_theta_peak(p_xy, freq, theta_band_f1, theta_band_f2)\n",
" \n", " \n",
@ -337,13 +338,13 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 16,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"application/vnd.jupyter.widget-view+json": { "application/vnd.jupyter.widget-view+json": {
"model_id": "e28818ca79be42abaf9c2b6106580c75", "model_id": "564d1ef5339f46eebee42ec41cfcfe62",
"version_major": 2, "version_major": 2,
"version_minor": 0 "version_minor": 0
}, },
@ -361,6 +362,13 @@
"/home/mikkel/.virtualenvs/expipe/lib/python3.6/site-packages/scipy/signal/spectral.py:1578: RuntimeWarning: invalid value encountered in true_divide\n", "/home/mikkel/.virtualenvs/expipe/lib/python3.6/site-packages/scipy/signal/spectral.py:1578: RuntimeWarning: invalid value encountered in true_divide\n",
" Cxy = np.abs(Pxy)**2 / Pxx / Pyy\n" " Cxy = np.abs(Pxy)**2 / Pxx / Pyy\n"
] ]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n"
]
} }
], ],
"source": [ "source": [
@ -370,12 +378,86 @@
] ]
}, },
{ {
"cell_type": "code", "cell_type": "markdown",
"execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [],
"source": [ "source": [
"%debug" "# plot"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b20a9a26e0864f578e1a9aa0c021999b",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, max=1298), HTML(value='')))"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n"
]
}
],
"source": [
"coher, freqs = {}, {}\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",
" \n",
" name = f'{action_id}_{channel_group}_{unit_name}'\n",
" \n",
" lfp = data_loader.lfp(action_id, channel_group) # TODO consider choosing strongest stim response\n",
" \n",
" sptr = data_loader.spike_train(action_id, channel_group, unit_name)\n",
" \n",
" lim = get_lim(action_id)\n",
"\n",
" p_xys, freq, clean_lfp = compute_spike_lfp(lfp, sptr, *lim, NFFT=NFFT)\n",
" \n",
" snls = signaltonoise(clean_lfp)\n",
" best_channel = np.argmax(snls)\n",
" snl = snls[best_channel]\n",
" p_xy = p_xys[:,best_channel].magnitude\n",
" freq = freq.magnitude\n",
" \n",
" coher.update({name: p_xy})\n",
" freqs.update({name: freq})"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "'dict' object has no attribute 'to_feather'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-18-bf8a91a90c5a>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mcoher\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mto_feather\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0moutput\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0;34m'data'\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0;34m'coherence.feather'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mfreqs\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mto_feather\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0moutput\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0;34m'data'\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0;34m'freqs.feather'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mAttributeError\u001b[0m: 'dict' object has no attribute 'to_feather'"
]
}
],
"source": [
"coher.to_feather(output / 'data' / 'coherence.feather')\n",
"freqs.to_feather(output / 'data' / 'freqs.feather')"
] ]
}, },
{ {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

File diff suppressed because it is too large Load Diff