atlannot.notebook.util module

Notebook utils.

atlannot.notebook.util.create_legend_handles(imgs, region_meta, color_map)[source]

Create the handles of a legend for given images.

Note that you can plot those handles by doing: fig.legend(handles=handles)

Parameters:
  • imgs (list of np.ndarray) – List of all the images containing the labels to legend.

  • region_meta (atlannot.region_meta.RegionMeta) – Region Meta containing all the information concerning the labels.

  • color_map (dict) – Conversion between region labels and the color in the image.

Returns:

handles – List of patches containing the color of the different labels, the value of the label and the name of the region.

Return type:

list of matplotlib.patches.Patch

atlannot.notebook.util.image_grid(image_dict, n_columns=2, plot_width=12, fig_title=None, save_as=None)[source]

Plot images in a grid.

Note that this function returns a matplotlib figure. Because of this if image_grid is the last expression in a jupyter notebook cell, then two identical figures will be plotted. To avoid this either assign the return value of image_grid to a variable or add a semicolon at the end of the line.

Parameters:
  • image_dict (dict) – Mapping image title => image data.

  • n_columns (int) – The number of columns in the plot grid.

  • plot_width (float) – The width of the plot in inches (same as for the figsize parameter in the matplotlib library).

  • fig_title (str or None, optional) – The figure title.

  • save_as (str or pathlib.Path, optional) – Save the figure as the given file.

atlannot.notebook.util.print_misalignments(unfurled_atlas_1, unfurled_atlas_2, file=None)[source]

Print misalignment for every region hierarchy level.

Parameters:
  • unfurled_atlas_1 (np.ndarray) – First atlas of shape (n_level, n_slice, height, width).

  • unfurled_atlas_2 (np.ndarray) – Second atlas of the same shape as unfurled_atlas_1.

  • file – The output file. If None then sys.stdout is used.