Ptychography

General description
Coherent beam, smaller than the sample, scan across the sample to get a bunch of diffraction patterns.

Phase retrieval algorithms
Ptychographic phase retrieval is very similar to other iterative phase retrieval algorithms—alternate back and forth between real space and Fourier space, imposing constraints as you go. There is some nuance to it, however, because it involves separating the probe from the object.

The PIE family
The Ptychographic Iterative Engine (PIE) and its offshoots, such as the extended PIE (ePIE) and the regularized PIE (rPIE), are a family of similar algorithms that perform iterative phase retrieval for ptychographic data. The original PIE was published in 2004, with the ePIE coming in this 2009 paper and rPIE in this 2017 paper. My derivation/explanation borrows heavily from these two papers, and I cannot stress enough how important it is to read them if you plan to implement this method.

Each PIE iteration has many sub-iterations (one for each probe position). Let’s take a look at a single sub-iteration. All the variations of the PIE start the same way. We start with the current exit wave guess for that region, which is acquired by shifting the probe to the appropriate position over the object and multiplying the overlapping parts of the arrays together. This is transformed into the Fourier plane, and the amplitude is replaced with the measured diffraction pattern. The updated Fourier plane is then transformed back. These steps are represented by the following equations:


 * $$\begin{aligned}

\psi &= O P \label{pie:psi}\\ \Psi &= \mathcal{F}(\psi) \label{pie:PSI}\\ \Psi' &= A_{\mathrm{meas}} \frac{\Psi}{|\Psi|} \label{pie:PSI1}\\ \psi' &= \mathcal{F}^{-1}(\Psi') \label{pie:psi1} \end{aligned}$$

If you’ve done any kind of phase retrieval, this process should look a little familiar—it’s no different from the Fourier constraint in the ER and HIO algorithms. Here, though, it gets a little more tricky, because the object and probe are still all mixed up together in $\psi$, preventing us from using the ER/HIO object constraints. It’s clear that $\psi'$ is a step in the right direction, but how we use it to update the object is where the PIE variants differ.

The original PIE uses the update function



O' = O + \frac{|P|P^*(\psi'-\psi)}{|P|_\mathrm{max}(|P|^2+\alpha|P|^2_\mathrm{max})}, $$

which works fairly well, but only if the probe is known. More recent PIE algorithms are able to simultaneously update both the object and the probe, which is infinitely more useful. The ePIE uses the update functions


 * $$\begin{aligned}

O' = O + \alpha\, \frac{P^*(\psi'-\psi)}{|P|^2_{\mathrm{max}}} \label{pie:epie_obj} \\ P' = P + \beta\, \frac{O^*(\psi'-\psi)}{|O|^2_{\mathrm{max}}}\label{pie:epie_pro},\end{aligned} $$

and the rPIE uses


 * $$\begin{aligned}

O' = O + \frac{P^*(\psi'-\psi)}{(1-\alpha)|P|^2+\alpha|P|^2_\mathrm{max}} \label{pie:rpie_obj} \\ P' = P + \frac{O^*(\psi'-\psi)}{(1-\beta)|O|^2+\beta|O|^2_\mathrm{max}}\label{pie:rpie_pro}.\end{aligned} $$

Generally speaking, rPIE is fast and coarse and ePIE is slow and fine. The two can be used sequentially or alternately to get the best of both.

But why do these update functions work? Well let’s go through the process of coming up with an update function. Looking back at, we might start by simply dividing out our current guess for the probe:



O_\mathrm{div} = \frac{\psi'}{P} = \frac{P^*\psi'}{|P|^2}. $$

However, in places where $|P|$ approaches zero, any noise in $\psi'$  will be greatly amplified in $O'$. The various An ideal object update function would favor change in regions where the probe is bright while suppressing change where the probe is dim. So let’s throw in a weighting array $W$ which will allow the update to affect some regions more than others:


 * $$\begin{split}

O' &= W\frac{P^*\psi'}{|P|^2} + (1-W)O \\ &= O - WO + W\frac{P^*\psi'}{|P|^2}. \end{split}$$

While both forms of this equation are equivalent, they highlight what’s going on in different ways. In the top form, a fraction of the update comes from $O_\mathrm{div}$, with the rest coming from the previous object guess. In the bottom form, the update starts with the original object, removes some portion of it, and replaces it with an equal measure of $O_\mathrm{div}$. Either way, $W$ allows us to control which parts of the object are updated the most and which parts stay mostly the same. The ePIE uses $W=\alpha\frac{|P|^2}{|P|^2_{\mathrm{max}}}$.