Skip to content

Commit

Permalink
Merge branch 'main' into olex/misc
Browse files Browse the repository at this point in the history
  • Loading branch information
olejandro authored Dec 17, 2024
2 parents 0d202cb + 2272b9c commit ace3a10
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 100 deletions.
2 changes: 1 addition & 1 deletion xl2times/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ def convert_xl_to_times(
transforms.process_units,
transforms.complete_commodity_groups,
transforms.process_wildcards,
transforms.convert_aliases,
transforms.apply_transform_tables,
transforms.explode_process_commodity_cols,
transforms.apply_final_fixup,
transforms.convert_aliases,
transforms.assign_model_attributes,
transforms.fix_topology,
transforms.resolve_remaining_cgs,
Expand Down
16 changes: 16 additions & 0 deletions xl2times/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from collections.abc import Iterable
from dataclasses import dataclass, field
from enum import Enum
from functools import cached_property
from importlib import resources
from itertools import chain
from pathlib import PurePath
Expand Down Expand Up @@ -266,6 +267,21 @@ def model_years(self) -> set[int]:
"""
return self.past_years | set(self.time_periods["m"].values)

# TODO: Invalidate and recompute the below property when self.topology changes.
@cached_property
def veda_cgs(self) -> dict[tuple[str, str, str], str]:
"""A dictionary mapping commodities to their Veda commodity groups."""
cols = ["region", "process", "commodity", "csets"]
# Exclude auxillary flows
index = self.topology["io"].isin({"IN", "OUT"})
veda_cgs = self.topology[cols + ["io"]][index].copy()
veda_cgs.drop_duplicates(subset=cols, keep="last", inplace=True)
veda_cgs["veda_cg"] = veda_cgs["csets"] + veda_cgs["io"].str[:1]
veda_cgs = veda_cgs.set_index(["region", "process", "commodity"])[
"veda_cg"
].to_dict()
return veda_cgs


class Config:
"""Encapsulates all configuration options for a run of the tool, including the
Expand Down
Loading

0 comments on commit ace3a10

Please sign in to comment.