Skip to main content

twig-emissions-indicators

Python Poetry Ruff

Python package for quantification of CO2 intensities of european electricity bidding zones. It relies on ENTSO-E data from the ENTSO-E Transparency Platform.

The accounting method is following a multi-regional input output approach developed in the following paper: Evaluation Method for the Hourly Average CO2eq. Intensity of the Electricity Mix and Its Application to the Demand Response of Residential Heating and further developed in the following documentation available in the github repository.

Through the MRIO method, average emissions factors are calculated. Then, a Linear Model Tree is trained to quantify the marginal emissions factors. For further information, please refer to the documentation available in the github repository.

The core functionalities of the twig-emissions-indicators package are:

  • entsoe data loading
  • data processing through MRIO approach
  • Linear Model Tree Training for Marginal Emissions Factors quantification

Installation

pip install twig-emissions-indicators

Usage

Data Loading and MRIO Calculation

In order to use the twig-emissions-indicators package and generate the needed data for the Linear Model Tree training, you need to first load the ENTSO-E data using the DataLoader class through the MRIO approach.

from twig_emissions_indicators.data import DataLoader
from twig_emissions_indicators.mrio import CalculatorMRIO

ENTSOE_TOKEN = "Your ENTSO-E token"
period_start = pd.Timestamp('20250101', tz='Europe/Brussels')
period_end = pd.Timestamp('20251231', tz='Europe/Brussels')

data_loader = DataLoader(start=period_start, 
                         end=period_end, 
                         api_key=ENTSOE_TOKEN, 
                         dir=Path("folder_path_for_entsoe_data"))
calc = CalculatorMRIO(data_loader, bidding_zone='DK_2')
calc.store_results(results_folder="folder_path_for_results")

In the above example, the DataLoader is used to load the ENTSO-E data, and the CalculatorMRIO is used to process the data through the MRIO approach. The results are then stored in the specified folder.

This step is necessary to generate the data needed for the Linear Model Tree training.

Linear Model Tree Training

Once the MRIO calculation has produced emissions data, prepare three time-aligned inputs:

  • dE: a pandas.Series containing the change in emissions (the prediction target).
  • dL: a pandas.Series containing the corresponding change in load.
  • X: a pandas.DataFrame of explanatory features, such as generation mix or weather.

All three inputs should use the same DatetimeIndex. The model combines dL with X; by default, it treats Hour, Month, and Dow as circular time features when those columns are present.

from twig_emissions_indicators.linearmodeltree import LinearTreeModel

# Build these from your processed data. Keep the same DatetimeIndex on all inputs.
dE = data["delta_emissions"]
dL = data["delta_load"]
X = data[["Hour", "Month", "Dow", "Wind", "Solar", "Gas"]]

model = LinearTreeModel(random_state=42)
model.fit(dE=dE, dL=dL, X=X, test_year=2025)

# The fitted model predicts the target (delta emissions) using dL as the regressor.
predicted_dE = model.predict(X, dL=dL)
print(f"Test R²: {model.get_results().metrics['test_r2']:.3f}")

# Inspect the estimated marginal emissions factors for the held-out observations.
results = model.get_results()
print(results.mef.head())

model.save("linear_tree_model.joblib")

fit drops rows with missing target or feature values. By default it trains on years before test_year and evaluates on that year (2025 by default); pass test_size instead to use a chronological fraction of the observations as the test set, for example model.fit(dE, dL, X, test_size=0.2). Hyperparameters are tuned using time-series cross-validation, so training requires enough observations for the configured number of splits (n_splits, default 5).

The results container returned by get_results() includes train/test metrics, feature importances, selected features, baseline metrics, and g_k, the estimated marginal emissions factor for each held-out row. A saved model can be restored with LinearTreeModel.load("linear_tree_model.joblib").


CO2 intensity factors

For each generator, the CO2 intensity factor is defined from IPCC data and are gathered in the twig_emissions_indicators.config module. Potential neighbors zones that do not have ENTSOE data are assigned a default value from the EMISSION_FACTORS dictionary. This default dataset can be overridden by providing a custom emissions factors dictionary when initializing the DataLoader, under the emissions_factors parameter.

# Emission factors (kgCO2eq/MWh)
EMISSION_FACTORS = {
    "Fossil Hard coal": 820,
    "Fossil Gas":       490,
    "Nuclear":          12,
    "Wind Onshore":     11,
    "Wind Offshore":    12,
    "Solar":            48,
    "Hydro":            24,
    "Biomass":          230,
    "Fossil Oil":       840,
    "Fossil Brown coal/Lignite": 820,
    "Fossil Coal-derived gas": 820,
    "Fossil Peat": 820,
    "Geothermal": 38,
    "Waste": 230,
    "Other": 258,
    "Other renewable": 48,
    "Hydro Pumped Storage": 24,
    "Hydro Run-of-river and poundage": 24,
    "Hydro Water Reservoir": 24,
    "Energy storage": 358,
    "Marine": 10,
    # Imports # Electricity Maps 2024
    "Import_GB": 175,
    "Import_EE": 291,
    "Import_RU": 354.0,
}

Dependencies

The package depends on the following libraries:

  • pandas (>=3.0.5,<4.0.0)
  • entsoe-py (>=0.8.0,<0.9.0)
  • matplotlib (>=3.11.1,<4.0.0)
  • linear-tree (fork compatible with scikit-learn >= 1.7.0)

Metadata

Release files for twig-emissions-indicators 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for twig-emissions-indicators 0.1.3
File Size Uploaded Provenance Actions
twig_emissions_indicators-0.1.3.tar.gz 18.9 kB Without provenance Details for twig_emissions_indicators-0.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for twig-emissions-indicators 0.1.3
File Interpreter ABI Platform Actions
twig_emissions_indicators-0.1.3-py3-none-any.whl Python 3 none any Details for twig_emissions_indicators-0.1.3-py3-none-any.whl

Total release size: 37.9 kB

Release files / twig_emissions_indicators-0.1.3.tar.gz

Download URL twig_emissions_indicators-0.1.3.tar.gz
Size 18.9 kB
Tags Source
SHA-256 checksum
How to use checksums
bd7f7d7951cd6ed9c3e9656aee161f42264c6a474a7a5af7a984f83c04a57a71
BLAKE2b-256 checksum
How to use checksums
bc9201137799092370045b15f179b16510290fad7798361edee7228d03e3f74c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / twig_emissions_indicators-0.1.3-py3-none-any.whl

Download URL twig_emissions_indicators-0.1.3-py3-none-any.whl
Size 19.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ce5ebdbcc9852852721af3612a572fe673d27203f39b97d0167c46875697f17d
BLAKE2b-256 checksum
How to use checksums
004bbc0eec0f978c57fad8eac6d684c370974c6e123d1037479cc13e084e7fde
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for twig-emissions-indicators 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page