Skip to main content

GPU-accelerated tcBF and acBF

This repository provides a fast GPU implementation of aberration-corrected bright-field 4D-STEM (tcBF/acBF) reconstruction.

It is designed to serve as the seed for:

  1. Future native integration of tcBF and acBF into PtyRAD pipeline
  2. Real-time visualization during 4D-STEM data acquisition

The underlying imaging theory and initial CPU implementation of acBF were developed by Dr. Desheng Ma and Dr. Steven Zeltmann [1, 2], while the tcBF method has a longer history; readers are encouraged to read this paper by Dr. Yue Yu [3].

This implementation (fast-acBF) was developed independently focusing on GPU acceleration and integration with the PtyRAD reconstruction framework. It is shared as a working research implementation; interfaces may change as development continues.

Installation guide

Major Dependencies:

  • python >=3.10
  • pytorch >=2.4
  • ptyrad

1. Get the fast-acBF code from GitHub

You can either download the repository as a .zip file and extract it, or use the following command if you have git installed.

git clone https://github.com/chiahao3/fast-acbf

2. Create and Activate the Python Environment

Assuming you're using conda, you can create an independent environment and install the packages with these commands:

# Enter the commands one by one
conda create -n fast-acbf python=3.12 -y
conda activate fast-acbf
cd fast-acbf
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu126
pip install -e .

If you prefer a legacy version of PyTorch, or a different version of CUDA runtime other than CUDA 12.6, see instruction here.

Get Started

  1. Download the demo tBL-WSe2 data "Figure 4.zip" from the Zenodo link
  2. Run the get_acBF.ipynb Jupyter notebook to reconstruct tcBF / acBF images

Data Pipeline Defaults

BFSolver is the main user entry point. By default it uses pipeline="balanced" with automatic policy resolution:

from fast_acbf import BFSolver, Dataset4D

dataset = Dataset4D.from_hdf5("scan.h5", key="array")  # lazy by default

solver = BFSolver(
    dataset=dataset,
    max_alpha=25.0,
    scan_step_size=0.43,
    dk=0.04,
    wavelength=0.04176,
    device="cuda",
)

The solver consumes ImageFFT chunks internally. The policy controls where that FFT cache lives, when it is filled, and how virtual BF images are extracted from the raw 4D data.

Pipeline Intended use Default behavior
speed Small data that can afford temporary materialization Prefer device ImageFFT and, when raw 4D can be materialized and fit in VRAM with vBF/ImageFFT, do a whole-pass device_mask precompute.
balanced General default Cache ImageFFT on device if it fits, otherwise host RAM, otherwise stream. Avoids raw-on-device extraction for lazy disk data unless explicitly requested.
memory Largest data / lowest persistent memory Keep imagefft_storage="none" and compute on the fly, using disk extraction for lazy data.

Advanced users can override the resolved policy:

solver = BFSolver(
    dataset=dataset,
    ...,
    pipeline="balanced",
    imagefft_storage="host",     # auto | device | host | none
    imagefft_fill="precompute",  # auto | precompute | lazy | on_the_fly
    extractor_strategy="auto",   # auto | device_mask | host_mask | disk_*
)

Impossible or wasteful combinations are rejected early with memory/path guidance. For example, extractor_strategy="device_mask" requires persistent ImageFFT storage and imagefft_fill="precompute" because it is a whole-pass route: temporarily move raw 4D to the compute device, extract all vBF images, precompute ImageFFT, then release raw/vBF intermediates.

References

[1] Ma, Desheng, et al. "Information in 4D-STEM: Where it is, and How to Use it." Ultramicroscopy (2026). https://doi.org/10.1016/j.ultramic.2026.114351

[2] Ma, Desheng, David A. Muller, and Steven E. Zeltmann. "Using Aberrations to Improve Dose-Efficient Tilt-corrected 4D-STEM Imaging." Microscopy and Microanalysis (2026). https://doi.org/10.1093/mam/ozag008

[3] Yu, Yue, et al. "Dose-efficient cryo-electron microscopy for thick samples using tilt-corrected scanning transmission electron microscopy." Nature Methods (2025). https://doi.org/10.1038/s41592-025-02834-9

Relevant Repositories

Author

Chia-Hao Lee (cl2696@cornell.edu)

Developed at the Muller Group, Cornell University.

Download files

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

Source Distribution

fast_acbf-0.7.0.tar.gz (70.5 kB view details)

Uploaded Source

Built Distribution

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

fast_acbf-0.7.0-py3-none-any.whl (56.2 kB view details)

Uploaded Python 3

File details

Details for the file fast_acbf-0.7.0.tar.gz.

File metadata

  • Download URL: fast_acbf-0.7.0.tar.gz
  • Upload date:
  • Size: 70.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for fast_acbf-0.7.0.tar.gz
Algorithm Hash digest
SHA256 cc90b9abf83b8a4bea7b191fcfc3169085f7c98037a6cdc1eee0e870ff0b6df1
MD5 21088ff87050b12e38dec7585234565f
BLAKE2b-256 3ae5579561f468e67541d24ae3b2a5cb605a9ae20a31557c4d6408297b6c5d65

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast_acbf-0.7.0.tar.gz:

Publisher: publish_pypi.yml on chiahao3/fast-acbf

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

File details

Details for the file fast_acbf-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: fast_acbf-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 56.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for fast_acbf-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b11128645079d86c46cd72fe896c6cfd840aaed3eeb7aa082cb7a45a653d4a21
MD5 95e0a6d0ff5c19b245398559998846e5
BLAKE2b-256 3c1f909c25d69ab8266f6e36200bd8c23c1829094deb6c97e7427a3b0f499a8a

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast_acbf-0.7.0-py3-none-any.whl:

Publisher: publish_pypi.yml on chiahao3/fast-acbf

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

Release history Release notifications | RSS feed

This release

0.7.0 This release

2 files

Supported by

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