Python-LMDI: A Tool for Index Decomposition Analysis of Building Carbon Emissions

A timely analysis for carbon emission reduction in buildings is an effective global response to the crisis of climate change. The logarithmic mean Divisia index (LMDI) decomposition analysis approach has been extensively used to assess the carbon emission reduction potential of the buildings sector. In order to simplify the calculation process and to expand its application scope, a new open-source Python tool (PyLMDI) developed in this article is used to compute the results of LMDI decomposition analysis, including multiplicative and additive decomposition. Users can quickly obtain the decomposition result by initializing the input data through a simple class data structure. In addition, the carbon emissions from commercial buildings are used as a numerical example to demonstrate the function of PyLMDI. In summary, PyLMDI is a potential calculation tool for index decomposition analysis that can provide calculation guidance for carbon emission reduction in the buildings sector. The data and codes for the numerical example are also included.


Introduction
Buildings as major carbon emitters have attracted growing attention in recent decades [1]. According to the latest global status report for buildings and construction, carbon emissions from buildings were 11.7 gigatons in 2020, accounting for 36% of total global carbon emissions [2,3]. In addition, there is considerable evidence that as the demand for building terminal equipment and energy consumption continues to grow, the buildings sector will continue to be the source of a significant increase in carbon emissions in the future [4,5]. Therefore, a timely tapping of the emission reduction potential of the buildings is an important measure to achieve the goal of controlling the global temperature rise below 2 degrees. At the same time, to formulate realistic emission reduction targets as well as to track and evaluate performance, it is particularly important to accurately identify changes in the driving forces behind carbon emissions from buildings [6,7].
Index decomposition analysis (IDA) is an important technical method for quantitatively analyzing the impact of interest on aggregate indicators, especially the intensity or total amount of carbon emissions [8]. In 2004, Ang [9] compared various decomposition analysis methods and concluded that the logarithmic mean Divisia index (LMDI) was the ideal decomposition analysis approach. Subsequently, a study by [10] further introduced the theory of LMDI and provided practical guidance. Later, Xu and Ang [11] comprehensively reviewed the index decomposition analysis methods applied to carbon emissions in 2013 and found that LMDI was the most studied and widely applied method. Recently, Ang [12] again reviewed the history of LMDI and found that the LMDI approach was still dominant in many areas, and this situation was expected to become more evident over time. Motivated by this fact, Ma and his collaborators [13,14] focused on the energy and emission systems in the buildings sector, and their results confirmed that LMDI was an excellent decomposition analysis method. However, the existing literature on LMDI is too technical and professional and includes intricate calculation methods. Therefore, potential users face significant challenges, such as complex and time-consuming calculations, when analyzing specified problems using LMDI [15].
To bridge the above gap, in this study, we aim to solve the following two problems: • How to develop a simple and convenient tool for LMDI decomposition analysis; • How to use this tool to analyze carbon emissions from commercial buildings, using China and the US as examples.
To address these two issues, this is the first study to develop an open-source tool for calculating LMDI decomposition analysis based on Python, abbreviated as PyLMDI, available at https://github.com/xiwang2718/PyLMDI (accessed on 10 December 2021). PyLMDI can easily and quickly calculate the multiplicative and additive decomposition results of LMDI. On the basis of this, the carbon emissions from commercial buildings in China and the US are utilized as a numerical example to demonstrate how to perform an LMDI decomposition analysis with the developed PyLMDI.
The most advanced contribution of this study is the tool for LMDI decomposition analysis that has been developed. The decomposition results can be calculated by the tool once the decomposition model and data are given. To the best of our knowledge, although researchers have studied LMDI extensively, presently, there is no effective tool for calculating the decomposition result of LMDI. The developed PyLMDI tool in this study bridges this gap and is expected to extend the LMDI decomposition analysis method to other fields.
The remainder of this paper consists of the following four parts: In Section 2, we review the index decomposition analysis methods; in Section 3, we introduce the theory of LMDI and the development of PyLMDI; in Section 4, we present a numerical example; and finally, in Section 5, we summarize the contributions of this study.

Literature Review
Decomposition analysis is an accounting or description technique, including IDA(Index decomposition analysis) and SDA(Structure decomposition analysis)which has been extensively utilized to better analyze and understand energy and emission systems [16,17]. Figure 1 summarizes the development process of decomposition analysis theory. It can be observed that the Divisia index and the Laspeyres index are the two main ideas in IDA, which can work well in both multiplication and addition decomposition [18][19][20]. Since 1990, researchers have focused on Divisia decomposition and proposed the arithmetic mean decomposition analysis method (AMDI) [21,22]. Later, Ang et al. further proposed the well-known logarithmic mean Divisia index (LMDI) decomposition analysis method [23]. In recent years, in order to improve the emission reduction contribution of the construction sector, LMDI has attracted the interest of researchers with its outstanding performance [24,25]. Table 1 lists the research results of LMDI on carbon emissions from buildings in China over the last five years, which includes the scope of the study and key drivers. These research trends suggest that LMDI is expected to continue to play an important role in the future of carbon emissions in the buildings sector.
ulation [48][49][50], and system optimization [51,52], have been developed based on the Python language. These tools have greatly improved the productivity of scientists and engineers and are widely recognized and accepted in academia and industry [53,54]. However, to the best of our knowledge, no tools or frameworks for decomposition analysis are currently being designed and developed. The above analysis shows that LMDI is the preferred decomposition analysis approach in terms of theoretical technology and application scope and has been widely recognized and cited in the field of carbon emissions from buildings. Nevertheless, to date, efforts have mainly focused on the application of LMDI but lacked discussion of its calculation method. Consequently, the computational cost and application difficulty of the LMDI decomposition technology have increased. Therefore, there is an urgent need to calculate the decomposition results of LMDI in a simpler way. In this study, we provide the following contributions: A tool for calculating LMDI decomposition results is designed and developed based on Python, which can significantly reduce the computational cost of LMDI. The developed PyLMDI can be easily applied to carbon emission reduction in many other fields.

PyLMDI: A Python Tool for LMDI Decomposition Analysis
In this section, first, an overview of LMDI theory, which includes multiplicative decomposition and addition factorization groups, is presented. Then, the calculation process of LMDI is further explained. Finally, based on the calculation process, a new tool for LMDI decomposition analysis is developed.

The LMDI Decomposition Analysis
In general, we assume that V is the aggregate of m sectors and can be represented which is used to describe the influence of n driving forces  Python, as one of the most promising programming languages, has inherited good features from other programming languages, such as C, Fortran, and Haskell, with simpler and more elegant syntax [45,46]. Therefore, it is recognized as a leader in open-source project development. At present, a large number of open-source tools, which are often used to analyze energy and emission systems, such as data processing [47], dynamic simulation [48][49][50], and system optimization [51,52], have been developed based on the Python language. These tools have greatly improved the productivity of scientists and engineers and are widely recognized and accepted in academia and industry [53,54]. However, to the best of our knowledge, no tools or frameworks for decomposition analysis are currently being designed and developed.
The above analysis shows that LMDI is the preferred decomposition analysis approach in terms of theoretical technology and application scope and has been widely recognized and cited in the field of carbon emissions from buildings. Nevertheless, to date, efforts have mainly focused on the application of LMDI but lacked discussion of its calculation method. Consequently, the computational cost and application difficulty of the LMDI decomposition technology have increased. Therefore, there is an urgent need to calculate the decomposition results of LMDI in a simpler way. In this study, we provide the following contributions: A tool for calculating LMDI decomposition results is designed and developed based on Python, which can significantly reduce the computational cost of LMDI. The developed PyLMDI can be easily applied to carbon emission reduction in many other fields.

PyLMDI: A Python Tool for LMDI Decomposition Analysis
In this section, first, an overview of LMDI theory, which includes multiplicative decomposition and addition factorization groups, is presented. Then, the calculation process of LMDI is further explained. Finally, based on the calculation process, a new tool for LMDI decomposition analysis is developed.

The LMDI Decomposition Analysis
In general, we assume that V is the aggregate of m sectors and can be represented where V i represents the target variable from the i-th department. In ndimensional space, V i can be further defined as which is used to describe the influence of n driving forces x j,i (j = 1, 2, . . . , n) over time on the target variable V i .
In the time period [0, T], the change of the target variable from n,i can be described in different modes, which include multiplicative decomposition: and additive decomposition: The D tot and ∆V tot on the left side of Equations (2) and (3) represent the change of the target variable, and the terms on the right side of Equations (2) and (3) represent the influence of various related driving factors.
As mentioned above, the Divisia index decomposition analysis is the most commonly used decomposition method, which was proposed by the French mathematician Divisia in 1924 [55]. In the Divisia index decomposition analysis theory, all factors to be decomposed are treated as continuous differentiable functions related to time t. Then, by perform-ing the differential operation on time, the influence of the change of each factor on the decomposition target variable is obtained.
According to the definition of Divisia index decomposition analysis, take the derivative of target variable with respect to time T, one obtains: Integrate both sides with respect to time, we have: Consider simultaneously Equation (3) and Equation (5), the additive decomposition Equation (3) can be written as In addition, divide both sides of Equation (5) by V T , and integrate again with respect to time, one obtains: where ω i is the weight function and is represented by ω i = V i V [10]. Taking both sides of Equation (7) to the exponent, the multiplicative decomposition Equation (2) can be written as It is difficult to directly calculate the additive decomposition (Equation (6)) and multiplicative decomposition (Equation (8)), resulting in a large number of approximation methods being studied in order to obtain a reasonable decomposition result. Then, Ang et al. [23] proposed a new logarithmic mean Divisia index decomposition analysis approach, which was abbreviated as LMDI for simplicity. The additive decomposition Equation (6) can be further expressed as Similarly, the multiplicative decomposition Equation (8) can also be further transformed into where L(·) is the logarithmic mean function. Suppose p and q represent the target variables at different periods, L(·) is defined as follows: Buildings 2022, 12, 83 6 of 13

The PyLMDI Open-Source Tool
A reasonable model framework and algorithm design flow are important prerequisites for improving computational efficiency and broadening the scope of application [56,57]. Rearranging the LMDI theory introduced in the previous subsection, the calculation process of LMDI can be summarized by the following five steps: Step 1: Input the original data of the target variable and related driving force factors and establish the LMDI decomposition identity.
Step 2: Determine the decomposition mode used for analysis.
Step 3: Calculate the change of target variable according to Equations (2) and (3).
Step 4: Calculate the influence of driving forces according to Equations (9) and (10).
Step 5: Output the decomposition results of the LMDI decomposition analysis. Python is a popular programming language with advanced features such as open source, interpretive and object-oriented programming [58,59]. Python has been widely applied in scientific research [60][61][62], and more importantly, it can be run on all available operating systems. Combined with the above calculation steps, a new tool for calculating LMDI decomposition results was developed based on Python and abbreviated as PyLMDI.
In our research work, PyLMDI was developed to rely on a class data structure, with target variables (V 0 and V T ) and driver variables (X 0 = x 0 1,i , x 0 2,i , · · · , x 0 n,i and X T = x T 1,i , x T 2,i , · · · , x T n,i ) being input as the class parameters. The additive decomposition and multiplicative decomposition are also encapsulated as class methods and output their decomposition results. Figure 2 further illustrates the design principle of PyLMDI and provides an overview of the research flow of this study. Moreover, a demo file was produced to test the function of PyLMDI, using data from studies by Ang et al. [9,12]. In addition, a detailed instruction manual is attached to the PyLMDI project library, which guides all users to quickly start PyLMDI and run the code. All Python scripts and related files mentioned in our study are freely available from the GitHub repository (https://gith ub.com/xiwang2718/PyLMDI, accessed on 10 December 2021), where anyone can view, download, and edit the source code.

Historical Carbon Abatement in the Commercial Building Operation: China versus the US
Commercial buildings, an important component of the buildings sector, are also regarded as having more potential for carbon emission reduction than other sectors [63,64]. On the other hand, as the world's top two carbon emitters, the efforts of China and the US to reduce carbon emissions can effectively contribute to the global response to climate change [65,66]. In this section, carbon emission models for China and the US can be established based on carbon emissions from commercial buildings (C), energy consumption (E), population size (P), public floor area (F), tertiary industry added value (Gs), and GDP (G).

Historical Carbon Abatement in the Commercial Building Operation: China versus the US
Commercial buildings, an important component of the buildings sector, are also regarded as having more potential for carbon emission reduction than other sectors [63,64]. On the other hand, as the world's top two carbon emitters, the efforts of China and the US to reduce carbon emissions can effectively contribute to the global response to climate change [65,66]. In this section, carbon emission models for China and the US can be established based on carbon emissions from commercial buildings (C), energy consumption (E), population size (P), public floor area (F), tertiary industry added value (G s ), and GDP (G). The developed PyLMDI was applied to calculate the degree of influence driving forces exerted on the carbon emissions from commercial buildings in different time periods. The raw data related to China's commercial buildings were collected from IBED(International Building Emission Dataset) datasets, which have been extensively accepted by existing efforts [67][68][69], and the raw data related to China's economy and population were collected from the China Statistical Yearbook. The raw data for the US were derived from the Energy Information Administration. Figure 3 illustrates the dynamic of carbon emissions in China and the US from 2000 to 2018. According to the classic IPAT(Impact, population, affluence, technology) model [70,71], the carbon emission models for commercial buildings can be extended as follows:.

C P g s i e K
= ⋅ ⋅ ⋅ ⋅ ⋅ According to the classic IPAT(Impact, population, affluence, technology) model [70,71], the carbon emission models for commercial buildings can be extended as follows:.
where g = G P represents the Gross Domestic Product (GDP) per capita, s = G s G represents the industrial structure,e = E F represents the Energy intensity, i = F G s represents the economic efficiency, and K = C E represents the total emissions factor. By performing LMDI multiplication decomposition analysis on Equation (12), the contribution of each driving force to carbon emissions at different time periods can be obtained as shown below: In addition, according to the time span of the collected research data, in this study we adopt the analysis strategy of decomposition every six years. The developed PyLMDI was utilized to calculate the decomposition analysis results of the carbon emissions from commercial buildings. First, according to Equation (12), the observed data of carbon emissions and the driving forces at different moments are input. Then, we instantiate the corresponding PyLMDI classes for China and the US. Next, the additive decomposition class method is used to compute the results of all the items in Equation (13). Finally, the results of the LMDI decomposition analysis are output and visualized in Figure 4. The source code for the calculations is also available at https://github.com/xiwang2718/Py LMDI (accessed on 10 December 2021). The code is run through Spyder IDE (Python 3.8) on a Windows operating system.  Figure 4 shows the staged changes of different driving forces on the carbon emissions from commercial buildings in the past 20 years. As shown in Figure 4a, the most prominent positive driving force for changes in China's carbon emissions is the GDP per capita. Additionally, the greatest negative contribution to carbon emissions from China's commercial buildings is energy intensity, which also means energy intensity is the key driving force to promote carbon reduction from China's commercial buildings. Regarding the US, Figure 4b shows that the per capita GDP also plays a significant, positive role in carbon emissions of commercial buildings in the US, and it should be pointed out that this influence is very different from that in China. In addition, industrial structure and economic efficiency are the major factors in reducing carbon emissions from the US's commercial buildings.
After determining the contribution level of each influencing factor on carbon emissions in three different time periods, PyLMDI was again applied to calculate the year-byyear decomposition results over nearly 20 years, and then to assess their respective historical carbon emission reduction levels ( Figure 5). To boost the interpretability of the results, two error bands are attached in Figure 5. (The error ranges for China and the US are 20.45 MtCO2 and 31.55 MtCO2, respectively). As illustrated in Figure 5a, the total carbon emission reduction in China's commercial buildings has shown an increasing trend. The curve in Figure 5b shows a significant downward trend in the total amount of carbon reduction in the US. By comparing the carbon emission reduction levels of commercial buildings in China and the US, it is easy to find that there has been little difference between the total carbon emission reduction over the past nearly two decades. Specifically,   Figure 4 shows the staged changes of different driving forces on the carbon emissions from commercial buildings in the past 20 years. As shown in Figure 4a, the most prominent positive driving force for changes in China's carbon emissions is the GDP per capita. Additionally, the greatest negative contribution to carbon emissions from China's commercial buildings is energy intensity, which also means energy intensity is the key driving force to promote carbon reduction from China's commercial buildings. Regarding the US, Figure 4b shows that the per capita GDP also plays a significant, positive role in carbon emissions of commercial buildings in the US, and it should be pointed out that this influence is very different from that in China. In addition, industrial structure and economic efficiency are the major factors in reducing carbon emissions from the US's commercial buildings.
After determining the contribution level of each influencing factor on carbon emissions in three different time periods, PyLMDI was again applied to calculate the year-by-year decomposition results over nearly 20 years, and then to assess their respective historical carbon emission reduction levels ( Figure 5). To boost the interpretability of the results, two error bands are attached in Figure 5. (The error ranges for China and the US are 20.45 MtCO 2 and 31.55 MtCO 2 , respectively). As illustrated in Figure 5a, the total carbon emission reduction in China's commercial buildings has shown an increasing trend. The curve in Figure 5b shows a significant downward trend in the total amount of carbon reduction in the US. By comparing the carbon emission reduction levels of commercial buildings in China and the US, it is easy to find that there has been little difference between the total carbon emission reduction over the past nearly two decades. Specifically, China's annual carbon emission reduction is 50.44 ± 20.45 MtCO 2 , while that in the US is 65.36 ± 31.55 MtCO 2 . Nonetheless, China and the US show considerable differences in their carbon emission reduction trends. Overall, China shows more carbon emission reduction potential than the US, and similar conclusions can be drawn from recent research efforts [69].

Discussion
In the previous subsection, LMDI was used to analyze the carbon emission reduction potential of commercial buildings in China and the U.S. All decomposition results were calculated via PyLMDI. In this subsection we further illustrate the reliability of the results by discussing the residual value of the decomposition results.
Theoretically, we assume that there is a residual term in the decomposition Equation Substituting Equation (8) into Equation (14), one obtains:  T  T  T  T  T  T  T  T   T  T  T  T  T  T  T  T   T  T  T  T   T  T Therefore, Equation (13) is proven to be a constant equation, i.e., there is no decomposition residual term. In addition, the calculation results from PyLMDI also verify this conclusion numerically.

Conclusions
The logarithmic mean Divisia index (LMDI) is a mature decomposition analysis method. Recently, LMDI has been extensively recognized by researchers and applied in

Discussion
In the previous subsection, LMDI was used to analyze the carbon emission reduction potential of commercial buildings in China and the U.S. All decomposition results were calculated via PyLMDI. In this subsection we further illustrate the reliability of the results by discussing the residual value of the decomposition results.
Theoretically, we assume that there is a residual term in the decomposition Equation (13), and it is expressed as ∆C res ; then, the residual term ∆C res can be defined as follows: Substituting Equation (8) into Equation (14), one obtains: ∆C res = ∆C| 0→T − (∆P + ∆g + ∆s + ∆i + ∆e + ∆K) = ∆C| 0→T − L C T , C 0 ln P T P 0 + ln g T g 0 + ln s T s 0 + ln i T i 0 + ln e T e 0 + ln K T K 0 Therefore, Equation (13) is proven to be a constant equation, i.e., there is no decomposition residual term. In addition, the calculation results from PyLMDI also verify this conclusion numerically.

Conclusions
The logarithmic mean Divisia index (LMDI) is a mature decomposition analysis method. Recently, LMDI has been extensively recognized by researchers and applied in many fields. The trends suggest that it will continue to play an important role in energy consumption and emission decomposition analysis in the future, particularly in the buildings sector.
In this study, the theory and application of LMDI were introduced in detail. A new open-source tool, called PyLMDI, for calculating LMDI decomposition results was developed based on the Python programming language (available on https://github.com/x iwang2718/PyLMDI, accessed on 10 December 2021), which provided enough information for interested users to use the LMDI decomposition approach in the "black box" mode. In addition, the numerical example shows that PyLMDI is an efficient tool for analyzing carbon emission reductions from commercial buildings in China and the United States [72]. Overall, the PyLMDI tool developed in this study provides calculation guidance for carbon emission decomposition analysis in the buildings sector and other fields. Future studies should aim to update the tool based on other programming languages and software (such as R language), and also to develop tools for other new decomposition analysis methods such as the generalized Divisia index method [73,74].