stitching_plots#

Plot functions and Layout/Alignment plot mixins for rigid and wobbly stitching.

Mixins are injected at runtime via @lazy_mixin, so matplotlib is never imported on a headless cluster unless a plot method is actually called.

Standalone functions duck-type on layout / source / alignment objects and only import from stitching_rigid / stitching_wobbly locally when they need to construct helper objects.

class AlignmentBasePlotMixin[source]#

Bases: object

Plot methods for AlignmentBase, injected via @lazy_mixin.

overlay(**kwargs)[source]#

Return a colour-overlay array of the two sources.

overlay_mip(*args, **kwargs)[source]#

Overlay using max intensity projection.

overlay_overlap(max_shifts=0)[source]#

Return the overlapping sub-arrays of pre and post.

plot(*args, **kwargs)[source]#

Plot the two sources overlayed.

plot_mip(*args, **kwargs)[source]#

Plot using max intensity projection.

plot_overlap(**kwargs)[source]#

Display the overlap region with the 3D viewer.

plot_overlay(**kwargs)[source]#

Overlay and display with 3D viewer.

class AlignmentPlotMixin[source]#

Bases: AlignmentBasePlotMixin

Plot methods for Alignment.

Overrides plot to shift post by the computed displacement before overlaying.

plot(*args, **kwargs)[source]#

Plot the two sources overlayed.

class LayoutPlotMixin[source]#

Bases: object

Plot methods for Layout, injected via @lazy_mixin.

overlay(colors=None, percentile=98, normalize=True, coordinate=None, axis=2)[source]#
plot(colors=None, percentile=98, normalize=True, color_ids=None, coordinate=None, axis=2)[source]#

Plots overlayed sources to check their placement.

Arguments

colorslist of tuple of floats or color names

The optional RGB colors to use.

percentileint

Use this percentile as upper cutoff in the resulting image to enhance contrast.

normalizebool

If True normalize image to floats between 0 and 1.

color_idslist of ints

Use specific color ids for the sources contributing to the layout.

coordinateint or None

Optional coordinate at which to take a slice.

axisint

Optional axis to take the slice in.

Returns

imagearray

A color image.

plot_alignments(cmap=None, annotate=True, axes=None)[source]#

Overlays and plots regions to check the alignment of this layout.

Arguments

cmapcolormap

The color map to use to color the regions.

annotatebool

Use annotation or not.

axestuple of ints

Axes to use if sources are larger than 2d.

plot_regions(cmap=None, annotate=True, axes=None)[source]#

Overlays and plots regions to check the alignment of this layout.

Arguments

cmapcolormap

The color map to use to color the regions.

annotatebool

Use annotation or not.

axestuple of ints

Axes to use if sources are larger than 2d.

class WobblyAlignmentPlotMixin[source]#

Bases: object

Plot methods for WobblyAlignment, injected via @lazy_mixin.

overlay_mip_wobbly(overlap=True, mip_axis=None, percentile=98, normalize=True)[source]#

Colour MIP overlay of the wobbly alignment.

plot_mip_wobbly(overlap=True, mip_axis=None, percentile=98)[source]#

Display wobbly MIP overlay with matplotlib.

plot_overlay_wobbly()[source]#

Display wobbly overlay with 3D viewer.

class WobblyLayoutPlotMixin[source]#

Bases: object

Plot methods for WobblyLayout, injected via @lazy_mixin.

alignment_info(tile_position, coordinate, plot=True, use_displacements=True, **kwargs)[source]#

Diagnostic: gather alignment info and optionally overlay a slice.

plot_wobble()[source]#

Plot per-alignment displacement curves.

layout_along_axis_mip(src1, src2, axis=2, depth=10, max_shifts=10, ranges=None, verbose=False)[source]#

Build a Layout from MIP-projected sources.

layout_coloring(layout, colors=None, color_ids=None)[source]#

Assign colours to sources based on adjacency colouring.

overlay_along_axis_mip(src1, src2, axis=2, depth=10, max_shifts=10, ranges=None, verbose=False, **kwargs)[source]#

Build a colour overlay of a MIP-projected alignment.

overlay_layout(layout, colors=None, percentile=98, normalize=True, color_ids=None)[source]#

Build a colour-overlay array of all sources in a layout.

Arguments

layoutLayout

The layout with the sources to overlay.

colorslist of colours, 'ids', or None

RGB colours, or 'ids' to return per-channel arrays.

percentileint

Upper cutoff percentile for contrast enhancement.

normalizebool

Normalize to [0, 1] floats.

color_idslist of int or None

Explicit colour index per source.

Returns

imagearray

A colour image (or list of single-channel images when colors='ids').

overlay_sources(sources, colors=None, percentile=98, normalize=True)[source]#

Overlays the sources to check their placement.

Arguments

sourceslist of Source

The sources to overlay.

colorslist of tuple of floats or color names

The optional RGB colors to use.

percentileint

Use this percentile as upper cutoff in the resulting image to enhance contrast.

normalizebool

If True normalize image to floats between 0 and 1.

Returns

imagearray

A color image.

plot_alignments(alignments, sources=None, axes=None, annotate=True, min_quality=-inf, cmap=None)[source]#

Plot alignment edges coloured by quality.

plot_along_axis_mip(src1, src2, axis=2, depth=10, max_shifts=10, ranges=None, verbose=False, **kwargs)[source]#

Plot a MIP-projected alignment.

plot_layout(layout, colors=None, percentile=98, normalize=True, color_ids=None)[source]#

Overlays and plots sources in a layout to check alignment.

..Note::

For 2-D layouts uses matplotlib; for 3-D uses Plot3d.

Arguments

layoutLayout class

The layout to use for plotting.

colorslist of colors or None

The optional RGB colors to use.

percentileint

Use this percentile as upper cutoff in the resulting image to enhance contrast.

normalizebool

If True normalize image to floats between 0 and 1.

Returns

imagearray

A color image of the overlayed sources.

plot_regions(regions, sources=None, cmap=None, annotate=True, axes=None)[source]#

Overlays and plots regions to check the alignment.

Arguments

regionslist of Region classes

The regions to plot.

sourceslist of Source or None

Sources used for annotation ids.

cmapcolormap

The color map to use to color the regions.

annotatebool

Use annotation or not.

plot_sources(sources, colors=None, percentile=98, normalize=True)[source]#

Overlays and plots sources in a layout to check alignment.

Arguments

sourceslist of Source

The sources to overlay.

colorslist of colors or None

The optional RGB colors to use.

percentileint

Use this percentile as upper cutoff in the resulting image to enhance contrast.

normalizebool

If True normalize image to floats between 0 and 1.

Returns

imagearray

A color image of the overlayed sources.