Skip to content

Commit 6e5b0e5

Browse files
SolarDrewDrew Leonardpre-commit-ci[bot]Cadair
authored
WCS Plotter (#73)
* Catch ValueError in 1D animation update * Catch error setting clim in 2D plots * Changelog * Check for NaNs instead of catching ValueError * And again * Well obviously that only works for dask arrays * Use nanmin/nanmax in case some but not all of the data is nan * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Not sure how this became this PR's problem, but fix the docs build * Update tox.ini * Update pyproject.toml * Update tox.ini --------- Co-authored-by: Drew Leonard <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Stuart Mumford <[email protected]>
1 parent 85d198b commit 6e5b0e5

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

changelog/73.trivial.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Catch errors when animating plots with missing data and replace them with warnings.

mpl_animators/wcs.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import warnings
12
from functools import partial
23

34
import numpy as np
@@ -277,8 +278,13 @@ def update_plot_1d(self, val, line, slider):
277278

278279
# If we are not setting ylim globally then we set it per frame.
279280
if self.ylim == 'dynamic':
280-
self.axes.set_ylim(float(self.data[self.frame_index].min()),
281-
float(self.data[self.frame_index].max()))
281+
vmin = float(np.nanmin(self.data[self.frame_index]))
282+
vmax = float(np.nanmax(self.data[self.frame_index]))
283+
if np.isnan(vmin) or np.isnan(vmax):
284+
warnings.warn(UserWarning(f"No data found for data slice {self.frame_index} - cannot set ylim"))
285+
return
286+
287+
self.axes.set_ylim(vmin, vmax)
282288
slider.cval = val
283289

284290
def plot_start_image_2d(self, ax):
@@ -315,7 +321,12 @@ def _get_2d_plot_limits(self):
315321
Get vmin, vmax of a data slice when clip_interval is specified.
316322
"""
317323
percent_limits = self.clip_interval.to('%').value
318-
vmin, vmax = AsymmetricPercentileInterval(*percent_limits).get_limits(self.data_transposed)
324+
if np.isnan(self.data_transposed).all():
325+
warnings.warn(UserWarning(f"No data found for data slice {self.frame_index} - cannot set vmin, vmax"))
326+
vmin, vmax = 0, 0
327+
else:
328+
vmin, vmax = AsymmetricPercentileInterval(*percent_limits).get_limits(self.data_transposed)
329+
319330
return vmin, vmax
320331

321332
def update_plot_2d(self, val, im, slider):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ docs = [
3939
"sunpy-sphinx-theme",
4040
"packaging",
4141
"sphinx_gallery",
42-
"sunpy",
42+
"sunpy[map]",
4343
"scipy",
4444
]
4545
all = [

0 commit comments

Comments
 (0)