diff --git a/src/antares/model/solar.py b/src/antares/model/solar.py index dd13c41c..de5e30b3 100644 --- a/src/antares/model/solar.py +++ b/src/antares/model/solar.py @@ -12,10 +12,8 @@ from pathlib import Path from typing import Optional, Any -import pandas as pd - from antares.tools.ini_tool import IniFile, IniFileTypes -from antares.tools.time_series_tool import TimeSeries, ConversionFile, TimeSeriesFileType, TimeSeriesFile +from antares.tools.time_series_tool import TimeSeries, ConversionFile, TimeSeriesFileType, TimeSeriesFile, DataFile class Solar(TimeSeries): @@ -38,14 +36,16 @@ def __init__( conversion if conversion is not None else TimeSeries( - ConversionFile.data, - TimeSeriesFile(TimeSeriesFileType.SOLAR_CONVERSION, study_path, area_id, ConversionFile.data), + ConversionFile().data, + TimeSeriesFile(TimeSeriesFileType.SOLAR_CONVERSION, study_path, area_id, ConversionFile().data), ) ) self._data = ( data if data is not None - else TimeSeries(pd.DataFrame([]), TimeSeriesFile(TimeSeriesFileType.SOLAR_DATA, study_path, area_id)) + else TimeSeries( + DataFile().data, TimeSeriesFile(TimeSeriesFileType.SOLAR_DATA, study_path, area_id, DataFile().data) + ) ) @property diff --git a/src/antares/tools/time_series_tool.py b/src/antares/tools/time_series_tool.py index e248d74f..d70e5bc1 100644 --- a/src/antares/tools/time_series_tool.py +++ b/src/antares/tools/time_series_tool.py @@ -14,6 +14,7 @@ from pathlib import Path from typing import Optional +import numpy as np import pandas as pd @@ -127,4 +128,16 @@ def local_file(self, local_file: TimeSeriesFile) -> None: class ConversionFile: - data = pd.DataFrame([[-9999999980506447872, 0, 9999999980506447872], [0, 0, 0]]) + 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 54f863cb..3efe74ba 100644 --- a/tests/antares/services/local_services/test_area.py +++ b/tests/antares/services/local_services/test_area.py @@ -842,3 +842,29 @@ def test_data_txt_exists(self, area_fr, fr_solar): assert expected_file_path.exists() assert expected_file_path.is_file() assert fr_solar.data.local_file.file_path == expected_file_path + + def test_data_txt_has_correct_default_values(self, area_fr, fr_solar): + # Given + expected_file_contents = """1\t1\t0\t1\t1\t1 +1\t1\t0\t1\t1\t1 +1\t1\t0\t1\t1\t1 +1\t1\t0\t1\t1\t1 +1\t1\t0\t1\t1\t1 +1\t1\t0\t1\t1\t1 +1\t1\t0\t1\t1\t1 +1\t1\t0\t1\t1\t1 +1\t1\t0\t1\t1\t1 +1\t1\t0\t1\t1\t1 +1\t1\t0\t1\t1\t1 +1\t1\t0\t1\t1\t1 +""" + 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: + actual_file_contents = fr_solar_file.read() + actual_file_data = fr_solar.data.time_series + + # Then + assert actual_file_data.equals(expected_file_data) + assert actual_file_contents == expected_file_contents