computer programs\(\def\hfill{\hskip 5em}\def\hfil{\hskip 3em}\def\eqno#1{\hfil {#1}}\)

Journal logoJOURNAL OF
SYNCHROTRON
RADIATION
ISSN: 1600-5775

PyXAS – an open-source package for 2D X-ray near-edge spectroscopy analysis

CROSSMARK_Color_square_no_text.svg

aNational Synchrotron Light Source II (NSLS-II), Upton, NY 11973, USA
*Correspondence e-mail: wklee@bnl.gov

Edited by R. W. Strange, University of Essex, UK (Received 30 December 2019; accepted 27 January 2020; online 20 February 2020)

In the synchrotron X-ray community, X-ray absorption near-edge spectroscopy (XANES) is a widely used technique to probe the local coordination environment and the oxidation states of specific elements within a sample. Although this technique is usually applied to bulk samples, the advent of new synchrotron sources has enabled spatially resolved versions of this technique (2D XANES). This development has been extremely powerful for the study of heterogeneous systems, which is the case for nearly all real applications. However, associated with the development of 2D XANES comes the challenge of analyzing very large volumes of data. As an example, a single 2D XANES measurement at a synchrotron can easily produce ∼106 spatially resolved XANES spectra. Conventional manual analysis of an individual XANES spectrum is no longer feasible. Here, a software package is described that has been developed for high-throughput 2D XANES analysis. A detailed description of the software as well as example applications are provided.

1. Introduction

X-ray absorption near-edge spectroscopy (XANES) is a versatile approach that measures the local atomic structure of specific elements, which can provide valuable information about the oxidation states and local atomic coordination environment (Koningsberger & Prins, 1988[Koningsberger, D. C. & Prins, R. (1988). X-ray Absorption: Principles, Applications, Techniques of EXAFS, SEXAFS and XANES. New York: John Wiley and Sons.]; Rehr & Ankudinov, 2005[Rehr, J. J. & Ankudinov, A. L. (2005). Coord. Chem. Rev. 249, 131-140.]). A typical XANES measurement is conducted at a synchrotron light source by scanning the X-ray energy of the incident beam onto the sample across a specific element absorption edge. Depending on the setup, a variety of different signals can be used to construct the XANES spectrum, allowing the technique to be either surface sensitive (e.g. total electron yield, Auger electron yield) (Bianconi, 1980[Bianconi, A. (1980). Appl. Surf. Sci. 6, 392-418.]; Kitajima et al., 1989[Kitajima, Y., Yokoyama, T., Funabashi, M., Ohta, T. & Kuroda, H. (1989). Physica B, 158, 668-669.]; Isomura et al., 2015[Isomura, N., Soejima, N., Iwasaki, S., Nomoto, T., Murai, T. & Kimoto, Y. (2015). Appl. Surf. Sci. 355, 268-271.]; Frazer et al., 2003[Frazer, B. H., Gilbert, B., Sonderegger, B. R. & De Stasio, G. (2003). Surf. Sci. 537, 161-167.]) or bulk averaged (transmission mode, fluorescence yield) (Espinosa et al., 2012[Espinosa, A., Serrano, A., Llavona, A., Jimenez de la Morena, J., Abuin, M., Figuerola, A., Pellegrino, T., Fernández, J. F., Garcia-Hernandez, M., Castro, G. R. & Garcia, M. A. (2012). Meas. Sci. Technol. 23, 015602.]; Yang et al., 2005[Yang, L. C., McRae, R., Henary, M. M., Patel, R., Lai, B., Vogt, S. & Fahrni, C. J. (2005). P. Natl Acad. Sci. USA, 102, 11179-11184.]). Traditionally, a single XANES spectrum provides ensemble-averaged information of the sample, integrated over the area or volume that was exposed to the X-rays. Recently, by incorporating XANES into scanning X-ray microscopy and full-field transmission X-ray microscopy, spatially resolved XANES imaging (2D XANES) can be performed to analyze the sample heterogeneity by mapping out, for example, the valence states of the element of interest (Ade et al., 1992[Ade, H., Zhang, X., Cameron, S., Costello, C., Kirz, J. & Williams, S. (1992). Science, 258, 972-975.]; Fayard et al., 2013[Fayard, B., Pouyet, E., Berruyer, G., Bugnazet, D., Cornu, C., Cotte, M., Andrade, V. D., Chiaro, F. D., Hignette, O., Kieffer, J., Martin, T., Papillon, E., Salomé, M. & Sole, V. A. (2013). J. Phys. Conf. Ser. 425, 192001.]; Liu et al., 2011[Liu, Y., Andrews, J. C., Meirer, F., Mehta, A., Gil, S. C., Sciau, P., Mester, Z. & Pianetta, P. (2011). AIP Conf. Proc. 1365, 357-360.]). Specifically, 2D XANES analysis enables spatially resolved maps of the valence state or local coordination fractions of the element of interest. In addition, the large penetration depth of X-rays enables samples to be measured under in situ/in operando conditions, enabling dynamic system studies that track morphology and valence-state evolution (Wang et al., 2013[Wang, J. J., Chen-Wiegart, Y. K. & Wang, J. (2013). Chem. Commun. 49, 6480-6482.]). XANES has been used to gain a fundamental understanding of materials in many research fields such as condensed matter physics (Bianconi et al., 1987[Bianconi, A., Castellano, A. C., De Santis, M., Rudolf, P., Lagarde, P., Flank, A. M. & Marcelli, A. (1987). Solid State Commun. 63, 1009-1013.]; Lee et al., 2004[Lee, C. H., Matsuhata, H., Yamaguchi, H., Sekine, C., Kihou, K., Suzuki, T., Noro, T. & Shirotani, I. (2004). Phys. Rev. B, 70, 153105.]), energy storage (Lu et al., 2017[Lu, J., Wu, T. P. & Amine, K. (2017). Nat. Energy, 2, 17011.]; Wang et al., 2017[Wang, L. G., Wang, J. J., Zhang, X. Y., Ren, Y., Zuo, P. J., Yin, G. P. & Wang, J. (2017). Nano Energy, 34, 215-223.]; Yang et al., 2019[Yang, H. P., Wu, H. H., Ge, M. Y., Li, L. J., Yuan, Y. F., Yao, Q., Chen, J., Xia, L. F., Zheng, J. M., Chen, Z. Y., Duan, J., Kisslinger, K., Zeng, X. C., Lee, W. K., Zhang, Q. B. & Lu, J. (2019). Adv. Funct. Mater. 29, 1808825.]), catalysts (Andrews & Weckhuysen, 2013[Andrews, J. C. & Weckhuysen, B. M. (2013). Chem. Phys. Chem. 14, 3655-3666.]; Puga, 2018[Puga, A. V. (2018). Catal. Sci. Technol. 8, 5681-5707.]), etc.

Although the interpretation of XANES spectrum analysis has been well documented and there are several packages with comprehensive analysis capabilities (Ravel & Newville, 2005[Ravel, B. & Newville, M. (2005). J. Synchrotron Rad. 12, 537-541.]), batch processing a large number of spectra for spatially resolved XANES imaging remains a challenge (Liu et al., 2012[Liu, Y., Meirer, F., Williams, P. A., Wang, J., Andrews, J. C. & Pianetta, P. (2012). J. Synchrotron Rad. 19, 281-287.]). Generally, a 2D XANES measurement taken with a full-field synchrotron X-ray microscope consists of >106 spectra. A brute force approach directly looping over individual spectrums is not practical because of the processing time. The problem is further exacerbated for time-resolved (in operando) studies (Wang et al., 2014[Wang, J. J., Chen-Wiegart, Y. K. & Wang, J. (2014). Nat. Commun. 5, 4570.]) or 3D XANES tomography (Meirer et al., 2011[Meirer, F., Cabana, J., Liu, Y., Mehta, A., Andrews, J. C. & Pianetta, P. (2011). J. Synchrotron Rad. 18, 773-781.]; Nelson et al., 2011[Nelson, G. J., Harris, W. M., Izzo, J. R., Grew, K. N., Chiu, W. K. S., Chu, Y. S., Yi, J., Andrews, J. C., Liu, Y. J. & Pianetta, P. (2011). Appl. Phys. Lett. 98, 173109.]). For example, at the FXI beamline at National Synchrotron Light Source II (NSLS-II), a typical 2D XANES measurement with 100 energy points will take less than 10 minutes (Coburn et al., 2019[Coburn, D. S., Nazaretski, E., Xu, W., Ge, M. Y., Longo, C., Xu, H., Gofron, K., Yin, Z., Chen, H. H., Hwu, Y. & Lee, W. K. (2019). Rev. Sci. Instrum. 90, 053701.]; Ge et al., 2018[Ge, M. Y., Coburn, D. S., Nazaretski, E., Xu, W. H., Gofron, K., Xu, H. J., Yin, Z. J. & Lee, W. K. (2018). Appl. Phys. Lett. 113, 083109.]). Coupled with the desire to perform in operando 2D or 3D XANES, it is not unusual for a user to generate ∼109 spectra over 24 h. In order to analyze the data efficiently, it is necessary to streamline the image-analysis procedure so that one can retrieve the material information in a timely fashion.

Here, we describe a Python software package optimized for 2D XANES analysis with a graphic user interface (GUI) and demonstrate its functionalities through a few examples. Although this package can also be used for XANES analysis using fluorescence data, we will focus on data from a full-field transmission X-ray microscope. This package is deployed at the FXI beamline and is used for all analysis of XANES data collected at the beamline (Yang et al., 2019[Yang, H. P., Wu, H. H., Ge, M. Y., Li, L. J., Yuan, Y. F., Yao, Q., Chen, J., Xia, L. F., Zheng, J. M., Chen, Z. Y., Duan, J., Kisslinger, K., Zeng, X. C., Lee, W. K., Zhang, Q. B. & Lu, J. (2019). Adv. Funct. Mater. 29, 1808825.]; Zhang et al., 2019[Zhang, M. J., Hu, X. B., Li, M. F., Duan, Y. D., Yang, L. Y., Yin, C., Ge, M. Y., Xiao, X. H., Lee, W. K., Ko, J. Y. P., Amine, K., Chen, Z. H., Zhu, Y. M., Dooryhee, E., Bai, J. M., Pan, F. & Wang, F. (2019). Adv. Energ. Mater. 9, 1901915.]).

2. Package structure for 2D XANES analysis

The general approach for XANES analysis is to fit the measured spectrum to a linear combination of reference spectra. The major functional components of the package are: (i) data loading, (ii) preprocessing, (iii) edge normalization, (iv) XANES fitting, (v) post-analysis and (vi) miscellaneous. The components are modular and their specific functions can be easily updated or replaced; for example, to input different file structures or to incorporate alternate optimization algorithms. Fig. 1[link](a) illustrates the layout of the analysis pipeline and Fig. 2[link] shows the GUI of the related modules. The GUI is written using PyQT. In the following, we will describe each section in detail.

[Figure 1]
Figure 1
Overview of 2D XANES fitting. (a) Workflow of the XANES analysis package. (b) An example of raw TXM images data taken at different X-ray energies. (c) Pre- and post-edge normalization. (d) Edge-normalized image data. (e) Fitted results showing the 2D distribution of two components. Regions without particles have been masked out. The color bars on the right show the fractions.
[Figure 2]
Figure 2
Screenshot of the PyXAS GUI. (a) Main screen. Data loading and preprocessing are indicated by the areas enclosed by red and blue lines. (b) Edge normalization, (c) XANES fitting, and (d) and (e) post-analysis.

3. Data loading

For 2D XANES analysis, we need a 2D XANES image stack and an energy list associated with the images. The current PyXAS package supports two input file formats: a simple TIFF image stack or a HDF5 (.h5) file. For the .h5 format, the attribute name of the data entry for the image stack is required. The associated energy list can be imported either from an ascii file (.txt) or from a .h5 file with the data-entry attribute specified. A manual command-line input of the energy list is also supported.

4. Preprocessing

The first step for most X-ray image analysis is to perform what is normally called `flat-field correction' where the `dark' field is subtracted and the inhomogeneity of the incident beam (`white' or `background' field) is removed by normalization. The program loads all these files and computes the flat-field corrected images. Once this is done, it is necessary to align the flat-field corrected images to correct for possible sample/image drifts that occur during data acquisition. Such drifts can come from imperfect beamline optics' alignment and/or sample motions during the energy scans. For transmission X-ray microscopy (TXM) images, for example, this step corrects for small image shifts caused by the required motions of the optics during changes in the incident X-ray energy. The package has implemented two image-registration algorithms [`StackReg' (Thevenaz et al., 1998[Thevenaz, P., Ruttimann, U. E. & Unser, M. (1998). IEEE Trans. Image Process. 7, 27-41.]) and `Cross-correlation'] to align the XANES image stack without any prior knowledge about the physical motor positions used in the experiment. Specifically, `StackReg' is capable of correcting a variety of image motions/distortions such as translation, rotation and scaling. `Cross-correlation' can only correct for image translations in the current version. In general, `StackReg' performs better than `Cross-correlation' if the image object has an abundance of feature details. In the package, one can specify any image from the image stack as a reference image [either using the full frame or a region of interest (ROI)] and align the rest of the images with respect to it. After the image stack has been aligned, the user can choose whether to take the negative natural log of the pixel value of the image. The negative log is required for transmission X-ray images (e.g. TXM-XANES) but not required for fluorescent XANES images. Explicitly, for TXM images,

[I_{\rm TXM}^E = \int\limits_z {\mu _i^E(z)\,{\rm d}z} = - \ln \biggl({{{I^E} - {I_{\rm dark}}} \over {I_{\rm bkg}^E - {I_{\rm dark}}}}\biggr), \eqno(1)]

where IE is the measured 2D intensity image of the sample with incident X-ray at energy E, Idark is the measured 2D dark image without X-ray illumination, IbkgE is the measured 2D background image without the sample at X-ray energy E and ITXME is the normalized (i.e. flat-field corrected) TXM intensity image. [\mu _i^E] is the linear attenuation coefficient of different components i inside the sample at X-ray energy E and z is the thickness of the sample.

5. Edge normalization

For analysis, a single XANES spectrum from a material mixture is considered as a linear superposition of the spectrum from individual components inside the sample (e.g. a metal oxide with different oxidation states). Given the spectrum for each component (denoted as reference spectrum), one of the main tasks in XANES analysis is to calculate the percentage (ratio) of each component. Because the reference spectra are usually normalized to zero and one in the pre-edge and post-edge regions, respectively, similar normalization is required for the measured data to enable subsequent analysis. Furthermore, the pixel values in the flat-field corrected images as indicated in equation (1)[link] reflect the integrated absorption coefficients over the sample thickness, which includes contributions from all material components. For optimal fitting to the reference spectrum of the element of interest, it is necessary to be able to remove the absorption contributions from the other elements. The edge-normalization procedure addresses both these aspects: removes the contribution from the other elements and normalizes the spectrum so that it can be fitted against references.

The edge normalization starts with linear fits to the pre-edge and post-edge regions [see Fig. 1[link](c)]. For this to work, it is assumed that both the attenuation contributions to pre-edge and post-edge regions are linear in energy. This is a reasonable assumption because the energy ranges involved here are in the tens to hundreds of eV range and assumed to be away from any other absorption edges. Pre-edge normalization is a method to remove the contribution from other elements and focus on the element of interest only. The difference between the post-edge and pre-edge fitted lines is then attributed to the `thickness' of the element in question. Since the slopes of these two lines are generally not identical, a single thickness value is calculated by averaging over a range of energy points in the post-edge region (see Section 7.1[link]).

The following equation describes the edge-normalization process,

[I_{\rm edge-norm}^E = {{I_{\rm TXM}^E - I_{\rm TXM}^{{E_{\rm pre-edge}}}} \over {I_{\rm TXM}^{{E_{\rm post-edge}}} - I_{\rm TXM}^{{E_{\rm pre-edge}}}}}, \eqno(2)]

where ITXMEpre-edge and ITXMEpost-edge are the calculated intensity image through a linear fit of ITXME at the pre-edge and post-edge energy ranges and extrapolated to all energies, respectively. Thus, after the edge-normalization process, the value of each pixel in the generated image [Iedge-normE, Fig. 1[link](d)] represents a normalized linear attenuation coefficient for the element in question, which can now be fitted to reference spectra.

6. XANES fitting

After edge normalization, the edge-normalized XANES can be written as

[{[\,{y_1},{y_2},\ldots {y_m}]^T} = {A^{m{{\times}}k}} \cdot [{x_1},{x_2},\ldots {x_k}], \eqno(3)]

in which yi is the edge-normalized spectrum (Iedge-normE) at a single pixel i, xj is the jth reference spectrum with n energy points, m is the number of pixels and k is the number of reference spectrum. Am×k is the coefficient matrix.

Explicitly, yi and xj can be written as

[{y}_{i} = \left[I_{\rm edge-norm}^{E_1}[i], I_{\rm edge-norm}^{E_2}[i], \ldots, I_{\rm edge-norm}^{E_n}[i] \right]^T]

and

[{x_j} = \left[ r_j^{E_1}, r_j^{E_2},\ldots, r_j^{E_n} \right]^T,]

where rjEn is the intensity of the jth reference spectrum at energy En. The coefficient matrix A can be solved using direct linear least-square fitting or the alternating direction method of multipliers (ADMM) – an iterative linear algebra solving engine (Boyd et al., 2011[Boyd, S., Parikh, N., Chu, E., Peleato, B. & Eckstein, J. (2011). Mach. Learn. 3, 1-122.]). The choice of the fitting method heavily depends on the data quality. Direct fitting is preferred when the XANES image is of high fidelity with good signal-to-noise ratio. ADMM is more robust for dealing with noisy images. In the package, both methods are optimized (vectorized) for processing large XANES images. Running on a single CPU (e.g. a desktop PC with an Intel i7-6800K processor) it takes only a few seconds to fit 100 energy points of 2k × 2k XANES images. The user can define the range of energies over which to fit the spectrum. The resulting values of the coefficient matrix A give the fraction of each reference material for the pixel.

As an illustration, Figs. 1[link](b)–1[link](e) summarize the XANES fitting procedure. Fig. 1[link](b) is the original XANES image taken from the transmission X-ray microscope. Fig. 1[link](c) demonstrates the edge normalization after the image was preprocessed (alignment and negative natural log taken), resulting in the normalized image as shown in Fig. 1[link](d). Fig. 1[link](e) shows the fitting results. In this case, two individual components are distinguished. And their fractions are encoded with the same color scheme. Note that only the region with particles is presented, and the empty region where the fitting gives poor results has been masked out (see Section 8.2[link]).

7. Post-analysis

7.1. `Thickness' image

The software generates two additional image files for visualization: `image thickness' and `fitting error'. The `image thickness' is derived from absorption-edge normalization (see Section 5[link]). For each pixel, once the pre-edge is normalized, the numerical value of the pixel (μE) in the post-edge energy range is largely related to the `thickness' of the specific element that the X-ray associated with the pixel has traversed. This is defined as the average `image thickness', which is approximately proportional to the amount of the specific element locally, and it can be written as

[{I_{\rm thickness}}\, \propto\, {\bar{\mu }}_i^E z = {1 \over n} \sum\limits_{\rm post-edge{\,\rm{ energies}}}\!\! {\left(I_{\rm TXM}^{{E_{\rm post-edge}}} - I_{\rm TXM}^{{E_{\rm pre-edge}}}\right)},]

where n is the number of energy points in the post-edge region used for the average and [{\bar{\mu}} _i^E] is the averaged attenuation coefficient in the range of post-edge energy for element i.

7.2. Fitting evaluation

Once the XANES fitting is done, it is important to evaluate the goodness of fit. One figure of merit is the fitting error at each pixel: [{\rm err} = \textstyle\sum_i {{{| {{y_i} - {{\hat y}_i}}|}^2}}], where i denotes the different energy points, yi is the pixel value at energy i and [{\hat y_i}] is the fit value. As an example, Fig. 3[link](a) shows an LiNixCoyAlzO2 particle in an Li ion battery cathode material that has been partially charged. XANES imaging of Ni is obtained by recording the X-ray transmission images at different energies from 8.23 to 8.60 keV with a total of 72 energy points. Two Ni reference spectra are used to fit the results. Specifically, the reference spectrum `ref1' is the Ni oxidation state derived from the same material at its pristine state (mostly Ni3+) and `ref2' is derived from the material at its fully charged state (mostly Ni4+). Figs. 3[link](b) and 3[link](c) are the fitting results showing the spatial distribution of N3+ and Ni4+, respectively. As expected, outside the particle, the fitting distribution is very noisy, with large fitting errors [Fig. 3[link](d)] because this region does not contain characteristic features of reference spectrums. The package provides a tool to explicitly check the fitting results at a specified ROI. As illustrated in Fig. 3[link](e), a good match between the fitting curve and the raw data in ROI #1 validates the high fitting accuracy, which is in sharp contrast to the poor fitting in ROI #2 as shown in Fig. 3[link](f). This is useful for masking out regions that are not relevant for subsequent analysis (see Section 8[link]).

[Figure 3]
Figure 3
2D XANES fitting evaluation. (a) Flat-field corrected TXM image of a partially charged LiNixCoyAlzO2 particle taken at 8.36 keV. (b) 2D distribution of Ni3+ after fitting. (c) 2D distribution of Ni4+ after fitting. (d) Fitting error on a log scale. (e) Comparison of fitting curve and raw data extracted from ROI #1 shown in (a). (f) Comparison of fitting curve and raw data extracted from ROI #2 shown in (a).

8. Miscellaneous

8.1. Peak finding

The package provides functions to find the peak positions in XANES spectra. For screening purposes, for example, peak positions can be used as rough indicators to show the composition differences (e.g. oxidation state) at different locations without performing a complete XANES fitting analysis. In the package, we can take either the raw images (ITXME) or the edge-normalized images (Iedge-normE) as the input. Given the range of energy we would like to fit, the package uses a third-order spline curve to fit individual spectrum at each pixel and display the peak-position map in a color scale.

8.2. Segmentation (mask)

From the above fitting routines (Section 6[link]), oxidation-state fractions can be obtained for every individual image pixel. However, the resulting fraction map can have regions that are very noisy, for example, from regions where the relevant element is not present and/or within very small particles that have very large fitting errors (see Fig. 2[link]). It is desirable to mask out (or segment) these regions so that subsequent analysis can be performed only on regions with good fits. Another goal in XANES imaging is to be able to identify different material compositions, for example, regions where there may be small differences in stoichiometry or regions where the oxidation state of an element may be distinctly different.

In the package, we provide two simple yet versatile segmentation methods for this purpose: threshold masking and clustering masking. In the threshold-masking method, we can use any image (raw or processed) inside the package to generate a mask by choosing a proper pixel value as a threshold. For example, we can choose a threshold according to the error map [Fig. 3[link](d)] to mask out the parts where the fitting error is greater than a certain value. We can also use the `image thickness' to effectively generate a mask. It is easy to set a threshold to remove the regions with less material. The threshold masks generated from different images can be sequentially propagated and applied to all images available in the package. For example, Fig. 4[link](a) show the `thickness' image. The arrows in Fig. 4[link](a) show the regions we would like to mask out. Fig. 4[link](b) shows the mask image that removes the pixels with values <0.2 in the `thickness' image. Fig. 4[link](c) shows a second mask that removes pixels with values >1 in the `Error' image [Fig. 3[link](d)], which gives the result shown in Fig. 4[link](d).

[Figure 4]
Figure 4
Example of threshold mask. (a) Thickness image of the LiNixCoyAlzO2 particle. The arrows indicate the regions to be masked out. Specifically, arrow 1 and arrow 2 indicate the two small particles, and arrow 3 indicates the error part (a long stripe of yellow color) that comes from image alignment. (b) Mask generated from thickness image with a threshold set to 0.2. (c) Mask generated from `error' image [Fig. 2[link](d)] with a threshold set to 1. (d) Thickness image after applying the masks in (b) and (c).

The second segmentation/masking tool included in the software is based on cluster analysis (O'Sullivan, 1995[O'Sullivan, F. (1995). Ann. Statist. 23, 1267-1300.]; Pedregosa et al., 2011[Pedregosa, F., Varoquaux, G., Gramfort, A., Michel, V., Thirion, B., Grisel, O., Blondel, M., Prettenhofer, P., Weiss, R., Dubourg, V., Vanderplas, J., Passos, A., Cournapeau, D., Brucher, M., Perrot, M. & Duchesnay, E. (2011). J. Mach. Learn. Res. 12, 2825-2830.]). There are several different algorithms for cluster analysis, among them are: connectivity based, centroid based (k means), distribution based and density based. Two early uses of cluster analysis for X-ray applications have been for X-ray diffraction (Liao & Chen, 1992[Liao, B. & Chen, J. (1992). J. Appl. Cryst. 25, 336-339.]) and soft X-ray spectromicroscopy (Lerotic et al., 2005[Lerotic, M., Jacobsen, C., Gillow, J. B., Francis, A. J., Wirick, S., Vogt, S. & Maser, J. (2005). J. Electron Spectrosc. Relat. Phenom. 144-147, 1137-1143.]). More recently, for hard X-ray TXM, density-based cluster analysis has been used to identify chemically different compounds (Duan et al., 2016[Duan, X., Yang, F., Antono, E., Yang, W., Pianetta, P., Ermon, S., Mehta, A. & Liu, Y. (2016). Sci. Rep. 6, 34406.]), and k-means-based cluster analysis has been used to look for minority phases (Zhang et al., 2017[Zhang, K., Ren, F., Wang, X., Hu, E., Xu, Y., Yang, X. Q., Li, H., Chen, L., Pianetta, P., Mehta, A., Yu, X. & Liu, Y. (2017). Nano Lett. 17, 7782-7788.]) and outliers (Mao et al., 2019[Mao, Y., Wang, X., Xia, S., Zhang, K., Wei, C., Bak, S., Shadike, Z., Liu, X., Yang, Y., Xu, R., Pianetta, P., Ermon, S., Stavitski, E., Zhao, K., Xu, Z., Lin, F., Yang, X. Q., Hu, E. & Liu, Y. (2019). Adv. Funct. Mater. 29, 1900247.]). Currently, in our package, the cluster analysis is based on the k-means algorithm (Pedregosa et al., 2011[Pedregosa, F., Varoquaux, G., Gramfort, A., Michel, V., Thirion, B., Grisel, O., Blondel, M., Prettenhofer, P., Weiss, R., Dubourg, V., Vanderplas, J., Passos, A., Cournapeau, D., Brucher, M., Perrot, M. & Duchesnay, E. (2011). J. Mach. Learn. Res. 12, 2825-2830.]). The references above and our examples below clearly demonstrate the great potential of cluster analysis for XANES imaging.

An application example of this algorithm (Fig. 5[link]) is applied to a sintered mixture of Li7La3Zr2O12 (LLZO) and LiNi0.8Mn0.1Co0.1O2 (NMC), which holds the promise for the next generation of all-solid lithium ion battery. In the XANES images, across the Ni-K edge, NMC undergoes significant contrast change, while LLZO only shows a gradual contrast change owing to mass attenuation. Here, 101 3D tomographic datasets were taken from 8.212 keV (below the Ni-K edge) to 8.777 keV (above the Ni-K edge). All the data were reconstructed and one cross-sectional slice of the reconstructed data at 8.32 keV is shown in Fig. 5[link](a), and the same slice at 8.35 keV is shown in Fig. 5[link](b). The dramatic changes in the absorption coefficient in the dashed regions in Fig. 5[link](a) compared with similar regions in Fig. 5[link](b) clearly indicates Ni-rich regions (NMC particles). However, the changes in other regions are more subtle, and whether there is a separate material component is not obvious. Cluster analysis can be a useful tool to identify such subtle differences. To demonstrate this, the entire 2D XANES reconstructed image-slice stack (i.e the same slice for all the 101 energies) was provided as input to the clustering algorithm. The algorithm requires the user to input the number of clusters desired; in this case, four (three material phases plus empty regions). Fig. 5[link](c) shows the results from the clustering analysis of the 540 × 640 × 100 individual pixel spectrum. It shows that there are indeed three different material components, not two. To investigate the validity of the cluster analysis as shown in Fig. 5[link](c), averaged spectra can be calculated from each of the three different identified material components. Fig. 5[link](d) clearly shows that the three different groups have very different spectra. Note that because in this example the input to the cluster analysis is from 3D reconstructed data, material thickness has already been accounted for. The difference in spectrum between the low-Ni component and NMC is not because of thickness. We hypothesize that the low-Ni component is an inter-diffusion region of Ni (NMC) and LLZO. The spatial distribution of these different components revealed by the analysis will help to understand the sintering process at high temperature and provide guidance for researchers in the synthesis of the materials with desired properties and functionalities. Note that in the above example the cluster analysis was able to differentiate the three component materials without performing edge normalization (Section 5[link]) or fitting (Section 6[link]) on the data.

[Figure 5]
Figure 5
Example of clustering mask. (a) Image of the LLZO-NMC at 8.32 keV. (b) Image of the LLZO-NMC at 8.34 keV. (c) Separation of the LLZO-NMC material into three different material groups based on the characteristic features of XANES spectrum at individual pixels using the clustering-mask algorithm. (d) Spectra derived from the area of the three material groups with the same color scheme as shown in (c).

The above example demonstrates a way to differentiate materials using the clustering-analysis package. Clustering analysis can also help to distinguish different oxidation states in a material without having to do XANES fitting. This is especially useful in cases where reference spectra are not available. We demonstrate this application on a LiNix­CoyAlzO2 sample (same material as in Figs. 3[link] and 4[link]). As mentioned before, a full 2D XANES image stack (72 energy points, Ni-K edge) was collected and edge normalized as described in equation (2)[link]. The edge-normalized 2D image stack was provided as an input to the cluster algorithm and, as before, the desired number of phases was assigned to be four. Fig. 6[link](a) shows the output from the cluster analysis where the three identified components have been grouped based on the difference of XANES spectrum at individual pixel level. Fig. 6[link](b) compares the spectrum (8.345–8.360 keV) that is averaged from each of the three identified components. Although subtle, the differences in the spectrum for each component can be seen. We note that the cluster analysis did not require reference spectra.

[Figure 6]
Figure 6
Comparison of clustering masks generated from different input datasets. (a) Clustering-mask generated map with an edge-normalized XANES image of the LiNixCoyAlzO2 particle as the input. The averaged spectrum from R1, R2 and R3 are found to have Ni4+ concentrations of 0.542, 0.573 and 0.641, respectively, after we do the regular XANES fitting. (b) XANES spectra derived from the area of the three groups with the same color scheme as shown in (a). (c) Colormix of the fitting: red and green represent the distribution of Ni3+ and Ni4+, respectively. (d) Clustering-mask generated map with the fitted Ni4+ fraction as the input (linear least-square fitting with reference spectra given). The averaged spectrum from R1, R2 and R3 are found to have Ni4+ concentrations of 0.472, 0.577 and 0.683, respectively. (e) Clustering-mask generated map from XANES image without edge normalization as the input. See main text for explanation. (f) XANES spectra derived from the area of the three groups with the same color scheme as shown in (e).

As a way to investigate the validity of this cluster analysis, we performed a complete XANES fitting analysis on the data using the procedure described in Section 7[link]. As a comparison, Fig. 6[link](c) shows the actual fitting results of Ni3+ (red) and Ni4+ (green) distribution. Taking the Ni4+ distribution image as the input and applying the clustering method with four components assigned, Fig. 6[link](d) shows the three-component separation derived from the fitting results using the same color scheme as used in Fig. 6[link](a). It is worth noting that applying the cluster mask or fundamentally the k-mean cluster algorithm to a single image is equivalent to grouping the pixels according to the pixel value, which in this case is the amount (fraction) of Ni4+. The similarities between Figs. 6[link](a) and 6[link](d) demonstrate the ability of the cluster analysis to differentiate oxidation states for unknown material systems when reference spectra are not available. However, the difference between Figs. 6[link](a) and 6[link](d) indicates that regular XANES fitting prior to cluster analysis yields more accurate quantitative results. The clustering mask backed by the k-mean clustering algorithm is more sensitive to the noise, especially when the image signal is weak.

As a final remark about the cluster-analysis algorithm, the proper input into the algorithm is important. For example, in the case of Fig. 6[link], it is noted that correct edge normalization is necessary to achieve reasonable results. To show this, Figs. 6[link](e) and 6[link](f) are the output from the cluster analysis when the input images are not edge normalized as described in equation (2)[link]. Without proper edge normalization, the values in the input image matrix to the algorithm are highly correlated to the amount of material each ray traverses before it hits the pixel and, thus, the `largest change' in the cluster parameter space is caused by thickness effect instead of features of the spectrum such as peak shape and position. That is why the resulting Fig. 6[link](e) looks like a `thickness' map. In other words, without proper edge normalization, the sample thickness information dominates the signal and the cluster-analysis output reflects the depth integrated elemental concentration (or `thickness'). The need to perform proper edge normalization here compared with the example in Fig. 5[link] is because of the fact that in Fig. 5[link] thickness has already been accounted for because the input images come from reconstructed 3D volumes.

9. 3D application

3D XANES analysis can be realized through a batch fitting of a 2D XANES image stack by calling the functions in the PyXAS package in a Python environment. In a typical 3D XANES experiment, 3D tomography at different energies of incident X-rays are collected, reconstructed and aligned. As an example, the material system we are demonstrating in Fig. 7[link] is LiNi5Mn3Co2O2 particles after being charged/discharged for 72 cycles. In the experiment, we acquired 56 3D tomography datasets across the Ni absorption edge and then performed image registration of the 2D projection collected at the same angle at different energies. Once the projections are aligned, the reconstructed 3D objects are fully aligned automatically. The next step was re-assembling the slice of the 3D object at the same height to form a 2D XANES image stack, which can be batched fitted using the functions provided in the PyXAS package. The results are shown in Fig. 7[link]. Specifically, Fig. 7[link](a) represents the 3D distribution of Ni3+ concentration. Fig. 7[link](b) is a cross-section view of the results, where red represents Ni2+ and green represents Ni3+. It is clear to see the enrichment of Ni2+ (red) around the crack area, which has arisen from the particle degradation after battery cycling.

[Figure 7]
Figure 7
3D XANES of Ni for material LiNi5Mn3Co2O2 after being charged/discharged for 72 cycles. (a) 3D volume rendering of Ni3+ concentration. (b) One slice of a cross-section view of Ni2+ (red) and Ni3+ (green) distribution.

10. Summary and future development

We introduced an efficient 2D XANES analysis package that is currently deployed at the NSLS-II FXI beamline. Generally, a regular XANES image (2k × 2k) with tens to hundreds of energy points collected at a synchrotron imaging beamline can be analyzed within a few minutes using a mid-level PC. The package is organized as a collection of modularized functions that can be easily modified or updated. A GUI has been implemented for 2D XANES analysis. The package is freely distributed with instructional documentation available on github: https://github.com/gmysage/pyxas. Currently, all the functions in the package can be called in the Python environment externally by importing the PyXAS package. This is especially useful for batch processing of 2D XANES image slices in order to build up a full 3D XANES model. In the future, we will incorporate the batch-process capability and other functions related to 3D XANES analysis into the GUI interface.

Acknowledgements

We thank Dr Seong Min Bak (chemistry department at BNL) and Dr Feng Wang (BNL) for providing the test samples. We also thank Dr Hanfei Yan for the discussion about ADMM implementation.

Funding information

This research used resources at the FXI beamline (18-ID) of NSLS-II, a US Department of Energy (DOE) Office of Science User Facility operated for the DOE Office of Science by Brookhaven National Laboratory (BNL) under Contract No. DE-SC0012704.

References

First citationAde, H., Zhang, X., Cameron, S., Costello, C., Kirz, J. & Williams, S. (1992). Science, 258, 972–975.  CrossRef PubMed CAS Web of Science Google Scholar
First citationAndrews, J. C. & Weckhuysen, B. M. (2013). Chem. Phys. Chem. 14, 3655–3666.  Web of Science CrossRef CAS PubMed Google Scholar
First citationBianconi, A. (1980). Appl. Surf. Sci. 6, 392–418.  CrossRef CAS Web of Science Google Scholar
First citationBianconi, A., Castellano, A. C., De Santis, M., Rudolf, P., Lagarde, P., Flank, A. M. & Marcelli, A. (1987). Solid State Commun. 63, 1009–1013.  CrossRef CAS Web of Science Google Scholar
First citationBoyd, S., Parikh, N., Chu, E., Peleato, B. & Eckstein, J. (2011). Mach. Learn. 3, 1–122.  Google Scholar
First citationCoburn, D. S., Nazaretski, E., Xu, W., Ge, M. Y., Longo, C., Xu, H., Gofron, K., Yin, Z., Chen, H. H., Hwu, Y. & Lee, W. K. (2019). Rev. Sci. Instrum. 90, 053701.  Web of Science CrossRef PubMed Google Scholar
First citationDuan, X., Yang, F., Antono, E., Yang, W., Pianetta, P., Ermon, S., Mehta, A. & Liu, Y. (2016). Sci. Rep. 6, 34406.  Web of Science CrossRef PubMed Google Scholar
First citationEspinosa, A., Serrano, A., Llavona, A., Jimenez de la Morena, J., Abuin, M., Figuerola, A., Pellegrino, T., Fernández, J. F., Garcia-Hernandez, M., Castro, G. R. & Garcia, M. A. (2012). Meas. Sci. Technol. 23, 015602.  Web of Science CrossRef Google Scholar
First citationFayard, B., Pouyet, E., Berruyer, G., Bugnazet, D., Cornu, C., Cotte, M., Andrade, V. D., Chiaro, F. D., Hignette, O., Kieffer, J., Martin, T., Papillon, E., Salomé, M. & Sole, V. A. (2013). J. Phys. Conf. Ser. 425, 192001.  CrossRef Google Scholar
First citationFrazer, B. H., Gilbert, B., Sonderegger, B. R. & De Stasio, G. (2003). Surf. Sci. 537, 161–167.  Web of Science CrossRef CAS Google Scholar
First citationGe, M. Y., Coburn, D. S., Nazaretski, E., Xu, W. H., Gofron, K., Xu, H. J., Yin, Z. J. & Lee, W. K. (2018). Appl. Phys. Lett. 113, 083109.  Web of Science CrossRef Google Scholar
First citationIsomura, N., Soejima, N., Iwasaki, S., Nomoto, T., Murai, T. & Kimoto, Y. (2015). Appl. Surf. Sci. 355, 268–271.  Web of Science CrossRef CAS Google Scholar
First citationKitajima, Y., Yokoyama, T., Funabashi, M., Ohta, T. & Kuroda, H. (1989). Physica B, 158, 668–669.  CrossRef CAS Web of Science Google Scholar
First citationKoningsberger, D. C. & Prins, R. (1988). X-ray Absorption: Principles, Applications, Techniques of EXAFS, SEXAFS and XANES. New York: John Wiley and Sons.  Google Scholar
First citationLee, C. H., Matsuhata, H., Yamaguchi, H., Sekine, C., Kihou, K., Suzuki, T., Noro, T. & Shirotani, I. (2004). Phys. Rev. B, 70, 153105.  Web of Science CrossRef Google Scholar
First citationLerotic, M., Jacobsen, C., Gillow, J. B., Francis, A. J., Wirick, S., Vogt, S. & Maser, J. (2005). J. Electron Spectrosc. Relat. Phenom. 144–147, 1137–1143.  Web of Science CrossRef CAS Google Scholar
First citationLiao, B. & Chen, J. (1992). J. Appl. Cryst. 25, 336–339.  CrossRef CAS Web of Science IUCr Journals Google Scholar
First citationLiu, Y., Andrews, J. C., Meirer, F., Mehta, A., Gil, S. C., Sciau, P., Mester, Z. & Pianetta, P. (2011). AIP Conf. Proc. 1365, 357–360.  CrossRef Google Scholar
First citationLiu, Y., Meirer, F., Williams, P. A., Wang, J., Andrews, J. C. & Pianetta, P. (2012). J. Synchrotron Rad. 19, 281–287.  Web of Science CrossRef CAS IUCr Journals Google Scholar
First citationLu, J., Wu, T. P. & Amine, K. (2017). Nat. Energy, 2, 17011.  Web of Science CrossRef Google Scholar
First citationMao, Y., Wang, X., Xia, S., Zhang, K., Wei, C., Bak, S., Shadike, Z., Liu, X., Yang, Y., Xu, R., Pianetta, P., Ermon, S., Stavitski, E., Zhao, K., Xu, Z., Lin, F., Yang, X. Q., Hu, E. & Liu, Y. (2019). Adv. Funct. Mater. 29, 1900247.  Web of Science CrossRef Google Scholar
First citationMeirer, F., Cabana, J., Liu, Y., Mehta, A., Andrews, J. C. & Pianetta, P. (2011). J. Synchrotron Rad. 18, 773–781.  Web of Science CrossRef CAS IUCr Journals Google Scholar
First citationNelson, G. J., Harris, W. M., Izzo, J. R., Grew, K. N., Chiu, W. K. S., Chu, Y. S., Yi, J., Andrews, J. C., Liu, Y. J. & Pianetta, P. (2011). Appl. Phys. Lett. 98, 173109.  Web of Science CrossRef Google Scholar
First citationO'Sullivan, F. (1995). Ann. Statist. 23, 1267–1300.  Google Scholar
First citationPedregosa, F., Varoquaux, G., Gramfort, A., Michel, V., Thirion, B., Grisel, O., Blondel, M., Prettenhofer, P., Weiss, R., Dubourg, V., Vanderplas, J., Passos, A., Cournapeau, D., Brucher, M., Perrot, M. & Duchesnay, E. (2011). J. Mach. Learn. Res. 12, 2825–2830.  Google Scholar
First citationPuga, A. V. (2018). Catal. Sci. Technol. 8, 5681–5707.  Web of Science CrossRef CAS Google Scholar
First citationRavel, B. & Newville, M. (2005). J. Synchrotron Rad. 12, 537–541.  Web of Science CrossRef CAS IUCr Journals Google Scholar
First citationRehr, J. J. & Ankudinov, A. L. (2005). Coord. Chem. Rev. 249, 131–140.  Web of Science CrossRef CAS Google Scholar
First citationThevenaz, P., Ruttimann, U. E. & Unser, M. (1998). IEEE Trans. Image Process. 7, 27–41.  Web of Science CrossRef PubMed CAS Google Scholar
First citationWang, J. J., Chen-Wiegart, Y. K. & Wang, J. (2013). Chem. Commun. 49, 6480–6482.  Web of Science CrossRef CAS Google Scholar
First citationWang, J. J., Chen-Wiegart, Y. K. & Wang, J. (2014). Nat. Commun. 5, 4570.  Web of Science CrossRef PubMed Google Scholar
First citationWang, L. G., Wang, J. J., Zhang, X. Y., Ren, Y., Zuo, P. J., Yin, G. P. & Wang, J. (2017). Nano Energy, 34, 215–223.  Web of Science CrossRef Google Scholar
First citationYang, H. P., Wu, H. H., Ge, M. Y., Li, L. J., Yuan, Y. F., Yao, Q., Chen, J., Xia, L. F., Zheng, J. M., Chen, Z. Y., Duan, J., Kisslinger, K., Zeng, X. C., Lee, W. K., Zhang, Q. B. & Lu, J. (2019). Adv. Funct. Mater. 29, 1808825.  Web of Science CrossRef Google Scholar
First citationYang, L. C., McRae, R., Henary, M. M., Patel, R., Lai, B., Vogt, S. & Fahrni, C. J. (2005). P. Natl Acad. Sci. USA, 102, 11179–11184.  Web of Science CrossRef CAS Google Scholar
First citationZhang, K., Ren, F., Wang, X., Hu, E., Xu, Y., Yang, X. Q., Li, H., Chen, L., Pianetta, P., Mehta, A., Yu, X. & Liu, Y. (2017). Nano Lett. 17, 7782–7788.  Web of Science CrossRef CAS PubMed Google Scholar
First citationZhang, M. J., Hu, X. B., Li, M. F., Duan, Y. D., Yang, L. Y., Yin, C., Ge, M. Y., Xiao, X. H., Lee, W. K., Ko, J. Y. P., Amine, K., Chen, Z. H., Zhu, Y. M., Dooryhee, E., Bai, J. M., Pan, F. & Wang, F. (2019). Adv. Energ. Mater. 9, 1901915.  Web of Science CrossRef Google Scholar

© International Union of Crystallography. Prior permission is not required to reproduce short quotations, tables and figures from this article, provided the original authors and source are cited. For more information, click here.

Journal logoJOURNAL OF
SYNCHROTRON
RADIATION
ISSN: 1600-5775
Follow J. Synchrotron Rad.
Sign up for e-alerts
Follow J. Synchrotron Rad. on Twitter
Follow us on facebook
Sign up for RSS feeds