-
-
Notifications
You must be signed in to change notification settings - Fork 49
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
Skip plotting line data if it's all NaNs #802
base: main
Are you sure you want to change the base?
Conversation
|
@@ -145,7 +145,9 @@ def _plot_1D_cube(self, wcs, axes=None, axes_coordinates=None, axes_units=None, | |||
# We plot against pixel coordinates | |||
axes.errorbar(np.arange(len(ydata)), ydata, yerr=yerror, **kwargs) | |||
else: | |||
axes.plot(ydata, **kwargs) | |||
# compute() will break on numpy arrays to catch dask arrays by casting to bool instead |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment should make more sense to those who aren't dask wonks ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does an equivalent check need to be done for plotting a 2D image?
@@ -0,0 +1 @@ | |||
Skip plotting line data if all values are NaN |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skip plotting line data if all values are NaN | |
Make `~ndcube.visualization.mpl_plotter.MatplotlibPlotter` only add data to line plots if at least one value of the data is unmasked and finite. |
@@ -145,7 +145,9 @@ def _plot_1D_cube(self, wcs, axes=None, axes_coordinates=None, axes_units=None, | |||
# We plot against pixel coordinates | |||
axes.errorbar(np.arange(len(ydata)), ydata, yerr=yerror, **kwargs) | |||
else: | |||
axes.plot(ydata, **kwargs) | |||
# compute() will break on numpy arrays to catch dask arrays by casting to bool instead | |||
if not bool(np.isnan(ydata).all()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could something like
if not bool(np.isnan(ydata).all()): | |
if np.isfinite(ydata).any() and unmasked: |
be used instead without causing dask problems? This way both NaN and Inf would be checked. In addition, it would check whether there are valid unmasked data because unmasked
would be a bool
that would indicate that at least one finite data value is unmasked and default to True
. It would be calculated around here.
Closes DKISTDC/dkist#477
Over in the DKIST python tools I discovered that trying to line plot a slice of a dataset took many times longer if there was no actual data there. This skips the attempt to actually plot a line full of NaNs which should solve that and cause no other problems anywhere, probably.