def test_cls_method_hoy(self): """Make sure default values are set correctly.""" location = EPW(self.epwfile).location hoys = range(1, 24) slh = SolarAccessGridBased.from_location_and_hoys( location, hoys, [self.test_pts], [self.test_vec]) bat = slh.write(self.base_folder, project_name="test") sh = bat_to_sh(bat) # start to run the subprocess if os.name == 'nt': success = slh.run(bat) else: success = slh.run(sh) if success: ag = slh.results()[0] for sensor in ag: value = sum(v[0] for v in sensor.combined_values_by_id(sensor.hoys)) assert value == 10
def run_from_json(recipe, folder, name): """Create a python recipe from json object and run the analysis.""" if recipe["id"] == 0: rec = SolarAccessGridBased.fromJson(recipe) elif recipe["id"] == 1: rec = GridBased.fromJson(recipe) else: raise ValueError( "Invalid id input {}. " "Currently only the id of [0] SolarAccess and [1] pointintime are supported!" .format(recipe['id'])) # generate bat file bat = rec.write(folder, name) # Convert bat to sh sh = bat_to_sh(bat) # import pdb; pdb.set_trace() # start to run the subprocess if os.name == 'nt': success = rec.run(bat) else: success = rec.run(sh) # run post-processing code if success: return (True, [r.toJson() for r in rec.results()]) else: return (False, ())
def test_init_func(self): """Test normal init function.""" slh = SolarAccessGridBased(self.sun_vectors, self.hoys, [self.analysis_grid]) bat = slh.write(self.base_folder, project_name="test") sh = bat_to_sh(bat) # start to run the subprocess if os.name == 'nt': success = slh.run(bat) else: success = slh.run(sh) if success: assert slh.results()[0].ToString( ) == "AnalysisGrid::test_grid::#3::[*]"
def run_from_json(recipe, folder, name): """Create a python recipe from json object and run the analysis.""" if recipe["type"] == "gridbased": if recipe["id"] == "solar_access": rec = SolarAccessGridBased.from_json(recipe) elif recipe["id"] == "point_in_time": rec = PITGridBased.from_json(recipe) elif recipe["id"] == "daylight_factor": rec = DFGridBased.from_json(recipe) elif recipe["id"] == "annual": raise NotImplementedError( "Annual recipe is not supported use daylightcoeff recipe instead." ) elif recipe["id"] == "daylight_coeff": rec = DCGridBased.from_json(recipe) else: raise NotImplementedError( "{} {} recipe is not supported yet.".format( recipe['type'], recipe['id'])) else: raise NotImplementedError("{} {} recipe is not supported yet.".format( recipe['type'], recipe['id'])) # generate bat file bat = rec.write(folder, name) # Convert bat to sh sh = bat_to_sh(bat) # start to run the subprocess if os.name == 'nt': success = rec.run(bat) else: success = rec.run(sh) # run post-processing code if success: return (True, [r.to_json() for r in rec.results()]) else: return (False, ())
# Load analysis grids analysis_grid = load_json(analysis_grid_path) zone_name = analysis_grid["analysis_grids"][0]["name"] print("Analysis grid_file for {0:} loaded from {1:}\n".format(zone_name, analysis_grid_path)) # Set configurations annual_config = {"type": "gridbased", "id": "annual", "simulation_type": 0, "rad_parameters": {"gridbased_parameters": quality}} df_config = {"type": "gridbased", "id": "daylight_factor", "rad_parameters": {"gridbased_parameters": quality}} # Prepare Daylight Factor recipe from JSON origin string df_recipe_json = {k: v for d in [df_config, analysis_grid, surfaces] for k, v in d.items()} df_recipe = GridBased_DaylightFactor.from_json(df_recipe_json) print("Daylight Factor recipe prepared\n") df_bat_file = df_recipe.write(str(df_recipe.analysis_grids[0].name), "daylightfactor") df_shell_file = bat_to_sh(df_bat_file) print("Daylight Factor recipe converted to Radiance case\n") # Run Daylight Factor simulation if "win" in sys.platform.lower() and "dar" not in sys.platform.lower(): df_recipe.run(df_bat_file, False) else: df_recipe.run(df_shell_file, False) # Prepare Annual recipe from JSON origin string annual_recipe_json = {k: v for d in [annual_config, analysis_grid, surfaces, sky_mtx] for k, v in d.items()} annual_recipe = GridBased_Annual.from_json(annual_recipe_json) print("Annual recipe prepared\n") annual_bat_file = annual_recipe.write(str(annual_recipe.analysis_grids[0].name), "annual") annual_shell_file = bat_to_sh(annual_bat_file)