Example #1
0
def readdatacommdct1(
        idfname,  # type: str
        iddfile="Energy+.idd",  # type: str
        commdct=None,  # type: Optional[List[List[Dict[str, Any]]]]
        block=None,  # type: Optional[List]
):
    # type: (...) -> Tuple[Optional[List[Any]], Any, List[List[Dict[str, Any]]], Any]
    """Read the idf file.

    This is patched so that the IDD index is not lost when reading a new IDF without reloading the modeleditor module.

    :param idfname: Name of the IDF file to read.
    :param iddfile: Name of the IDD file to use to interpret the IDF.
    :param commdct: Descriptions of IDF fields from the IDD. Defaults to None.
    :param block: EnergyPlus field ID names of the IDF from the IDD. Defaults to None.
    :returns: block EnergyPlus field ID names of the IDF from the IDD.
    :returns data: Eplusdata object containing representions of IDF objects.
    :returns: commdct List of names of IDF objects.
    :returns: idd_index A pair of dicts used for fast lookups of names of groups of objects.

    """
    if not commdct:
        block, commlst, updated_commdct, idd_index = parse_idd.extractidddata(
            iddfile)
        theidd = eplusdata.Idd(block, 2)
    else:
        theidd = eplusdata.Idd(block, 2)
        name2refs = iddindex.makename2refdct(commdct)
        ref2namesdct = iddindex.makeref2namesdct(name2refs)
        idd_index = dict(name2refs=name2refs, ref2names=ref2namesdct)
        updated_commdct = iddindex.ref2names2commdct(ref2namesdct, commdct)
    data = eplusdata.Eplusdata(theidd, idfname)
    return block, data, updated_commdct, idd_index
Example #2
0
def make_idd_index(extract_func, fname, debug):
    """generate the iddindex"""
    astr = _readfname(fname)

    # fname is exhausted by the above read
    # reconstitute fname as a StringIO
    fname = StringIO(astr)

    # glist = iddgroups.iddtxt2grouplist(astr.decode('ISO-8859-2'))

    blocklst, commlst, commdct = extract_func(fname)

    name2refs = iddindex.makename2refdct(commdct)
    ref2namesdct = iddindex.makeref2namesdct(name2refs)
    idd_index = dict(name2refs=name2refs, ref2names=ref2namesdct)
    commdct = iddindex.ref2names2commdct(ref2namesdct, commdct)

    return blocklst, commlst, commdct, idd_index
Example #3
0
def make_idd_index(extract_func, fname, debug):
    """generate the iddindex"""
    astr = _readfname(fname)

    # fname is exhausted by the above read
    # reconstitute fname as a StringIO
    fname = StringIO(astr)

    # glist = iddgroups.iddtxt2grouplist(astr.decode('ISO-8859-2'))
    
    
    blocklst, commlst, commdct = extract_func(fname)
    
    name2refs = iddindex.makename2refdct(commdct)
    ref2namesdct = iddindex.makeref2namesdct(name2refs)
    idd_index = dict(name2refs=name2refs, ref2names=ref2namesdct)
    commdct = iddindex.ref2names2commdct(ref2namesdct, commdct)
    
    return blocklst, commlst, commdct, idd_index
Example #4
0
def test_ref2names2commdct():
    """py.test for ref2names2commdct"""
    thedata = (
        (
            # ------------
            [
                [
                    {
                        "idfobj": "referedto1"
                    },
                    {
                        "field": ["Name"],
                        "reference": ["rname11", "rname12", "rname_both"],
                    },
                ],
                [
                    {
                        "idfobj": "referedto2"
                    },
                    {
                        "field": ["Name"],
                        "reference": ["rname21", "rname22", "rname_both"],
                    },
                ],
                [
                    {
                        "idfobj": "referingobj1"
                    },
                    {
                        "field": ["Name"]
                    },
                    {
                        "field": ["referingfield"],
                        "type": ["object-list"],
                        "object-list": ["rname11"],
                    },
                ],
                [
                    {
                        "idfobj": "referingobj2"
                    },
                    {
                        "field": ["Name"]
                    },
                    {
                        "field": ["referingfield"],
                        "type": ["object-list"],
                        "object-list": ["rname_both"],
                    },
                ],
            ],
            # ------------
            [
                [
                    {
                        "idfobj": "referedto1"
                    },
                    {
                        "field": ["Name"],
                        "reference": ["rname11", "rname12", "rname_both"],
                    },
                ],
                [
                    {
                        "idfobj": "referedto2"
                    },
                    {
                        "field": ["Name"],
                        "reference": ["rname21", "rname22", "rname_both"],
                    },
                ],
                [
                    {
                        "idfobj": "referingobj1"
                    },
                    {
                        "field": ["Name"]
                    },
                    {
                        "field": ["referingfield"],
                        "type": ["object-list"],
                        "object-list": ["rname11"],
                        "validobjects": set(["referedto1".upper()]),
                    },
                ],
                [
                    {
                        "idfobj": "referingobj2"
                    },
                    {
                        "field": ["Name"]
                    },
                    {
                        "field": ["referingfield"],
                        "type": ["object-list"],
                        "object-list": ["rname_both"],
                        "validobjects": set(["REFEREDTO1", "REFEREDTO2"]),
                    },
                ],
            ],
        ),  # commdct, expected
    )
    for commdct, expected in thedata:
        name2refdct = iddindex.makename2refdct(commdct)
        ref2names = iddindex.makeref2namesdct(name2refdct)
        result = iddindex.ref2names2commdct(ref2names, commdct)
        for r_item, e_item in zip(result, expected):
            assert r_item == e_item
            # the test below is ensure that the embedded data is not a copy,
            # but is pointing to the set in ref2names
            for item in r_item:
                try:
                    reference = item["object-list"][0]
                    validobjects = item["validobjects"]
                    assert id(ref2names[reference]) == id(validobjects)
                except KeyError as e:
                    continue
Example #5
0
def test_makeref2namesdct():
    """pytest for makeref2namesdct"""
    thedata = (
        (
            {
                "wall": ["surface", "surfandsubsurf"],
                "roof": ["surface", "surfandsubsurf"],
                "window": ["surfandsubsurf", "subsurf"],
                "skylight": ["surfandsubsurf", "subsurf"],
                "zone": ["zname"],
            },
            {
                "surface": set(["wall", "roof"]),
                "subsurf": set(["window", "skylight"]),
                "surfandsubsurf": set(["wall", "roof", "window", "skylight"]),
                "zname": set(["zone"]),
            },
        ),  # name2refdct, expected
        (
            {
                "ZONE": [
                    "ZoneNames",
                    "OutFaceEnvNames",
                    "ZoneAndZoneListNames",
                    "AirflowNetworkNodeAndZoneNames",
                ],
                "WINDOW": [
                    "SubSurfNames",
                    "SurfAndSubSurfNames",
                    "AllHeatTranSurfNames",
                    "OutFaceEnvNames",
                    "AllHeatTranAngFacNames",
                    "RadGroupAndSurfNames",
                    "SurfGroupAndHTSurfNames",
                    "AllShadingAndHTSurfNames",
                ],
                "WALL:EXTERIOR": [
                    "SurfaceNames",
                    "SurfAndSubSurfNames",
                    "AllHeatTranSurfNames",
                    "HeatTranBaseSurfNames",
                    "AllHeatTranAngFacNames",
                    "RadGroupAndSurfNames",
                    "SurfGroupAndHTSurfNames",
                    "AllShadingAndHTSurfNames",
                ],
                "FENESTRATIONSURFACE:DETAILED": [
                    "SubSurfNames",
                    "SurfAndSubSurfNames",
                    "AllHeatTranSurfNames",
                    "OutFaceEnvNames",
                    "AllHeatTranAngFacNames",
                    "RadGroupAndSurfNames",
                    "SurfGroupAndHTSurfNames",
                    "AllShadingAndHTSurfNames",
                ],
                "BUILDINGSURFACE:DETAILED": [
                    "SurfaceNames",
                    "SurfAndSubSurfNames",
                    "AllHeatTranSurfNames",
                    "HeatTranBaseSurfNames",
                    "OutFaceEnvNames",
                    "AllHeatTranAngFacNames",
                    "RadGroupAndSurfNames",
                    "SurfGroupAndHTSurfNames",
                    "AllShadingAndHTSurfNames",
                ],
            },
            {
                "AirflowNetworkNodeAndZoneNames": {"ZONE"},
                "AllHeatTranAngFacNames": {
                    "BUILDINGSURFACE:DETAILED",
                    "FENESTRATIONSURFACE:DETAILED",
                    "WALL:EXTERIOR",
                    "WINDOW",
                },
                "AllHeatTranSurfNames": {
                    "BUILDINGSURFACE:DETAILED",
                    "FENESTRATIONSURFACE:DETAILED",
                    "WALL:EXTERIOR",
                    "WINDOW",
                },
                "AllShadingAndHTSurfNames": {
                    "BUILDINGSURFACE:DETAILED",
                    "FENESTRATIONSURFACE:DETAILED",
                    "WALL:EXTERIOR",
                    "WINDOW",
                },
                "HeatTranBaseSurfNames":
                {"BUILDINGSURFACE:DETAILED", "WALL:EXTERIOR"},
                "OutFaceEnvNames": {
                    "BUILDINGSURFACE:DETAILED",
                    "FENESTRATIONSURFACE:DETAILED",
                    "WINDOW",
                    "ZONE",
                },
                "RadGroupAndSurfNames": {
                    "BUILDINGSURFACE:DETAILED",
                    "FENESTRATIONSURFACE:DETAILED",
                    "WALL:EXTERIOR",
                    "WINDOW",
                },
                "SubSurfNames": {"FENESTRATIONSURFACE:DETAILED", "WINDOW"},
                "SurfAndSubSurfNames": {
                    "BUILDINGSURFACE:DETAILED",
                    "FENESTRATIONSURFACE:DETAILED",
                    "WALL:EXTERIOR",
                    "WINDOW",
                },
                "SurfGroupAndHTSurfNames": {
                    "BUILDINGSURFACE:DETAILED",
                    "FENESTRATIONSURFACE:DETAILED",
                    "WALL:EXTERIOR",
                    "WINDOW",
                },
                "SurfaceNames": {"BUILDINGSURFACE:DETAILED", "WALL:EXTERIOR"},
                "ZoneAndZoneListNames": {"ZONE"},
                "ZoneNames": {"ZONE"},
            },
        ),  # name2refdct, expected
    )
    for name2refdct, expected in thedata:
        result = iddindex.makeref2namesdct(name2refdct)
        assert result == expected
Example #6
0
def test_ref2names2commdct():
    """py.test for ref2names2commdct"""
    thedata = (
        (
            # ------------
            [
                [
                    {
                        'idfobj': 'referedto1'
                    },
                    {
                        'field': ['Name'],
                        'reference': ['rname11', 'rname12', 'rname_both'],
                    },
                ],
                [
                    {
                        'idfobj': 'referedto2'
                    },
                    {
                        'field': ['Name'],
                        'reference': ['rname21', 'rname22', 'rname_both'],
                    },
                ],
                [{
                    'idfobj': 'referingobj1'
                }, {
                    'field': ['Name']
                }, {
                    'field': ['referingfield'],
                    'type': ['object-list'],
                    'object-list': ['rname11'],
                }],
                [{
                    'idfobj': 'referingobj2'
                }, {
                    'field': ['Name']
                }, {
                    'field': ['referingfield'],
                    'type': ['object-list'],
                    'object-list': ['rname_both'],
                }],
            ],
            # ------------
            [
                [
                    {
                        'idfobj': 'referedto1'
                    },
                    {
                        'field': ['Name'],
                        'reference': ['rname11', 'rname12', 'rname_both'],
                    },
                ],
                [
                    {
                        'idfobj': 'referedto2'
                    },
                    {
                        'field': ['Name'],
                        'reference': ['rname21', 'rname22', 'rname_both'],
                    },
                ],
                [{
                    'idfobj': 'referingobj1'
                }, {
                    'field': ['Name']
                }, {
                    'field': ['referingfield'],
                    'type': ['object-list'],
                    'object-list': ['rname11'],
                    'validobjects': set(['referedto1'.upper()]),
                }],
                [{
                    'idfobj': 'referingobj2'
                }, {
                    'field': ['Name']
                }, {
                    'field': ['referingfield'],
                    'type': ['object-list'],
                    'object-list': ['rname_both'],
                    'validobjects': set(['REFEREDTO1', 'REFEREDTO2'])
                }],
            ],
        ),  # commdct, expected
    )
    for commdct, expected in thedata:
        name2refdct = iddindex.makename2refdct(commdct)
        ref2names = iddindex.makeref2namesdct(name2refdct)
        result = iddindex.ref2names2commdct(ref2names, commdct)
        for r_item, e_item in zip(result, expected):
            assert r_item == e_item
            # the test below is ensure that the embedded data is not a copy,
            # but is pointing to the set in ref2names
            for item in r_item:
                try:
                    reference = item['object-list'][0]
                    validobjects = item['validobjects']
                    assert id(ref2names[reference]) == id(validobjects)
                except KeyError as e:
                    continue
Example #7
0
def test_makeref2namesdct():
    """pytest for makeref2namesdct"""
    thedata = (
        ({
            'wall': ['surface', 'surfandsubsurf'],
            'roof': ['surface', 'surfandsubsurf'],
            'window': ['surfandsubsurf', 'subsurf'],
            'skylight': ['surfandsubsurf', 'subsurf'],
            'zone': [
                'zname',
            ]
        }, {
            'surface': set(['wall', 'roof']),
            'subsurf': set(['window', 'skylight']),
            'surfandsubsurf': set(['wall', 'roof', 'window', 'skylight']),
            'zname': set(['zone']),
        }),  # name2refdct, expected
        ({
            'ZONE': [
                u'ZoneNames', u'OutFaceEnvNames', u'ZoneAndZoneListNames',
                u'AirflowNetworkNodeAndZoneNames'
            ],
            'WINDOW': [
                u'SubSurfNames', u'SurfAndSubSurfNames',
                u'AllHeatTranSurfNames', u'OutFaceEnvNames',
                u'AllHeatTranAngFacNames', u'RadGroupAndSurfNames',
                u'SurfGroupAndHTSurfNames', u'AllShadingAndHTSurfNames'
            ],
            'WALL:EXTERIOR': [
                u'SurfaceNames', u'SurfAndSubSurfNames',
                u'AllHeatTranSurfNames', u'HeatTranBaseSurfNames',
                u'AllHeatTranAngFacNames', u'RadGroupAndSurfNames',
                u'SurfGroupAndHTSurfNames', u'AllShadingAndHTSurfNames'
            ],
            'FENESTRATIONSURFACE:DETAILED': [
                u'SubSurfNames', u'SurfAndSubSurfNames',
                u'AllHeatTranSurfNames', u'OutFaceEnvNames',
                u'AllHeatTranAngFacNames', u'RadGroupAndSurfNames',
                u'SurfGroupAndHTSurfNames', u'AllShadingAndHTSurfNames'
            ],
            'BUILDINGSURFACE:DETAILED': [
                u'SurfaceNames', u'SurfAndSubSurfNames',
                u'AllHeatTranSurfNames', u'HeatTranBaseSurfNames',
                u'OutFaceEnvNames', u'AllHeatTranAngFacNames',
                u'RadGroupAndSurfNames', u'SurfGroupAndHTSurfNames',
                u'AllShadingAndHTSurfNames'
            ],
        }, {
            u'AirflowNetworkNodeAndZoneNames': {'ZONE'},
            u'AllHeatTranAngFacNames': {
                'BUILDINGSURFACE:DETAILED', 'FENESTRATIONSURFACE:DETAILED',
                'WALL:EXTERIOR', 'WINDOW'
            },
            u'AllHeatTranSurfNames': {
                'BUILDINGSURFACE:DETAILED', 'FENESTRATIONSURFACE:DETAILED',
                'WALL:EXTERIOR', 'WINDOW'
            },
            u'AllShadingAndHTSurfNames': {
                'BUILDINGSURFACE:DETAILED', 'FENESTRATIONSURFACE:DETAILED',
                'WALL:EXTERIOR', 'WINDOW'
            },
            u'HeatTranBaseSurfNames':
            {'BUILDINGSURFACE:DETAILED', 'WALL:EXTERIOR'},
            u'OutFaceEnvNames': {
                'BUILDINGSURFACE:DETAILED', 'FENESTRATIONSURFACE:DETAILED',
                'WINDOW', 'ZONE'
            },
            u'RadGroupAndSurfNames': {
                'BUILDINGSURFACE:DETAILED', 'FENESTRATIONSURFACE:DETAILED',
                'WALL:EXTERIOR', 'WINDOW'
            },
            u'SubSurfNames': {'FENESTRATIONSURFACE:DETAILED', 'WINDOW'},
            u'SurfAndSubSurfNames': {
                'BUILDINGSURFACE:DETAILED', 'FENESTRATIONSURFACE:DETAILED',
                'WALL:EXTERIOR', 'WINDOW'
            },
            u'SurfGroupAndHTSurfNames': {
                'BUILDINGSURFACE:DETAILED', 'FENESTRATIONSURFACE:DETAILED',
                'WALL:EXTERIOR', 'WINDOW'
            },
            u'SurfaceNames': {'BUILDINGSURFACE:DETAILED', 'WALL:EXTERIOR'},
            u'ZoneAndZoneListNames': {'ZONE'},
            u'ZoneNames': {'ZONE'}
        }),  # name2refdct, expected
    )
    for name2refdct, expected in thedata:
        result = iddindex.makeref2namesdct(name2refdct)
        assert result == expected
Example #8
0
def test_ref2names2commdct():
    """py.test for ref2names2commdct"""
    thedata = (
    (
# ------------
[
[
    {'idfobj':'referedto1'},
    {
        'field':['Name'],
        'reference':['rname11', 'rname12', 'rname_both'],
    },
    
],

[
    {'idfobj':'referedto2'},
    {
        'field':['Name'],
        'reference':['rname21', 'rname22', 'rname_both'],
    },
    
],  

[
    {'idfobj':'referingobj1'},
    {'field':['Name']},
    {
        'field':['referingfield'],
        'type':['object-list'],
        'object-list':['rname11'],
    }
    
],  

[
    {'idfobj':'referingobj2'},
    {'field':['Name']},
    {
        'field':['referingfield'],
        'type':['object-list'],
        'object-list':['rname_both'],
    }
    
],  

],
# ------------
[
[
    {'idfobj':'referedto1'},
    {
        'field':['Name'],
        'reference':['rname11', 'rname12', 'rname_both'],
    },
    
],

[
    {'idfobj':'referedto2'},
    {
        'field':['Name'],
        'reference':['rname21', 'rname22', 'rname_both'],
    },
    
],  

[
    {'idfobj':'referingobj1'},
    {'field':['Name']},
    {
        'field':['referingfield'],
        'type':['object-list'],
        'object-list':['rname11'],
        'validobjects':set(['referedto1'.upper()]),
    }
    
],  

[
    {'idfobj':'referingobj2'},
    {'field':['Name']},
    {
        'field':['referingfield'],
        'type':['object-list'],
        'object-list':['rname_both'],
        'validobjects':set(['REFEREDTO1', 'REFEREDTO2'])
    }
    
],  
],
    ), # commdct, expected
    )
    for commdct, expected in thedata:
        name2refdct = iddindex.makename2refdct(commdct)
        ref2names = iddindex.makeref2namesdct(name2refdct)
        result = iddindex.ref2names2commdct(ref2names, commdct)
        for r_item, e_item in zip(result, expected):
            assert r_item == e_item
            # the test below is ensure that the embedded data is not a copy,
            # but is pointing to the set in ref2names
            for item in r_item:
                try:
                    reference = item['object-list'][0]
                    validobjects = item['validobjects']
                    assert id(ref2names[reference]) == id(validobjects)
                except KeyError as e:
                    continue
Example #9
0
def test_makeref2namesdct():
    """pytest for makeref2namesdct"""
    thedata = (
    (
        {
            'wall':['surface', 'surfandsubsurf'],
            'roof':['surface', 'surfandsubsurf'],
            'window':['surfandsubsurf', 'subsurf'],
            'skylight':['surfandsubsurf', 'subsurf'],
            'zone':['zname',]
        },
        {
            'surface':set(['wall', 'roof']),
            'subsurf':set(['window', 'skylight']),
            'surfandsubsurf':set(['wall', 'roof', 'window', 'skylight']),
            'zname':set(['zone']),
        }
    ), # name2refdct, expected
    (
        {
        'ZONE':[u'ZoneNames',
                u'OutFaceEnvNames',
                u'ZoneAndZoneListNames',
                u'AirflowNetworkNodeAndZoneNames'],
        'WINDOW':[u'SubSurfNames',
                u'SurfAndSubSurfNames',
                u'AllHeatTranSurfNames',
                u'OutFaceEnvNames',
                u'AllHeatTranAngFacNames',
                u'RadGroupAndSurfNames',
                u'SurfGroupAndHTSurfNames',
                u'AllShadingAndHTSurfNames'],
        'WALL:EXTERIOR':[u'SurfaceNames',
                u'SurfAndSubSurfNames',
                u'AllHeatTranSurfNames',
                u'HeatTranBaseSurfNames',
                u'AllHeatTranAngFacNames',
                u'RadGroupAndSurfNames',
                u'SurfGroupAndHTSurfNames',
                u'AllShadingAndHTSurfNames'],
        'FENESTRATIONSURFACE:DETAILED':[u'SubSurfNames',
                u'SurfAndSubSurfNames',
                u'AllHeatTranSurfNames',
                u'OutFaceEnvNames',
                u'AllHeatTranAngFacNames',
                u'RadGroupAndSurfNames',
                u'SurfGroupAndHTSurfNames',
                u'AllShadingAndHTSurfNames'],
        'BUILDINGSURFACE:DETAILED':[u'SurfaceNames',
                u'SurfAndSubSurfNames',
                u'AllHeatTranSurfNames',
                u'HeatTranBaseSurfNames',
                u'OutFaceEnvNames',
                u'AllHeatTranAngFacNames',
                u'RadGroupAndSurfNames',
                u'SurfGroupAndHTSurfNames',
                u'AllShadingAndHTSurfNames'],
        
        },
        {u'AirflowNetworkNodeAndZoneNames': {'ZONE'},
         u'AllHeatTranAngFacNames': {'BUILDINGSURFACE:DETAILED',
          'FENESTRATIONSURFACE:DETAILED',
          'WALL:EXTERIOR',
          'WINDOW'},
         u'AllHeatTranSurfNames': {'BUILDINGSURFACE:DETAILED',
          'FENESTRATIONSURFACE:DETAILED',
          'WALL:EXTERIOR',
          'WINDOW'},
         u'AllShadingAndHTSurfNames': {'BUILDINGSURFACE:DETAILED',
          'FENESTRATIONSURFACE:DETAILED',
          'WALL:EXTERIOR',
          'WINDOW'},
         u'HeatTranBaseSurfNames': {'BUILDINGSURFACE:DETAILED', 'WALL:EXTERIOR'},
         u'OutFaceEnvNames': {'BUILDINGSURFACE:DETAILED',
          'FENESTRATIONSURFACE:DETAILED',
          'WINDOW',
          'ZONE'},
         u'RadGroupAndSurfNames': {'BUILDINGSURFACE:DETAILED',
          'FENESTRATIONSURFACE:DETAILED',
          'WALL:EXTERIOR',
          'WINDOW'},
         u'SubSurfNames': {'FENESTRATIONSURFACE:DETAILED', 'WINDOW'},
         u'SurfAndSubSurfNames': {'BUILDINGSURFACE:DETAILED',
          'FENESTRATIONSURFACE:DETAILED',
          'WALL:EXTERIOR',
          'WINDOW'},
         u'SurfGroupAndHTSurfNames': {'BUILDINGSURFACE:DETAILED',
          'FENESTRATIONSURFACE:DETAILED',
          'WALL:EXTERIOR',
          'WINDOW'},
         u'SurfaceNames': {'BUILDINGSURFACE:DETAILED', 'WALL:EXTERIOR'},
         u'ZoneAndZoneListNames': {'ZONE'},
         u'ZoneNames': {'ZONE'}}
    ), # name2refdct, expected
    )
    for name2refdct, expected in thedata:
        result = iddindex.makeref2namesdct(name2refdct)
        assert result == expected