-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
262 additions
and
165 deletions.
There are no files selected for viewing
This file contains 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 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 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,53 @@ | ||
# Copyright (c) 2024, RTE (https://www.rte-france.com) | ||
# | ||
# See AUTHORS.txt | ||
# | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# | ||
# SPDX-License-Identifier: MPL-2.0 | ||
# | ||
# This file is part of the Antares project. | ||
from dataclasses import asdict | ||
from typing import Union | ||
|
||
from antares.craft.model.area import AdequacyPatchMode, AreaProperties, AreaPropertiesUpdate | ||
from antares.craft.model.commons import FilterOption | ||
from antares.craft.service.api_services.models.base_model import APIBaseModel | ||
from antares.craft.tools.all_optional_meta import all_optional_model | ||
|
||
AreaPropertiesType = Union[AreaProperties, AreaPropertiesUpdate] | ||
|
||
|
||
@all_optional_model | ||
class AreaPropertiesAPI(APIBaseModel): | ||
energy_cost_unsupplied: float | ||
energy_cost_spilled: float | ||
non_dispatch_power: bool | ||
dispatch_hydro_power: bool | ||
other_dispatch_power: bool | ||
filter_synthesis: set[FilterOption] | ||
filter_by_year: set[FilterOption] | ||
adequacy_patch_mode: AdequacyPatchMode | ||
spread_unsupplied_energy_cost: float | ||
spread_spilled_energy_cost: float | ||
|
||
@staticmethod | ||
def from_user_model(user_class: AreaPropertiesType) -> "AreaPropertiesAPI": | ||
user_dict = asdict(user_class) | ||
return AreaPropertiesAPI.model_validate(user_dict) | ||
|
||
def to_user_model(self) -> AreaProperties: | ||
return AreaProperties( | ||
energy_cost_unsupplied=self.energy_cost_spilled, | ||
energy_cost_spilled=self.energy_cost_spilled, | ||
non_dispatch_power=self.non_dispatch_power, | ||
dispatch_hydro_power=self.dispatch_hydro_power, | ||
other_dispatch_power=self.other_dispatch_power, | ||
filter_synthesis=self.filter_synthesis, | ||
filter_by_year=self.filter_by_year, | ||
adequacy_patch_mode=self.adequacy_patch_mode, | ||
spread_unsupplied_energy_cost=self.spread_unsupplied_energy_cost, | ||
spread_spilled_energy_cost=self.spread_spilled_energy_cost, | ||
) |
This file contains 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 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 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
100 changes: 100 additions & 0 deletions
100
src/antares/craft/service/local_services/models/area.py
This file contains 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,100 @@ | ||
# Copyright (c) 2024, RTE (https://www.rte-france.com) | ||
# | ||
# See AUTHORS.txt | ||
# | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# | ||
# SPDX-License-Identifier: MPL-2.0 | ||
# | ||
# This file is part of the Antares project. | ||
|
||
from typing import Any, Union | ||
|
||
from antares.craft.model.area import AdequacyPatchMode, AreaProperties, AreaPropertiesUpdate, default_filtering | ||
from antares.craft.model.commons import FilterOption | ||
from antares.craft.service.local_services.models.base_model import LocalBaseModel | ||
from antares.craft.tools.alias_generators import to_kebab | ||
from pydantic import Field, field_validator | ||
|
||
AreaPropertiesType = Union[AreaProperties, AreaPropertiesUpdate] | ||
|
||
|
||
class OptimizationPropertiesLocal(LocalBaseModel, alias_generator=to_kebab): | ||
non_dispatchable_power: bool = True | ||
dispatchable_hydro_power: bool = True | ||
other_dispatchable_power: bool = True | ||
spread_unsupplied_energy_cost: float = 0.0 | ||
spread_spilled_energy_cost: float = 0.0 | ||
|
||
|
||
class FilteringPropertiesLocal(LocalBaseModel, alias_generator=to_kebab): | ||
filter_synthesis: set[FilterOption] = Field(default_factory=default_filtering) | ||
filter_year_by_year: set[FilterOption] = Field(default_factory=default_filtering) | ||
|
||
@field_validator("filter_synthesis", "filter_year_by_year", mode="before") | ||
def validate_accuracy_on_correlation(cls, v: Any) -> set[str]: | ||
if isinstance(v, (list, set)): | ||
return set(v) | ||
if isinstance(v, str): | ||
if v[0] == "[": | ||
v = v[1:-1] | ||
return set(v.replace(" ", "").split(",")) | ||
raise ValueError(f"Value {v} not supported for filtering") | ||
|
||
|
||
class AdequacyPatchPropertiesLocal(LocalBaseModel, alias_generator=to_kebab): | ||
adequacy_patch_mode: AdequacyPatchMode = AdequacyPatchMode.OUTSIDE | ||
|
||
|
||
class AreaPropertiesLocal(LocalBaseModel): | ||
nodal_optimization: OptimizationPropertiesLocal = Field(alias="nodal optimization") | ||
filtering: FilteringPropertiesLocal | ||
adequacy_patch: AdequacyPatchPropertiesLocal = Field(alias="adequacy-patch") | ||
energy_cost_unsupplied: float = 0.0 | ||
energy_cost_spilled: float = 0.0 | ||
|
||
@staticmethod | ||
def from_user_model(user_class: AreaPropertiesType) -> "AreaPropertiesLocal": | ||
args = { | ||
"adequacy_patch": {"adequacy_patch_mode": user_class.adequacy_patch_mode}, | ||
"filtering": { | ||
"filter_synthesis": user_class.filter_synthesis, | ||
"filter_year_by_year": user_class.filter_by_year, | ||
}, | ||
"nodal_optimization": { | ||
"non_dispatchable_power": user_class.non_dispatch_power, | ||
"dispatchable_hydro_power": user_class.dispatch_hydro_power, | ||
"other_dispatchable_power": user_class.other_dispatch_power, | ||
"spread_unsupplied_energy_cost": user_class.spread_unsupplied_energy_cost, | ||
"spread_spilled_energy_cost": user_class.spread_spilled_energy_cost, | ||
}, | ||
"energy_cost_unsupplied": user_class.energy_cost_unsupplied, | ||
"energy_cost_spilled": user_class.energy_cost_spilled, | ||
} | ||
|
||
return AreaPropertiesLocal.model_validate(args) | ||
|
||
def to_user_model(self) -> AreaProperties: | ||
return AreaProperties( | ||
energy_cost_unsupplied=self.energy_cost_unsupplied, | ||
energy_cost_spilled=self.energy_cost_spilled, | ||
non_dispatch_power=self.nodal_optimization.non_dispatchable_power, | ||
dispatch_hydro_power=self.nodal_optimization.dispatchable_hydro_power, | ||
other_dispatch_power=self.nodal_optimization.other_dispatchable_power, | ||
filter_synthesis=self.filtering.filter_synthesis, | ||
filter_by_year=self.filtering.filter_year_by_year, | ||
adequacy_patch_mode=self.adequacy_patch.adequacy_patch_mode, | ||
spread_unsupplied_energy_cost=self.nodal_optimization.spread_unsupplied_energy_cost, | ||
spread_spilled_energy_cost=self.nodal_optimization.spread_spilled_energy_cost, | ||
) | ||
|
||
def to_adequacy_ini(self) -> dict[str, dict[str, str]]: | ||
return self.model_dump(mode="json", include={"adequacy_patch"}, by_alias=True) | ||
|
||
def to_optimization_ini(self) -> dict[str, dict[str, str]]: | ||
args = self.model_dump(mode="json", include={"nodal_optimization", "filtering"}, by_alias=True) | ||
args["filtering"]["filter-synthesis"] = ", ".join(sorted(args["filtering"]["filter-synthesis"])) | ||
args["filtering"]["filter-year-by-year"] = ", ".join(sorted(args["filtering"]["filter-year-by-year"])) | ||
return args |
Oops, something went wrong.