Skip to content

Commit

Permalink
Faster animation with draw_idle
Browse files Browse the repository at this point in the history
  • Loading branch information
mcuntz committed Jul 14, 2024
1 parent f5abb77 commit 4a5eaac
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 32 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
---------

v4.4.3 (Jul 2024)
* Use `draw_idle` instead of `draw` in map update method for
faster animation.
* Change formatting of file string for multiple files.

v4.4.2 (Jul 2024)
* Use `matplotlib.colormaps[name]` instead of
`matplotlib.colormaps.get_cmap(name)` to work with
Expand All @@ -11,7 +16,7 @@ v4.4.1 (Feb 2024)

v4.4 (Feb 2024)
* Added borders, rivers, and lakes checkbuttons in map.
* Bugfix formatted string used wrong data type in `analyse_netcdf`.
* Bugfix: formatted string used wrong data type in `analyse_netcdf`.
* Move themes and images directories from src/ncvue to src directory.

v4.3 (Jan 2024)
Expand Down
2 changes: 1 addition & 1 deletion docs/html/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 7c07df56c7e585943f0ca8b4ecb99ae8
config: 4546b62aa505b55392a3c0b0e1a783ee
tags: 645f666f9bcd5a90fca523b33c5a78b7
7 changes: 5 additions & 2 deletions docs/html/_modules/ncvue/ncvmap.html
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ <h1>Source code for ncvue.ncvmap</h1><div class="highlight"><pre>
<span class="sd"> * Move themes/ and images/ back to src/ncvue/, Feb 2024, Matthias Cuntz</span>
<span class="sd"> * Use matplotlib.colormaps[name] instead of</span>
<span class="sd"> matplotlib.colormaps.get_cmap(name), Jul 2024, Matthias Cuntz</span>
<span class="sd"> * Use draw_idle instead of draw in update method for faster animation,</span>
<span class="sd"> Jul 2024, Matthias Cuntz</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">os</span>
Expand Down Expand Up @@ -1771,7 +1773,8 @@ <h1>Source code for ncvue.ncvmap</h1><div class="highlight"><pre>
<a class="viewcode-back" href="../../ncvmap.html#ncvue.ncvmap.ncvMap.update">[docs]</a>
<span class="k">def</span> <span class="nf">update</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">frame</span><span class="p">,</span> <span class="n">isframe</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Updates data of the current the plot.</span>
<span class="sd"> Updates data of the current plot.</span>

<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">anim_first</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">anim</span><span class="o">.</span><span class="n">event_source</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
Expand Down Expand Up @@ -1862,7 +1865,7 @@ <h1>Source code for ncvue.ncvmap</h1><div class="highlight"><pre>
<span class="n">vmin</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">ivmin</span><span class="p">,</span> <span class="n">vmax</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">ivmax</span><span class="p">,</span>
<span class="n">cmap</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">icmap</span><span class="p">,</span> <span class="n">extend</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">iextend</span><span class="p">,</span>
<span class="n">transform</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">itrans</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">draw</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">draw_idle</span><span class="p">()</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">cc</span><span class="p">,</span></div>
</div>

Expand Down
9 changes: 6 additions & 3 deletions docs/html/_modules/ncvue/ncvue.html
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ <h1>Source code for ncvue.ncvue</h1><div class="highlight"><pre>
<span class="sd"> * Move themes/ and images/ directories from src/ncvue/ to src/ directory,</span>
<span class="sd"> Jan 2024, Matthias Cuntz</span>
<span class="sd"> * Move themes/ and images/ back to src/ncvue/, Feb 2024, Matthias Cuntz</span>
<span class="sd"> * Change formatting of file string for multiple files,</span>
<span class="sd"> Jul 2024, Matthias Cuntz</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">os</span>
Expand Down Expand Up @@ -500,16 +502,17 @@ <h1>Source code for ncvue.ncvue</h1><div class="highlight"><pre>
<span class="k">for</span> <span class="n">ii</span><span class="p">,</span> <span class="n">nn</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">ncfile</span><span class="p">):</span>
<span class="n">top</span><span class="o">.</span><span class="n">fi</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">nc</span><span class="o">.</span><span class="n">Dataset</span><span class="p">(</span><span class="n">nn</span><span class="p">,</span> <span class="s1">&#39;r&#39;</span><span class="p">))</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">ncfile</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">top</span><span class="o">.</span><span class="n">groups</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;file</span><span class="si">{</span><span class="n">ii</span><span class="si">:</span><span class="s1">03d</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">)</span>
<span class="n">nnc</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">ceil</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">log10</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">ncfile</span><span class="p">)))</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="nb">int</span><span class="p">)</span>
<span class="n">top</span><span class="o">.</span><span class="n">groups</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;file</span><span class="si">{</span><span class="n">ii</span><span class="si">:</span><span class="s1">0</span><span class="si">{</span><span class="n">nnc</span><span class="si">}</span><span class="s1">d</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">)</span>
<span class="c1"># Check groups</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">ncfile</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">top</span><span class="o">.</span><span class="n">groups</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">top</span><span class="o">.</span><span class="n">fi</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">groups</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">for</span> <span class="n">ii</span><span class="p">,</span> <span class="n">nn</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">ncfile</span><span class="p">):</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">top</span><span class="o">.</span><span class="n">fi</span><span class="p">[</span><span class="n">ii</span><span class="p">]</span><span class="o">.</span><span class="n">groups</span><span class="o">.</span><span class="n">keys</span><span class="p">()))</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;Either multiple files or one file with groups&#39;</span>
<span class="sa">f</span><span class="s1">&#39; allowed as input. Multiple files and file </span><span class="si">{</span><span class="n">nn</span><span class="si">}</span><span class="s1">&#39;</span>
<span class="sa">f</span><span class="s1">&#39; has groups.&#39;</span><span class="p">)</span>
<span class="sa">f</span><span class="s1">&#39; allowed as input. Multiple files given but file&#39;</span>
<span class="sa">f</span><span class="s1">&#39; </span><span class="si">{</span><span class="n">nn</span><span class="si">}</span><span class="s1"> has groups.&#39;</span><span class="p">)</span>
<span class="k">for</span> <span class="n">fi</span> <span class="ow">in</span> <span class="n">top</span><span class="o">.</span><span class="n">fi</span><span class="p">:</span>
<span class="n">fi</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="n">top</span><span class="o">.</span><span class="n">quit</span><span class="p">()</span>
Expand Down
8 changes: 7 additions & 1 deletion docs/html/changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,12 @@ <h1>Changelog</h1>
<section id="changelog">
<span id="id1"></span><h1>Changelog<a class="headerlink" href="#changelog" title="Link to this heading">#</a></h1>
<dl class="simple">
<dt>v4.4.3 (Jul 2024)</dt><dd><ul class="simple">
<li><p>Use <cite>draw_idle</cite> instead of <cite>draw</cite> in map update method for
faster animation.</p></li>
<li><p>Change formatting of file string for multiple files.</p></li>
</ul>
</dd>
<dt>v4.4.2 (Jul 2024)</dt><dd><ul class="simple">
<li><p>Use <cite>matplotlib.colormaps[name]</cite> instead of
<cite>matplotlib.colormaps.get_cmap(name)</cite> to work with
Expand All @@ -390,7 +396,7 @@ <h1>Changelog</h1>
</dd>
<dt>v4.4 (Feb 2024)</dt><dd><ul class="simple">
<li><p>Added borders, rivers, and lakes checkbuttons in map.</p></li>
<li><p>Bugfix formatted string used wrong data type in <cite>analyse_netcdf</cite>.</p></li>
<li><p>Bugfix: formatted string used wrong data type in <cite>analyse_netcdf</cite>.</p></li>
<li><p>Move themes and images directories from src/ncvue to src directory.</p></li>
</ul>
</dd>
Expand Down
6 changes: 4 additions & 2 deletions docs/html/ncvmap.html
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,8 @@ <h2> Contents </h2>
<li><p>Move themes/ and images/ back to src/ncvue/, Feb 2024, Matthias Cuntz</p></li>
<li><p>Use matplotlib.colormaps[name] instead of
matplotlib.colormaps.get_cmap(name), Jul 2024, Matthias Cuntz</p></li>
<li><p>Use draw_idle instead of draw in update method for faster animation,
Jul 2024, Matthias Cuntz</p></li>
</ul>
</dd>
</dl>
Expand Down Expand Up @@ -1024,7 +1026,7 @@ <h2> Contents </h2>
<td><p>Unbind for all widgets with bindtag CLASSNAME for event SEQUENCE all functions.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#ncvue.ncvmap.ncvMap.update" title="ncvue.ncvmap.ncvMap.update"><code class="xref py py-obj docutils literal notranslate"><span class="pre">update</span></code></a>(frame[, isframe])</p></td>
<td><p>Updates data of the current the plot.</p></td>
<td><p>Updates data of the current plot.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#ncvue.ncvmap.ncvMap.update_idletasks" title="ncvue.ncvmap.ncvMap.update_idletasks"><code class="xref py py-obj docutils literal notranslate"><span class="pre">update_idletasks</span></code></a>()</p></td>
<td><p>Enter event loop until all idle callbacks have been called.</p></td>
Expand Down Expand Up @@ -2372,7 +2374,7 @@ <h2> Contents </h2>
<dl class="py method">
<dt class="sig sig-object py" id="ncvue.ncvmap.ncvMap.update">
<span class="sig-name descname"><span class="pre">update</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">frame</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">isframe</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/ncvue/ncvmap.html#ncvMap.update"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#ncvue.ncvmap.ncvMap.update" title="Link to this definition">#</a></dt>
<dd><p>Updates data of the current the plot.</p>
<dd><p>Updates data of the current plot.</p>
</dd></dl>

<dl class="py method">
Expand Down
2 changes: 2 additions & 0 deletions docs/html/ncvue.html
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,8 @@ <h2> Contents </h2>
<li><p>Move themes/ and images/ directories from src/ncvue/ to src/ directory,
Jan 2024, Matthias Cuntz</p></li>
<li><p>Move themes/ and images/ back to src/ncvue/, Feb 2024, Matthias Cuntz</p></li>
<li><p>Change formatting of file string for multiple files,
Jul 2024, Matthias Cuntz</p></li>
</ul>
</dd>
</dl>
Expand Down
2 changes: 1 addition & 1 deletion docs/html/searchindex.js

Large diffs are not rendered by default.

33 changes: 17 additions & 16 deletions docs/src/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ def setup(app):
"use_issues_button": True,
"use_repository_button": True,
"use_download_button": True,
"navigation_with_keys": False,
}
# # Add any paths that contain custom static files (such as style sheets) here,
# # relative to this directory. They are copied after the builtin static files,
Expand Down Expand Up @@ -260,20 +261,20 @@ def setup(app):

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {
"Python": ("https://docs.python.org/3/", None),
"NumPy": ("https://numpy.org/doc/stable/", None),
"SciPy": ("https://docs.scipy.org/doc/scipy/reference/", None),
"matplotlib": ("https://matplotlib.org/stable/", None),
"Pandas": ("https://pandas.pydata.org/docs/", None),
"cython": ("https://cython.readthedocs.io/en/latest/", None),
"cftime": ("https://unidata.github.io/cftime/", None),
# "netcdf4-python": ("https://unidata.github.io/netcdf4-python/", None),
"openpyxl": ("https://openpyxl.readthedocs.io/en/stable/", None),
"Sphinx": ("https://www.sphinx-doc.org/en/master/", None),
"schwimmbad": ("https://schwimmbad.readthedocs.io/en/latest/", None),
"mpi4py": ("https://mpi4py.readthedocs.io/en/latest/", None),
"emcee": ("https://emcee.readthedocs.io/en/latest/", None),
"partialwrap": ("https://mcuntz.github.io/partialwrap/html/", None),
"pyeee": ("https://pyeee.readthedocs.io/en/latest/", None),
"hesseflux": ("https://mcuntz.github.io/hesseflux/html/", None),
"Python": ("https://docs.python.org/3/", None),
"NumPy": ("https://numpy.org/doc/stable/", None),
"SciPy": ("https://docs.scipy.org/doc/scipy/", None),
"matplotlib": ("https://matplotlib.org/stable/", None),
"Pandas": ("https://pandas.pydata.org/docs/", None),
"cython": ("https://cython.readthedocs.io/en/latest/", None),
"cftime": ("https://unidata.github.io/cftime/", None),
# "netcdf4-python": ("https://unidata.github.io/netcdf4-python/", None),
"openpyxl": ("https://openpyxl.readthedocs.io/en/stable/", None),
"Sphinx": ("https://www.sphinx-doc.org/en/master/", None),
"schwimmbad": ("https://schwimmbad.readthedocs.io/en/latest/", None),
"mpi4py": ("https://mpi4py.readthedocs.io/en/latest/", None),
"emcee": ("https://emcee.readthedocs.io/en/latest/", None),
"partialwrap": ("https://mcuntz.github.io/partialwrap/html/", None),
"pyeee": ("https://pyeee.readthedocs.io/en/latest/", None),
"hesseflux": ("https://mcuntz.github.io/hesseflux/html/", None),
}
7 changes: 5 additions & 2 deletions src/ncvue/ncvmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
* Move themes/ and images/ back to src/ncvue/, Feb 2024, Matthias Cuntz
* Use matplotlib.colormaps[name] instead of
matplotlib.colormaps.get_cmap(name), Jul 2024, Matthias Cuntz
* Use draw_idle instead of draw in update method for faster animation,
Jul 2024, Matthias Cuntz
"""
import os
Expand Down Expand Up @@ -1365,7 +1367,8 @@ def redraw(self):

def update(self, frame, isframe=False):
"""
Updates data of the current the plot.
Updates data of the current plot.
"""
if self.anim_first:
self.anim.event_source.stop()
Expand Down Expand Up @@ -1456,5 +1459,5 @@ def update(self, frame, isframe=False):
vmin=self.ivmin, vmax=self.ivmax,
cmap=self.icmap, extend=self.iextend,
transform=self.itrans)
self.canvas.draw()
self.canvas.draw_idle()
return self.cc,
9 changes: 6 additions & 3 deletions src/ncvue/ncvue.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
* Move themes/ and images/ directories from src/ncvue/ to src/ directory,
Jan 2024, Matthias Cuntz
* Move themes/ and images/ back to src/ncvue/, Feb 2024, Matthias Cuntz
* Change formatting of file string for multiple files,
Jul 2024, Matthias Cuntz
"""
import os
Expand Down Expand Up @@ -186,16 +188,17 @@ def ncvue(ncfile=[], miss=np.nan):
for ii, nn in enumerate(ncfile):
top.fi.append(nc.Dataset(nn, 'r'))
if len(ncfile) > 1:
top.groups.append(f'file{ii:03d}')
nnc = np.ceil(np.log10(len(ncfile))).astype(int)
top.groups.append(f'file{ii:0{nnc}d}')
# Check groups
if len(ncfile) == 1:
top.groups = list(top.fi[0].groups.keys())
else:
for ii, nn in enumerate(ncfile):
if len(list(top.fi[ii].groups.keys())) > 0:
print(f'Either multiple files or one file with groups'
f' allowed as input. Multiple files and file {nn}'
f' has groups.')
f' allowed as input. Multiple files given but file'
f' {nn} has groups.')
for fi in top.fi:
fi.close()
top.quit()
Expand Down

0 comments on commit 4a5eaac

Please sign in to comment.