Skip to content

Commit

Permalink
Add .tools.costs.config.Config dataclass
Browse files Browse the repository at this point in the history
Also cherry-pick 80464da
to satisfy mypy.
  • Loading branch information
khaeru committed Oct 25, 2023
1 parent 160a6e4 commit b7321ed
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
53 changes: 53 additions & 0 deletions message_ix_models/tools/costs/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from dataclasses import dataclass
from typing import Literal, Optional

BASE_YEAR = 2021
ADJ_BASE_YEAR = 2020
FIRST_MODEL_YEAR = 2020
Expand All @@ -11,3 +14,53 @@
# Conversion rate from 2021 USD to 2005 USD
# Taken from https://www.officialdata.org/us/inflation/2021?endYear=2005&amount=1
CONVERSION_2021_TO_2005_USD = 0.72


@dataclass
class Config:
"""Configuration for :mod:`.costs`."""

#: Base year for projections.
base_year: int = BASE_YEAR

#: Year of convergence; used when :attr:`.method` is "convergence". See
#: :func:`.create_projections_converge`.
convergence_year: int = 2050

#: Rate of increase/decrease of fixed operating and maintenance costs.
fom_rate: float = 0.025

#: Format of output. One of:
#:
#: - "iamc": IAMC time series data structure.
#: - "message": :mod:`message_ix` parameter data.
format: Literal["iamc", "message"] = "message"

#: Spatial resolution
node: Literal["R11", "R12", "R20"] = "R12"

#: Projection method; one of:
#:
#: - "convergence": uses :func:`.create_projections_converge`
#: - "gdp": :func:`.create_projections_gdp`
#: - "learning": :func:`.create_projections_converge`
method: Literal["convergence", "gdp", "learning"] = "gdp"

#: Model variant to prepare data for.
module: Literal["base", "materials"] = "base"

#: Reference region; default "{node}_NAM".
ref_region: Optional[str] = None

#: Set of SSPs referenced by :attr:`scenario`. One of:
#:
#: - "original": :obj:`SSP_2017`
#: - "updated": :obj:`SSP_2024`
scenario_version: Literal["original", "updated"] = "updated"

#: Scenario(s) for which to create data.
scenario: Literal["all", "LED", "SSP1", "SSP2", "SSP3", "SSP4", "SSP5"] = "all"

def __post_init__(self):
if self.ref_region is None:
self.ref_region = f"{self.node}_NAM"

Check warning on line 66 in message_ix_models/tools/costs/config.py

View check run for this annotation

Codecov / codecov/patch

message_ix_models/tools/costs/config.py#L65-L66

Added lines #L65 - L66 were not covered by tests
4 changes: 3 additions & 1 deletion message_ix_models/util/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ def read_file(self, path: Path, fail="raise") -> None:
# Use name manipulation on the attribute value also
value = existing.replace(**value)
elif not isinstance(existing, type):
value = replace(existing, **value)
# https://github.com/python/mypy/issues/15843
# TODO Check that fix is available in mypy 1.7.x; remove
value = replace(existing, **value) # type: ignore [misc]
setattr(self, key, value)

def replace(self, **kwargs):
Expand Down

0 comments on commit b7321ed

Please sign in to comment.