def test_dict_methods(): """Test JSON serialization methods""" # test first with a continuous annual Wea epw_path = './tests/assets/epw/chicago.epw' wea = Wea.from_epw_file(epw_path) assert wea.to_dict() == Wea.from_dict(wea.to_dict()).to_dict() # then test with a filtered Wea including datetimes in the dict wea_file = './tests/assets/wea/chicago_filtered.wea' wea = Wea.from_file(wea_file) assert wea.to_dict() == Wea.from_dict(wea.to_dict()).to_dict()
def from_dict(cls, input_dict): """Create the sky from a dictionary. Args: input_dict: A python dictionary in the following format .. code-block:: python { 'type': 'SkyMatrix', 'wea': {}, 'north': 0.0 # optional 'density': 1 # optional } """ if 'type' not in input_dict or input_dict['type'] != 'SkyMatrix': raise ValueError('Input dict "type" must be "SkyMatrix".') if 'north' in input_dict: north = input_dict['north'] else: north = 0 if 'density' in input_dict: density = input_dict['density'] else: density = 1 sky = cls(Wea.from_dict(input_dict['wea']), north, density) return sky
def test_import_stat(): """Test to compare import from stat with its dict version.""" stat_path = './tests/assets/stat/chicago.stat' wea_from_stat = Wea.from_stat_file(stat_path) wea_dict = wea_from_stat.to_dict() wea_from_dict = Wea.from_dict(wea_dict) assert wea_from_dict.direct_normal_irradiance.values == \ wea_from_stat.direct_normal_irradiance.values assert wea_from_dict.diffuse_horizontal_irradiance.values == \ wea_from_stat.diffuse_horizontal_irradiance.values
def test_import_epw(): """Test to compare import from epw with its dict version.""" epw_path = './tests/assets/epw/chicago.epw' wea_from_epw = Wea.from_epw_file(epw_path) wea_dict = wea_from_epw.to_dict() wea_from_dict = Wea.from_dict(wea_dict) assert wea_from_dict.direct_normal_irradiance.values == \ wea_from_epw.direct_normal_irradiance.values assert wea_from_dict.diffuse_horizontal_irradiance.values == \ wea_from_epw.diffuse_horizontal_irradiance.values
def from_json(cls, rec_json): """Create sky from json file { "wea": {}, // ladybug wea schema "sky_density": int, // [1] Tregenza Sky, [2] Reinhart Sky, etc. (Default: 1) "north": float, // Angle in degrees between 0-360 to indicate North "hoys": [], // List of hours for generating the sky "mode": int, // Sky mode, integer between 0 and 2 "suffix": string //Suffix for sky matrix } """ wea = Wea.from_dict(rec_json["wea"]) return cls(wea, rec_json["sky_density"], rec_json["north"], rec_json["hoys"], rec_json["mode"], rec_json["suffix"])
def from_dict(cls, input_dict): """Create the sky from a dictionary. Args: input_dict: A python dictionary in the following format .. code-block:: python { 'type': 'SunMatrix', 'wea': {}, 'north': 0.0 # optional } """ if 'type' not in input_dict or input_dict['type'] != 'SunMatrix': raise ValueError('Input dict "type" must be "SunMatrix".') if 'north' in input_dict: sky = cls(Wea.from_dict(input_dict['wea']), input_dict['north']) else: sky = cls(input_dict['wea']) return sky
def test_dict_methods(): """Test JSON serialization methods""" epw_path = './tests/epw/chicago.epw' wea = Wea.from_epw_file(epw_path) assert wea.to_dict() == Wea.from_dict(wea.to_dict()).to_dict()