spike lfp analysis
|
@ -1,5 +1,5 @@
|
|||
registered: '2019-10-15T17:17:48'
|
||||
data:
|
||||
results: results.csv
|
||||
notebook: 10-calculate-stimulus-spike-lfp-response.ipynb
|
||||
html: 10-calculate-stimulus-spike-lfp-response.html
|
||||
notebook: 20_stimulus-spike-lfp-response.ipynb
|
||||
html: 20_stimulus-spike-lfp-response.html
|
||||
|
|
|
@ -13172,7 +13172,7 @@ div#notebook {
|
|||
|
||||
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -13202,7 +13202,7 @@ div#notebook {
|
|||
<div class="inner_cell">
|
||||
<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">'output/stimulus-spike-lfp-response'</span><span class="p">)</span>
|
||||
<span class="p">(</span><span class="n">output</span> <span class="o">/</span> <span class="s1">'figures'</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">'data'</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>
|
||||
|
||||
</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">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="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 class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [ ]:</div>
|
||||
<div class="prompt input_prompt">In [9]:</div>
|
||||
<div class="inner_cell">
|
||||
<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>
|
||||
|
@ -13324,7 +13324,7 @@ div#notebook {
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [ ]:</div>
|
||||
<div class="prompt input_prompt">In [10]:</div>
|
||||
<div class="inner_cell">
|
||||
<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>
|
||||
|
@ -13354,7 +13354,7 @@ div#notebook {
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [ ]:</div>
|
||||
<div class="prompt input_prompt">In [11]:</div>
|
||||
<div class="inner_cell">
|
||||
<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>
|
||||
|
@ -13370,7 +13370,7 @@ div#notebook {
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [ ]:</div>
|
||||
<div class="prompt input_prompt">In [12]:</div>
|
||||
<div class="inner_cell">
|
||||
<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>
|
||||
|
@ -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">></span> <span class="n">t_start</span><span class="p">)</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"><</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">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">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 class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [ ]:</div>
|
||||
<div class="prompt input_prompt">In [13]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython3"><pre><span></span><span class="c1"># action_id_0 = '1833-200619-1'</span>
|
||||
|
@ -13437,7 +13437,7 @@ div#notebook {
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [ ]:</div>
|
||||
<div class="prompt input_prompt">In [14]:</div>
|
||||
<div class="inner_cell">
|
||||
<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>
|
||||
|
@ -13451,7 +13451,7 @@ div#notebook {
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [ ]:</div>
|
||||
<div class="prompt input_prompt">In [15]:</div>
|
||||
<div class="inner_cell">
|
||||
<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>
|
||||
|
@ -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">'channel_group'</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">'unit_name'</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>
|
||||
|
||||
|
@ -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">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="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>
|
||||
|
||||
|
@ -13520,7 +13521,7 @@ div#notebook {
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [ ]:</div>
|
||||
<div class="prompt input_prompt">In [16]:</div>
|
||||
<div class="inner_cell">
|
||||
<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>
|
||||
|
@ -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 ">
|
||||
<script type="text/javascript">
|
||||
var element = $('#cbc4a88c-0fa4-49d2-ad4a-a148cc94b80e');
|
||||
var element = $('#fdf01411-110c-4f09-8a74-86966ed09bad');
|
||||
</script>
|
||||
<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>
|
||||
</div>
|
||||
|
||||
|
@ -13570,22 +13571,141 @@ var element = $('#cbc4a88c-0fa4-49d2-ad4a-a148cc94b80e');
|
|||
</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">¶</a></h1>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [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">'action'</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">'channel_group'</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">'unit_name'</span><span class="p">]</span>
|
||||
|
||||
<span class="n">name</span> <span class="o">=</span> <span class="n">f</span><span class="s1">'</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">'</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 class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [ ]:</div>
|
||||
<div class="prompt input_prompt">In [18]:</div>
|
||||
<div class="inner_cell">
|
||||
<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">'data'</span> <span class="o">/</span> <span class="s1">'coherence.feather'</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">'data'</span> <span class="o">/</span> <span class="s1">'freqs.feather'</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 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"><ipython-input-18-bf8a91a90c5a></span> in <span class="ansi-cyan-fg"><module></span>
|
||||
<span class="ansi-green-fg">----> 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">'data'</span> <span class="ansi-blue-fg">/</span> <span class="ansi-blue-fg">'coherence.feather'</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">'data'</span> <span class="ansi-blue-fg">/</span> <span class="ansi-blue-fg">'freqs.feather'</span><span class="ansi-blue-fg">)</span>
|
||||
|
||||
<span class="ansi-red-fg">AttributeError</span>: 'dict' object has no attribute 'to_feather'</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">
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"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": [],
|
||||
"source": [
|
||||
"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",
|
||||
"\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",
|
||||
"\n",
|
||||
" for ch in range(anas.shape[1]):\n",
|
||||
|
@ -148,7 +148,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
@ -165,7 +165,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
@ -191,7 +191,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 11,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
@ -203,7 +203,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 12,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
@ -217,7 +217,7 @@
|
|||
" mask = (anas.times > t_start) & (anas.times < t_stop)\n",
|
||||
" anas = np.array(anas)[mask,:]\n",
|
||||
"\n",
|
||||
" cleaned_anas = zscore(clean_lfp(anas))\n",
|
||||
" cleaned_anas = zscore(compute_clean_lfp(anas))\n",
|
||||
" \n",
|
||||
" cleaned_anas = neo.AnalogSignal(\n",
|
||||
" signal=cleaned_anas * units, sampling_rate=sampling_rate, t_start=t_start\n",
|
||||
|
@ -234,7 +234,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 13,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
@ -262,7 +262,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 14,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
@ -272,7 +272,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 15,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
@ -281,7 +281,7 @@
|
|||
" channel_group = row['channel_group']\n",
|
||||
" unit_name = row['unit_name']\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",
|
||||
" sptr = data_loader.spike_train(action_id, channel_group, unit_name)\n",
|
||||
" \n",
|
||||
|
@ -292,7 +292,8 @@
|
|||
" snls = signaltonoise(clean_lfp)\n",
|
||||
" best_channel = np.argmax(snls)\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",
|
||||
" theta_f, theta_p_max = find_theta_peak(p_xy, freq, theta_band_f1, theta_band_f2)\n",
|
||||
" \n",
|
||||
|
@ -337,13 +338,13 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 16,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"application/vnd.jupyter.widget-view+json": {
|
||||
"model_id": "e28818ca79be42abaf9c2b6106580c75",
|
||||
"model_id": "564d1ef5339f46eebee42ec41cfcfe62",
|
||||
"version_major": 2,
|
||||
"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",
|
||||
" Cxy = np.abs(Pxy)**2 / Pxx / Pyy\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
|
@ -370,12 +378,86 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"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')"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
After Width: | Height: | Size: 59 KiB |
BIN
actions/stimulus-spike-lfp-response/data/figures/spike-lfp-coherence-gridcell.svg (Stored with Git LFS)
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
actions/stimulus-spike-lfp-response/data/figures/spike-lfp-coherence-histogram-stim_energy-gridcell.svg (Stored with Git LFS)
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
actions/stimulus-spike-lfp-response/data/figures/spike-lfp-coherence-histogram-stim_energy-not-bs.svg (Stored with Git LFS)
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
actions/stimulus-spike-lfp-response/data/figures/spike-lfp-coherence-histogram-stim_half_width-gridcell.svg (Stored with Git LFS)
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
actions/stimulus-spike-lfp-response/data/figures/spike-lfp-coherence-histogram-stim_half_width-not-bs.svg (Stored with Git LFS)
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
actions/stimulus-spike-lfp-response/data/figures/spike-lfp-coherence-histogram-stim_p_max-gridcell.svg (Stored with Git LFS)
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
actions/stimulus-spike-lfp-response/data/figures/spike-lfp-coherence-histogram-stim_p_max-not-bs.svg (Stored with Git LFS)
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
actions/stimulus-spike-lfp-response/data/figures/spike-lfp-coherence-histogram-stim_strength-gridcell.svg (Stored with Git LFS)
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
actions/stimulus-spike-lfp-response/data/figures/spike-lfp-coherence-histogram-stim_strength-not-bs.svg (Stored with Git LFS)
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
actions/stimulus-spike-lfp-response/data/figures/spike-lfp-coherence-histogram-theta_energy-gridcell.svg (Stored with Git LFS)
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
actions/stimulus-spike-lfp-response/data/figures/spike-lfp-coherence-histogram-theta_energy-not-bs.svg (Stored with Git LFS)
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
actions/stimulus-spike-lfp-response/data/figures/spike-lfp-coherence-histogram-theta_freq-gridcell.svg (Stored with Git LFS)
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
actions/stimulus-spike-lfp-response/data/figures/spike-lfp-coherence-histogram-theta_freq-not-bs.svg (Stored with Git LFS)
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
actions/stimulus-spike-lfp-response/data/figures/spike-lfp-coherence-histogram-theta_half_width-gridcell.svg (Stored with Git LFS)
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
actions/stimulus-spike-lfp-response/data/figures/spike-lfp-coherence-histogram-theta_half_width-not-bs.svg (Stored with Git LFS)
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
actions/stimulus-spike-lfp-response/data/figures/spike-lfp-coherence-histogram-theta_peak-gridcell.svg (Stored with Git LFS)
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
actions/stimulus-spike-lfp-response/data/figures/spike-lfp-coherence-histogram-theta_peak-not-bs.svg (Stored with Git LFS)
Normal file
After Width: | Height: | Size: 60 KiB |