예제 #1
0
def window_construction_by_identifier(construction_identifier):
    """Get an window construction from the library given the construction identifier.

    Args:
        construction_identifier: A text string for the identifier of the construction.
    """
    try:
        return _window_constructions[construction_identifier]
    except KeyError:
        try:  # search the extension data
            constr_dict = _window_constr_standards_dict[
                construction_identifier]
            if constr_dict['type'] == 'WindowConstructionAbridged':
                mats = {}
                for mat in constr_dict['layers']:
                    mats[mat] = _m.window_material_by_identifier(mat)
                return WindowConstruction.from_dict_abridged(constr_dict, mats)
            else:  # WindowConstructionShade
                mats = {}
                for mat in constr_dict['window_construction']['layers']:
                    mats[mat] = _m.window_material_by_identifier(mat)
                shd_mat = constr_dict['shade_material']
                mats[shd_mat] = _m.window_material_by_identifier(shd_mat)
                try:
                    sch_id = constr_dict['schedule']
                    schs = {sch_id: _s.schedule_by_identifier(sch_id)}
                except KeyError:  # no schedule key provided
                    schs = {}
                return WindowConstructionShade.from_dict_abridged(
                    constr_dict, mats, schs)
        except KeyError:  # construction is nowhere to be found; raise an error
            raise ValueError(
                '"{}" was not found in the window energy construction library.'
                .format(construction_identifier))
예제 #2
0
def dict_abridged_to_construction(constr_dict,
                                  materials,
                                  schedules,
                                  raise_exception=True):
    """Get a Python object of any Construction from an abridged dictionary.

    Args:
        constr_dict: An abridged dictionary of any Honeybee energy construction.
        materials: Dictionary of all material objects that might be used in the
            construction with the material identifiers as the keys.
        schedules: Dictionary of all schedule objects that might be used in the
            construction with the schedule identifiers as the keys.
        raise_exception: Boolean to note whether an excpetion should be raised
            if the object is not identified as a construction. Default: True.

    Returns:
        A Python object derived from the input constr_dict.
    """
    try:  # get the type key from the dictionary
        constr_type = constr_dict['type']
    except KeyError:
        raise ValueError('Construction dictionary lacks required "type" key.')

    if constr_type == 'OpaqueConstructionAbridged':
        return OpaqueConstruction.from_dict_abridged(constr_dict, materials)
    elif constr_type == 'WindowConstructionAbridged':
        return WindowConstruction.from_dict_abridged(constr_dict, materials)
    elif constr_type == 'WindowConstructionShade':
        return WindowConstructionShade.from_dict_abridged(
            constr_dict, materials, schedules)
    elif constr_type == 'ShadeConstruction':
        return ShadeConstruction.from_dict(constr_dict)
    elif constr_type == 'AirBoundaryConstructionAbridged':
        return AirBoundaryConstruction.from_dict_abridged(
            constr_dict, schedules)
    elif constr_type == 'AirBoundaryConstruction':  # special case for ConstructionSet
        return AirBoundaryConstruction.from_dict(constr_dict)
    elif raise_exception:
        raise ValueError(
            '{} is not a recognized energy Construction type'.format(
                constr_type))