def newepj(version: str = None) -> EPJ: """open a new idf file easy way to open a new idf file for particular version. Works only if Energyplus of that version is installed. Parameters ---------- version: string version of the new file you want to create. Will work only if this version of Energyplus has been installed. Returns ------- idf file of type eppy.modelmake.IDF """ # noqa: E501 if not version: version = "9.6" import eppy.easyopen as easyopen idfstring = """{{ "Version": {{ "Version 1": {{ "version_identifier": "{}", "idf_order": 1 }} }} }}""".format(str(version)) fhandle = StringIO(idfstring) return EPJ(fhandle)
def test_surf2list(surfobjecttxt, expected): """py.test for surf2list""" epj = EPJ(StringIO(surfobjecttxt)) surfs = epj.epobjects["BuildingSurface:Detailed"] surfobject = surfs[0] result = listfields.surf2list(surfobject) assert result == expected
def openidf(idfpath: Union[str, PathLike[str]], epjpath: Union[str, PathLike[str]] = None, schemapath: Union[str, bytes, PathLike] = None, epjext: str = None) -> EPJ: """open and idf file as a epj file""" if not epjext: epjext = "epJSON" idfpath = pathlib.Path(idfpath) if not schemapath: with open(idfpath, "r") as idfhandle: version = getidfversion(idfhandle) schemapath = installlocation.schemapath(version) if not epjpath: epjpath = idfpath.with_suffix(f".{epjext}") schemahandle = open(schemapath, "r") idfhandle = open(idfpath, "r") epjtxt = idf2json(idfhandle, schemahandle) epj = EPJ(StringIO(epjtxt)) epj.epjname = epjpath return epj
def epjfile2idffile(epjpath, idfpath=None, schemapath=None): """convert an EPJ file on disk to an IDF file on disk""" epjpath = pathlib.Path(epjpath) if not schemapath: epj = EPJ(epjpath) version = epj.epobjects["Version"][0].version_identifier schemapath = installlocation.schemapath(version) if not idfpath: idfpath = epjpath.with_suffix(".idf") schemahandle = open(schemapath, "r") epjhandle = open(epjpath, "r") idftxt = json2idf(epjhandle, schemahandle) with open(idfpath, "w") as idfhandle: idfhandle.write(idftxt)
"""py.test for epjviewer""" import pytest from eppy3000.modelmaker import EPJ from eppy3000 import epjviewer try: from IPython.display import IFrame JUPYTER = True except ModuleNotFoundError as e: JUPYTER = False # schema_file = "./eppy3000/resources/schema/V9_3/Energy+.schema.epJSON" ep_file = "./eppy3000/resources/epJSON/V9_3/smallfile.epJSON" epj = EPJ(epjname=ep_file) ep_file_big = ( "./eppy3000/resources/snippets/V9_0/5Zone_Unitary_HXAssistedCoil.epJSONout" ) epj_big = EPJ(epjname=ep_file_big) def test_epj2html(): """py.test for epj2html""" expected = '<table border="1"><tr><th>Version</th><td><table border="1"><tr><th>Version 1</th><td><table border="1"><tr><th>version_identifier</th><td>9.3</td></tr><tr><th>idf_order</th><td>1</td></tr></table></td></tr></table></td></tr><tr><th>SimulationControl</th><td><table border="1"><tr><th>SimulationControl 1</th><td><table border="1"><tr><th>do_zone_sizing_calculation</th><td>Yes</td></tr><tr><th>do_system_sizing_calculation</th><td>Yes</td></tr><tr><th>do_plant_sizing_calculation</th><td>Yes</td></tr><tr><th>run_simulation_for_sizing_periods</th><td>No</td></tr><tr><th>run_simulation_for_weather_file_run_periods</th><td>Yes</td></tr><tr><th>idf_order</th><td>2</td></tr></table></td></tr></table></td></tr><tr><th>Building</th><td><table border="1"><tr><th>Empire State Building</th><td><table border="1"><tr><th>north_axis</th><td>30</td></tr><tr><th>terrain</th><td>City</td></tr><tr><th>loads_convergence_tolerance_value</th><td>0.04</td></tr><tr><th>temperature_convergence_tolerance_value</th><td>0.4</td></tr><tr><th>solar_distribution</th><td>FullExterior</td></tr><tr><th>maximum_number_of_warmup_days</th><td>25</td></tr><tr><th>minimum_number_of_warmup_days</th><td>6</td></tr><tr><th>idf_order</th><td>3</td></tr></table></td></tr></table></td></tr><tr><th>Site:Location</th><td><table border="1"><tr><th>CHICAGO_IL_USA TMY2-94846</th><td><table border="1"><tr><th>latitude</th><td>41.78</td></tr><tr><th>longitude</th><td>-87.75</td></tr><tr><th>time_zone</th><td>-6</td></tr><tr><th>elevation</th><td>190</td></tr><tr><th>idf_order</th><td>4</td></tr></table></td></tr></table></td></tr></table>' result = epjviewer.epj2html(epj) assert result == expected def test_epmunch2dct(): """py.test for epmunch2dct"""
def idf2epj(idf, epjsonhandle): """convert idf to json. return a eppy3000.IDF structure""" idfhandle = StringIO(idf.idfstr()) epjstr = eppy3000.idfjsonconverter.idf2json(idfhandle, epjsonhandle) epjsonhandle.seek(0) # need to reset, since we are reading it again return EPJ(StringIO(epjstr), epw=idf.epw, epschemaname=epjsonhandle)