Skip to content

Commit

Permalink
Align wrt to Materials
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Nov 6, 2023
1 parent 7dca24c commit 359e1c2
Show file tree
Hide file tree
Showing 37 changed files with 48,902 additions and 1,063 deletions.
4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ include premise/data/fuels/*.txt
include premise/data/fuels/*.csv
include premise/data/fuels/*.yml
include premise/data/fuels/*.yaml
include premise/data/metals/*.txt
include premise/data/metals/*.csv
include premise/data/metals/*.yml
include premise/data/metals/*.yaml
include premise/data/transport/*.yaml
include premise/data/GAINS_emission_factors/*.csv
include premise/data/GAINS_emission_factors/*.yaml
Expand Down
26 changes: 26 additions & 0 deletions premise/activity_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@

POWERPLANT_TECHS = VARIABLES_DIR / "electricity_variables.yaml"
FUELS_TECHS = VARIABLES_DIR / "fuels_variables.yaml"
METALS_TECHS = DATA_DIR / "metals" / "activities_mapping.yml"
MATERIALS_TECHS = DATA_DIR / "utils" / "materials_vars.yml"
DAC_TECHS = VARIABLES_DIR / "direct_air_capture_variables.yaml"
CARBON_STORAGE_TECHS = VARIABLES_DIR / "carbon_storage_variables.yaml"
CEMENT_TECHS = VARIABLES_DIR / "cement_variables.yaml"
GAINS_MAPPING = (
DATA_DIR / "GAINS_emission_factors" / "gains_ecoinvent_sectoral_mapping.yaml"
)
ACTIVITIES_METALS_MAPPING = DATA_DIR / "metals" / "activities_mapping.yml"
# METALS_MAPPING = DATA_DIR / "metals" / "metals_mapping.yml"


def get_mapping(filepath: Path, var: str, model: str = None) -> dict:
Expand Down Expand Up @@ -154,6 +157,21 @@ def __init__(
filepath=GAINS_MAPPING, var="ecoinvent_aliases"
)

self.activity_metals_filters = get_mapping(
filepath=ACTIVITIES_METALS_MAPPING, var="ecoinvent_aliases"
)
# self.metals_filters = get_mapping(
# filepath=METALS_MAPPING, var="ecoinvent_aliases"
# )

def generate_activities_using_metals_map(self) -> dict:
"""
Filter ecoinvent processes related to metals.
Returns a dictionary with metal names as keys (see below) and
a set of related ecoinvent activities' names as values.
"""
return self.generate_sets_from_filters(self.activity_metals_filters)

def generate_gains_mapping_IAM(self, mapping):
EU_to_IAM_var = get_mapping(filepath=GAINS_MAPPING, var="gains_aliases_IAM")
new_map = defaultdict(set)
Expand Down Expand Up @@ -243,6 +261,14 @@ def generate_material_map(self) -> dict:
"""
return self.generate_sets_from_filters(self.materials_filters)

def generate_metals_activities_map(self) -> dict:
"""
Filter ecoinvent processes related to metals.
Rerurns a dictionary with material names as keys (see below) and
a set of related ecoinvent activities' names as values.
"""
return self.generate_sets_from_filters(self.activity_metals_filters)

def generate_sets_from_filters(self, filtr: dict, database=None) -> dict:
"""
Generate a dictionary with sets of activity names for
Expand Down
54 changes: 8 additions & 46 deletions premise/cement.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
logger = create_logger("cement")


def _update_cement(scenario, version, system_model, modified_datasets, cache=None):
def _update_cement(scenario, version, system_model, cache=None):
cement = Cement(
database=scenario["database"],
model=scenario["model"],
Expand All @@ -25,19 +25,19 @@ def _update_cement(scenario, version, system_model, modified_datasets, cache=Non
year=scenario["year"],
version=version,
system_model=system_model,
modified_datasets=modified_datasets,
cache=cache,
)

if scenario["iam data"].cement_markets is not None:
cement.add_datasets_to_database()
scenario["database"] = cement.database
modified_datasets = cement.modified_datasets
cache = cement.cache
else:
print("No cement markets found in IAM data. Skipping.")

return scenario, modified_datasets, cache
cement.relink_datasets()

return scenario, cache


class Cement(BaseTransformation):
Expand Down Expand Up @@ -70,7 +70,6 @@ def __init__(
year: int,
version: str,
system_model: str,
modified_datasets: dict,
cache: dict = None,
):
super().__init__(
Expand All @@ -81,7 +80,6 @@ def __init__(
year,
version,
system_model,
modified_datasets,
cache,
)
self.version = version
Expand Down Expand Up @@ -474,16 +472,7 @@ def add_datasets_to_database(self) -> None:
for new_dataset in clinker_prod_datasets:
self.write_log(new_dataset)
# add it to list of created datasets
self.modified_datasets[(self.model, self.scenario, self.year)][
"created"
].append(
(
new_dataset["name"],
new_dataset["reference product"],
new_dataset["location"],
new_dataset["unit"],
)
)
self.add_to_index(new_dataset)

# print("Create new clinker market datasets and delete old datasets")
clinker_market_datasets = list(
Expand All @@ -500,16 +489,7 @@ def add_datasets_to_database(self) -> None:
for new_dataset in clinker_market_datasets:
self.write_log(new_dataset)
# add it to list of created datasets
self.modified_datasets[(self.model, self.scenario, self.year)][
"created"
].append(
(
new_dataset["name"],
new_dataset["reference product"],
new_dataset["location"],
new_dataset["unit"],
)
)
self.add_to_index(new_dataset)

# print("Create new cement market datasets")

Expand Down Expand Up @@ -537,16 +517,7 @@ def add_datasets_to_database(self) -> None:
for new_dataset in list(new_cement_markets.values()):
self.write_log(new_dataset)
# add it to list of created datasets
self.modified_datasets[(self.model, self.scenario, self.year)][
"created"
].append(
(
new_dataset["name"],
new_dataset["reference product"],
new_dataset["location"],
new_dataset["unit"],
)
)
self.add_to_index(new_dataset)

new_datasets.extend(list(new_cement_markets.values()))

Expand Down Expand Up @@ -581,16 +552,7 @@ def add_datasets_to_database(self) -> None:
for new_dataset in list(new_cement_production.values()):
self.write_log(dataset=new_dataset, status="updated")
# add it to list of created datasets
self.modified_datasets[(self.model, self.scenario, self.year)][
"created"
].append(
(
new_dataset["name"],
new_dataset["reference product"],
new_dataset["location"],
new_dataset["unit"],
)
)
self.add_to_index(new_dataset)

new_datasets.extend(list(new_cement_production.values()))

Expand Down
Binary file added premise/data/additional_inventories/lci-PGM.xlsx
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added premise/data/metals/BGS_mapping.xlsx
Binary file not shown.
Binary file added premise/data/metals/activities_mapping.xlsx
Binary file not shown.
Loading

0 comments on commit 359e1c2

Please sign in to comment.