Esempio n. 1
0
def dict_to_construction(constr_dict, raise_exception=True):
    """Get a Python object of any Construction from a dictionary.

    Args:
        constr_dict: A dictionary of any Honeybee energy construction. Note
            that this should be a non-abridged dictionary to be valid.
        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 == 'OpaqueConstruction':
        return OpaqueConstruction.from_dict(constr_dict)
    elif constr_type == 'WindowConstruction':
        return WindowConstruction.from_dict(constr_dict)
    elif constr_type == 'WindowConstructionShade':
        return WindowConstructionShade.from_dict(constr_dict)
    elif constr_type == 'ShadeConstruction':
        return ShadeConstruction.from_dict(constr_dict)
    elif constr_type == 'AirBoundaryConstruction':
        return AirBoundaryConstruction.from_dict(constr_dict)
    elif raise_exception:
        raise ValueError(
            '{} is not a recognized energy Construction type'.format(
                constr_type))
Esempio n. 2
0
    def from_dict(cls, data, host):
        """Create ContextShadeEnergyProperties from a dictionary.

        Note that the dictionary must be a non-abridged version for this
        classmethod to work.

        Args:
            data: A dictionary representation of ContextShadeEnergyProperties.
            host: A ContextShade object that hosts these properties.
        """
        assert data['type'] == 'ContextShadeEnergyProperties', \
            'Expected ContextShadeEnergyProperties. Got {}.'.format(data['type'])

        new_prop = cls(host)
        if 'construction' in data and data['construction'] is not None:
            new_prop.construction = ShadeConstruction.from_dict(
                data['construction'])
        if 'transmittance_schedule' in data and \
                data['transmittance_schedule'] is not None:
            sch_dict = data['transmittance_schedule']
            if sch_dict['type'] == 'ScheduleRuleset':
                new_prop.transmittance_schedule = \
                    ScheduleRuleset.from_dict(data['transmittance_schedule'])
            elif sch_dict['type'] == 'ScheduleFixedInterval':
                new_prop.transmittance_schedule = \
                    ScheduleFixedInterval.from_dict(data['transmittance_schedule'])
            else:
                raise ValueError(
                    'Expected non-abridged Schedule dictionary for ContextShade '
                    'transmittance_schedule. Got {}.'.format(sch_dict['type']))
        return new_prop
Esempio n. 3
0
def shade_construction_by_identifier(construction_identifier):
    """Get an shade construction from the library given the construction identifier.

    Args:
        construction_identifier: A text string for the identifier of the construction.
    """
    try:
        return _shade_constructions[construction_identifier]
    except KeyError:
        try:  # search the extension data
            constr_dict = _shade_constr_standards_dict[construction_identifier]
            return ShadeConstruction.from_dict(constr_dict)
        except KeyError:  # construction is nowhere to be found; raise an error
            raise ValueError(
                '"{}" was not found in the shade energy construction library.'.
                format(construction_identifier))
Esempio n. 4
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))
Esempio n. 5
0
def test_construction_from_lib():
    """Test the existence of construction objects in the library."""
    runner = CliRunner()

    result = runner.invoke(opaque_material_by_id, ['Generic Gypsum Board'])
    assert result.exit_code == 0
    mat_dict = json.loads(result.output)
    assert isinstance(EnergyMaterial.from_dict(mat_dict), EnergyMaterial)

    result = runner.invoke(window_material_by_id, ['Generic Low-e Glass'])
    assert result.exit_code == 0
    mat_dict = json.loads(result.output)
    assert isinstance(EnergyWindowMaterialGlazing.from_dict(mat_dict),
                      EnergyWindowMaterialGlazing)

    result = runner.invoke(opaque_construction_by_id,
                           ['Generic Exterior Wall'])
    assert result.exit_code == 0
    con_dict = json.loads(result.output)
    assert isinstance(OpaqueConstruction.from_dict(con_dict),
                      OpaqueConstruction)

    result = runner.invoke(window_construction_by_id, ['Generic Double Pane'])
    assert result.exit_code == 0
    con_dict = json.loads(result.output)
    assert isinstance(WindowConstruction.from_dict(con_dict),
                      WindowConstruction)

    result = runner.invoke(shade_construction_by_id, ['Generic Context'])
    assert result.exit_code == 0
    mat_dict = json.loads(result.output)
    assert isinstance(ShadeConstruction.from_dict(mat_dict), ShadeConstruction)

    result = runner.invoke(construction_set_by_id,
                           ['Default Generic Construction Set'])
    assert result.exit_code == 0
    con_dict = json.loads(result.output)
    assert isinstance(ConstructionSet.from_dict(con_dict), ConstructionSet)
Esempio n. 6
0
def test_shade_dict_methods():
    """Test the to/from dict methods."""
    shade_constr = ShadeConstruction('Outdoor Light Shelf', 0.4, 0.6)
    constr_dict = shade_constr.to_dict()
    new_constr = ShadeConstruction.from_dict(constr_dict)
    assert constr_dict == new_constr.to_dict()