def test_init_func(self): """Test normal init function.""" slh = SolarAccessGridBased(self.sun_vectors, self.test_pts, self.test_vec) slh.write_to_file(self.base_folder, project_name="test") if slh.run(): self.assertEqual(slh.results(), [4])
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_cls_method_hoy(self): """Make sure default values are set correctly.""" location = EPW(self.epwfile).location hoys = range(1, 24) slh = SolarAccessGridBased.fromLocationAndHoys( location, hoys, self.test_pts, self.test_vec) slh.write_to_file(self.base_folder, project_name="test") if slh.run(): self.assertEqual(slh.results(), [4])
def test_cls_method_analysis_period(self): """Make sure default values are set correctly.""" location = EPW(self.epwfile).location ap = AnalysisPeriod(st_month=1, end_month=3) slh = SolarAccessGridBased.fromLocationAndAnalysisPeriod( location, ap, self.test_pts, self.test_vec) slh.write_to_file(self.base_folder, project_name="test") if slh.run(): self.assertEqual(slh.results(), [475])
def test_cls_method_hoy(self): """Make sure default values are set correctly.""" location = EPW(self.epwfile).location hoys = range(1, 24) slh = SolarAccessGridBased.fromLocationAndHoys(location, hoys, self.test_pts, self.test_vec) slh.write_to_file(self.base_folder, project_name="test") if slh.run(): self.assertEqual(slh.results(), [4])
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, ())
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::[*]"
# assign inputs _sunVectors, _hoys, _analysisGrids, _timestep_ = IN analysisRecipe = None try: from honeybee.radiance.recipe.solaraccess.gridbased import SolarAccessGridBased except ImportError as e: raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e)) if _sunVectors and _sunVectors[0] != None and \ _hoys and _hoys[0] != None and _analysisGrids: # set a sunlight hours analysis recipe together if there are points analysisRecipe = SolarAccessGridBased(_sunVectors, _hoys, _analysisGrids, _timestep_) # assign outputs to OUT OUT = (analysisRecipe, )
def generateAnalysis(test_points, pts_vectors, name, window_groups, sun_vectors, hoys, timestep, hb_object_ids, hb_object_types, hb_object_mats, folder, filename, save_file_only, grid_mesh): try: analysis_grids = AnalysisGrid.from_points_and_vectors( test_points, pts_vectors, name, window_groups) #get analysis recipe analysis_recipe = None if sun_vectors and sun_vectors[0] != None and \ hoys and hoys[0] != None and analysis_grids: # set a sunlight hours analysis recipe together if there are points analysis_recipe = SolarAccessGridBased(sun_vectors, hoys, [analysis_grids], timestep) else: print "missing sun vector data" return #HB surfaces #convert scene hb objects into rhino common geo_list = [] for id in hb_object_ids: if rs.IsBrep(id): geo_list += [rc.DocObjects.ObjRef(id).Brep()] elif rs.IsMesh(id): geo_list += [rc.DocObjects.ObjRef(id).Mesh()] else: continue #preapre paramters if len(geo_list) != 0 and geo_list[0] != None: names = None #not included yet in eto interface (could use scene object name) hb_objects = [] for index, geo in enumerate(geo_list): type = hb_object_types[index] radMat = hb_object_mats[index] isNameSetByUser = False if names: isNameSetByUser = True isTypeSetByUser = True if not type: isTypeSetByUser = False rad_prop = RadianceProperties( radMat) if radMat else RadianceProperties() ep_prop = None if radMat and radMat.__class__.__name__ == 'Plastic': hb_objects += HBSurface.from_geometry( names, geo, type, isNameSetByUser, isTypeSetByUser, rad_prop, ep_prop) elif radMat and radMat.__class__.__name__ == 'Glass': hb_objects += HBFenSurface.from_geometry( names, geo, isNameSetByUser, rad_prop, ep_prop) else: print "No valid HB surfaces selected" return # Run analysis rad_scene = None if not hb_objects or not analysis_recipe: print "Missing HB objects or analysis recipe" return try: for obj in hb_objects: assert hasattr(obj, 'isHBObject') except AssertionError: raise ValueError( "\n{} is not a valid Honeybee object.".format(obj)) assert hasattr(analysis_recipe, 'isAnalysisRecipe'), \ ValueError("\n{} is not a Honeybee recipe.".format(analysis_recipe)) legend_par = analysis_recipe.legend_parameters #write to file # Add Honeybee objects to the recipe analysis_recipe.hb_objects = hb_objects analysis_recipe.scene = rad_scene batch_file = analysis_recipe.write(folder, filename) #run if 'save file only' is not checked outputs = None if not save_file_only: if analysis_recipe.run(batch_file, False): try: outputs = analysis_recipe.results() except StopIteration: raise ValueError( 'Length of the results is smaller than the analysis grids ' 'point count [{}]. In case you have changed the analysis' ' Grid you must re-calculate daylight/view matrix!' .format(analysis_recipe.total_point_count)) if outputs: LadybugEto.displayAnalysis(grid_mesh, outputs, legend_par, filename) except Exception as e: print e
vectors are looking downwards from the sun (e.g. z < 0). _hoys: A list of hours of the year. _analysis_grids: List of honeybee analysis grids. Use Analysis grid component which you can find under 00 :: Create to create them. _timestep_: Timstep for sun vectors. Default is 1 which means each sun vector represents an hour of time. Returns: readMe!: Reports, errors, warnings, etc. analysis_recipe: Sunlight hours analysis recipe. Connect this recipe to Run Radiance Simulation to run a sunlight hours analysis. """ ghenv.Component.Name = "HoneybeePlus_Solar Access Recipe" ghenv.Component.NickName = 'solarAccessRecipe' ghenv.Component.Message = 'VER 0.0.05\nOCT_22_2018' ghenv.Component.Category = "HoneybeePlus" ghenv.Component.SubCategory = '03 :: Daylight :: Recipe' ghenv.Component.AdditionalHelpFromDocStrings = "1" try: from honeybee.radiance.recipe.solaraccess.gridbased import SolarAccessGridBased except ImportError as e: raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e)) if _sun_vectors and _sun_vectors[0] is not None and \ _hoys and _hoys[0] is not None and _analysis_grids \ and _analysis_grids[0] is not None: # set a sunlight hours analysis recipe together if there are points analysis_recipe = SolarAccessGridBased( _sun_vectors, _hoys, _analysis_grids, _timestep_)