Skip to content

Commit 37dd9c0

Browse files
authored
Updates display warnings / errors (#43)
* make animshow/imshow shape errors more informative * changes ipython animshow warning to error, when relevant
1 parent 198cab0 commit 37dd9c0

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/pyrtools/tools/display.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44
from matplotlib import cm
55
from matplotlib.figure import Figure
66
from matplotlib import animation
7-
try:
8-
from IPython.display import HTML
9-
except ImportError:
10-
warnings.warn("Unable to import IPython.display.HTML, animshow must be called with "
11-
"as_html5=False")
127
from ..pyramids import convert_pyr_coeffs_to_pyr
138

149

@@ -529,16 +524,18 @@ def _process_signal(signal, title, plot_complex, video=False):
529524
if sig.ndim == (3 + time_dim):
530525
if sig.shape[-1] not in [3, 4]:
531526
raise Exception(
532-
"Can't figure out how to plot {} with shape {}"
527+
f"Can't figure out how to plot {sigtype} with shape {sig.shape} "
533528
"as RGB(A)! RGB(A) signals should have their final"
534-
"dimension of shape 3 or 4.".format(sigtype, sig.shape))
529+
"dimension of shape 3 or 4."
530+
)
535531
contains_rgb = True
536532
elif sig.ndim != (2 + time_dim):
537533
raise Exception(
538-
"Can't figure out how to plot image with "
539-
"shape {}! Images should be be either 2d "
540-
"(grayscale) or 3d (RGB(A), last dimension with 3 or"
541-
" 4 elements).".format(sig.shape))
534+
f"Can't figure out how to plot {sigtype} with "
535+
f"shape {sig.shape}! {sigtype.capitalize()}s should be be either "
536+
f"{2 + time_dim}d (grayscale) or {3 + time_dim}d (RGB(A), last "
537+
"dimension with 3 or 4 elements)."
538+
)
542539
if np.iscomplexobj(sig):
543540
if plot_complex == 'rectangular':
544541
signal_tmp.extend([np.real(sig), np.imag(sig)])
@@ -776,6 +773,7 @@ def animshow(video, framerate=2., as_html5=True, repeat=False,
776773
as_html : `bool`
777774
If True, return an HTML5 video; otherwise return the underying matplotlib animation object
778775
(e.g. to save to .gif). should set to True to display in a Jupyter notebook.
776+
Requires ipython to be installed.
779777
repeat : `bool`
780778
whether to loop the animation or just play it once
781779
vrange : `tuple` or `str`
@@ -832,7 +830,12 @@ def animshow(video, framerate=2., as_html5=True, repeat=False,
832830
Animation, format depends on `as_html`.
833831
834832
"""
835-
833+
if as_html5:
834+
try:
835+
from IPython.display import HTML
836+
except ImportError:
837+
raise ImportError("Unable to import IPython.display.HTML, animshow must be called with "
838+
"as_html5=False")
836839
video = _convert_signal_to_list(video)
837840
video_n_frames = np.array([v.shape[0] for v in video])
838841
if (video_n_frames != video_n_frames[0]).any():

0 commit comments

Comments
 (0)