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:
- Future native integration of tcBF and acBF into PtyRAD pipeline
- 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
- Download the demo tBL-WSe2 data "Figure 4.zip" from the Zenodo link
- Run the
get_acBF.ipynbJupyter 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc90b9abf83b8a4bea7b191fcfc3169085f7c98037a6cdc1eee0e870ff0b6df1
|
|
| MD5 |
21088ff87050b12e38dec7585234565f
|
|
| BLAKE2b-256 |
3ae5579561f468e67541d24ae3b2a5cb605a9ae20a31557c4d6408297b6c5d65
|
Provenance
The following attestation bundles were made for fast_acbf-0.7.0.tar.gz:
Publisher:
publish_pypi.yml on chiahao3/fast-acbf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fast_acbf-0.7.0.tar.gz -
Subject digest:
cc90b9abf83b8a4bea7b191fcfc3169085f7c98037a6cdc1eee0e870ff0b6df1 - Sigstore transparency entry: 2295800453
- Sigstore integration time:
-
Permalink:
chiahao3/fast-acbf@e1e8ab49db0e8d444d10d6cec2b51fd4869d27ee -
Branch / Tag:
refs/tags/v0.7.0 - Owner: https://github.com/chiahao3
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_pypi.yml@e1e8ab49db0e8d444d10d6cec2b51fd4869d27ee -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b11128645079d86c46cd72fe896c6cfd840aaed3eeb7aa082cb7a45a653d4a21
|
|
| MD5 |
95e0a6d0ff5c19b245398559998846e5
|
|
| BLAKE2b-256 |
3c1f909c25d69ab8266f6e36200bd8c23c1829094deb6c97e7427a3b0f499a8a
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fast_acbf-0.7.0-py3-none-any.whl -
Subject digest:
b11128645079d86c46cd72fe896c6cfd840aaed3eeb7aa082cb7a45a653d4a21 - Sigstore transparency entry: 2295800610
- Sigstore integration time:
-
Permalink:
chiahao3/fast-acbf@e1e8ab49db0e8d444d10d6cec2b51fd4869d27ee -
Branch / Tag:
refs/tags/v0.7.0 - Owner: https://github.com/chiahao3
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_pypi.yml@e1e8ab49db0e8d444d10d6cec2b51fd4869d27ee -
Trigger Event:
release
-
Statement type: