Skip to content

Commit

Permalink
A prompt has been added when getting IDF.meters and IDF.variables for…
Browse files Browse the repository at this point in the history
… a weather file run when design_day is specified in the IDF file. (#179)

* More robust meters and variables

* AttributeError

* not returning EnergySeries

* Fix

* Fix2
  • Loading branch information
Samuel Letellier-Duchesne authored Jun 11, 2021
1 parent ead8f7c commit e06867e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
29 changes: 27 additions & 2 deletions archetypal/idfclass/meters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""EnergyPlus meters module."""

import inspect
import logging

import pandas as pd
from energy_pandas import EnergySeries
Expand Down Expand Up @@ -38,6 +39,7 @@ def values(
self,
units=None,
reporting_frequency="Hourly",
environment_type=None,
normalize=False,
sort_values=False,
ascending=False,
Expand All @@ -53,10 +55,12 @@ def values(
is detected automatically and a dimensionality check is performed.
reporting_frequency (str): Timestep, Hourly, Daily, Monthly,
RunPeriod, Environment, Annual or Detailed. Default "Hourly".
environment_type (int): The environment type (1 = Design Day, 2 = Design
Run Period, 3 = Weather Run Period).
normalize (bool): Normalize between 0 and 1.
sort_values (bool): If True, values are sorted (default ascending=True)
ascending (bool): If True and `sort_values` is True, values are sorted in
ascending order.
ascending order.
agg_func: #Todo: Document
Returns:
Expand All @@ -70,12 +74,33 @@ def values(
key_name = self._epobject.Key_Name
except BadEPFieldError:
key_name = self._epobject.Name # Backwards compatibility
if environment_type is None:
if self._idf.design_day:
environment_type = 1
elif self._idf.annual:
environment_type = 3
else:
# the environment_type is specified by the simulationcontrol.
try:
for ctrl in self._idf.idfobjects["SIMULATIONCONTROL"]:
if ctrl.Run_Simulation_for_Weather_File_Run_Periods.lower() == "yes":
environment_type = 3
else:
environment_type = 1
except (KeyError, IndexError, AttributeError):
reporting_frequency = 3
report = ReportData.from_sqlite(
sqlite_file=self._idf.sql_file,
table_name=key_name,
environment_type=1 if self._idf.design_day else 3,
environment_type=environment_type,
reporting_frequency=bunch2db[reporting_frequency],
)
if report.empty:
logging.error(
f"The variable is empty for environment_type `{environment_type}`. "
f"Try another environment_type (1, 2 or 3) or specify IDF.annual=True "
f"and rerun the simulation."
)
return EnergySeries.from_reportdata(
report,
to_units=units,
Expand Down
30 changes: 28 additions & 2 deletions archetypal/idfclass/variables.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""EnergyPlus variables module."""
import logging

import pandas as pd
from energy_pandas import EnergyDataFrame
from energy_pandas import EnergyDataFrame, EnergySeries
from geomeppy.patches import EpBunch

from archetypal.idfclass.extensions import bunch2db
Expand Down Expand Up @@ -34,6 +35,7 @@ def values(
self,
units=None,
reporting_frequency="Hourly",
environment_type=None,
normalize=False,
sort_values=False,
):
Expand All @@ -51,6 +53,8 @@ def values(
is detected automatically and a dimensionality check is performed.
reporting_frequency (str): Timestep, Hourly, Daily, Monthly,
RunPeriod, Environment, Annual or Detailed. Default "Hourly".
environment_type (int): The environment type (1 = Design Day, 2 = Design
Run Period, 3 = Weather Run Period).
normalize (bool): Normalize between 0 and 1.
sort_values (bool): If True, values are sorted (default ascending=True).
Expand All @@ -61,12 +65,34 @@ def values(
if self._epobject not in self._idf.idfobjects[self._epobject.key]:
self._idf.addidfobject(self._epobject)
self._idf.simulate()
if environment_type is None:
if self._idf.design_day:
environment_type = 1
elif self._idf.annual:
environment_type = 3
else:
# the environment_type is specified by the simulationcontrol.
try:
for ctrl in self._idf.idfobjects["SIMULATIONCONTROL"]:
if ctrl.Run_Simulation_for_Weather_File_Run_Periods.lower() \
== "yes":
environment_type = 3
else:
environment_type = 1
except (KeyError, IndexError, AttributeError):
reporting_frequency = 3
report = ReportData.from_sqlite(
sqlite_file=self._idf.sql_file,
table_name=self._epobject.Variable_Name,
environment_type=1 if self._idf.design_day else 3,
environment_type=environment_type,
reporting_frequency=bunch2db[reporting_frequency],
)
if report.empty:
logging.error(
f"The variable is empty for environment_type `{environment_type}`. "
f"Try another environment_type (1, 2 or 3) or specify IDF.annual=True "
f"and rerun the simulation."
)
return EnergyDataFrame.from_reportdata(
report,
name=self._epobject.Variable_Name,
Expand Down

0 comments on commit e06867e

Please sign in to comment.