Skip to content

Commit

Permalink
[FIX] list.ini created when creating area for thermal/clusters (#64)
Browse files Browse the repository at this point in the history
chore(release)v:0.1.8_RC2
  • Loading branch information
vargastat authored Jan 27, 2025
1 parent 5d0cadd commit 27bf65e
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 13 deletions.
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10.12
8 changes: 8 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
v0.1.8_RC2 (2025-01-22)
-------------------
- upload renewable thermal matrices method added
- bug fix clusters/{area}/list.ini file was missing
- bug fix for input/thermal/series/{area}/{cluster}/series.txt /data.txt and modulation.txt, wrong path
at cluster creation


v0.1.8_RC1 (2025-01-22)
-------------------

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "antares_craft"
version = "0.1.8_RC1"
version = "0.1.8_RC2"
description = """Antares Craft python library under construction. It will allow to create, update and read antares studies."""
readme = "CONCATENATED_README.md"
license = {file = "LICENSE"}
Expand Down
14 changes: 11 additions & 3 deletions src/antares/craft/service/local_services/area_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,16 @@ def create_thermal_cluster(
local_thermal_properties = ThermalClusterPropertiesLocal.model_validate(args)

list_ini = IniFile(self.config.study_path, InitializationFilesTypes.THERMAL_LIST_INI, area_id=area_id)
IniFile(self.config.study_path, InitializationFilesTypes.THERMAL_PREPRO_MODULATION, area_id=area_id)
IniFile(self.config.study_path, InitializationFilesTypes.THERMAL_PREPRO_DATA, area_id=area_id)
IniFile(self.config.study_path, InitializationFilesTypes.THERMAL_SERIES, area_id=area_id)
IniFile(
self.config.study_path,
InitializationFilesTypes.THERMAL_MODULATION,
area_id=area_id,
cluster_id=thermal_name,
)
IniFile(self.config.study_path, InitializationFilesTypes.THERMAL_DATA, area_id=area_id, cluster_id=thermal_name)
IniFile(
self.config.study_path, InitializationFilesTypes.THERMAL_SERIES, area_id=area_id, cluster_id=thermal_name
)
try:
list_ini.add_section(local_thermal_properties.list_ini_fields)
except DuplicateSectionError:
Expand Down Expand Up @@ -304,6 +311,7 @@ def _line_exists_in_file(file_content: str, line_to_add: str) -> bool:
self.create_solar(area_name, empty_df)
self.create_wind(area_name, empty_df)
IniFile.create_link_ini_for_area(self.config.study_path, area_name)
IniFile.create_list_ini_for_area(self.config.study_path, area_name)

except Exception as e:
raise AreaCreationError(area_name, f"{e}") from e
Expand Down
15 changes: 11 additions & 4 deletions src/antares/craft/tools/ini_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ class InitializationFilesTypes(Enum):

THERMAL_AREAS_INI = "input/thermal/areas.ini"
THERMAL_LIST_INI = "input/thermal/clusters/{area_id}/list.ini"
THERMAL_PREPRO_MODULATION = "input/thermal/prepro/{area_id}/cluster/modulation.txt"
THERMAL_PREPRO_DATA = "input/thermal/prepro/{area_id}/cluster/data.txt"
THERMAL_SERIES = "input/thermal/series/{area_id}/cluster/series.txt"
THERMAL_MODULATION = "input/thermal/prepro/{area_id}/{cluster_id}/modulation.txt"
THERMAL_DATA = "input/thermal/prepro/{area_id}/{cluster_id}/data.txt"
THERMAL_SERIES = "input/thermal/series/{area_id}/{cluster_id}/series.txt"

WIND_CORRELATION_INI = "input/wind/prepro/correlation.ini"
WIND_SETTINGS_INI = "input/wind/prepro/{area_id}/settings.ini"
Expand All @@ -74,12 +74,13 @@ def __init__(
study_path: Path,
ini_file_type: InitializationFilesTypes,
area_id: Optional[str] = None,
cluster_id: Optional[str] = None,
ini_contents: Union[CustomRawConfigParser, dict[str, dict[str, str]], None] = None,
) -> None:
if "{area_id}" in ini_file_type.value and not area_id:
raise ValueError(f"Area name not provided, ini type {ini_file_type.name} requires 'area_id'")
self._full_path = study_path / (
ini_file_type.value.format(area_id=area_id)
ini_file_type.value.format(area_id=area_id, cluster_id=cluster_id)
if ("{area_id}" in ini_file_type.value and area_id)
else ini_file_type.value
)
Expand Down Expand Up @@ -220,6 +221,12 @@ def create_link_ini_for_area(cls, study_path: Path, area_id: str) -> None:

cls(study_path=study_path, ini_file_type=property_file, area_id=area_id)

@classmethod
def create_list_ini_for_area(cls, study_path: Path, area_id: str) -> None:
property_file = InitializationFilesTypes.THERMAL_LIST_INI

cls(study_path=study_path, ini_file_type=property_file, area_id=area_id)


def merge_dicts_for_ini(dict_a: dict[str, Any], dict_b: dict[str, Any]) -> dict:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,15 @@ def test_clusters_are_alphabetical_in_list_ini(
def test_create_thermal_initialization_files(self, local_study_w_areas):
study_path = Path(local_study_w_areas.path)
areas = local_study_w_areas.get_areas()

cluster_id = "cluster_test"
for area_id, area in areas.items():
area.create_thermal_cluster("cluster_test")
area.create_thermal_cluster(cluster_id)

for area_id in areas.keys():
expected_paths = [
study_path / f"input/thermal/prepro/{area_id}/cluster/modulation.txt",
study_path / f"input/thermal/prepro/{area_id}/cluster/data.txt",
study_path / f"input/thermal/series/{area_id}/cluster/series.txt",
study_path / f"input/thermal/prepro/{area_id}/{cluster_id}/modulation.txt",
study_path / f"input/thermal/prepro/{area_id}/{cluster_id}/data.txt",
study_path / f"input/thermal/series/{area_id}/{cluster_id}/series.txt",
]

for expected_path in expected_paths:
Expand Down
1 change: 1 addition & 0 deletions tests/antares/services/local_services/test_study.py
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,7 @@ def test_initialization_when_creating_area(self, tmp_path, local_study):
study_path / f"input/load/series/load_{area_id}.txt",
study_path / f"input/solar/series/solar_{area_id}.txt",
study_path / f"input/wind/series/wind_{area_id}.txt",
study_path / f"input/thermal/clusters/{area_id}/list.ini",
]

for expected_path in expected_paths:
Expand Down

0 comments on commit 27bf65e

Please sign in to comment.