diff --git a/src/antares/model/solar.py b/src/antares/model/solar.py index 57aca133..96e2ace8 100644 --- a/src/antares/model/solar.py +++ b/src/antares/model/solar.py @@ -9,10 +9,20 @@ # SPDX-License-Identifier: MPL-2.0 # # This file is part of the Antares project. +from pathlib import Path +from typing import Any, Optional - +from antares.tools.ini_tool import IniFile, IniFileTypes from antares.tools.time_series_tool import TimeSeries class Solar(TimeSeries): - pass + def __init__( + self, + *, + study_path: Optional[Path] = None, + **kwargs: Any, + ) -> None: + super().__init__(**kwargs) + if study_path is not None: + self.correlation = IniFile(study_path, IniFileTypes.SOLAR_CORRELATION_INI) diff --git a/src/antares/service/api_services/area_api.py b/src/antares/service/api_services/area_api.py index 5a846ca0..4ff44cf8 100644 --- a/src/antares/service/api_services/area_api.py +++ b/src/antares/service/api_services/area_api.py @@ -382,7 +382,7 @@ def create_solar(self, area: Area, series: Optional[pd.DataFrame]) -> Solar: series = series if series is not None else pd.DataFrame([]) series_path = f"input/solar/series/solar_{area.id}" self._upload_series(area, series, series_path) - return Solar(series) + return Solar(time_series=series) def create_misc_gen(self, area: Area, series: Optional[pd.DataFrame]) -> MiscGen: series = series if series is not None else pd.DataFrame([]) diff --git a/src/antares/service/local_services/area_local.py b/src/antares/service/local_services/area_local.py index a43d743c..3b1623e0 100644 --- a/src/antares/service/local_services/area_local.py +++ b/src/antares/service/local_services/area_local.py @@ -145,7 +145,7 @@ def create_reserves(self, area: Area, series: Optional[pd.DataFrame]) -> Reserve def create_solar(self, area: Area, series: Optional[pd.DataFrame]) -> Solar: series = series if series is not None else pd.DataFrame([]) local_file = TimeSeriesFile(TimeSeriesFileType.SOLAR, self.config.study_path, area.id, series) - return Solar(series, local_file) + return Solar(time_series=series, local_file=local_file, study_path=self.config.study_path) def create_misc_gen(self, area: Area, series: Optional[pd.DataFrame]) -> MiscGen: series = series if series is not None else pd.DataFrame([]) diff --git a/src/antares/tools/ini_tool.py b/src/antares/tools/ini_tool.py index 78991f7d..985253da 100644 --- a/src/antares/tools/ini_tool.py +++ b/src/antares/tools/ini_tool.py @@ -35,6 +35,7 @@ class IniFileTypes(Enum): HYDRO_INI = "input/hydro/hydro.ini" LINK_PROPERTIES_INI = "input/links/{area_name}/properties.ini" RENEWABLES_LIST_INI = "input/renewables/clusters/{area_name}/list.ini" + SOLAR_CORRELATION_INI = "input/solar/prepro/correlation.ini" ST_STORAGE_LIST_INI = "input/st-storage/clusters/{area_name}/list.ini" THERMAL_AREAS_INI = "input/thermal/areas.ini" THERMAL_LIST_INI = "input/thermal/clusters/{area_name}/list.ini" diff --git a/src/antares/tools/time_series_tool.py b/src/antares/tools/time_series_tool.py index ea2ebb9c..42e28fa0 100644 --- a/src/antares/tools/time_series_tool.py +++ b/src/antares/tools/time_series_tool.py @@ -19,11 +19,16 @@ class TimeSeriesFileType(Enum): """ - The relative paths to different timeseries files used in the generation of an Antares study, starting from the - base folder of the study. + DTO for storing the paths to Antares time series files. - Files where the path contains {area_id} have to be used with .format(area_id=) where is the id - in question to access the correct path. + This DTO contains the relative paths to different timeseries files used in the generation of an Antares study, + starting from the base folder of the study. + + Files where the path contains {area_id} have to be used with .format(area_id=) where is replaced + with the area's id to access the correct path. + + Example: + TimeSeriesFileType.SOLAR.value.format(area_id="test_area") """ MISC_GEN = "input/misc-gen/miscgen-{area_id}.txt" @@ -87,6 +92,10 @@ def _write_file(self) -> None: class TimeSeries: """ A time series for use in Antares + + Args: + time_series: Pandas DataFrame containing the time series. + local_file: TimeSeriesFile to store the time series if the study is local. """ def __init__( diff --git a/tests/antares/services/local_services/conftest.py b/tests/antares/services/local_services/conftest.py index c6d9ee31..90a4c5b5 100644 --- a/tests/antares/services/local_services/conftest.py +++ b/tests/antares/services/local_services/conftest.py @@ -16,6 +16,7 @@ from antares.model.area import Area from antares.model.hydro import HydroProperties from antares.model.renewable import RenewableClusterProperties, TimeSeriesInterpretation, RenewableClusterGroup +from antares.model.solar import Solar from antares.model.st_storage import STStorageProperties, STStorageGroup from antares.model.study import Study, create_study_local from antares.model.thermal import ( @@ -210,3 +211,8 @@ def actual_hydro_ini(local_study_with_hydro) -> IniFile: @pytest.fixture def area_fr(local_study_with_hydro) -> Area: return local_study_with_hydro.get_areas()["fr"] + + +@pytest.fixture +def fr_solar(area_fr) -> Solar: + return area_fr.create_solar(None) diff --git a/tests/antares/services/local_services/test_area.py b/tests/antares/services/local_services/test_area.py index a65485bd..83c76156 100644 --- a/tests/antares/services/local_services/test_area.py +++ b/tests/antares/services/local_services/test_area.py @@ -794,3 +794,12 @@ def test_can_create_solar_ts_file_with_time_series(self, area_fr): # Then assert actual_time_series.equals(expected_time_series) assert actual_time_series_string == expected_time_series_string + + def test_correlation_ini_exists(self, area_fr, fr_solar): + # Given + expected_ini_path = area_fr._area_service.config.study_path / "input/solar/prepro/correlation.ini" + + # Then + assert expected_ini_path.exists() + assert expected_ini_path.is_file() + assert expected_ini_path == fr_solar.correlation.ini_path