fast-acbf 0.7.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fast_acbf-0.7.0/LICENSE +165 -0
- fast_acbf-0.7.0/PKG-INFO +148 -0
- fast_acbf-0.7.0/README.md +118 -0
- fast_acbf-0.7.0/pyproject.toml +60 -0
- fast_acbf-0.7.0/setup.cfg +4 -0
- fast_acbf-0.7.0/src/fast_acbf/__init__.py +24 -0
- fast_acbf-0.7.0/src/fast_acbf/core/__init__.py +0 -0
- fast_acbf-0.7.0/src/fast_acbf/core/aberrations.py +165 -0
- fast_acbf-0.7.0/src/fast_acbf/core/acbf.py +226 -0
- fast_acbf-0.7.0/src/fast_acbf/core/functional.py +190 -0
- fast_acbf-0.7.0/src/fast_acbf/core/tcbf.py +53 -0
- fast_acbf-0.7.0/src/fast_acbf/data/__init__.py +5 -0
- fast_acbf-0.7.0/src/fast_acbf/data/bf_extractor.py +149 -0
- fast_acbf-0.7.0/src/fast_acbf/data/bf_preparer.py +275 -0
- fast_acbf-0.7.0/src/fast_acbf/data/dataset4d.py +252 -0
- fast_acbf-0.7.0/src/fast_acbf/data/geometry.py +191 -0
- fast_acbf-0.7.0/src/fast_acbf/data/imagefft.py +197 -0
- fast_acbf-0.7.0/src/fast_acbf/optimization/__init__.py +0 -0
- fast_acbf-0.7.0/src/fast_acbf/optimization/metrics.py +93 -0
- fast_acbf-0.7.0/src/fast_acbf/optimization/refinement.py +919 -0
- fast_acbf-0.7.0/src/fast_acbf/recon/__init__.py +0 -0
- fast_acbf-0.7.0/src/fast_acbf/recon/cache.py +128 -0
- fast_acbf-0.7.0/src/fast_acbf/recon/pipeline.py +376 -0
- fast_acbf-0.7.0/src/fast_acbf/recon/reconstructor.py +311 -0
- fast_acbf-0.7.0/src/fast_acbf/solver.py +890 -0
- fast_acbf-0.7.0/src/fast_acbf/vis/__init__.py +0 -0
- fast_acbf-0.7.0/src/fast_acbf/vis/plotting.py +190 -0
- fast_acbf-0.7.0/src/fast_acbf.egg-info/PKG-INFO +148 -0
- fast_acbf-0.7.0/src/fast_acbf.egg-info/SOURCES.txt +38 -0
- fast_acbf-0.7.0/src/fast_acbf.egg-info/dependency_links.txt +1 -0
- fast_acbf-0.7.0/src/fast_acbf.egg-info/requires.txt +13 -0
- fast_acbf-0.7.0/src/fast_acbf.egg-info/top_level.txt +1 -0
- fast_acbf-0.7.0/tests/test_aberration_state.py +149 -0
- fast_acbf-0.7.0/tests/test_benchmark_vram.py +124 -0
- fast_acbf-0.7.0/tests/test_bf_extractor.py +302 -0
- fast_acbf-0.7.0/tests/test_bf_solver.py +1693 -0
- fast_acbf-0.7.0/tests/test_coordinate_transform.py +250 -0
- fast_acbf-0.7.0/tests/test_dataset4d_normalize.py +296 -0
- fast_acbf-0.7.0/tests/test_pipeline_matrix_script.py +17 -0
- fast_acbf-0.7.0/tests/test_utils.py +180 -0
fast_acbf-0.7.0/LICENSE
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
6
|
+
of this license document, but changing it is not allowed.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
11
|
+
License, supplemented by the additional permissions listed below.
|
|
12
|
+
|
|
13
|
+
0. Additional Definitions.
|
|
14
|
+
|
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
17
|
+
General Public License.
|
|
18
|
+
|
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
|
20
|
+
other than an Application or a Combined Work as defined below.
|
|
21
|
+
|
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
25
|
+
of using an interface provided by the Library.
|
|
26
|
+
|
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
28
|
+
Application with the Library. The particular version of the Library
|
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
|
30
|
+
Version".
|
|
31
|
+
|
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
35
|
+
based on the Application, and not on the Linked Version.
|
|
36
|
+
|
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
38
|
+
object code and/or source code for the Application, including any data
|
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
41
|
+
|
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
|
43
|
+
|
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
|
46
|
+
|
|
47
|
+
2. Conveying Modified Versions.
|
|
48
|
+
|
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
|
51
|
+
that uses the facility (other than as an argument passed when the
|
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
|
53
|
+
version:
|
|
54
|
+
|
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
|
56
|
+
ensure that, in the event an Application does not supply the
|
|
57
|
+
function or data, the facility still operates, and performs
|
|
58
|
+
whatever part of its purpose remains meaningful, or
|
|
59
|
+
|
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
|
61
|
+
this License applicable to that copy.
|
|
62
|
+
|
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
|
64
|
+
|
|
65
|
+
The object code form of an Application may incorporate material from
|
|
66
|
+
a header file that is part of the Library. You may convey such object
|
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
|
68
|
+
material is not limited to numerical parameters, data structure
|
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
|
71
|
+
|
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
|
73
|
+
Library is used in it and that the Library and its use are
|
|
74
|
+
covered by this License.
|
|
75
|
+
|
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
77
|
+
document.
|
|
78
|
+
|
|
79
|
+
4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
|
82
|
+
taken together, effectively do not restrict modification of the
|
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
|
85
|
+
the following:
|
|
86
|
+
|
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
|
88
|
+
the Library is used in it and that the Library and its use are
|
|
89
|
+
covered by this License.
|
|
90
|
+
|
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
92
|
+
document.
|
|
93
|
+
|
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
|
95
|
+
execution, include the copyright notice for the Library among
|
|
96
|
+
these notices, as well as a reference directing the user to the
|
|
97
|
+
copies of the GNU GPL and this license document.
|
|
98
|
+
|
|
99
|
+
d) Do one of the following:
|
|
100
|
+
|
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
+
License, and the Corresponding Application Code in a form
|
|
103
|
+
suitable for, and under terms that permit, the user to
|
|
104
|
+
recombine or relink the Application with a modified version of
|
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
+
Corresponding Source.
|
|
108
|
+
|
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
|
111
|
+
a copy of the Library already present on the user's computer
|
|
112
|
+
system, and (b) will operate properly with a modified version
|
|
113
|
+
of the Library that is interface-compatible with the Linked
|
|
114
|
+
Version.
|
|
115
|
+
|
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
|
117
|
+
be required to provide such information under section 6 of the
|
|
118
|
+
GNU GPL, and only to the extent that such information is
|
|
119
|
+
necessary to install and execute a modified version of the
|
|
120
|
+
Combined Work produced by recombining or relinking the
|
|
121
|
+
Application with a modified version of the Linked Version. (If
|
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
126
|
+
for conveying Corresponding Source.)
|
|
127
|
+
|
|
128
|
+
5. Combined Libraries.
|
|
129
|
+
|
|
130
|
+
You may place library facilities that are a work based on the
|
|
131
|
+
Library side by side in a single library together with other library
|
|
132
|
+
facilities that are not Applications and are not covered by this
|
|
133
|
+
License, and convey such a combined library under terms of your
|
|
134
|
+
choice, if you do both of the following:
|
|
135
|
+
|
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
|
137
|
+
on the Library, uncombined with any other library facilities,
|
|
138
|
+
conveyed under the terms of this License.
|
|
139
|
+
|
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
|
141
|
+
is a work based on the Library, and explaining where to find the
|
|
142
|
+
accompanying uncombined form of the same work.
|
|
143
|
+
|
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
|
145
|
+
|
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
148
|
+
versions will be similar in spirit to the present version, but may
|
|
149
|
+
differ in detail to address new problems or concerns.
|
|
150
|
+
|
|
151
|
+
Each version is given a distinguishing version number. If the
|
|
152
|
+
Library as you received it specifies that a certain numbered version
|
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
|
154
|
+
applies to it, you have the option of following the terms and
|
|
155
|
+
conditions either of that published version or of any later version
|
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
|
160
|
+
|
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
164
|
+
permanent authorization for you to choose that version for the
|
|
165
|
+
Library.
|
fast_acbf-0.7.0/PKG-INFO
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fast-acbf
|
|
3
|
+
Version: 0.7.0
|
|
4
|
+
Summary: GPU-based Bright-field Ptychography Solver for tcBF and acBF built on PtyRAD
|
|
5
|
+
Author-email: Chia-Hao Lee <cl2696@cornell.edu>
|
|
6
|
+
License-Expression: LGPL-3.0
|
|
7
|
+
Project-URL: Repository, https://github.com/chiahao3/fast-acbf
|
|
8
|
+
Project-URL: Changelog, https://github.com/chiahao3/fast-acbf/blob/main/CHANGELOG.md
|
|
9
|
+
Project-URL: PtyRAD, https://github.com/chiahao3/ptyrad
|
|
10
|
+
Keywords: Ptychography
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: h5py
|
|
18
|
+
Requires-Dist: matplotlib
|
|
19
|
+
Requires-Dist: numpy
|
|
20
|
+
Requires-Dist: psutil
|
|
21
|
+
Requires-Dist: scipy
|
|
22
|
+
Requires-Dist: torch>=2.4
|
|
23
|
+
Requires-Dist: torchvision
|
|
24
|
+
Requires-Dist: ptyrad
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
27
|
+
Requires-Dist: pytest-cov>=5.0; extra == "dev"
|
|
28
|
+
Requires-Dist: zarr>=3.0; extra == "dev"
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# GPU-accelerated tcBF and acBF
|
|
32
|
+
|
|
33
|
+
This repository provides a fast GPU implementation of aberration-corrected bright-field 4D-STEM (tcBF/acBF) reconstruction.
|
|
34
|
+
|
|
35
|
+
It is designed to serve as the seed for:
|
|
36
|
+
|
|
37
|
+
1. Future native integration of tcBF and acBF into [PtyRAD](https://github.com/chiahao3/ptyrad) pipeline
|
|
38
|
+
2. Real-time visualization during 4D-STEM data acquisition
|
|
39
|
+
|
|
40
|
+
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].
|
|
41
|
+
|
|
42
|
+
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.
|
|
43
|
+
|
|
44
|
+
## Installation guide
|
|
45
|
+
|
|
46
|
+
**Major Dependencies:**
|
|
47
|
+
- python >=3.10
|
|
48
|
+
- pytorch >=2.4
|
|
49
|
+
- ptyrad
|
|
50
|
+
|
|
51
|
+
### 1. Get the fast-acBF code from GitHub
|
|
52
|
+
You can either download the repository as a .zip file and extract it, or use the following command if you have `git` installed.
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
git clone https://github.com/chiahao3/fast-acbf
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 2. Create and Activate the Python Environment
|
|
59
|
+
Assuming you're using conda, you can create an independent environment and install the packages with these commands:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
# Enter the commands one by one
|
|
63
|
+
conda create -n fast-acbf python=3.12 -y
|
|
64
|
+
conda activate fast-acbf
|
|
65
|
+
cd fast-acbf
|
|
66
|
+
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu126
|
|
67
|
+
pip install -e .
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
If you prefer a legacy version of PyTorch, or a different version of CUDA runtime other than CUDA 12.6, see instruction [here](https://pytorch.org/get-started/previous-versions/).
|
|
71
|
+
|
|
72
|
+
## Get Started
|
|
73
|
+
|
|
74
|
+
1. Download the demo tBL-WSe2 data "Figure 4.zip" from the [Zenodo link](https://doi.org/10.5281/zenodo.15283331)
|
|
75
|
+
2. Run the `get_acBF.ipynb` Jupyter notebook to reconstruct tcBF / acBF images
|
|
76
|
+
|
|
77
|
+
## Data Pipeline Defaults
|
|
78
|
+
|
|
79
|
+
`BFSolver` is the main user entry point. By default it uses
|
|
80
|
+
`pipeline="balanced"` with automatic policy resolution:
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from fast_acbf import BFSolver, Dataset4D
|
|
84
|
+
|
|
85
|
+
dataset = Dataset4D.from_hdf5("scan.h5", key="array") # lazy by default
|
|
86
|
+
|
|
87
|
+
solver = BFSolver(
|
|
88
|
+
dataset=dataset,
|
|
89
|
+
max_alpha=25.0,
|
|
90
|
+
scan_step_size=0.43,
|
|
91
|
+
dk=0.04,
|
|
92
|
+
wavelength=0.04176,
|
|
93
|
+
device="cuda",
|
|
94
|
+
)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
The solver consumes `ImageFFT` chunks internally. The policy controls where that
|
|
98
|
+
FFT cache lives, when it is filled, and how virtual BF images are extracted from
|
|
99
|
+
the raw 4D data.
|
|
100
|
+
|
|
101
|
+
| Pipeline | Intended use | Default behavior |
|
|
102
|
+
| --- | --- | --- |
|
|
103
|
+
| `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. |
|
|
104
|
+
| `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. |
|
|
105
|
+
| `memory` | Largest data / lowest persistent memory | Keep `imagefft_storage="none"` and compute on the fly, using disk extraction for lazy data. |
|
|
106
|
+
|
|
107
|
+
Advanced users can override the resolved policy:
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
solver = BFSolver(
|
|
111
|
+
dataset=dataset,
|
|
112
|
+
...,
|
|
113
|
+
pipeline="balanced",
|
|
114
|
+
imagefft_storage="host", # auto | device | host | none
|
|
115
|
+
imagefft_fill="precompute", # auto | precompute | lazy | on_the_fly
|
|
116
|
+
extractor_strategy="auto", # auto | device_mask | host_mask | disk_*
|
|
117
|
+
)
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Impossible or wasteful combinations are rejected early with memory/path guidance.
|
|
121
|
+
For example, `extractor_strategy="device_mask"` requires persistent ImageFFT
|
|
122
|
+
storage and `imagefft_fill="precompute"` because it is a whole-pass route:
|
|
123
|
+
temporarily move raw 4D to the compute device, extract all vBF images, precompute
|
|
124
|
+
ImageFFT, then release raw/vBF intermediates.
|
|
125
|
+
|
|
126
|
+
## References
|
|
127
|
+
|
|
128
|
+
[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
|
|
129
|
+
|
|
130
|
+
[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
|
|
131
|
+
|
|
132
|
+
[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
|
|
133
|
+
|
|
134
|
+
## Relevant Repositories
|
|
135
|
+
|
|
136
|
+
- [tcBF-STEM](https://github.com/yyu2017/tcBFSTEM)
|
|
137
|
+
- [acBF-STEM](https://github.com/dsmagiya/acBF-STEM)
|
|
138
|
+
- [PtyRAD](https://github.com/chiahao3/ptyrad)
|
|
139
|
+
- [py4DSTEM](https://github.com/py4dstem/py4DSTEM)
|
|
140
|
+
- [quantem](https://github.com/electronmicroscopy/quantem)
|
|
141
|
+
|
|
142
|
+
## Author
|
|
143
|
+
|
|
144
|
+
Chia-Hao Lee (cl2696@cornell.edu)
|
|
145
|
+
|
|
146
|
+
Developed at the Muller Group, Cornell University.
|
|
147
|
+
|
|
148
|
+
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# GPU-accelerated tcBF and acBF
|
|
2
|
+
|
|
3
|
+
This repository provides a fast GPU implementation of aberration-corrected bright-field 4D-STEM (tcBF/acBF) reconstruction.
|
|
4
|
+
|
|
5
|
+
It is designed to serve as the seed for:
|
|
6
|
+
|
|
7
|
+
1. Future native integration of tcBF and acBF into [PtyRAD](https://github.com/chiahao3/ptyrad) pipeline
|
|
8
|
+
2. Real-time visualization during 4D-STEM data acquisition
|
|
9
|
+
|
|
10
|
+
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].
|
|
11
|
+
|
|
12
|
+
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.
|
|
13
|
+
|
|
14
|
+
## Installation guide
|
|
15
|
+
|
|
16
|
+
**Major Dependencies:**
|
|
17
|
+
- python >=3.10
|
|
18
|
+
- pytorch >=2.4
|
|
19
|
+
- ptyrad
|
|
20
|
+
|
|
21
|
+
### 1. Get the fast-acBF code from GitHub
|
|
22
|
+
You can either download the repository as a .zip file and extract it, or use the following command if you have `git` installed.
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
git clone https://github.com/chiahao3/fast-acbf
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### 2. Create and Activate the Python Environment
|
|
29
|
+
Assuming you're using conda, you can create an independent environment and install the packages with these commands:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# Enter the commands one by one
|
|
33
|
+
conda create -n fast-acbf python=3.12 -y
|
|
34
|
+
conda activate fast-acbf
|
|
35
|
+
cd fast-acbf
|
|
36
|
+
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu126
|
|
37
|
+
pip install -e .
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
If you prefer a legacy version of PyTorch, or a different version of CUDA runtime other than CUDA 12.6, see instruction [here](https://pytorch.org/get-started/previous-versions/).
|
|
41
|
+
|
|
42
|
+
## Get Started
|
|
43
|
+
|
|
44
|
+
1. Download the demo tBL-WSe2 data "Figure 4.zip" from the [Zenodo link](https://doi.org/10.5281/zenodo.15283331)
|
|
45
|
+
2. Run the `get_acBF.ipynb` Jupyter notebook to reconstruct tcBF / acBF images
|
|
46
|
+
|
|
47
|
+
## Data Pipeline Defaults
|
|
48
|
+
|
|
49
|
+
`BFSolver` is the main user entry point. By default it uses
|
|
50
|
+
`pipeline="balanced"` with automatic policy resolution:
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from fast_acbf import BFSolver, Dataset4D
|
|
54
|
+
|
|
55
|
+
dataset = Dataset4D.from_hdf5("scan.h5", key="array") # lazy by default
|
|
56
|
+
|
|
57
|
+
solver = BFSolver(
|
|
58
|
+
dataset=dataset,
|
|
59
|
+
max_alpha=25.0,
|
|
60
|
+
scan_step_size=0.43,
|
|
61
|
+
dk=0.04,
|
|
62
|
+
wavelength=0.04176,
|
|
63
|
+
device="cuda",
|
|
64
|
+
)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The solver consumes `ImageFFT` chunks internally. The policy controls where that
|
|
68
|
+
FFT cache lives, when it is filled, and how virtual BF images are extracted from
|
|
69
|
+
the raw 4D data.
|
|
70
|
+
|
|
71
|
+
| Pipeline | Intended use | Default behavior |
|
|
72
|
+
| --- | --- | --- |
|
|
73
|
+
| `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. |
|
|
74
|
+
| `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. |
|
|
75
|
+
| `memory` | Largest data / lowest persistent memory | Keep `imagefft_storage="none"` and compute on the fly, using disk extraction for lazy data. |
|
|
76
|
+
|
|
77
|
+
Advanced users can override the resolved policy:
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
solver = BFSolver(
|
|
81
|
+
dataset=dataset,
|
|
82
|
+
...,
|
|
83
|
+
pipeline="balanced",
|
|
84
|
+
imagefft_storage="host", # auto | device | host | none
|
|
85
|
+
imagefft_fill="precompute", # auto | precompute | lazy | on_the_fly
|
|
86
|
+
extractor_strategy="auto", # auto | device_mask | host_mask | disk_*
|
|
87
|
+
)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Impossible or wasteful combinations are rejected early with memory/path guidance.
|
|
91
|
+
For example, `extractor_strategy="device_mask"` requires persistent ImageFFT
|
|
92
|
+
storage and `imagefft_fill="precompute"` because it is a whole-pass route:
|
|
93
|
+
temporarily move raw 4D to the compute device, extract all vBF images, precompute
|
|
94
|
+
ImageFFT, then release raw/vBF intermediates.
|
|
95
|
+
|
|
96
|
+
## References
|
|
97
|
+
|
|
98
|
+
[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
|
|
99
|
+
|
|
100
|
+
[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
|
|
101
|
+
|
|
102
|
+
[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
|
|
103
|
+
|
|
104
|
+
## Relevant Repositories
|
|
105
|
+
|
|
106
|
+
- [tcBF-STEM](https://github.com/yyu2017/tcBFSTEM)
|
|
107
|
+
- [acBF-STEM](https://github.com/dsmagiya/acBF-STEM)
|
|
108
|
+
- [PtyRAD](https://github.com/chiahao3/ptyrad)
|
|
109
|
+
- [py4DSTEM](https://github.com/py4dstem/py4DSTEM)
|
|
110
|
+
- [quantem](https://github.com/electronmicroscopy/quantem)
|
|
111
|
+
|
|
112
|
+
## Author
|
|
113
|
+
|
|
114
|
+
Chia-Hao Lee (cl2696@cornell.edu)
|
|
115
|
+
|
|
116
|
+
Developed at the Muller Group, Cornell University.
|
|
117
|
+
|
|
118
|
+
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "fast-acbf"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
authors = [
|
|
9
|
+
{ name="Chia-Hao Lee", email="cl2696@cornell.edu" },
|
|
10
|
+
]
|
|
11
|
+
description = "GPU-based Bright-field Ptychography Solver for tcBF and acBF built on PtyRAD"
|
|
12
|
+
keywords = ["Ptychography"]
|
|
13
|
+
readme = "README.md"
|
|
14
|
+
license = "LGPL-3.0"
|
|
15
|
+
license-files = ["LICENSE"]
|
|
16
|
+
requires-python = ">=3.10"
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Development Status :: 4 - Beta",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
]
|
|
22
|
+
dependencies = [
|
|
23
|
+
"h5py",
|
|
24
|
+
"matplotlib",
|
|
25
|
+
"numpy",
|
|
26
|
+
"psutil",
|
|
27
|
+
"scipy",
|
|
28
|
+
"torch>=2.4",
|
|
29
|
+
"torchvision",
|
|
30
|
+
"ptyrad"
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[tool.setuptools]
|
|
34
|
+
package-dir = {"" = "src"}
|
|
35
|
+
|
|
36
|
+
[tool.setuptools.packages.find]
|
|
37
|
+
where = ["src"]
|
|
38
|
+
|
|
39
|
+
[tool.setuptools.dynamic]
|
|
40
|
+
version = {attr = "fast_acbf.__version__"}
|
|
41
|
+
|
|
42
|
+
[project.optional-dependencies]
|
|
43
|
+
dev = [
|
|
44
|
+
"pytest>=8.0",
|
|
45
|
+
"pytest-cov>=5.0",
|
|
46
|
+
"zarr>=3.0",
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
[tool.pytest.ini_options]
|
|
50
|
+
testpaths = ["tests"]
|
|
51
|
+
addopts = "-v --tb=short"
|
|
52
|
+
markers = [
|
|
53
|
+
"regression: tests requiring real data fixtures (skip with -m 'not regression')",
|
|
54
|
+
]
|
|
55
|
+
filterwarnings = ["ignore::UserWarning"]
|
|
56
|
+
|
|
57
|
+
[project.urls]
|
|
58
|
+
Repository = "https://github.com/chiahao3/fast-acbf"
|
|
59
|
+
Changelog = "https://github.com/chiahao3/fast-acbf/blob/main/CHANGELOG.md"
|
|
60
|
+
"PtyRAD" = "https://github.com/chiahao3/ptyrad"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from .solver import BFSolver
|
|
2
|
+
from .core.aberrations import AberrationState
|
|
3
|
+
from .optimization.metrics import QualityMetrics
|
|
4
|
+
from .data.dataset4d import Dataset4D
|
|
5
|
+
from .data.bf_extractor import BFExtractor
|
|
6
|
+
from .data.geometry import DetectorGeometry, ScanGeometry, CoordinateTransform
|
|
7
|
+
from .data.imagefft import ImageFFT
|
|
8
|
+
from .recon.pipeline import PipelineManager, PipelineResolution
|
|
9
|
+
|
|
10
|
+
__version__ = "0.7.0" # 2026.07.30
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"BFSolver",
|
|
14
|
+
"AberrationState",
|
|
15
|
+
"QualityMetrics",
|
|
16
|
+
"Dataset4D",
|
|
17
|
+
"BFExtractor",
|
|
18
|
+
"DetectorGeometry",
|
|
19
|
+
"ScanGeometry",
|
|
20
|
+
"CoordinateTransform",
|
|
21
|
+
"ImageFFT",
|
|
22
|
+
"PipelineManager",
|
|
23
|
+
"PipelineResolution",
|
|
24
|
+
]
|
|
File without changes
|