Esempio n. 1
0
def view_idf_to_ax(fname=None, idf_txt=None, test=False):
    """This is originally from https://github.com/jamiebull1/geomeppy/blob/master/geomeppy/view_geometry.py
    This just returns an ax instead of viewing it on order to  plot it together with the sensorpoints"""
    from geomeppy.view_geometry import _get_collection, _get_collections, _get_surfaces, _get_limits  # probably these should not be imported here
    from io import StringIO
    from eppy.iddcurrent import iddcurrent
    # type: (Optional[str], Optional[str], Optional[bool]) -> None

    if fname and idf_txt:
        raise ValueError("Pass either fname or idf_txt, not both.")
    # set the IDD for the version of EnergyPlus
    iddfhandle = StringIO(iddcurrent.iddtxt)
    if IDF.getiddname() is None:
        IDF.setiddname(iddfhandle)

    if fname:
        # import the IDF
        idf = IDF(fname)
    elif idf_txt:
        idf = IDF()
        idf.initreadtxt(idf_txt)
    # create the figure and add the surfaces
    ax = plt.axes(projection="3d")
    collections = _get_collections(idf, opacity=0.5)
    for c in collections:
        ax.add_collection3d(c)

    # calculate and set the axis limits
    limits = _get_limits(idf=idf)
    ax.set_xlim(limits["x"])
    ax.set_ylim(limits["y"])
    ax.set_zlim(limits["z"])
    return ax
Esempio n. 2
0
def init_idf():
    """Initialise an IDF.
    """
    if IDF.getiddname() == None:
        IDF.setiddname(IDD)
    idf = IDF()
    idf.initnew(None)
    return idf
Esempio n. 3
0
def view_idf(fname=None, idf_txt=None, test=False, idf=None):
    # type: (Optional[str], Optional[str], Optional[bool], Optional[IDF]) -> None
    """Display an IDF for inspection.

    :param fname: Path to the IDF.
    :param idf_txt: The string representation of an IDF.
    """
    from geomeppy import IDF

    try:
        plt.figure()
    except TclError:
        # this is as expected on the test server
        return
    if len([arg for arg in [fname, idf_txt, idf] if arg]) > 1:
        raise ValueError("Pass only one of fname, idf_txt or idf.")
    if not idf:
        # set the IDD for the version of EnergyPlus
        iddfhandle = StringIO(iddcurrent.iddtxt)
        if IDF.getiddname() is None:
            IDF.setiddname(iddfhandle)

        if fname:
            # import the IDF
            idf = IDF(fname)
        elif idf_txt:
            idf = IDF()
            idf.initreadtxt(idf_txt)
    # create the figure and add the surfaces
    ax = plt.axes(projection="3d")
    collections = _get_collections(idf, opacity=0.5)
    for c in collections:
        ax.add_collection3d(c)

    # calculate and set the axis limits
    limits = _get_limits(idf=idf)
    ax.set_xlim(limits["x"])
    ax.set_ylim(limits["y"])
    ax.set_zlim(limits["z"])

    if not test:
        plt.show()