Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WCS Plotter #73

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions changelog/73.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Catch errors when animating plots with missing data and replace them with warnings.
17 changes: 14 additions & 3 deletions mpl_animators/wcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from mpl_animators.extern import modest_image
from .base import ArrayAnimator
import warnings

__all__ = ['ArrayAnimatorWCS']

Expand Down Expand Up @@ -277,8 +278,13 @@ def update_plot_1d(self, val, line, slider):

# If we are not setting ylim globally then we set it per frame.
if self.ylim == 'dynamic':
self.axes.set_ylim(float(self.data[self.frame_index].min()),
float(self.data[self.frame_index].max()))
vmin = float(np.nanmin(self.data[self.frame_index]))
vmax = float(np.nanmax(self.data[self.frame_index]))
if np.isnan(vmin) or np.isnan(vmax):
warnings.warn(UserWarning(f"No data found for data slice {self.frame_index} - cannot set ylim"))
return

self.axes.set_ylim(vmin, vmax)
slider.cval = val

def plot_start_image_2d(self, ax):
Expand Down Expand Up @@ -315,7 +321,12 @@ def _get_2d_plot_limits(self):
Get vmin, vmax of a data slice when clip_interval is specified.
"""
percent_limits = self.clip_interval.to('%').value
vmin, vmax = AsymmetricPercentileInterval(*percent_limits).get_limits(self.data_transposed)
if np.isnan(self.data_transposed).all():
warnings.warn(UserWarning(f"No data found for data slice {self.frame_index} - cannot set vmin, vmax"))
vmin, vmax = 0, 0
else:
vmin, vmax = AsymmetricPercentileInterval(*percent_limits).get_limits(self.data_transposed)

return vmin, vmax

def update_plot_2d(self, val, im, slider):
Expand Down
Loading