Example Data#

Open in Colab

Dataset page: bobleesj/quantem-data

Electron microscopists often want to try a viewer before finding, copying, or converting their own raw files. quantem.data provides a small public set of real microscopy datasets with calibration attached, so a notebook can say “load the gold HAADF example” and get a Dataset2d object ready for Show2D.

This page uses a real HAADF image of gold nanoparticles. The original array is 4096 by 4096 uint16 data; the tutorial makes a calibrated preview crop so the documentation page opens quickly while the full cached file remains available for local work.

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.

from quantem.widget import Show2D, Show3D
from quantem.widget import datasets as widget_datasets
from quantem.widget.datasets import show2d_gold, show3d_gold

Choose a widget tutorial dataset#

Use quantem.widget.datasets when you want a ready-to-view tutorial payload with clear size names and no Hugging Face path management. These helpers download from the widget-tutorials/ folder in the public dataset repository.

[name for name in widget_datasets.__all__ if name.startswith("show")]
['show1d_ducky',
 'show2d_gold',
 'show3d_gold',
 'show4dstem_gold',
 'showfolder_gold']

Load a calibrated HAADF image#

Load the small Show2D gold example by friendly name. The helper downloads the shared source image once, applies the documentation-sized stride, and returns a calibrated Dataset2d. Future runs reuse the local Hugging Face cache.

preview_dataset = show2d_gold(size="small", verbose=False)
preview = preview_dataset.array
pixel_size_nm = float(preview_dataset.sampling[0])

print(f"Dataset: {preview_dataset.name}")
print(f"Shape:   {preview.shape[0]} x {preview.shape[1]} pixels")
print(f"Counts:  {preview.dtype}")
print(f"Pixel:   {pixel_size_nm:.4f} {preview_dataset.units[0]}/pixel")
Dataset: Gold HAADF preview
Shape:   512 x 512 pixels
Counts:  float32
Pixel:   0.1489 nm/pixel

Show2D preview#

The preview keeps the calibrated pixel size, so the scale bar remains physically meaningful while the documentation page opens quickly.

Show2D(preview_dataset, cmap="inferno")

Show3D from the same source#

show3d_gold derives a moving-crop stack from the same shared HAADF source used by show2d_gold. The source is stored once under widget-tutorials/shared/gold-haadf/full; the Python helpers create the widget-specific view.

stack_dataset = show3d_gold(size="small", verbose=False)

Show3D(stack_dataset, fps=12, cmap="inferno")

Larger files#

The lower-level data APIs still work for larger raw 4D-STEM and EDS datasets. Choose those intentionally because they can be hundreds of MB or several GB.

# Example only: raw-data APIs may expose larger public folders depending on install.
# path = qdata.download("gold_512")
# data = qdata.load("gold_512", det_bin=4)

For shareable widget tutorials, prefer the quantem.widget.datasets helpers because they keep the tutorial payloads grouped under widget-tutorials/ and avoid per-widget copies of the same source data.

Widget tutorial shortcuts#

The widget tutorials use quantem.widget.datasets when the goal is to open a ready-to-view example without thinking about Hugging Face folder names, strides, or monitor-file layout:

from quantem.widget.datasets import (
    show1d_ducky,
    show2d_gold,
    show3d_gold,
    show4dstem_gold,
    showfolder_gold,
)

These helpers use the shared size language small, medium, large, and full. Tutorial payloads are grouped under widget-tutorials/ in the public Hugging Face dataset. Reused sources are stored once, for example Show2D and Show3D both derive from widget-tutorials/shared/gold-haadf/full instead of keeping separate copies.

Upload your own data#

The reference datasets above all live in one shared Hugging Face repo, bobleesj/quantem-data (MIT license), and anyone can contribute with the same three-line protocol:

from quantem.widget.io import upload

upload("/data/session/gold_512/", name="gold_512", folder="4dstem",
       meta={"sampling": [0.5, 0.5], "units": ["A", "A"], "voltage_kV": 300})

Folders of *_master.h5 go under 4dstem/, single images under haadf/, and the meta= dict becomes a meta.json sidecar so widgets pick up the calibration automatically. The full protocol — tokens, your-own-repo uploads via repo=, verifying, and deleting — is in Load and I/O: how do I upload data?.