def test_to_from_dict_with_states(): """Test the Shade from_dict method with radiance properties.""" pts = (Point3D(0, 0, 0), Point3D(0, 0, 3), Point3D(1, 0, 3), Point3D(1, 0, 0)) shd = Shade('TreeTrunk', Face3D(pts)) shd1 = StateGeometry.from_vertices( 'tree_foliage1', [[0, 0, 5], [2, 0, 5], [2, 2, 5], [0, 2, 5]]) shd2 = StateGeometry.from_vertices( 'tree_foliage2', [[0, 0, 5], [-2, 0, 5], [-2, 2, 5], [0, 2, 5]]) trans1 = Glass.from_single_transmittance('TreeTrans1', 0.5) trans2 = Glass.from_single_transmittance('TreeTrans2', 0.27) trans3 = Glass.from_single_transmittance('TreeTrans3', 0.14) trans4 = Glass.from_single_transmittance('TreeTrans4', 0.01) tr1 = RadianceShadeState(trans1) tr2 = RadianceShadeState(trans2) tr3 = RadianceShadeState(trans3, [shd1]) tr4 = RadianceShadeState(trans4, [shd1.duplicate(), shd2]) states = (tr1, tr2, tr3, tr4) shd.properties.radiance.dynamic_group_identifier = 'DeciduousTrees' shd.properties.radiance.states = states ad = shd.to_dict() new_shade = Shade.from_dict(ad) assert new_shade.properties.radiance.dynamic_group_identifier == \ shd.properties.radiance.dynamic_group_identifier state_ids1 = [state.modifier for state in states] state_ids2 = [ state.modifier for state in new_shade.properties.radiance.states ] assert state_ids1 == state_ids2 assert new_shade.to_dict() == ad
def test_to_from_dict(): """Test the to/from dict of Shade objects.""" vertices = [[0, 0, 0], [0, 10, 0], [0, 10, 3], [0, 0, 3]] shd = Shade.from_vertices('RectangleShade', vertices, True) shd_dict = shd.to_dict() new_shd = Shade.from_dict(shd_dict) assert isinstance(new_shd, Shade) assert new_shd.to_dict() == shd_dict
def test_from_dict(): """Test the Shade from_dict method with radiance properties.""" shade = Shade.from_vertices( 'tree', [[0, 0, 0], [10, 0, 0], [10, 0, 10], [0, 0, 10]]) foliage = Glass.from_single_transmittance('Foliage', 0.2) shade.properties.radiance.modifier = foliage shdd = shade.to_dict() new_shade = Shade.from_dict(shdd) assert new_shade.properties.radiance.modifier == foliage assert new_shade.to_dict() == shdd
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))
def test_from_dict(): """Test the Shade from_dict method with energy properties.""" verts = [ Point3D(0, 0, 0), Point3D(1, 0, 0), Point3D(1, 0, 3), Point3D(0, 0, 3) ] shade = Shade('overhang', Face3D(verts)) light_shelf = ShadeConstruction('Light Shelf', 0.5, 0.5, True) shade.properties.energy.construction = light_shelf fritted_glass_trans = ScheduleRuleset.from_constant_value( 'Fritted Glass', 0.5, schedule_types.fractional) shade.properties.energy.transmittance_schedule = fritted_glass_trans shade_dict = shade.to_dict() new_shade = Shade.from_dict(shade_dict) assert new_shade.properties.energy.construction == light_shelf assert shade.properties.energy.construction.solar_reflectance == 0.5 assert shade.properties.energy.construction.visible_reflectance == 0.5 assert shade.properties.energy.construction.is_specular assert new_shade.properties.energy.transmittance_schedule == fritted_glass_trans assert new_shade.to_dict() == shade_dict