Show3DSlices#

Open in Colab

Show3DSlices links a top slice, an arbitrary-angle side cut, and a 3D volume view. Move the crosshair and rotate the oblique cut to inspect how features extend through depth.

Tip

Run this exact notebook with the Colab badge above, or View or download this notebook on GitHub. For finished results, use HTML and file export to export interactive HTML or share a trusted notebook with widget state.

Hide synthetic data generation code

import quantem.widget as qw
qw.profile()

import numpy as np

# Synthetic scalar inspection volume, not a reconstructed or simulated potential:
# Gaussian columns drift across
# depth, so scrubbing through the slices shows the lattice shift slice by slice.
depth, size = 24, 256
row, col = np.mgrid[0:size, 0:size]
spacing = 20
sites = np.arange(spacing // 2, size, spacing)
volume = np.zeros((depth, size, size), dtype=np.float32)
for slice_index in range(depth):
    shift = 6.0 * np.sin(2 * np.pi * slice_index / depth)  # columns sway with depth
    for r0 in sites:
        for c0 in sites:
            volume[slice_index] += np.exp(-(((row - r0 - shift) ** 2 + (col - c0) ** 2)) / (2 * 2.5 ** 2))
volume.shape, volume.dtype
quantem.widget  0.0.1rc44.dev0
  install       editable checkout
  commit        2d009a7f61ee (dirty checkout)
quantem.gpu     0.0.1rc18.dev0
  install       local build
  commit        not recorded
quantem         0.1.10
  install       installed package
  commit        not recorded
webgpu kernels  fa4a86c (fa4a86cfee85), pinned fa4a86cfee85ea719be2dd98206d2098f0dd3344
torch           2.14.1+cu130  device=cpu
python          3.12.15
((24, 256, 256), dtype('float32'))

Linked top and side cuts#

Pass the stack with depth and lateral calibration so Show3DSlices can draw calibrated scale bars. Move the crosshair on the top slice to position the side cut. Adjust the oblique angle to inspect a different direction through the columns. The 3D view shows where those planes cut the volume.

from quantem.widget import Show3DSlices

slices = Show3DSlices(
    volume,
    sampling=(0.3, 0.18, 0.18),
    units=("nm", "nm", "nm"),
    title="Synthetic column volume (arbitrary units)",
)
slices

Use a reconstructed volume#

The array order is (depth, row, col). Sampling supplies the spacing along those same axes; use the actual reconstruction spacing rather than the nominal specimen thickness divided by an assumed count. These synthetic Gaussian values have arbitrary units and are not calibrated atomic potential or phase.

Change the colormap, move the linked crosshair, and rotate the side-cut angle. The depth stretch helps display anisotropic voxels; it does not change their calibration. For one depth slider, playback, and a moving average, open the same volume in Show3D below. A three-plane mean helps inspection but does not improve the reconstruction’s physical resolution.

scrubber = qw.Show3D(volume, sampling=0.18, units="nm", avg_window=3)
scrubber

Keep the comparison interactive#

slices.export_html("depth-slices.html", encoding="full")
scrubber.export_html("depth-playback.html", encoding="full")

encoding="full" preserves the display values rather than quantizing them for a smaller browse file. See HTML export for packaging and browser requirements. Continue with ShowCIF to inspect a known atomic model, or the demo route for the complete sequence.