Exemplo n.º 1
0
def test_to_from_dict_with_states():
    """Test the Aperture from_dict method with radiance properties."""
    ap = Aperture.from_vertices(
        'wall_aperture', [[0, 0, 0], [10, 0, 0], [10, 0, 10], [0, 0, 10]])
    shd1 = StateGeometry.from_vertices(
        'wall_overhang1', [[0, 0, 10], [10, 0, 10], [10, 2, 10], [0, 2, 10]])
    shd2 = StateGeometry.from_vertices(
        'wall_overhang2', [[0, 0, 5], [10, 0, 5], [10, 2, 5], [0, 2, 5]])

    ecglass1 = Glass.from_single_transmittance('ElectrochromicState1', 0.4)
    ecglass2 = Glass.from_single_transmittance('ElectrochromicState2', 0.27)
    ecglass3 = Glass.from_single_transmittance('ElectrochromicState3', 0.14)
    ecglass4 = Glass.from_single_transmittance('ElectrochromicState4', 0.01)

    tint1 = RadianceSubFaceState(ecglass1)
    tint2 = RadianceSubFaceState(ecglass2)
    tint3 = RadianceSubFaceState(ecglass3, [shd1])
    tint4 = RadianceSubFaceState(ecglass4, [shd1.duplicate(), shd2])
    states = (tint1, tint2, tint3, tint4)

    ap.properties.radiance.dynamic_group_identifier = 'ElectrochromicWindow1'
    ap.properties.radiance.states = states
    tint4.gen_geos_from_tmtx_thickness(0.05)

    ad = ap.to_dict()
    new_aperture = Aperture.from_dict(ad)
    assert new_aperture.properties.radiance.dynamic_group_identifier == \
        ap.properties.radiance.dynamic_group_identifier
    state_ids1 = [state.modifier for state in states]
    state_ids2 = [
        state.modifier for state in new_aperture.properties.radiance.states
    ]
    assert state_ids1 == state_ids2
    assert new_aperture.to_dict() == ad
Exemplo n.º 2
0
def test_to_from_dict():
    """Test the to/from dict of Aperture objects."""
    vertices = [[0, 0, 0], [0, 10, 0], [0, 10, 3], [0, 0, 3]]
    ap = Aperture.from_vertices('RectangleWindow', vertices)

    ap_dict = ap.to_dict()
    new_ap = Aperture.from_dict(ap_dict)
    assert isinstance(new_ap, Aperture)
    assert new_ap.to_dict() == ap_dict
Exemplo n.º 3
0
def test_to_from_dict():
    """Test the Aperture from_dict method with states."""
    aperture = Aperture.from_vertices(
        'wall_aperture', [[0, 0, 0], [10, 0, 0], [10, 0, 10], [0, 0, 10]])
    triple_pane = Glass.from_single_transmittance('TriplePane', 0.45)
    aperture.properties.radiance.modifier = triple_pane

    ad = aperture.to_dict()
    new_aperture = Aperture.from_dict(ad)
    assert new_aperture.properties.radiance.modifier == triple_pane
    assert new_aperture.to_dict() == ad
Exemplo n.º 4
0
def test_from_dict():
    """Test the Aperture from_dict method with energy properties."""
    aperture = Aperture.from_vertices(
        'wall_window', [[0, 0, 0], [10, 0, 0], [10, 0, 10], [0, 0, 10]])
    clear_glass = EnergyWindowMaterialGlazing('Clear Glass', 0.005715,
                                              0.770675, 0.07, 0.8836, 0.0804,
                                              0, 0.84, 0.84, 1.0)
    gap = EnergyWindowMaterialGas('air gap', thickness=0.0127)
    triple_pane = WindowConstruction(
        'Triple Pane', [clear_glass, gap, clear_glass, gap, clear_glass])
    aperture.properties.energy.construction = triple_pane

    ad = aperture.to_dict()
    new_aperture = Aperture.from_dict(ad)
    assert new_aperture.properties.energy.construction == triple_pane
    assert new_aperture.to_dict() == ad
Exemplo n.º 5
0
    def from_dict(cls, _dict):
        
        new_obj = cls()
        new_obj.quantity = _dict.get('quantity')
        new_obj._tolerance = _dict.get('_tolerance')
        new_obj.aperture = Aperture.from_dict( _dict.get('aperture') )
        new_obj._shading_factor_winter =_dict.get('_shading_factor_winter')
        new_obj._shading_factor_summer =_dict.get('_shading_factor_summer')
        new_obj._glazing_edge_lengths = _dict.get('_glazing_edge_lengths')
        new_obj.variant_type = _dict.get('variant_type')
        new_obj.install_depth = _dict.get('install_depth')

        #----
        _edges = _dict.get('_window_edges', {})
        _left = _edges.get('Left')
        _left = LineSegment3D.from_dict( _left )

        _right = _edges.get('Right')
        _right = LineSegment3D.from_dict( _right )

        _bottom = _edges.get('Bottom')
        _bottom = LineSegment3D.from_dict( _bottom )

        _top = _edges.get('Top')
        _top = LineSegment3D.from_dict( _top )      
        
        new_obj._window_edges = cls.Output(_left, _right, _bottom, _top)

        #----
        _glazing_surface = _dict.get('_glazing_surface')
        _glazing_surface = Face3D.from_dict(_glazing_surface)
        _glazing_surface = from_face3d(_glazing_surface)
        new_obj._glazing_surface = _glazing_surface

        new_obj.frame = LBT2PH.windows.PHPP_Frame.from_dict( _dict.get('_frame') )
        new_obj.glazing = LBT2PH.windows.PHPP_Glazing.from_dict( _dict.get('_glazing') )
        new_obj.installs = LBT2PH.windows.PHPP_Installs.from_dict( _dict.get('_installs') )
        new_obj.shading_dimensions = LBT2PH.shading.PHPP_Shading_Dims.from_dict( _dict.get('shading_dimensions') )        

        return new_obj
Exemplo n.º 6
0
def dict_to_object(honeybee_dict, raise_exception=True):
    """Re-serialize a dictionary of almost any object within honeybee.

    This includes any Model, Room, Face, Aperture, Door, Shade, or boundary
    condition object.

    Args:
        honeybee_dict: A dictionary of any Honeybee object. 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 part of honeybee.
            Default: True.

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

    if obj_type == 'Model':
        return Model.from_dict(honeybee_dict)
    elif obj_type == 'Room':
        return Room.from_dict(honeybee_dict)
    elif obj_type == 'Face':
        return Face.from_dict(honeybee_dict)
    elif obj_type == 'Aperture':
        return Aperture.from_dict(honeybee_dict)
    elif obj_type == 'Door':
        return Door.from_dict(honeybee_dict)
    elif obj_type == 'Shade':
        return Shade.from_dict(honeybee_dict)
    elif hasattr(hbc, obj_type):
        bc_class = getattr(hbc, obj_type)
        return bc_class.from_dict(honeybee_dict)
    elif raise_exception:
        raise ValueError(
            '{} is not a recognized honeybee object'.format(obj_type))