Skip to content

Commit

Permalink
Add bio CO2 fix for biogas activities
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Dec 10, 2023
1 parent 6e2c79d commit 4f4e696
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 22 deletions.
4 changes: 4 additions & 0 deletions premise/data/fuels/biomethane_correction.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- treatment of sewage sludge by anaerobic digestion
- anaerobic digestion of manure
- treatment of biowaste by anaerobic digestion
- treatment of used vegetable cooking oil by anaerobic digestion
2 changes: 1 addition & 1 deletion premise/data/fuels/fuel_groups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ kerosen:
- kerosene, synthetic, from biomass, energy allocation
- kerosene, synthetic, from biomass, energy allocation, with CCS

liquified petroleum gas:
liquefied petroleum gas:
- liquefied petroleum gas
- liquefied petroleum gas, synthetic, from natural gas
- liquefied petroleum gas, synthetic, from natural gas, with CCS
Expand Down
12 changes: 0 additions & 12 deletions premise/data/utils/logging/reporting.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,6 @@ premise_electricity:
name: New electrical efficiency
description: Electrical efficiency after adjustment (1 / fuel energy input)
unit: 0-1
biomass share:
name: Biomass share
description: Share of biomass from forestry residues vs. purpose-grown biomass
unit: 0-1
transformation loss:
name: Transformation loss
description: Loss in transforming high to medium and low-voltage electricity
Expand Down Expand Up @@ -334,14 +330,6 @@ premise_cement:
name: Electricity consumed
description: Electricity consumed (kWh) per kg cement
unit: kWh/kg
old clinker-to-cement ratio:
name: Old clinker-to-cement ratio
description: Clinker-to-cement ratio before adjustment
unit: 0-1
new clinker-to-cement ratio:
name: New clinker-to-cement ratio
description: Clinker-to-cement ratio after adjustment
unit: 0-1
tab: Cement

premise_fuel:
Expand Down
73 changes: 71 additions & 2 deletions premise/fuels.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import copy
from functools import lru_cache
from pprint import pprint
from typing import Union

import wurst
Expand Down Expand Up @@ -46,6 +45,13 @@
BIOFUEL_SOURCES = DATA_DIR / "fuels" / "biofuels_activities.yml"
FUEL_GROUPS = DATA_DIR / "fuels" / "fuel_groups.yaml"

def load_methane_correction_list():
"""
Load biomethane_correction.yaml file and return a list
"""
with open(DATA_DIR / "fuels" / "biomethane_correction.yaml", "r") as f:
methane_correction_list = yaml.safe_load(f)
return methane_correction_list

def fetch_mapping(filepath: str) -> dict:
"""Returns a dictionary from a YML file"""
Expand Down Expand Up @@ -296,6 +302,7 @@ def _update_fuels(scenario, version, system_model, cache=None):
scenario["iam data"].hydrogen_markets,
)
):
fuels.correct_biogas_activities()
fuels.generate_fuel_markets()
scenario["database"] = fuels.database
cache = fuels.cache
Expand Down Expand Up @@ -377,6 +384,60 @@ def __init__(
dim="variables",
)

def correct_biogas_activities(self):
"""
Some activities producing biogas are not given any
biogenic CO2 input, leading to imbalanced carbon flows
when combusted.
"""

list_biogas_activities = load_methane_correction_list()

# find datasets that have a name in the list
filters = [
ws.either(*[ws.equals("name", name)
for name in list_biogas_activities]),
]

biogas_datasets = ws.get_many(
self.database,
*filters,
ws.equals("reference product", "biogas"),
ws.equals("unit", "cubic meter"),
)

# add a flow of "Carbon dioxide, in air" to the dataset
# if not present. We add 1.96 kg CO2/m3 biogas.

for ds in biogas_datasets:
if not any(
exc
for exc in ws.biosphere(ds)
if exc["name"] == "Carbon dioxide, in air"
):
ds["exchanges"].append(
{
"uncertainty type": 0,
"amount": 1.96,
"type": "biosphere",
"name": "Carbon dioxide, in air",
"unit": "kilogram",
"categories": ("natural resource", "in air"),
"input": (
"biosphere3",
self.biosphere_flows[
(
"Carbon dioxide, in air",
"natural resource",
"in air",
"kilogram",
)
],
),
}
)


def find_transport_activity(
self, items_to_look_for: List[str], items_to_exclude: List[str], loc: str
) -> Tuple[str, str, str, str]:
Expand Down Expand Up @@ -2311,10 +2372,18 @@ def generate_fuel_markets(self):
d_fuels = self.get_fuel_mapping()

vars_map = {
"petrol, low-sulfur": ["petrol", "ethanol", "methanol", "gasoline"],
"petrol, low-sulfur": [
"petrol",
"ethanol",
"methanol",
"gasoline",
"bioethanol",
],
"diesel, low-sulfur": ["diesel", "biodiesel"],
"natural gas": ["natural gas", "biomethane"],
"hydrogen": ["hydrogen"],
"kerosene": ["kerosene"],
"liquefied petroleum gas": ["liquefied petroleum gas"],
}

new_datasets = []
Expand Down
1 change: 0 additions & 1 deletion premise/iam_variables_mapping/fuels_variables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,6 @@ diesel, synthetic, from coal:
- diesel production, synthetic, Fischer Tropsch process, hydrogen from coal gasification, energy allocation
- diesel production, from methanol, hydrogen from coal gasification, energy allocation


diesel, synthetic, from coal, with CCS:
lhv: 43
co2: 0.0732
Expand Down
14 changes: 9 additions & 5 deletions premise/steel.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,16 @@ def create_steel_markets(self):
steel_markets = {
loc: dataset
for loc, dataset in steel_markets.items()
if self.iam_data.production_volumes.sel(
region=loc, variables=["steel - primary", "steel - secondary"]
if (
self.iam_data.production_volumes.sel(
region=loc,
variables=["steel - primary", "steel - secondary"],
)
.interp(year=self.year)
.sum(dim="variables")
> 0
or loc == "World"
)
.interp(year=self.year)
.sum(dim="variables")
> 0
}
else:
for loc, dataset in steel_markets.items():
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ bw2io>=0.8.10
constructive-geometries>=0.9.4
cryptography
datapackage
numpy<=1.26.2
numpy
pandas
platformdirs
premise_gwp
Expand Down

0 comments on commit 4f4e696

Please sign in to comment.