Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the Outputs class has been refactored to better handle specific output requirements #213

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
28 changes: 13 additions & 15 deletions archetypal/eplus_interface/basement.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,10 @@ def run(self):

# Get executable using shutil.which (determines the extension based on
# the platform, eg: .exe. And copy the executable to tmp
self.basement_exe = Path(
shutil.which(
"Basement", path=self.eplus_home / "PreProcess" / "GrndTempCalc"
)
).copy(self.run_dir)
self.basement_idd = (
self.eplus_home / "PreProcess" / "GrndTempCalc" / "BasementGHT.idd"
).copy(self.run_dir)
self.basement_exe = Path(shutil.which("Basement", path=self.eplus_home)).copy(
self.run_dir
)
self.basement_idd = (self.eplus_home / "BasementGHT.idd").copy(self.run_dir)
self.outfile = self.idf.name

# The BasementGHTin.idf file is copied from the self.include list (
Expand Down Expand Up @@ -207,11 +203,13 @@ def cancelled_callback(self, stdin, stdout):

@property
def eplus_home(self):
eplus_exe, eplus_home = paths_from_version(self.idf.as_version.dash)
if not Path(eplus_home).exists():
raise EnergyPlusVersionError(
msg=f"No EnergyPlus Executable found for version "
f"{EnergyPlusVersion(self.idf.as_version)}"
)
"""Get the version-dependant directory where executables are installed."""
if self.idf.file_version <= EnergyPlusVersion("7.2"):
install_dir = self.idf.file_version.current_install_dir / "bin"
else:
return Path(eplus_home)
install_dir = (
self.idf.file_version.current_install_dir
/ "PreProcess"
/ "GrndTempCalc"
)
return install_dir
17 changes: 7 additions & 10 deletions archetypal/eplus_interface/expand_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ def run(self):
self.epw = self.idf.epw.copy(tmp / "in.epw").expand()
self.idfname = Path(self.idf.savecopy(tmp / "in.idf")).expand()
self.idd = self.idf.iddname.copy(tmp / "Energy+.idd").expand()
self.expandobjectsexe = Path(
shutil.which("ExpandObjects", path=self.eplus_home.expand())
).copy2(tmp)
expand_object_exe = shutil.which("ExpandObjects", path=self.eplus_home)
self.expandobjectsexe = Path(expand_object_exe).copy2(tmp)
self.run_dir = Path(tmp).expand()

# Run ExpandObjects Program
Expand Down Expand Up @@ -151,11 +150,9 @@ def cancelled_callback(self, stdin, stdout):

@property
def eplus_home(self):
eplus_exe, eplus_home = paths_from_version(self.idf.as_version.dash)
if not Path(eplus_home).exists():
raise EnergyPlusVersionError(
msg=f"No EnergyPlus Executable found for version "
f"{EnergyPlusVersion(self.idf.as_version)}"
)
"""Get the version-dependant directory where executables are installed."""
if self.idf.file_version <= EnergyPlusVersion("7.2"):
install_dir = self.idf.file_version.current_install_dir / "bin"
else:
return Path(eplus_home)
install_dir = self.idf.file_version.current_install_dir
return install_dir
26 changes: 13 additions & 13 deletions archetypal/eplus_interface/slab.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,10 @@ def run(self):

# Get executable using shutil.which (determines the extension based on
# the platform, eg: .exe. And copy the executable to tmp
self.slabexe = Path(
shutil.which("Slab", path=self.eplus_home / "PreProcess" / "GrndTempCalc")
).copy(self.run_dir)
self.slabidd = (
self.eplus_home / "PreProcess" / "GrndTempCalc" / "SlabGHT.idd"
).copy(self.run_dir)
self.slabexe = Path(shutil.which("Slab", path=self.eplus_home)).copy(
self.run_dir
)
self.slabidd = (self.eplus_home / "SlabGHT.idd").copy(self.run_dir)

# The GHTin.idf file is copied from the self.include list (added by
# ExpandObjects. If self.include is empty, no need to run Slab.
Expand Down Expand Up @@ -164,11 +162,13 @@ def cancelled_callback(self, stdin, stdout):

@property
def eplus_home(self):
eplus_exe, eplus_home = paths_from_version(self.idf.as_version.dash)
if not Path(eplus_home).exists():
raise EnergyPlusVersionError(
msg=f"No EnergyPlus Executable found for version "
f"{EnergyPlusVersion(self.idf.as_version)}"
)
"""Get the version-dependant directory where executables are installed."""
if self.idf.file_version <= EnergyPlusVersion("7.2"):
install_dir = self.idf.file_version.current_install_dir / "bin"
else:
return Path(eplus_home)
install_dir = (
self.idf.file_version.current_install_dir
/ "PreProcess"
/ "GrndTempCalc"
)
return install_dir
7 changes: 7 additions & 0 deletions archetypal/eplus_interface/transition.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ def run(self):

generator = TransitionExe(self.idf, tmp_dir=tmp)

# set the initial version from which we are transitioning
last_successful_transition = self.idf.file_version

for trans in tqdm(
generator,
total=len(generator.transitions),
Expand Down Expand Up @@ -214,10 +217,14 @@ def run(self):
time.time() - start_time
)
)
last_successful_transition = trans.trans
self.success_callback()
for line in self.p.stderr:
self.msg_callback(line.decode("utf-8"))
else:
# set the version of the IDF the latest it was able to transition
# to.
self.idf.as_version = last_successful_transition
self.msg_callback("Transition failed")
self.failure_callback()

Expand Down
4 changes: 1 addition & 3 deletions archetypal/eplus_interface/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
from path import Path

from archetypal import settings
from archetypal.eplus_interface.exceptions import (
InvalidEnergyPlusVersion,
)
from archetypal.eplus_interface.exceptions import InvalidEnergyPlusVersion


class EnergyPlusVersion(Version):
Expand Down
48 changes: 39 additions & 9 deletions archetypal/idfclass/idf.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,23 +288,24 @@ def __init__(
self.upgrade(to_version=self.as_version, overwrite=False)
finally:
# Set model outputs
self._outputs = Outputs(idf=self)
self._outputs = Outputs(idf=self, include_html=False, include_sqlite=False)
if self.prep_outputs:
(
self._outputs.add_basics()
.add_umi_template_outputs()
.add_custom(outputs=self.prep_outputs)
.add_profile_gas_elect_ouputs()
.apply()
)
self._outputs.include_html = True
self._outputs.include_sqlite = True
self._outputs.add_basics()
if isinstance(self.prep_outputs, list):
self._outputs.add_custom(outputs=self.prep_outputs)
self._outputs.add_profile_gas_elect_outputs()
self._outputs.add_umi_template_outputs()
self._outputs.apply()

@property
def outputtype(self):
"""Get or set the outputtype for the idf string representation of self."""
return self._outputtype

@outputtype.setter
def outputtype(self, value):
"""Get or set the outputtype for the idf string representation of self."""
assert value in self.OUTPUTTYPES, (
f'Invalid input "{value}" for output_type.'
f"\nOutput type must be one of the following: {self.OUTPUTTYPES}"
Expand Down Expand Up @@ -688,6 +689,10 @@ def prep_outputs(self):

@prep_outputs.setter
def prep_outputs(self, value):
assert isinstance(value, (bool, list)), (
f"Expected bool or list of dict for "
f"SimulationOutput outputs. Got {type(value)}."
)
self._prep_outputs = value

@property
Expand Down Expand Up @@ -1522,6 +1527,29 @@ def process_results(self):
else:
return results

def add_idf_object_from_idf_string(self, idf_string):
"""Add an IDF object (or more than one) from an EnergyPlus text string.

Args:
idf_string (str): A text string fully describing an EnergyPlus object.
"""
loaded_string = IDF(
StringIO(idf_string),
file_version=self.file_version,
as_version=self.as_version,
prep_outputs=False,
)
added_objects = []
for sequence in loaded_string.idfobjects.values():
if sequence:
for obj in sequence:
data = obj.to_dict()
key = data.pop("key")
added_objects.append(self.newidfobject(key=key.upper(), **data))
# added_objects.extend(self.addidfobjects(list(sequence)))
del loaded_string # remove
return added_objects

def upgrade(self, to_version=None, overwrite=True):
"""`EnergyPlus` idf version updater using local transition program.

Expand Down Expand Up @@ -1906,6 +1934,8 @@ def removeidfobject(self, idfobject):
def removeidfobjects(self, idfobjects: Iterable[EpBunch]):
"""Remove an IDF object from the model.

Resetting dependent variables will wait after all objects have been removed.

Args:
idfobjects: The object to remove from the model.
"""
Expand Down
5 changes: 4 additions & 1 deletion archetypal/idfclass/meters.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ def values(
# 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":
if (
ctrl.Run_Simulation_for_Weather_File_Run_Periods.lower()
== "yes"
):
environment_type = 3
else:
environment_type = 1
Expand Down
Loading