## Abstract

Ptychographic coherent x-ray diffractive imaging is a form of scanning microscopy that does not require optics to image a sample. A series of scanned coherent diffraction patterns recorded from multiple overlapping illuminated regions on the sample are inverted numerically to retrieve its image. The technique recovers the phase lost by detecting the diffraction patterns by using experimentally known constraints, in this case the measured diffraction intensities and the assumed scan positions on the sample. The spatial resolution of the recovered image of the sample is limited by the angular extent over which the diffraction patterns are recorded and how well these constraints are known. Here, we explore how reconstruction quality degrades with uncertainties in the scan positions. We show experimentally that large errors in the assumed scan positions on the sample can be numerically determined and corrected using conjugate gradient descent methods. We also explore in simulations the limits, based on the signal to noise of the diffraction patterns and amount of overlap between adjacent scan positions, of just how large these errors can be and still be rendered tractable by this method.

© 2014 Optical Society of America

## 1. Introduction

Coherent x-ray diffractive imaging (CXDI) is a form of microscopy that forms an image of a sample under investigation without optics. Rather, it recovers the exit wave leaving the sample from a measurement of its coherent diffraction pattern using phase retrieval techniques. This approach solves the “phase problem” [1], which arises due to the inability of x-ray detectors to measure complex valued wave fields. Retrieval of the missing phase starts with a guess of the sample exit wave field and iteratively corrects the guess using information known about the system. This information includes the measured diffraction intensities as well as constraints on the sample, e.g. a support constraint [2] or known positions of the illuminating wave field on the sample [3]. A solution is found when the initial guess is corrected to such a degree that it simultaneously satisfies all constraints. The recovered exit wave has been shown to be unique [4], and the achievable spatial resolution is theoretically diffraction limited. The first experimental demonstration of using iterative techniques to overcome the phase problem in x-ray microscopy was performed by Miao et al. [5]. This approach has since been expanded to many diverse samples and experimental regimes [6–10].

A typical coherent diffractive imaging experiment in the forward-scattering geometry is shown in Fig. 1 [11]. Here, we define *a* as the detector pixel size, *λ* as the x-ray wavelength, *k* = 2*π/λ* the x-ray wavenumber, *ℓ* as the sample to detector distance, and as the detector is placed in the far field, the array size in the sample to detector Fourier transformation as *N* × *N*. The field of view at the detector is *L _{D}* =

*Na*, while the field of view at the sample plane is

*L*=

_{S}*λℓN/L*. Thus the real space pixel size at the sample plane is Δ

_{D}*x*=

_{S}*L*=

_{S}/N*λℓ/Na*, and the Fourier space pixel size at the detector plane is found using the relation Δ

*q*Δ

*x*= 2

_{S}*π/N*, resulting in Δ

*q*=

*ka/ℓ*. Samples larger than the incident x-ray beam can be imaged by a scanning variant of CXDI known as ptychography. In this scheme, the sample is illuminated with overlapping regions at multiple scan positions [12], as shown in Fig. 1 by the overlapping circles. Here, a simulated x-ray wave field

*p*(

**r**) is generated by computing the Fresnel diffraction integral for a plane wave incident on a circular pinhole aperture, with a propagation distance of a few millimeters from the pinhole to the sample. This

*p*(

**r**) is incident on the sample with transmission function

*T*(

**r**) at some location

**r**

_{1}. The exit wave is defined using the projection approximation as

*ψ*

_{1}(

**r**) =

*p*(

**r**)

*T*(

**r**−

**r**

_{1}), and is propagated to the detector by taking its Fourier transform, giving the wavefield at the detector:

*ℱ*[

*ψ*

_{1}(

**r**)], where

*ℱ*is the spatial Fourier transform:

*N*is the array size in the both the

*x*and

*y*directions. An area detector can only measure the intensity of the wavefield at the detector, and so we use

*I*

_{1}(

**q**) = |

*ℱ*[

*ψ*

_{1}(

**r**)]|

^{2}as a simulated diffraction intensity measurement. The sample is then moved to a new location

**r**

_{2}so that a neighboring but overlapping region with exit wave

*ψ*

_{2}(

**r**) =

*p*(

**r**)

*T*(

**r**−

**r**

_{2}) can be illuminated, and this can be repeated for further

**r**

*,*

_{j}*j*∈ ℤ, so that we have some desired total field of view on the sample.

The purpose of collecting diffraction from overlapping regions is that it provides a very robust constraint on the reconstruction: we have multiple diffraction measurements constraining each region on the sample. This drastically reduces image artifacts resulting from imperfect measurements of the diffraction patterns; e.g. noisy diffraction or missing low spatial frequency information due to the use of a beam stop [13]. The enantiomorph ambiguity associated with single-view diffractive imaging is also removed, because scanning the sample removes the Fourier transform symmetries from which this problem arises, allowing for vastly improved algorithmic performance. Ptychographic imaging allows for an arbitrarily large field of view imaging of extended samples. It also allows for the simultaneous determination of the sample transmission function and the x-ray wave field illuminating the sample [14, 15]. Furthermore, by using a known test sample, the ptychographic approach is a powerful and robust method for determining the full complex valued wave field of the beam used to illuminate the test sample as well as the optics upstream of it [16].

The algorithms used in CXDI to extract the sample exit wave from an initial guess using experimental constraints can be formulated in terms of gradient descent of an error metric [17–19] or as a “projections onto constraint sets” algorithm [20]. In gradient descent type algorithms, an error metric *ε _{j}* is defined:

*(*

_{j,n}**q**) =

*ℱ*[

*ψ*(

_{j,n}**r**)] =

*ℱ*[

*p*(

**r**)

*T*(

**r**−

**r**

*)] is the*

_{j}*n*

^{th}iterate of the exit wave at position

**r**

*propagated to the detector, and the sum over*

_{j}**q**only includes pixels where the diffraction intensity measurement

*I*(

_{j}**q**) is defined (e.g. missing information behind a beam stop or due to damaged detector pixels is not included). The gradient of the error metric with respect to the sample transmission function

*T*(

**r**−

**r**

*) or the x-ray illumination function*

_{j}*p*(

**r**) is then performed analytically [19]. This will generate an “update function” [15] with which we modify

*T*(

**r**−

**r**

*) and*

_{j}*p*(

**r**) to iteratively travel to a location in error metric space that has minimum error. The measurement space constraints of diffraction from overlapping scan positions appear to be stringent enough to allow us to find the

*global*minimum in error metric space. This is implied from the fact that, for diffraction not significantly degraded by Poisson shot noise or missing data regions, we always recover the same

*T*(

**r**−

**r**

*) and*

_{j}*p*(

**r**) even with very different initial guesses of these functions. That we are at a global minimum is further supported by the use of the Difference Map (DM) algorithm to recover

*T*(

**r**−

**r**

*) and*

_{j}*p*(

**r**) since the DM has well noted ability to escape local minima and find global minima [18, 20].

The ability to quickly and robustly converge to a solution for *T*(**r**) and *p*(**r**) is drastically degraded when errors in the assumed scan positions accumulate. Errors in the assumed scan positions **r*** _{j}* can be caused by thermal drift, vibrations and other mechanical errors in the experimental equipment when undertaking experiments. If using a beam on the order of tens of nanometers in size, knowledge of the scan positions can be compromised significantly if vibrations are not damped adequately. The effect of scan position errors on ptychography due to vibration and drift and various schemes to correct for them have been addressed recently [21–26]. The schemes devised in those references include the use of genetic algorithms, simulated annealing, transmission function correlation methods, and model-based drift correction. The common feature of these methods is to find some configuration of scan positions

**r**

*which minimize an error metric of a similar form to Eq. (2), and they explore various ways of accomplishing this. In this paper, we quantify the improvements that can be achieved using conjugate gradient (CG) descent methods to minimize Eq. (2) and so determine the scan positions*

_{j}**r**

*. In contrast to reference [19], which uses CG methods to solve for*

_{j}*T*(

**r**),

*p*(

**r**), and the scan positions

**r**

*simultaneously, we introduce a novel method showing how to combine existing and well-established ptychographic algorithms, the enhanced ptychographic iterative engine (ePIE) [15] and the difference map (DM) [14], with a CG approach to correct for insufficiently known scan positions. This is important as using only a gradient descent approach to ptychographically find*

_{j}*T*(

**r**),

*p*(

**r**), and the

**r**

*simultaneously can become trapped in local minima easily; combining CG correction of the scan positions*

_{j}**r**

*with ePIE and DM updates for*

_{j}*T*(

**r**) and

*p*(

**r**) can overcome this. We also introduce the concept of a critical scan position error in ptychography and then determine it using the combination of established methods to recover

*T*(

**r**) and

*p*(

**r**) and a GC recovery of the scan positions

**r**

*.*

_{j}We performed a simulated ptychography experiment to explore the effects of scan position errors on image quality. A series of diffraction patterns was generated by raster scanning a sample *T*(**r**) with an illumination function *p*(**r**), which had a diameter of ≃ 280Δ*x _{S}*, in the forward scattering geometry shown in Fig. 1. The simulated sample

*T*(

**r**) is an image of several cells, and is represented in an HSV colorspace, with the hue as the phase (ranging from 0 to 2

*π*) of the sample, the brightness as the magnitude (ranging from 0 to 1), and the saturation is set to 1. The illumination

*p*(

**r**) is generated by Fresnel propagating a simulated perfectly circular aperture over a small distance. The overlap between adjacent illumination regions is 75%, which corresponds to having the adjacent scan positions separated by a distance of 70Δ

*x*. In this way, 49 diffraction patterns are created by scanning a 7×7 square grid. A thin rectangular portion of each of these diffraction patterns is removed to simulate the effect of a beam stop, also as seen in Fig. 1. When no errors in the scan positions are present, we reconstruct

_{S}*p*(

**r**) and

*T*(

**r**) as shown in Fig. 2(a) and 2(b). When scan position errors are present, here random scan position errors of up to 10Δ

*x*added to the

_{S}*x*and

*y*components for each of the 49 scan positions, we see significant degradation of the reconstructions of

*p*(

**r**) and

*T*(

**r**), as seen in Fig. 2(c) and 2(d). The reconstructions shown in Fig. 2 illustrate how sensitive ptychography is to errors in the assumed scan positions.

## 2. Iterative refinement of the overlap constraint

Ptychographic diffraction measurements are often information-rich enough to allow us to extract, in addition to the sample transmission function *T*(**r**) and the illumination function *p*(**r**), the scan positions **r*** _{j}*. One conceptually simple way of doing this is to take the gradient of Eq. (2) with respect to the scan positions

**r**

*and use an iterative process to correct for scan position errors [19]. Just as we are able to take the gradient of Eq. (2) with respect to*

_{j}*T*(

**r**) and

*p*(

**r**) and update our guesses of these quantities in an iterative fashion, we can use a gradient descent scheme to refine our initial guesses for the

**r**

*so that we iteratively find the true locations.*

_{j}In this way, we have a very simple, and as will soon be seen, very effective method for incorporating iterative scan position correction into DM and ePIE, the standard ptychographic reconstruction algorithms [14, 15]. The steepest descent method for correcting scan positions using an analytical calculation of the gradient of Eq. (2) with respect to the scan positions **r*** _{j}* is given by:

**r**

_{j,}_{0}are the initial guesses for the scan positions, ∇

_{rj,n}is the gradient operator with respect to the scan positions

**r**

*, the*

_{j,n}*α*is a step length taken along the steepest descent or conjugate gradient directions, and

_{n}*β*is calculated using the Polak-Ribière method [27]:

_{n}*= −∇*

_{j,n}_{rj,n}

*ε*,

_{j}*T*denotes the transpose, and the CG direction reset ${\beta}_{n}=\text{max}\left\{0,{\beta}_{n}^{PR}\right\}$ is used. Explicit expressions for the analytical gradient computation ∇

_{rj,n}

*ε*=

_{j}**x̂**

*∂ε*+

_{j}/∂x_{j,n}**ŷ**

*∂ε*are given by [19]:

_{j}/∂y_{j,n}*T̂*(

**q**) =

*ℱ*[

*T*(

**r**)], and * denotes the complex conjugate.

We integrate this CG correction of the scan positions into the standard ptychographic reconstruction algorithms by using the **r**_{j}_{,0} positions initially, and update *T*(**r** − **r*** _{j}*) and

*p*(

**r**) using either the DM or ePIE for some tens of iterations. Once this is done, we use these newly obtained

*T*(

**r**−

**r**

*) and*

_{j}*p*(

**r**) in the gradient calculation of Eq. (2), and update the

**r**

*using Eq. (4). We choose the step length*

_{j}*α*by rescaling Λ

_{n}*so that it is a unit vector, and either simply pick a value of*

_{j,n}*α*(say 1 or 2 pixels along the Λ

_{n}*direction), or perform a line search along the Λ*

_{j,n}*direction by evaluating the error metric Eq. (2) at a few trial values of*

_{j,n}*α*:

_{n}*is a unit vector, some sensible trial values for*

_{j,n}*α*are say 1 pixel, 5 pixels, and 10 pixels along the CG direction Λ

_{n}*. Once we have found a value for*

_{j,n}*α*which gives us the smallest value of

_{n}*ε*(

_{j}*α*), we use this

_{n}*α*to update

_{n}**r**

_{j,n}_{+1}as in Eq. (4). Next, we run the DM or ePIE to again update

*T*(

**r**−

**r**

*) and*

_{j}*p*(

**r**) for another ten iterations or so using the just updated

**r**

_{j,n}_{+1}, and repeat the above CG scan position correction procedure again after this. For the results shown in the subsequent sections below, we use 100 iterations of DM and 50 iterations of ePIE to update

*T*(

**r**) and

*p*(

**r**), and update the

**r**

*every 10 iterations (regardless of whether DM or ePIE is being used). The recipe just given is then repeated for however many iterations it takes to get the error metric to converge to zero. By performing the scan position correction step only every ten iterations, the increased computing time is minimal, typically a ≃ 20% increase. Performing scan position correction more frequently appears to have little advantage as it is noticed that many times some scan positions can oscillate between two different locations, indicating algorithmic stagnation.*

_{j,n}## 3. Experimental demonstration

Here we demonstrate experimentally that the scan position correction scheme given in the preceding section works robustly and allows us to recover *T*(**r**), *p*(**r**) and the scan positions **r*** _{j}* even when large scan position errors are present. The experiment was performed at beamline 2-ID-B [28] at the Advanced Photon Source in the transmission geometry shown in Fig. 1. The pinhole aperture used to define

*p*(

**r**) was circular in shape, 10

*μ*m in diameter and placed a few millimeters upstream of the sample. A 13×13 square grid was scanned, with scanning steps of 3

*μ*m to give an overlap of 70%. The sample used was a magnetic multilayer which exhibits maze-like ordering of the magnetic domains [29–32]. In these multilayer systems, depositing alternating layers of a transition metal and a rare-earth metal causes formation of an artificial ferrimagnet with perpendicular magnetic anisotropy. Previous experiments and measurements on multilayer samples similar to the one used here have shown that the ferrimagnetic domain widths range between 200 nm to 1

*μ*m, with the Bloch domain walls ∼ 50 nm [8, 33–36]. The magnetization of the domains in this type of sample is primarily out of plane. X-ray magnetic circular dichroism is the primary magnetic contrast mechanism in the sample transmission function

*T*(

**r**) at L and M resonances in the multilayer materials.

Due to scan stage misalignment, rather than scanning a set of positions on a square grid, a region on the sample can instead inadvertently be scanned on a parallelogram shaped grid. Because of this, the larger the field of view scanned, the more that scan position errors can accumulate. Horizontal and vertical scanning stage misalignments of as little as a few degrees can cause scan position errors of up to a few microns to accumulate in scans a few tens of *μ*m in size. The effect this has on reconstructions is seen in Fig. 3(a) and 3(b). Here, the reconstructed *T*(**r**) (in Fig. 3(a)) and *p*(**r**) (in Fig. 3(b)) show significant artifacts. For this experimental geometry with the multilayer plane oriented normal to the incident x-ray beam as shown in Fig. 1, the domains are oriented parallel and antiparallel to the wavefield propagation direction [33, 37]. A reconstruction of *T*(**r**) should therefore be approximately a binary structure with values of only ±*M _{s}*, where

*M*is the out of plane saturation magnetization value [8]. However in Fig. 3(a), there are many regions in the

_{s}*T*(

**r**) reconstruction which are intermediate to the ±

*M*out of plane magnetizations, which is unphysical. Also the reconstruction of

_{s}*p*(

**r**) is far from what is expected of a wavefield a few millimeters downstream of a plane wavefield exiting a circular pinhole aperture. Fresnel fringes within the circular region should be evident but are absent; instead other numerical artifacts are shown.

The effectiveness of the scan position scheme discussed in the previous section can be seen in Fig. 3(c) to 3(e), where it is shown that we can recover from quite severe errors in the scan positions. After its application, we have corrected the scan positions **r*** _{j}* with the result that the reconstructions for

*T*(

**r**) and

*p*(

**r**) are of much higher quality with the magnetic moment directions predominantly having the expected values of only ±

*M*. We also can see for the reconstruction of

_{s}*p*(

**r**) the expected clearly defined Fresnel fringing. The recovered scan positions

**r**

*, shown in Fig. 3(e), can be seen to be off from the incorrectly assumed scan positions by up to almost 3*

_{j}*μ*m in some locations, which is almost equal to the scanning step sizes and is about 30% of the diameter of the illumination function

*p*(

**r**).

## 4. Maximum recoverable scan position error

Here we address in simulated experiments the limits to our ability to solve for *T*(**r**), *p*(**r**) and the scan positions **r*** _{j}* using the methods of Section 2 when the diffraction signal is degraded in an experimentally realistic way. The primary cause of signal degradation encountered in coherent imaging experiments at synchrotron light sources is the limited dynamic range of the detectors typically used, resulting in information loss at high spatial frequencies due to Poisson noise. Also, it may be necessary to use a beam stop to prevent damage to the detector. As a result, low spatial frequency information may be altogether missing (the rectangular black region in Fig. 4(a)). Another experimental parameter that greatly affects the performance of ptychographic reconstruction algorithms and scan position recovery is the overlap of the scan positions. For example, in Fig. 4(b) and 4(c) a 2×2 square grid is scanned; the overlap in Fig. 4(b) is significantly lower than in Fig. 4(c), which means that the four diffraction patterns one would obtain in Fig. 4(b) contain less spatial information redundancy than the four diffraction patterns one would obtain in Fig. 4(c). As it is this redundant information content in the diverse diffraction that allows us to solve for

*T*(

**r**),

*p*(

**r**) and the scan positions

**r**

*, we expect to be able to tolerate larger scan position errors with greater overlap. As will be seen, the overlap plays a crucial role in the maximum recoverable scan position error*

_{j}**e**

*. For example with the loosely scanned region, it might not be possible to recover the true scan positions (shown as the black circles with centers at the black dots) from the incorrect scan positions (the white dots). If we use a higher overlap like that shown on the right, it becomes much more likely that we are able to recover the true scan positions.*

_{j,max}We present simulation results exploring the performance of the CG scan position correction method versus varying the diffraction signal to noise as a function of spatial frequency as well as the overlap of the scanned region on the sample. We look at different values of diffraction integrated intensities; in Fig. 4(d) the integrated intensity *I*(**q**) is varied between 10^{5} and 10^{13} (arbitrary units) in steps of 10^{2}, and to show the intensity versus spatial frequency decay, is then integrated azimuthally at each spatial frequency. The SNR, defined as
$\text{SNR}=10{\text{log}}_{10}\left(I(\mathbf{q})/\sqrt{I(\mathbf{q})}\right)$, for these different integrated intensities is shown in Fig. 4(e). In all cases, a portion of the diffraction intensity is next removed (as in Fig. 4(a)) to simulate the effects of a beamstop. We also vary the overlap of the scan positions. We scan a simulated sample on a square 7 × 7 grid with ptychographic overlap of 65%, 75%, and 85%, and add random errors **e*** _{j}* to each scan position so that the actual (and assumed unknown) scan positions used to generate diffraction are

**r**

*+*

_{j}**e**

*. The procedure given in Sec. 2 is then performed with the aim of determining just how large of maximum random errors*

_{j}**e**

*we can tolerate, and still recover the positions*

_{j,max}**r**

*.*

_{j}The results of varying SNR and overlap versus average scan position error are shown in Fig. 5. Remarkably, there appears to be a point at which increasing the SNR versus spatial frequency of a diffraction pattern has no further effect on the maximum recoverable scan position error. For the 85% overlap square 7 × 7 grid (corresponding to Fig. 5(a)), integrated intensities of 10^{7}, 10^{9}, 10^{11}, and 10^{13} (which correspond to the black, blue, green, and magenta curves respectively in Fig. 4(d) and 4(e)) all have a maximum recoverable error of about
${\mathbf{e}}_{j,\mathit{max}}\simeq 90\sqrt{2}\mathrm{\Delta}{x}_{S}$, which we define as where the final average scan position error
$\mathrm{\Delta}{r}_{\mathit{avg}}^{\mathit{final}}$ ceases to be roughly flat with increasing
$\mathrm{\Delta}{r}_{\mathit{avg}}^{\mathit{initial}}$ and begins to increase with increasing
$\mathrm{\Delta}{r}_{\mathit{avg}}^{\mathit{initial}}$. However when the integrated intensity is 10^{5} (corresponding the the red curves in Fig. 4(d) and 4(e)), the maximum recoverable error is reduced to
$\mathrm{\Delta}{r}_{\mathit{avg}}^{\mathit{initial}}\simeq 53.6\mathrm{\Delta}{x}_{S}$, corresponding to
${\mathbf{e}}_{j,\mathit{max}}\simeq 70\sqrt{2}\mathrm{\Delta}{x}_{S}$. What this indicates is that there is a strong SNR and overlap dependency on the maximum recoverable error for lower SNR diffraction, but at some point the SNR dependency is lost and the maximum recoverable error becomes fixed for a particular amount of overlap. Similar behavior is seen for the 75% and 65% overlap square 7 × 7 grids, as shown in Fig. 5(b) and 5(c). This means that we can recover errors up to 45% of the diameter of *p*(**r**) for 85% overlap, up to 30% for 75% overlap, and only 20% for 65% overlap at integrated intensities greater than 10^{7} (the diameter of *p*(**r**) is ≃ 280Δ*x _{S}*). For the integrated intensity of 10

^{5}, Fig. 5 shows a decrease in

**e**

*of about 20Δ*

_{j,max}*x*for all overlap cases when compared to the other intensities.

_{S}We see the impact on the SNR versus spatial frequency for integrated intensities between 10^{5} and 10^{7}: no photons are detected near the spatial frequency limit of the detector, defined here as *q _{max}* =

*N*Δ

*q*=

*Nka/ℓ*(we used an array size

*N*= 512). For example, the average intensity for the 10

^{5}integrated intensity case in Fig. 4(d) is less than unity for spatial frequencies greater than ≈ 35Δ

*q*. This corresponds to a SNR of ≈ 2 dB, about where the signal becomes lost in the noise. Because of this, some dependence of $\mathrm{\Delta}{r}_{\mathit{avg}}^{\mathit{initial}}$ on the integrated intensity is both expected and observed. Combined with the effects of the missing spatial frequencies due to the beamstop, the diffraction data for integrated intensities between 10

^{5}and 10

^{7}appear to have insufficient information content for position error recovery comparable to the higher integrated intensities. For an integrated intensity of 10

^{7}the signal becomes lost in the noise at ≈ 10

^{2}Δ

*q*, still far from

*q*=

_{max}*N*Δ

*q*/2, yet we are able to solve for approximately the same

**e**

*for the higher integrated intensity cases, indicating these data have sufficient information content. Starting above an integrated intensity of 10*

_{j}^{7}, the SNR is greater than ≈ 2 dB for all spatial frequencies. From these simulations we find that the recoverable position errors

**e**

*becomes independent of the integrated intensity when the SNR approaches this value for pixels at the spatial frequency limit of the detector.*

_{j,max}Some representative recovered scan positions **r*** _{j}* as well as the recovered

*T*(

**r**) and

*p*(

**r**) are shown in Fig. 6. As the maximum scan position error

**e**

*becomes large, corresponding to when $\mathrm{\Delta}{r}_{\mathit{avg}}^{\mathit{final}}$ begins to increase with increasing $\mathrm{\Delta}{r}_{\mathit{avg}}^{\mathit{initial}}$, the scan positions at the periphery of the scanned region become more and more difficult to solve for, as seen in Fig. 6(a). The reason for this is that these peripheral regions have fewer independent diffraction patterns constraining possible solutions for*

_{j,max}*T*(

**r**),

*p*(

**r**), and

**r**

*while scan positions in the center of the scanned region have relatively many diffraction patterns. What this means is that there is not enough information content in the ptychographic diffraction data at these peripheral regions to allow us to effectively converge to simultaneous solutions for*

_{j}*T*(

**r**),

*p*(

**r**), and

**r**

*. As $\mathrm{\Delta}{r}_{\mathit{avg}}^{\mathit{initial}}$ becomes even larger, even some central scan positions become intractable, as seen in Fig. 6(b), and at some point none of the scan positions are recoverable (Fig. 6(c)). This critical $\mathrm{\Delta}{r}_{\mathit{avg}}^{\mathit{initial}}$ at which the peripheral scan positions become difficult to recover corresponds to when the average scan position error, defined as*

_{j}*x*, as seen in Fig. 5 for all overlap cases, and when $\mathrm{\Delta}{\text{r}}_{\mathit{avg}}^{\mathit{final}}$ exceeds this, the recovered

_{S}*T*(

**r**),

*p*(

**r**), and

**r**

*begin to become too degraded to be of any use.*

_{j}When we are in the vicinity of, but still below the critical
$\mathrm{\Delta}{r}_{\mathit{avg}}^{\mathit{initial}}$, it is possible to further refine those scan positions at the periphery which have not been correctly solved for. Take for example the scan position configuration in Fig. 7(a). Here, the central scan positions are correctly solved for while some of those located at the periphery have not been. What can be done next is to use the recovered scan positions **r*** _{j}* in Fig. 7(a) as well as the recovered illumination

*p*(

**r**), but start with a new initial transmission function

*T*(

**r**) consisting of complex valued random numbers. Running the method given in Section 2 again a number of times, here twenty, and at the end averaging the results for the recovered

**r**

*gives almost perfectly recovered scan positions, with a $\mathrm{\Delta}{r}_{\mathit{avg}}^{\mathit{final}}\simeq 0.1\mathrm{\Delta}{x}_{S}$, as seen in Fig. 7(b). It should be noted in Fig. 7(b) that we have recovered the scan positions only to integer pixel accuracy. If positioning errors exist on sub-pixel length scales, the recovered positions in Fig. 7(b) can be used as a starting point for a correlation method [21, 38] combined with sub-pixel registration methods [39].*

_{j}We also note that the results shown in Fig. 5 are independent on the scan trajectory used. Spiral and concentric circular scan patterns are popular for avoiding the so-called “raster pathology” that can arise with scans performed on a periodic lattice [40–42]. However, as long as the overlap between adjacent scan positions **r*** _{j}* is the same to within a few percentage points, the critical initial average error
$\mathrm{\Delta}{r}_{\mathit{avg}}^{\mathit{initial}}$ is about the same for both raster and non-raster scans. The only significant difference between the two cases is that the starting probe position guesses are different. The CG method still determines the true scan positions from different guessed positions if
$\mathrm{\Delta}{r}_{\mathit{avg}}^{\mathit{initial}}$ is about the same. This situation is analogous to using different initial guesses for

*T*(

**r**): using DM or ePIE, we can still recover the sample transmission function from these different starts.

## 5. Conclusions

We have shown in numerical simulations that the conjugate gradient method can be used to correct scan position errors in ptychography robustly and quickly when used with established phase retrieval algorithms, even when the diffraction patterns have been degraded in ways similar to those we see in experiments. Using this method we found in simulation that we can recover errors of up to approximately 45% of the illumination function diameter and up to almost 300% of the scan step size when the initial overlap of the illumination function between adjacent ptychographic scan steps is 85%. We show experimentally that this method can recover errors of approximately 30% of the illumination function diameter and almost 100% of the scan step size. We further observe that the integrated intensity of the diffraction data (and thus the signal-to-noise ratio versus spatial frequency), if increased past some cutoff, ceases to play a role in the ability of the method to recover severe scan position errors compared to lower integrated intensities, and that the degree of overlap plays the dominant role in the ability to recover large scan position errors at larger integrated intensities. From these simulations we obtain an upper bound on the recoverable random errors at each scan location - a critical scan position error - as a function of overlap and diffraction integrated intensity. This critical scan position error is specific to the use of the conjugate gradient method used to solve for scan position errors in combination with the DM and ePIE methods. This work shows that both the signal-to-noise ratios of the diffraction patterns, and the overlap between adjacent scan positions, play crucial roles in determining the magnitude of scan position errors can be recovered before the conjugate gradient method fails. We anticipate that these results can be extended to experiments to set quantitative limits on tolerable scan errors and the source brightness or measurement time required for weakly scattering samples.

## Acknowledgments

The authors acknowledge the support of the Australian Research Council Centre of Excellence for Coherent X-ray Science and the U.S. Department of Energy, Office of Science, Office of Basic Energy Sciences, under Contract DE-SC0001805 and Contract DE-AC02-06CH11357.

## References and links

**1. **D. Sayre, “Some implications of a theorem due to Shannon,” Acta Cryst. **5**, 843 (1952). [CrossRef]

**2. **J. Fienup, “Reconstruction of an object from the modulus of its Fourier transform,” Opt. Lett. **3**, 27–29 (1978). [CrossRef]

**3. **J.M. Rodenburg and H.M.L. Faulkner, “A phase retrieval algorithm for shifting illumination,” Appl. Phys. Lett. **85**, 4795–4797 (2004). [CrossRef]

**4. **R. H. T. Bates, “Fourier phase problems are uniquely solvable in more than one dimension. I. Underlying theory,” Optik **61**, 247–262 (1982).

**5. **J. Miao, P. Charalambous, J. Kirz, and D. Sayre, “An extension of the methods of x-ray crystallography to allow imaging of micron-size non-crystalline specimens,” Nature **400**, 342–344 (1999). [CrossRef]

**6. **P. Godard, G. Carbone, M. Allain, F. Mastropietro, G. Chen, L. Capello, A. Diaz, T. H. Metzger, J. Stangl, and V. Chamard, “Three-dimensional high-resolution quantitative microscopy of extended crystals,” Nat. Communications **2**, 568 (2011). [CrossRef]

**7. **K. Giewekemeyer, P. Thibault, S. Kalbfleisch, A. Beerlink, C.M. Kewish, M. Dierolf, F. Pfeiffer, and T. Salditt, “Quantitative biological imaging by ptychographic X-ray diffraction microscopy,” Proc. Natl. Acad. Sci. USA **107**, 529–534 (2010). [CrossRef]

**8. **A. Tripathi, J. Mohanty, S.H. Dietze, O.G. Shpyrko, E. Shipton, E.E. Fullerton, S.S. Kim, and I. McNulty, “Dichroic coherent diffractive imaging,” Proc. Natl. Acad. Sci. USA **108**, 13393–13398 (2011). [CrossRef]

**9. **B. Abbey, K.A. Nugent, G.J. Williams, J.N. Clark, A.G. Peele, M.A. Pfeifer, M. de Jonge, and I. McNulty, “Keyhole coherent diffractive imaging,” Nat. Physics **4**, 394–398 (2008). [CrossRef]

**10. **M. Dierolf, A. Menzel, P. Thibault, P. Schneider, C.M. Kewish, R. Wepf, O. Bunk, and F. Pfeiffer, “Ptychographic X-ray computed tomography at the nanoscale,” Nature **467**, 436–439 (2010). [CrossRef]

**11. **Image of sample modified from an original courtesy of Invitrogen: http://www.biovis.com/carv-ii.htm.

**12. **O. Bunk, M. Dierolf, S. Kynde, I. Johnson, O. Marti, and F. Pfeiffer, “Influence of the overlap parameter on the convergence of the ptychographical iterative engine,” Ultramicroscopy **108**481–487 (2008). [CrossRef]

**13. **H.N. Chapman, A. Barty, S. Marchesini, A. Noy, S.P. Hau-Riege, C. Cui, M.R. Howells, R. Rosen, H. He, J.C.H. Spence, U. Weierstall, T. Beetz, C. Jacobsen, and D. Shapiro, “High-resolution ab initio three-dimensional x-ray diffraction microscopy,” J. Opt. Soc. Am. A **23**, 1179–1200 (2006). [CrossRef]

**14. **P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, and F. Pfeiffer, “High-Resolution Scanning X-ray Diffraction Microscopy,” Science **321**, 379–382 (2008). [CrossRef]

**15. **A.M. Maiden and J.M. Rodenburg, “An improved ptychographical phase retrieval algorithm for diffractive imaging,” Ultramicroscopy **109**, 1256–1262 (2009). [CrossRef]

**16. **C.M. Kewish, M. Guizar-Sicairos, C. Liu, J. Qian, B. Shi, C. Benson, A.M. Khounsary, J. Vila-Comamala, O. Bunk, J.R. Fienup, A.T. Macrander, and L. Assoufid, “Reconstruction of an astigmatic hard X-ray beam and alignment of K-B mirrors from ptychographic coherent diffraction data,” Opt. Express **18**, 23420–23427 (2010). [CrossRef]

**17. **J. R. Fienup, “Phase retrieval algorithms: a comparison,” App. Opt. **21**, 2758–2769 (1982). [CrossRef]

**18. **S. Marchesini, “A unified evaluation of iterative projection algorithms for phase retrieval,” Rev. Sci. Instrum. **78**, 011301 (2007). [CrossRef]

**19. **M. Guizar-Sicairos and J.R. Fienup, “Phase retrieval with transverse translation diversity: a nonlinear optimization approach,” Opt. Express **16**, 7264–7278 (2008). [CrossRef]

**20. **V. Elser, I. Rankenburg, and P. Thibault, “Searching with iterated maps,” Proc. Natl. Acad. Sci. USA **104**, 418–423 (2007). [CrossRef]

**21. **F. Zhang, I. Peterson, J. Vila-Comamala, A. Diaz, F. Berenguer, R. Bean, B. Chen, A. Menzel, I. K. Robinson, and J. M. Rodenburg, “Translation position determination in ptychographic coherent diffraction imaging,” Opt. Express **21**, 13592–13606 (2013). [CrossRef]

**22. **A. Shenfield and J. M. Rodenburg, “Evolutionary determination of experimental parameters for ptychographical imaging,” J. Appl. Phys. **109**, 124510 (2011). [CrossRef]

**23. **M. Beckers, T. Senkbeil, T. Gorniak, K. Giewekemeyer, T. Salditt, and A. Rosenhahn, “Drift correction in ptychographic diffractive imaging,” Ultramicroscopy **126**, 44–47 (2013). [CrossRef]

**24. **Y. Takahashi, A. Suzuki, N. Zettsu, Y. Kohmura, Y. Senba, H. Ohashi, K. Yamauchi, and T. Ishikawa, “Towards high-resolution ptychographic x-ray diffraction microscopy,” Phys. Rev. B **83**, 214109 (2011). [CrossRef]

**25. **A.M. Maiden, M.J. Humphry, M.C. Sarahan, B. Kraus, and J.M. Rodenburg, “An annealing algorithm to correct positioning errors in ptychography,” Ultramicroscopy **120**, 164–172 (2012). [CrossRef]

**26. **P. Thibault and A. Menzel, “Reconstructing state mixtures from diffraction measurements,” Nature **494**, 68–71(2013). [CrossRef]

**27. **E. Polak and G. Ribière, “Note sur la convergence de méthodes de directions conjuguées,” Rev. Fr. Inform. Rech. Oper. **16**, 35–43 (1969).

**28. **I. McNulty, A.M. Khounsary, Y.P. Feng, Y. Qian, J. Barraza, C. Benson, and D. Shu, “A beamline for 1–4 keV microscopy and coherence experiments at the Advanced Photon Source,” Rev. Sci. Instrum. **67**, 3372 (1996). [CrossRef]

**29. **C. Kittel, “Physical theory of ferromagnetic domains,” Rev. Mod. Phys. **21**, 541–583 (1949). [CrossRef]

**30. **C. Kooy and U. Enz, “Experimental and theoretical study of the domain configuration in thin layers of BaFe_{12}O_{9},” Philips Res. Rep. **15**, 7–29 (1960).

**31. **M. Seul and D. Andelman, “Domain shapes and patterns: The phenomenology of modulated phases,” Science **267**, 476–483 (1995). [CrossRef]

**32. **M.T. Johnson, P.J.H. Bloemen, F.J.A. den Broeder, and J.J. de Vries, “Magnetic anisotropy in metallic multilayers,” Rep. Prog. Phys. **59**, 1409–1458 (1996). [CrossRef]

**33. **O. Hellwig, G. Denbeau, B. Kortright, and E.E. Fullerton, “X-ray studies of aligned magnetic stripe domains in perpendicular multilayers,” Physica B **336**, 136–144 (2003). [CrossRef]

**34. **D. Raasch, J. Reck, C. Mathieu, and B. Hillebrands, “Exchange stiffness constant and wall energy density of amorphous GdTb-FeCo thin films,” J. Appl. Phys. **76**, 1145–1149 (1994). [CrossRef]

**35. **Y. Mimura, N. Imamura, T. Kobayashi, A. Okada, and Y. Kushiro, “Magnetic properties of amorphous alloy films of Fe with Gd, Tb, Dy, Ho, or Er,” J. Appl. Phys. **49**, 1208–1215 (1978). [CrossRef]

**36. **C. Mathieu, B. Hillebrands, and D. Raasch, “Exchange stiffness constant and effective gyromagnetic factor of Gd, Tb, and Nd containing, amorphous rare earth-transition metal film,” IEEE Trans. Magn. **30**, 4434–4436 (1994). [CrossRef]

**37. **E. Dudzik, S. S. Dhesi, S. P. Collins, H. A. Dürr, G. van der Laan, K. Chesnel, M. Belakhovsky, A. Marty, Y. Samson, and J. B. Goedkoop, “X-ray resonant magnetic scattering from FePd thin films,” J. Appl. Phys. **87**, 5469–5471 (2000). [CrossRef]

**38. **A. C. Hurst, T. B. Edo, T. Walther, F. Sweeney, and J. M. Rodenburg, “Probe position recovery for ptychographical imaging,” J. Phys. Conf. Ser. **241**, 012004 (2010). [CrossRef]

**39. **M. Guizar-Sicairos, S. T. Thurman, and J. R. Fienup, “Efficient subpixel image registration algorithms,” Opt. Lett. **33**, 156–158 (2008). [CrossRef]

**40. **M. Dierolf, A. Menzel, P. Thibault, P. Schneider, C. M. Kewish, R. Wepf, O. Bunk, and F. Pfeiffer, “Ptychographic X-ray computed tomography at the nanoscale,” Nature **467**, 436–439 (2010). [CrossRef]

**41. **P. Thibault, M. Dierolf, O. Bunk, A. Menzel, and F. Pfeiffer, “Probe retrieval in ptychographic coherent diffractive imaging,” Ultramicroscopy **109**, 338–343 (2009). [CrossRef]

**42. **M. Dierolf, P. Thibault, A. Menzel, C. M. Kewish, K. Jefimovs, I. Schlichting, K. von König, O. Bunk, and F. Pfeiffer, “Ptychographic coherent diffractive imaging of weakly scattering specimens,” New J. Phys. **12**035017 (2010). [CrossRef]