Skip to content

Commit

Permalink
Finish TIAM-UCL integration
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Oct 9, 2024
1 parent 71edaf6 commit ecb1b0a
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 12 deletions.
1 change: 1 addition & 0 deletions premise/data/consequential/leadtimes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Coal PC: 4
Coal PC CCS: 5
Coal CHP: 4
Coal CHP CCS: 5
Coal USC: 4
Gas OC: 3
Gas CC: 3
Gas CC CCS: 3
Expand Down
1 change: 1 addition & 0 deletions premise/data/consequential/lifetimes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Coal PC: 40
Coal PC CCS: 40
Coal CHP: 40
Coal CHP CCS: 40
Coal USC: 40
Gas OC: 35
Gas CC: 35
Gas CC CCS: 35
Expand Down
33 changes: 25 additions & 8 deletions premise/fuels.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

import copy
from functools import lru_cache
from typing import Union

import xarray as xr
import yaml
from numpy import ndarray

from .filesystem_constants import DATA_DIR, VARIABLES_DIR
from .inventory_imports import get_biosphere_code
Expand Down Expand Up @@ -539,9 +537,14 @@ def generate_hydrogen_activities(self) -> None:
)

if initial_energy_use is None or initial_energy_use == 0:
print(
f"Initial energy consumption for {fuel_type} in {region} is None."
)
if "waste" not in fuel_type:
print(
f"Initial energy consumption for {fuel_type} in {region} is None."
)
print(f"List of exchanges:")
for exc in dataset["exchanges"]:
print(exc)
print()

# add it to "log parameters"
if "log parameters" not in dataset:
Expand Down Expand Up @@ -2257,14 +2260,21 @@ def generate_regional_fuel_market(
.interp(year=self.year)
.sum(dim=["variables"]),
0,
atol=1e-3,
rtol=1e-3,
):
if "hydrogen" in dataset["name"].lower():
prod_vars = [
"hydrogen, from natural gas",
]

if "natural gas" in dataset["name"].lower():
prod_vars = [
"natural gas",
]

sum_share = 0
shares = {}

for prod_var in prod_vars:
if len(prod_vars) > 1:
share = fuel_providers[prod_var]["find_share"](
Expand All @@ -2281,6 +2291,13 @@ def generate_regional_fuel_market(
if isinstance(share, np.ndarray):
share = share.item(0)

shares[prod_var] = share

# normalize shares
shares = {k: v / sum_share for k, v in shares.items()}

for prod_var, share in shares.items():

blacklist = [
"petroleum coke",
"petroleum gas",
Expand Down Expand Up @@ -2335,7 +2352,7 @@ def generate_regional_fuel_market(
# so that the overall composition maintains
# the same average LHV
amount = supplier_share * (
activity["lhv"] / self.fuels_specs[prod_var]["lhv"]
activity["lhv"] / self.fuels_specs[prod_var]["lhv"]
)

lhv = self.fuels_specs[prod_var]["lhv"]
Expand All @@ -2358,7 +2375,7 @@ def generate_regional_fuel_market(
if text not in string:
string += text

if not np.isclose(sum_share, 1.0, rtol=1e-3):
if not np.isclose(sum(e for e in shares.values()), 1.0, rtol=1e-3):
print(
f"WARNING: sum of shares for {dataset['name']} in {region} is {sum_share} instead of 1.0"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
remind: ES|Transport|VKM|Pass|Road|LDV|Medium|FCEV
tiam-ucl:
- Distance|Transport|Car|Hydrogen Fuel Cell|Car Hydrogen
- Distance|Transport|Car|Hydrogen Fuel Cell|Electricity
energy_use_aliases:
remind: FE|Transport|VKM|Pass|Road|LDV|Medium|FCEV
tiam-ucl:
Expand Down
7 changes: 4 additions & 3 deletions premise/transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,10 @@ def find_fuel_efficiency(
)
)
if energy_input == 0:
print(
f"Warning: {dataset['name'], dataset['location']} has no energy input"
)
if not any(x in dataset["name"] for x in ("waste", "treatment")):
print(
f"Warning: {dataset['name'], dataset['location']} has no energy input"
)

if energy_input != 0 and float(energy_out) != 0:
current_efficiency = float(energy_out) / energy_input
Expand Down
4 changes: 4 additions & 0 deletions tests/test_process_ei310_EN15804.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
scenarios = [
{"model": "remind", "pathway": "SSP2-Base", "year": 2050},
{"model": "image", "pathway": "SSP2-RCP19", "year": 2050},
{"model": "tiam-ucl", "pathway": "SSP2-RCP19", "year": 2050},
]


Expand Down Expand Up @@ -58,11 +59,14 @@ def test_brightway():
del bw2data.databases["test1"]
if "test2" in bw2data.databases:
del bw2data.databases["test2"]
if "test3" in bw2data.databases:
del bw2data.databases["test3"]

ndb.write_db_to_brightway(
[
"test1",
"test2",
"test3"
]
)

Expand Down
4 changes: 4 additions & 0 deletions tests/test_process_ei310_conseq.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
scenarios = [
{"model": "remind", "pathway": "SSP2-Base", "year": 2050},
{"model": "image", "pathway": "SSP2-RCP19", "year": 2050},
{"model": "tiam-ucl", "pathway": "SSP2-RCP19", "year": 2050},
]


Expand Down Expand Up @@ -59,11 +60,14 @@ def test_brightway():
del bw2data.databases["test1"]
if "test2" in bw2data.databases:
del bw2data.databases["test2"]
if "test3" in bw2data.databases:
del bw2data.databases["test3"]

ndb.write_db_to_brightway(
[
"test1",
"test2",
"test3"
]
)

Expand Down
4 changes: 4 additions & 0 deletions tests/test_process_ei310_cutoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
scenarios = [
{"model": "remind", "pathway": "SSP2-Base", "year": 2050},
{"model": "image", "pathway": "SSP2-RCP19", "year": 2050},
{"model": "tiam-ucl", "pathway": "SSP2-RCP19", "year": 2050},
]


Expand Down Expand Up @@ -54,11 +55,14 @@ def test_brightway():
del bw2data.databases["test1"]
if "test2" in bw2data.databases:
del bw2data.databases["test2"]
if "test3" in bw2data.databases:
del bw2data.databases["test3"]

ndb.write_db_to_brightway(
[
"test1",
"test2",
"test3"
]
)

Expand Down
1 change: 1 addition & 0 deletions tests/test_process_ei310_cutoff_datapackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
scenarios = [
{"model": "remind", "pathway": "SSP2-Base", "year": 2050},
{"model": "image", "pathway": "SSP2-RCP19", "year": 2050},
{"model": "tiam-ucl", "pathway": "SSP2-RCP19", "year": 2050},
]


Expand Down
1 change: 1 addition & 0 deletions tests/test_process_ei310_cutoff_olca.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
scenarios = [
{"model": "remind", "pathway": "SSP2-Base", "year": 2050},
{"model": "image", "pathway": "SSP2-RCP19", "year": 2050},
{"model": "tiam-ucl", "pathway": "SSP2-RCP19", "year": 2050},
]


Expand Down
1 change: 1 addition & 0 deletions tests/test_process_ei310_cutoff_simapro.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
scenarios = [
{"model": "remind", "pathway": "SSP2-Base", "year": 2050},
{"model": "image", "pathway": "SSP2-RCP19", "year": 2050},
{"model": "tiam-ucl", "pathway": "SSP2-RCP19", "year": 2050},
]


Expand Down
1 change: 1 addition & 0 deletions tests/test_process_ei310_cutoff_super.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
scenarios = [
{"model": "remind", "pathway": "SSP2-Base", "year": 2050},
{"model": "image", "pathway": "SSP2-RCP19", "year": 2050},
{"model": "tiam-ucl", "pathway": "SSP2-RCP19", "year": 2050},
]


Expand Down
4 changes: 4 additions & 0 deletions tests/test_process_ei38_conseq.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
scenarios = [
{"model": "remind", "pathway": "SSP2-Base", "year": 2050},
{"model": "image", "pathway": "SSP2-RCP19", "year": 2050},
{"model": "tiam-ucl", "pathway": "SSP2-RCP19", "year": 2050},
]


Expand Down Expand Up @@ -59,11 +60,14 @@ def test_brightway():
del bw2data.databases["test1"]
if "test2" in bw2data.databases:
del bw2data.databases["test2"]
if "test3" in bw2data.databases:
del bw2data.databases["test3"]

ndb.write_db_to_brightway(
[
"test1",
"test2",
"test3"
]
)

Expand Down
4 changes: 4 additions & 0 deletions tests/test_process_ei38_cutoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
scenarios = [
{"model": "remind", "pathway": "SSP2-Base", "year": 2050},
{"model": "image", "pathway": "SSP2-RCP19", "year": 2050},
{"model": "tiam-ucl", "pathway": "SSP2-RCP19", "year": 2050},
]


Expand Down Expand Up @@ -58,11 +59,14 @@ def test_brightway():
del bw2data.databases["test1"]
if "test2" in bw2data.databases:
del bw2data.databases["test2"]
if "test3" in bw2data.databases:
del bw2data.databases["test3"]

ndb.write_db_to_brightway(
[
"test1",
"test2",
"test3"
]
)

Expand Down
4 changes: 4 additions & 0 deletions tests/test_process_ei39_conseq.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
scenarios = [
{"model": "remind", "pathway": "SSP2-Base", "year": 2050},
{"model": "image", "pathway": "SSP2-RCP19", "year": 2050},
{"model": "tiam-ucl", "pathway": "SSP2-RCP19", "year": 2050},
]


Expand Down Expand Up @@ -59,11 +60,14 @@ def test_brightway():
del bw2data.databases["test1"]
if "test2" in bw2data.databases:
del bw2data.databases["test2"]
if "test3" in bw2data.databases:
del bw2data.databases["test3"]

ndb.write_db_to_brightway(
[
"test1",
"test2",
"test3"
]
)

Expand Down
4 changes: 4 additions & 0 deletions tests/test_process_ei39_cutoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
scenarios = [
{"model": "remind", "pathway": "SSP2-Base", "year": 2050},
{"model": "image", "pathway": "SSP2-RCP19", "year": 2050},
{"model": "tiam-ucl", "pathway": "SSP2-RCP19", "year": 2050},
]


Expand Down Expand Up @@ -58,11 +59,14 @@ def test_brightway():
del bw2data.databases["test1"]
if "test2" in bw2data.databases:
del bw2data.databases["test2"]
if "test3" in bw2data.databases:
del bw2data.databases["test3"]

ndb.write_db_to_brightway(
[
"test1",
"test2",
"test3"
]
)

Expand Down

0 comments on commit ecb1b0a

Please sign in to comment.