From 16a73dc32cd41c9e893536c61fd62c58aa766ce8 Mon Sep 17 00:00:00 2001 From: David Young Date: Sun, 26 Jan 2020 22:41:58 +0800 Subject: [PATCH] Fix errors from missing labels image when opacity is set to 0 - Rather than always skipping images that are invisible, provide an option for whether to create the `AxesImage` object or not - Create these images for Atlas Editor plots since they need to be available if the opacity is increased --- magmap/gui/roi_editor.py | 3 ++- magmap/io/export_stack.py | 3 ++- magmap/plot/plot_support.py | 12 ++++++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/magmap/gui/roi_editor.py b/magmap/gui/roi_editor.py index 7fb4416e7..4934aad5d 100644 --- a/magmap/gui/roi_editor.py +++ b/magmap/gui/roi_editor.py @@ -601,7 +601,8 @@ def show_overview(ax_ov, lev, imgs, cmaps, vmins, vmaxs): show.setdefault("vmaxs", []).append(vmax) show["alphas"] = libmag.pad_seq( config.alphas, len(show["imgs2d"]), 0.9) - plot_support.overlay_images(ax_ov, aspect, origin, **show) + plot_support.overlay_images( + ax_ov, aspect, origin, ignore_invis=True, **show) ax_ov.add_patch(patches.Rectangle( np.divide(patch_offset, downsample), *np.divide(roi_size[0:2], downsample), diff --git a/magmap/io/export_stack.py b/magmap/io/export_stack.py index dbea348d7..693b00af0 100644 --- a/magmap/io/export_stack.py +++ b/magmap/io/export_stack.py @@ -170,7 +170,8 @@ def _build_stack(ax, images, process_fnc, rescale=1, aspect=None, # a nested list containing a list for each image, which in turn # contains a list of artists for each channel ax_imgs = plot_support.overlay_images( - ax, aspect, origin, imgs, None, cmaps_all, alphas) + ax, aspect, origin, imgs, None, cmaps_all, alphas, + ignore_invis=True) if colorbar and len(ax_imgs) > 0 and len(ax_imgs[0]) > 0: # add colorbar with scientific notation if outside limits cbar = ax.figure.colorbar(ax_imgs[0][0], ax=ax, shrink=0.7) diff --git a/magmap/plot/plot_support.py b/magmap/plot/plot_support.py index 6c64e81c7..ec15dd52c 100644 --- a/magmap/plot/plot_support.py +++ b/magmap/plot/plot_support.py @@ -26,7 +26,7 @@ def imshow_multichannel(ax, img2d, channel, cmaps, aspect, alpha, vmin=None, vmax=None, origin=None, interpolation=None, - norms=None, nan_color=None): + norms=None, nan_color=None, ignore_invis=False): """Show multichannel 2D image with channels overlaid over one another. Applies :attr:`config.transform` with :obj:`config.Transforms.ROTATE` @@ -55,6 +55,8 @@ def imshow_multichannel(ax, img2d, channel, cmaps, aspect, alpha, vmin=None, norms: List of normalizations, which should correspond to ``cmaps``. nan_color (str): String of color to use for NaN values; defaults to None to use "black". + ignore_invis (bool): True to give None instead of an ``AxesImage`` + object that would be invisible; defaults to False. Returns: List of ``AxesImage`` objects. @@ -102,7 +104,7 @@ def imshow_multichannel(ax, img2d, channel, cmaps, aspect, alpha, vmin=None, if is_alpha_seq: alpha_plane = alpha[chl] img_chl = None - if alpha_plane > 0: + if not ignore_invis or alpha_plane > 0: # skip display if alpha is 0 to avoid outputting a hidden image # that may show up in other renderers (eg PDF viewers) img_chl = ax.imshow( @@ -127,7 +129,7 @@ def imshow_multichannel(ax, img2d, channel, cmaps, aspect, alpha, vmin=None, def overlay_images(ax, aspect, origin, imgs2d, channels, cmaps, alphas, - vmins=None, vmaxs=None): + vmins=None, vmaxs=None, ignore_invis=False): """Show multiple, overlaid images. Wrapper function calling :meth:`imshow_multichannel` for multiple @@ -157,6 +159,8 @@ def overlay_images(ax, aspect, origin, imgs2d, channels, cmaps, alphas, vmaxs: A list of vmaxs for each image; defaults to None to use :attr:``config.vmax_overview`` for the first image and None for all others. + ignore_invis (bool): True to avoid creating ``AxesImage`` objects + for images that would be invisible; defaults to False. Returns: Nested list containing a list of ``AxesImage`` objects @@ -219,7 +223,7 @@ def fill(fill_with, chls, filled=None, pad=None): ax_img = imshow_multichannel( ax, img, channels[i], cmap, aspect, alphas[i], vmin=vmins[i], vmax=vmaxs[i], origin=origin, interpolation="none", - norms=norm, nan_color=nan_color) + norms=norm, nan_color=nan_color, ignore_invis=ignore_invis) ax_imgs.append(ax_img) return ax_imgs