Example #1
0
def construction_from_idf(construction_idf, output_file):
    """Translate a Construction IDF file to a honeybee JSON as an array of constructions.

    \b
    Args:
        construction_idf: Full path to a Construction IDF file. Only the constructions
            and materials in this file will be extracted.
    """
    try:
        # re-serialize the Constructions to Python
        opaque_constrs = OpaqueConstruction.extract_all_from_idf_file(construction_idf)
        win_constrs = WindowConstruction.extract_all_from_idf_file(construction_idf)

        # create the honeybee dictionaries
        hb_obj_list = []
        for constr in opaque_constrs[0]:
            hb_obj_list.append(constr.to_dict())
        for constr in win_constrs[0]:
            hb_obj_list.append(constr.to_dict())

        # write out the JSON file
        output_file.write(json.dumps(hb_obj_list))
    except Exception as e:
        _logger.exception('Construction translation failed.\n{}'.format(e))
        sys.exit(1)
    else:
        sys.exit(0)
Example #2
0
def test_window_construction_init_from_idf_file():
    """Test the initalization of WindowConstruction from file."""
    lbnl_window_idf_file = './tests/idf/GlzSys_Triple Clear_Avg.idf'
    glaz_constrs, glaz_mats = WindowConstruction.extract_all_from_idf_file(
        lbnl_window_idf_file)

    assert len(glaz_mats) == 2
    glaz_constr = glaz_constrs[0]
    constr_str = glaz_constr.to_idf()
    mat_str = [mat.to_idf() for mat in glaz_constr.unique_materials]
    new_glaz_constr = WindowConstruction.from_idf(constr_str, mat_str)
    new_constr_str = new_glaz_constr.to_idf()

    assert glaz_constr.name == new_glaz_constr.name == 'GlzSys_5'
    assert glaz_constr.u_factor == new_glaz_constr.u_factor == \
        pytest.approx(1.75728, rel=1e-2)
    assert glaz_constr.thickness == new_glaz_constr.thickness == \
        pytest.approx(0.0425, rel=1e-2)
    assert constr_str == new_constr_str
import os

# empty dictionaries to hold idf-loaded materials and constructions
_idf_opaque_materials = {}
_idf_window_materials = {}
_idf_opaque_constructions = {}
_idf_window_constructions = {}

# load materials and constructions from the default and user-supplied files
cur_dir = os.path.dirname(__file__)
construction_lib = os.path.join(cur_dir, 'library', 'constructions')
for f in os.listdir(construction_lib):
    f_path = os.path.join(construction_lib, f)
    if os.path.isfile(f_path) and f_path.endswith('.idf'):
        constructions, materials = OpaqueConstruction.extract_all_from_idf_file(
            f_path)
        for mat in materials:
            mat.lock()
            _idf_opaque_materials[mat.name] = mat
        for cnstr in constructions:
            cnstr.lock()
            _idf_opaque_constructions[cnstr.name] = cnstr
        constructions, materials = WindowConstruction.extract_all_from_idf_file(
            f_path)
        for mat in materials:
            mat.lock()
            _idf_window_materials[mat.name] = mat
        for cnstr in constructions:
            cnstr.lock()
            _idf_window_constructions[cnstr.name] = cnstr