PtyLab.py: Unified Ptychography Toolbox
Key Features | Getting Started | Installation | Documentation
PtyLab is an inverse modeling toolbox for Conventional (CPM) and Fourier (FPM) ptychography in a unified framework. See the paper for details.
Key Features
- Classic engines: ePIE, mPIE, mqNewton, qNewton
- Advanced corrections: position correction, defocus correction (zPIE), angle correction (aPIE), orthogonal probe relaxation (OPR)
- Multi-modal: multi-slice, multi-wavelength, mixed-state object and probe
- Multiple propagators: Fraunhofer, Fresnel, Angular Spectrum (ASP), scaled ASP, polychromatic variants
- Unified array layout: object and probe are 6D arrays
(nlambda, nosm, npsm, nslice, N, N), i.e. wavelengths, object and probe state mixtures, depth slices, then the frame - GPU acceleration: same code runs on CPU and GPU (NumPy/CuPy)
- Live monitor: follow the object, probe and error metric as the iterations run, along with any corrected parameters such as scan positions, sample-detector distance, wavelength or angle
How it works
PtyLab.py is built around five core classes: ExperimentalData, Reconstruction, Params, Engine and Monitor. Data flows through them to a reconstruction as below:
flowchart LR
file[(HDF5 data)] --> exp[ExperimentalData]
exp --> recon["Reconstruction<br/>(object, probe)"]
exp & recon & params[Params] --> engine["Engine<br/>(ePIE, mPIE, ...)"]
engine -.->|updates| recon
engine <-->|each iteration| corr["Optional Corrections: positions, distance, angle"]
engine -.-> mon[Monitor<br/>live plots]
corr -.-> mon
engine -->|reconstruct| out["Saved to HDF5<br/>object, probe, error, corrected parameters"]
Getting started
Try the demo in Google Colab:
To explore more features, we have extensive tutorials in our documentation.
Installation
Install from PyPI within your virtual environment:
pip install -U ptylab
For faster installs, we recommend uv: uv pip install -U ptylab
For GPU support:
uv pip install -U "ptylab[gpu]" # supports CuPy with CUDA 12
Check whether GPU is correctly configured with uv run ptylab check gpu. For additional information on other extras such as gui, see the installation guide.
Contributing
Contributions are welcome! See the contributing guide for the development setup, tests and how to open a pull request.
Citation
If you use this package, please cite:
@article{Loetgering:23,
author = {Lars Loetgering and Mengqi Du and Dirk Boonzajer Flaes and Tomas Aidukas and Felix Wechsler and Daniel S. Penagos Molina and Max Rose and Antonios Pelekanidis and Wilhelm Eschen and J\"{u}rgen Hess and Thomas Wilhein and Rainer Heintzmann and Jan Rothhardt and Stefan Witte},
journal = {Opt. Express},
number = {9},
pages = {13763--13797},
publisher = {Optica Publishing Group},
title = {PtyLab.m/py/jl: a cross-platform, open-source inverse modeling toolbox for conventional and Fourier ptychography},
volume = {31},
month = {Apr},
year = {2023},
doi = {10.1364/OE.485370},
}
Metadata
Release files for ptylab 0.3.7
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 |
|---|---|---|---|---|
| ptylab-0.3.7.tar.gz | 158.6 kB | With provenance | Details for ptylab-0.3.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ptylab-0.3.7-py3-none-any.whl | Python 3 | none | any | Details for ptylab-0.3.7-py3-none-any.whl |
Total release size: 338.8 kB
Release files / ptylab-0.3.7.tar.gz
| Download URL | ptylab-0.3.7.tar.gz |
|---|---|
| Size | 158.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e6e32ca2ad743ab8cd36f7f46f7d46d1dcf55c16ea03a07ff2df492993a993bf
|
|
BLAKE2b-256 checksum How to use checksums |
5a6b67a462c9d7e81f2a114646372b4d7a17155ca8592695d975378051335e32
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 24, 2026.
Transparency logRelease files / ptylab-0.3.7-py3-none-any.whl
| Download URL | ptylab-0.3.7-py3-none-any.whl |
|---|---|
| Size | 180.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0c7f9b1781a9c93b61db4235273b94c841f8fa42701251350e507c8dede73326
|
|
BLAKE2b-256 checksum How to use checksums |
a34c8e17f80eb2f334a5ec86bb647e550f80a6e52db05efb95fdf96b46f6a326
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 24, 2026.
Transparency logSecurity for ptylab 0.3.7
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 ptylab-0.3.7.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 Oct 24, 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.