Skip to content

Commit

Permalink
Refactor prepro folders
Browse files Browse the repository at this point in the history
  • Loading branch information
Sigurd-Borge committed Sep 9, 2024
1 parent c7361e4 commit 621ce45
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 163 deletions.
76 changes: 14 additions & 62 deletions src/antares/model/solar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
76 changes: 14 additions & 62 deletions src/antares/model/wind.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
74 changes: 74 additions & 0 deletions src/antares/tools/prepro_folder.py
Original file line number Diff line number Diff line change
@@ -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
17 changes: 0 additions & 17 deletions src/antares/tools/time_series_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from pathlib import Path
from typing import Optional

import numpy as np
import pandas as pd


Expand Down Expand Up @@ -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
Loading

0 comments on commit 621ce45

Please sign in to comment.