diff --git a/src/antares/model/solar.py b/src/antares/model/solar.py index ad8f30b7..fece9ea5 100644 --- a/src/antares/model/solar.py +++ b/src/antares/model/solar.py @@ -10,79 +10,31 @@ # # This file is part of the Antares project. from pathlib import Path -from typing import Optional, Any +from typing import Optional import pandas as pd -from antares.tools.ini_tool import IniFile, IniFileTypes -from antares.tools.time_series_tool import TimeSeries, ConversionFile, TimeSeriesFileType, TimeSeriesFile, DataFile +from antares.tools.prepro_folder import PreproFolder +from antares.tools.time_series_tool import TimeSeries, TimeSeriesFile -class Solar(TimeSeries): +class Solar: def __init__( self, - *, + time_series: pd.DataFrame = pd.DataFrame([]), + local_file: Optional[TimeSeriesFile] = None, study_path: Optional[Path] = None, area_id: Optional[str] = None, - settings: Optional[IniFile] = None, - conversion: Optional[TimeSeries] = None, - data: Optional[TimeSeries] = None, - k: Optional[TimeSeries] = None, - translation: Optional[TimeSeries] = None, - **kwargs: Any, ) -> None: - super().__init__(**kwargs) - if study_path: - self._settings = ( - settings if settings is not None else IniFile(study_path, IniFileTypes.SOLAR_SETTINGS_INI, area_id) - ) - self._conversion = ( - conversion - if conversion is not None - else TimeSeries( - ConversionFile().data, - TimeSeriesFile(TimeSeriesFileType.SOLAR_CONVERSION, study_path, area_id, ConversionFile().data), - ) - ) - self._data = ( - data - if data is not None - else TimeSeries( - DataFile().data, TimeSeriesFile(TimeSeriesFileType.SOLAR_DATA, study_path, area_id, DataFile().data) - ) - ) - self._k = ( - k - if k is not None - else TimeSeries( - pd.DataFrame([]), TimeSeriesFile(TimeSeriesFileType.SOLAR_K, study_path, area_id, pd.DataFrame([])) - ) - ) - self._translation = ( - translation - if translation is not None - else TimeSeries( - pd.DataFrame([]), - TimeSeriesFile(TimeSeriesFileType.SOLAR_TRANSLATION, study_path, area_id, pd.DataFrame([])), - ) - ) + self._time_series = TimeSeries(time_series, local_file) + self._prepro = ( + PreproFolder(folder="solar", study_path=study_path, area_id=area_id) if study_path and area_id else None + ) @property - def settings(self) -> IniFile: - return self._settings + def time_series(self) -> TimeSeries: + return self._time_series @property - def conversion(self) -> TimeSeries: - return self._conversion - - @property - def data(self) -> TimeSeries: - return self._data - - @property - def k(self) -> TimeSeries: - return self._k - - @property - def translation(self) -> TimeSeries: - return self._translation + def prepro(self) -> Optional[PreproFolder]: + return self._prepro diff --git a/src/antares/model/wind.py b/src/antares/model/wind.py index 99165980..ee02fab6 100644 --- a/src/antares/model/wind.py +++ b/src/antares/model/wind.py @@ -10,79 +10,31 @@ # # This file is part of the Antares project. from pathlib import Path -from typing import Optional, Any +from typing import Optional import pandas as pd -from antares.tools.ini_tool import IniFile, IniFileTypes -from antares.tools.time_series_tool import TimeSeries, ConversionFile, TimeSeriesFile, TimeSeriesFileType, DataFile +from antares.tools.prepro_folder import PreproFolder +from antares.tools.time_series_tool import TimeSeries, TimeSeriesFile -class Wind(TimeSeries): +class Wind: def __init__( self, - *, + time_series: pd.DataFrame = pd.DataFrame([]), + local_file: Optional[TimeSeriesFile] = None, study_path: Optional[Path] = None, area_id: Optional[str] = None, - settings: Optional[IniFile] = None, - conversion: Optional[TimeSeries] = None, - data: Optional[TimeSeries] = None, - k: Optional[TimeSeries] = None, - translation: Optional[TimeSeries] = None, - **kwargs: Any, ) -> None: - super().__init__(**kwargs) - if study_path: - self._settings = ( - settings if settings is not None else IniFile(study_path, IniFileTypes.WIND_SETTINGS_INI, area_id) - ) - self._conversion = ( - conversion - if conversion is not None - else TimeSeries( - ConversionFile().data, - TimeSeriesFile(TimeSeriesFileType.WIND_CONVERSION, study_path, area_id, ConversionFile().data), - ) - ) - self._data = ( - data - if data is not None - else TimeSeries( - DataFile().data, TimeSeriesFile(TimeSeriesFileType.WIND_DATA, study_path, area_id, DataFile().data) - ) - ) - self._k = ( - k - if k is not None - else TimeSeries( - pd.DataFrame([]), TimeSeriesFile(TimeSeriesFileType.WIND_K, study_path, area_id, pd.DataFrame([])) - ) - ) - self._translation = ( - translation - if translation is not None - else TimeSeries( - pd.DataFrame([]), - TimeSeriesFile(TimeSeriesFileType.WIND_TRANSLATION, study_path, area_id, pd.DataFrame([])), - ) - ) + self._time_series = TimeSeries(time_series, local_file) + self._prepro = ( + PreproFolder(folder="wind", study_path=study_path, area_id=area_id) if study_path and area_id else None + ) @property - def settings(self) -> IniFile: - return self._settings + def time_series(self) -> TimeSeries: + return self._time_series @property - def conversion(self) -> TimeSeries: - return self._conversion - - @property - def data(self) -> TimeSeries: - return self._data - - @property - def k(self) -> TimeSeries: - return self._k - - @property - def translation(self) -> TimeSeries: - return self._translation + def prepro(self) -> Optional[PreproFolder]: + return self._prepro diff --git a/src/antares/tools/prepro_folder.py b/src/antares/tools/prepro_folder.py new file mode 100644 index 00000000..f520b3cd --- /dev/null +++ b/src/antares/tools/prepro_folder.py @@ -0,0 +1,74 @@ +from pathlib import Path + +import numpy as np +import pandas as pd + +from antares.tools.ini_tool import IniFileTypes, IniFile +from antares.tools.time_series_tool import TimeSeriesFileType, TimeSeries, TimeSeriesFile + + +class PreproFolder: + def __init__(self, folder: str, study_path: Path, area_id: str) -> None: + folders = ["load", "solar", "wind"] + if folder not in folders: + raise ValueError(f"Folder must be one of the following: {', '.join(folders[:-1])}, and {folders[-1]}") + if folder == "solar": + settings = IniFileTypes.SOLAR_SETTINGS_INI + conversion = TimeSeriesFileType.SOLAR_CONVERSION + data = TimeSeriesFileType.SOLAR_DATA + k = TimeSeriesFileType.SOLAR_K + translation = TimeSeriesFileType.SOLAR_TRANSLATION + elif folder == "wind": + settings = IniFileTypes.WIND_SETTINGS_INI + conversion = TimeSeriesFileType.WIND_CONVERSION + data = TimeSeriesFileType.WIND_DATA + k = TimeSeriesFileType.WIND_K + translation = TimeSeriesFileType.WIND_TRANSLATION + + self._settings = IniFile(study_path, settings, area_id) + self._conversion = TimeSeries( + ConversionFile().data, + TimeSeriesFile(conversion, study_path, area_id, ConversionFile().data), + ) + self._data = TimeSeries(DataFile().data, TimeSeriesFile(data, study_path, area_id, DataFile().data)) + self._k = TimeSeries(pd.DataFrame([]), TimeSeriesFile(k, study_path, area_id, pd.DataFrame([]))) + self._translation = TimeSeries( + pd.DataFrame([]), + TimeSeriesFile(translation, study_path, area_id, pd.DataFrame([])), + ) + + @property + def settings(self) -> IniFile: + return self._settings + + @property + def conversion(self) -> TimeSeries: + return self._conversion + + @property + def data(self) -> TimeSeries: + return self._data + + @property + def k(self) -> TimeSeries: + return self._k + + @property + def translation(self) -> TimeSeries: + return self._translation + + +class ConversionFile: + def __init__(self) -> None: + self.data = pd.DataFrame([[-9999999980506447872, 0, 9999999980506447872], [0, 0, 0]]) + + +class DataFile: + def __init__(self) -> None: + default_data = pd.DataFrame(np.ones([12, 6])) + default_data[2] = 0 + self._data = default_data.astype(int) + + @property + def data(self) -> pd.DataFrame: + return self._data diff --git a/src/antares/tools/time_series_tool.py b/src/antares/tools/time_series_tool.py index 1aeb8e98..55116f3e 100644 --- a/src/antares/tools/time_series_tool.py +++ b/src/antares/tools/time_series_tool.py @@ -14,7 +14,6 @@ from pathlib import Path from typing import Optional -import numpy as np import pandas as pd @@ -131,19 +130,3 @@ def local_file(self) -> Optional[TimeSeriesFile]: def local_file(self, local_file: TimeSeriesFile) -> None: self._local_file = local_file self._time_series = local_file.time_series - - -class ConversionFile: - def __init__(self) -> None: - self.data = pd.DataFrame([[-9999999980506447872, 0, 9999999980506447872], [0, 0, 0]]) - - -class DataFile: - def __init__(self) -> None: - default_data = pd.DataFrame(np.ones([12, 6])) - default_data[2] = 0 - self._data = default_data.astype(int) - - @property - def data(self) -> pd.DataFrame: - return self._data diff --git a/tests/antares/services/local_services/test_area.py b/tests/antares/services/local_services/test_area.py index bfb39e83..fe220793 100644 --- a/tests/antares/services/local_services/test_area.py +++ b/tests/antares/services/local_services/test_area.py @@ -765,7 +765,7 @@ def test_settings_ini_exists(self, area_fr, fr_wind): # Then assert expected_ini_path.exists() assert expected_ini_path.is_file() - assert expected_ini_path == fr_wind.settings.ini_path + assert expected_ini_path == fr_wind.prepro.settings.ini_path def test_conversion_txt_exists(self, area_fr, fr_wind): # Given @@ -776,7 +776,7 @@ def test_conversion_txt_exists(self, area_fr, fr_wind): # Then assert expected_file_path.exists() assert expected_file_path.is_file() - assert fr_wind.conversion.local_file.file_path == expected_file_path + assert fr_wind.prepro.conversion.local_file.file_path == expected_file_path def test_conversion_txt_has_correct_default_values(self, area_fr, fr_wind): # Given @@ -787,9 +787,9 @@ def test_conversion_txt_has_correct_default_values(self, area_fr, fr_wind): expected_file_data = pd.read_csv(StringIO(expected_file_contents), sep="\t", header=None).astype(str) # When - with fr_wind.conversion.local_file.file_path.open("r") as fr_wind_file: + with fr_wind.prepro.conversion.local_file.file_path.open("r") as fr_wind_file: actual_file_contents = fr_wind_file.read() - actual_file_data = fr_wind.conversion.time_series.astype(str) + actual_file_data = fr_wind.prepro.conversion.time_series.astype(str) # Then assert actual_file_data.equals(expected_file_data) @@ -804,7 +804,7 @@ def test_data_txt_exists(self, area_fr, fr_wind): # Then assert expected_file_path.exists() assert expected_file_path.is_file() - assert fr_wind.data.local_file.file_path == expected_file_path + assert fr_wind.prepro.data.local_file.file_path == expected_file_path def test_data_txt_has_correct_default_values(self, area_fr, fr_wind): # Given @@ -824,9 +824,9 @@ def test_data_txt_has_correct_default_values(self, area_fr, fr_wind): expected_file_data = pd.read_csv(StringIO(expected_file_contents), sep="\t", header=None) # When - with fr_wind.data.local_file.file_path.open("r") as fr_wind_file: + with fr_wind.prepro.data.local_file.file_path.open("r") as fr_wind_file: actual_file_contents = fr_wind_file.read() - actual_file_data = fr_wind.data.time_series + actual_file_data = fr_wind.prepro.data.time_series # Then assert actual_file_data.equals(expected_file_data) @@ -841,14 +841,14 @@ def test_k_txt_exists(self, area_fr, fr_wind): # Then assert expected_file_path.exists() assert expected_file_path.is_file() - assert fr_wind.k.local_file.file_path == expected_file_path + assert fr_wind.prepro.k.local_file.file_path == expected_file_path def test_k_txt_is_empty_by_default(self, area_fr, fr_wind): # Given expected_file_contents = """""" # When - with fr_wind.k.local_file.file_path.open("r") as fr_wind_file: + with fr_wind.prepro.k.local_file.file_path.open("r") as fr_wind_file: actual_file_contents = fr_wind_file.read() # Then @@ -863,14 +863,14 @@ def test_translation_txt_exists(self, area_fr, fr_wind): # Then assert expected_file_path.exists() assert expected_file_path.is_file() - assert fr_wind.translation.local_file.file_path == expected_file_path + assert fr_wind.prepro.translation.local_file.file_path == expected_file_path def test_translation_txt_is_empty_by_default(self, area_fr, fr_wind): # Given expected_file_contents = """""" # When - with fr_wind.translation.local_file.file_path.open("r") as fr_wind_file: + with fr_wind.prepro.translation.local_file.file_path.open("r") as fr_wind_file: actual_file_contents = fr_wind_file.read() # Then @@ -920,7 +920,7 @@ def test_settings_ini_exists(self, area_fr, fr_solar): # Then assert expected_ini_path.exists() assert expected_ini_path.is_file() - assert expected_ini_path == fr_solar.settings.ini_path + assert expected_ini_path == fr_solar.prepro.settings.ini_path def test_conversion_txt_exists(self, area_fr, fr_solar): # Given @@ -931,7 +931,7 @@ def test_conversion_txt_exists(self, area_fr, fr_solar): # Then assert expected_file_path.exists() assert expected_file_path.is_file() - assert fr_solar.conversion.local_file.file_path == expected_file_path + assert fr_solar.prepro.conversion.local_file.file_path == expected_file_path def test_conversion_txt_has_correct_default_values(self, area_fr, fr_solar): # Given @@ -942,9 +942,9 @@ def test_conversion_txt_has_correct_default_values(self, area_fr, fr_solar): expected_file_data = pd.read_csv(StringIO(expected_file_contents), sep="\t", header=None).astype(str) # When - with fr_solar.conversion.local_file.file_path.open("r") as fr_solar_file: + with fr_solar.prepro.conversion.local_file.file_path.open("r") as fr_solar_file: actual_file_contents = fr_solar_file.read() - actual_file_data = fr_solar.conversion.time_series.astype(str) + actual_file_data = fr_solar.prepro.conversion.time_series.astype(str) # Then assert actual_file_data.equals(expected_file_data) @@ -959,7 +959,7 @@ def test_data_txt_exists(self, area_fr, fr_solar): # Then assert expected_file_path.exists() assert expected_file_path.is_file() - assert fr_solar.data.local_file.file_path == expected_file_path + assert fr_solar.prepro.data.local_file.file_path == expected_file_path def test_data_txt_has_correct_default_values(self, area_fr, fr_solar): # Given @@ -979,9 +979,9 @@ def test_data_txt_has_correct_default_values(self, area_fr, fr_solar): expected_file_data = pd.read_csv(StringIO(expected_file_contents), sep="\t", header=None) # When - with fr_solar.data.local_file.file_path.open("r") as fr_solar_file: + with fr_solar.prepro.data.local_file.file_path.open("r") as fr_solar_file: actual_file_contents = fr_solar_file.read() - actual_file_data = fr_solar.data.time_series + actual_file_data = fr_solar.prepro.data.time_series # Then assert actual_file_data.equals(expected_file_data) @@ -996,14 +996,14 @@ def test_k_txt_exists(self, area_fr, fr_solar): # Then assert expected_file_path.exists() assert expected_file_path.is_file() - assert fr_solar.k.local_file.file_path == expected_file_path + assert fr_solar.prepro.k.local_file.file_path == expected_file_path def test_k_txt_is_empty_by_default(self, area_fr, fr_solar): # Given expected_file_contents = """""" # When - with fr_solar.k.local_file.file_path.open("r") as fr_solar_file: + with fr_solar.prepro.k.local_file.file_path.open("r") as fr_solar_file: actual_file_contents = fr_solar_file.read() # Then @@ -1019,14 +1019,14 @@ def test_translation_txt_exists(self, area_fr, fr_solar): # Then assert expected_file_path.exists() assert expected_file_path.is_file() - assert fr_solar.translation.local_file.file_path == expected_file_path + assert fr_solar.prepro.translation.local_file.file_path == expected_file_path def test_translation_txt_is_empty_by_default(self, area_fr, fr_solar): # Given expected_file_contents = """""" # When - with fr_solar.translation.local_file.file_path.open("r") as fr_solar_file: + with fr_solar.prepro.translation.local_file.file_path.open("r") as fr_solar_file: actual_file_contents = fr_solar_file.read() # Then