def dict_to_simulation(sim_dict, raise_exception=True): """Get a Python object of any Simulation object from a dictionary. Args: sim_dict: A dictionary of any Honeybee energy simulation 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 simulation object. Default: True. Returns: A Python object derived from the input sim_dict. """ try: # get the type key from the dictionary sim_type = sim_dict['type'] except KeyError: raise ValueError('Simulation dictionary lacks required "type" key.') if sim_type == 'SimulationControl': return SimulationControl.from_dict(sim_dict) elif sim_type == 'RunPeriod': return RunPeriod.from_dict(sim_dict) elif sim_type == 'DaylightSavingTime': return DaylightSavingTime.from_dict(sim_dict) elif sim_type == 'ShadowCalculation': return ShadowCalculation.from_dict(sim_dict) elif sim_type == 'SizingParameter': return SizingParameter.from_dict(sim_dict) elif sim_type == 'SimulationOutput': return SimulationOutput.from_dict(sim_dict) elif sim_type == 'SimulationParameter': return SimulationParameter.from_dict(sim_dict) elif raise_exception: raise ValueError( '{} is not a recognized energy Simulation type'.format(sim_type))
def test_simulation_control_dict_methods(): """Test the to/from dict methods.""" sizing = SizingParameter(1) sizing_dict = sizing.to_dict() new_sizing = SizingParameter.from_dict(sizing_dict) assert new_sizing == sizing assert sizing_dict == new_sizing.to_dict()
def test_sizing_parameter_dict_methods(): """Test the to/from dict methods.""" sizing = SizingParameter(None, 1) relative_path = './tests/ddy/chicago.ddy' sizing.add_from_ddy_996_004(relative_path) sizing_dict = sizing.to_dict() new_sizing = SizingParameter.from_dict(sizing_dict) new_sizing.apply_location(sizing[0].location) assert new_sizing == sizing assert sizing_dict == new_sizing.to_dict()