1. Introduction
4d is a software package for the processing of 4D scanning transmission electron microscopy (4D-STEM) data. A 4D-STEM dataset is a scanned area of a sample in which a full 2D diffraction pattern (a convergent-beam electron diffraction pattern, CBED) is recorded at every probe position β yielding a four-dimensional array of two scan dimensions Γ two detector dimensions. 4d provides a user-friendly graphical environment for importing, calibrating, reconstructing, and interpreting these datasets, covering virtual-detector imaging (bright-field / dark-field), parallax imaging, integrated differential phase contrast (iDPC), and iterative electron ptychography.
4d is a collaborative software project between the labs of Henning Stahlberg, EPFL & UNIL, Knut MΓΌller-Caspary, LMU Munich, and Carsten Sachse, ER-C JΓΌlich. It inherits its architecture and a substantial amount of code from the FOCUS / 2dx electron-microscopy software. 4d is released under the GNU General Public License v3.
Architecturally, 4d is a compiled C++ / Qt 6 desktop application that acts as a graphical front end and project manager. The application itself performs little of the numerical work: instead it organizes your data into projects and runs a tree of Python and shell (Bash or C-shell) processing scripts, presenting each script's parameters, log output, and result images in a consistent interface. This design makes 4d easy to extend β new processing steps are added simply by dropping new scripts into the script tree. Figure 1 shows how these parts fit together.
2. Installation & launch
4d runs on macOS (Intel & Apple Silicon),
Linux (Ubuntu, Fedora/RHEL) and Windows 10/11
(built and run inside the MSYS2 environment). It is built from source. The
full, step-by-step instructions live in the repository, one guide per platform:
docs/installation_osx.md,
docs/installation_linux.md and
docs/installation_windows.md; the
summary below orients you. The Windows guide is a self-contained walkthrough;
the notes below describe macOS and Linux.
Dependencies
Install with your system package manager (Homebrew on macOS, apt/yum on Linux, MSYS2's pacman on Windows):
- Build tools: CMake β₯ 3.16, a C++ compiler,
gh(GitHub CLI). - Libraries: Qt 6, FFTW3, HDF5 + tools, LZ4; on Linux, the X11/GL runtime libraries.
- Shell & tools:
bashandtcsh(the scripts are written in either),gawk, a text editor (e.g.gedit). - Python 3.12 in a dedicated virtual environment, with
numpy,scipy,scikit-learn,py4DSTEM,torch,h5py,hdf5plugin,blosc2,bitshuffleand the other extensions listed in the installation guide. - Optional (CUDA): the NVIDIA CUDA toolkit and
cupyfor GPU-accelerated reconstruction. - MotionCor3 for the drift correction comes with 4d:
on a Mac it is built with 4d and runs on the GPU through Metal; on
Linux, build it with
-DMC3_BACKEND=CUDAor install your own. - Optional external tools: MotionCor2, Zorro, Unblur (drift correction); CTFFIND4, GCTF (CTF); EMAN2, IMOD.
Building 4d
Clone into a dedicated code directory (not ~/4d, which is the default install location) and build:
mkdir ~/Projects && cd ~/Projects
git clone https://github.com/LBEM-CH/4d.git
cd 4d
./build_all
The build script inquires about the install location, checks dependencies,
downloads and compiles the Blosc2 compression library, compiles the 4d source
tree, installs into your chosen location, and updates your shell environment
(e.g. .zshrc). Developers can pass the four choices as arguments
and skip the questions, e.g. ./build_all 1 2 1 1 β install
location, script mode, clean install, and whether to build AI Help mode. Leave
one off and the script asks for it.
On Windows the same command runs in the MSYS2 UCRT64 shell
after the MSYS2 packages of the installation guide are in place; it installs
to C:\Users\<you>\4d. AI Help mode is not available on
Windows yet, so the fourth choice is ignored there.
Launching 4d
Activate your Python virtual environment, then run the 4d binary from the install directory:
source /Users/<you>/venvs/py4d/bin/activate
~/4d/bin/4d
On Windows, start C:\Users\<you>\4d\bin\4d.cmd (from
Explorer, cmd or PowerShell), or 4d in an MSYS2 UCRT64 shell. The
launcher puts the MSYS2 libraries and shells that 4d needs on the PATH; the
Python environment is a Windows one, with its interpreter under
Scripts\.
/Users/<you>/venvs/py4d/bin/python3).
Use absolute paths, not ~. Nearly all processing scripts depend on this
being correct.
3. Core concepts
Projects and project modes
A project is a directory on a fast local disk where all of your data and processing results are stored. When you create a project you choose a project mode, which tailors the tools, parameters, and library columns to a workflow:
| Mode | Purpose |
|---|---|
| 4D-STEM | The main 4D-STEM / electron-ptychography workflow: import, calibrate, reconstruct. Adds the Planning tab. |
| Fibril picking | A mode designed to sit inside an existing RELION project (pointing at
its MotionCorr/ folder) for detecting and analysing
amyloid fibrils; 4d works inside a fibrilpicker/ subfolder
and does not touch RELION's files. Fibrils are picked in the
maximized image inspection view. |
| cryoET | Cryo-electron tomography: each tilt series becomes one dataset, made into a tomogram from its EER movies (RELION, tomotools with MotionCor3, AreTomo2 and IMOD, on the Slurm queue), shown as tilt series, aligned tilt series and tomogram side by side. The raw data are only linked. See cryoET. |
Inside a project, project-level configuration lives in a merge/
subfolder, and every dataset lives in its own subfolder. Datasets
are organized into image groups (including a special
TRASH group). Recently opened projects are remembered and
reappear on startup and under File βΈ Recent Projects.
Datasets and the library
Each imported 4D-STEM acquisition becomes a dataset (historically also called an "image"). All datasets in a project are listed in the Library β a sortable, groupable table where you browse, flag, select, and launch processing. Datasets are stored in 4d's native HDF5 format (see Β§7), which holds the diffraction patterns, scan positions, correction masks, and derived overview images.
The script mechanism β how 4d actually works
This is the key idea behind 4d. Every processing step is a script
β Python (.py), or a shell script (.script/.com)
written in Bash or in the C shell β stored
in the scripts/ tree. Folders in that tree become the
sections and menus you see in the GUI. Each script carries special
header comment lines that the application reads:
| Directive | Effect in the GUI |
|---|---|
# Title: | The script's display name in the menu. |
# MANUAL: | The help / description text shown in the Setup panel and Help dialog (may contain HTML). |
# HELP: <page>.html#<anchor> | The script's page in this manual: it gives the script a ? button in the script list and next to its manual text. |
# DISPLAY: <var> | Names exactly which parameters the GUI shows for that script β the panel is filtered to just these variables. |
Bash or C shell. The first line of a shell script, its
#! line, decides which shell runs it: #!/bin/bash (or
sh) makes it a Bash script, #!/bin/tcsh a C-shell script;
a .sh file without one gets Bash. The two kinds live side by side in
the same folders and are treated alike β only the way the parameters reach the
script follows the shell. Besides the # DISPLAY: parameters, a script
lists the further parameters it needs between the markers
#$end_local_vars and #$end_vars, one per line as an
empty assignment: name="" in Bash, set name = "" in the
C shell. Before a run, 4d replaces each of these with the project's current value
(quoted, so that it stays literal), fills in the paths bin_4d and
proc_4d (the helper programs and the scripts/proc/
directory), the run number run_iteration_number of a
relaunched series, and the settings of the
Preferences, and writes the result as proc/<name>.com in the
working directory, where it is run. What a script hands back is the same in
every language: lines set name = value, # IMAGE: path <label>
and # IMAGE-IMPORTANT: path <label> appended to
LOGS/<name>.results, and on its standard output
: / :: for the two verbosity levels,
<<@progress: N>> for the progress bar,
<<@evaluate>> to have the results re-read while the
script still runs, and a live block: the lines between
<<@live: NAME>> and <<@live-end>>
(each marker on a line of its own) take the place of the block of the same
NAME printed before, in the log window and in the log file, so a table the
script prints again at every poll stays one current table at the end of the
log. Bash scripts find their helpers in scripts/proc/
as initialize.sh, StarFileGenerator.sh and
4d/4d_get_param.sh; the Datasets steps are written this way. The
script list shows the language of each script in its icon (see
Manual Processing).
When you select a script, 4d shows its manual text and its declared parameters (pulling each parameter's label, type, allowed values, and tooltip from the central parameter definitions). You edit the values in the GUI, press Run, and 4d executes the script in your chosen Python environment, streaming its output to a log panel and collecting its result images. The very same scripts are used whether you run them interactively on one dataset (Manual Processing), in a parallel batch on this computer (LocalQueue), or automatically during import.
4. The 4d application (GUI)
Quick start
- Create a project. On launch, the Project initialization wizard opens. Choose Add Project, pick a location on a fast local disk, name it, choose the 4D-STEM mode, and initialize it from master (or copy settings from an existing project).
- Set your Python environment. Open Preferences βΈ Software and enter the activation command and absolute interpreter path.
- Import data. Use the Import tab to bring raw HDF5 files into the project, or run the Import scripts on a dataset (Import 4D STEM β Scan Pattern into HDF5 β Get BF and DF image).
- Browse the Library. Your datasets appear in the Library table. Double-click one to open it for processing.
- Reconstruct. In the per-dataset tab, work through the WASP section top to bottom: calibrate, map defocus, correct drift, then run a ptychography reconstruction (how the ptychography step works).
- Batch or export. Check several datasets in the Library and press Process Selected to run them in parallel via LocalQueue, or use the Export section to hand results to cryoSPARC / RELION.
Startup & project selection
Launching 4d without arguments opens the Project
initialization wizard (pass a project directory on the command line to
skip straight to it). The wizard has three pages:
- Open project β a list whose first row is always Add Project; below it, each recently used project shows its mode icon, name, and full path. Use arrow keys and Next.
- Add project β choose the project path (a fast local disk), a name (auto-filled from the folder), and the mode. If the folder is new, a dialog offers Initialize from master or Copy from existing project.
- Loading project β a progress checklist: registering parameters, finding images on disk, initializing parameters, loading the library, placing the widgets.
Main window & navigation
The title bar shows the version, current project name, and project directory. A horizontal navigation toolbar of large icon buttons switches between full-window views; a header bar above shows the current section's title and an βN Images Selectedβ count. The navigation buttons, in order:
| Button | Opens |
|---|---|
| Mode: β¦ | Not a view: shows the project's program mode (Mode: 4D-STEM or Mode: Fibril picking) with its icon, at the left end of the bar. A click opens Change Project Mode, as on the Project page. |
| Project | Manage the project (rename, mode, repair, image maintenance, parameter search). |
| FT | The Fourier Analyzer (embedded ft tool). |
| Planning | Experiment planning tools (4D-STEM mode only). |
| Import | Automatic import of datasets. |
| Library | The project Library table. |
| Manual | Manual processing of individual datasets. |
| LocalQueue | Parallel batch processing queue on this computer, formerly AutoProcess (button pulses while running). |
| SlurmQueue | The Slurm GPU cluster: its settings, its nodes and your jobs on it (button pulses while you have jobs pending or running). |
| Datasets | Single-particle processing of the whole project with RELION, run again and again while the data come in. |
| Export | Hand-off of the project's results to cryoSPARC, RELION and others. |
| (further tabs) | One tab per top-level script folder with content in the project's mode. |
| Preferences | Application settings. |
| Help | A question box that searches this manual β see Help. |
Menus provide File (Open Project Ctrl+O, Recent Projects, Save Ctrl+S, Quit Ctrl+Q), Options (Preferences), and Help (online help, report an issue, Update, About). Quitting with unsaved changes prompts Save & Quit / Quit Anyway / Cancel.
Library tab
The Library is the table of every dataset in the project. A toolbar sits on top; below, a splitter divides the dataset table (left) from a preview panel (right).
The table
Rows are grouped by image group, with sortable and drag-reorderable columns. The first two columns are fixed: a Select checkbox and a Flag color. The remaining columns are parameters you choose to display (Preferences βΈ LibraryTable). 4d distinguishes two selection concepts, both shown in the status line:
- Highlighted β rows you clicked/shift/ctrl-selected in the view.
- Selected β the checkbox state; this is the set fed to processing.
Toolbar actions
- Process Selected β queue the checked datasets for batch processing.
- Selection: Show selected only Ctrl+X, Select All Ctrl+A, Deselect All, Invert Ctrl+I, Select highlighted Space.
- Flags: set highlighted rows to none / red / green / blue / gold (N/R/G/B/O).
- Groups & files: Add Group Ctrl+F, Rename Group, Move highlighted Ctrl+M, Trash Ctrl+T, Copy to a second project, Save/Load a selection list, Empty Trash.
- Auto Selection Tool β auto-check datasets whose chosen parameter falls in a numeric range (with optional sign-ignore and flag-color filters).
Preview panel
When a real dataset row is current, the preview panel shows its overview images (bright-field, dark-field, iDPC, thumbnail β configured in Preferences βΈ LibraryPanels) with previous/next navigation and a maximize mode. Double-click a dataset to open it in the Manual Processing tab.
Manual Processing tab & the execution view
The Manual tab is where you run scripts on individual datasets. It starts empty (βSelect entries in the library for processing by double-clicking themβ); each opened dataset becomes a closable sub-tab. A sub-tab turns green with a running icon while its script executes and cannot be closed until the script finishes.
Each sub-tab is an execution view β the core βrun a script and see its outputβ surface, also reused by Project utilities, the importer, and custom tabs. Its layout:
- Left tool rail β one button per script module/section (e.g. Prepare, the image sections, project utilities).
- Script list β the scripts in the selected section, with a Python/shell icon (missing scripts show in red) and a Dependent Scripts list you can open in your editor.
- Title bar β the script name, an optional Python environment dropdown (Python scripts only), a Run/Stop play button, Reload & Save results, Save as project default, and Show Help. A progress bar fills the bar while running.
- Setup panel β the script's Manual help text above its declared parameters, with a divider between them that can be dragged. The manual opens as tall as its text; the buttons on its title line make the text smaller or larger (A-/A+) and set its weight (Thin/Normal/Bold), and its font is chosen in Preferences βΈ General βΈ Manual (see The Manual panel). The panel’s title line holds toggles for Use FAST mode, Show manual, Advanced parameters, Show Defaults (Manual Processing tab and the Planning tab’s ScanPattern section only: each parameter's default value, with an arrow that copies it to the parameter), and a parameter search box.
- Output panel β live stdout/stderr with a Verbosity slider (Low/Medium/High); double-click to open the external log browser.
- Results / Images panel β result files and image thumbnails; right-click an image to open it in the viewer, open it in the Fourier Analyzer, or reveal it in the file system. Both panels shrink to what they list when a script is selected or has finished, but stay at least five lines tall, leaving the rest of the column to the File Preview.
- File Preview β the selected result file with its header summary, or its full File Information. Pictures and text are shown as they are and animated GIFs play with a transport bar. 3D MRC maps and stacks open in an interactive volume viewer: drag to turn the volume, scroll to zoom, and double-click for full screen; show it as an iso-surface (with threshold and speck removal), a maximum-intensity projection, or a slice perpendicular to the viewing direction; animate it at 1x, 2x or 4x β turning about a tiltable axis, or sweeping the slice through the volume β and choose the colour scheme, background, perspective and scale bar. 2D MRC images are shown flat in the same viewer and double-click into the full-screen MRC browser, with the local and whole-image Fourier transforms and the fitting of the defocus to the Thon rings; HDF5 files show their information sheet.
Panel-visibility buttons let you hide or show the Parameters, Output, Results, History, and Status panels.
LocalQueue tab (parallel batch processing on this computer)
LocalQueue β called AutoProcess until the SlurmQueue tab came to sit next to it β is the parallel queue processor of this computer. Datasets sent with Process Selected from the Library β or produced by the importer β are processed concurrently. While a queue runs, the LocalQueue navigation button pulses yellowβorange and the corresponding Library rows animate through queued and processing states. This runs the same scripts as Manual Processing; only the timing and parallelism differ.
The tab is built from three panels β Concurrency Selection (how much of the machine the batch may use: parallel jobs, live CPU/RAM/disk read-outs, per-GPU use checkboxes and FAST mode), Processing Queue (the datasets waiting, with Add Images, Prioritize, Clear Selected and Clear All), and Current Status (start/stop, the live throughput and remaining-time read-out, the auto-start option, and a per-dataset progress log).
The ? button on this tab's header bar β and the full description of all three panels, the select β submit β queue workflow, the Library row colours, and a worked throughput example β are on the dedicated AutoProcessing page.
SlurmQueue tab (the GPU cluster: its nodes and your jobs)
SlurmQueue shows the Slurm cluster of Preferences βΈ System βΈ Slurm Batch Queue System. The top of the tab holds the settings of a job on the left β partition, GPUs, cores, memory and time limit, edited here with the same effect, the other Slurm settings staying in Preferences, with a ? button to the page above β and, on the right, a table of the nodes of the configured partition: state, GPU type and memory per GPU, GPUs, CPUs, memory, load and a Busy bar, refreshed at most every 10 s. Hovering a row shows everything Slurm knows about the node; Probe hardware adds the GPU model, driver and CPU of each node through one short job per node.
Below, your Slurm queue: the jobs finished today (from the accounting) first, then the running ones, then the pending ones, coloured by state, with Prioritize, Cancel Selected, Cancel All Mine and Refresh. Jobs are not submitted here: the processing steps that know the batch queue submit them while they run (Utilities βΈ 40 Slurm batch queue β test, WASP βΈ 44 Ptycho β SLURM version). The navigation button pulses while you have jobs pending or running.
Datasets tab β RELION on the particles of all images
The Datasets tab runs the steps that work on the project as a whole: a RELION 2D classification of the particles of the most recent images, an initial 3D model from the best classes, and a STAR file of all particles for processing elsewhere. The window is that of the Manual Processing tab, for the whole project instead of one image, with a pulldown next to the Run button: Launch Y times (1 to 100, or β) turns a run into a series, and for more than one run a second line, Relaunch every X minutes, appears below it β the classification is run again every X minutes on the newest images, starting from its previous classes, so the class averages follow the collection. Launch 1 time runs once; Launch β times runs until stopped; the Run button shows the number of the current run and stops the series when clicked. The ? at the top right opens the detailed page.
Export tab β the results for cryoSPARC, RELION and others
The Export tab collects results from every image of the project
into a folder structure another program can read: the
reconstructed images for cryoSPARC with a
STAR file of their metadata, the
picked fibril coordinates for RELION; four
development exports inherited from Focus await porting and are not shown in
4D-STEM or Fibril picking projects. The export directory, export_basedir, lies inside
merge/ unless given as an absolute path, and the image export can be
run as a simulation first (export_doit = n). The ? at
the top right opens the detailed page; the scripts are listed on the
Export, Stats & Notifications page.
Import tab
The Import tab watches a folder and brings new microscope files into the project as datasets, optionally processing them on arrival. The window is a two-column split of six panels: the left column defines what to import and how (source folder & import mode, import parameters, and the scripts to run on arrival), while the right column drives and monitors the import (status & controls, file-name parsing & delay, and the live files table). The ? button on each panel title β and the one on the IMPORT DATASETS title bar β opens the matching section of the dedicated page.
Planning tab (4D-STEM mode)
Available in 4D-STEM mode, the Planning tab helps you design a 4D-STEM experiment before acquisition:
- Ptychoscopy β plan the analysis method (e.g. iterative vs. SSB) and calibration ranges for probe, detector, pixel size, CTF, and camera length.
- ScanPattern β design the probe scan pattern with the preparation scripts. As in the Manual Processing tab, Show Defaults shows each parameter's default value at the right end of its row, with an arrow that copies it to the parameter.
- ScanInspect β load a scan-position
.starfile and visualize the probe scan pattern as dots on a canvas. Controls include the scan-generator coordinate convention, static/animated display, transparency, probe diameter (nm), animation speed (one slider: drawing speed left of its centre mark, dots per step at full speed right of it), zoom (1β100Γ, with pan and scroll/pinch), and an nm-per-scan-unit scale.
FT tab β Fourier Analyzer
The FT tab embeds the standalone
ft Fourier Analyzer
(maintained in its own ft repository on github and pulled in when 4d is built). It is an interactive tool for loading an
image into a buffer and inspecting its Fourier transform and related analyses,
with a full-screen mode. You can also reach it via the βopen in Fourier
Analyzerβ right-click action on result images. Its Load image
dialog opens by default in the bundled EXAMPLE_IMAGES directory.
The Fourier Analyzer has a manual of its own β tools, theory sections and exercises β at lbem-status.epfl.ch/ft-manual/manual.html, reached from the Help button inside the FT tab. 4d's own Help box covers it too: its AI mode answers questions about the Fourier Analyzer alongside questions about 4d, citing the ft manual's sections.
Project tab (Manage Project)
The Project tab manages project-wide settings and maintenance. The header shows the mode, name, path, and image count, with buttons to Rename Project, Change Project Mode, and Repair Project Links, plus image-maintenance actions (Re-index, Reset Parameters, Renumber, Assign Even/Odd). Below are tabs for Search Parameters (view/edit parameters at project or per-dataset scope), Synchronize Image Parameters, and Utility Scripts.
Preferences
The Preferences dialog has eight pages:
| Page | Settings |
|---|---|
| General | How 4d itself behaves, in four sections: General (startup hint, auto-save configurations, show advanced parameters and default values by default, import-from-EPU default, default verbosity, colored log background); Manual (whether the script manual of the processing windows is shown by default, and its font, size and weight); Overall Font (the interface font); and Viewers, the external programs used to open each file type (viewer details). (details) |
| Microscope | The instrument these data come from: microscope name, Cs, high tension, and whether a phase plate is in use β the defaults the processing scripts fall back on. (details) |
| System | System locations (SCRATCH and FASTDISK scratch disks), the Slurm batch queue of a GPU cluster (login host and SSH access, job resources, shared directory) and the automatic system warning e-mails to the administrator: who is notified, when, and the image-quality thresholds that trigger a warning. (details) |
| Software | Paths to helper programs (editor, log browser) and the Python Environments table β detect environments, set a default, or add a custom one. Configure your Python interpreter here. (details) |
| Parameters | The full parameter editor: add/copy/cut/paste/search parameters, edit each parameter's metadata, filter by program mode. (details) |
| LibraryTable | Which parameters appear as columns in the Library table, and their order. (details) |
| LibraryPanels | The overview/preview images shown in the Library preview panel. (details) |
| Web Server | The status website of the microscope: whether results are gathered in a local status folder, the microscope tag, the folder, and whether the website’s thumbnails are blurred; and, in Manual Web Pages, whether the Help (?) buttons open the manual in a window inside 4d or in the web browser, and at which address. (details) |
On the General (its Viewers section), Microscope and System pages, each parameter row ends with the value 4d was installed with, under the heading Default Values, and an arrow that copies it into the parameter (after a copy, a cross that undoes it) — the construction of the Show Defaults column of the Manual Processing tab, here always shown.
Help
The Help button at the right end of the navigation bar (the blue question mark) opens a box in which a question can be typed, with three ways of answering it:
| Button | What it does |
|---|---|
| Find in manual | Searches every page of this manual and of the embedded Fourier Analyzer's manual, listing each occurrence as a snippet. Clicking a 4d snippet opens that page where the words are β in the help window or in the web browser, whichever Preferences βΈ Web Server βΈ Manual Web Pages is set to, the same as the ? buttons throughout the program. Fourier Analyzer snippets follow the same preference: the copy of that manual installed with 4d in the help window, or its web pages. |
| Ask Google | Runs a Google search restricted to the manual's web address. It finds answers that a word-for-word search cannot, but only covers pages Google has indexed. |
| Activate AI mode | Answers the question directly instead of listing occurrences: a language model running on this computer reads the manual sections that match the question and writes an answer citing them β each citation a numbered link into the manual, listed again under Sources below the answer, where each source first names which manual it comes from (4d or Fourier Analyzer); hovering over any link shows its address. The index covers this manual and the Fourier Analyzer's, so questions about either program land here. Everything runs locally; no question leaves the machine. Activating starts the model, which takes a few seconds β the box reports its progress, and the model then stays warm until 4d quits. The models are normally downloaded when 4d is built, so nothing is fetched here; where that did not happen, the first activation downloads several GB and takes minutes instead. While AI mode is active the button reads Deactivate AI mode, and questions are sent with Ask local AI agent (or simply Enter). AI mode needs a one-time installation of its Python environment, described in docs/INSTALLATION.md β create it once and every later build prepares the models and the search index for you; on a computer without it, the box says what is missing. Find in manual keeps working in AI mode, and the answers of a small local model deserve the same scepticism as any other model's β the cited sources are one click away to verify. |
The banner's corner buttons adjust the box itself: A+ and Aβ change the font size, and Dark mode switches between the manual pages' light look and a dark background with bright text. Both choices are remembered. The link at the top of the box opens the manual's front page. The box stays open while you work, so a page can be read and the program used side by side.
About & Update
Help βΈ About shows the version, revision, and a short about page. Help βΈ Update checks the release server for a newer version, shows release notes (improvements / bug fixes), and offers an Update Version button; a newer version can also prompt you on startup.
5. Processing sections & scripts
The processing steps are organized into sections β the folders
in the scripts/ tree that appear as menus in the execution view.
Within each section, scripts are numbered to indicate their intended order.
Legend: core workflow
alternative engine
experimental.
Planning Tab
Manual Processing Tab
Datasets Tab
Export Tab
Each card above opens a dedicated page listing that category's scripts and what each one does.
6. Parameter groups
Every parameter shown in the GUI is defined centrally, grouped into
parameter groups. Each parameter carries a human-readable label, a
type (text, integer, float, drop-down menu, β¦), a tooltip/legend, an example, and
the program modes in which it applies. Scripts reference these parameters by name
through their # DISPLAY: directives, so the same parameter can appear
in several scripts and its edited value is shared. You can browse and edit them in
Preferences βΈ Parameters (project scope) or in the
Project βΈ Search Parameters tab (project or per-dataset scope).
The parameter groups, in the order they appear:
| Group | Group | Group |
|---|---|---|
| 4D STEM | Method | Electron Dose |
| Parallax | PtychoScopy | Defocus |
| Ptychography | Shadow Montage | Utility |
| Motion correction | Torchslice | Export |
| Fibrils | Flags | Program Technical Data |
| Image File | Import Settings | Ripple filter |
| Drift Correction | Damage model | Image fusion |
7. Data format (HDF5)
4d stores datasets as HDF5 files following the project's version
2.0 electron-ptychography convention (see
docs/CONVENTIONS.md for the full
specification). Diffraction patterns are preferably stored with
Blosc2 compression for efficient storage and fast display.
A stem_dataset file has three main groups:
/header/β metadata as attributes: beam energy, convergence semi-angle, scan rotation/transpose, gain-correction flag, step size, detector calibration, camera type, scan mode, precomputed pattern statistics, detector center, and BF/DF detector radii./data/β the diffraction patterns (dpatterns), correction masks (flatfield_mask,deadpixel_mask), an optionalvacuumProbe, athumbnail, and overview maps (df_map,bf_map,idpc_map)./positions/β real-space probe positions in scan units (units), angstroms (angs), and drift-refined angstroms (shadow).
The dpatterns dataset comes in two layouts:
| Layout | Shape | Used for |
|---|---|---|
| 4D regular grid | [scan_y, scan_x, det_y, det_x] | Regular rectangular scans (requires step_size_angstroms). |
| 3D arbitrary positions | [N, det_y, det_x] | Non-rectangular scans (requires a /positions/ dataset). |
Within 4d, opening an .h5 dataset launches the interactive
4D Full-Screen Browser β
browse the diffraction patterns by scan position and compute DF/BF, shadow and
iDPC reconstructions on the fly.
You can inspect any file with the standard HDF5 tools, e.g.:
h5dump -H mydataset.h5 # structure only
8. Getting help
- In-app: the small
help buttons found throughout the program open the matching page of this
manual in your browser; each script's Show Help button and Setup panel
display that script's own manual text; Help βΈ View Online Help
opens the online documentation. - Ask a question: the Help button at the right end of the navigation bar searches this manual word for word, and its AI mode has a local language model answer the question directly, with citations into this manual and the Fourier Analyzer's β see Help.
- Repository: github.com/LBEM-CH/4d β source, installation guide (docs/INSTALLATION.md), conventions (docs/CONVENTIONS.md), and contributing guidelines.
- Issues & bugs: Help βΈ Report Issue, or open an issue at github.com/LBEM-CH/4d/issues.
- Related tools: py4DSTEM, FOCUS, and the embedded ft Fourier Analyzer.