Skip to content

pysrx.forward

pysrx.forward

Forward and adjoint operators.

Projector

Forward/back projection with a cached OTF stack; pad px of zero padding against FFT wrap-around.

shift_px (V, Z, 2): per view/depth parallax (optics.psf_model), applied exactly as a phase ramp on the OTF, so psf only needs to hold the centred blur. The padding then also covers the largest shift.

forward(x)

x (Z, Y, X) -> (V, Y, X).

backward(r)

r (V, Y, X) -> (Z, Y, X) (adjoint).

SimOperator

forward(x)

(Zo, Yo, Xo) object -> (H, Zr, Y, X) raw phases.

backward(r)

Adjoint: (H, Zr, Y, X) -> (Zo, Yo, Xo).

lightfield

Multi-view Richardson-Lucy (+ total variation) light-field deconvolution on the GPU.

Model (equation 1): y_v = sum_z H_{v,z} * x_z + b (* = 2D convolution, v = view, z = depth) Update (equation 2): x <- x [ H^T( y / (H x + b) ) / H^T 1 ] TV (Dey et al. 2006): denominator becomes H^T 1 - lambda . div( grad x / |grad x| )

GPU layout: everything lives in the Fourier domain. The PSF stack is turned once into OTFs (V, Z, Y, X/2+1); a forward projection is a batched complex multiply-and-sum over z followed by V inverse FFTs, a back projection the conjugate multiply-and-sum over v followed by Z inverse FFTs. Depth is processed in chunks of z_chunk planes so the OTF cache fits in VRAM (37 x 99 x 512 x 257 complex64 = 3.9 GB for the full 20x grid).

Projector

Forward/back projection with a cached OTF stack; pad px of zero padding against FFT wrap-around.

shift_px (V, Z, 2): per view/depth parallax (optics.psf_model), applied exactly as a phase ramp on the OTF, so psf only needs to hold the centred blur. The padding then also covers the largest shift.

forward(x)

x (Z, Y, X) -> (V, Y, X).

backward(r)

r (V, Y, X) -> (Z, Y, X) (adjoint).

sim

3D lattice-SIM forward operator (Gustafsson per-order form) and its exact adjoint.

raw_h(r, z) = bin_s [ sum_o e^{i phi_oh} ( h_o (*)_3D ( c_o e^{2 pi i k_o . r} x ) ) ](r, z = z_i)
            = bin_s [ sum_g h_g (*)_3D ( I_hg x ) ]                           h_g = h cos(2 pi kz_g z)

x is the emission density on the object grid (s x finer laterally, r_z x finer axially than the raw stack). The pattern moves with the focal plane (z-stack by stage / objective), so its axial structure multiplies the PSF: orders with axial frequency kz_o (cycles / um, the beam geometry) use h cos(2 pi kz_o z). Orders sharing kz form a group g with the real illumination I_hg(r) = Re sum_{o in g} c_o e^{i (2 pi k_o . r + m phi_a,h + n phi_b,h)}; one real 3D FFT convolution per phase and group. The Elyra lattice (4 beams on one pupil ring, no centre beam) has kz = 0 for all its orders: a single group, i.e. raw_h = bin(h (*) (I_h x)).

Geometry: raw pixel j has centre j + origin (camera px, the frame estimate_pattern works in, so tiles keep the absolute pattern phase); object pixel i covers it at (i - (s - 1) / 2) / s. Raw plane i is object plane i r_z, and a camera pixel integrates (sums) its s x s object pixels. Convolutions are linear (zero padding of pad_xy / pad_z object pixels / planes on each side); the object is modelled only inside the tile. z_margin adds object planes beyond both ends of the data stack (raw planes each side): emitters above / below the imaged range then have somewhere to live instead of being pushed into the boundary planes (crop with data_planes afterwards).

SimOperator

forward(x)

(Zo, Yo, Xo) object -> (H, Zr, Y, X) raw phases.

backward(r)

Adjoint: (H, Zr, Y, X) -> (Zo, Yo, Xo).

fit_amplitudes(pattern, lat, optics, x, raw, pixel_um, dz_um, **op_kwargs)

Refit the complex order amplitudes (and a gain and offset) by linear least squares through the forward model.

With the object x fixed, raw_h = g B_0(x)_h + sum_p [a_p B_p,re(x)_h + b_p B_p,im(x)h] + offset, where B_0 is the zero-order (widefield) response and B_p,re / B_p,im the responses of order pair p = {o, -o} at c_o = 1 / i. Then c_o = (a_p + i b_p) / g, c-o = conj(c_o). Orders keep their k (inactive orders stay inactive). Returns the refitted Pattern and {"gain", "offset", "rss"}. op_kwargs go to SimOperator (upsample, origin, pads, kz, device).