Example #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))
def test_material_lib():
    """Test that the honeybee-energy lib has been extended with new material data."""
    possible_types = (EnergyWindowMaterialGlazing,
                      EnergyWindowMaterialSimpleGlazSys,
                      EnergyWindowMaterialGas, EnergyWindowMaterialGasMixture)

    assert len(
        mat_lib.WINDOW_MATERIALS) > 4  # should now have many more materials

    mat_from_lib = mat_lib.window_material_by_identifier(
        mat_lib.WINDOW_MATERIALS[0])
    assert isinstance(mat_from_lib, possible_types)

    mat_from_lib = mat_lib.window_material_by_identifier(
        mat_lib.WINDOW_MATERIALS[4])
    assert isinstance(mat_from_lib, possible_types)
Example #3
0
def create_EP_const(_win_EP_material):
    """ Creates an 'E+' style construction for the window

    Args:
        _win_EP_material (): The E+ Material for the window
    Returns:
        constr (): The new E+ Construction for the window
    """

    try:  # import the core honeybee dependencies
        from honeybee.typing import clean_and_id_ep_string
    except ImportError as e:
        raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e))

    try:  # import the honeybee-energy dependencies
        from honeybee_energy.construction.window import WindowConstruction
        from honeybee_energy.lib.materials import window_material_by_identifier
    except ImportError as e:
        raise ImportError('\nFailed to import honeybee_energy:\n\t{}'.format(e))
    
    material_objs = []
    for material in [_win_EP_material]:
        if isinstance(material, str):
            material = window_material_by_identifier(material)
        material_objs.append(material)
    
    name = 'PHPP_CONST_{}'.format(_win_EP_material.display_name)

    constr = WindowConstruction(clean_and_id_ep_string(name), material_objs)
    constr.display_name = name

    return constr
def test_window_material_by_identifier():
    """Test that all of the materials in the library can be loaded by identifier."""
    possible_types = (EnergyWindowMaterialGlazing,
                      EnergyWindowMaterialSimpleGlazSys,
                      EnergyWindowMaterialGas, EnergyWindowMaterialGasMixture)

    for mat in mat_lib.WINDOW_MATERIALS:
        mat_from_lib = mat_lib.window_material_by_identifier(mat)
        assert isinstance(mat_from_lib, possible_types)
Example #5
0
def window_material_by_id(material_id, output_file):
    """Get a window material definition from the standards lib with its identifier.
    \n
    Args:
        material_id: The identifier of an window material in the library.
    """
    try:
        output_file.write(json.dumps(window_material_by_identifier(material_id).to_dict()))
    except Exception as e:
        _logger.exception(
            'Retrieval from window material library failed.\n{}'.format(e))
        sys.exit(1)
    else:
        sys.exit(0)
Example #6
0
def from_standards_dict(cls, data):
    """Create a WindowConstruction from an OpenStudio standards gem dictionary.

    Args:
        data: An OpenStudio standards dictionary of a window construction in the
            format below.

    .. code-block:: json

        {
        "name": "ASHRAE 189.1-2009 ExtWindow ClimateZone 4-5",
        "intended_surface_type": "ExteriorWindow",
        "materials": ["Theoretical Glass [207]"]
        }
    """
    materials = tuple(mat_lib.window_material_by_identifier(mat)
                      for mat in data['materials'])
    return cls(data['name'], materials)
Example #7
0
def materials_by_id(material_ids, output_file):
    """Get several material definitions from the standards lib at once.
    \n
    Args:
        material_ids: A list of material identifiers to be retrieved from the library.
    """
    try:
        mats = []
        for mat_id in material_ids:
            try:
                mats.append(opaque_material_by_identifier(mat_id))
            except ValueError:
                mats.append(window_material_by_identifier(mat_id))
        output_file.write(json.dumps([mat.to_dict() for mat in mats]))
    except Exception as e:
        _logger.exception(
            'Retrieval from material library failed.\n{}'.format(e))
        sys.exit(1)
    else:
        sys.exit(0)
Example #8
0
try:  # import the core honeybee dependencies
    from honeybee.typing import clean_and_id_ep_string, clean_ep_string
except ImportError as e:
    raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e))

try:  # import the honeybee-energy dependencies
    from honeybee_energy.construction.window import WindowConstruction
    from honeybee_energy.lib.materials import window_material_by_identifier
except ImportError as e:
    raise ImportError('\nFailed to import honeybee_energy:\n\t{}'.format(e))

try:  # import ladybug_rhino dependencies
    from ladybug_rhino.grasshopper import all_required_inputs
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))


if all_required_inputs(ghenv.Component):
    name = clean_and_id_ep_string('WindowConstruction') if _name_ is None else \
        clean_ep_string(_name_)

    material_objs = []
    for material in _materials:
        if isinstance(material, str):
            material = window_material_by_identifier(material)
        material_objs.append(material)

    constr = WindowConstruction(name, material_objs)
    if _name_ is not None:
        constr.display_name = _name_
    from ladybug_rhino.grasshopper import all_required_inputs
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))
try:
    from ladybug.datatype.rvalue import RValue
    from ladybug.datatype.uvalue import UValue
except ImportError as e:
    raise ImportError('\nFailed to import ladybug:\n\t{}'.format(e))

if all_required_inputs(ghenv.Component):
    # check the input
    if isinstance(_mat, str):
        try:
            _mat = opaque_material_by_identifier(_mat)
        except ValueError:
            _mat = window_material_by_identifier(_mat)

    # get the values and attribute names
    mat_str = str(_mat)
    values = parse_idf_string(mat_str)
    attr_name_pattern1 = re.compile(r'!- (.*)\n')
    attr_name_pattern2 = re.compile(r'!- (.*)$')
    attr_names = attr_name_pattern1.findall(mat_str) + \
        attr_name_pattern2.findall(mat_str)

    # get the r-value
    try:
        r_val_si = _mat.r_value
        r_val_ip = RValue().to_ip([r_val_si], 'm2-K/W')[0][0]
    except AttributeError:
        r_val_si = 'varies'