Example #1
0
def test_to_from_dict_with_states():
    """Test the Door from_dict method with radiance properties."""
    dr = Door.from_vertices('front_door',
                            [[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)

    dr.properties.radiance.dynamic_group_identifier = 'ElectrochromicDoor1'
    dr.properties.radiance.states = states

    drd = dr.to_dict()
    new_door = Door.from_dict(drd)
    assert new_door.properties.radiance.dynamic_group_identifier == \
        dr.properties.radiance.dynamic_group_identifier
    state_ids1 = [state.modifier for state in states]
    state_ids2 = [
        state.modifier for state in new_door.properties.radiance.states
    ]
    assert state_ids1 == state_ids2
    assert new_door.to_dict() == drd
Example #2
0
def test_to_from_dict():
    """Test the to/from dict of Door objects."""
    vertices = [[0, 0, 0], [0, 10, 0], [0, 10, 3], [0, 0, 3]]
    dr = Door.from_vertices('RectangleDoor', vertices)

    dr_dict = dr.to_dict()
    new_dr = Door.from_dict(dr_dict)
    assert isinstance(new_dr, Door)
    assert new_dr.to_dict() == dr_dict
Example #3
0
def test_from_dict():
    """Test the Door from_dict method with radiance properties."""
    door = Door.from_vertices('wall_door',
                              [[0, 0, 0], [10, 0, 0], [10, 0, 10], [0, 0, 10]])
    painted_door = Plastic.from_single_reflectance('PaintedDoor', 0.75)
    door.properties.radiance.modifier = painted_door

    ad = door.to_dict()
    new_door = Door.from_dict(ad)
    assert new_door.properties.radiance.modifier == painted_door
    assert new_door.to_dict() == ad
Example #4
0
def test_from_dict():
    """Test the Door from_dict method with energy properties."""
    door = Door.from_vertices('front door',
                              [[0, 0, 0], [10, 0, 0], [10, 0, 10], [0, 0, 10]])
    concrete5 = EnergyMaterial('5cm Concrete', 0.05, 2.31, 2322, 832,
                               'MediumRough', 0.95, 0.75, 0.8)
    mass_constr = OpaqueConstruction('Concrete Door', [concrete5])
    door.properties.energy.construction = mass_constr

    drd = door.to_dict()
    new_door = Door.from_dict(drd)
    assert new_door.properties.energy.construction == mass_constr
    assert new_door.to_dict() == drd
Example #5
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))