-
Notifications
You must be signed in to change notification settings - Fork 58
Collect water module settings into Config dataclass #509
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
Merged
Wegatriespython
merged 6 commits into
iiasa:main
from
Wegatriespython:wr/pr-c-water-config
May 26, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5052ae2
Introduce water Config dataclass for context.water
Wegatriespython 0c447e6
Preserve stored Context values on None CLI option overwrites
Wegatriespython 29f8746
Remove legacy water Config context bridge
Wegatriespython 3a18720
Update whatsnew
Wegatriespython 907295b
Update docstring
Wegatriespython 6110b41
Add type hint for test
Wegatriespython File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| from .config import Config | ||
| from .data import demands, water_supply | ||
| from .utils import read_config | ||
|
|
||
| __all__ = ["demands", "read_config", "water_supply"] | ||
| __all__ = ["Config", "demands", "read_config", "water_supply"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| from dataclasses import dataclass, field | ||
| from typing import TYPE_CHECKING, Any, Literal | ||
|
|
||
| from message_ix_models.util.config import ConfigHelper | ||
|
|
||
| if TYPE_CHECKING: | ||
| from message_ix_models import Context | ||
|
|
||
|
|
||
| @dataclass | ||
| class Config(ConfigHelper): | ||
| """Settings for :mod:`message_ix_models.model.water`.""" | ||
|
|
||
| #: Water build variant. | ||
| nexus_set: Literal["cooling", "nexus"] = "nexus" | ||
|
|
||
| #: Climate scenario used for water availability and cooling data. | ||
| RCP: str = "no_climate" | ||
|
|
||
| #: Water SDG policy setting. | ||
| SDG: str = "baseline" | ||
|
|
||
| #: Hydrological-data reliability setting. | ||
| REL: str = "low" | ||
|
|
||
| #: Time slices handled by the water module. | ||
| time: list[str] = field(default_factory=lambda: ["year"]) | ||
|
|
||
| #: Whether :attr:`regions` names a global node codelist or a single country. | ||
| type_reg: Literal["country", "global"] = "global" | ||
|
|
||
| #: Single-country model mapping from region code to ISO code. | ||
| map_ISO_c: dict[str, str] = field(default_factory=dict) | ||
|
|
||
| #: Enable basin filtering. | ||
| reduced_basin: bool = False | ||
|
|
||
| #: Basins to add to the automatic reduced-basin selection. | ||
| filter_list: list[str] = field(default_factory=list) | ||
|
|
||
| #: Number of basins per region to keep when :attr:`reduced_basin` is enabled. | ||
| num_basins: int | None = None | ||
|
|
||
| #: Automatic reduced-basin selection method. | ||
| basin_selection: Literal["first_k", "stress"] = "first_k" | ||
|
|
||
| #: Basin names retained after optional filtering. | ||
| valid_basins: set[str] = field(default_factory=set) | ||
|
|
||
| #: Water-module basin node labels, populated during structural mapping. | ||
| all_nodes: Any = None | ||
|
|
||
| @classmethod | ||
| def from_context(cls, context: "Context") -> "Config": | ||
| """Return the shared water configuration for `context`. | ||
|
|
||
| Create `context.water` if missing, or convert a mapping to `Config`. | ||
| Repeated calls return the same `Config` instance. | ||
| """ | ||
| if "water" not in context: | ||
| context["water"] = cls() | ||
| elif isinstance(context["water"], dict): | ||
| context["water"] = cls.from_dict(context["water"]) | ||
|
|
||
| return context["water"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great for now. In some cases it might make sense, in the future, to add an Enum, which can also help to sanitize user input: