Skip to main content

Minimal ndarray viewer for Jupyter notebooks, for interactive exploration of image data in notebooks.

Project description

notebook-nd-viewer

Status Latest Release CI Coverage Python Package Manager Linter Type Checker

notebook-nd-viewer provides a small, copyable ndarray image viewer for Jupyter notebooks. It is intended for quick interactive inspection of 2D images, Z-stacks, and channel images without introducing a full image-viewer application into an analysis notebook.

The public Python import package is nb_nd_viewer.

Features

  • Display 2D image planes from NumPy-compatible arrays.
  • Use axis labels to browse stack dimensions with notebook sliders.
  • Mark one axis as channels with C and inspect channels individually, as RGB overlays, or side by side.
  • Configure channel names and Matplotlib-compatible channel colors.
  • Adjust display contrast with absolute min/max or percentile thresholds.
  • Downsample large rendered planes by default to keep notebook interaction responsive.

Display controls only affect rendering. They do not modify, mask, or rescale the source array.

Installation

From another project, install the package into an environment that can run Jupyter widgets:

uv add notebook-nd-viewer

Or with pip:

pip install notebook-nd-viewer

Do not run either command from inside this repository: uv add records a dependency in the current project, and a project should not install itself as a dependency.

For local development inside this repository:

git clone https://github.com/Darlokt/notebook-nd-viewer.git
cd notebook-nd-viewer
uv sync --dev

If you use classic Notebook, JupyterLab, VS Code notebooks, or another frontend, make sure that ipywidgets is enabled for that environment.

Usage

import numpy as np

from nb_nd_viewer import view_image_layers

image = np.random.default_rng(0).normal(size=(12, 256, 256))

view_image_layers(image, axis_order="ZYX")

axis_order must contain one label per array dimension. When both Y and X are present, they are rendered as the image plane with Y as rows and X as columns, no matter where they appear in axis_order. Other non-channel axes become layer sliders.

If either Y or X is missing, the viewer falls back to positional behavior: the last two non-channel axes are rendered in their listed order, and earlier non-channel axes become layer sliders. This keeps arbitrary labels such as AB, TZR, or labels with only one of Y/X working as before.

For channel data, mark the channel axis with C:

image = np.random.default_rng(0).normal(size=(8, 3, 256, 256))

view_image_layers(
    image,
    axis_order="ZCYX",
    channel_names=("DAPI", "Actin", "Tubulin"),
    channel_colors=("blue", "green", "magenta"),
)

axis_order="ZCXY" also renders rows as Y and columns as X; only the underlying array-axis positions differ.

Large image planes are downsampled before rendering by default:

view_image_layers(
    image,
    axis_order="ZCYX",
    max_render_pixels=1_000_000,
    render_downsampling="stride",
)

Set max_render_pixels=None or render_downsampling="none" to render every source pixel.

API

view_image_layers(
    image,
    axis_order,
    channel_names=None,
    channel_colors=None,
    figsize=(6, 6),
    cmap="gray",
    *,
    continuous_update=False,
    max_render_pixels=1_000_000,
    render_downsampling="stride",
)

Parameters:

  • image: NumPy-compatible image array.
  • axis_order: axis labels matching image.ndim; use C for the optional channel axis. When both Y and X are present, they define image rows and columns; otherwise the last two non-channel axes are rendered.
  • channel_names: optional names for the channel axis.
  • channel_colors: optional Matplotlib-compatible colors for channel rendering.
  • figsize: Matplotlib figure size used before notebook scaling.
  • cmap: colormap for non-channel images.
  • continuous_update: redraw continuously while dragging sliders when True.
  • max_render_pixels: maximum rendered pixels per 2D plane; use None to disable pixel-count based downsampling.
  • render_downsampling: one of "stride", "nearest", "bilinear", "bicubic", or "none".

Development

This project uses uv for dependency management:

uv sync

Run the main quality gates before submitting changes:

uv run ruff format src tests notebooks
uv run ruff check src tests notebooks
uv run ty check
uv run pytest

The default pytest configuration runs unit and integration tests while excluding tests marked external. Tests under tests/unit/ and tests/integration/ are marked automatically from their path, so focused runs can use:

uv run pytest -m unit
uv run pytest -m integration

Coverage is configured with a 90% minimum:

uv run pytest --cov

Install the repository's pre-commit hooks with:

uv run prek install

Project Layout

notebook-nd-viewer/
├── src/nb_nd_viewer/    # importable package
├── tests/unit/          # focused unit tests
├── tests/integration/   # public API and workflow tests
├── notebooks/           # Example notebooks
├── pyproject.toml       # package metadata and tool configuration
└── uv.lock              # locked development environment

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

notebook_nd_viewer-0.2.0.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

notebook_nd_viewer-0.2.0-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file notebook_nd_viewer-0.2.0.tar.gz.

File metadata

  • Download URL: notebook_nd_viewer-0.2.0.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for notebook_nd_viewer-0.2.0.tar.gz
Algorithm Hash digest
SHA256 daf52ca98e8bec88f4cbb7b5cc133fda8deef7b731337290e13f9989f8f7dc12
MD5 0ebb7d3a5ea6975b20498e2bcf6daf07
BLAKE2b-256 2b995d6c5a9973197f4b2bb6d6183d8eb8b0f763ab373f124ac34845c8cfd308

See more details on using hashes here.

Provenance

The following attestation bundles were made for notebook_nd_viewer-0.2.0.tar.gz:

Publisher: publish.yml on Darlokt/notebook-nd-viewer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file notebook_nd_viewer-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for notebook_nd_viewer-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 33ba653c48aca03d761a3b14a8e961eabf94203ef603c4ac2bf9154e86d2a3cf
MD5 a2757ce2bb4885809c41bee111153981
BLAKE2b-256 a6e5af8e481085696c2a47f677dde8f6e9bb821e0a53d5fe2ff29fc7a1a6c06e

See more details on using hashes here.

Provenance

The following attestation bundles were made for notebook_nd_viewer-0.2.0-py3-none-any.whl:

Publisher: publish.yml on Darlokt/notebook-nd-viewer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page