py4D-browser-fast-acbf
py4D-browser-fast-acbf wires
fast-acbf into
py4D-browser as a plugin for
GPU-accelerated tcBF and acBF reconstruction. The plugin builds a
fast_acbf.solver.BFSolver from the current py4D-browser datacube, uses CUDA
when available, then MPS on Apple Silicon, and falls back to CPU.
Installation
You can install py4D-browser-fast-acbf directly from PyPI:
pip install py4D-browser-fast-acbf
💡 Note:
- If you install into a fresh Python environment,
py4D-browser,py4DSTEM,fast-acbf, and PyTorch will be installed automatically as dependencies.- If you already have
py4D-browserinstalled, install this plugin into the same Python environment.
A step-by-step guide including creating a fresh Python environment via conda would look like this:
conda create -n py4dgui python=3.12
conda activate py4dgui
pip install py4D-browser-fast-acbf
To install from source instead, e.g. for development:
git clone https://github.com/chiahao3/py4D-browser-fast-acbf.git
cd py4D-browser-fast-acbf
pip install -e '.[test]'
Compatibility
py4D-browser 1.6 introduced a versioned plugin API and only loads plugins that declare the API version they were written for, so plugin and browser versions must match:
| py4D-browser-fast-acbf | py4D-browser | fast-acbf |
|---|---|---|
| 0.7.x | ≥ 1.6.0 | ≥ 0.7.0 |
| 0.6.x | 1.5.x (does not load in 1.6) | ≥ 0.6.0 |
To upgrade an existing environment, upgrade the plugin; pip pulls in py4D-browser 1.6 (and its new PyOpenGL dependency) with it:
pip install -U py4D-browser-fast-acbf
If you need to stay on py4D-browser 1.5.x, pin both packages:
pip install "py4D-browser-fast-acbf<0.7" "py4D-browser<1.6"
py4D-browser prints a "Skipping plugin 'chiahao3.fast_acbf' … does not declare
an api_version" line at startup when an older plugin is paired with 1.6.
Standalone macOS application
The repository also contains a PyInstaller definition for a standalone
py4DGUI.app. Build it on macOS from the repository root, in the same Conda
environment used for py4D-browser:
pip install -e '.[build-app]'
pyinstaller --clean fast_acbf.spec
The bundle is written to dist/py4DGUI.app. The current spec targets macOS 13
or newer, includes Torch's MPS runtime when present, and disables UPX. It
discovers the active environment's Python shared library through sysconfig;
it is not tied to a hardcoded Python minor version. The bundle's version string
is read from the plugin's __version__.
The bundle includes py4D-browser's calibration and metadata plugins alongside
fast-acbf. The logging and legacy tcBF plugins are intentionally omitted (both
are development-only in py4D-browser 1.6), as are 1.6's new Copy Image to Tab,
Open Raw, and TIFF-volume plugins. Signing and notarization are not configured,
so distributed builds require those release steps separately. Build and launch
validation must be performed on macOS; the .app cannot be smoke-tested from
Linux.
Usage
Start py4D-browser:
py4dgui
After loading a 4D datacube, open Plugins > Fast tcBF/acBF. The flyout contains:
- Show Simple Menu: toggles the compact toolbar for orientation, calibration, tcBF/acBF reconstruction, defocus search, volume reconstruction, and manual C10 stepping.
- Advanced Dashboard: opens the dashboard for calibration, aberration/orientation overrides, reconstruction previews, automated refinement, and refinement history.
- Live View: starts reconstructing every new datacube as it arrives (see Live View).
- Configuration: edits fast-acbf physics, device, reconstruction, output, orientation, aberration, refinement, Live View, and Simple Menu settings.
Results appear in their own tabs in py4D-browser's virtual-image pane, next to the built-in virtual image, which the plugin no longer overwrites (see Output).
Simple Menu
Show Simple Menu adds a "Fast acBF" toolbar to the main window:
- tcBF runs a tcBF reconstruction with the configured aberration search. Its drop-down holds Set Dataset Orientation..., Coarse Defocus Search, Refine Defocus, Reset Aberrations, Reconstruct Volume..., and the upscale factor.
- acBF runs an acBF reconstruction. acBF needs real calibration: if the datacube is uncalibrated, the calibration dialog opens first and the run starts once it is saved. Its drop-down holds Set Calibrations..., Reconstruct Volume..., and the same upscale factor.
- Advanced opens the Advanced Dashboard.
- C10 (-df) shows the current defocus; after a first reconstruction, stepping it reconstructs at the new value. The ⚙ button sets the step size.
Reconstruct Volume
Reconstruct Volume... (in both the tcBF and acBF drop-downs) reconstructs a defocus stack centred on the current C10 and opens it as a 3D volume tab. The dialog asks for:
- Defocus range (±) in Å. The stack spans C10 ± this value. It defaults to 50 × T1, where T1 = λ / (4 α²) from the wavelength and max alpha, or ±100 Å when max alpha is unset.
- Number of slices (default 25), evenly spaced across that range.
The volume is displayed with a fixed, compressed depth scale (a depth voxel twice the in-plane pixel) instead of its physical aspect ratio, which would be very elongated along the defocus axis. Adjust it with the volume tab's z-size slider. Volume tabs need a working OpenGL context.
Dashboard
The dashboard is the main workflow surface. It shows the current global calibration, a Display mode selector, reconstruction and side-view image panels, and a compact refinement history.
Display and refinement are intentionally separate:
- Display mode controls the image reconstructed after each run or
refinement (
tcBForacBF). - Refinement mode controls the mode passed to fast-acbf refinement methods.
This means a common workflow is supported directly: refine parameters in tcBF
for speed/stability, then display the updated result in acBF.
Next to the reconstruction, Show picks the probe (|ψ|, |ψ|², complex ψ), the
aberration surface χ, ∇χ or the vBF image shifts. Depth switches between 2D
and 3D: in 3D, Compute stack builds a cached stack over C10 with a slice
slider and an orthogonal view. The probe and χ are drawn
on the output frame's own k grid: in the Detector frame they are PtyRAD's probe and χ
for meas_flipT = the flips (flipud, fliplr, transpose), so the coefficients and
the pictures match a PtyRAD run; in the Scan frame they are rotated with the scan,
like the image. Each image pane's
Export saves the image as TIFF (raw values) or PNG (as displayed); in 3D it also
saves the whole stack (reconstruction, probe view or χ) as one multi-page float32 TIFF
with the pixel size, slice step and the C10 of each slice in its metadata. Default
file names say what was saved (tcbf, acbf, probe_amp, probe_int, probe_cplx,
chi, plus _stack).
Dashboard actions:
- Update Preview applies the current aberration/orientation overrides and
reconstructs using Display mode. The history step is recorded as
manual. - Refine All Params calls
BFSolver.refine_all_params(...)directly. - Refine Flips calls
BFSolver.refine_flips(...)directly. - Refine Scan Rotation calls
BFSolver.refine_scan_rotation(...)with the adaptive Brent method and the configured range or half-width. The configured point count is not used by Brent, and this action currently uses fast-acbf's default Brent tolerance. - Refine Defocus calls
BFSolver.refine_defocus(...)directly. The Simple Menu exposes a coarsemaxsearch and a separate Brent refinement. - Refine Aberrations calls
BFSolver.refine_aberrations(...)directly. - Zero All resets displayed aberration coefficients to zero.
- Reset Orientation resets scan rotation,
flipud,fliplr, andtranspose. - Return to py4D-browser closes the dashboard.
Every dashboard run also updates the reconstruction and probe tabs in py4D-browser. Computing a depth stack only updates the dashboard.
The dashboard history records the step, selected low-order aberration values, rotation, and the scalar quality metric value.
The reconstruction and probe panels both use real-space scale bars.
Live View
Live View reconstructs the current datacube and then every datacube that replaces it, e.g. one pushed by a streaming plugin during acquisition. While it runs:
- A "fast-acbf Live" dock at the top of the window has Start/Stop, Configure..., Auto Focus and Auto Aberrations toggles, and shows the status, frame timing, current C10, and max alpha.
- The result is shown in a single fast-acbf Live View tab, updated in place on every frame. Choose what it shows (tcBF, acBF, probe, χ, or None) with Live output in Configuration's Live View tab.
- Auto Focus and Auto Aberrations re-refine C10 and the aberrations at the intervals set in the same tab.
Stopping Live View closes its tab. Offline runs (Simple Menu, dashboard, volume) are blocked while Live View is active.
Configuration
The Configuration dialog is organized into Run, Physics, Aberrations, Orientation, Refinement, Live View, and Simple Menu tabs.
- Run selects Display mode, acBF algorithm, output frame, New tab per
run, upscale factor and method, optional padding, device, pipeline
(
balanced/speed/memory), basis mode, chunk size, and acBF reconstruction parameters. - Physics controls whether scan step,
dk, and voltage are read from the py4D calibration, whether a circular detector sets max alpha, and calibration-free operation; it also holds max alpha (in px and mrad), scan step, reciprocal pixel size, voltage, wavelength, and max aberration order. - Aberrations edits aberration coefficients and includes Zero All.
- Orientation edits scan rotation,
flipud,fliplr, andtranspose, and includes Reset Orientation. - Refinement selects refinement mode, quality metric, defocus search settings, coarse rotation points for Refine All Params, local scan rotation range/half-width/points/tolerance, and aberration optimizer settings.
- Live View selects the single Live output and the Auto Focus / Auto Aberrations intervals. Its probe and χ outputs are on the same grid as the Advanced Dashboard's.
- Simple Menu selects the aberration search depth and the calibration-free and seeded defocus search widths.
By default the plugin reads py4D-browser calibration for scan step, reciprocal
pixel size, and accelerating voltage. If a circular diffraction detector ROI is
active, it can also infer the collection semiangle from that ROI; otherwise it
detects the BF disk radius from the mean diffraction pattern. You can also set
max alpha, scan step, dk, and voltage/wavelength manually in Configuration.
The Edit Calibration... button opens the py4D-browser calibration dialog
with the current calibration values pre-filled; when the dialog closes, the
dashboard calibration display is refreshed.
Calibration-free mode
When the datacube's calibration is still at py4D-browser's pixel defaults, the Simple Menu's tcBF and orientation steps work directly in pixels instead of placeholder Ångström values. Max alpha is resolved from the BF disk radius in pixels either way. This mode switches off as soon as real calibration is set. acBF always needs real calibration. Toggle it with the calibration-free checkbox in the Physics tab.
Output
Every reconstruction (Simple Menu, dashboard, or orientation run) publishes two tabs in py4D-browser's virtual-image pane:
- fast-acbf tcBF / fast-acbf acBF: the reconstructed image, with a scale bar at the output pixel size (scan step / upscale).
- fast-acbf tcBF probe / fast-acbf acBF probe: the probe amplitude, with a scale bar at the probe's own real-space pixel size, 1 / (N·dk).
By default a new run updates the same pair of tabs in place (re-creating any you closed). Check New tab per run in the Run tab to open a fresh pair for every run instead. Volume reconstructions always open a new volume tab, and Live View uses its own tab (see above). Loading a different datacube closes all of the plugin's tabs and resets its state.
The output image is reconstructed in Display mode. Refinement methods may run in a different Refinement mode.
The zero_insert upscale method is the default for tcBF.
It requires an integer upscale factor and is not supported by acBF. When either
Display mode or Refinement mode is acBF, the plugin uses nearest by default
and disables or coerces incompatible zero_insert selections.
Device Selection
Set Device to:
auto: choose CUDA if available, then MPS if available, otherwise CPU.cuda: force CUDA.mps: force Apple Silicon MPS.cpu: force CPU.
If a cached solver exists and the solver-signature settings have not changed, the plugin reuses it. Changing physical solver inputs, max aberration order, device, pipeline, phase epsilon, padding, or upscale settings rebuilds the solver.
Development
Install the test extra and run the suite with pytest:
pip install -e '.[test]'
pytest
Tests run headless via Qt's offscreen platform plugin, so no display server
is required. The probe-frame cross-checks in tests/test_probe_frame.py compare
against PtyRAD and are skipped when
ptyrad is not installed. See CHANGELOG.md for release notes.
License
GNU GPLv3
py4D-browser-fast-acbf is open source software distributed under a GPLv3 license. It is free to use, alter, or build on, provided that any work derived from py4D-browser-fast-acbf is also kept free and open.
Metadata
Release files for py4D-browser-fast-acbf 0.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| py4d_browser_fast_acbf-0.7.0.tar.gz | 133.0 kB | With provenance | Details for py4d_browser_fast_acbf-0.7.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| py4d_browser_fast_acbf-0.7.0-py3-none-any.whl | Python 3 | none | any | Details for py4d_browser_fast_acbf-0.7.0-py3-none-any.whl |
Total release size: 241.7 kB
Release files / py4d_browser_fast_acbf-0.7.0.tar.gz
| Download URL | py4d_browser_fast_acbf-0.7.0.tar.gz |
|---|---|
| Size | 133.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
21be75df54e0a00f396f2d982224addbb0882d4937e50b6f31e81d3824304b02
|
|
BLAKE2b-256 checksum How to use checksums |
17584ad85b46a10e6ac1ee89a3144fe43ab6a59b77ffa36735cce2532c3e8e98
|
| 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 Dec 1, 2026.
Transparency logRelease files / py4d_browser_fast_acbf-0.7.0-py3-none-any.whl
| Download URL | py4d_browser_fast_acbf-0.7.0-py3-none-any.whl |
|---|---|
| Size | 108.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cd5496382671b9bca6079c911e5e7736fbe8b62b6c9f9aabe1306faf15b86421
|
|
BLAKE2b-256 checksum How to use checksums |
68a3de5d3caefa4445cace81d514c4488cd6976f5e4543b1c6249bae8cdc7008
|
| 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 Dec 1, 2026.
Transparency logSecurity for py4D-browser-fast-acbf 0.7.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.
Attestation for py4d_browser_fast_acbf-0.7.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 Dec 1, 2026.
Transparency logA 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.