Skip to content

Commit

Permalink
Updated TimeSeriesFile to require named arguments after file type and…
Browse files Browse the repository at this point in the history
… path, updated use to match
  • Loading branch information
Sigurd-Borge committed Sep 25, 2024
1 parent 784e45c commit d163cee
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 20 deletions.
12 changes: 6 additions & 6 deletions src/antares/model/area.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,12 @@ def create_thermal_cluster_with_matrices(
def create_renewable_cluster(
self, renewable_name: str, properties: Optional[RenewableClusterProperties], series: Optional[pd.DataFrame]
) -> RenewableCluster:
renewable = self._area_service.create_renewable_cluster(self.id, renewable_name, properties, series)
renewable = self._area_service.create_renewable_cluster(self.id, renewable_name, properties, series=series)
self._renewables[renewable.id] = renewable
return renewable

def create_load(self, series: Optional[pd.DataFrame]) -> Load:
load = self._area_service.create_load(self, series)
load = self._area_service.create_load(self, series=series)
self._load = load
return load

Expand Down Expand Up @@ -348,22 +348,22 @@ def update_ui(self, ui: AreaUi) -> None:
self._ui = new_ui

def create_wind(self, series: Optional[pd.DataFrame]) -> Wind:
wind = self._area_service.create_wind(self, series)
wind = self._area_service.create_wind(self, series=series)
self._wind = wind
return wind

def create_reserves(self, series: Optional[pd.DataFrame]) -> Reserves:
reserves = self._area_service.create_reserves(self, series)
reserves = self._area_service.create_reserves(self, series=series)
self._reserves = reserves
return reserves

def create_solar(self, series: Optional[pd.DataFrame]) -> Solar:
solar = self._area_service.create_solar(self, series)
solar = self._area_service.create_solar(self, series=series)
self._solar = solar
return solar

def create_misc_gen(self, series: Optional[pd.DataFrame]) -> MiscGen:
misc_gen = self._area_service.create_misc_gen(self, series)
misc_gen = self._area_service.create_misc_gen(self, series=series)
self._misc_gen = misc_gen
return misc_gen

Expand Down
20 changes: 15 additions & 5 deletions src/antares/service/local_services/area_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ def create_renewable_cluster(

def create_load(self, area: Area, series: Optional[pd.DataFrame]) -> Load:
series = series if series is not None else pd.DataFrame([])
local_file = TimeSeriesFile(TimeSeriesFileType.LOAD, self.config.study_path, area.id, series)
local_file = TimeSeriesFile(
TimeSeriesFileType.LOAD, self.config.study_path, area_id=area.id, time_series=series
)
return Load(time_series=series, local_file=local_file, study_path=self.config.study_path, area_id=area.id)

def create_st_storage(
Expand All @@ -146,22 +148,30 @@ def create_st_storage(

def create_wind(self, area: Area, series: Optional[pd.DataFrame]) -> Wind:
series = series if series is not None else pd.DataFrame([])
local_file = TimeSeriesFile(TimeSeriesFileType.WIND, self.config.study_path, area.id, series)
local_file = TimeSeriesFile(
TimeSeriesFileType.WIND, self.config.study_path, area_id=area.id, time_series=series
)
return Wind(time_series=series, local_file=local_file, study_path=self.config.study_path, area_id=area.id)

def create_reserves(self, area: Area, series: Optional[pd.DataFrame]) -> Reserves:
series = series if series is not None else pd.DataFrame([])
local_file = TimeSeriesFile(TimeSeriesFileType.RESERVES, self.config.study_path, area.id, series)
local_file = TimeSeriesFile(
TimeSeriesFileType.RESERVES, self.config.study_path, area_id=area.id, time_series=series
)
return Reserves(series, local_file)

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)
local_file = TimeSeriesFile(
TimeSeriesFileType.SOLAR, self.config.study_path, area_id=area.id, time_series=series
)
return Solar(time_series=series, local_file=local_file, study_path=self.config.study_path, area_id=area.id)

def create_misc_gen(self, area: Area, series: Optional[pd.DataFrame]) -> MiscGen:
series = series if series is not None else pd.DataFrame([])
local_file = TimeSeriesFile(TimeSeriesFileType.MISC_GEN, self.config.study_path, area.id, series)
local_file = TimeSeriesFile(
TimeSeriesFileType.MISC_GEN, self.config.study_path, area_id=area.id, time_series=series
)
return MiscGen(series, local_file)

def create_hydro(
Expand Down
12 changes: 8 additions & 4 deletions src/antares/tools/prepro_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,17 @@ def __init__(self, folder: str, study_path: Path, area_id: str) -> None:
self._settings = IniFile(study_path, settings, area_id)
self._conversion = TimeSeries(
ConversionFile().data,
TimeSeriesFile(conversion, study_path, area_id, ConversionFile().data),
TimeSeriesFile(conversion, study_path, area_id=area_id, time_series=ConversionFile().data),
)
self._data = TimeSeries(
DataFile().data, TimeSeriesFile(data, study_path, area_id=area_id, time_series=DataFile().data)
)
self._k = TimeSeries(
pd.DataFrame([]), TimeSeriesFile(k, study_path, area_id=area_id, time_series=pd.DataFrame([]))
)
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([])),
TimeSeriesFile(translation, study_path, area_id=area_id, time_series=pd.DataFrame([])),
)

@property
Expand Down
5 changes: 3 additions & 2 deletions src/antares/tools/time_series_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ class TimeSeriesFileType(Enum):
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=<area_id>) where <area_id> is replaced
with the area's id to access the correct path.
Files where the path contains {area_id} or {constraint_id} have to be used with `.format` to access the correct path.
Example:
TimeSeriesFileType.SOLAR.value.format(area_id="test_area")
"""

BINDING_CONSTRAINT_LESS = "input/bindingconstraints/{constraint_id}_lt.txt"
LOAD = "input/load/series/load_{area_id}.txt"
LOAD_CONVERSION = "input/load/prepro/{area_id}/conversion.txt"
LOAD_DATA = "input/load/prepro/{area_id}/data.txt"
Expand Down Expand Up @@ -70,6 +70,7 @@ def __init__(
self,
ts_file_type: TimeSeriesFileType,
study_path: Path,
*,
area_id: Optional[str] = None,
time_series: Optional[pd.DataFrame] = None,
) -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/antares/tools/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ def time_series_data():

@pytest.fixture
def time_series_file(tmp_path, time_series_data):
return TimeSeriesFile(TimeSeriesFileType.RESERVES, tmp_path, "test", time_series_data)
return TimeSeriesFile(TimeSeriesFileType.RESERVES, tmp_path, area_id="test", time_series=time_series_data)
4 changes: 2 additions & 2 deletions tests/antares/tools/test_time_series_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def test_file_exists_time_series_provided_gives_error(self, tmp_path, time_serie
with pytest.raises(
ValueError, match=f"File {tmp_path / file_name} already exists and a time series was provided."
):
TimeSeriesFile(TimeSeriesFileType.RESERVES, tmp_path, "test", time_series.time_series)
TimeSeriesFile(TimeSeriesFileType.RESERVES, tmp_path, area_id="test", time_series=time_series.time_series)

def test_file_exists_no_time_series_provided(self, tmp_path, time_series_data):
# Given
Expand All @@ -122,7 +122,7 @@ def test_file_exists_no_time_series_provided(self, tmp_path, time_series_data):
# When
file_name.parent.mkdir(exist_ok=True, parents=True)
time_series.time_series.to_csv(file_name, sep="\t", header=False, index=False, encoding="utf-8")
time_series_file = TimeSeriesFile(TimeSeriesFileType.RESERVES, tmp_path, "test")
time_series_file = TimeSeriesFile(TimeSeriesFileType.RESERVES, tmp_path, area_id="test")

# Then
assert time_series_file.time_series.equals(time_series_data)

0 comments on commit d163cee

Please sign in to comment.