Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend application of defaults beyond FI_T tables #240

Merged
merged 27 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
71b8491
Move _populate_defaults out of apply_fixups
olejandro Nov 11, 2024
b3f5105
Create fill_defaults_in_transform_tables
olejandro Nov 11, 2024
3eea791
Include fill_defaults_in_transform_tables in __main__.py
olejandro Nov 11, 2024
eca92eb
Extend the list of transform tables
olejandro Nov 12, 2024
b4f75e9
Refactor some parts to expose the logic
olejandro Nov 12, 2024
a5dfea8
Merge branch 'main' into olex/extend-defaults
olejandro Nov 12, 2024
b0864dc
Explode other_indexes as well
olejandro Nov 14, 2024
1a20d34
Merge branch 'main' into olex/extend-defaults
olejandro Nov 15, 2024
66aece7
Move veda_cgs calculation to model property
olejandro Nov 15, 2024
aa6dc26
Extend _populate_calculated_defaults to tfm tables
olejandro Nov 15, 2024
ab05a4d
Move things around
olejandro Nov 15, 2024
ea6f02f
Move things around again
olejandro Nov 16, 2024
1006245
Clean-up
olejandro Nov 16, 2024
b14fbbe
Make minor fixes
olejandro Nov 17, 2024
64b1240
Merge branch 'main' into olex/extend-defaults
siddharth-krishna Nov 19, 2024
5e9db3e
Merge branch 'main' into olex/extend-defaults
olejandro Nov 22, 2024
9829090
Merge branch 'main' into olex/extend-defaults
olejandro Nov 25, 2024
64e3c25
Merge branch 'main' into olex/extend-defaults
olejandro Nov 25, 2024
59a0eec
Eliminate additional rows
olejandro Nov 25, 2024
aea2790
Convert to string with a fixed float precision
siddharth-krishna Nov 29, 2024
4ebadce
Merge branch 'main' into olex/extend-defaults
olejandro Dec 7, 2024
7abfa93
Merge branch 'main' into olex/extend-defaults
olejandro Dec 14, 2024
ca46410
Fix naming post merge
olejandro Dec 14, 2024
76a30ad
Query on limtype
olejandro Dec 14, 2024
321aebd
Merge branch 'main' into olex/extend-defaults
olejandro Dec 14, 2024
85c82ca
Address review comments
olejandro Dec 17, 2024
691359e
Move around a comment
olejandro Dec 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
15 changes: 15 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,20 @@ def model_years(self) -> set[int]:
"""
return self.past_years | set(self.time_periods["m"].values)

@cached_property
def veda_cgs(self) -> dict[tuple[str, str, str], str]:
"""veda_cgs is a dictionary mapping commodities to their Veda commodity groups."""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""veda_cgs is a dictionary mapping commodities to their Veda commodity groups."""
"""A dictionary mapping commodities to their Veda commodity groups."""

Just double checking: we don't expect this value to change when other properties/fields of the dataclass changes? Maybe we should add a TODO to check when this cached property is invalidated and have a way to clear the cache / recompute this. I'm wondering if that will be useful once we allow people to work with TimesModel objects directly in e.g. Jupyter Notebooks?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a good idea!

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
Loading