Skip to content

Commit

Permalink
feat(storage): improve the CreateSTStorage and RemoveSTStorage co…
Browse files Browse the repository at this point in the history
…mmands
  • Loading branch information
laurent-laporte-pro committed Jul 3, 2023
1 parent 9ee2f84 commit 4e416ba
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
FileStudyTreeConfig,
Link,
Simulation,
STStorage,
transform_name_to_id,
)
from antarest.study.storage.rawstudy.model.filesystem.config.st_storage import (
STStorageConfig,
)
from antarest.study.storage.rawstudy.model.filesystem.root.settings.generaldata import (
DUPLICATE_KEYS,
)
Expand Down Expand Up @@ -382,7 +384,7 @@ def _parse_thermal(root: Path, area: str) -> List[Cluster]:
]


def _parse_st_storage(root: Path, area: str) -> List[STStorage]:
def _parse_st_storage(root: Path, area: str) -> List[STStorageConfig]:
"""
Parse the short-term storage INI file, return an empty list if missing.
"""
Expand All @@ -392,7 +394,7 @@ def _parse_st_storage(root: Path, area: str) -> List[STStorage]:
file_type=FileType.SIMPLE_INI,
)
return [
STStorage(id=storage_id, name=values["name"])
STStorageConfig(**dict(values, id=storage_id))
for storage_id, values in config_dict.items()
]

Expand Down
13 changes: 3 additions & 10 deletions antarest/study/storage/rawstudy/model/filesystem/config/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from antarest.core.utils.utils import DTO
from pydantic.main import BaseModel

from .st_storage import STStorageConfig


class ENR_MODELLING(Enum):
AGGREGATED = "aggregated"
Expand All @@ -25,15 +27,6 @@ class Cluster(BaseModel):
enabled: bool = True


class STStorage(BaseModel):
"""
Short-term storage model used in Area creation
"""

id: str
name: str


class Link(BaseModel):
"""
Object linked to /input/links/<link>/properties.ini information
Expand Down Expand Up @@ -71,7 +64,7 @@ class Config:
filters_synthesis: List[str]
filters_year: List[str]
# since v8.6
st_storages: List[STStorage] = []
st_storages: List[STStorageConfig] = []


class DistrictSet(BaseModel):
Expand Down
111 changes: 111 additions & 0 deletions antarest/study/storage/rawstudy/model/filesystem/config/st_storage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
from typing import Dict, Any

from pydantic import BaseModel, Extra, Field, root_validator

from antarest.study.business.enum_ignore_case import EnumIgnoreCase


class STStorageGroup(EnumIgnoreCase):
"""
This class defines the specific energy storage systems.
Enum values:
- PSP_OPEN: Represents an open pumped storage plant.
- PSP_CLOSED: Represents a closed pumped storage plant.
- PONDAGE: Represents a pondage storage system (reservoir storage system).
- BATTERY: Represents a battery storage system.
- OTHER: Represents other energy storage systems.
"""

PSP_OPEN = "PSP_open"
PSP_CLOSED = "PSP_closed"
PONDAGE = "Pondage"
BATTERY = "Battery"
OTHER = "Other"


class STStorageConfig(BaseModel):
"""
Manage the configuration files in the context of Short-Term Storage.
It provides a convenient way to read and write configuration data from/to an INI file format.
"""

class Config:
extra = Extra.forbid
allow_population_by_field_name = True

id: str = Field(
description="Short-term storage ID",
regex=r"[a-z0-9_(),& -]+",
)
name: str = Field(
description="Short-term storage name",
regex=r"[a-zA-Z0-9_(),& -]+",
)
group: STStorageGroup = Field(
...,
description="Energy storage system group (mandatory)",
)
injection_nominal_capacity: float = Field(
0,
description="Injection nominal capacity (MW)",
ge=0,
alias="injectionnominalcapacity",
)
withdrawal_nominal_capacity: float = Field(
0,
description="Withdrawal nominal capacity (MW)",
ge=0,
alias="withdrawalnominalcapacity",
)
reservoir_capacity: float = Field(
0,
description="Reservoir capacity (MWh)",
ge=0,
alias="reservoircapacity",
)
efficiency: float = Field(
1,
description="Efficiency of the storage system",
ge=0,
le=1,
)
initial_level: float = Field(
0,
description="Initial level of the storage system",
ge=0,
alias="initiallevel",
)
initial_level_optim: bool = Field(
False,
description="Flag indicating if the initial level is optimized",
alias="initialleveloptim",
)

@root_validator(pre=True)
def calculate_storage_id(cls, values: Dict[str, Any]) -> Dict[str, Any]:
"""
Calculate the short-term storage ID based on the storage name, if not provided.
Args:
values: values used to construct the object.
Returns:
The updated values.
"""
# Avoid circular imports
from antarest.study.storage.rawstudy.model.filesystem.config.model import (
transform_name_to_id,
)

if values.get("id") or not values.get("name"):
return values
storage_name = values["name"]
if storage_id := transform_name_to_id(storage_name):
values["id"] = storage_id
else:
raise ValueError(
f"Invalid short term storage name '{storage_name}'."
)
return values
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def _revert_create_st_storage(
history: List["ICommand"],
base: FileStudy,
) -> List[ICommand]:
storage_id = base_command.storage_id
storage_id = base_command.parameters.id
return [
RemoveSTStorage(
area_id=base_command.area_id,
Expand Down
Loading

0 comments on commit 4e416ba

Please sign in to comment.