Skip to main content

scatterem logo

scatterem

4D-STEM reconstruction and differentiable STEM simulations on the GPU, in PyTorch.

PyPI Python versions Documentation Zenodo DOI Licence

scatterem holds the reference implementations of three published methods in electron scattering. Each method comes with its paper, its data and the scripts that make the paper's figures.

Method What it does Paper
FF-STEM Fuses direct (single-side-band) ptychography and tilt-corrected dark field with SSNR-weighted Wiener weights. The image keeps the low-frequency phase contrast and the high-frequency detail. S. You et al., Adv. Sci. 13 (2026) e76620, doi:10.1002/advs.76620
BiP-PRISM Simulates core-loss STEM-EELS by transition-potential multislice, PRISM and the bi-partitioned PRISM algorithm. Full-resolution elemental maps fit on one consumer GPU. P. Pelz, J. Phys. Mater. (2026), doi:10.1088/2515-7639/aebdd0
Elastic PRISM Simulates 4D-STEM with the plane-wave and the beam-partitioned scattering matrix. as used in the BiP-PRISM paper
pip install scatterem                                # FF-STEM and elastic PRISM
CC=g++ pip install "scatterem[eels]" gpaw-data       # adds GPAW wavefunctions for EELS

Install

The install commands are at the top of this page. A CUDA GPU is strongly recommended. The reconstructions are FFT- and kernel-bound, and the NVIDIA Warp kernels need a GPU for anything beyond a small test. If the default torch wheel does not match your driver, install a matching build first.

The eels extra adds GPAW, the all-electron backend for quantitative STEM-EELS. pip builds GPAW from source, and the build needs a C++ compiler (see Installation).

The molab notebook installs the package, fetches one dataset from Zenodo and runs the full FF-STEM reconstruction on a free molab GPU. It sizes the scan to the GPU it gets, so it also works on smaller GPUs.

Run the FF-STEM paper figures

These scripts run the FF-STEM pipeline on the data of the paper figures, with the v0.4 code. Their outputs differ from the published figures and from v0.3. The measured causes are a fix of the tcDF parallax, the new default sign of the ptychography phase, changes to the aberration autofocus, the removal of the scan DC from up-sampled images, the detector frame of the astigmatism in tcDF and the new bright-field disk measurement, which sets dk. The paper figures were made with an earlier version of the code, which this repository does not contain. Run the paper's figure scripts gives the numbers.

The scripts are in this repository, not in the PyPI package. Clone the repository at the release tag and install the same release from PyPI:

git clone --branch v0.4.0 https://github.com/scatterem/scatterem
cd scatterem
pip install scatterem==0.4.0

Each script downloads its dataset from Zenodo on the first run and checks it by md5. You only set where the data goes:

export FFSTEM_DATA_ROOT=/path/with/space
python experiments/ff_stem/Fig2_carbon.py
Script Specimen Download Peak GPU memory
Fig2_carbon.py amorphous carbon 0.34 GB 0.8 GiB
Fig2_Co3O4.py Co₃O₄ 0.56 GB 1.2 GiB
Fig4_diffraction.py Au, low dose 0.5 GB 5.5 GiB (0.4 GiB with scan_edge_crop=224)
Fig1_Gd2O3.py Gd₂O₃ 6.6 GB 21.7 GiB

The peaks were measured with v0.4 on an NVIDIA RTX A6000. Each script also has a molab notebook in notebooks/ that runs it in the browser on a free GPU, for example Open in molab for Fig2_carbon.py.

Use FF-STEM on your own data

from scatterem import Dataset4DStem
from scatterem.reconstruction import run
from scatterem.reconstruction.darkfield import TiltCorrectedDarkFieldConfig
from scatterem.reconstruction.fusion.ffstem import FusedFullFieldConfig
from scatterem.reconstruction.ptychography.direct import (
    AberrationFitConfig,
    DirectPtychographyConfig,
)

dataset = Dataset4DStem.from_array(
    array,                          # (scan_y, scan_x, det_y, det_x)
    energy=300e3,                   # eV
    semiconvergence_angle=19.7e-3,  # rad
    scan_step=0.25,                 # Angstrom
    device="cuda",
)
# Measure dk from the bright-field disk. from_array sets a (1.0, 1.0)
# placeholder, and run() warns if it is still there.
dataset.calibrate_reciprocal_from_bright_field()
threshold = dataset.bright_field_mask_threshold

# The default "combined" fit takes its start from the bright-field shifts.
fit = run(dataset, AberrationFitConfig(correct_order=2, bright_field_mask_threshold=threshold))
dataset.meta = fit.applied_to(dataset.meta)

ptycho = run(dataset, DirectPtychographyConfig(upsample=2.0, bright_field_mask_threshold=threshold)).phase
dark_field = run(dataset, TiltCorrectedDarkFieldConfig(upsample=2.0, bright_field_mask_threshold=threshold)).image
fused = run(dataset, FusedFullFieldConfig(upsample=2.0, n_dark_field_segments=32)).fused

Simulate core-loss STEM-EELS and elastic 4D-STEM

import numpy as np
from scatterem.physics.atom_set import AtomSet
from scatterem.simulation.eels import PrismEelsSimulator

sto = AtomSet(
    np.array([3.905, 3.905, 3.905]),  # box sides (y, x, depth), Angstrom
    np.array([                        # fractional (y, x, depth)
        [0.0, 0.0, 0.0],              # Sr
        [0.5, 0.5, 0.5],              # Ti
        [0.5, 0.5, 0.0],              # O
        [0.5, 0.0, 0.5],
        [0.0, 0.5, 0.5],
    ]),
    np.array([38, 22, 8, 8, 8]),      # atomic numbers
).replicated((4, 4, 8))

sim = PrismEelsSimulator(
    sto,
    eV=100e3,
    semiconvergence_angle=25.0,      # mrad -- note: NOT radians
    pixels=(128, 128),
    scan=(16, 16),
    num_slices=16,
    interpolation_factor=2,
    device="cuda",
)

ti_map = sim.eels_map(
    (22, 2, 1),                      # Ti L: (Z, n, l)
    epsilon=10.0,                    # eV above the ionization threshold
    detector_mrad=25.0,              # EELS collection semi-angle
    inelastic_crop=4,
    partition=dict(n_radial=4),      # partition S1 ...
    partition_s2=dict(n_radial=4),   # ... and S2: this is BiP-PRISM
)
cube = sim.eels_cube((22, 2, 1), epsilon=10.0)   # cube.data: (16, 16, 128, 128)
cbed = sim.elastic_cbed()                        # elastic PRISM, cbed.data: (16, 16, 64, 64)

Quantitative EELS needs the optional gpaw dependency (the eels extra). It supplies all-electron bound and continuum radial wavefunctions. The default, wavefunctions="auto", uses GPAW when it is installed, as v0.3 did. Without GPAW, it falls back to hydrogenic orbitals and emits a HydrogenicFallbackWarning: the pipeline runs, but the numbers are not quantitative. v0.4 puts the transition potentials on a new absolute first-Born scale (Ų/eV). After a best scalar fit, the map shapes differ from v0.3 by 18-61 % with the hydrogenic states. With GPAW, they differ by 0.03-0.6 % for the K, L23 and M45 edges we tested, and by 1.4 % for Fe L1. The hydrogenic studies of the BiP-PRISM paper give different numbers, but their conclusions hold. They also hold when the v0.4 physics layer builds the specimen (structure, potentials, transmissions and probe); the maps then change by up to 12 % and the partitioning errors by up to 10 % of their value. The exact published numbers came from the paper's pre-release code, which uses the v0.3 transition potentials. See the STEM-EELS documentation.

Notes on this release

  • Aberration correction is the sharpness autofocus. It fits aberrations by maximising image sharpness and holds the scan rotation fixed. So meta.rotation must be correct before the fit. The autofocus needs a start for the low orders C10, C12a and C12b. It raises ValueError if it has none: with correction_method="autofocus", C10, C12a and C12b of meta.aberrations zero (a known Cs alone does not count), meta.defocus_guess 0 and a failed bright-field-shift fit. If only these slots are zero, the bright-field-shift fit gives the start. The default "combined" fit does not read meta.aberrations.
  • Sub-pixel dark-field shifts use drizzle by default (shift_method="drizzle", tcdf_shift_method="drizzle" in the fusion). The figure scripts and the notebooks use this default. The paper's figures used Fourier upsampling and a phase ramp (shift_method="fourier"). See Method.
  • The STEM-EELS code is the forward simulation only. There is no EELS reconstruction here.
  • This repository holds the published methods only. The wider scatterem codebase covers more; those parts accompany their own publications.

Authors

The authors of this software are Shengbo You, Nikita Palatkin, Sihan Shao and Philipp Pelz, as listed in CITATION.cff.

The FF-STEM method is the work of the paper's authors: Shengbo You, Georgios Varnavides, Sagar Khavnekar, Nikita Palatkin, Sihan Shao, Mingjian Wu, Daniel Stroppa, Darya Chernikova, Baixu Zhu, Ricardo Egoavil, Stefano Vespucci, Dileep Krishnan, Xingchen Ye, Florian K. M. Schur, Erdmann Spiecker and Philipp Pelz. BiP-PRISM is the work of Philipp Pelz.

CITATION.cff carries the machine-readable metadata for the software and both papers. Please cite the paper for the part you use.

Licence

Apache-2.0. See LICENSE. Third-party notices and data sources are in THIRD-PARTY-NOTICES.md: the MIT notice of quantem, the BSD-3-Clause notice of torchvision, the names kept from py_multislice, abTEM and py4DSTEM (with the Krivanek aberration labels, which v0.4 shares with abTEM), and the scattering-factor table of Lobato and Van Dyck (2014). Please cite that article when you use the table.

Metadata

Release files for scatterem 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for scatterem 0.4.0
File Size Uploaded Provenance Actions
scatterem-0.4.0.tar.gz 1.5 MB With provenance Details for scatterem-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for scatterem 0.4.0
File Interpreter ABI Platform Actions
scatterem-0.4.0-py3-none-any.whl Python 3 none any Details for scatterem-0.4.0-py3-none-any.whl

Total release size: 2.6 MB

Release files / scatterem-0.4.0.tar.gz

Download URL scatterem-0.4.0.tar.gz
Size 1.5 MB
Tags Source
SHA-256 checksum
How to use checksums
b54014a28e8f30a6afc5dd5646fb0afb8f1807a526794c22e4791ab25112ac14
BLAKE2b-256 checksum
How to use checksums
688016bf9d85bd7491fc6bfff8011c11e0dd405b44e0a79f7362a5669ccc793f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Release files / scatterem-0.4.0-py3-none-any.whl

Download URL scatterem-0.4.0-py3-none-any.whl
Size 1.1 MB
Tags Python 3
SHA-256 checksum
How to use checksums
4e8f6167b569bce3a4a8c4f79c9a5b803da5149676e29ec9cda12858f7a0df4b
BLAKE2b-256 checksum
How to use checksums
33eb52499f01d46eaad7d23cc7d3d7c5656694254649ab5f6bb788c49331ec2a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Security for scatterem 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for scatterem-0.4.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page