Skip to content

Commit

Permalink
doc updates [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
Circle Ci committed Oct 28, 2024
1 parent 571dc9c commit 163e745
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 10 deletions.
8 changes: 5 additions & 3 deletions dev/_modules/hnn_core/cell_response.html
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,8 @@ <h1>Source code for hnn_core.cell_response</h1><div class="highlight"><pre>
<span class="n">cell_response</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="n">trial_idx</span><span class="o">=</span><span class="n">trial_idx</span><span class="p">,</span> <span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">,</span> <span class="n">show</span><span class="o">=</span><span class="n">show</span><span class="p">)</span></div>

<div class="viewcode-block" id="CellResponse.plot_spikes_hist"><a class="viewcode-back" href="../../generated/hnn_core.CellResponse.html#hnn_core.CellResponse.plot_spikes_hist">[docs]</a> <span class="k">def</span> <span class="nf">plot_spikes_hist</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">trial_idx</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">ax</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">spike_types</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">color</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">show</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs_hist</span><span class="p">):</span>
<span class="n">invert_spike_types</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">show</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="o">**</span><span class="n">kwargs_hist</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Plot the histogram of spiking activity across trials.</span>

<span class="sd"> Parameters</span>
Expand Down Expand Up @@ -501,8 +502,9 @@ <h1>Source code for hnn_core.cell_response</h1><div class="highlight"><pre>
<span class="sd"> The matplotlib figure handle.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">plot_spikes_hist</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">trial_idx</span><span class="o">=</span><span class="n">trial_idx</span><span class="p">,</span> <span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">,</span>
<span class="n">spike_types</span><span class="o">=</span><span class="n">spike_types</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span>
<span class="n">show</span><span class="o">=</span><span class="n">show</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs_hist</span><span class="p">)</span></div>
<span class="n">spike_types</span><span class="o">=</span><span class="n">spike_types</span><span class="p">,</span>
<span class="n">invert_spike_types</span><span class="o">=</span><span class="n">invert_spike_types</span><span class="p">,</span>
<span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span> <span class="n">show</span><span class="o">=</span><span class="n">show</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs_hist</span><span class="p">)</span></div>

<div class="viewcode-block" id="CellResponse.to_dict"><a class="viewcode-back" href="../../generated/hnn_core.CellResponse.html#hnn_core.CellResponse.to_dict">[docs]</a> <span class="k">def</span> <span class="nf">to_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Return cell response as a dict object.</span>
Expand Down
70 changes: 66 additions & 4 deletions dev/_modules/hnn_core/viz.html
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,8 @@ <h1>Source code for hnn_core.viz</h1><div class="highlight"><pre>


<div class="viewcode-block" id="plot_spikes_hist"><a class="viewcode-back" href="../../generated/hnn_core.viz.plot_spikes_hist.html#hnn_core.viz.plot_spikes_hist">[docs]</a><span class="k">def</span> <span class="nf">plot_spikes_hist</span><span class="p">(</span><span class="n">cell_response</span><span class="p">,</span> <span class="n">trial_idx</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">ax</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">spike_types</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">color</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">show</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs_hist</span><span class="p">):</span>
<span class="n">color</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">invert_spike_types</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">show</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="o">**</span><span class="n">kwargs_hist</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Plot the histogram of spiking activity across trials.</span>

<span class="sd"> Parameters</span>
Expand Down Expand Up @@ -504,6 +505,16 @@ <h1>Source code for hnn_core.viz</h1><div class="highlight"><pre>
<span class="sd"> Valid strings also include leading characters of spike types</span>

<span class="sd"> | Ex: ``&#39;ev&#39;`` is equivalent to ``[&#39;evdist&#39;, &#39;evprox&#39;]``</span>
<span class="sd"> invert_spike_types: string | list | None</span>
<span class="sd"> String input of a valid spike type to be mirrored about the y axis</span>

<span class="sd"> | Ex: ``&#39;evdist&#39;``, ``&#39;evprox&#39;``, ...</span>

<span class="sd"> List of valid spike types to be mirrored about the y axis</span>

<span class="sd"> | Ex: ``[&#39;evdist&#39;, &#39;evprox&#39;]``</span>

<span class="sd"> If None, all input spike types are plotted on the same y axis</span>
<span class="sd"> color : str | list of str | dict | None</span>
<span class="sd"> Input defining colors of plotted histograms. If str, all</span>
<span class="sd"> histograms plotted with same color. If list of str provided,</span>
Expand Down Expand Up @@ -625,19 +636,70 @@ <h1>Source code for hnn_core.viz</h1><div class="highlight"><pre>
<span class="n">spike_type_times</span><span class="p">[</span><span class="n">spike_label</span><span class="p">]</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span>
<span class="n">spike_times</span><span class="p">[</span><span class="n">spike_types_mask</span><span class="p">[</span><span class="n">spike_type</span><span class="p">]])</span>

<span class="k">if</span> <span class="n">invert_spike_types</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">invert_spike_types</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">invert_spike_types</span><span class="p">,</span> <span class="p">(</span><span class="nb">str</span><span class="p">,</span> <span class="nb">list</span><span class="p">)):</span>
<span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span>
<span class="s2">&quot;&#39;invert_spike_types&#39; must be a string or a list of strings&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">invert_spike_types</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
<span class="n">invert_spike_types</span> <span class="o">=</span> <span class="p">[</span><span class="n">invert_spike_types</span><span class="p">]</span>

<span class="c1"># Check that spike types to invert are correctly specified</span>
<span class="n">unique_inputs</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">spike_labels</span><span class="o">.</span><span class="n">values</span><span class="p">())</span>
<span class="n">unique_invert_inputs</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">invert_spike_types</span><span class="p">)</span>
<span class="n">check_intersection</span> <span class="o">=</span> <span class="n">unique_invert_inputs</span><span class="o">.</span><span class="n">intersection</span><span class="p">(</span><span class="n">unique_inputs</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">check_intersection</span> <span class="o">==</span> <span class="n">unique_invert_inputs</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
<span class="s2">&quot;Elements of &#39;invert_spike_types&#39; must&quot;</span>
<span class="s2">&quot;map to valid input types&quot;</span>
<span class="p">)</span>

<span class="c1"># Initialize secondary axis</span>
<span class="n">ax1</span> <span class="o">=</span> <span class="kc">None</span>

<span class="c1"># Plot aggregated spike_times</span>
<span class="k">for</span> <span class="n">spike_label</span><span class="p">,</span> <span class="n">plot_data</span> <span class="ow">in</span> <span class="n">spike_type_times</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="n">hist_color</span> <span class="o">=</span> <span class="n">spike_color</span><span class="p">[</span><span class="n">spike_label</span><span class="p">]</span>
<span class="n">ax</span><span class="o">.</span><span class="n">hist</span><span class="p">(</span><span class="n">plot_data</span><span class="p">,</span> <span class="n">bins</span><span class="p">,</span>
<span class="n">label</span><span class="o">=</span><span class="n">spike_label</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="n">hist_color</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs_hist</span><span class="p">)</span>

<span class="c1"># Plot on the primary y-axis</span>
<span class="k">if</span> <span class="n">spike_label</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">invert_spike_types</span><span class="p">:</span>
<span class="n">ax</span><span class="o">.</span><span class="n">hist</span><span class="p">(</span><span class="n">plot_data</span><span class="p">,</span> <span class="n">bins</span><span class="p">,</span>
<span class="n">label</span><span class="o">=</span><span class="n">spike_label</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="n">hist_color</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs_hist</span><span class="p">)</span>
<span class="c1"># Plot on secondary y-axis</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">if</span> <span class="n">ax1</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">ax1</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">twinx</span><span class="p">()</span>
<span class="n">ax1</span><span class="o">.</span><span class="n">hist</span><span class="p">(</span><span class="n">plot_data</span><span class="p">,</span> <span class="n">bins</span><span class="p">,</span>
<span class="n">label</span><span class="o">=</span><span class="n">spike_label</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="n">hist_color</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs_hist</span><span class="p">)</span>

<span class="c1"># Set the y-limits based on the maximum across both axes</span>
<span class="k">if</span> <span class="n">ax1</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">ax_ylim</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">get_ylim</span><span class="p">()[</span><span class="mi">1</span><span class="p">]</span>
<span class="n">ax1_ylim</span> <span class="o">=</span> <span class="n">ax1</span><span class="o">.</span><span class="n">get_ylim</span><span class="p">()[</span><span class="mi">1</span><span class="p">]</span>

<span class="n">y_max</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">ax_ylim</span><span class="p">,</span> <span class="n">ax1_ylim</span><span class="p">)</span>
<span class="n">ax</span><span class="o">.</span><span class="n">set_ylim</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">y_max</span><span class="p">)</span>
<span class="n">ax1</span><span class="o">.</span><span class="n">set_ylim</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">y_max</span><span class="p">)</span>
<span class="n">ax1</span><span class="o">.</span><span class="n">invert_yaxis</span><span class="p">()</span>

<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">cell_response</span><span class="o">.</span><span class="n">times</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">ax</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">(</span><span class="n">left</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">right</span><span class="o">=</span><span class="n">cell_response</span><span class="o">.</span><span class="n">times</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ax</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">(</span><span class="n">left</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>

<span class="n">ax</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s2">&quot;Counts&quot;</span><span class="p">)</span>
<span class="n">ax</span><span class="o">.</span><span class="n">legend</span><span class="p">()</span>

<span class="k">if</span> <span class="n">ax1</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="c1"># Combine legends</span>
<span class="n">handles</span><span class="p">,</span> <span class="n">labels</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">get_legend_handles_labels</span><span class="p">()</span>
<span class="n">handles1</span><span class="p">,</span> <span class="n">labels1</span> <span class="o">=</span> <span class="n">ax1</span><span class="o">.</span><span class="n">get_legend_handles_labels</span><span class="p">()</span>
<span class="n">handles</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">handles1</span><span class="p">)</span>
<span class="n">labels</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">labels1</span><span class="p">)</span>

<span class="n">ax</span><span class="o">.</span><span class="n">legend</span><span class="p">(</span><span class="n">handles</span><span class="p">,</span> <span class="n">labels</span><span class="p">,</span> <span class="n">loc</span><span class="o">=</span><span class="s1">&#39;upper left&#39;</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ax</span><span class="o">.</span><span class="n">legend</span><span class="p">()</span>

<span class="n">plt_show</span><span class="p">(</span><span class="n">show</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ax</span><span class="o">.</span><span class="n">get_figure</span><span class="p">()</span></div>
Expand Down
Loading

0 comments on commit 163e745

Please sign in to comment.