Getting started¶
Two steps on real data: install pySRX in your project, then reconstruct a lattice SIM stack in a few lines. Then measure and plot the result.
1. Install¶
pySRX is used from a project repository (for example LF4D-Recon or
Elyra-SIM-Recon) and runs with pixi. Pixi builds one
reproducible environment from the project's pixi.toml and pixi.lock
(conda-forge, Python 3.12, linux-64), so everyone gets exactly the same
packages. Install pixi once (see pixi.sh for Windows and
macOS):
curl -fsSL https://pixi.sh/install.sh | bash
The project adds pySRX as a git submodule at dependency/pySRX and installs
it editable, so a fix made while working on a project lands in pySRX directly.
git submodule add git@github.com:Oxford-Zeiss-Centre-of-Excellence/pySRX.git dependency/pySRX
git submodule update --init --recursive
In the project's pixi.toml:
[pypi-dependencies]
pysrx = { path = "dependency/pySRX", editable = true }
Then pixi install.
git clone --recurse-submodules <project-url>
# or, in an existing clone
git submodule update --init --recursive
pixi install
flowchart LR
L["<b>pixi.toml + pixi.lock</b><br/>one locked recipe<br/>conda-forge, Python 3.12"]
L -- pixi install --> D["<b>default</b><br/>PyTorch on the CPU<br/><code>pixi run python my_script.py</code>"]
L -- pixi install --> C["<b>cuda</b><br/>PyTorch for CUDA 12, CuPy<br/><code>pixi run -e cuda python my_recon.py</code>"]
One locked recipe, the same packages on every machine.
Reconstructions run in a CUDA environment; everything else, including
pysrx.metrics, runs on a CPU.
Check that it imports:
pixi run python -c "import pysrx; print(pysrx.__version__)"
Commit the submodule pointer in the project whenever it depends on a newer pySRX commit.
| Extra | Packages | Notes |
|---|---|---|
gpu |
cupy-cuda12x |
CuPy kernels where they are faster than PyTorch |
io |
tanoa |
OME-Zarr reading and writing; a private sibling repository, not installed in CI |
sr-io |
tifffile, mrcfile |
the legacy SR-Metrics file formats |
2. Reconstruct in a few lines¶
The input is one ZEISS Elyra lattice SIM stack, converted from CZI to OME-Zarr by tanoa: 13 raw phases per plane, each the sample under a shifted lattice of light.

One plane of the raw data: the 13 phases look almost the same, because the lattice is finer than the optics can show. Their mean is the pseudo-widefield image. MT-CO1 (mitochondria), 488 nm, 62.6 nm camera pixels. Imaging: Robert Mitchell, Clarke Group, KIR, Oxford.
import numpy as np, torch
from pysrx.io import load_phases
from pysrx.optics.confocal import ConfocalOptics
from pysrx.optics.sim import LatticeSIM, estimate_pattern
from pysrx.forward.sim import SimOperator
from pysrx.solvers.opsolve import rl_op, fit_field_op
ph = load_phases("cell.ome.zarr", channels=[0]) # (C, 13, Z, Y, X) camera counts
raw = np.clip(ph.data[0] - 92.0, 0, None).astype(np.float32) # minus the camera offset
px_um, dz_um = ph.pixel_um, ph.z_um
lat = LatticeSIM.from_meta(ph.sim) # the 13 phase steps, from the metadata
optics = ConfocalOptics(na=1.4, n_medium=1.518, ex_um=0.488, em_um=0.525)
pattern = estimate_pattern(raw, lat, cutoff=2 * 1.4 / 0.525 * px_um) # the lattice, fitted from the data
A = SimOperator(pattern, lat, optics, raw.shape[1:], px_um, dz_um) # the microscope as one operator
y = torch.as_tensor(raw, device="cuda")
rl = rl_op(y, A, iterations=60, accelerate=True).volume # Richardson-Lucy through A
nerf = fit_field_op(y, A, spacing_um=(dz_um / 2, px_um / 2, px_um / 2), x_init=rl).volume # the world model
Both results are NumPy volumes on the object grid: half the camera pixel (31.3 nm) and half the plane step (60 nm).

The same plane: the mean of the raw phases, then the two reconstructions. The tubular mitochondria, a blur in widefield, separate.
Run it in the CUDA environment (pixi run -e cuda python recon.py) on an
NVIDIA GPU, or pass device="cpu"; Run on a GPU covers the
device, memory and timings. Each
solver is described in Concepts, and the full workflow, with the
pattern and the results of every method, on the
lattice SIM page.
Next: measure and plot¶
Measure and plot a reconstruction continues with these volumes: resolution, sharpness and agreement as tables, then the FRC curves, side-by-side panels and a line profile.
To work on pySRX itself, see Develop pySRX.