Skip to content
Merged
42 changes: 27 additions & 15 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
name: Deploy Docs
name: Docs

on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: github-pages
cancel-in-progress: false

jobs:
deploy:
build:
runs-on: ubuntu-latest

environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -33,17 +26,36 @@ jobs:
- name: Install documentation dependencies
run: uv sync --extra docs

- name: Configure GitHub Pages
uses: actions/configure-pages@v5

- name: Build documentation
run: uv run mkdocs build --strict

- name: Upload documentation
if: github.event_name != 'pull_request'
uses: actions/upload-pages-artifact@v4
with:
path: site

deploy:
needs: build
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest

permissions:
pages: write
id-token: write

concurrency:
group: github-pages
cancel-in-progress: false

environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

steps:
- name: Configure GitHub Pages
uses: actions/configure-pages@v5

- name: Deploy documentation
id: deployment
uses: actions/deploy-pages@v4
10 changes: 0 additions & 10 deletions PtyLab/Engines/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,3 @@
from .OPR import OPR
from .qNewton import qNewton
from .zPIE import zPIE


import warnings

warnings.warn(
"`pcPIE` is deprecated. Use `mPIE` with "
"`params.positionCorrectionSwitch = True` instead.",
DeprecationWarning,
stacklevel=2,
)
7 changes: 7 additions & 0 deletions PtyLab/Engines/mPIE.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import logging
import sys
import warnings

import tqdm

Expand Down Expand Up @@ -577,6 +578,12 @@ def __init__(
params: Params,
monitor: Monitor,
):
warnings.warn(
"`pcPIE` is deprecated. Use `mPIE` with "
"`params.positionCorrectionSwitch = True` instead.",
DeprecationWarning,
stacklevel=2,
)
super().__init__(
reconstruction,
experimentalData,
Expand Down
2 changes: 1 addition & 1 deletion PtyLab/Monitor/TensorboardMonitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def update_encoder(

axes["O"].set_title("Original positions")
axes["N"].set_title("Updated positions")
axes["S"].set_title(f"Diff. Mean: {meandiff} $\mu$m")
axes["S"].set_title(rf"Diff. Mean: {meandiff} $\mu$m")

# plot the original one everywhere

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
![Python 3.10+](https://img.shields.io/badge/python-3.10+-green.svg)
[![PyPI](https://img.shields.io/pypi/v/ptylab.svg)](https://pypi.org/project/ptylab/)
![Tests](https://github.com/PtyLab/PtyLab.py/actions/workflows/test.yml/badge.svg)
[![Docs](https://github.com/PtyLab/PtyLab.py/actions/workflows/docs.yml/badge.svg)](https://ptylab.github.io/PtyLab.py/)

[**Getting Started**](#getting-started) | [**Installation**](#installation) | [**Development**](#development) | [**Documentation**](https://ptylab.github.io/PtyLab.py/)

Expand All @@ -10,7 +11,7 @@ PtyLab is an inverse modeling toolbox for Conventional (CP) and Fourier (FP) pty
## Key Features

- **Classic engines**: ePIE, mPIE, mqNewton, qNewton
- **Advanced corrections**: position correction (pcPIE), defocus correction (zPIE), angle correction (aPIE), orthogonal probe relaxation (OPR)
- **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
- **GPU acceleration**: same code runs on CPU and GPU
Expand Down
11 changes: 7 additions & 4 deletions docs/advanced/position-correction.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

Scan position errors are common in practice — mechanical stage imperfections, thermal drift, and vibration all introduce deviations between the nominal encoder positions and the true sample positions. Even small position errors (a fraction of a pixel) degrade reconstruction quality. Position-correcting ptychography estimates and corrects these errors as part of the reconstruction.

## Using `pcPIE`
## Enabling position correction

The `pcPIE` engine extends the standard PIE update with a cross-correlation based position correction step:
Position correction is a cross-correlation based step built into the engines (`mPIE`, `mqNewton`). Turn it on with `params.positionCorrectionSwitch`:

```python
import PtyLab
from PtyLab import Engines

data, recon, params, monitor, engine = PtyLab.easyInitialize(
"data.hdf5",
engine=Engines.pcPIE,
engine=Engines.mPIE,
operationMode="CPM",
)

Expand All @@ -35,6 +35,9 @@ recon.saveResults("corrected_result.hdf5")
| `params.positionCorrectionSwitch` | `False` | Enable position correction |
| `params.positionCorrectionSwitch_radius` | `1` | Search radius (pixels) around each nominal position |

!!! note
`Engines.pcPIE` is deprecated. It is kept as a thin wrapper around `mPIE` for backward compatibility.

!!! tip
Start with a small radius (1–2 pixels). Large radii slow down reconstruction and can cause instabilities early in convergence. Run a few iterations without position correction first to let the object and probe stabilize.

Expand Down Expand Up @@ -76,5 +79,5 @@ recon.positions0 # original pixel positions (before correction)

## Related

- [Engines](../cpm/engines.md) — `pcPIE` and other specialized engines
- [Engines](../cpm/engines.md) — engines that support position correction
- [Configuration Reference](../cpm/configuration.md) — full parameter list
2 changes: 1 addition & 1 deletion docs/api/engines.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
show_root_full_path: false
inherited_members: false

::: PtyLab.Engines.pcPIE.pcPIE
::: PtyLab.Engines.mPIE.pcPIE
options:
show_root_heading: true
show_root_full_path: false
Expand Down
7 changes: 4 additions & 3 deletions docs/cpm/engines.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Engines implement the iterative reconstruction algorithms. All engines inherit f
| `multiPIE` | Multi-mode PIE | Multiple probe or object modes simultaneously |
| `zPIE` | Defocus-correcting PIE | Unknown or uncertain sample-detector distance |
| `aPIE` | Angle-correcting PIE | Reflection geometry with uncertain tilt angle |
| `pcPIE` | Position-correcting PIE | Corrects scan position errors during reconstruction |
| `e3PIE` | Enhanced ePIE | Multislice (thick sample) reconstruction |
| `OPR` | Orthogonal Probe Relaxation | Spatially varying probe (e.g. aberrations, drift) |

Expand Down Expand Up @@ -45,7 +44,9 @@ engine.betaProbe = 0.25 # probe update step size (0 < beta ≤ 1)

These engines use quasi-Newton updates and generally require fewer iterations than PIE-based methods.

### pcPIE (position correction)
### Position correction (mPIE, mqNewton)

`pcPIE` is deprecated; enable position correction on `mPIE` or `mqNewton` instead:

```python
params.positionCorrectionSwitch = True
Expand Down Expand Up @@ -84,7 +85,7 @@ Is the sample thick (multislice)?
No → continue

Are scan positions unreliable?
Yes → pcPIE
Yes → mPIE with params.positionCorrectionSwitch = True
No → continue

Do you want the fastest convergence?
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ For the original publication, see: [PtyLab.m/py/jl: a cross-platform, open-sourc
## Key features

- **Classic engines**: ePIE, mPIE, mqNewton, qNewton
- **Advanced corrections**: position correction (pcPIE), defocus correction (zPIE), angle correction (aPIE), orthogonal probe relaxation (OPR)
- **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
- **GPU acceleration**: same code runs on CPU and GPU
Expand Down
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ plugins:
show_root_heading: true
show_source: true
members_order: source
docstring_options:
returns_named_value: false
- mkdocs-jupyter:
include: ["*.ipynb"]
execute: false
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "ptylab"
version = "0.3.2"
version = "0.3.3"
description = "A cross-platform, open-source inverse modeling toolbox for conventional and Fourier ptychography"
authors = [
{ name = "Lars Loetgering", email = "lars.loetgering@fulbrightmail.org" },
Expand Down
Loading