Skip to content

Commit 1413726

Browse files
committed
Preview for PR #15 7399de6
1 parent 97f804b commit 1413726

5 files changed

Lines changed: 171 additions & 104 deletions

File tree

39.8 KB
Loading
847 KB
Loading

pr-15/_sources/notebooks/tutorials/as_points.ipynb

Lines changed: 137 additions & 91 deletions
Large diffs are not rendered by default.

pr-15/notebooks/tutorials/as_points.html

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -633,10 +633,31 @@ <h2>3. Labels: segmentation masks as centroids<a class="headerlink" href="#label
633633
</section>
634634
<section id="the-speed-trade-off">
635635
<h2>4. The speed trade-off<a class="headerlink" href="#the-speed-trade-off" title="Link to this heading">#</a></h2>
636-
<p><code class="docutils literal notranslate"><span class="pre">as_points</span></code> exists mainly for speed. We subsample the real cells across a range
637-
of counts, up to the full 167780, and time each render. The backend is held at
638-
matplotlib, so the comparison is drawing N polygons or masks against drawing N
639-
dots.</p>
636+
<p>First, the whole section drawn both ways: all 167780 cells, coloured by EPCAM. At
637+
this zoom each cell is only a few microns across, well under one pixel, so the
638+
full-geometry circles render sparse and speckled while <code class="docutils literal notranslate"><span class="pre">as_points</span></code> spreads each
639+
cell into a visible marker. The centroid view is the cleaner overview here, and,
640+
as the timings below show, much the faster one.</p>
641+
<div class="cell docutils container">
642+
<div class="cell_input docutils container">
643+
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">fig</span><span class="p">,</span> <span class="n">axes</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">12</span><span class="p">,</span> <span class="mf">5.5</span><span class="p">))</span>
644+
<span class="n">sdata</span><span class="o">.</span><span class="n">pl</span><span class="o">.</span><span class="n">render_shapes</span><span class="p">(</span>
645+
<span class="s2">&quot;cell_circles&quot;</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s2">&quot;EPCAM&quot;</span><span class="p">,</span> <span class="n">cmap</span><span class="o">=</span><span class="s2">&quot;magma&quot;</span><span class="p">,</span> <span class="n">outline_alpha</span><span class="o">=</span><span class="mf">0.0</span>
646+
<span class="p">)</span><span class="o">.</span><span class="n">pl</span><span class="o">.</span><span class="n">show</span><span class="p">(</span><span class="n">ax</span><span class="o">=</span><span class="n">axes</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">title</span><span class="o">=</span><span class="s2">&quot;full geometry (167780 circles)&quot;</span><span class="p">,</span> <span class="n">colorbar</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
647+
<span class="n">sdata</span><span class="o">.</span><span class="n">pl</span><span class="o">.</span><span class="n">render_shapes</span><span class="p">(</span>
648+
<span class="s2">&quot;cell_circles&quot;</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s2">&quot;EPCAM&quot;</span><span class="p">,</span> <span class="n">cmap</span><span class="o">=</span><span class="s2">&quot;magma&quot;</span><span class="p">,</span> <span class="n">as_points</span><span class="o">=</span><span class="kc">True</span>
649+
<span class="p">)</span><span class="o">.</span><span class="n">pl</span><span class="o">.</span><span class="n">show</span><span class="p">(</span><span class="n">ax</span><span class="o">=</span><span class="n">axes</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">title</span><span class="o">=</span><span class="s2">&quot;as_points (167780 dots)&quot;</span><span class="p">,</span> <span class="n">colorbar</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
650+
<span class="n">fig</span><span class="o">.</span><span class="n">tight_layout</span><span class="p">()</span>
651+
</pre></div>
652+
</div>
653+
</div>
654+
<div class="cell_output docutils container">
655+
<img alt="../../_images/e12e47aebe090e5abb24801680c15c37b701bb88ca3729c4513945204a7433c1.png" src="../../_images/e12e47aebe090e5abb24801680c15c37b701bb88ca3729c4513945204a7433c1.png" />
656+
</div>
657+
</div>
658+
<p>To put numbers on it, we subsample the real cells across a range of counts, up to
659+
the full 167780, and time each render. The backend is held at matplotlib, so the
660+
comparison is drawing N polygons or masks against drawing N dots.</p>
640661
<div class="cell docutils container">
641662
<div class="cell_input docutils container">
642663
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">time_best</span><span class="p">(</span><span class="n">fn</span><span class="p">,</span> <span class="n">repeat</span><span class="o">=</span><span class="mi">3</span><span class="p">):</span>
@@ -671,11 +692,11 @@ <h2>4. The speed trade-off<a class="headerlink" href="#the-speed-trade-off" titl
671692
</div>
672693
<div class="cell_output docutils container">
673694
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>N= 1000: full 0.03s as_points 0.01s (4x)
674-
N= 5000: full 0.14s as_points 0.02s (8x)
675-
N= 20000: full 0.50s as_points 0.04s (13x)
676-
N= 50000: full 1.26s as_points 0.09s (14x)
677-
N= 100000: full 2.49s as_points 0.17s (15x)
678-
N= 167780: full 4.21s as_points 0.27s (16x)
695+
N= 5000: full 0.13s as_points 0.02s (8x)
696+
N= 20000: full 0.51s as_points 0.04s (13x)
697+
N= 50000: full 1.26s as_points 0.09s (15x)
698+
N= 100000: full 2.50s as_points 0.17s (15x)
699+
N= 167780: full 4.19s as_points 0.27s (16x)
679700
</pre></div>
680701
</div>
681702
</div>
@@ -712,8 +733,8 @@ <h2>4. The speed trade-off<a class="headerlink" href="#the-speed-trade-off" titl
712733
</div>
713734
</div>
714735
<div class="cell_output docutils container">
715-
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>N= 424: full mask 0.10s as_points 0.10s
716-
N= 5833: full mask 0.11s as_points 0.10s
736+
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>N= 424: full mask 0.10s as_points 0.09s
737+
N= 5833: full mask 0.10s as_points 0.10s
717738
N= 18606: full mask 0.12s as_points 0.12s
718739
N= 39125: full mask 0.16s as_points 0.15s
719740
</pre></div>
@@ -741,7 +762,7 @@ <h2>4. The speed trade-off<a class="headerlink" href="#the-speed-trade-off" titl
741762
</div>
742763
</div>
743764
<div class="cell_output docutils container">
744-
<img alt="../../_images/119c3185d52ce0e5852a912f9956192546276c10b8887cfd5798ac5b4d3ae1d4.png" src="../../_images/119c3185d52ce0e5852a912f9956192546276c10b8887cfd5798ac5b4d3ae1d4.png" />
765+
<img alt="../../_images/827afb7dddaec5285fd0b9c78af6fd72749175941494151c9ae8f58aa57ca193.png" src="../../_images/827afb7dddaec5285fd0b9c78af6fd72749175941494151c9ae8f58aa57ca193.png" />
745766
</div>
746767
</div>
747768
<p>The two panels behave differently:</p>

pr-15/searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)