Overcoming the challenges of high-energy X-ray ptychography

X-ray ptychography is a coherent diffraction imaging technique with a high resolving power and excellent quantitative capabilities. Although very popular in synchrotron facilities nowadays, its implementation with X-ray energies above 15 keV is very rare due to the challenges imposed by the high energies. Here, the implementation of high-energy X-ray ptychography at 17 and 33.6 keV is demonstrated and solutions to overcome the important challenges are provided. Among the particular aspects addressed are the use of an efficient high-energy detector, a long synchrotron beamline for the high degree of spatial coherence, a beam with 1% monochromaticity providing high flux, and efficient multilayer coated Kirkpatrick–Baez X-ray optics to shape the beam. The constraints imposed by the large energy bandwidth are carefully analyzed, as well as the requirements to sample correctly the high-energy diffraction patterns with small speckle size. In this context, optimized scanning trajectories allow the total acquisition time to be reduced by up to 35%. The paper explores these innovative solutions at the ID16A nano-imaging beamline by ptychographic imaging of a 200 nm-thick gold lithography sample.

The first demonstration of X-ray ptychography in synchrotron facilities was performed in 2007 (Rodenburg et al., 2007) at the energy of 8 keV. Since then ptychography has been implemented mostly with energies below 10 keV. A few exceptions are one implementation at 15.25 keV (Schropp et al., 2010), another at 16.95 keV (Enders et al., 2014) and finally one at 14.9 keV (Hé monnot et al., 2016). Only recently we showed that ptychography could also be implemented at 17 keV (Haubrich et al., 2018), which was combined with tomography, and at 33.6 keV (da Silva et al., 2017), where it was used to characterize the smallest ever high-energy X-ray nanofocus. To the best of our knowledge, the latter is the highest energy at which ptychography has been implemented so far.
There are a wide range of applications in which the sample is too thick or opaque to low-energy X-rays and hence highenergy X-ray ptychography becomes essential. This includes, among many others, the characterization of metallic alloys formed by additive manufacturing in the metallurgic industry (Haubrich et al., 2018), the study of the structure degradation of solid oxide fuel cells after operation (Hubert et al., 2016), the development of new materials for long-duration batteries for energy-related problems, and the characterization of components of 3D integrated microelectronics (Fraczkiewicz et al., 2018). Although other approaches have been applied to those scientific problems, the high spatial resolution offered by high-energy X-ray ptychography can be crucial and definitively bridges the spatial resolution gap between electron microscopy and standard X-ray imaging. Furthermore, worldwide efforts are ongoing to build close to diffractionlimited storage rings, such as ESRF-EBS (ESRF-EBS, 2018), which will provide better coherence at higher energies. These efforts should obviously be accompanied by developments to make the techniques operational with the smaller wavelengths. Here we present our solutions to overcome the challenges to implement ptychography at high energies.
A few examples of these challenges are: the low efficiency of the detectors, the need for a sufficiently long beamline to provide high-energy coherent X-ray flux, and high stability of the experimental setup as well as a sufficiently long sample-todetector distance for proper data sampling. For instance, the pixel detectors for direct detection are commonly based on silicon sensors, which are increasingly transparent for energies above 15 keV, with the non-absorbed X-rays transmitted through the sensor damaging the electronics behind it.
Additionally, to obtain a sufficiently long transverse coherence length, we need a very large distance between a small source and the sample position due to the short wavelengths. The vertical emittance of third-generation synchrotron sources is already sufficiently small, but the horizontal one may be a thousand times larger. In the case of the ID16A beamline, which is installed in a high-section of the storage ring, the source size is 970 Â $10 mm (H Â V) assuming 4 nm Â 5 pm (H Â V) emittance. This implies the need for horizontal focusing optics to pre-focus the large source into a secondary source that needs to be far enough upstream of the sample to provide a long transverse coherence length at the sample position. The ongoing upgrade of the sources to fourth-generation mainly aims at reducing this horizontal emittance.
Although optimized for nanofocusing and near-field imaging, the ID16A beamline of the ESRF offers versatility and can also be used for high-energy far-field ptychography (Haubrich et al., 2018;da Silva et al., 2017). Fig. 1 shows a simplified layout of the beamline set for ptychographic experiments. This long beamline works at two discrete energies: 17 and 33.6 keV. The focusing optics based on Kirkpatrick-Baez (KB) mirrors and the nanopositioning system were previously described (Villar et al., 2018;da Silva et al., 2017).
In the next sections, we will describe how we deal with the challenges for the implementation of high-energy ptycho-graphy at this beamline and our solutions to perform not only 2D ptychography but also 3D imaging via ptychographic X-ray computed tomography (PXCT) (Dierolf et al., 2010). While they are developed in the context of a specific beamline, most solutions can be readily transposed to other facilities.

High-energy X-ray detector
Although it can be implemented using an indirect detection system based on a scintillator screen optically coupled to a CCD or CMOS sensor (da Silva et al., 2017;Rodenburg et al., 2007), X-ray ptychography fully benefits from the high sensitivity and low noise of single-photon-counting direct detection systems. The high-frequency speckles typically submerged by the CCD noise are revealed. However, most direct detectors available today are based on Si sensors, which are fairly inefficient for energies above 15 keV. For higher energies, a significant amount of photons pass through the Si sensors and can damage the electronics behind the pixels. Since we work at the energies of 17 and 33.6 keV at the ID16A beamline, the Sibased detectors are not suitable.
For that reason, we tested single-photon-counting pixel detectors with two different high-Z sensors: a 1 mm-thick CdTe sensor and a 500 mm-thick GaAs sensor. The results obtained with CdTe were not satisfactory due to a number of intrinsic problems of this material: non-homogeneous changes of the background, charge trapping and the need for frequent bias resets. On the other hand, the tests with GaAs sensors were very successful. We tested a MAXIPIX (Ponchut et al., 2007(Ponchut et al., , 2011, from the ESRF, based on Medipix2 technology, and a LAMBDA (Pennicard et al., 2013(Pennicard et al., , 2014, from X-Spectrum GmbH, Germany, based on Medipix3 technology. Both sensors have a pixel size of 55 mm. Among the differences, Medipix3 provides increased count rates and optimized counters, whereas Medipix2 offers a lower count rate and limited counters, requiring accumulation of consecutive frames. Despite the difference between the two technologies, both detectors provided very good quantitative results.
The use of high-Z elements as sensors requires the images to be corrected for the inhomogeneity of the material. This is done by pixel-by-pixel division with a flat-field image taken with homogeneous illumination of the detector with an X-ray energy close to the target utilization energy. Thus, we acquired flat-field images of MAXIPIX and LAMBDA detectors using the X-ray fluorescence from a molybdenum foil illuminated with an X-ray tube. The main fluorescence yield of molybdenum occurs at 17.5 keV, which is fairly close to the X-ray energy of 17 keV we used in our experiments. We set the detector threshold to 8 keV during the acquisition and normalized the acquired flat-field image such that the average of the counts across the detector is 1. Each diffraction pattern taken later during the ptychographic scan was then divided by the normalized flat-field image. Appendix A presents a ptychographic diffraction pattern acquired with the MAXIPIX detector before and after the correction.
Concerning the energy of 33.6 keV, the GaAs sensor cannot absorb all the X-rays, which can be detrimental to the detector. For this reason, we choose to use a FReLoN Kodak (KAF-4320 CCD) indirect detection system (Labiche et al., 2007), optically coupled to an almost-defect-free GGG:Eu scintillator. The physical pixel size of the CCD is 24 mm, which is demagnified by 2.5Â using an inhouse-designed combination of lenses between the CCD and the scintillator to an effective detector pixel size of 9.6 mm. It is binned twice to reach a final pixel size of 19.2 mm, and a region of 400 Â 400 pixels of the detector is typically selected after the binning, but it can be adjusted to different sizes according to a trade-off between the beam size at the sample and the X-ray monochromaticity. The binning is done to accumulate more photons into the same pixel and speed up the read-out of the camera. Because of the dark current noise, the use of CCDs requires the acquisition of dark images without beam, of which the average is subtracted from the diffraction pattern images. The response of the detector used here is sufficiently homogeneous and no flat-field correction is applied. Additionally, since the speckles at 33.6 keV are smaller than the ones at 17 keV, the smaller pixel size of the CCD is very suitable for ptychography at such a high energy.
While the single-photon-counting direct detection systems have the big advantage of being very sensitive and able to detect single photons, the maximum count rate of the detectors we have used is not high enough to handle the high flux of optimized third-generation synchrotron setups. This implies that the X-ray beam has to be attenuated to not saturate the detector. On the other hand, the indirect detectors based on optical coupling to a CCD/CMOS can stand a much higher flux, but are limited in effective dynamic range, have defects on the scintillator which can degrade the quality of the acquired images, and are not single-photon-sensitive in most cases. Currently, at the ID16A beamline, we find a compromise between the two technologies for each energy: we use the LAMBDA GaAs single-photon-counting direct detection system at 17 keV and the indirect scintillator/CCD-based detection system at 33.6 keV.

X-ray transverse coherence
The transverse coherence length t of an X-ray beam at the sample position can be written as where is the wavelength, is the beam divergence, Z ss is the source-to-sample distance and D s is the source size. We assume that Z ss is sufficiently large such that ' D s =Z ss . Given that the transverse coherence length of a beam depends on the wavelength, the higher the X-ray energy, the more complicated it is to obtain a relatively large coherence length to implement ptychography. Nevertheless, equation (1) also shows that one can increase the transverse coherence length by increasing the source-to-sample distance, rather than reducing the source size by slitting down the beam. As illustrated in Fig. 1, the ID16A beamline is 185 m long, with a horizontal secondary source located 145 m upstream of the sample, which is sufficient to provide a high-energy coherent X-ray beam for ptychography.
There are only two discrete energies available at ID16A, which are 17 and 33.6 keV with a 1% bandwidth in both cases. The vertical size of the ID16A's source 185 m upstream of the sample position is as small as $10 mm, while the horizontal size is as large as 970 mm. The horizontal secondary source is created 145 m upstream of the sample by focusing the beam onto horizontal slits using a multilayer coated spherical mirror. This allows extraction of a fairly coherent X-ray beam at the sample position. For an extension to other beamlines without a secondary source, one needs to consider the primary source size, which can be reduced using the first pair of slits closest to the source to improve the coherence length at the expense of photon flux.
Figs. 2(a) and 2(b) show the transverse coherence lengths estimated using equation (1) for different source-to-sample distances as a function of the secondary source size for 17 and 33.6 keV, respectively. We can notice that the values of t are about twice smaller at 33.6 keV relative to at 17 keV for the same source sizes. As illustrated, the reduction of the secondary source size to increase t costs many photons. This highlights one of the biggest challenges of working at high energies.
At the ID16A beamline, the secondary source size is selected to coherently illuminate the KB optics. The typical aperture values in front of the focusing optics are 230 Â 550 mm (H Â V) and 215 Â 460 mm (H Â V) for 17 and 33.6 keV, respectively. Therefore, we see from Fig. 2(a) that we need a secondary source aperture of about 50 mm or less to reach a transverse coherence length equal to or larger than the aperture upstream of the KB mirrors at 17 keV. The situation is even more complicated at 33.6 keV, where one needs to close the secondary source to less than 30 mm as observed from Fig. 2 These requirements cannot always be fulfilled, especially when a high photon flux is needed. We have two ways to deal with this problem. In the first, we close the aperture right upstream of the KB mirrors to select a coherent area of the photons. This also provides control of the divergence of the beam. We typically work with an aperture of 104 Â 240 mm (H Â V) or 52 Â 120 mm (H Â V), depending on the photon flux demand, for both energies. With focal distances of 43 mm (H) and 100 mm (V) of the KB mirrors, this means a divergence of 2.4 mrad or 1.2 mrad, respectively. In this way, at the sample-to-detector distances of 1.936 m at 17 keV and of 1.265 m at 33.6 keV, the transmitted direct beam will not fully cover the detector area and we can record simultaneously the bright-field and the dark-field parts of the coherent diffraction pattern. The bright direct beam contains an in-line hologram, whereas the dark-field part contains the scattering beyond the direct beam with high-resolution information. Both regions are very important for the ptychographic phase retrieval and a beam stopper would disrupt the quality of the reconstructions. An advantage of doing this is that we spread the direct beam across several pixels in the detector, which reduces the demand for high count rate and high dynamic range of the detector.
The second way, sometimes used in combination with the first one, is to take into account partial coherence effects during the ptychographic phase retrieval. It was shown that one can decompose the retrieved beam at the sample position in orthogonal modes by reconstructing mixed probe states during the ptychographic phase retrieval (Thibault & Menzel, 2013). As we will discuss later in more detail, three modes for 17 keV and five modes for 33.6 keV measurements are sufficient to reconstruct high-quality images with the secondary source opened to 50 mm in both cases.

X-ray longitudinal coherence
One of the main challenges when working with high energies is the demand for high coherent photon flux. In order to increase this flux, the idea of using pink beam, with 1% energy bandwith such as the one in the ID16A beamline, is very attractive. However, although one can still obtain a long transverse coherence length of the beam, the drawback is the limited longitudinal coherence. The short longitudinal coherence length will reduce the visibility of the high-frequency speckles, which are the ones we want to detect in order to reach high spatial resolution in the reconstructed image.
This problem has already been discussed in previous works on coherent X-ray imaging techniques (Jacobsen et al., 2017;Enders et al., 2014;Abbey et al., 2011;van der Veen & Pfeiffer, 2004). Briefly, the beam size D must fulfill the following condition: where l ¼ 2 =2Á is the longitudinal coherence length, 2 is the maximum X-ray scattering angle, is the wavelength, Á is the bandwidth, and we call Á= the monochromaticity. As a consequence of this limitation, we need to work with a relatively small beam at short wavelengths, which will slow down the scans of large samples. In order to scan a large area, our solution is to use only a small region of the detector to collect the diffraction pattern, which implies decreasing the value of 2 in equation (2). This allows us to use a relatively large beam at the sample position.
The drawback is a possible reduction of spatial resolution given that, in case the sample scatters beyond the region of the detector we use, we will not record those high-frequency speckles. Nevertheless, the extent of the diffraction pattern is reduced due to the high energy and we can still work in such a way for most of the samples. In the case of samples such as test patterns that scatter a lot, we lose resolution. Secondly, given that one needs to acquire several hundreds of 2D images over 180 for PXCT, any undersampling in angle will decrease the resolution (da Silva et al., 2018). Thus, we will anyhow lose spatial resolution after the tomographic reconstruction if we cannot acquire 2D images relatively quickly.
In summary, the high flux and degree of monochromaticity have to be carefully balanced. We evaluate the constraints imposed by equation (2) to find a compromise between the spatial resolution of the acquired images and the speed of the scan for a given field-of-view. Fig. 3 displays the estimates of the maximum beam size we can use for the different X-ray wavelengths and different monochromaticity degrees according to equation (2). Fig. 3(a) displays a bi-dimensional histogram calculated for a sampleto-detector distance of 1.936 m and a detection area of 256 Â 256 pixels with a pixel size of 55 mm typical of a Medipix-based detector. This is the regular configuration used at the ID16A beamline for ptychography at 17 keV and 1% monochromaticity. In this case, we see from Transverse coherence lengths at the sample position as a function of the source size according to equation (1) for (a) different source-to-sample distances at 17 keV ( = 0.73 Å ) and (b) different source-to-sample distances at 33.6 keV ( = 0.37 Å ). In all figures, the lines with the transverse coherence length values assist the visualization of the color scale on the bi-dimensional histogram at certain positions. use a beam size larger than 2 mm at the sample position for ptychography at 17 keV. Fig. 3(b) shows the estimates calculated for a sample-todetector distance of 1.265 m and using an indirect scintillator/ CCD-based detection system, with an effective pixel size of 19.2 mm and a detection area of 400 Â 400 pixels after binning. This is the typical configuration at the ID16A beamline for ptychography at 33.6 keV and 1% monochromaticity. In this case, we see from Fig. 3(b) that we cannot use a beam size larger than 1.2 mm at the sample position for ptychography at 33.6 keV.
In practice, the beam size is selected by working slightly out of focus and setting the focus-to-sample distance according to the focus size and beam divergence.

Sampling requirements
Besides the requirements of transverse and longitudinal coherence, ptychography requires certain conditions on the sampling of the diffraction pattern to be fulfilled. These sampling requirements were described in previous works (da Edo et al., 2013), which extended the sampling requirements of coherent X-ray diffraction imaging (Miao et al., 1998) to ptychography. Briefly, we need the beam size D to be such that where Z sd is the sample-to-detector distance and p det is the detector pixel size.
Given that the size of the smallest speckle is Z sd =D, equation (3) implies that at least two pixels are needed for each detected speckle. Figs. 4(a) and 4(b) display the maximum detector pixel size for different sample-to-detector distances as a function of the beam size for 17 and 33.6 keV, respectively.
Equation (3) covers the sampling of the diffraction pattern, but ptychography is a combination of measuring in reciprocal space as a function of positional scanning in real space. Overlap between adjacent scanning positions is required and the common rule is to choose a step size of 1/3 of the beam size at the sample position . It has been recently shown that a denser sampling in real space can compensate for sparse sampling in reciprocal space and vice versa (da Edo et al., 2013;Batey et al., 2014). Based on the previous works, the sampling condition for ptychography is defined by the 1D sampling ratio given by (da  research papers Maximum beam size at the sample position as a function of the wavelength (energy) and the X-ray beam monochromaticity at beamline ID16A according to equation (2) where ¼ R=D is the ratio between the step size R and the beam size D, and is the inverse of the oversampling factor in reciprocal space and can be written as ¼ p det D=Z sd . Therefore, equation (4) takes precedence over equation (3). Equation (4) ensures there is no gap in the filling of the joint real-reciprocal phase space of ptychography and the Heisenberg boxes partially overlap (da .

High-energy X-ray optics and stability of the experimental setup
Two key components to ensure high-quality nano-imaging with ptychography are the stability of the experimental setup of the beamline at the nanometre range and efficient X-ray optics to shape the beam at the sample position. The nanopositioning (Villar et al., 2018) and the multilayer coated KB mirrors (Kirkpatrick & Baez, 1948) optics of the ID16A beamline (da Silva et al., 2017;Morawe et al., 2015) have been described previously.
The main point concerns the scanning nature of ptychography. The positioning of the sample relative to the beam during the scan needs to be as accurate as the expected spatial resolution. In addition, the beam must not change during each ptychographic scan. Since the ID16A beamline is a nanoimaging beamline designed to offer the smallest ever focus size in the high-energy X-ray regime, it fulfills these requirements. Although ptychography does not require a nanofocus, it can still fully benefit from the accurate nanopositioning and stability of the experimental setup.
The solution at the ID16A beamline to the requirements imposed by the ptychographic scan are fine movement stages with an active correction scheme (Villar et al., 2018). The positioning is done by a six degrees of freedom piezo stage with an accuracy better than 5 nm over a scanning range of 50 mm Â 50 mm. Twelve capacitive sensors attached to a reference metrology frame are used to correct the movements of the piezo stage. The long-term stability of the system (12 nm over a period of 10 h in the horizontal direction) largely exceeds the stability requirement considering a ptychography scan duration of less than 10 min. Nevertheless, further work is ongoing to reference as well the KB optics with respect to the reference metrology frame in the two directions transverse to the beam.
In regard to the X-ray optics, multilayer coated KB mirrors are currently the most efficient focusing optics of high-energy X-rays and have a large acceptance. The efficiency of Fresnel zone plates (Baez, 1961) is generally low at photon energies above 20 keV. Compound refractive optics (Snigirev et al., 1996) on the other hand suffer from a very low numerical aperture at those energies. In addition, although multilayer Laue lenses (MLLs) (Kang et al., 2008;Yan et al., 2011) can also offer high efficiency at high energies, they require high monochromaticity and have a small acceptance. Their use is complicated due to the shorter focal distances compared with the KBs that offer more flexibility.

Strategy for fast data acquisition with irregular scanning grids
One of the main sources of overhead in ptychographic scans is the movement of the motors. For the sake of stability, the speed of the piezo actuators at the ID16A beamline is currently limited to 4 mm s À1 in the horizontal direction and 1 mm s À1 in the vertical direction. One can notice that the ptychographic scan of samples of tens of microns with step sizes of 1 mm will take a considerable amount of time due to the motor movements. Additionally, the periodic raster grids which could favor the faster horizontal movements can lead to artifacts due to the raster grid pathology of ptychography (Thibault et al., 2009).
The continuous scan mode, sometimes also called fly scan, has been proposed to overcome the bottleneck of slow motor movement (Deng et al., 2015;Pelz et al., 2014;Clark et al., 2014). However, it is more noise sensitive relative to the conventional step-base scanning mode, the reconstruction methods requiring a large number of probe modes (>10) to account for the effectively reduced spatial coherence (Thibault & Menzel, 2013). This increases the computational complexity and affects necessarily the achieved signal-to-noise ratio associated with the deconvolution. In addition, since the continuous scan is restricted to a linear path with constant velocity only, it leads to periodic raster grid artifacts. Alternatively, a new scheme involving simultaneous scanning of optics (Fresnel zone plate) and sample was recently demonstrated (Odstrčil et al., 2018), but its complexity is hardly compatible with KB mirrors.
In view of all this, we use the step-based ptychography at the ID16A beamline. We need therefore to optimize the trajectory of the scan, somehow taking into account the difference of speed in the two directions. As a GPS that optimizes the trajectory of cars, or a delivery company that optimizes the way the packages are delivered to gain time, we can also optimize the trajectory of the ptychographic scan in such a way that all the points of the scan grids are visited in a minimum amount of time with the constraints of speed of the motors. Our idea is then to use a solver of the fundamental traveling salesman problem (Applegate et al., 2007). Such an algorithm allows us to find the shortest possible route, or a very good approximation, to visit points in a city, given the distance between each pair of points, and return to the origin.
We used the 'Google Operations Research tools' Python package (OR Tools) (Google, 2018) to create a server that implements such an optimization as follows: (i) generate the scan grid based on parameters such as scanning grid geometry, dimensions of the field-of-view, and step size; (ii) calculate the combination of the distances between each pair of points; (iii) optimize the trajectory using OR Tools taking into account the difference of speed between horizontal and vertical directions; (iv) return an optimized trajectory back to the software controlling the movements of the motors; research papers (v) during the scan the piezos start moving to the next scan position while the detector is reading out the data. The latter optimization is quite time saving when using CCDs (read-out time = 0.55 s in our case). Fig. 5(a) shows a non-optimized typical scanning grid we use at the ID16A beamline for a spiral scan of 4 Â 4 mm and radial step size of 0.4 mm. Figs. 5(b) and 5(c) show the resulting optimized grids using Euclidean and Chebyshev metrics, respectively. The Euclidean metrics corresponds to an isotropic actuator. The Chebyshev metrics corresponds well to the usual case where a horizontal and vertical actuator are moved in parallel, each at its own speed. Since Chebyshev metrics optimizes the maximum of the absolute values of the position differences, it will favor the movements in the diagonal, in contrast to the Euclidean metrics that optimizes the squares of the position differences and will favor the orthogonal movements as seen in Fig. 5. We choose the central point as the starting point to save time during the tomographic scan. After each rotation, the motors are positioned at or close to the starting point such that we do not need to wait for the motors before starting the next ptychographic scan.
The optimization depends on lengths of the field-of-view and, consequently, on the number of points of the scan. Fig. 6 shows how the total scan time evolves as a function of the square field-of-view lengths and the number of scan points before and after the optimization. For the estimates, we only take into account the time spent during the motor movement, not the detector read-out time. We clearly see the gain in time as we increase the size of the scanning area. A reduction of up to 35% of scanning time relative to the scan without optimized trajectory can be achieved. For example, Fig. 6 shows that for a scanning region of 20 mm Â 20 mm with a step size of 0.4 mm at the ID16A beamline, the total scanning time with optimized trajectory takes about 22 min compared with 33 min for the one without optimization.
For these estimates, since we increase the field-of-view length equally in horizontal and vertical directions, one can expect that the behavior of the total time as a function of the field-of-view length should follow a second-order polynomial. We can observe this behavior in Fig. 6. We therefore fit a second-order polynomial ax 2 þ bx þ c to the curves and obtain: a ¼ 5:0, b ¼ À1:0 and c ¼ 0:4 without optimization; a ¼ 3:2, b ¼ 1:7 and c ¼ À0:4 with optimization assuming Euclidean metrics; a ¼ 3:3, b ¼ 1:3 and c ¼ À2:6 with optimization using Chebyshev metrics. We notice the coefficients of the second-power term are similar between Euclidean and Chebyshev metrics, but they are considerably smaller than the one obtained without optimization. Example of the optimization of the scan grid trajectory of a ptychographic scan of 4 mm Â 4 mm using the optimization open-source software OR Tools by Google. Two different metrics are compared. (a) The typical scan grid composed of concentric circles truncated at the border to fit into a rectangular region. Such a grid prevents the raster grid pathology of ptychography. (b) Optimized trajectory using Euclidean metrics. (c) Optimized trajectory using Chebyshev metrics, which favors diagonal movements. The starting point is indicated by a blue triangle and the ending point is indicated by a green square.

Figure 6
Comparison of the total time for a square ptychographic scan before and after optimization, and assuming Euclidean or Chebyshev metrics. Total time as a function of the field-of-view length and, as a consequence, the number of scan points. A second-order polynomial fit is shown alongside each curve.

Optimized ptychographic imaging of a lithography structure
As a validation we present here the results of the ptychographic imaging of a 200 nm-thick gold lithography structure of a Siemens star whose smallest spoke width is 50 nm. The same sample was scanned at the two energies available at the ID16A beamline and the data were processed using the Python package Ptypy (Enders & Thibault, 2016). We describe each scan separately in the following subsections. Fig. 7 shows the results of the ptychographic imaging at 17 keV of the test sample. Figs. 7(a) and 7(b) display the phase contrast and amplitude contrast images, respectively, obtained after data processing of the ptychographic scan. The data processing was done with 600 iterations of the difference map algorithm (Thibault et al., 2008(Thibault et al., , 2009, followed by 200 iterations of maximum likelihood (Thibault & Guizar-Sicairos, 2012) and assuming three probe modes. The pixel size of the reconstructed images was 10 nm and the spatial resolution estimated by Fourier ring correlation (FRC) ( van Heel & Schatz, 2005) using the phase contrast image was 25 nm as shown in Appendix B. Figs. 7(c), 7(d) and 7(e) show the three orthogonal modes of the retrieved beam at the sample position. We can see that the main mode concentrates most of the power, about 95%, while the other two contribute only up to 5%, which means that the X-ray beam was fairly coherent or that the contribution of other partial coherence effects was small.

Ptychography at 17 keV
The ptychographic scan was performed with the sample 1 mm downstream of the focus position where the beam size is about 1.2 mm. The aperture upstream of the KB mirrors was 52 mm Â 120 mm (H Â V), which gives a divergence of 1.2 mrad. A pinhole of 30 mm diameter was positioned after the KB mirrors to clean the scattering of the KB mirrors. The scanning positions lay on a circular shell grid with a radial step size of 0.4 mm. The field-of-view was about 20 mm Â 20 mm, which corresponds to 1995 diffraction patterns of 256 Â 256 pixels acquired with 0.5 s exposure time each.
The MAXIPIX detector with a 500 mm-thick GaAs-sensor and pixel size of 55 mm was positioned 1.936 m downstream of the sample. The X-ray beam was attenuated by a factor of 65 by a foil of 4.6 mm of gold and another foil of 2 mm of silicon due to the limited count rate of the MAXIPIX detector. For the experiments with the LAMBDA detector in a similar setup, we attenuated the beam by a factor of 31 by two foils of gold, one 4.6 mm thick and another 9.2 mm thick, which highlights the difference between the Medipix2 and Medipix3 technologies. The horizontal secondary source of the beamline was closed to 50 mm to increase the transverse coherence of the illumination.
One can notice that the sampling requirement in reciprocal space according to equation (3) is fulfilled because it requires that D < 1.28 mm. Additionally, if we consider the joint real and reciprocal space sampling requirements, we obtain ¼ 0:33, ¼ 0:47 and then 1= ¼ 6:45, which is considerably larger than 1 and the sampling condition of equation (4) is fulfilled. The data processing was done with 800 iterations of the difference map algorithm followed by 300 iterations of maximum likelihood and assuming five probe modes. The pixel size of the reconstructed images was 7.6 nm and the spatial resolution estimated by FRC using the phase contrast image was 15 nm as shown in Appendix B.

Ptychography at 33.6 keV
Given that the X-ray absorption by the sample at 33.6 keV is much lower than at 17 keV, we noticed the decrease of the quality of the amplitude image in Fig. 8(b) relative to Fig. 7(b).  show the five orthogonal modes of the retrieved beam at the sample position. In this case, we see that the main mode concentrates about 85% of the power, while the other four contribute up to 15%. This is different from the results at 17 keV in Fig. 7 because the transverse coherence length at 33.6 keV is shorter than the one at 17 keV given that the horizontal secondary source was closed to 50 mm in both cases. However, the X-ray beam was fairly coherent given that the main mode carried 85% of the power.
The ptychographic scan was performed with the sample 0.834 mm downstream of the focus position where the beam size is about 1 mm. The aperture upstream of the KB mirrors was 52 Â 120 mm (H Â V), which gives a divergence of 1.2 mrad. The horizontal secondary source of the beamline was closed to 50 mm to increase the transverse coherence of the illumination. A pinhole of 30 mm diameter was positioned after the KB mirrors to clean the scattering of the KB mirrors. The indirect scintillator/CCD-based detector with effective pixel size of 9.6 mm was positioned 1.265 m downstream of the sample. The X-ray beam was basically not attenuated, because the indirect detector system can stand a high photon flux. The scanning positions lay on a circular shell grid with a radial step size of 0.35 mm. The field-of-view was about 7 mm Â 7 mm, which corresponds to 320 diffraction patterns of 640 Â 640 pixels acquired with 1 s exposure time each.
During the data processing, the detector pixel size was binned 2Â to 19.2 mm, yielding diffraction patterns with 320 Â 320 pixels. Those values were in agreement with equation (2) and the sampling requirements of equation (3). The joint realreciprocal space sampling condition of equation (4) is also fulfilled given that ¼ 0:35, ¼ 0:41, yielding 1= ¼ 6:9, which is larger than 1.

Conclusions
The use of high-energy X-rays in imaging is very attractive for several reasons: the larger penetration power enables the study of samples opaque to low-energy X-rays, the depth of focus increases for a given resolution, the dose received by the sample is potentially lowered, and it seems possible to improve the resolution with the shorter wavelengths. Additionally, for the emerging technique of spectral ptychography, which combines spectroscopic measurements and ptychography, the high-energy X-rays are critical to access the absorption edges of certain high-Z elements.
In this work, we presented solutions to overcome major challenges to implement X-ray ptychography at high energies. We addressed particular aspects such as the choice of an X-ray detector that handles the high-energy photons, the challenging layout of long beamlines to obtain long transverse coherence lengths at short wavelength, the use of a beam of 1% monochromaticity to increase photon flux, and the optimization of the scan trajectory to reduce the duration of the scan. We also showed how to deal with the stringent sampling requirements of ptychography at high energies.
Because of their intrinsic advantages and limitations, we found a compromise between two different detector technologies for the two discrete energies of the beamline. We used a LAMBDA GaAs single-photon-counting direct detection system at 17 keV and an indirect scintillator/CCD-based detection system at 33.6 keV. We expect the constant evolution of detector technology will improve this situation, particularly when attention is given to high-Z sensor materials.
Concerning the use of pink beam, we investigated the constraints imposed by 1% monochromaticity to implement high-energy ptychography with a high flux of coherent photons. Since this imposes a limit to the maximum beam size at the sample position for a ptychographic scan, we found a compromise between the spatial resolution of the acquired images and the speed of the scan for a given field-of-view.
Another challenge was the scanning nature of ptychography. The slow movements of the scanning motors cause overhead in ptychographic scans. To minimize the time loss we optimized the trajectory of the scan using an optimization approach based on the traveling salesman problem. We took advantage of software tools provided by Google to save up to 35% of the duration of the scan relative to the standard scans without optimization. It should be noted that the trajectory optimization remains relevant in the context of continuous scans with irregular patterns (Odstrčil et al., 2018).
Although the solutions presented here have been implemented at the ID16A nano-imaging beamline of the ESRF, they can be readily extended to other beamlines in other facilities. This work offers a guide to overcoming the challenges and paves the way to a more routine use of high-energy X-ray ptychography.
APPENDIX A Flat-field correction of the diffraction patterns acquired with the GaAs sensor MAXIPIX Fig. 9 shows a ptychographic diffraction pattern acquired with the GaAs sensor MAXIPIX detector before and after the correction. Fig. 9(a) presents the diffraction pattern without correction where we can observe the grainy structure of the detector flat-field as well as defects in the sensor indicated by the arrows. Fig. 9(b) presents the diffraction pattern after flatfield correction, where we can notice the correction is highly efficient as it removes the grainy structure and defects. The  the correction of the grainy structures. The orthogonal lines are actual features of the beam produced by the KB optics.

APPENDIX B Estimate of spatial resolution by Fourier ring correlation
We estimated the spatial resolution of the reconstructed images in Figs. 7 and 8 using the FRC method ( van Heel & Schatz, 2005). Figs. 10(a) and 10(b) display the resulting curves for 17 and 33.6 keV, respectively. The estimates were performed from the results of two independent ptychographic scans with identical parameters for each energy. The spatial resolution is estimated from the division of the pixel size by the abscissa value of the intersection between the correlation curves with the 1 bit threshold curve, whose values are indicated in the figures.

Figure 10
Fourier ring correlation curves to estimate the spatial resolution using 1 bit threshold. (a) Estimate for the ptychographic reconstruction of the phase contrast image at 17 keV from Fig. 7, on which the pixel size is 10 nm and the resolution is 25 nm. (b) Estimate for the ptychographic reconstruction of the phase contrast image at 33.6 keV from Fig. 8, on which the pixel size is 7.6 nm and the resolution is 15 nm. The values on the axis of the abscissae correspond to the spatial frequency normalized by the Nyquist's frequency. The values of the abscissae where the FRC curve intersects the threshold curve are indicated.