def setUp(self): """Set up the test case by initiating the class.""" # create a sky to be able to initiate gridbased module sky = radSky(1000) points = [(0,0,0),(1,1,0),(3,2,0)] analysis_grid = AnalysisGrid.from_points_and_vectors(points) self.rp = GridBased(sky, analysis_grids = [analysis_grid])
def setUp(self): """Set up the test case by initiating the class.""" self.test_pts = [(0, 0, 0), (1, 1, 0), (3, 2, 0)] self.test_vec = [(0, 0, 1), (0, 0, 1), (0, 0, 1)] self.analysis_grid = AnalysisGrid.from_points_and_vectors( self.test_pts, self.test_vec, 'test_grid') self.hoys = [1908, 2000, 2530, 3254, 3658, 4000, 4116, 6324, 8508] self.sun_vectors = [(-0.810513, 0.579652, -0.084093), (-0.67166, 0.702357, -0.235729), (-0.487065, 0.798284, -0.354275), (-0.269301, 0.8609, -0.431657), (-0.033196, 0.885943, -0.462605), (0.20517, 0.871705, -0.445013), (0.429563, 0.819156, -0.380077), (0.624703, 0.731875, -0.272221), (0.777301, 0.615806, -0.128788)] self.base_folder = os.path.abspath("tests/room/testrun") self.run_folder = os.path.abspath( "tests/room/testrun/test/solaraccess") self.command = os.path.abspath( "tests/room/testrun/test/solaraccess/commands.bat") self.epwfile = os.path.abspath("tests/room/test.epw")
# assign inputs _name_, _testPoints, ptsVectors_, wGroups_ = IN analysisGrid = None try: from honeybee.radiance.analysisgrid import AnalysisGrid except ImportError as e: raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e)) if _testPoints: analysisGrid = AnalysisGrid.fromPointsAndVectors(_testPoints, ptsVectors_, _name_, wGroups_) # assign outputs to OUT OUT = (analysisGrid, )
_test_points: A list or a datatree of points. Each branch of the datatree will be considered as a point group. pts_vectors_: A list or a datatree of vectors. Each vector represents the direction of the respective test point in testPoints. If only one value is provided it will be used for all the test points. If no value is provided (0, 0, 1) will be assigned for all the vectors. w_groups_: An optional list of window groups. This input is only important for multi-phase daylight simulation to avoid unnecessary view matrix calculations. If this input is left empty for multi-phase daylight recipes the view matrix will be calculated for each analysis grid and every window group. Returns: readMe!: Reports, errors, warnings, etc. analysis_grid: Use this analysis grid to create a grid-based analysis. """ ghenv.Component.Name = "HoneybeePlus_Analysis Grid" ghenv.Component.NickName = 'analysisGrid' ghenv.Component.Message = 'VER 0.0.05\nOCT_22_2018' ghenv.Component.Category = "HoneybeePlus" ghenv.Component.SubCategory = '00 :: Create' ghenv.Component.AdditionalHelpFromDocStrings = "2" try: from honeybee.radiance.analysisgrid import AnalysisGrid except ImportError as e: raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e)) if _test_points: analysis_grid = AnalysisGrid.from_points_and_vectors( _test_points, pts_vectors_, _name_, w_groups_)
# assign inputs _name_, _testPoints, ptsVectors_, wGroups_ = IN analysisGrid = None try: from honeybee.radiance.analysisgrid import AnalysisGrid except ImportError as e: raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e)) if _testPoints: analysisGrid = AnalysisGrid.from_points_and_vectors( _testPoints, ptsVectors_, _name_, wGroups_) # assign outputs to OUT OUT = (analysisGrid, )
chunked_points = list(chunks(points, chunk_size)) # print("{0:} seperate grids generated".format(len(chunked_points))) print("These settings will produce a case with {0:} points".format( len(points))) print( "With a chunk size of {0:}, this means a total number of {1:} tasks (spread over {2:} pools) will be created." .format(chunk_size, len(chunked_points), int(np.ceil(float(len(chunked_points)) / 100)))) response = raw_input("Do you want to continue? [y/N]: ") if response == "y": hb_analysis_grids = [] for n, c in enumerate(chunked_points): hb_analysis_grids.append( AnalysisGrid.from_points_and_vectors( c, name="gridmatrix{0:04d}".format(n))) print( "Analysis grid_file for gridmatrix{0:04d} generated ({1:} points)" .format(n, len(c))) elif response != "y": raise RuntimeError("You didn't continue. Good for you.") sys.exit(1) else: print("Generating a 2D Radiance case") # TODO: UNDER CONSTRUCTION # Define analysis grids for each zone for simulation in Radiance hb_analysis_grids = [] for floor_srf in [ i for i in idf.idfobjects["BUILDINGSURFACE:DETAILED"]
ghenv.Component.AdditionalHelpFromDocStrings = "2" try: from honeybee.radiance.analysisgrid import AnalysisGrid except ImportError as e: msg = '\nFailed to import honeybee. Did you install honeybee on your machine?' + \ '\nYou can download the installer file from github: ' + \ 'https://github.com/ladybug-analysis-tools/honeybee-plus/tree/master/plugin/grasshopper/samplefiles' + \ '\nOpen an issue on github if you think this is a bug:' + \ ' https://github.com/ladybug-analysis-tools/honeybee-plus/issues' raise ImportError('{}\n\t{}'.format(msg, e)) if _testPoints: # match points and vectors try: from honeybee_grasshopper import datatree _testPoints = tuple(i.list for i in datatree.dataTreeToList(_testPoints)) ptsVectors_ = tuple(i.list for i in datatree.dataTreeToList(ptsVectors_)) except ImportError: # Dynamo pass else: ptsVectors_ = ptsVectors_ or ((),) ptsVectors_ = tuple(ptsVectors_[i] if i < len(ptsVectors_) else ptsVectors_[-1] for i in range(len(_testPoints))) analysisGrid = (AnalysisGrid.fromPointsAndVectors(pts, vectors) for pts, vectors in zip(_testPoints, ptsVectors_))
def run_radiance(epw_file: str, ground: Ground, shades: Shade = None, case_name: str = "openfield", output_directory: str = pathlib.Path(tempfile.gettempdir()), run: bool = False): """ Run Radiance for a point in an open-field (with or without shade) Parameters ---------- epw_file : str Path to EPW file ground : Ground Ground object to simulate ground : Ground Ground object to simulate case_name : str Name of case being simulated output_directory : str Directory where simulation results will be stored run : bool Run the simulation Returns ------- [direct_radiation, diffuse_radiation] : float Annual hourly direct and diffuse radiation """ # Construct case output directory and process variables epw_file = pathlib.Path(epw_file) # Create ground and shade (if included) context geometry and materials context_geometry = [] context_geometry.append(ground.to_hb()) if shades is not None: for shd in shades: context_geometry.append(shd.to_hb()) # Flatten objects context_geometry = flatten(context_geometry) with _HiddenPrints(): # Prepare Radiance case for radiation incident on exposed test-point sky_matrix = SkyMatrix.from_epw_file(epw_file) analysis_grid = AnalysisGrid.from_points_and_vectors([[0, 0, 1.2]], name="openfield") recipe = GridBased(sky_mtx=sky_matrix, analysis_grids=[analysis_grid], simulation_type=1, hb_objects=context_geometry, reuse_daylight_mtx=True) # Run annual irradiance simulation command_file = recipe.write(target_folder=output_directory, project_name=case_name) if run: with _HiddenPrints(): recipe.run(command_file=command_file) print("Direct and diffuse solar radiation simulation completed") # Read Radiance results radiation_direct, radiation_diffuse = load_radiance_results( output_directory / case_name / "gridbased_annual" / "result") return radiation_direct, radiation_diffuse else: print("Radiance case written to {}".format( str(output_directory / case_name / "gridbased_annual"))) return None
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
def run(epw_file: str, case_name: str = None, output_directory: str = None): """ Calculate the open-field irradiation from the sky, split into direct-from-sun, and diffuse-from-sky-dome components :param epw_file: Weather-file with location and climatic conditions for simulation :param case_name: Name of case being simulated :param output_directory: Location of generated outputs :return DirectHorizontalIrradiance, DiffuseHorizontalIrradiance: """ case_name = "openfield" if case_name is None else case_name output_directory = pathlib.Path(tempfile.gettempdir( )) if output_directory is None else output_directory # Preparation epw_file = pathlib.Path(epw_file) output_directory = pathlib.Path(output_directory) # Prepare Radiance case for radiation incident on exposed test-point smx = SkyMatrix.from_epw_file(epw_file) ag = AnalysisGrid.from_points_and_vectors([[0, 0, 1.2]], name="OpenField") recipe = GridBased(sky_mtx=smx, analysis_grids=[ag], simulation_type=1) # Run annual irradiance simulation command_file = recipe.write(target_folder=output_directory, project_name=case_name) recipe.run(command_file=command_file) # Read Radiance results total = pd.read_csv( output_directory / case_name / "gridbased_annual" / "result" / "total..scene..default.ill", skiprows=6, sep="\t", header=None, ).T.dropna() / 179 direct = pd.read_csv( output_directory / case_name / "gridbased_annual" / "result" / "direct..scene..default.ill", skiprows=6, sep="\t", header=None, ).T.dropna() / 179 diffuse = (total - direct)[0].values sun = (pd.read_csv( output_directory / case_name / "gridbased_annual" / "result" / "sun..scene..default.ill", skiprows=6, sep="\t", header=None, ).T.dropna() / 179)[0].values sun = HourlyContinuousCollection(header=Header( DirectHorizontalIrradiance(), unit="W/m2", analysis_period=AnalysisPeriod()), values=sun) diffuse = HourlyContinuousCollection(header=Header( DiffuseHorizontalIrradiance(), unit="W/m2", analysis_period=AnalysisPeriod()), values=diffuse) print("Direct and diffuse solar radiation simulation completed") return sun, diffuse