Live processing of momentum-resolved STEM data for first moment imaging and ptychography
Abstract
A reformulated implementation of single-sideband ptychography enables analysis and display of live detector data streams in 4D scanning transmission electron microscopy (STEM) using the LiberTEM open-source platform. This is combined with live first moment and further virtual STEM detector analysis. Processing of both real experimental and simulated data shows the characteristics of this method when data is processed progressively, as opposed to the usual offline processing of a complete dataset. In particular, the single side band method is compared to other techniques such as the enhanced ptychographic engine in order to ascertain its capability for structural imaging at increased specimen thickness. Qualitatively interpretable live results are obtained also if the sample is moved, or magnification is changed during the analysis. This allows live optimization of instrument as well as specimen parameters during the analysis. The methodology is especially expected to improve contrast- and dose-efficient in-situ imaging of weakly scattering specimens, where fast live feedback during the experiment is required.
Key Words: 4D-STEM, Ptychography, First moment imaging, Phase retrieval, In2Se3, SrTiO3
(Received 6 May 2021; revised 6 July 2021; accepted 17 July 2021))
1 Introduction
The development of ultrafast cameras for transmission electron microscopy (TEM) such as the pnCCD (Müller et al., 2012; Ryll et al., 2016), the Medipix3 chip (Plackett et al., 2013), delay-line detectors (Müller-Caspary et al., 2015; Oelsner et al., 2001) or the EMPAD (Tate et al., 2016) enabled the collection of the full diffraction space up to a flexible cut-off spatial frequency at each scan point in scanning TEM (STEM). This technology paved the way for momentum-resolved STEM techniques with high samplings in both real and diffraction space, sometimes being referred to as 4D-STEM. Acquisitions with a detector frame rate of several kHz are currently achieved by employing these cameras. In particular, the mapping of electric fields and charge densities down to the atomic scale (Müller et al., 2014), meso-scale strain, and electric field measurements by nano-beam electron diffraction (Müller-Caspary et al., 2015), and, furthermore, electron ptychography (Hoppe, 1969; Hegerl & Hoppe, 1970) have been enabled by this dramatic detector speed enhancement (Nellist et al., 1995; Rodenburg & Bates, 1992; Rodenburg et al., 1993; Jiang et al., 2018; Humphry et al., 2012).
Due to its excellent dose efficiency (Zhou et al., 2020) STEM ptychography as a method to retrieve the complex object transmission function has gained increasing interest. Four-dimensional data sets combining real and diffraction space information have been shown to provide enormous flexibility in post-acquisition processing. For example, ptychography has been demonstrated to be capable of both resolution improvement and aberration correction after the acquisition using computational methods (Nellist et al., 1995; Gao et al., 2017). It achieves a better signal to noise ratio for weak phase objects than annular bright field or differential phase contrast (Seki et al., 2018) and allows reconstruction at extremely low dose (O’Leary et al., 2020).
The high data rates require an efficient implementation of advanced methods for imaging contrast via post-processing in order to minimise the duration of numerical processing. Ultimately, computing and software implementation capabilities are desirable that allow for the live reconstruction of the ptychographic phase and amplitude, first moments, electric fields, and charge densities, for example.
During experiments a region of interest is usually selected via imaging employing conventional STEM detectors. Weakly scattering and beam sensitive specimens, where ptychography and first moment imaging (Waddell & Chapman, 1979; Müller et al., 2014) can be most advantageous, generate poor contrast in conventional imaging modes and quickly degrade using typical beam currents in conventional STEM (Peet et al., 2019). 4D-STEM analyses are normally applied after data acquisition and transfer to a data processing workstation. It is therefore not possible to be certain that the selected region and microscope settings were appropriate until after successful reconstruction. For that reason, one often acquires a larger number of data sets, which takes considerable storage space in the case of 4D-STEM. In contrast, a fast implementation of the considered computational methods would allow to perform this data evaluation live during the experiment.
In this study, we demonstrate 4D-STEM continuous live scanning with the simultaneous ptychographic single-sideband (SSB) reconstruction combined with bright field, annular dark field, and first moment imaging, including its divergence which is proportional to the charge density in thin specimens. To this end, the ptychographic algorithm was firstly reformulated mathematically. This allows navigation on the sample and change of microscope parameters with a live view of the reconstruction, alongside signals from other 4D-STEM techniques. Secondly, we use SrTiO3 and In2Se3 to demonstrate the live evaluation capability of our approach in experiments by in-situ processing of the data stream of an ultrafast camera. Thirdly, the results obtained live are validated by conventional post-processing. Particular attention is drawn to the capability of SSB to provide reliable structural images, to reconstruction artefacts arising from processing partial scans and to reconstructing non-periodic objects. Moreover, the performances of SSB ptychography and the enhanced ptychographic engine (ePIE) are compared, interestingly pointing towards SSB being significantly more robust against dynamical scattering in terms of qualitative structural imaging. This article closes with a detailed discussion and a summary.
2 Materials and Methods
2.1 Live imaging
A continuous live scanning display for large-scale 4D-STEM data benefits greatly from a data processing method where smaller portions of input data are processed independently and merged progressively into the complete result. For virtual detectors and first moments, often referred to as "centre-of-mass (COM)", this is trivial to achieve since each detector frame, i.e., diffraction pattern, produces an independent entry in the final data set which allows frames to be processed individually, accumulating results in a buffer. Displaying the contents of this buffer at regular intervals provides a live-updating view.
In contrast, ptychography generates results by putting detector frames from the entire data set, or at least a local environment, in relation to each other. Consequently, adapting the methodology so as to circumvent the processing of the entire data set at once, thus gradually merging partial results extracted from portions of the input data into the complete result, is necessary. As previously demonstrated by Rodenburg & Bates (1992), Rodenburg et al. (1993) and Pennycook et al. (2015), both phase and amplitude information can be extracted from a set of diffraction patterns (usually restricting to the Ronchigram region) by performing the Fourier transform of the four-dimensional data set with respect to the scan raster and reordering the dimensions. Depending on the model presumed for the interaction between specimen and incident STEM probe, the direct inversion of the data can either be done by Wigner Distribution Deconvolution (WDD) or the SSB ptychography scheme (Rodenburg et al., 1993). Whereas WDD is based on a single interaction with an arbitrary complex object transmission function and is capable of separating specimen and probe, the weak phase approximation
(1) |
governs the SSB approach. Here, the specimen exit wave at a given scan point can be expressed by a multiplication of the probe wave function with the first-order Taylor expansion of a phase object with phase distribution . It is hence limited to weakly scattering ultra-thin objects e.g. thin light matter investigated with relativistic electrons. Any quantitative interpretation of SSB reconstructions of real data should, therefore, be examined critically since eq. (1) breaks down quickly with increasing thickness. Its capability of direct, dose-efficient phase recovery makes it nevertheless attractive for the in situ qualitative assessment of specimen and imaging conditions. A more advanced ptychography scheme can still be applied after recording. Because a data point in the final reconstruction depends on all recorded scan points, the reconstruction is only accurate if it is applied to the full 4D data.

We refer to original work for a derivation of the conventional SSB methodology (Rodenburg & Bates, 1992; Pennycook et al., 2015) and give a concise summary here. The first processing step consists of Fourier transforming the 4D data cube as to the scan coordinate, translating the scan coordinate in real space to spatial frequencies sampled by the scanning probe. This new 4D data cube can be ordered such that each scan spatial frequency defines one plane. By employing the weak phase object approximation in eq. (1), Rodenburg et al. have shown analytically that the data in each plane is described by three discs of the size of the probe-forming aperture, positioned at the origin and as Friedel pairs at the positions defined by the spatial frequency vector . Importantly, double overlaps as depicted schematically in Fig. 1 contain the complex Fourier coefficients of , potentially affected by aberrations of the probe-forming system. The double overlap regions are often referred to as trotters colloquially.
The ptychographic SSB reconstruction is a linear function of the input data since the result is obtained with a sequence of linear transformations, such as Fourier transforms, element-wise multiplication, and summation (Pennycook et al., 2015). Such linear functions are particularly suitable for incremental processing since they are additive. Mathematically, the complete input data can be understood as the sum of smaller individual data portions that are padded with zeros to fill the shape of the complete data set. Additive functions allow to calculate the complete result by accumulating the processing results of zero-padded portions in any subdivision and order. Furthermore, intermediate results can be extracted at any desired stage from the yet incomplete sum of results.
However, directly processing zero-padded data this way is very inefficient for computationally demanding algorithms such as ptychography employing large 4D-STEM data, because the processing effort and memory consumption is amplified by the number of subdivisions. For that reason, the algorithm should be reformulated to process smaller input data portions without zero-padding. The additivity and homogeneity of linear functions gives ample freedom to restructure the underlying data processing flow towards this goal, allowing development of mathematically equivalent implementations that are optimized for live imaging.
In the particular case of SSB ptychography, individual spatial frequencies of the result are extracted from spatial frequencies of signals at specific scattering angle ranges within the double overlaps (Rodenburg et al., 1993; Pennycook et al., 2015) introduced in Fig. 1.
Suppose we have the intensity of diffraction patterns present as four-dimensional data, which is written as and the notation represents the set of natural numbers not exceeding . That is, with the total number of elements . The indices represent the scan position index, with the total number of scanning steps being and in each direction. Each matrix is a diffraction pattern where and represent the pixel index on the detector with dimension . Each pixel index corresponds to a scattering angle, or equivalently, spatial frequency in the specimen.
We can write the Fourier transform with respect to the scan raster as
(2) |
where and denote the spatial frequencies in the scan dimension, taking the places of and . Therefore we obtain a four-dimensional dataset in the spatial frequency domain, i.e., .
The next step in SSB is to apply a filter for each tuple of spatial frequencies that calculates the weighted average of the spatial frequency signal over specific ranges of pixels, i.e. scattering angles , that can have positive or negative weight as defined by the trotters. It should be noted that the structure of this filter is different for each tuple of spatial frequencies.
Using (2), we can write the reconstruction in the Fourier domain as
(3) | ||||
The reformulation is given by interchanging the summation and the index dimension of detector and the index of scan points in the real and frequency domain, respectively. This nested summation can be pruned without changing the result by skipping parts that are known to yield zero, for example calculations for empty double overlap regions. Note that essentially represents the Fourier coefficients of in eq. (1) which are potentially affected by aberrations of the probe-forming system.
The inner part of eq. (3) can be implemented with a matrix product between and . The outer sum over and can then be sub-divided and reordered to process the input data incrementally in smaller portions. Numerically, the filter matrix can be stored efficiently as a sparse matrix since the trotters for the highest frequencies are often empty (no overlap), and for many frequencies the double overlap region where the filter is non-zero, is small.
As an intermediate summary, this formulation translates the SSB scheme to a matrix product of a partial input data matrix with a sparse matrix containing the double overlap regions. Elements of a Fourier transform are then applied to the result of this matrix product. This generates a partial reconstruction result in the frequency domain that covers the entire field of view. The partial reconstructions for all partial input data portions are accumulated in a global buffer using a sum, as described above. For a live view of the reconstruction in the spatial domain, the contents of this buffer can be inversely Fourier transformed at any desired time to show the transmission function of the specimen within the weak phase object approximation.
We used LiberTEM (Clausen et al., 2021) as a data processing framework since it is optimized for MapReduce-like approaches and designed with live data processing capabilities in mind (Clausen et al., 2020). LiberTEM user-defined functions (UDFs) provide the application programming interface (API) to efficiently implement operations that follow the described pattern: A method to process a stack of frames that is called repeatedly, task data to store constant data such as the sparse matrix for the double overlaps, result buffers of arbitrary type and shape, and user-defined merging operations to generate a result of arbitrary complexity from partial results. Furthermore, LiberTEM allows to update a result display each time a partial result is merged. UDFs for first moment analysis and virtual detectors were already implemented before for offline data analysis.
To run the UDFs on live data, we implemented a prototype live UDF back-end that allows to run a set of UDFs on data from a Quantum Detectors Merlin for EM Medipix3 for electron microscopy (Plackett et al., 2013; Quantum Detectors, 2019). It uses multiple CPU cores for decoding the raw data from the detector, and a single GPU for the main processing task, which was sufficient for this application. A production-ready version with support for multiple processing nodes, further enhanced use of multiple CPUs and multiple GPUs similar to the offline data processing capabilities of LiberTEM is being designed at the time of writing and will be published as open-source as a part of LiberTEM.
For comparison, ePIE (Maiden & Rodenburg, 2009) based ptychographic reconstructions have been performed in post processing as it can reconstruct both the complex object transmission function and the complex illumination, still presuming single interaction of probe and specimen, but considering an arbitrary complex object transmission function. This was done to check whether the straightforward SSB approach compromises the quality of the result compared to more advanced ptychographic schemes. It has to be noted that, as an iterative method, ePIE is not suitable for live imaging in the current realisations.
2.2 Material system
We demonstrate live processing using two different specimens. First, indium selenide (In2Se3) was used to highlight the advantages of live ptychography and centre of mass in comparison to conventional STEM (Ye et al., 1998). Second, a strontium titanate (SrTiO3) lamella with the electron beam incident along the [100] axis for a more quantitative analysis was used. The latter is stable and provides good contrast in conventional STEM for comparison and adjustments, is well-characterized, and at the same time can highlight the ability to also resolve the light oxygen columns that are difficult to image with reliable contrast by conventional STEM techniques (Browning et al., 1995). Too small double overlap regions with an area of less than 10 px were omitted in live processing to avoid the introduction of excessive noise. This can be understood as a band-pass filter applied to exclude the high frequencies close to the transfer limit of SSB ptychography which corresponds to twice the radius of the probe-forming aperture.
2.3 Experimental setup
First moment imaging and ptychography require the correct alignment and calibration of the scan (specimen) coordinate system with respect to the detector coordinate system. The convergence angle of the incident probe was measured with a polycrystalline gold specimen. Employing parallel illumination first, the (111) gold diffraction ring was used to calibrate the diffraction space assuming a lattice constant of gold of 0.4083 nm (Villars & Cenzual, 2016). With the known wavelength the convergence semi-angle was determined to 22.1 mrad from a Ronchigram recorded in the same STEM setting as used in the actual experiment.
The rotation of the detector coordinate system with respect to the scan axes was determined by minimizing the curl of the first moment vector field and making sure that the divergence of the field is negative at atom positions. Note that, in theory, the curl of purely electrostatic fields should vanish. The pixel size in the scan dimension was taken from the STEM control software during live processing and verified by comparison with the known lattice constant of SrTiO3. The residual scan distortion, that is, the translation of the diffraction pattern as a whole during scanning, was not compensated for since it turned out to be negligible at the atomic-resolution STEM magnifications used in this analysis.
Data was acquired at a probe-corrected FEI Titan 80-300 STEM (Heggen et al., 2016) operated at kV. The microscope was equipped with a Medipix Merlin for EM detector operated at an acquisition rate for a single diffraction pattern of kHz in continuous mode. The scan size was scan points and the recorded diffraction patterns had a dimension of pixel. In addition, the high-angle annular dark field (HAADF) signal has been recorded with a Fischione Model 3000 detector covering an angular range of 121.7 mrad to approximately 200 mrad. The upper limit is defined by apertures of the microscope rather than by the outer radius of the detector. The run time for each step of the data processing flow was measured using the line-profiler Python package.
3 Results

3.1 Live processing
The performance of our approach is demonstrated in Fig. 2 which depicts (a) the structure of In2Se3 together with the projected potential and (b) snapshots of the reconstructed phase in nanosheets of this material using SSB ptychography at different stages of the scan. The reconstruction is performed progressively such that only the diffraction patterns of incoming scan pixels are processed and added to the final reconstruction according to eq. (3) in which all pixels are affected. Whereas current research in the field of materials science explores ultra-thin In2Se3 as a candidate for 2D ferroelectrics, this specimen was chosen due to its robustness against electron dose for the methodological development. The data in Fig. 2 b was taken from a live video recorded during the STEM session, being available as supplementary material online.

In general, the quality of the ptychographic reconstruction strongly depends on matching the position and radius of the (usually circular) aperture function on the detector with the double-overlap regions. Even small deviations lead to a mismatch between the mask borders and the edges of the zero-order disk, which adds noise and reconstruction errors from those erroneous border pixels. A precise alignment can be done, e.g. using a position-averaged diffraction pattern or by recording the bright-field disc with the specimen removed from the field of view, as in our analyses.
It must be pointed out that a partial SSB reconstruction only approximates the result because not all spatial frequencies have been completely sampled at this point. However, it is already possible to see the atom columns in the partial reconstructions. This allows time- and dose-efficient live focusing and navigation to regions of interest on specimens. In Fig. 3, complete reconstructions of In2Se3 are shown. All atom columns can be seen clearly in the bright field images, in the divergence of the first moment and in the phase of the object transmission function obtained by SSB ptychography. All signals were calculated live from the 4D-STEM data stream.

Figure 4 depicts the phase of ptychographic SSB reconstructions of SrTiO3 performed live while changing microscope parameters such as the STEM magnification (scan pixel size) in Fig. 4 a-c, and the probe focus in Fig. 4 d. The full video showing live updating during continuous scanning while microscope parameters are changed is available in the supplementary material online.
Although the inherent reconstruction parameters are naturally robust against a change of the probe focus for direct ptychography schemes that do not intend to correct aberrations, a magnification change influences the relation between a spatial frequency in the reconstruction in pixel coordinates, and the pixel distance in sample coordinates. This means that the geometry of a double overlap region that contains the signal to reconstruct a certain spatial frequency in the result changes with magnification. In the strict sense, changing the magnification without updating the scan step size (and double overlap masks) in the reconstruction is, therefore, mathematically inaccurate. In practice, however, it is desirable to be able to lower the magnification so as to navigate coarsely to a specimen region of interest without a new calibration or pre-calculation of the masks in eq. (3) to be time-efficient, and then observe or record details after switching back to the correct magnification again. Therefore, we studied to which extent the reconstruction is robust against a magnification change despite keeping the internal SSB parameters unchanged in Fig. 4 a-c. It showcases that the structural contrast is in general maintained. A possible future development with only a moderate effort could be pre-defining double overlap masks for common magnifications in order to build a look-up table that solves inaccuracies. We assume without loss of generality regarding the algorithmic structure, that live processing is required at a dedicated magnification being equal to the final recording where data is actually stored, and mention a certain robustness against changes of the scan pixel size as a valuable side note.
3.2 Computational details
In our implementation the sparse matrix product was the throughput-limiting step. By using an efficient GPU implementation from cupyx.scipy.sparse (CuPy), this could be accelerated sufficiently to allow processing of over 1000 frames per second at suitable parameters, enabling for live imaging using a Medipix3 sensor.
The memory consumption of the current SSB ptychography implementation scales as with the number of scan points at constant aspect ratio since the number of spatial frequencies to reconstruct scales linearly with the number of scan points, and each reconstructed frequency adds a double overlap region. These regions sample the diffraction data more densely when extracting more spatial frequencies, meaning the average number of non-zero entries per trotter is roughly constant for a given pixel size and beam parameters. As the processing time for dense-sparse matrix products roughly scales linearly with the number of non-zero entries in the sparse matrix and number of vectors in the dense matrix, SSB scales poorly with in computation time with the number of scan points.
The size of the matrix containing the double overlap regions is highly dependent upon the acquisition parameters in the present implementation. A larger camera length increases the Ronchigram size, consequently increasing non-zero entries. The relationship between scan pixel size and the convergence angle changes the spatial frequency limit above which no double overlaps occur. The less often spatial frequencies create double overlaps, the smaller the matrix becomes. In this study the scan area for live processing was limited to a size of and microscope parameters were chosen to keep the matrix size low enough to fit into the GPU RAM.
3.3 Post processing
We concentrated up to this point, solely on the live evaluation in order to facilitate optimisation of experimental parameters during the session. This avoided the need for saving vast amounts of 4D-STEM data that would have required significant disc space due to the continuous nature of the experiments. During the experiments only a few reliable data sets were recorded. To verify the reliability of our approach we compared the post-processing of the recorded data against the live experiment to determine if the inherent parameters used in post-processing such as the Ronchigram position and radius, are in sufficient agreement with those of the live results.

In Fig. 5, the post processing of In2Se3 data is shown. Here, the two different atom columns highlighted in Fig. 2 a can be seen in the first moment vector field (Fig. 5 a), in its divergence (Fig. 5 b), and in the HAADF image (Fig. 5 c). The phase of the SSB reconstruction (Fig. 5 d) also yields site-specific contrast, which is more pronounced than in the live imaging result in Fig. 3 d. Recalling that SSB ptychography relies on the weak phase object approximation in eq. (1) that breaks down already at the thinnest of specimen as to a quantitative interpretability, conclusions from relative phases among different atomic sites need to be drawn with great care.

In Figure 6, a comparison between different signals as well as between live imaging and post processing of SrTiO3 is shown. Strontium titanate enables evaluation of the different imaging modes regarding their capability for simultaneous imaging of light oxygen columns and comparably heavy Sr and Ti oxide columns, adding to the results obtained for In2Se3 in Fig. 5. The first moment vector field (Fig. 6 a) predominantly shows the heavy atom columns as sinks. The fact this vector field also contains sinks at the oxygen sites becomes visible in the divergence map in Fig. 6 b, whereas the HAADF signal recorded separately with the conventional annular detector in Fig. 6 c visualises only the heavy-atom sites of Sr and Ti oxide. In the post-processed SSB (Fig. 6d) the oxygen columns can be easily determined simultaneously with the heavy sites. The live SSB (Fig. 6g) has some noise, but the oxygen columns are still visible. Moreover, a comparison of the conventional HAADF in Fig. 6 c with the annular dark field signal generated by a virtual annular detector applied to the 4D-STEM data in Fig. 6 f demonstrates that practically all main contrast mechanisms exploiting low- as well as high-angle scattering can be captured by the 4D-STEM imaging mode.

Earlier we stated that the live ptychographic reconstruction exploits the SSB algorithm, because it is a non-iterative, linear and direct scheme that allows for in-situ processing. However, the weak phase object interaction model given by eq. (1) is a seemingly drastic limitation of this approach. In the analysis of post processing data, it is beneficial to explore whether a ptychographic scheme based more on an advanced interaction model, neglecting computational hardware constraints for the moment, could have been the better choice for live ptychography. To this end, we used the ePIE algorithm to reconstruct the SrTiO3 data as shown in Fig. 6 e. The standard ePIE implementation clearly does not give a reasonable result, at least for the usual reconstruction settings reported in literature that we used here. To explore this in more detail, the sample thickness was determined to approximately 25 nm by comparing the experimental PACBED with a thickness dependent simulation as in Fig. 7. Consequently, the specimen thickness was far beyond the validity of both the weak phase object approximation and the single-slice model used in ePIE. At first sight it is nevertheless surprising that the latter approach performs worse, since one must consider it more advanced than the weak phase model from the viewpoint of scattering theory. In fact, ePIE tries to iteratively find both the probe and the object transmission function in such a way that the modulus of the Fourier transform of their product agrees best with all details of the experimental diffraction data. When dynamical scattering sets in, this multiplicative interaction scheme is incapable of delivering the details of the diffraction pattern, so that the algorithm does not converge to a reliable solution. In this particular case ePIE has put some lattice information in the probe (Fig. 6 h). This will be studied in the next subsection by means of simulations.
To summarise the experimental results, performing live ptychography using the SSB method had originally been motivated by computational aspects, but contrary to expectations it also turns out to be more robust against the violation of the weak phase object approximation and dynamical scattering. Of course, this only holds for qualitative imaging, but it is a significant advantage in practice where suitable structural contrast is obtained also at elevated specimen thickness for both light and heavy atomic columns.
3.4 Simulation studies
Partial reconstruction.


As the implementation of live ptychography based on eq. (3) maps the result of single scan points successively to the final reconstruction, a simulation study has been conducted in which we investigated the accuracy of the reconstructed phase in already scanned regions in dependence of the scan progress. A synthetic dataset has been simulated, based on an SrTiO3 unit cell as a starting point. Then, a five by five super cell was created by repetition and the phase grating (Fig. 8) has been calculated. Two artificial spatial frequencies were added to the phase grating, one with a wavelength of a single unit cell and one with a wavelength of the super cell. To eliminate dynamical scattering in this conceptual study, a 4D-STEM simulation with scan points per unit cell was performed using only one slice with a thickness of one unit cell along electron beam direction . Finally, partial SSB reconstructions have been performed using the full range of scan pixels in vertical directions, but only portions of 20 scan pixels horizontally, mimicking a reconstruction during progressive scanning as depicted in Fig. 9. An animation calculated from 100 single pixel columns is available in the supplementary material.
Figure 9 contains the individual blocks of the 20 scan pixel wide reconstructions in the left hand column, and the accumulated result on the right hand side with the scan progressing from top to bottom. Consequently, the phase bottom right is the final reconstruction for the full scan, obtained by our cumulative approach which we found to be identical to a reconstruction using the conventional treatment employing the whole 4D scan. Only here, the low, medium and atomic-scale spatial frequencies are reconstructed correctly without artefacts. In that respect, it is instructive to explore the partial reconstructions in Fig. 9. Since we used subsets that equal the size of a single unit cell, spatial frequencies down to the synthetic one with a period of one unit cell appear at least qualitatively in all partial reconstructions. The sharp edges between the available data and the yet-missing region have resulted in a ringing effect near the edges known as the Gibbs-phenomenon. A closer look at the left column of Fig. 9 exhibits that these artefacts largely interfere destructively during accumulation as seen, e.g. by a maximum at horizontal scan pixel 20 in the top row and a minimum at this position in the row below. Consequently, ringing artefacts become less obvious in the full reconstruction on the right within the region that has already been scanned. Therefore, it is already possible to visualise the atomic structure and partly meso-scale phase variations for partial scans, making it possible to navigate on the sample and visually interpret results in a real experiment.
Real specimens and scan regions do not usually fulfill periodic boundary conditions which still apply to the full scan of Fig. 9. Therefore, Fig. 10 shows the impact of selecting different reconstruction areas by simulating the reconstruction of a smaller scan area that is not aligned with the underlying lattice. SSB reconstructs the specimen with an assumption of a periodic boundary condition and cannot reconstruct spatial frequencies above a certain threshold, as previously discussed. Trying to reconstruct a field of view where wrapping around the edges creates a discontinuity, i.e. frequencies higher than SSB can reconstruct, leads to reconstruction artefacts as seen in Fig. 9. Quantitatively, the difference between the ground truth taken from the marked rectangle of the full reconstruction in Fig. 10 a and a reconstruction that solely employs the scan pixels therein, as seen in Fig. 10 b is mapped in Fig. 10 c and can take significant values of 5-10 % of the phase itself in the present example.
As a solution, the field of view where an accurate reconstruction is required can be surrounded by a smooth transition to a zero-valued buffer area so that the presence of spatial frequencies above the resolution limit is minimized when the reconstruction area is wrapped around at the edges. In future studies a Lanczos filtering (Duchon, 1979) scheme could be added for our live ptychography approach.

Thickness effects. A comprehensive algorithmic review is not our focus but touching briefly on the findings in conjunction with Fig. 6 we elucidate the impact of dynamical scattering, or, equivalently, specimen thickness, on different signals. A multislice simulation (Rosenauer & Schowalter, 2007) has been performed for SrTiO3 in projection employing the experimental parameters and using scan pixels. The data was evaluated for thicknesses of 1 nm and 30 nm, addressing both the kinematic case and the situation of elevated thickness in our experiment. The results have been compiled in Fig. 11.
Figure 11 a shows the phase grating used in the multislice simulation for structural reference. In figure part (b) we added the theoretical result that would be obtained for SSB ptychography in case all methodological premises were fulfilled in practice. That is, we generated a 4D-STEM data set by means of the weak phase approximation in eq. (1) for a single slice with the thickness of one SrTiO3 unit cell and performed the SSB reconstruction. Note that this is identical to the phase in eq. (1), low-pass filtered with a circular aperture that has twice the radius of the probe-forming aperture.
Figures 11 c-j show the results of evaluating the 1 nm (left column) and the 30 nm data (right column) using different methods aligned row-wise. As can be expected from former studies employing first moment based imaging (Müller-Caspary et al., 2017; Müller et al., 2014) of centrosymmetric structures, Figs. 11 c-f resemble the atomic structure in terms of momentum transfer vector maps and their divergences with the atoms being sites of central fields. This is preserved in qualitative manner only for more elevated thicknesses. Note that Figs. 11 c and e are proportional to the probe-convoluted distributions of the projected electric field and charge density, respectively.
Similarly, the SSB reconstructions in Figs. 11 g and h yield reliable structural contrast at both low and elevated thickness despite the violation of the weak phase approximation in eq. (1), which confirms our interpretation in the post processing section. However, already the result in Fig. 11 g should be considered as qualitative except for the oxygen sites. Please note that the probe had been focused on the specimen surface in the simulation. Because the SSB reconstruction considers the 30 nm thick specimen as a single slice here, the optimum focus would have been at some depth inside the specimen which is one reason why atomic sites appear slightly broader (Fig. 11 h).
The situation is different for the ePIE results in Figs. 11 i,j. Whereas the reconstruction for the thin specimen in Fig. 11 i represents the phase excellently and can be considered quantitative within the general framework of validity of ePIE, the algorithm has severe difficulties in reconstructing the object transmission function at 30 nm thickness in Fig. 11 j. In Fig. 11 k the reconstructed probe looks like an airy disc. This is the result of an aberration free probe, limited only by an aperture in diffraction space, and that was used in the simulation. In Fig. 11 l sample information is transferred to the probe. This further confirms our observations concerning ePIE in the post processing section by simulation. However, Fig. 6 e,h gives even less information from the specimen than Fig. 11 j,l, which can be attributed to Poisson noise neglected in the simulation, residual aberrations, and importantly, different manners of separating probe and object which starts to fail when dynamical scattering sets in. To conclude, selecting the SSB scheme for live imaging of structural contrast can also be supported from the simulation point of view.

Low dose. The performance of the SSB reconstruction and the divergence of the first moment was checked in a low dose simulation (Fig. 12). At 1000 electrons per Å2 (Fig. 12a,b) the heavy atom columns are visible. At this dose, the SSB reconstruction gives stronger contrast than the divergence of the first moment. At 10000 electrons per Å2 (Fig. 12c,d) also the oxygen atom columns are visible. The SSB reconstruction and the divergence of the first moment shows similar performance at this dose.

4 Discussion
The digitisation that took place decades ago with key developments such as charge-coupled device (CCD) cameras and computer controlling, processing and visualisation in STEM denotes one of the drastic paradigm changes in electron microscopy. It enabled the live assessment of recorded data and transformed an optimisation of experimental parameters from multiple sessions to a quick feedback loop taking only several minutes within a single session. Surprisingly, innovative hardware associated with an increase of the dimensionality of the recorded data has, to some extent, put us back to ancient workflows for advanced methodologies. A major challenge for contemporary imaging in the era of Big Data is thus to make current ex-situ multidimensional evaluations capable for live imaging. Within this context, the present work shall be seen as a first step that demonstrates the feasibility of such a workflow using a rather straightforward example. Our work highlights the ongoing push towards high-performance computational methods in electron microscopy that are driven by an increasing camera performance (Weber et al., 2020). That includes suitable software frameworks, connections, storage, processing hardware, and know-how in computer science and engineering to be used in synergy with established and future imaging methodologies.
Several important general conclusions can be drawn from the present study. First, adequate computational hardware is already available for this purpose, given that the mathematical formulation can be adapted to make use of it efficiently. Second, and most importantly, open and well-defined software interfaces which were available for the hardware used here, are key prerequisites to implement nonstandard imaging concepts developed in science into established infrastructures. Third, it can be beneficial to exploit partly simplistic models to achieve live imaging capabilities, exemplified here by the use of the SSB algorithm for a materials science case. On the one hand, it violates inherent assumptions significantly, on the other hand, the qualitative nature of the results is better than one might expect from the weak phase approximation. In particular, the present setup can be considered to be highly beneficial for low-dose ptychographic live imaging of challenging specimen in the fields of structural biology and soft matter in Cryo electron microscopy. A suitable experimental setup with open software interfaces to tap the data stream of a 4D-Cryo-STEM experiment was unfortunately not available to the authors to enable the inclusion of respective examples in the present report. On the other hand, this would not change the methodological setup worked out in this paper using solid-state examples.
The current implementation mainly served to investigate the fundamental feasibility and characteristics of ptychography for live imaging. Integrating the parameter selection and results display in to existing instrument control software could be the next steps to improve the usability, making it more practical to apply routinely in microscopy. In that respect, live focusing, stigmation, and, prospectively, correction of further aberrations based on ptychography are possible. Furthermore, the implementation can be extended to include mitigation of artefacts from the edges that are demonstrated in Figure 10.
Existing LiberTEM UDFs that were previously only used for offline processing were applied to live data without modification, proving a long-standing design goal of LiberTEM (Clausen et al., 2020). In particular, the UDF interface allowed to disentangle details of the data logistics from the numerical and scientific aspects of the used algorithms. The prototype data decoder and UDF runner could easily keep up with the data rate of the Merlin detector. UDFs with low computational load such as virtual detectors or first moments remained at single-digit CPU load percentages. That means much higher data rates are likely to be possible with a suitable distributed UDF runner implementation. This will be required to support multi-chip cameras such as the Gatan K2 or K3 IS or X-Spectrum Lambda. Computationally intensive operations like ptychography are more challenging to scale to such data rates.
The poor scaling behaviour of the current SSB implementation has proven to be a limiting factor. For illustration, doubling the scan resolution at constant aspect ratio quadruples the number of scan points and results in 16x increased computation time. In future, an implementation that significantly reduces the computational load would be highly desirable to make this technique useful for mainstream data analysis. Ideally there would be a constant memory consumption independent of scan area and or scaling for computation effort as a function of the number of scan points.
5 Summary
Live imaging of central 4D-STEM signals such as the ptychographic phase, first moments, their divergence and rotation, as well as flexible virtual detectors has been demonstrated. A direct processing of the data stream of a Medipix3 chip mounted in an aberration-corrected STEM was implemented. An enhanced version is available open-source under https://github.com/LiberTEM/LiberTEM-live. A prototype was used to generate the live results and is available upon request. The live imaging capability could be demonstrated for two materials science cases In2Se3 and SrTiO3, where single-sideband ptychography proved surprisingly robust against imaging at elevated specimen thicknesses around 20 nm. It is anticipated that the live imaging approach presented here, and the transfer of such direct workflows to further imaging methods, can also enhance imaging in life sciences where, e.g., ptychography is a promising candidate for high-contrast, low-dose imaging of weakly scattering objects without compromising spatial resolution.
Acknowledgements Knut Müller-Caspary, Achim Strauch and Benjamin März were supported by funding from the Initiative and Network Fund of the Helmholtz Association (Germany) under contract VH-NG-1317 (moreSTEM project). Dieter Weber, Alexander Clausen, Arya Bangun, Benjamin März and Knut Müller-Caspary acknowledge support from Helmholtz within the project "Ptychography 4.0" under contract ZT-I-0025. Dieter Weber, Alexander Clausen and Rafal Dunin-Borkowski received funding from the European Union’s Horizon 2020 research and innovation programme under grant agreements No. 823717 – ESTEEM3 and No. 780487 - VIDEO.
6 Supplementary material
-
1.
Video of live view: https://www.youtube.com/watch?v=6s_ewwgOhoI
-
2.
Animation of gradual processing:
https://ptychography-4-0.github.io/ptychography/algorithms.html - 3.
-
4.
Sample notebooks: https://github.com/Ptychography-4-0/ptychography/tree/master/examples
- 5.
References
- Browning et al. (1995) Browning, N.D., Pennycook, S.J., Chisholm, M.F., McGIBBON, M.M. & McGIBBON, A.J. (1995). Observation of structural units at symmetric [001] tilt boundaries in SrTi03, Interface Science 2, 397–423.
- Clausen & Weber (2021) Clausen, A. & Weber, D. (2021). LiberTEM/LiberTEM-live: 0.1.0, URL https://github.com/LiberTEM/LiberTEM-live/.
- Clausen et al. (2021) Clausen, A., Weber, D., Ruzaeva, K., Migunov, V., Baburajan, A., Bahuleyan, A., Caron, J., Chandra, R., Dey, S., Halder, S., Katz, D.S., Levin, B.D., Nord, M., Ophus, C., Peter, S., Schyndel van, J., Shin, J., Sunku, S., Müller-Caspary, K. & Dunin-Borkowski, R.E. (2021). LiberTEM/LiberTEM: 0.7.1, URL https://github.com/LiberTEM/LiberTEM/.
- Clausen et al. (2020) Clausen, A., Weber, D., Ruzaeva, K., Migunov, V., Baburajan, A., Bahuleyan, A., Caron, J., Chandra, R., Halder, S., Nord, M., Müller-Caspary, K. & Dunin-Borkowski, R.E. (2020). LiberTEM: Software platform for scalable multidimensional data processing in transmission electron microscopy, Journal of Open Source Software 5, 2006, URL https://doi.org/10.21105/joss.02006.
- CuPy (2015) CuPy (2015). A numpy-compatible array library accelerated by cuda, URL https://cupy.dev/.
- Duchon (1979) Duchon, C.E. (1979). Lanczos filtering in one and two dimensions, Journal of Applied Meteorology 18, 1016–1022.
- Gao et al. (2017) Gao, S., Wang, P., Zhang, F., Martinez, G.T., Nellist, P.D., Pan, X. & Kirkland, A.I. (2017). Electron ptychographic microscopy for three-dimensional imaging, Nat Commun 8, 163, URL https://doi.org/10.1038/s41467-017-00150-1.
- Hegerl & Hoppe (1970) Hegerl, R. & Hoppe, W. (1970). Dynamische theorie der kristallstrukturanalyse durch elektronenbeugung im inhomogenen primärstrahlwellenfeld, Berichte der Bunsengedellschaft für physikalische Chemie 74, 1148–1154.
- Heggen et al. (2016) Heggen, M., Luysberg, M. & Tillmann, K. (2016). FEI titan 80-300 STEM, Journal of large-scale research facilities JLSRF 2, A42, URL http://jlsrf.org/index.php/lsf/article/view/67.
- Hoppe (1969) Hoppe, W. (1969). Beugung im inhomogenen Primärstrahlwellenfeld. I. Prinzip einer Phasenmessung von Elektronenbeungungsinterferenzen, Acta Crystallographica Section A 25, 495–501, URL https://doi.org/10.1107/S0567739469001045.
- Humphry et al. (2012) Humphry, M., Kraus, B., Hurst, A., Maiden, A. & Rodenburg, J. (2012). Ptychographic electron microscopy using high-angle dark-field scattering for sub-nanometre resolution imaging, Nature Communications 3, 730, URL http://www.nature.com/articles/ncomms1733.
- Jiang et al. (2018) Jiang, Y., Chen, Z., Han, Y., Deb, P., Gao, H., Xie, S., Purohit, P., Tate, M.W., Park, J., Gruner, S.M., Elser, V. & Muller, D.A. (2018). Electron ptychography of 2d materials to deep sub-ångström resolution, Nature 559, 343–349, URL http://www.nature.com/articles/s41586-018-0298-5.
- Maiden & Rodenburg (2009) Maiden, A.M. & Rodenburg, J.M. (2009). An improved ptychographical phase retrieval algorithm for diffractive imaging, Ultramicroscopy 109, 1256–1262, URL https://linkinghub.elsevier.com/retrieve/pii/S0304399109001284.
- Müller et al. (2014) Müller, K., Krause, F.F., Beche, A., Schowalter, M., Galioit, V., Löffler, S., Verbeeck, J., Zweck, J., Schattschneider, P. & Rosenauer, A. (2014). Atomic electric fields revealed by a quantum mechanical approach to electron picodiffraction, Nature Comm 5, 5653:1–8, URL http://dx.doi.org/10.1038/ncomms6653.
- Müller-Caspary et al. (2017) Müller-Caspary, K., Krause, F.F., Grieb, T., Löffler, S., Schowalter, M., Béché, A., Galioit, V., Marquardt, D., Zweck, J., Schattschneider, P., Verbeeck, J. & Rosenauer, A. (2017). Measurement of atomic electric fields and charge densities from average momentum transfers using scanning transmission electron microscopy, Ultramicroscopy 178, 62–80, URL http://www.sciencedirect.com/science/article/pii/S0304399116300596.
- Müller et al. (2012) Müller, K., Ryll, H., Ordavo, I., Ihle, S., Strüder, L., Volz, K., Zweck, J., Soltau, H. & Rosenauer, A. (2012). Scanning transmission electron microscopy strain measurement from millisecond frames of a direct electron charge coupled device, Applied Physics Letters 101, 212110, URL http://aip.scitation.org/doi/10.1063/1.4767655.
- Müller-Caspary et al. (2015) Müller-Caspary, K., Oelsner, A. & Potapov, P. (2015). Two-dimensional strain mapping in semiconductors by nano-beam electron diffraction employing a delay-line detector, Applied Physics Letters 107, 072110, URL http://aip.scitation.org/doi/10.1063/1.4927837.
- Nellist et al. (1995) Nellist, P.D., McCallum, B.C. & Rodenburg, J.M. (1995). Resolution beyond the ’information limit’ in transmission electron microscopy, Nature 374, 630–632, URL http://www.nature.com/articles/374630a0.
- Oelsner et al. (2001) Oelsner, A., Schmidt, O., Schicketanz, M., Klais, M., Schönhense, G., Mergel, V., Jagutzki, O. & Schmidt-Böcking, H. (2001). Microspectroscopy and imaging using a delay line detector in time-of-flight photoemission microscopy, Review of Scientific Instruments 72, 3968–3974, URL http://aip.scitation.org/doi/10.1063/1.1405781.
- O’Leary et al. (2020) O’Leary, C.M., Allen, C.S., Huang, C., Kim, J.S., Liberti, E., Nellist, P.D. & Kirkland, A.I. (2020). Phase reconstruction using fast binary 4D STEM data, Applied Physics Letters 116, 124101, URL https://doi.org/10.1063/1.5143213.
- Peet et al. (2019) Peet, M.J., Henderson, R. & Russo, C.J. (2019). The energy dependence of contrast and damage in electron cryomicroscopy of biological molecules, Ultramicroscopy 203, 125–131, URL https://linkinghub.elsevier.com/retrieve/pii/S0304399118304261.
- Pennycook et al. (2015) Pennycook, T.J., Lupini, A.R., Yang, H., Murfitt, M.F., Jones, L. & Nellist, P.D. (2015). Efficient phase contrast imaging in stem using a pixelated detector. part 1: Experimental demonstration at atomic resolution, Ultramicroscopy 151, 160 – 167, URL http://www.sciencedirect.com/science/article/pii/S0304399114001934, special Issue: 80th Birthday of Harald Rose; PICO 2015 – Third Conference on Frontiers of Aberration Corrected Electron Microscopy.
- Plackett et al. (2013) Plackett, R., Horswell, I., Gimenez, E.N., Marchal, J., Omar, D. & Tartoni, N. (2013). Merlin: a fast versatile readout system for medipix3, Journal of Instrumentation 8, C01038, URL https://iopscience.iop.org/article/10.1088/1748-0221/8/01/C01038.
- Quantum Detectors (2019) Quantum Detectors (2019). MerlinEM technical datasheet, URL https://quantumdetectors.com/wp-content/uploads/2019/11/2347-MerlinEM-Technical-datasheet.pdf.
- Rodenburg & Bates (1992) Rodenburg, J.M. & Bates, R.H.T. (1992). The Theory of Super-Resolution Electron Microscopy Via Wigner-Distribution Deconvolution, Philosophical Transactions Section A: Physical Sciences and Engineering 339, 521–553.
- Rodenburg et al. (1993) Rodenburg, J.M., McCallum, B.C. & Nellist, P.D. (1993). Experimental tests on double-resolution coherent imaging via STEM, Ultramicroscopy 48, 304–314.
- Rosenauer & Schowalter (2007) Rosenauer, A. & Schowalter, M. (2007). STEMSIM-a new software tool for simulation of STEM HAADF Z-contrast imaging, A.G. Cullis & P.A. Midgley (eds.), Springer Proceedings in Physics, vol. 120, 169–172, Springer, URL https://link.springer.com/chapter/10.1007%2F978-1-4020-8615-1_36.
- Ryll et al. (2016) Ryll, H., Simson, M., Hartmann, R., Holl, P., Huth, M., Ihle, S., Kondo, Y., Kotula, P., Liebel, A., Müller-Caspary, K., Rosenauer, A., Sagawa, R., Schmidt, J., Soltau, H. & Strüder, L. (2016). A pnCCD-based, fast direct single electron imaging camera for TEM and STEM, Journal of Instrumentation 11, P04006, URL https://iopscience.iop.org/article/10.1088/1748-0221/11/04/P04006.
- Seki et al. (2018) Seki, T., Ikuhara, Y. & Shibata, N. (2018). Theoretical framework of statistical noise in scanning transmission electron microscopy, Ultramicroscopy 193, 118–125, URL https://www.sciencedirect.com/science/article/pii/S0304399118300603.
- Strauch et al. (2021a) Strauch, A., Clausen, A., Weber, D. & Müller-Caspary, K. (2021a). High-resolution 4D STEM dataset of SrTiO3 along the [1 0 0] axis at high magnification, URL https://doi.org/10.5281/zenodo.5113449.
- Strauch et al. (2021b) Strauch, A., Weber, D., Clausen, A. & Müller-Caspary, K. (2021b). Synthetic 4D STEM dataset based on a SrTiO3 supercell with two additional artificial spatial frequencies, URL https://doi.org/10.5281/zenodo.5113235.
- Tate et al. (2016) Tate, M.W., Purohit, P., Chamberlain, D., Nguyen, K.X., Hovden, R., Chang, C.S., Deb, P., Turgut, E., Heron, J.T., Schlom, D.G., Ralph, D.C., Fuchs, G.D., Shanks, K.S., Philipp, H.T., Muller, D.A. & Gruner, S.M. (2016). High dynamic range pixel array detector for scanning transmission electron microscopy, Microscopy and Microanalysis 22, 237–249, URL https://www.cambridge.org/core/product/identifier/S1431927615015664/type/journal_article.
- Villars & Cenzual (2016) Villars, P. & Cenzual, K. (2016). gold (au, t = 300 k) crystal structure: Datasheet from “pauling file multinaries edition – 2012” in springermaterials, URL https://materials.springer.com/isp/crystallographic/docs/sd_1628821, copyright 2016 Springer-Verlag Berlin Heidelberg & Material Phases Data System (MPDS), Switzerland & National Institute for Materials Science (NIMS), Japan.
- Waddell & Chapman (1979) Waddell, E.M. & Chapman, J.N. (1979). Linear imaging of strong phase objects using asymmetrical detectors in STEM, Optik 54, 83–96, URL http://xrm.phys.northwestern.edu/research/pdf_papers/1979/waddell_optik_1979b.pdf.
- Weber et al. (2020) Weber, D., Clausen, A. & Dunin-Borkowski, R.E. (2020). Next-generation information technology systems for fast detectors in electron microscopy, Handbook on Big Data and Machine Learning in the Physical Sciences, 83–120, World Scientific, URL https://arxiv.org/abs/2003.11332.
- Weber et al. (2021) Weber, D., Lesnichaia, A., Strauch, A., Clausen, A., Bangun, A., Melnyk, O., Meissner, H., Ehrig, S., Wendt, R., Sukumaran, M., Wollgarten, M., zu Castell, W. & Müller-Caspary, K. (2021). Ptychography 4.0: 0.1.0, URL https://github.com/Ptychography-4-0/ptychography/.
- Ye et al. (1998) Ye, J., Soeda, S., Nakamura, Y. & Nittono, O. (1998). Crystal structures and phase transformation in In2Se3 compound semiconductor, Japanese Journal of Applied Physics 37, 4264–4271.
- Zhou et al. (2020) Zhou, L., Song, J., Kim, J.S., Pei, X., Huang, C., Boyce, M., Mendonça, L., Clare, D., Siebert, A., Allen, C.S., Liberti, E., Stuart, D., Pan, X., Nellist, P.D., Zhang, P., Kirkland, A.I. & Wang, P. (2020). Low-dose phase retrieval of biological specimens using cryo-electron ptychography, Nature Communications 11, 2773, URL https://doi.org/10.1038/s41467-020-16391-6.