Skip to content

Commit

Permalink
Merge f393e34 into 7e46ea1
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineDao committed Nov 2, 2021
2 parents 7e46ea1 + f393e34 commit 780c938
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 13 deletions.
16 changes: 9 additions & 7 deletions honeybee_vtk/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,8 @@ def load_config(json_path: str, model: Model, scene: Scene,
assert len(model.sensor_grids.data) > 0, 'Sensor grids are not loaded on'\
' this model. Reload them using grid options.'

config_dir = pathlib.Path(json_path).parent

try:
with open(json_path) as fh:
config = json.load(fh)
Expand All @@ -464,14 +466,14 @@ def load_config(json_path: str, model: Model, scene: Scene,
data = DataConfig.parse_obj(json_obj)
# only if data is requested move forward.
if not data.hide:
if not pathlib.Path(json_obj['path']).is_dir():
raise FileNotFoundError(
f'The path {json_obj["path"]} does not exist. It is likely that the'
' config file is not in the current working directory and the paths'
' to the result folders defined in the config file are relative to'
' the location of the config file.'
)
folder_path = pathlib.Path(data.path)
if not folder_path.is_dir():
folder_path = config_dir.joinpath(
folder_path).resolve().absolute()
data.path = folder_path.as_posix()
if not folder_path.is_dir():
raise FileNotFoundError(
f'No folder found at {data.path}')
identifier = data.identifier
grid_type = _get_grid_type(model)
# Validate data if asked for
Expand Down
1 change: 1 addition & 0 deletions honeybee_vtk/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ def color_by(self, value: str):
fields_info = self.fields_info
if not value:
self._color_by = None
return
else:
assert value in fields_info, \
f'{value} is not a valid data field for this ModelDataSet. Available ' \
Expand Down
44 changes: 40 additions & 4 deletions tests/assets/config/valid.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@
"min": 0,
"max": 20,
"color_set": "original",
"position": [0.5, 0.05],
"position": [
0.5,
0.05
],
"label_parameters": {
"color": [34, 247, 10],
"color": [
34,
247,
10
],
"size": 0,
"bold": true
}
Expand All @@ -30,11 +37,40 @@
"min": 0,
"max": 100,
"color_set": "nuanced",
"position": [0.9, 0.5],
"position": [
0.9,
0.5
],
"orientation": "vertical",
"width": 0.05,
"height": 0.45
}
},
{
"identifier": "Relative Path DF Results",
"object_type": "grid",
"unit": "Percentage",
"path": "../df_results",
"hide": false,
"legend_parameters": {
"hide_legend": false,
"min": 0,
"max": 20,
"color_set": "original",
"position": [
0.5,
0.05
],
"label_parameters": {
"color": [
34,
247,
10
],
"size": 0,
"bold": true
}
}
}
]
}
}
12 changes: 10 additions & 2 deletions tests/github/types_test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"""Unit test for the types module."""

import warnings
import pytest
import vtk
from honeybee.model import Model as HBModel
from honeybee_vtk.types import PolyData, _get_data_range
from honeybee_vtk.model import Model
from honeybee_vtk.types import ModelDataSet, PolyData, _get_data_range

file_path = r'tests/assets/gridbased.hbjson'
hb_model = HBModel.from_hbjson(file_path)
Expand Down Expand Up @@ -151,3 +150,12 @@ def test_get_data_range():
# make sure when string array is used, simply data_range is returned
values = vtk.vtkStringArray()
assert _get_data_range('test', [0, 100], values) == (0, 100)


def test_model_dataset_initialization_with_polydata():
polydata = PolyData()
polydata.add_data([1, 2, 3], 'demo-data')
md = ModelDataSet('test', [polydata])

assert md.data == [polydata]
assert md._color_by is None

0 comments on commit 780c938

Please sign in to comment.