Skip to content

Commit

Permalink
fix: modify the code to work with the three phase recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
mostaphaRoudsari committed Feb 13, 2022
1 parent 62a7b7e commit 6776c59
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
41 changes: 25 additions & 16 deletions honeybee_radiance_folder/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
See https://github.com/ladybug-tools/radiance-folder-structure#radiance-folder-structure
"""
import json
import os
import re
import shutil
Expand Down Expand Up @@ -524,17 +525,21 @@ def combined_receivers(self, folder='receivers', auto_mtx_path=True):
as values.
"""
grids = self.grid_data_all()

apt_group_folder = self.aperture_group_folder(full=False)

states = self.aperture_groups_states(full=True)
states = {d['identifier']: d['states'] for d in states}
rec_folder = os.path.join(
self.model_folder(True), folder
)
if not os.path.isdir(rec_folder):
os.mkdir(rec_folder)

if not os.path.isdir(folder):
os.mkdir(folder)

receiver_dict = dict()
receivers_info = []

# find the light_path for each grid
for grid in grids.values():
for grid in grids:
light_path = grid['light_path']
# remove the static windows
# another way is to check for the ones which has a mtx file.
Expand All @@ -546,11 +551,21 @@ def combined_receivers(self, folder='receivers', auto_mtx_path=True):
grid['identifier'],
apt_group_folder,
aperture_groups,
folder, add_output_header=auto_mtx_path)
rec_folder, add_output_header=auto_mtx_path
)
receivers_info.append(
{
'identifier': grid['identifier'],
'path': receiver_file
}
)

receivers_info_file = os.path.join(rec_folder, 'receivers_info.json')

receiver_dict[grid['identifier']] = receiver_file
with open(receivers_info_file, 'w') as outf:
outf.write(json.dumps(receivers_info))

return receiver_dict
return receivers_info

def dynamic_scene(self, indoor=False, reload=False):
"""List of dynamic non-aperture geometries.
Expand Down Expand Up @@ -604,19 +619,13 @@ def grid_data_all(self, info_from_model=False):
"""

grid_info = self.grid_info(is_model=info_from_model)
grid_folder = self.grid_folder(full=True)

grid_data_dict = {}

if not grid_info:
return None
else:
for grid in grid_info:
grid_id = grid.pop('full_id')
grid_data_dict[grid_id] = parse_grid_json(
os.path.join(grid_folder, grid_id + '.json'))
grid_data_dict[grid_id].update(grid)
return grid_data_dict
grid.pop('full_id')
return grid_info

def write(self, folder_type=0, cfg=None, overwrite=False):
"""Write an empty model folder.
Expand Down
11 changes: 8 additions & 3 deletions honeybee_radiance_folder/folderutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class SceneState(object):
* default
* direct
"""

def __init__(self, identifier, default, direct):
self.identifier = identifier
self.default = _as_posix(default)
Expand Down Expand Up @@ -319,7 +320,8 @@ def parse_aperture_groups(states_file, validate=True, bsdf_folder=None):
with open(states_file) as inf:
data = json.load(inf)

apertures = [ApertureGroup.from_dict({key: value}) for key, value in data.items()]
apertures = [ApertureGroup.from_dict(
{key: value}) for key, value in data.items()]

if validate:
# check for the files to exist
Expand Down Expand Up @@ -376,7 +378,8 @@ def add_output_spec_to_receiver(receiver_file, output_spec, output_file=None):
with open(receiver_file, 'r') as f:
content = f.read()
try:
value = re.search(r'^#@rfluxmtx[\s\S].*$', content, re.MULTILINE).group(0)
value = re.search(r'^#@rfluxmtx[\s\S].*$',
content, re.MULTILINE).group(0)
except AttributeError:
raise ValueError(
'%s is not a valid receiver file with '
Expand Down Expand Up @@ -429,6 +432,7 @@ def combined_receiver(grid_name, apt_group_folder, apt_groups, target_folder,
The path of the file that was written out as the combined receiver.
"""
file_name = '%s..receiver.rad' % grid_name

apt_group_folder = apt_group_folder.replace('\\', '/')
content = []
content.append('# %s\n' % file_name) # add header
Expand All @@ -441,7 +445,8 @@ def combined_receiver(grid_name, apt_group_folder, apt_groups, target_folder,
with open(out_file, 'w') as outf:
outf.write('\n'.join(content))

return out_file
return file_name


def _nukedir(target_dir, rmdir=True):
"""Delete all the files inside target_dir.
Expand Down

0 comments on commit 6776c59

Please sign in to comment.