Skip to content
Snippets Groups Projects
Commit 814549bf authored by Jonathan Kriwet's avatar Jonathan Kriwet
Browse files

added simulation and calibration capability

parent 3dfb41aa
Branches
No related tags found
No related merge requests found
File deleted
File deleted
File deleted
File deleted
...@@ -34,13 +34,13 @@ class EPlusSimulationSetup(SimulationSetup): ...@@ -34,13 +34,13 @@ class EPlusSimulationSetup(SimulationSetup):
_default_solver: Default solver setting _default_solver: Default solver setting
_allowed_solvers: List of allowed solver options _allowed_solvers: List of allowed solver options
""" """
sim_intervals: List[str] = Field( sim_intervals: List[Union[str, Tuple[datetime, datetime]]] = Field(
default=['2024-01-01 to 2024-01-02'], default=['2024-01-01 to 2024-01-02'],
description='One or many simulation intervals in format "YYYY-MM-DD to YYYY-MM-DD"', description='One or many simulation intervals in format "YYYY-MM-DD to YYYY-MM-DD"',
title='sim_intervals' title='sim_intervals'
) )
evaluation_intervals: List[str] = Field( evaluation_intervals: List[Union[str, Tuple[datetime, datetime]]] = Field(
default=['2024-01-01 to 2024-01-02'], default=['2024-01-01 to 2024-01-02'],
description='One or many evaluation intervals in format "YYYY-MM-DD to YYYY-MM-DD"', description='One or many evaluation intervals in format "YYYY-MM-DD to YYYY-MM-DD"',
title='evaluation_intervals' title='evaluation_intervals'
...@@ -50,7 +50,7 @@ class EPlusSimulationSetup(SimulationSetup): ...@@ -50,7 +50,7 @@ class EPlusSimulationSetup(SimulationSetup):
default='Timestep', default='Timestep',
description='Interval of the resulting dataframe ("Hourly" or "Timestep")', description='Interval of the resulting dataframe ("Hourly" or "Timestep")',
title='dataframe_interval' title='dataframe_interval'
), )
n_steps_per_hour: int = Field( n_steps_per_hour: int = Field(
default=6, default=6,
...@@ -63,42 +63,55 @@ class EPlusSimulationSetup(SimulationSetup): ...@@ -63,42 +63,55 @@ class EPlusSimulationSetup(SimulationSetup):
@field_validator('sim_intervals', 'evaluation_intervals') @field_validator('sim_intervals', 'evaluation_intervals')
@classmethod @classmethod
def check_intervals(cls, def check_intervals(
intervals: List[str]) -> List[Tuple[datetime, datetime]]: cls,
intervals: List[Union[str, Tuple[datetime, datetime]]]) -> List[Tuple[datetime, datetime]]:
""" """
Validate and convert interval strings to datetime tuples. Validate and convert interval strings or datetime tuples.
Args: Args:
intervals: List of interval strings in format "YYYY-MM-DD to YYYY-MM-DD" intervals: List of either:
- interval strings in format "YYYY-MM-DD to YYYY-MM-DD"
- tuples of (start_datetime, stop_datetime)
Returns: Returns:
List of (start, stop) datetime tuples List of (start_datetime, stop_datetime) tuples
Raises: Raises:
ValueError: If intervals are invalid or not chronologically ordered ValueError: If intervals are invalid or not chronologically ordered
""" """
if intervals is None: if intervals is None:
return intervals return intervals
_intervals = [] _intervals = []
for sim_interval in intervals: for interval in intervals:
if not isinstance(sim_interval, str): # If already a datetime tuple, validate and add directly
return intervals if isinstance(interval, tuple):
start, stop = sim_interval.split(' to ') start, stop = interval
if not (isinstance(start, datetime) and isinstance(stop, datetime)):
raise ValueError('Tuple intervals must contain datetime objects')
# If string, parse to datetime tuple
elif isinstance(interval, str):
start, stop = interval.split(' to ')
start = datetime.strptime(start, "%Y-%m-%d") start = datetime.strptime(start, "%Y-%m-%d")
stop = datetime.strptime(stop, "%Y-%m-%d") stop = datetime.strptime(stop, "%Y-%m-%d")
else:
raise ValueError('Intervals must be either strings or datetime tuples')
if stop <= start: if stop <= start:
raise ValueError('Start must be before stop in sim intervals') raise ValueError('Start must be before stop in intervals')
_intervals.append((start, stop)) _intervals.append((start, stop))
# Check chronological order
for n in range(len(_intervals) - 1): for n in range(len(_intervals) - 1):
if _intervals[n][1] > _intervals[n + 1][0]: if _intervals[n][1] > _intervals[n + 1][0]:
raise ValueError( raise ValueError(
'When specifying sim intervals, they must be increasing in time, meaning the first' 'Intervals must be increasing in time, meaning the first '
'simulation interval is the "oldest" interval') 'interval is the "oldest" interval')
return intervals return _intervals
@field_validator('dataframe_interval') @field_validator('dataframe_interval')
@classmethod @classmethod
...@@ -192,8 +205,7 @@ class EnergyPlusAPI(SimulationAPI): ...@@ -192,8 +205,7 @@ class EnergyPlusAPI(SimulationAPI):
model_name=str(model_path), model_name=str(model_path),
n_cpu=n_cpu n_cpu=n_cpu
) )
# will be set via the intervals in the simulation setup
# set via the sim_intervals in the simulation setup
self._start_date = None self._start_date = None
self._stop_date = None self._stop_date = None
...@@ -299,10 +311,7 @@ class EnergyPlusAPI(SimulationAPI): ...@@ -299,10 +311,7 @@ class EnergyPlusAPI(SimulationAPI):
_dfs = [] _dfs = []
for interval in self.sim_setup.sim_intervals: for start, stop in self.sim_setup.sim_intervals:
start, stop = interval.split(' to ')
start = datetime.strptime(start, "%Y-%m-%d")
stop = datetime.strptime(stop, "%Y-%m-%d")
self._start_date = start self._start_date = start
self._stop_date = stop self._stop_date = stop
...@@ -521,10 +530,7 @@ class EnergyPlusAPI(SimulationAPI): ...@@ -521,10 +530,7 @@ class EnergyPlusAPI(SimulationAPI):
""" """
_df_list = [] _df_list = []
for interval in self.sim_setup.evaluation_intervals: for start, stop in self.sim_setup.evaluation_intervals:
start, stop = interval.split(' to ')
start = datetime.strptime(start, "%Y-%m-%d")
stop = datetime.strptime(stop, "%Y-%m-%d")
_df = df.loc[(df.index > start) & _df = df.loc[(df.index > start) &
(df.index <= stop + pd.Timedelta(days=1))].copy() (df.index <= stop + pd.Timedelta(days=1))].copy()
_df_list.append(_df) _df_list.append(_df)
......
...@@ -18,6 +18,15 @@ def main(): ...@@ -18,6 +18,15 @@ def main():
'2015-01-01 to 2015-02-01' '2015-01-01 to 2015-02-01'
]} ]}
simulation_setup = {"output_interval": 600,
"sim_intervals": [
'2015-01-01 to 2015-02-01'
],
"evaluation_intervals": [
'2015-01-01 to 2015-02-01'
],
"dataframe_interval": "Hourly"}
parameters = None parameters = None
EP_API = EnergyPlusAPI( EP_API = EnergyPlusAPI(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment