def test_from_dict_vent_opening(): """Test the Room2D from_dict method with ventilation opening energy properties.""" pts = (Point3D(0, 0, 3), Point3D(10, 0, 3), Point3D(10, 10, 3), Point3D(0, 10, 3)) ashrae_base = SimpleWindowRatio(0.4) room = Room2D('SquareShoebox', Face3D(pts), 3) room.set_outdoor_window_parameters(ashrae_base) ventilation = VentilationControl() ventilation.min_indoor_temperature = 22 ventilation.max_indoor_temperature = 28 ventilation.min_outdoor_temperature = 12 ventilation.max_outdoor_temperature = 32 ventilation.delta_temperature = 0 opening = VentilationOpening() opening.fraction_area_operable = 0.25 opening.fraction_height_operable = 0.5 opening.wind_cross_vent = True room.properties.energy.window_vent_control = ventilation room.properties.energy.window_vent_opening = opening rd = room.to_dict() new_room = Room2D.from_dict(rd) assert new_room.to_dict() == rd
def test_to_from_dict(): """Test the to/from dict of Room2D objects.""" pts = (Point3D(0, 0, 3), Point3D(5, 0, 3), Point3D(5, 10, 3), Point3D(0, 10, 3)) ashrae_base = SimpleWindowRatio(0.4) overhang = Overhang(1) boundarycs = (bcs.outdoors, bcs.ground, bcs.outdoors, bcs.ground) window = (ashrae_base, None, ashrae_base, None) shading = (overhang, None, None, None) room = Room2D('ShoeBoxZone', Face3D(pts), 3, boundarycs, window, shading, True) room_dict = room.to_dict() new_room = Room2D.from_dict(room_dict) assert isinstance(new_room, Room2D) assert new_room.to_dict() == room_dict
def test_from_dict(): """Test the Room2D from_dict method with energy properties.""" pts = (Point3D(0, 0, 3), Point3D(10, 0, 3), Point3D(10, 10, 3), Point3D(0, 10, 3)) ashrae_base = SimpleWindowRatio(0.4) room = Room2D('SquareShoebox', Face3D(pts), 3) room.set_outdoor_window_parameters(ashrae_base) mass_set = ConstructionSet('Thermal Mass Construction Set') room.properties.energy.construction_set = mass_set rd = room.to_dict() new_room = Room2D.from_dict(rd) assert new_room.properties.energy.construction_set.identifier == \ 'Thermal Mass Construction Set' assert new_room.to_dict() == rd
def dict_to_object(dragonfly_dict, raise_exception=True): """Re-serialize a dictionary of almost any object within dragonfly. This includes any Model, Building, Story, Room2D, WindowParameter, ShadingParameter, and boundary conditions. Args: dragonfly_dict: A dictionary of any Dragonfly 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 dragonfly. Default: True. Returns: A Python object derived from the input dragonfly_dict. """ try: # get the type key from the dictionary obj_type = dragonfly_dict['type'] except KeyError: raise ValueError('Dragonfly dictionary lacks required "type" key.') if obj_type == 'Model': return Model.from_dict(dragonfly_dict) elif obj_type == 'Building': return Building.from_dict(dragonfly_dict) elif obj_type == 'Story': return Story.from_dict(dragonfly_dict) elif obj_type == 'Room2D': return Room2D.from_dict(dragonfly_dict) elif obj_type == 'ContextShade': return ContextShade.from_dict(dragonfly_dict) elif hasattr(dfw, obj_type): win_class = getattr(dfw, obj_type) return win_class.from_dict(dragonfly_dict) elif hasattr(dfs, obj_type): shd_class = getattr(dfs, obj_type) return shd_class.from_dict(dragonfly_dict) elif hasattr(hbc, obj_type): bc_class = getattr(hbc, obj_type) return bc_class.from_dict(dragonfly_dict) elif raise_exception: raise ValueError( '{} is not a recognized dragonfly object'.format(obj_type))