Skip to content

Commit

Permalink
solar/prepro/<area_id>/data.txt has correct default values
Browse files Browse the repository at this point in the history
  • Loading branch information
Sigurd-Borge committed Sep 9, 2024
1 parent 5d2919f commit 1c6f20a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/antares/model/solar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down
15 changes: 14 additions & 1 deletion src/antares/tools/time_series_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from pathlib import Path
from typing import Optional

import numpy as np
import pandas as pd


Expand Down Expand Up @@ -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
26 changes: 26 additions & 0 deletions tests/antares/services/local_services/test_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1c6f20a

Please sign in to comment.