🐝 VTK - Honeybee extension for viewing HBJSON in a web browser.
Installation
pip install honeybee-vtk
QuickStart
importhoneybee_vtk
Translate a HBJSON file to an HTML or vtkjs file
Usage: honeybee-vtk translate [OPTIONS] HBJSON_FILE Translate a HBJSON file to an HTML or a vtkjs file. Args: hbjson-file: Path to an HBJSON file.Options: -n, --name TEXT Name of the output file. [default: model] -f, --folder DIRECTORY Path to target folder. [default: .] -ft, --file-type [html|vtkjs|vtp|vtk] Switch between html and vtkjs formats [default: html] -mdm, --model-display-mode [shaded|surface|surfacewithedges|wireframe|points] Set display mode for the model. [default: shaded] -gdm, --grid-display-mode [shaded|surface|surfacewithedges|wireframe|points] Set display mode for the grid. [default: shaded] -go, --grid-options [ignore|points|meshes] Export sensor grids as either points or meshes. [default: ignore] -sh, --show-html, --show Open the generated HTML file in a browser. [default: False] -cf, --config PATH File Path to the config json file which can be used to mount simulation data on HBJSON. -vd, --validate-data Validate simulation data before loading on the model. This is recommended when using this command locally. [default: False] --help Show this message and exit.
Export images from an HBJSON file
Usage: honeybee-vtk export-images [OPTIONS] HBJSON_FILE Export images from radiance views in a HBJSON file. Args: hbjson-file: Path to an HBJSON file.Options: -f, --folder DIRECTORY Path to target folder. [default: .] -it, --image-type [png|jpg|ps|tiff|bmp|pnm] choose the type of image file. [default: jpg] -iw, --image-width INTEGER Width of images in pixels. If not set, Radiance default x dimension of view will be used. [default: 0] -ih, --image-height INTEGER Height of images in pixels.If not set, Radiance default y dimension of view will be used. [default: 0] -bc, --background-color <INTEGER INTEGER INTEGER>... Set background color for images [default: 255, 255, 255] -mdm, --model-display-mode [shaded|surface|surfacewithedges|wireframe|points] Set display mode for the model. [default: shaded] -go, --grid-options [ignore|points|meshes] Export sensor grids as either points or meshes. [default: ignore] -gdm, --grid-display-mode [shaded|surface|surfacewithedges|wireframe|points] Set display mode for the Sensorgrids. [default: surfacewithedges] -vf, --view PATH File Path to the Radiance view file. Multiple view files are accepted. -cf, --config PATH File Path to the config json file which can be used to mount simulation data on HBJSON. -vd, --validate-data Validate simulation data before loading on the model. This is recommended when using this command locally. [default: False] --grid / --model Boolean to decide whether to export the images of a whole model or only the grids. Set it to True to export the grids. [default: False] -gf, --grid-filter TEXT Filter sensor grids by name. Use this option multiple times to use multiple grid identifiers as filters. [default: ] --text-content TEXT Text to be displayed on the image. -th, --text-height INTEGER Set the height of the text in pixels. [default: 15] -tc, --text-color <INTEGER INTEGER INTEGER>... Set the text color. [default: 0, 0, 0] -tp, --text-position <FLOAT FLOAT>... Set the text position in the image. The setting is applied at the lower left point of the text. (0,0) will give you the lower left corner of the image. (1,1) will give you the upper right corner of the image. [default: 0.5, 0.0] -tb, --text-bold Set the text to be bold. [default: False] --help Show this message and exit.
Write a config file to be consumed by the Translate command
Usage: honeybee-vtk config [OPTIONS] INPUT_FILE Write a config file to be consumed by honeybee-vtk. Args: input_file: A path to the input file in json format. folder_path: Path to the folder where the config file shall be written. Defaults to the current working directory. name: A string as the name of the config file. Defaults to 'config'.Options: -fp, --folder-path PATH Path to the folder where the config file shall be written. [default: .] -n, --name TEXT Name of the config file. [default: config] --help Show this message and exit.
Create arrows and write to a vtp file and open it in a minimalist desktop viewer
fromhoneybee_vtk.modelimportModel, DisplayModefromladybug.colorimportColorhbjson=r'./tests/assets/gridbased.hbjson'model=Model.from_hbjson(hbjson)
# update model visualization to show edgesmodel.update_display_mode(DisplayMode.SurfaceWithEdges)
# set shades to wireframe mode and change their color to blackmodel.shades.display_mode=DisplayMode.Wireframemodel.shades.color=Color(0, 0, 0, 255)
# create an HTML file with embedded visualization. You can share this HTML as is# and it will include all the information.model.to_html('.', name='two-rooms', show=True)
# alternatively you can write it as a vtkjs file and visualize it in ParaviewGlance# the `to_html` method calls this method under the hood.# model.to_vtkjs(folder='.')
Load HB Model and daylight factor results
fromhoneybee_vtk.modelimportModel, DisplayMode, SensorGridOptionsimportpathlibhbjson=r'./tests/assets/revit_model/model.hbjson'results_folder=r'./tests/assets/revit_model/df_results'model=Model.from_hbjson(hbjson, load_grids=SensorGridOptions.Mesh)
# load the results for each grid# note that we load the results using the order for model to ensure the order will matchdaylight_factor= []
forgridinmodel.sensor_grids.data:
res_file=pathlib.Path(results_folder, f'{grid.identifier}.res')
grid_res= [float(v) forvinres_file.read_text().splitlines()]
daylight_factor.append(grid_res)
# add the results to sensor grids as a new field# per face is set to True since we loaded grids as a meshmodel.sensor_grids.add_data_fields(daylight_factor, name='Daylight Factor', per_face=True)
model.sensor_grids.color_by='Daylight Factor'# make it pop!# change display mode for sensor grids to be surface with edgesmodel.sensor_grids.display_mode=DisplayMode.SurfaceWithEdges# update model visualization to wireframemodel.update_display_mode(DisplayMode.Wireframe)
# make shades to be shaded with edgemodel.shades.display_mode=DisplayMode.SurfaceWithEdges# export the model to a HTML file with embedded viewer and open the page in a browsermodel.to_html('c:/ladybug', name='revit-model', show=True)
# alternatively you can write it as a vtkjs file and visualize it in ParaviewGlance# the `to_html` method calls this method under the hood.# model.to_vtkjs(folder='.')
Load HB Model and annual daylight results
fromhoneybee_vtk.modelimportModel, DisplayMode, SensorGridOptionsimportpathlibhbjson=r'./tests/assets/gridbased.hbjson'results_folder=r'./tests/assets/annual_metrics'model=Model.from_hbjson(hbjson, load_grids=SensorGridOptions.Mesh)
# load the results for each grid# note that we load the results using the order for model to ensure the order will matchannual_metrics= [
{'folder': 'da', 'extension': 'da', 'name': 'Daylight Autonomy'},
{'folder': 'cda', 'extension': 'cda', 'name': 'Continuous Daylight Autonomy'},
{'folder': 'udi', 'extension': 'udi', 'name': 'Useful Daylight Illuminance'},
{'folder': 'udi_lower', 'extension': 'udi', 'name': 'Lower Daylight Illuminance'},
{'folder': 'udi_upper', 'extension': 'udi', 'name': 'Excessive Daylight Illuminance'}
]
formetricinannual_metrics:
results= []
forgridinmodel.sensor_grids.data:
res_file=pathlib.Path(
results_folder, metric['folder'], f'{grid.identifier}.{metric["extension"]}'
)
grid_res= [float(v) forvinres_file.read_text().splitlines()]
results.append(grid_res)
# add the results to sensor grids as a new field# per face is set to True since we loaded grids as a meshmodel.sensor_grids.add_data_fields(results, name=metric['name'], per_face=True)
# Set color by to Useful Daylight Illuminancemodel.sensor_grids.color_by='Useful Daylight Illuminance'# make it pop!# change display mode for sensor grids to be surface with edgesmodel.sensor_grids.display_mode=DisplayMode.SurfaceWithEdges# update model visualization to wireframemodel.update_display_mode(DisplayMode.Wireframe)
# export the model to a HTML file with embedded viewer and open the page in a browsermodel.to_html('.', name='two-rooms', show=True)
# alternatively you can write it as a vtkjs file and visualize it in ParaviewGlance# the `to_html` method calls this method under the hood.# model.to_vtkjs(folder='.')
Save model with results as an image
fromhoneybee_vtk.modelimportModel, DisplayMode, SensorGridOptionsfromhoneybee_vtk.sceneimportSceneimportpathlibhbjson=r'./tests/assets/gridbased.hbjson'results_folder=r'./tests/assets/df_results'model=Model.from_hbjson(hbjson, load_grids=SensorGridOptions.Mesh)
# load the results for each grid# note that we load the results using the order for model to ensure the order will matchdaylight_factor= []
forgridinmodel.sensor_grids.data:
res_file=pathlib.Path(results_folder, f'{grid.identifier}.res')
grid_res= [float(v) forvinres_file.read_text().splitlines()]
daylight_factor.append(grid_res)
# add the results to sensor grids as a new field# per face is set to True since we loaded grids as a meshmodel.sensor_grids.add_data_fields(
daylight_factor, name='Daylight Factor', per_face=True, data_range=(0, 20)
)
model.sensor_grids.color_by='Daylight Factor'# make it pop!# change display mode for sensor grids to be surface with edgesmodel.sensor_grids.display_mode=DisplayMode.SurfaceWithEdges# update model visualization to wireframemodel.update_display_mode(DisplayMode.Wireframe)
# make shades to be shaded with edgemodel.shades.display_mode=DisplayMode.SurfaceWithEdges# create a scene to render the modelscene=Scene()
scene.add_model(model)
# set a scale bar based on daylight factor valuescolor_range=model.sensor_grids.active_field_info.color_range()
# you can also save the scene as an image.# right now you can't control the camera but camera control can be implemented.scene.to_image('.', name='daylight_factor', image_scale=2, color_range=color_range)
# alternatively you can start an interactive window# scene.show(color_range)