actions/stimulus-lfp-response
This commit is contained in:
parent
90a650c468
commit
d9d94e0553
|
@ -1,5 +1,5 @@
|
||||||
registered: '2019-10-14T17:03:05'
|
registered: '2019-10-14T17:03:05'
|
||||||
data:
|
data:
|
||||||
results: results.csv
|
results: results.csv
|
||||||
notebook: 20_stimulus-lfp-response.ipynb
|
notebook: 10-calculate-stimulus-lfp-response.ipynb
|
||||||
html: 20_stimulus-lfp-response.html
|
html: 10-calculate-stimulus-lfp-response.html
|
||||||
|
|
|
@ -13147,6 +13147,8 @@ div#notebook {
|
||||||
<span class="kn">import</span> <span class="nn">quantities</span> <span class="k">as</span> <span class="nn">pq</span>
|
<span class="kn">import</span> <span class="nn">quantities</span> <span class="k">as</span> <span class="nn">pq</span>
|
||||||
<span class="kn">import</span> <span class="nn">shutil</span>
|
<span class="kn">import</span> <span class="nn">shutil</span>
|
||||||
<span class="kn">from</span> <span class="nn">distutils.dir_util</span> <span class="k">import</span> <span class="n">copy_tree</span>
|
<span class="kn">from</span> <span class="nn">distutils.dir_util</span> <span class="k">import</span> <span class="n">copy_tree</span>
|
||||||
|
<span class="kn">import</span> <span class="nn">scipy</span>
|
||||||
|
<span class="kn">import</span> <span class="nn">scipy.signal</span> <span class="k">as</span> <span class="nn">ss</span>
|
||||||
|
|
||||||
<span class="kn">from</span> <span class="nn">scipy.signal</span> <span class="k">import</span> <span class="n">find_peaks</span>
|
<span class="kn">from</span> <span class="nn">scipy.signal</span> <span class="k">import</span> <span class="n">find_peaks</span>
|
||||||
<span class="kn">from</span> <span class="nn">scipy.interpolate</span> <span class="k">import</span> <span class="n">interp1d</span>
|
<span class="kn">from</span> <span class="nn">scipy.interpolate</span> <span class="k">import</span> <span class="n">interp1d</span>
|
||||||
|
@ -13171,7 +13173,9 @@ div#notebook {
|
||||||
|
|
||||||
|
|
||||||
<div class="output_subarea output_stream output_stderr output_text">
|
<div class="output_subarea output_stream output_stderr output_text">
|
||||||
<pre>10:26:07 [I] klustakwik KlustaKwik2 version 0.2.6
|
<pre>19:43:24 [I] klustakwik KlustaKwik2 version 0.2.6
|
||||||
|
/home/mikkel/.virtualenvs/expipe/lib/python3.6/site-packages/ipykernel_launcher.py:24: TqdmDeprecationWarning: This function will be removed in tqdm==5.0.0
|
||||||
|
Please use `tqdm.notebook.*` instead of `tqdm._tqdm_notebook.*`
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -13200,8 +13204,16 @@ div#notebook {
|
||||||
<div class="prompt input_prompt">In [4]:</div>
|
<div class="prompt input_prompt">In [4]:</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">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-lfp-response'</span><span class="p">)</span>
|
<div class=" highlight hl-ipython3"><pre><span></span><span class="c1">#############################</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>
|
|
||||||
|
<span class="n">perform_zscore</span> <span class="o">=</span> <span class="kc">True</span>
|
||||||
|
|
||||||
|
<span class="k">if</span> <span class="ow">not</span> <span class="n">perform_zscore</span><span class="p">:</span>
|
||||||
|
<span class="n">zscore_str</span> <span class="o">=</span> <span class="s2">"-no-zscore"</span>
|
||||||
|
<span class="k">else</span><span class="p">:</span>
|
||||||
|
<span class="n">zscore_str</span> <span class="o">=</span> <span class="s2">""</span>
|
||||||
|
|
||||||
|
<span class="c1">#################################</span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -13212,6 +13224,20 @@ div#notebook {
|
||||||
<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 [5]:</div>
|
<div class="prompt input_prompt">In [5]:</div>
|
||||||
|
<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-lfp-response'</span> <span class="o">+</span> <span class="n">zscore_str</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>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="cell border-box-sizing code_cell rendered">
|
||||||
|
<div class="input">
|
||||||
|
<div class="prompt input_prompt">In [6]:</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">identify_neurons</span> <span class="o">=</span> <span class="n">actions</span><span class="p">[</span><span class="s1">'identify-neurons'</span><span class="p">]</span>
|
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">identify_neurons</span> <span class="o">=</span> <span class="n">actions</span><span class="p">[</span><span class="s1">'identify-neurons'</span><span class="p">]</span>
|
||||||
|
@ -13225,7 +13251,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 [6]:</div>
|
<div class="prompt input_prompt">In [7]:</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">channel_groups</span> <span class="o">=</span> <span class="p">[]</span>
|
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">channel_groups</span> <span class="o">=</span> <span class="p">[]</span>
|
||||||
|
@ -13242,7 +13268,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 [7]:</div>
|
<div class="prompt input_prompt">In [8]:</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">channel_groups</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">channel_groups</span><span class="p">)</span>
|
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">channel_groups</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">channel_groups</span><span class="p">)</span>
|
||||||
|
@ -13255,7 +13281,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 [8]:</div>
|
<div class="prompt input_prompt">In [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">get_lim</span><span class="p">(</span><span class="n">action_id</span><span class="p">):</span>
|
<div class=" highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">get_lim</span><span class="p">(</span><span class="n">action_id</span><span class="p">):</span>
|
||||||
|
@ -13286,7 +13312,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 [9]:</div>
|
<div class="prompt input_prompt">In [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">signaltonoise</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">ddof</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
|
<div class=" highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">signaltonoise</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">ddof</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
|
||||||
|
@ -13313,7 +13339,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 [10]:</div>
|
<div class="prompt input_prompt">In [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_energy</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">compute_energy</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>
|
||||||
|
@ -13322,6 +13348,19 @@ div#notebook {
|
||||||
<span class="n">mask</span> <span class="o">=</span> <span class="p">(</span><span class="n">f</span> <span class="o">></span> <span class="n">f1</span><span class="p">)</span> <span class="o">&</span> <span class="p">(</span><span class="n">f</span> <span class="o"><</span> <span class="n">f2</span><span class="p">)</span>
|
<span class="n">mask</span> <span class="o">=</span> <span class="p">(</span><span class="n">f</span> <span class="o">></span> <span class="n">f1</span><span class="p">)</span> <span class="o">&</span> <span class="p">(</span><span class="n">f</span> <span class="o"><</span> <span class="n">f2</span><span class="p">)</span>
|
||||||
<span class="n">df</span> <span class="o">=</span> <span class="n">f</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">f</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
|
<span class="n">df</span> <span class="o">=</span> <span class="n">f</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">f</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
|
||||||
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="n">mask</span><span class="p">])</span> <span class="o">*</span> <span class="n">df</span>
|
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="n">mask</span><span class="p">])</span> <span class="o">*</span> <span class="n">df</span>
|
||||||
|
|
||||||
|
|
||||||
|
<span class="k">def</span> <span class="nf">compute_band_power</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>
|
||||||
|
<span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">isnan</span><span class="p">(</span><span class="n">f1</span><span class="p">)</span> <span class="ow">or</span> <span class="n">np</span><span class="o">.</span><span class="n">all</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">isnan</span><span class="p">(</span><span class="n">p</span><span class="p">)):</span>
|
||||||
|
<span class="k">return</span> <span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">nan</span><span class="p">]</span> <span class="o">*</span> <span class="mi">2</span>
|
||||||
|
<span class="kn">from</span> <span class="nn">scipy.integrate</span> <span class="k">import</span> <span class="n">simps</span>
|
||||||
|
<span class="n">dx</span> <span class="o">=</span> <span class="n">f</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">f</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
|
||||||
|
<span class="n">mask</span> <span class="o">=</span> <span class="p">(</span><span class="n">f</span> <span class="o">></span> <span class="n">f1</span><span class="p">)</span> <span class="o">&</span> <span class="p">(</span><span class="n">f</span> <span class="o"><</span> <span class="n">f2</span><span class="p">)</span>
|
||||||
|
<span class="c1"># Compute the absolute power by approximating the area under the curve</span>
|
||||||
|
<span class="n">band_power</span> <span class="o">=</span> <span class="n">simps</span><span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="n">mask</span><span class="p">],</span> <span class="n">dx</span><span class="o">=</span><span class="n">dx</span><span class="p">)</span>
|
||||||
|
<span class="n">total_power</span> <span class="o">=</span> <span class="n">simps</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">dx</span><span class="o">=</span><span class="n">dx</span><span class="p">)</span>
|
||||||
|
<span class="n">rel_power</span> <span class="o">=</span> <span class="n">band_power</span> <span class="o">/</span> <span class="n">total_power</span>
|
||||||
|
<span class="k">return</span> <span class="n">band_power</span><span class="p">,</span> <span class="n">rel_power</span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -13331,11 +13370,13 @@ 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 [11]:</div>
|
<div class="prompt input_prompt">In [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">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>
|
<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>
|
||||||
<span class="n">mask</span> <span class="o">=</span> <span class="p">(</span><span class="n">f</span> <span class="o">></span> <span class="mi">6</span><span class="p">)</span> <span class="o">&</span> <span class="p">(</span><span class="n">f</span> <span class="o"><</span> <span class="mi">10</span><span class="p">)</span>
|
<span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">all</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">isnan</span><span class="p">(</span><span class="n">p</span><span class="p">)):</span>
|
||||||
|
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">nan</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">nan</span>
|
||||||
|
<span class="n">mask</span> <span class="o">=</span> <span class="p">(</span><span class="n">f</span> <span class="o">></span> <span class="n">f1</span><span class="p">)</span> <span class="o">&</span> <span class="p">(</span><span class="n">f</span> <span class="o"><</span> <span class="n">f2</span><span class="p">)</span>
|
||||||
<span class="n">p_m</span> <span class="o">=</span> <span class="n">p</span><span class="p">[</span><span class="n">mask</span><span class="p">]</span>
|
<span class="n">p_m</span> <span class="o">=</span> <span class="n">p</span><span class="p">[</span><span class="n">mask</span><span class="p">]</span>
|
||||||
<span class="n">f_m</span> <span class="o">=</span> <span class="n">f</span><span class="p">[</span><span class="n">mask</span><span class="p">]</span>
|
<span class="n">f_m</span> <span class="o">=</span> <span class="n">f</span><span class="p">[</span><span class="n">mask</span><span class="p">]</span>
|
||||||
<span class="n">peaks</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">find_peaks</span><span class="p">(</span><span class="n">p_m</span><span class="p">)</span>
|
<span class="n">peaks</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">find_peaks</span><span class="p">(</span><span class="n">p_m</span><span class="p">)</span>
|
||||||
|
@ -13350,52 +13391,40 @@ 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 [12]:</div>
|
<div class="prompt input_prompt">In [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="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">power</span><span class="p">,</span> <span class="n">freq</span><span class="p">,</span> <span class="n">max_power</span><span class="p">,</span> <span class="n">max_frequency</span><span class="p">,</span> <span class="n">band</span><span class="p">,</span> <span class="n">band_width</span><span class="o">=</span><span class="mi">1</span><span class="p">):</span>
|
||||||
<span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">isnan</span><span class="p">(</span><span class="n">m_p</span><span class="p">):</span>
|
<span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">isnan</span><span class="p">(</span><span class="n">max_power</span><span class="p">):</span>
|
||||||
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">nan</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">nan</span>
|
<span class="k">return</span> <span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">nan</span><span class="p">]</span> <span class="o">*</span> <span class="mi">3</span>
|
||||||
|
|
||||||
|
<span class="c1"># estimate baseline power</span>
|
||||||
|
<span class="n">low_baseline_mask</span> <span class="o">=</span> <span class="p">(</span><span class="n">freq</span> <span class="o">></span> <span class="n">band</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">band_width</span><span class="p">)</span> <span class="o">&</span> <span class="p">(</span><span class="n">freq</span> <span class="o"><</span> <span class="n">band</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
|
||||||
|
<span class="n">high_baseline_mask</span> <span class="o">=</span> <span class="p">(</span><span class="n">freq</span> <span class="o">></span> <span class="n">band</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">&</span> <span class="p">(</span><span class="n">freq</span> <span class="o"><</span> <span class="n">band</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">band_width</span><span class="p">)</span>
|
||||||
|
<span class="n">baseline</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">([</span><span class="n">power</span><span class="p">[</span><span class="n">low_baseline_mask</span><span class="p">],</span> <span class="n">power</span><span class="p">[</span><span class="n">high_baseline_mask</span><span class="p">]]))</span>
|
||||||
|
<span class="n">p</span> <span class="o">=</span> <span class="n">power</span> <span class="o">-</span> <span class="n">baseline</span>
|
||||||
|
<span class="n">m_p</span> <span class="o">=</span> <span class="n">max_power</span> <span class="o">-</span> <span class="n">baseline</span>
|
||||||
|
<span class="n">m_f</span> <span class="o">=</span> <span class="n">max_frequency</span>
|
||||||
|
<span class="n">f</span> <span class="o">=</span> <span class="n">freq</span>
|
||||||
|
|
||||||
|
<span class="c1"># estimate half width</span>
|
||||||
<span class="n">m_p_half</span> <span class="o">=</span> <span class="n">m_p</span> <span class="o">/</span> <span class="mi">2</span>
|
<span class="n">m_p_half</span> <span class="o">=</span> <span class="n">m_p</span> <span class="o">/</span> <span class="mi">2</span>
|
||||||
<span class="n">half_p</span> <span class="o">=</span> <span class="n">p</span> <span class="o">-</span> <span class="n">m_p_half</span>
|
<span class="n">half_p</span> <span class="o">=</span> <span class="n">p</span> <span class="o">-</span> <span class="n">m_p_half</span>
|
||||||
<span class="n">idx_f</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">f</span> <span class="o"><=</span> <span class="n">m_f</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">max</span><span class="p">()</span>
|
<span class="n">idx_f</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">f</span> <span class="o"><=</span> <span class="n">m_f</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">max</span><span class="p">()</span>
|
||||||
<span class="n">idxs_p1</span><span class="p">,</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">half_p</span><span class="p">[:</span><span class="n">idx_f</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span> <span class="o">></span> <span class="mi">0</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)</span>
|
<span class="n">idxs_p1</span><span class="p">,</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">half_p</span><span class="p">[:</span><span class="n">idx_f</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span> <span class="o">></span> <span class="mi">0</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)</span>
|
||||||
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">idxs_p1</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
|
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">idxs_p1</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
|
||||||
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">nan</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">nan</span>
|
<span class="k">return</span> <span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">nan</span><span class="p">]</span> <span class="o">*</span> <span class="mi">3</span>
|
||||||
<span class="n">m1</span> <span class="o">=</span> <span class="n">idxs_p1</span><span class="o">.</span><span class="n">max</span><span class="p">()</span>
|
<span class="n">m1</span> <span class="o">=</span> <span class="n">idxs_p1</span><span class="o">.</span><span class="n">max</span><span class="p">()</span>
|
||||||
<span class="n">idxs_p2</span><span class="p">,</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">half_p</span><span class="p">[</span><span class="n">idx_f</span><span class="p">:]</span> <span class="o">></span> <span class="mi">0</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)</span>
|
<span class="n">idxs_p2</span><span class="p">,</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">half_p</span><span class="p">[</span><span class="n">idx_f</span><span class="p">:]</span> <span class="o">></span> <span class="mi">0</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)</span>
|
||||||
|
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">idxs_p2</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
|
||||||
|
<span class="k">return</span> <span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">nan</span><span class="p">]</span> <span class="o">*</span> <span class="mi">3</span>
|
||||||
<span class="n">m2</span> <span class="o">=</span> <span class="n">idxs_p2</span><span class="o">.</span><span class="n">min</span><span class="p">()</span> <span class="o">+</span> <span class="n">idx_f</span>
|
<span class="n">m2</span> <span class="o">=</span> <span class="n">idxs_p2</span><span class="o">.</span><span class="n">min</span><span class="p">()</span> <span class="o">+</span> <span class="n">idx_f</span>
|
||||||
<span class="c1"># plt.plot(f, p)</span>
|
<span class="c1"># assert p[m1] < m_p_half < p[m1+1], (p[m1], m_p_half, p[m1+1])</span>
|
||||||
<span class="c1"># plt.plot(m_f, m_p, marker='o', ls='none', markersize=10)</span>
|
<span class="c1"># assert p[m2] > m_p_half > p[m2+1], (p[m2], m_p_half, p[m2+1])</span>
|
||||||
<span class="c1"># plt.plot(f[m1], p[m1], marker='x', ls='none', markersize=10, c='r')</span>
|
|
||||||
<span class="c1"># plt.plot(f[m1+1], p[m1+1], marker='+', ls='none', markersize=10, c='r')</span>
|
|
||||||
|
|
||||||
<span class="c1"># plt.plot(f[m2], p[m2], marker='x', ls='none', markersize=10, c='k')</span>
|
|
||||||
<span class="c1"># plt.plot(f[m2+1], p[m2+1], marker='+', ls='none', markersize=10, c='k')</span>
|
|
||||||
|
|
||||||
<span class="c1"># plt.xlim(4,12)</span>
|
|
||||||
<span class="k">assert</span> <span class="n">p</span><span class="p">[</span><span class="n">m1</span><span class="p">]</span> <span class="o"><</span> <span class="n">m_p_half</span> <span class="o"><</span> <span class="n">p</span><span class="p">[</span><span class="n">m1</span><span class="o">+</span><span class="mi">1</span><span class="p">],</span> <span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="n">m1</span><span class="p">],</span> <span class="n">m_p_half</span><span class="p">,</span> <span class="n">p</span><span class="p">[</span><span class="n">m1</span><span class="o">+</span><span class="mi">1</span><span class="p">])</span>
|
|
||||||
<span class="k">assert</span> <span class="n">p</span><span class="p">[</span><span class="n">m2</span><span class="p">]</span> <span class="o">></span> <span class="n">m_p_half</span> <span class="o">></span> <span class="n">p</span><span class="p">[</span><span class="n">m2</span><span class="o">+</span><span class="mi">1</span><span class="p">],</span> <span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="n">m2</span><span class="p">],</span> <span class="n">m_p_half</span><span class="p">,</span> <span class="n">p</span><span class="p">[</span><span class="n">m2</span><span class="o">+</span><span class="mi">1</span><span class="p">])</span>
|
|
||||||
|
|
||||||
<span class="n">f1</span> <span class="o">=</span> <span class="n">interp1d</span><span class="p">([</span><span class="n">half_p</span><span class="p">[</span><span class="n">m1</span><span class="p">],</span> <span class="n">half_p</span><span class="p">[</span><span class="n">m1</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]],</span> <span class="p">[</span><span class="n">f</span><span class="p">[</span><span class="n">m1</span><span class="p">],</span> <span class="n">f</span><span class="p">[</span><span class="n">m1</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]])(</span><span class="mi">0</span><span class="p">)</span>
|
<span class="n">f1</span> <span class="o">=</span> <span class="n">interp1d</span><span class="p">([</span><span class="n">half_p</span><span class="p">[</span><span class="n">m1</span><span class="p">],</span> <span class="n">half_p</span><span class="p">[</span><span class="n">m1</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]],</span> <span class="p">[</span><span class="n">f</span><span class="p">[</span><span class="n">m1</span><span class="p">],</span> <span class="n">f</span><span class="p">[</span><span class="n">m1</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]])(</span><span class="mi">0</span><span class="p">)</span>
|
||||||
<span class="n">f2</span> <span class="o">=</span> <span class="n">interp1d</span><span class="p">([</span><span class="n">half_p</span><span class="p">[</span><span class="n">m2</span><span class="p">],</span> <span class="n">half_p</span><span class="p">[</span><span class="n">m2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]],</span> <span class="p">[</span><span class="n">f</span><span class="p">[</span><span class="n">m2</span><span class="p">],</span> <span class="n">f</span><span class="p">[</span><span class="n">m2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]])(</span><span class="mi">0</span><span class="p">)</span>
|
<span class="n">f2</span> <span class="o">=</span> <span class="n">interp1d</span><span class="p">([</span><span class="n">half_p</span><span class="p">[</span><span class="n">m2</span><span class="p">],</span> <span class="n">half_p</span><span class="p">[</span><span class="n">m2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]],</span> <span class="p">[</span><span class="n">f</span><span class="p">[</span><span class="n">m2</span><span class="p">],</span> <span class="n">f</span><span class="p">[</span><span class="n">m2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]])(</span><span class="mi">0</span><span class="p">)</span>
|
||||||
<span class="k">return</span> <span class="n">f1</span><span class="p">,</span> <span class="n">f2</span>
|
<span class="k">return</span> <span class="n">f1</span><span class="p">,</span> <span class="n">f2</span><span class="p">,</span> <span class="n">m_p_half</span> <span class="o">+</span> <span class="n">baseline</span>
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<div class="cell border-box-sizing code_cell rendered">
|
|
||||||
<div class="input">
|
|
||||||
<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="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>
|
|
||||||
<span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">isnan</span><span class="p">(</span><span class="n">s_f</span><span class="p">):</span>
|
|
||||||
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">nan</span>
|
|
||||||
<span class="k">return</span> <span class="n">interp1d</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">p</span><span class="p">)(</span><span class="n">s_f</span><span class="p">)</span>
|
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -13408,8 +13437,18 @@ div#notebook {
|
||||||
<div class="prompt input_prompt">In [14]:</div>
|
<div class="prompt input_prompt">In [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">10000</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>
|
||||||
<span class="n">theta_band_f1</span><span class="p">,</span> <span class="n">theta_band_f2</span> <span class="o">=</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">10</span>
|
<span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">isnan</span><span class="p">(</span><span class="n">s_f</span><span class="p">):</span>
|
||||||
|
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">nan</span>
|
||||||
|
<span class="k">return</span> <span class="n">interp1d</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">p</span><span class="p">)(</span><span class="n">s_f</span><span class="p">)</span>
|
||||||
|
|
||||||
|
|
||||||
|
<span class="k">def</span> <span class="nf">compute_relative_peak</span><span class="p">(</span><span class="n">power</span><span class="p">,</span> <span class="n">freq</span><span class="p">,</span> <span class="n">max_power</span><span class="p">,</span> <span class="n">band</span><span class="p">,</span> <span class="n">band_width</span><span class="o">=</span><span class="mi">1</span><span class="p">):</span>
|
||||||
|
<span class="c1"># estimate baseline power</span>
|
||||||
|
<span class="n">low_baseline_mask</span> <span class="o">=</span> <span class="p">(</span><span class="n">freq</span> <span class="o">></span> <span class="n">band</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">band_width</span><span class="p">)</span> <span class="o">&</span> <span class="p">(</span><span class="n">freq</span> <span class="o"><</span> <span class="n">band</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
|
||||||
|
<span class="n">high_baseline_mask</span> <span class="o">=</span> <span class="p">(</span><span class="n">freq</span> <span class="o">></span> <span class="n">band</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">&</span> <span class="p">(</span><span class="n">freq</span> <span class="o"><</span> <span class="n">band</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">band_width</span><span class="p">)</span>
|
||||||
|
<span class="n">baseline</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">([</span><span class="n">power</span><span class="p">[</span><span class="n">low_baseline_mask</span><span class="p">],</span> <span class="n">power</span><span class="p">[</span><span class="n">high_baseline_mask</span><span class="p">]]))</span>
|
||||||
|
<span class="k">return</span> <span class="p">(</span><span class="n">max_power</span> <span class="o">-</span> <span class="n">baseline</span><span class="p">)</span> <span class="o">/</span> <span class="nb">abs</span><span class="p">(</span><span class="n">baseline</span><span class="p">)</span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -13419,12 +13458,28 @@ 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 [15]:</div>
|
<div class="prompt input_prompt">In [ ]:</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="n">theta_band_f1</span><span class="p">,</span> <span class="n">theta_band_f2</span> <span class="o">=</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">10</span>
|
||||||
|
</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="inner_cell">
|
||||||
|
<div class="input_area">
|
||||||
|
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">psd_data</span><span class="p">,</span> <span class="n">freq_data</span> <span class="o">=</span> <span class="p">{},</span> <span class="p">{}</span>
|
||||||
|
|
||||||
|
<span class="k">def</span> <span class="nf">process</span><span class="p">(</span><span class="n">row</span><span class="p">,</span> <span class="n">perform_zscore</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">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">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">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="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="n">clean_lfp</span> <span class="o">=</span> <span class="n">select_and_clean</span><span class="p">(</span><span class="n">lfp</span><span class="p">)</span>
|
<span class="n">clean_lfp</span> <span class="o">=</span> <span class="n">select_and_clean</span><span class="p">(</span><span class="n">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">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>
|
||||||
|
@ -13434,19 +13489,30 @@ div#notebook {
|
||||||
<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">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">mask</span> <span class="o">=</span> <span class="n">get_mask</span><span class="p">(</span><span class="n">lfp</span><span class="p">,</span> <span class="n">lim</span><span class="p">)</span>
|
<span class="n">mask</span> <span class="o">=</span> <span class="n">get_mask</span><span class="p">(</span><span class="n">lfp</span><span class="p">,</span> <span class="n">lim</span><span class="p">)</span>
|
||||||
<span class="n">signal</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">mask</span><span class="p">,</span> <span class="n">best_channel</span><span class="p">]</span><span class="o">.</span><span class="n">ravel</span><span class="p">())</span>
|
<span class="k">if</span> <span class="n">perform_zscore</span><span class="p">:</span>
|
||||||
|
<span class="n">signal</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">mask</span><span class="p">,</span> <span class="n">best_channel</span><span class="p">]</span><span class="o">.</span><span class="n">ravel</span><span class="p">())</span>
|
||||||
|
<span class="k">else</span><span class="p">:</span>
|
||||||
|
<span class="n">signal</span> <span class="o">=</span> <span class="n">clean_lfp</span><span class="p">[</span><span class="n">mask</span><span class="p">,</span> <span class="n">best_channel</span><span class="p">]</span><span class="o">.</span><span class="n">ravel</span><span class="p">()</span>
|
||||||
|
|
||||||
<span class="n">p_xx</span><span class="p">,</span> <span class="n">freq</span> <span class="o">=</span> <span class="n">mlab</span><span class="o">.</span><span class="n">psd</span><span class="p">(</span><span class="n">signal</span><span class="p">,</span> <span class="n">Fs</span><span class="o">=</span><span class="n">lfp</span><span class="o">.</span><span class="n">sampling_rate</span><span class="o">.</span><span class="n">magnitude</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">window</span> <span class="o">=</span> <span class="mi">6</span> <span class="o">*</span> <span class="n">lfp</span><span class="o">.</span><span class="n">sampling_rate</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_xx</span><span class="p">,</span> <span class="n">freq</span><span class="p">)</span>
|
<span class="c1"># p_xx, freq = mlab.psd(signal, Fs=lfp.sampling_rate.magnitude, NFFT=NFFT)</span>
|
||||||
|
<span class="n">freq</span><span class="p">,</span> <span class="n">p_xx</span> <span class="o">=</span> <span class="n">ss</span><span class="o">.</span><span class="n">welch</span><span class="p">(</span><span class="n">signal</span><span class="p">,</span> <span class="n">fs</span><span class="o">=</span><span class="n">lfp</span><span class="o">.</span><span class="n">sampling_rate</span><span class="o">.</span><span class="n">magnitude</span><span class="p">,</span> <span class="n">nperseg</span><span class="o">=</span><span class="n">window</span><span class="p">,</span> <span class="n">nfft</span><span class="o">=</span><span class="n">scipy</span><span class="o">.</span><span class="n">fftpack</span><span class="o">.</span><span class="n">next_fast_len</span><span class="p">(</span><span class="n">window</span><span class="p">))</span>
|
||||||
|
<span class="n">p_xx</span> <span class="o">=</span> <span class="mi">10</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">log10</span><span class="p">(</span><span class="n">p_xx</span><span class="p">)</span>
|
||||||
|
|
||||||
<span class="n">theta_energy</span> <span class="o">=</span> <span class="n">compute_energy</span><span class="p">(</span><span class="n">p_xx</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="c1"># theta band 6 - 10 Hz</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_xx</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_half_f1</span><span class="p">,</span> <span class="n">theta_half_f2</span> <span class="o">=</span> <span class="n">compute_half_width</span><span class="p">(</span><span class="n">p_xx</span><span class="p">,</span> <span class="n">freq</span><span class="p">,</span> <span class="n">theta_p_max</span><span class="p">,</span> <span class="n">theta_f</span><span class="p">)</span>
|
<span class="n">theta_bandpower</span><span class="p">,</span> <span class="n">theta_relpower</span> <span class="o">=</span> <span class="n">compute_band_power</span><span class="p">(</span><span class="n">p_xx</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_relpeak</span> <span class="o">=</span> <span class="n">compute_relative_peak</span><span class="p">(</span><span class="n">p_xx</span><span class="p">,</span> <span class="n">freq</span><span class="p">,</span> <span class="n">theta_p_max</span><span class="p">,</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_half_f1</span><span class="p">,</span> <span class="n">theta_half_f2</span><span class="p">,</span> <span class="n">theta_half_power</span> <span class="o">=</span> <span class="n">compute_half_width</span><span class="p">(</span><span class="n">p_xx</span><span class="p">,</span> <span class="n">freq</span><span class="p">,</span> <span class="n">theta_p_max</span><span class="p">,</span> <span class="n">theta_f</span><span class="p">,</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_half_width</span> <span class="o">=</span> <span class="n">theta_half_f2</span> <span class="o">-</span> <span class="n">theta_half_f1</span>
|
<span class="n">theta_half_width</span> <span class="o">=</span> <span class="n">theta_half_f2</span> <span class="o">-</span> <span class="n">theta_half_f1</span>
|
||||||
|
|
||||||
<span class="n">theta_half_energy</span> <span class="o">=</span> <span class="n">compute_energy</span><span class="p">(</span><span class="n">p_xx</span><span class="p">,</span> <span class="n">freq</span><span class="p">,</span> <span class="n">theta_half_f1</span><span class="p">,</span> <span class="n">theta_half_f2</span><span class="p">)</span> <span class="c1"># theta band 6 - 10 Hz</span>
|
<span class="n">psd_data</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_xx</span><span class="p">})</span>
|
||||||
|
<span class="n">freq_data</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>
|
||||||
|
|
||||||
|
|
||||||
<span class="c1"># stim</span>
|
<span class="c1"># stim</span>
|
||||||
|
|
||||||
|
@ -13454,27 +13520,33 @@ div#notebook {
|
||||||
|
|
||||||
<span class="n">stim_p_max</span> <span class="o">=</span> <span class="n">compute_stim_peak</span><span class="p">(</span><span class="n">p_xx</span><span class="p">,</span> <span class="n">freq</span><span class="p">,</span> <span class="n">stim_freq</span><span class="p">)</span>
|
<span class="n">stim_p_max</span> <span class="o">=</span> <span class="n">compute_stim_peak</span><span class="p">(</span><span class="n">p_xx</span><span class="p">,</span> <span class="n">freq</span><span class="p">,</span> <span class="n">stim_freq</span><span class="p">)</span>
|
||||||
|
|
||||||
<span class="n">stim_half_f1</span><span class="p">,</span> <span class="n">stim_half_f2</span> <span class="o">=</span> <span class="n">compute_half_width</span><span class="p">(</span><span class="n">p_xx</span><span class="p">,</span> <span class="n">freq</span><span class="p">,</span> <span class="n">stim_p_max</span><span class="p">,</span> <span class="n">stim_freq</span><span class="p">)</span>
|
<span class="n">stim_half_f1</span><span class="p">,</span> <span class="n">stim_half_f2</span><span class="p">,</span> <span class="n">stim_half_power</span> <span class="o">=</span> <span class="n">compute_half_width</span><span class="p">(</span><span class="n">p_xx</span><span class="p">,</span> <span class="n">freq</span><span class="p">,</span> <span class="n">stim_p_max</span><span class="p">,</span> <span class="n">stim_freq</span><span class="p">,</span> <span class="p">[</span><span class="n">stim_freq</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="n">stim_freq</span> <span class="o">+</span> <span class="mi">1</span><span class="p">])</span>
|
||||||
|
|
||||||
<span class="n">stim_half_width</span> <span class="o">=</span> <span class="n">stim_half_f2</span> <span class="o">-</span> <span class="n">stim_half_f1</span>
|
<span class="n">stim_half_width</span> <span class="o">=</span> <span class="n">stim_half_f2</span> <span class="o">-</span> <span class="n">stim_half_f1</span>
|
||||||
|
|
||||||
<span class="n">stim_energy</span> <span class="o">=</span> <span class="n">compute_energy</span><span class="p">(</span><span class="n">p_xx</span><span class="p">,</span> <span class="n">freq</span><span class="p">,</span> <span class="n">stim_half_f1</span><span class="p">,</span> <span class="n">stim_half_f2</span><span class="p">)</span>
|
<span class="n">stim_bandpower</span><span class="p">,</span> <span class="n">stim_relpower</span> <span class="o">=</span> <span class="n">compute_band_power</span><span class="p">(</span><span class="n">p_xx</span><span class="p">,</span> <span class="n">freq</span><span class="p">,</span> <span class="n">stim_freq</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="n">stim_freq</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
|
||||||
|
|
||||||
|
<span class="n">stim_relpeak</span> <span class="o">=</span> <span class="n">compute_relative_peak</span><span class="p">(</span><span class="n">p_xx</span><span class="p">,</span> <span class="n">freq</span><span class="p">,</span> <span class="n">stim_p_max</span><span class="p">,</span> <span class="p">[</span><span class="n">stim_freq</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="n">stim_freq</span> <span class="o">+</span> <span class="mi">1</span><span class="p">])</span>
|
||||||
|
|
||||||
<span class="n">result</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">Series</span><span class="p">({</span>
|
<span class="n">result</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">Series</span><span class="p">({</span>
|
||||||
<span class="s1">'signal_to_noise'</span><span class="p">:</span> <span class="n">snl</span><span class="p">,</span>
|
<span class="s1">'signal_to_noise'</span><span class="p">:</span> <span class="n">snl</span><span class="p">,</span>
|
||||||
<span class="s1">'best_channel'</span><span class="p">:</span> <span class="n">best_channel</span><span class="p">,</span>
|
<span class="s1">'best_channel'</span><span class="p">:</span> <span class="n">best_channel</span><span class="p">,</span>
|
||||||
<span class="s1">'theta_freq'</span><span class="p">:</span> <span class="n">theta_f</span><span class="p">,</span>
|
<span class="s1">'theta_freq'</span><span class="p">:</span> <span class="n">theta_f</span><span class="p">,</span>
|
||||||
<span class="s1">'theta_peak'</span><span class="p">:</span> <span class="n">theta_p_max</span><span class="p">,</span>
|
<span class="s1">'theta_peak'</span><span class="p">:</span> <span class="n">theta_p_max</span><span class="p">,</span>
|
||||||
<span class="s1">'theta_energy'</span><span class="p">:</span> <span class="n">theta_energy</span><span class="p">,</span>
|
<span class="s1">'theta_bandpower'</span><span class="p">:</span> <span class="n">theta_bandpower</span><span class="p">,</span>
|
||||||
|
<span class="s1">'theta_relpower'</span><span class="p">:</span> <span class="n">theta_relpower</span><span class="p">,</span>
|
||||||
|
<span class="s1">'theta_relpeak'</span><span class="p">:</span> <span class="n">theta_relpeak</span><span class="p">,</span>
|
||||||
<span class="s1">'theta_half_f1'</span><span class="p">:</span> <span class="n">theta_half_f1</span><span class="p">,</span>
|
<span class="s1">'theta_half_f1'</span><span class="p">:</span> <span class="n">theta_half_f1</span><span class="p">,</span>
|
||||||
<span class="s1">'theta_half_f2'</span><span class="p">:</span> <span class="n">theta_half_f2</span><span class="p">,</span>
|
<span class="s1">'theta_half_f2'</span><span class="p">:</span> <span class="n">theta_half_f2</span><span class="p">,</span>
|
||||||
<span class="s1">'theta_half_width'</span><span class="p">:</span> <span class="n">theta_half_width</span><span class="p">,</span>
|
<span class="s1">'theta_half_width'</span><span class="p">:</span> <span class="n">theta_half_width</span><span class="p">,</span>
|
||||||
<span class="s1">'theta_half_energy'</span><span class="p">:</span> <span class="n">theta_half_energy</span><span class="p">,</span>
|
|
||||||
<span class="s1">'stim_freq'</span><span class="p">:</span> <span class="n">stim_freq</span><span class="p">,</span>
|
<span class="s1">'stim_freq'</span><span class="p">:</span> <span class="n">stim_freq</span><span class="p">,</span>
|
||||||
<span class="s1">'stim_p_max'</span><span class="p">:</span> <span class="n">stim_p_max</span><span class="p">,</span>
|
<span class="s1">'stim_p_max'</span><span class="p">:</span> <span class="n">stim_p_max</span><span class="p">,</span>
|
||||||
<span class="s1">'stim_half_f1'</span><span class="p">:</span> <span class="n">stim_half_f1</span><span class="p">,</span>
|
<span class="s1">'stim_half_f1'</span><span class="p">:</span> <span class="n">stim_half_f1</span><span class="p">,</span>
|
||||||
<span class="s1">'stim_half_f2'</span><span class="p">:</span> <span class="n">stim_half_f2</span><span class="p">,</span>
|
<span class="s1">'stim_half_f2'</span><span class="p">:</span> <span class="n">stim_half_f2</span><span class="p">,</span>
|
||||||
<span class="s1">'stim_half_width'</span><span class="p">:</span> <span class="n">stim_half_width</span><span class="p">,</span>
|
<span class="s1">'stim_half_width'</span><span class="p">:</span> <span class="n">stim_half_width</span><span class="p">,</span>
|
||||||
<span class="s1">'stim_energy'</span><span class="p">:</span> <span class="n">stim_energy</span>
|
<span class="s1">'stim_bandpower'</span><span class="p">:</span> <span class="n">stim_bandpower</span><span class="p">,</span>
|
||||||
|
<span class="s1">'stim_relpower'</span><span class="p">:</span> <span class="n">stim_relpower</span><span class="p">,</span>
|
||||||
|
<span class="s1">'stim_relpeak'</span><span class="p">:</span> <span class="n">stim_relpeak</span><span class="p">,</span>
|
||||||
<span class="p">})</span>
|
<span class="p">})</span>
|
||||||
<span class="k">return</span> <span class="n">result</span>
|
<span class="k">return</span> <span class="n">result</span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
@ -13486,11 +13558,11 @@ 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 [16]:</div>
|
<div class="prompt input_prompt">In [ ]:</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">channel_groups</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">channel_groups</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span>
|
||||||
<span class="n">channel_groups</span><span class="o">.</span><span class="n">progress_apply</span><span class="p">(</span><span class="n">process</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">),</span>
|
<span class="n">channel_groups</span><span class="o">.</span><span class="n">progress_apply</span><span class="p">(</span><span class="n">process</span><span class="p">,</span> <span class="n">perform_zscore</span><span class="o">=</span><span class="n">perform_zscore</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">),</span>
|
||||||
<span class="n">left_index</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">right_index</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
|
<span class="n">left_index</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">right_index</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
|
@ -13512,13 +13584,13 @@ div#notebook {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="ccdb069e-4b63-4db1-9535-31624e57bc0e"></div>
|
<div id="1e0ab9a5-d5fa-41a2-82b4-a29075688ad9"></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 = $('#ccdb069e-4b63-4db1-9535-31624e57bc0e');
|
var element = $('#1e0ab9a5-d5fa-41a2-82b4-a29075688ad9');
|
||||||
</script>
|
</script>
|
||||||
<script type="application/vnd.jupyter.widget-view+json">
|
<script type="application/vnd.jupyter.widget-view+json">
|
||||||
{"model_id": "e733903bb8d7406ea6c05bf5af093bfc", "version_major": 2, "version_minor": 0}
|
{"model_id": "0a39fef20b724ef186ce6ce5299b3719", "version_major": 2, "version_minor": 0}
|
||||||
</script>
|
</script>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -13529,8 +13601,19 @@ var element = $('#ccdb069e-4b63-4db1-9535-31624e57bc0e');
|
||||||
<div class="prompt"></div>
|
<div class="prompt"></div>
|
||||||
|
|
||||||
|
|
||||||
<div class="output_subarea output_stream output_stdout output_text">
|
<div class="output_subarea output_stream output_stderr output_text">
|
||||||
<pre>
|
<pre>/home/mikkel/.virtualenvs/expipe/lib/python3.6/site-packages/ipykernel_launcher.py:9: RuntimeWarning: invalid value encountered in greater
|
||||||
|
if __name__ == '__main__':
|
||||||
|
/home/mikkel/.virtualenvs/expipe/lib/python3.6/site-packages/ipykernel_launcher.py:9: RuntimeWarning: invalid value encountered in less
|
||||||
|
if __name__ == '__main__':
|
||||||
|
/home/mikkel/.virtualenvs/expipe/lib/python3.6/site-packages/ipykernel_launcher.py:10: RuntimeWarning: invalid value encountered in greater
|
||||||
|
# Remove the CWD from sys.path while we load stuff.
|
||||||
|
/home/mikkel/.virtualenvs/expipe/lib/python3.6/site-packages/ipykernel_launcher.py:10: RuntimeWarning: invalid value encountered in less
|
||||||
|
# Remove the CWD from sys.path while we load stuff.
|
||||||
|
/home/mikkel/.virtualenvs/expipe/lib/python3.6/site-packages/numpy/core/fromnumeric.py:3257: RuntimeWarning: Mean of empty slice.
|
||||||
|
out=out, **kwargs)
|
||||||
|
/home/mikkel/.virtualenvs/expipe/lib/python3.6/site-packages/numpy/core/_methods.py:161: RuntimeWarning: invalid value encountered in true_divide
|
||||||
|
ret = ret.dtype.type(ret / rcount)
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -13541,112 +13624,17 @@ var element = $('#ccdb069e-4b63-4db1-9535-31624e57bc0e');
|
||||||
</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 [17]:</div>
|
<div class="prompt input_prompt">In [ ]:</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">psd</span><span class="p">,</span> <span class="n">freqs</span> <span class="o">=</span> <span class="p">{},</span> <span class="p">{}</span>
|
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">psd_data</span><span class="p">)</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">'psd.feather'</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">channel_groups</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">channel_groups</span><span class="p">)):</span>
|
<span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">freq_data</span><span class="p">)</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>
|
||||||
<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">action_group</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="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">clean_lfp</span> <span class="o">=</span> <span class="n">select_and_clean</span><span class="p">(</span><span class="n">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">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">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">mask</span> <span class="o">=</span> <span class="n">get_mask</span><span class="p">(</span><span class="n">lfp</span><span class="p">,</span> <span class="n">lim</span><span class="p">)</span>
|
|
||||||
<span class="n">signal</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">mask</span><span class="p">,</span> <span class="n">best_channel</span><span class="p">]</span><span class="o">.</span><span class="n">ravel</span><span class="p">())</span>
|
|
||||||
|
|
||||||
<span class="n">p_xx</span><span class="p">,</span> <span class="n">freq</span> <span class="o">=</span> <span class="n">mlab</span><span class="o">.</span><span class="n">psd</span><span class="p">(</span><span class="n">signal</span><span class="p">,</span> <span class="n">Fs</span><span class="o">=</span><span class="n">lfp</span><span class="o">.</span><span class="n">sampling_rate</span><span class="o">.</span><span class="n">magnitude</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">psd</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="n">action_group</span><span class="p">:</span> <span class="n">p_xx</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">action_group</span><span class="p">:</span> <span class="n">freq</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 id="6a05ea1e-3782-40af-8458-e7713b9c2fb7"></div>
|
|
||||||
<div class="output_subarea output_widget_view ">
|
|
||||||
<script type="text/javascript">
|
|
||||||
var element = $('#6a05ea1e-3782-40af-8458-e7713b9c2fb7');
|
|
||||||
</script>
|
|
||||||
<script type="application/vnd.jupyter.widget-view+json">
|
|
||||||
{"model_id": "0184251a265a40a2a1e9910405f05db8", "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 [18]:</div>
|
|
||||||
<div class="inner_cell">
|
|
||||||
<div class="input_area">
|
|
||||||
<div class=" highlight hl-ipython3"><pre><span></span><span class="p">(</span><span class="n">psd</span><span class="p">)</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">'psd.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-7660e1d3307d></span> in <span class="ansi-cyan-fg"><module></span>
|
|
||||||
<span class="ansi-green-fg">----> 1</span><span class="ansi-red-fg"> </span>psd<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">'psd.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>
|
||||||
<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">
|
||||||
|
@ -13660,7 +13648,7 @@ var element = $('#6a05ea1e-3782-40af-8458-e7713b9c2fb7');
|
||||||
<div class="prompt input_prompt">In [ ]:</div>
|
<div class="prompt input_prompt">In [ ]:</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">action</span> <span class="o">=</span> <span class="n">project</span><span class="o">.</span><span class="n">require_action</span><span class="p">(</span><span class="s2">"stimulus-lfp-response"</span><span class="p">)</span>
|
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">action</span> <span class="o">=</span> <span class="n">project</span><span class="o">.</span><span class="n">require_action</span><span class="p">(</span><span class="s2">"stimulus-lfp-response"</span> <span class="o">+</span> <span class="n">zscore_str</span><span class="p">)</span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -13674,7 +13662,7 @@ var element = $('#6a05ea1e-3782-40af-8458-e7713b9c2fb7');
|
||||||
<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">action</span><span class="o">.</span><span class="n">modules</span><span class="p">[</span><span class="s1">'parameters'</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span>
|
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">action</span><span class="o">.</span><span class="n">modules</span><span class="p">[</span><span class="s1">'parameters'</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span>
|
||||||
<span class="s1">'NFFT'</span><span class="p">:</span> <span class="n">NFFT</span><span class="p">,</span>
|
<span class="s1">'window'</span><span class="p">:</span> <span class="mi">6</span><span class="p">,</span>
|
||||||
<span class="s1">'theta_band_f1'</span><span class="p">:</span> <span class="n">theta_band_f1</span><span class="p">,</span>
|
<span class="s1">'theta_band_f1'</span><span class="p">:</span> <span class="n">theta_band_f1</span><span class="p">,</span>
|
||||||
<span class="s1">'theta_band_f2'</span><span class="p">:</span> <span class="n">theta_band_f2</span>
|
<span class="s1">'theta_band_f2'</span><span class="p">:</span> <span class="n">theta_band_f2</span>
|
||||||
<span class="p">}</span>
|
<span class="p">}</span>
|
||||||
|
|
|
@ -19,7 +19,9 @@
|
||||||
"name": "stderr",
|
"name": "stderr",
|
||||||
"output_type": "stream",
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"10:26:07 [I] klustakwik KlustaKwik2 version 0.2.6\n"
|
"19:43:24 [I] klustakwik KlustaKwik2 version 0.2.6\n",
|
||||||
|
"/home/mikkel/.virtualenvs/expipe/lib/python3.6/site-packages/ipykernel_launcher.py:24: TqdmDeprecationWarning: This function will be removed in tqdm==5.0.0\n",
|
||||||
|
"Please use `tqdm.notebook.*` instead of `tqdm._tqdm_notebook.*`\n"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -39,6 +41,8 @@
|
||||||
"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",
|
||||||
|
"import scipy\n",
|
||||||
|
"import scipy.signal as ss\n",
|
||||||
"\n",
|
"\n",
|
||||||
"from scipy.signal import find_peaks\n",
|
"from scipy.signal import find_peaks\n",
|
||||||
"from scipy.interpolate import interp1d\n",
|
"from scipy.interpolate import interp1d\n",
|
||||||
|
@ -66,8 +70,16 @@
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"output = pathlib.Path('output/stimulus-lfp-response')\n",
|
"#############################\n",
|
||||||
"(output / 'data').mkdir(parents=True, exist_ok=True)"
|
"\n",
|
||||||
|
"perform_zscore = True\n",
|
||||||
|
"\n",
|
||||||
|
"if not perform_zscore:\n",
|
||||||
|
" zscore_str = \"-no-zscore\"\n",
|
||||||
|
"else:\n",
|
||||||
|
" zscore_str = \"\"\n",
|
||||||
|
"\n",
|
||||||
|
"#################################"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -75,6 +87,16 @@
|
||||||
"execution_count": 5,
|
"execution_count": 5,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"output = pathlib.Path('output/stimulus-lfp-response' + zscore_str)\n",
|
||||||
|
"(output / 'data').mkdir(parents=True, exist_ok=True)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 6,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"identify_neurons = actions['identify-neurons']\n",
|
"identify_neurons = actions['identify-neurons']\n",
|
||||||
"sessions = pd.read_csv(identify_neurons.data_path('sessions'))"
|
"sessions = pd.read_csv(identify_neurons.data_path('sessions'))"
|
||||||
|
@ -82,7 +104,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 6,
|
"execution_count": 7,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
|
@ -95,7 +117,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 7,
|
"execution_count": 8,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
|
@ -104,7 +126,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 8,
|
"execution_count": 9,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
|
@ -131,7 +153,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 9,
|
"execution_count": 10,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
|
@ -154,7 +176,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 10,
|
"execution_count": 11,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
|
@ -163,17 +185,32 @@
|
||||||
" return np.nan\n",
|
" return np.nan\n",
|
||||||
" mask = (f > f1) & (f < f2)\n",
|
" mask = (f > f1) & (f < f2)\n",
|
||||||
" df = f[1] - f[0]\n",
|
" df = f[1] - f[0]\n",
|
||||||
" return np.sum(p[mask]) * df"
|
" return np.sum(p[mask]) * df\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"def compute_band_power(p, f, f1, f2):\n",
|
||||||
|
" if np.isnan(f1) or np.all(np.isnan(p)):\n",
|
||||||
|
" return [np.nan] * 2\n",
|
||||||
|
" from scipy.integrate import simps\n",
|
||||||
|
" dx = f[1] - f[0]\n",
|
||||||
|
" mask = (f > f1) & (f < f2)\n",
|
||||||
|
" # Compute the absolute power by approximating the area under the curve\n",
|
||||||
|
" band_power = simps(p[mask], dx=dx)\n",
|
||||||
|
" total_power = simps(p, dx=dx)\n",
|
||||||
|
" rel_power = band_power / total_power\n",
|
||||||
|
" return band_power, rel_power"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 11,
|
"execution_count": 12,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"def find_theta_peak(p, f):\n",
|
"def find_theta_peak(p, f, f1, f2):\n",
|
||||||
" mask = (f > 6) & (f < 10)\n",
|
" if np.all(np.isnan(p)):\n",
|
||||||
|
" return np.nan, np.nan\n",
|
||||||
|
" mask = (f > f1) & (f < f2)\n",
|
||||||
" p_m = p[mask]\n",
|
" p_m = p[mask]\n",
|
||||||
" f_m = f[mask]\n",
|
" f_m = f[mask]\n",
|
||||||
" peaks, _ = find_peaks(p_m)\n",
|
" peaks, _ = find_peaks(p_m)\n",
|
||||||
|
@ -183,49 +220,41 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 12,
|
"execution_count": 13,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"def compute_half_width(p, f, m_p, m_f):\n",
|
"def compute_half_width(power, freq, max_power, max_frequency, band, band_width=1):\n",
|
||||||
" if np.isnan(m_p):\n",
|
" if np.isnan(max_power):\n",
|
||||||
" return np.nan, np.nan\n",
|
" return [np.nan] * 3\n",
|
||||||
|
" \n",
|
||||||
|
" # estimate baseline power\n",
|
||||||
|
" low_baseline_mask = (freq > band[0] - band_width) & (freq < band[0])\n",
|
||||||
|
" high_baseline_mask = (freq > band[1]) & (freq < band[1] + band_width)\n",
|
||||||
|
" baseline = np.mean(np.concatenate([power[low_baseline_mask], power[high_baseline_mask]]))\n",
|
||||||
|
" p = power - baseline\n",
|
||||||
|
" m_p = max_power - baseline\n",
|
||||||
|
" m_f = max_frequency\n",
|
||||||
|
" f = freq\n",
|
||||||
|
" \n",
|
||||||
|
" # estimate half width\n",
|
||||||
" m_p_half = m_p / 2\n",
|
" m_p_half = m_p / 2\n",
|
||||||
" half_p = p - m_p_half\n",
|
" half_p = p - m_p_half\n",
|
||||||
" idx_f = np.where(f <= m_f)[0].max()\n",
|
" idx_f = np.where(f <= m_f)[0].max()\n",
|
||||||
" idxs_p1, = np.where(np.diff(half_p[:idx_f + 1] > 0) == 1)\n",
|
" idxs_p1, = np.where(np.diff(half_p[:idx_f + 1] > 0) == 1)\n",
|
||||||
" if len(idxs_p1) == 0:\n",
|
" if len(idxs_p1) == 0:\n",
|
||||||
" return np.nan, np.nan\n",
|
" return [np.nan] * 3\n",
|
||||||
" m1 = idxs_p1.max()\n",
|
" m1 = idxs_p1.max()\n",
|
||||||
" idxs_p2, = np.where(np.diff(half_p[idx_f:] > 0) == 1)\n",
|
" idxs_p2, = np.where(np.diff(half_p[idx_f:] > 0) == 1)\n",
|
||||||
" m2 = idxs_p2.min() + idx_f \n",
|
" if len(idxs_p2) == 0:\n",
|
||||||
"# plt.plot(f, p)\n",
|
" return [np.nan] * 3\n",
|
||||||
"# plt.plot(m_f, m_p, marker='o', ls='none', markersize=10)\n",
|
" m2 = idxs_p2.min() + idx_f\n",
|
||||||
"# plt.plot(f[m1], p[m1], marker='x', ls='none', markersize=10, c='r')\n",
|
"# assert p[m1] < m_p_half < p[m1+1], (p[m1], m_p_half, p[m1+1])\n",
|
||||||
"# plt.plot(f[m1+1], p[m1+1], marker='+', ls='none', markersize=10, c='r')\n",
|
"# assert p[m2] > m_p_half > p[m2+1], (p[m2], m_p_half, p[m2+1])\n",
|
||||||
" \n",
|
|
||||||
"# plt.plot(f[m2], p[m2], marker='x', ls='none', markersize=10, c='k')\n",
|
|
||||||
"# plt.plot(f[m2+1], p[m2+1], marker='+', ls='none', markersize=10, c='k')\n",
|
|
||||||
" \n",
|
|
||||||
"# plt.xlim(4,12)\n",
|
|
||||||
" assert p[m1] < m_p_half < p[m1+1], (p[m1], m_p_half, p[m1+1])\n",
|
|
||||||
" assert p[m2] > m_p_half > p[m2+1], (p[m2], m_p_half, p[m2+1])\n",
|
|
||||||
" \n",
|
" \n",
|
||||||
" f1 = interp1d([half_p[m1], half_p[m1 + 1]], [f[m1], f[m1 + 1]])(0)\n",
|
" f1 = interp1d([half_p[m1], half_p[m1 + 1]], [f[m1], f[m1 + 1]])(0)\n",
|
||||||
" f2 = interp1d([half_p[m2], half_p[m2 + 1]], [f[m2], f[m2 + 1]])(0)\n",
|
" f2 = interp1d([half_p[m2], half_p[m2 + 1]], [f[m2], f[m2 + 1]])(0)\n",
|
||||||
" return f1, f2"
|
" return f1, f2, m_p_half + baseline"
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": 13,
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"def compute_stim_peak(p, f, s_f):\n",
|
|
||||||
" if np.isnan(s_f):\n",
|
|
||||||
" return np.nan\n",
|
|
||||||
" return interp1d(f, p)(s_f)"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -234,19 +263,41 @@
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"NFFT = 10000\n",
|
"def compute_stim_peak(p, f, s_f):\n",
|
||||||
|
" if np.isnan(s_f):\n",
|
||||||
|
" return np.nan\n",
|
||||||
|
" return interp1d(f, p)(s_f)\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"def compute_relative_peak(power, freq, max_power, band, band_width=1):\n",
|
||||||
|
" # estimate baseline power\n",
|
||||||
|
" low_baseline_mask = (freq > band[0] - band_width) & (freq < band[0])\n",
|
||||||
|
" high_baseline_mask = (freq > band[1]) & (freq < band[1] + band_width)\n",
|
||||||
|
" baseline = np.mean(np.concatenate([power[low_baseline_mask], power[high_baseline_mask]]))\n",
|
||||||
|
" return (max_power - baseline) / abs(baseline)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
"theta_band_f1, theta_band_f2 = 6, 10 "
|
"theta_band_f1, theta_band_f2 = 6, 10 "
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 15,
|
"execution_count": null,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"def process(row):\n",
|
"psd_data, freq_data = {}, {}\n",
|
||||||
|
"\n",
|
||||||
|
"def process(row, perform_zscore):\n",
|
||||||
" action_id = row['action']\n",
|
" action_id = row['action']\n",
|
||||||
" channel_group = row['channel_group']\n",
|
" channel_group = row['channel_group']\n",
|
||||||
|
" name = f'{action_id}_{channel_group}'\n",
|
||||||
" lfp = data_loader.lfp(action_id, channel_group)\n",
|
" lfp = data_loader.lfp(action_id, channel_group)\n",
|
||||||
" clean_lfp = select_and_clean(lfp)\n",
|
" clean_lfp = select_and_clean(lfp)\n",
|
||||||
" snls = signaltonoise(clean_lfp)\n",
|
" snls = signaltonoise(clean_lfp)\n",
|
||||||
|
@ -256,19 +307,30 @@
|
||||||
" lim = get_lim(action_id)\n",
|
" lim = get_lim(action_id)\n",
|
||||||
" \n",
|
" \n",
|
||||||
" mask = get_mask(lfp, lim)\n",
|
" mask = get_mask(lfp, lim)\n",
|
||||||
" signal = zscore(clean_lfp[mask, best_channel].ravel())\n",
|
" if perform_zscore:\n",
|
||||||
|
" signal = zscore(clean_lfp[mask, best_channel].ravel())\n",
|
||||||
|
" else:\n",
|
||||||
|
" signal = clean_lfp[mask, best_channel].ravel()\n",
|
||||||
" \n",
|
" \n",
|
||||||
" p_xx, freq = mlab.psd(signal, Fs=lfp.sampling_rate.magnitude, NFFT=NFFT)\n",
|
" window = 6 * lfp.sampling_rate.magnitude\n",
|
||||||
" \n",
|
" \n",
|
||||||
" theta_f, theta_p_max = find_theta_peak(p_xx, freq)\n",
|
"# p_xx, freq = mlab.psd(signal, Fs=lfp.sampling_rate.magnitude, NFFT=NFFT)\n",
|
||||||
|
" freq, p_xx = ss.welch(signal, fs=lfp.sampling_rate.magnitude, nperseg=window, nfft=scipy.fftpack.next_fast_len(window))\n",
|
||||||
|
" p_xx = 10 * np.log10(p_xx)\n",
|
||||||
" \n",
|
" \n",
|
||||||
" theta_energy = compute_energy(p_xx, freq, theta_band_f1, theta_band_f2) # theta band 6 - 10 Hz\n",
|
" theta_f, theta_p_max = find_theta_peak(p_xx, freq, theta_band_f1, theta_band_f2)\n",
|
||||||
" \n",
|
" \n",
|
||||||
" theta_half_f1, theta_half_f2 = compute_half_width(p_xx, freq, theta_p_max, theta_f)\n",
|
" theta_bandpower, theta_relpower = compute_band_power(p_xx, freq, theta_band_f1, theta_band_f2)\n",
|
||||||
|
" \n",
|
||||||
|
" theta_relpeak = compute_relative_peak(p_xx, freq, theta_p_max, [theta_band_f1, theta_band_f2])\n",
|
||||||
|
" \n",
|
||||||
|
" theta_half_f1, theta_half_f2, theta_half_power = compute_half_width(p_xx, freq, theta_p_max, theta_f, [theta_band_f1, theta_band_f2])\n",
|
||||||
" \n",
|
" \n",
|
||||||
" theta_half_width = theta_half_f2 - theta_half_f1\n",
|
" theta_half_width = theta_half_f2 - theta_half_f1\n",
|
||||||
" \n",
|
" \n",
|
||||||
" theta_half_energy = compute_energy(p_xx, freq, theta_half_f1, theta_half_f2) # theta band 6 - 10 Hz\n",
|
" psd_data.update({name: p_xx})\n",
|
||||||
|
" freq_data.update({name: freq})\n",
|
||||||
|
"\n",
|
||||||
" \n",
|
" \n",
|
||||||
" # stim\n",
|
" # stim\n",
|
||||||
" \n",
|
" \n",
|
||||||
|
@ -276,133 +338,89 @@
|
||||||
" \n",
|
" \n",
|
||||||
" stim_p_max = compute_stim_peak(p_xx, freq, stim_freq)\n",
|
" stim_p_max = compute_stim_peak(p_xx, freq, stim_freq)\n",
|
||||||
" \n",
|
" \n",
|
||||||
" stim_half_f1, stim_half_f2 = compute_half_width(p_xx, freq, stim_p_max, stim_freq)\n",
|
" stim_half_f1, stim_half_f2, stim_half_power = compute_half_width(p_xx, freq, stim_p_max, stim_freq, [stim_freq - 1, stim_freq + 1])\n",
|
||||||
|
" \n",
|
||||||
" stim_half_width = stim_half_f2 - stim_half_f1\n",
|
" stim_half_width = stim_half_f2 - stim_half_f1\n",
|
||||||
" \n",
|
" \n",
|
||||||
" stim_energy = compute_energy(p_xx, freq, stim_half_f1, stim_half_f2)\n",
|
" stim_bandpower, stim_relpower = compute_band_power(p_xx, freq, stim_freq - 1, stim_freq + 1)\n",
|
||||||
|
" \n",
|
||||||
|
" stim_relpeak = compute_relative_peak(p_xx, freq, stim_p_max, [stim_freq - 1, stim_freq + 1])\n",
|
||||||
" \n",
|
" \n",
|
||||||
" result = pd.Series({\n",
|
" result = pd.Series({\n",
|
||||||
" 'signal_to_noise': snl,\n",
|
" 'signal_to_noise': snl,\n",
|
||||||
" 'best_channel': best_channel,\n",
|
" 'best_channel': best_channel,\n",
|
||||||
" 'theta_freq': theta_f,\n",
|
" 'theta_freq': theta_f,\n",
|
||||||
" 'theta_peak': theta_p_max,\n",
|
" 'theta_peak': theta_p_max,\n",
|
||||||
" 'theta_energy': theta_energy,\n",
|
" 'theta_bandpower': theta_bandpower,\n",
|
||||||
|
" 'theta_relpower': theta_relpower,\n",
|
||||||
|
" 'theta_relpeak': theta_relpeak,\n",
|
||||||
" 'theta_half_f1': theta_half_f1, \n",
|
" 'theta_half_f1': theta_half_f1, \n",
|
||||||
" 'theta_half_f2': theta_half_f2,\n",
|
" 'theta_half_f2': theta_half_f2,\n",
|
||||||
" 'theta_half_width': theta_half_width,\n",
|
" 'theta_half_width': theta_half_width,\n",
|
||||||
" 'theta_half_energy': theta_half_energy,\n",
|
|
||||||
" 'stim_freq': stim_freq,\n",
|
" 'stim_freq': stim_freq,\n",
|
||||||
" 'stim_p_max': stim_p_max,\n",
|
" 'stim_p_max': stim_p_max,\n",
|
||||||
" 'stim_half_f1': stim_half_f1, \n",
|
" 'stim_half_f1': stim_half_f1, \n",
|
||||||
" 'stim_half_f2': stim_half_f2,\n",
|
" 'stim_half_f2': stim_half_f2,\n",
|
||||||
" 'stim_half_width': stim_half_width,\n",
|
" 'stim_half_width': stim_half_width,\n",
|
||||||
" 'stim_energy': stim_energy\n",
|
" 'stim_bandpower': stim_bandpower,\n",
|
||||||
|
" 'stim_relpower': stim_relpower,\n",
|
||||||
|
" 'stim_relpeak': stim_relpeak,\n",
|
||||||
" })\n",
|
" })\n",
|
||||||
" return result"
|
" return result"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 16,
|
"execution_count": null,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"application/vnd.jupyter.widget-view+json": {
|
"application/vnd.jupyter.widget-view+json": {
|
||||||
"model_id": "e733903bb8d7406ea6c05bf5af093bfc",
|
"model_id": "0a39fef20b724ef186ce6ce5299b3719",
|
||||||
"version_major": 2,
|
"version_major": 2,
|
||||||
"version_minor": 0
|
"version_minor": 0
|
||||||
},
|
},
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"HBox(children=(IntProgress(value=0, max=704), HTML(value='')))"
|
"HBox(children=(IntProgress(value=0, max=696), HTML(value='')))"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "display_data"
|
"output_type": "display_data"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stderr",
|
||||||
"output_type": "stream",
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"\n"
|
"/home/mikkel/.virtualenvs/expipe/lib/python3.6/site-packages/ipykernel_launcher.py:9: RuntimeWarning: invalid value encountered in greater\n",
|
||||||
|
" if __name__ == '__main__':\n",
|
||||||
|
"/home/mikkel/.virtualenvs/expipe/lib/python3.6/site-packages/ipykernel_launcher.py:9: RuntimeWarning: invalid value encountered in less\n",
|
||||||
|
" if __name__ == '__main__':\n",
|
||||||
|
"/home/mikkel/.virtualenvs/expipe/lib/python3.6/site-packages/ipykernel_launcher.py:10: RuntimeWarning: invalid value encountered in greater\n",
|
||||||
|
" # Remove the CWD from sys.path while we load stuff.\n",
|
||||||
|
"/home/mikkel/.virtualenvs/expipe/lib/python3.6/site-packages/ipykernel_launcher.py:10: RuntimeWarning: invalid value encountered in less\n",
|
||||||
|
" # Remove the CWD from sys.path while we load stuff.\n",
|
||||||
|
"/home/mikkel/.virtualenvs/expipe/lib/python3.6/site-packages/numpy/core/fromnumeric.py:3257: RuntimeWarning: Mean of empty slice.\n",
|
||||||
|
" out=out, **kwargs)\n",
|
||||||
|
"/home/mikkel/.virtualenvs/expipe/lib/python3.6/site-packages/numpy/core/_methods.py:161: RuntimeWarning: invalid value encountered in true_divide\n",
|
||||||
|
" ret = ret.dtype.type(ret / rcount)\n"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"results = channel_groups.merge(\n",
|
"results = channel_groups.merge(\n",
|
||||||
" channel_groups.progress_apply(process, axis=1), \n",
|
" channel_groups.progress_apply(process, perform_zscore=perform_zscore, axis=1), \n",
|
||||||
" left_index=True, right_index=True)"
|
" left_index=True, right_index=True)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 17,
|
"execution_count": null,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [],
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"application/vnd.jupyter.widget-view+json": {
|
|
||||||
"model_id": "0184251a265a40a2a1e9910405f05db8",
|
|
||||||
"version_major": 2,
|
|
||||||
"version_minor": 0
|
|
||||||
},
|
|
||||||
"text/plain": [
|
|
||||||
"HBox(children=(IntProgress(value=0, max=704), HTML(value='')))"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"metadata": {},
|
|
||||||
"output_type": "display_data"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stdout",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"\n"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
"source": [
|
||||||
"psd, freqs = {}, {}\n",
|
"pd.DataFrame(psd_data).to_feather(output / 'data' / 'psd.feather')\n",
|
||||||
"for i, row in tqdm(channel_groups.iterrows(), total=len(channel_groups)):\n",
|
"pd.DataFrame(freq_data).to_feather(output / 'data' / 'freqs.feather')"
|
||||||
" action_id = row['action']\n",
|
|
||||||
" channel_group = row['channel_group']\n",
|
|
||||||
" action_group = f'{action_id}_{channel_group}'\n",
|
|
||||||
" lfp = data_loader.lfp(action_id, channel_group)\n",
|
|
||||||
" clean_lfp = select_and_clean(lfp)\n",
|
|
||||||
" snls = signaltonoise(clean_lfp)\n",
|
|
||||||
" best_channel = np.argmax(snls)\n",
|
|
||||||
" snl = snls[best_channel]\n",
|
|
||||||
" \n",
|
|
||||||
" lim = get_lim(action_id)\n",
|
|
||||||
" \n",
|
|
||||||
" mask = get_mask(lfp, lim)\n",
|
|
||||||
" signal = zscore(clean_lfp[mask, best_channel].ravel())\n",
|
|
||||||
" \n",
|
|
||||||
" p_xx, freq = mlab.psd(signal, Fs=lfp.sampling_rate.magnitude, NFFT=NFFT)\n",
|
|
||||||
" psd.update({action_group: p_xx})\n",
|
|
||||||
" freqs.update({action_group: 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-7660e1d3307d>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mpsd\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'psd.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": [
|
|
||||||
"(psd).to_feather(output / 'data' / 'psd.feather')\n",
|
|
||||||
"freqs.to_feather(output / 'data' / 'freqs.feather')"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -418,7 +436,7 @@
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"action = project.require_action(\"stimulus-lfp-response\")"
|
"action = project.require_action(\"stimulus-lfp-response\" + zscore_str)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -428,7 +446,7 @@
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"action.modules['parameters'] = {\n",
|
"action.modules['parameters'] = {\n",
|
||||||
" 'NFFT': NFFT,\n",
|
" 'window': 6,\n",
|
||||||
" 'theta_band_f1': theta_band_f1,\n",
|
" 'theta_band_f1': theta_band_f1,\n",
|
||||||
" 'theta_band_f2': theta_band_f2\n",
|
" 'theta_band_f2': theta_band_f2\n",
|
||||||
"}"
|
"}"
|
||||||
|
@ -490,5 +508,5 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
"nbformat_minor": 2
|
"nbformat_minor": 4
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
|
@ -1,3 +1,3 @@
|
||||||
NFFT: 10000
|
window: 6
|
||||||
theta_band_f1: 6
|
theta_band_f1: 6
|
||||||
theta_band_f2: 10
|
theta_band_f2: 10
|
||||||
|
|
Loading…
Reference in New Issue