Show3D#
- class quantem.widget.Show3D(**kwargs: Any)[source]#
Bases:
AnyWidgetInteractive 3D stack viewer with advanced features for electron microscopy.
View a stack of 2D images along a specific dimension (e.g., defocus sweep, time series, depth stack, in-situ movies). Includes playback controls, statistics panel, ROI selection, FFT view, and more.
- Parameters:
data (array_like) – 3D array of shape (N, height, width) where N is the stack dimension.
labels (list of str, optional) – Labels for each slice (e.g., [“C10=-500nm”, “C10=-400nm”, …]). If None, uses slice indices.
title (str, optional) – Title to display above the image.
cmap (str or Colormap, default Colormap.MAGMA) – Colormap name. Use Colormap enum (Colormap.MAGMA, Colormap.VIRIDIS, etc.) or string (“magma”, “viridis”, “gray”, “inferno”, “plasma”).
vmin (float, optional) – Minimum value for colormap. If None, uses data min.
vmax (float, optional) – Maximum value for colormap. If None, uses data max.
pixel_size (float, optional) – Pixel size in Å for scale bar display.
log_scale (bool, default False) – Use log scale for intensity mapping.
auto_contrast (bool, default False) – Use percentile-based contrast (ignores vmin/vmax).
percentile_low (float, default 1.0) – Lower percentile for auto-contrast.
percentile_high (float, default 99.0) – Upper percentile for auto-contrast.
fps (float, default 5.0) – Frames per second for playback.
timestamps (list of float, optional) – Timestamps for each frame (e.g., seconds or dose values).
timestamp_unit (str, default "s") – Unit for timestamps (e.g., “s”, “ms”, “e/A2”).
disabled_tools (list of str, optional) – Tool groups to lock while still showing controls. Supported:
"display","histogram","stats","playback","view","export","roi","profile","all"."navigation"is accepted as an alias of"playback".disable_* (bool, optional) – Convenience flags mirroring
disabled_tools. Includesdisable_navigationas an alias ofdisable_playback.hidden_tools (list of str, optional) – Tool groups to hide from the UI. Uses the same keys as
disabled_tools.hide_* (bool, optional) – Convenience flags mirroring
disable_*forhidden_tools.
Examples
>>> import numpy as np >>> from quantem.widget import Show3D >>> >>> # View defocus sweep >>> labels = [f"C10={c10:.0f}nm" for c10 in np.linspace(-500, -200, 12)] >>> Show3D(stack, labels=labels, title="Defocus Sweep") >>> >>> # View in-situ movie with timestamps >>> times = np.arange(100) * 0.1 # 100 frames at 10 fps >>> Show3D(movie, timestamps=times, timestamp_unit="s", fps=30) >>> >>> # With scale bar >>> Show3D(data, pixel_size=0.5, title="HRTEM")
Key Methods
- Show3D.set_image(data, labels=None)[source]#
Replace the stack data. Preserves all display settings.
- Show3D.save_image(path: str | Path, *, frame_idx: int | None = None, format: str | None = None, dpi: int = 150) Path[source]#
Save a single frame as PNG, PDF, or TIFF.
- Parameters:
path (str or pathlib.Path) – Output file path.
frame_idx (int, optional) – Frame index to export. Defaults to current slice_idx.
format (str, optional) – ‘png’, ‘pdf’, or ‘tiff’. If omitted, inferred from file extension.
dpi (int, default 150) – Output DPI metadata.
- Returns:
The written file path.
- Return type:
Playback
Line Profile
- Show3D.profile_all_frames(start: tuple | None = None, end: tuple | None = None) ndarray[source]#
Extract the line profile from every frame, returning (n_slices, n_points).
Uses the current profile_line unless start/end are provided. Always samples raw data (ignores diff_mode).
- Show3D.set_profile(start: tuple, end: tuple) Self[source]#
Set a line profile between two points (image pixel coordinates).
ROI
- Show3D.set_roi(row: int, col: int, radius: int = 10) Self[source]#
Set selected ROI position and size (creates one if needed).
- Show3D.duplicate_selected_roi(row_offset: int = 3, col_offset: int = 3) Self[source]#
Duplicate selected ROI with a small offset and auto-assigned color.
- Show3D.roi_rectangle(width: int = 20, height: int = 10) Self[source]#
Set selected ROI shape to rectangle.
- Show3D.roi_annular(inner: int = 5, outer: int = 10) Self[source]#
Set selected ROI shape to annular (donut).
State Persistence