Metadata-Version: 2.1
Name: BenToTru
Version: 0.0.21
Summary: Estimation of GHG emissions based on energy consumption in Brazil, broken down by 51 and 68 distinct activities.
Home-page: https://github.com/fms-1988
Author: Felipe Morelli Da Silva
Author-email: fms.morelli@gmail.com
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE

# Description of the BenToTru Package

## BenToTru
This package estimates the emissions of certain greenhouse gases (CO2, CH4, N2O, NOx, CO, and SO2) generated by energy consumption in Brazil. It uses the annual energy consumption data provided by the Energy Research Company (EPE) and the emission factors provided by the IPCC (1996 revision) and adapted by the NGO Economia e Energia (E&E) to Brazilian conditions. The result is the emissions by economic sector (IPCC structure) and by product (diesel, electricity, alcohol, etc).

In addition to estimating emissions for the 22 sectors, the package also breaks down these emissions into 51 or 68 sectors (according to the IBGE structure). To perform this disaggregation, we use an adaptation of the method by Montoya et al. (2013) which is described [here](#).

For the structure based on 51 sectors, we have data spanning from 2000 to 2022. For the one based on 68 sectors, the available data covers the period from 2010 to 2022. In addition to data related to economic sectors, we've also incorporated information regarding emissions attributed to households. A detailed description of the functions is provided in the following sections.

## How to Install BenToTru
The most recent version of the BenToTru package is 0.0.21. The main module, which is also the fastest because it uses matrix operations instead of loops, is 'btt'.

```python
pip install BenToTru==0.0.21
from BenToTru import btt as btt
```

## Estimating Emissions
You require three main pieces of information to estimate emissions: year, type of GHG, and number of sectors. The available gasses are: ('CO2', 'CH4', 'N2O', 'NOx', 'CO', and 'SO2'). The available sector numbers are: ('51' and '68'). The available years are: '2000' to '2022' for '51' sectors and '2010' to '2022' for '68' sectors.

```python
sys = btt.system('2010','68','t','CO2')
```


Don't worry about the 'level' variable for now, which can be 't' or 't-1'. Its function is related to the creation of distribution coefficients ('t': considers current values, 't-1': considers values lagged by one period).

## Estimating emissions for households
The 'system' function is preset to account for emissions from the 'household' sector. If you don't want this information in the final data, set the parameter to 'False'.

```python
sys = btt.system('2010','68','t','CO2',household=False)
```
## Selecting the Estimation Method
The 'btt' module offers two methods for emission estimation: the 'exact' method and the 'non-exact' method. The distinctions between them are detailed in this file (here). At its core, the 'exact' method ensures that the total emissions for the 22 sectors (following the IPCC structure) match the disaggregated emissions of either '51' or '68' activities (based on the IBGE structure). However, it might be less precise in attributing the exact emissions for each activity. The 'non-exact' method exhibits the opposite characteristics. In my opinion, it's preferable to retain the accuracy of activity-specific emissions rather than the overall total. To achieve this, we should set the 'exact_estimation' parameter to False.

```python
sys = btt.system('2010','68','t','CO2',exact_estimation=False)
```
## Variables of the 'system' Class
The table below outlines all the variables of the 'system' class. Our primary variable of interest is 'sys.emission_tru', which represents the amount of emissions generated from the consumption of the 17 products and distributed across all TRU activities. The unit for this variable is Gg of GHG.

| Variable               	| Description                                                  	| Structure/Note                                                    	| Unit                   	|
|----------------------------|------------------------------------------------------------------|-----------------------------------------------------------------------|---------------------------|
| `sys.ben`              	| Original data from BEN.                                      	| Matrix with 20 sectors and 27 products                            	| 10³ tep               	|
| `sys.ben_reduced`      	| Data from BEN considering only products that emit GHG.       	| Matrix with 20 sectors and 17 products                            	| 10³ tep               	|
| `sys.tru_CI_energy`    	| Original data from TRU only for products that emit GHG.      	| Matrix with 51 or 68 sectors (plus household) and 17 products    	| Market price values (BRL) |
| `sys.ben_to_tru_products`  | Dictionary mapping between BEN products and TRU products.    	|                                                                   	|                       	|
| `sys.ben_to_tru_sectors`   | Dictionary mapping between BEN sectors and TRU sectors.      	|                                                                   	|                       	|
| `sys.coef1`            	| Coefficients for distribution of tep values.                 	| Matrix with 51 or 68 sectors (plus household) and 17 products    	| BRL/BRL               	|
| `sys.tep`              	| Tep values distributed for TRU sectors (Only for 'non-exact' model). | Matrix with 51 or 68 sectors (plus household) and 17 products 	| 10³ tep               	|
| `sys.coef2`            	| Conversion factors for tep values into emissions (Only for 'non-exact' model). | Matrix with 51 or 68 sectors (plus household) and 17 products 	| Gg of GHG per 10³ tep  	|
| `sys.emission_tru`     	| Emissions for the N TRU sectors.                             	| Matrix with 51 or 68 sectors (plus household) and 17 products    	| Gg of GHG              	|
| `sys.emission_ben`     	| Emissions for the J BEN sectors. (Only for 'exact' model).   	| Matrix with 20 sectors and 27 products                            	| Gg of GHG              	|



## Graphical Representation
What truly interests us is the time series that illustrates the evolution of emissions generated by a specific TRU activity. The code below demonstrates how to obtain and visually represent this series.

```python
import pandas as pd
df = btt.system('2010','68','t','CO2').emission_tru
df['year'] = '2010'
for i in ['2011','2012','2013','2014','2015','2016','2017','2018','2019','2022']:
   try:
       df_ = btt.system(i,'68','t','CO2').emission_tru
       df_['year'] = i
       df = pd.concat([df, df_])
   except:
       print('error')
```

```python
import matplotlib.pyplot as plt

df_h = df[df.index == 'RESIDENCIAL']

df_h.plot(x='year', y='GÁS NATURAL', marker='o', linestyle='-')
plt.title("Emission of CO2 by households from the consumption of natural gas.")
plt.xlabel("Year")
plt.ylabel("Gg of GHG")
plt.grid(True)
plt.show()
```

![Alt text](https://raw.githubusercontent.com/fms-1988/datas/main/chart_BenToTru.png)

## Mapping from BEN Sectors to TRU
A sector (J) in BEN encompasses various TRU activities. The function X simplifies the transformation of a DataFrame from the BEN structure to the TRU structure. Let's say you want to understand the emissions from sector (J) and product (i), but represented in terms of activities.

```python
J = 1 #sector ‘SETOR ENERGÉTICO’
i = 1 #product ‘CARVÃO VAPOR’
btt.map_ben_to_tru(sys,sys.emission_tru,J,i)[0]
```

