Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(breeam): Add CLI for BREEAM vis metadata #208

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions honeybee_radiance_postprocess/breeam/breeam.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,10 @@ def breeam_daylight_assessment_4b(
metrics_summary['comply'] = True
else:
metrics_summary['comply'] = False
metrics_summary['average-comply'] = True if avg_comply else False
metrics_summary['minimum-comply'] = True if minimum_comply else False

metrics_summary['count'] = grid_info['count']

type_summary[program_type][grid_info['full_id']].append(metrics_summary)

Expand Down Expand Up @@ -467,12 +471,31 @@ def breeam_daylight_assessment_4b(
credit_summary.append(_building_type_summary)

if sub_folder:
folder = Path(sub_folder)
folder.mkdir(parents=True, exist_ok=True)
sub_folder = Path(sub_folder)
sub_folder.mkdir(parents=True, exist_ok=True)

credit_summary_file = folder.joinpath('summary.json')
credit_summary_file = sub_folder.joinpath('summary.json')
credit_summary_file.write_text(json.dumps(credit_summary, indent=2))
program_summary_file = folder.joinpath('program_summary.json')
program_summary_file = sub_folder.joinpath('program_summary.json')
program_summary_file.write_text(json.dumps(program_summary, indent=2))

pf_folder = sub_folder.joinpath('pass_fail')
pf_folder.mkdir(parents=True, exist_ok=True)
grids_info_file = pf_folder.joinpath('grids_info.json')
grids_info_file.write_text(json.dumps(grids_info, indent=2))
for program_type, grid_summary in type_summary.items():
for grid_id, metrics_list in grid_summary.items():
fill_value = 0
for metric in metrics_list:
if metric['comply']:
fill_value = 3
break
elif metric['average-comply']:
fill_value = 2
elif metric['minimum-comply']:
fill_value = 1
pf_file = pf_folder.joinpath(f'{grid_id}.pf')
pf_array = np.full(metric['count'], fill_value)
np.savetxt(pf_file, pf_array, fmt='%d')

return credit_summary, program_summary
44 changes: 44 additions & 0 deletions honeybee_radiance_postprocess/cli/breeam.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
import sys
import logging
from pathlib import Path
import os
import json
import click

from ladybug.color import Color
from ladybug.datatype.generic import GenericType
from ladybug.legend import LegendParameters

from honeybee_radiance_postprocess.breeam.breeam import breeam_daylight_assessment_4b

_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -45,3 +51,41 @@ def breeam_4b(
sys.exit(1)
else:
sys.exit(0)


@breeam.command('breeam-4b-vis-metadata')
@click.option(
'--output-folder', '-o', help='Output folder for vis metadata files.',
type=click.Path(exists=False, file_okay=False, dir_okay=True, resolve_path=True),
default='visualization', show_default=True
)
def breeam_4b_vis(output_folder):
"""Write visualization metadata files for BREEAM 4b."""
colors = [Color(220, 0, 0), Color(240, 170, 130), Color(250, 200, 170), Color(0, 220, 0)]
pass_fail_lpar = \
LegendParameters(min=0, max=3, colors=colors, segment_count=4, title='Pass/Fail')
pass_fail_lpar.ordinal_dictionary = {
0: 'Fail', 1: 'Min. illuminance only', 2: 'Avg. illuminance only', 3: 'Pass'}

metric_info_dict = {
'pass_fail': {
'type': 'VisualizationMetaData',
'data_type': GenericType('Pass/Fail', '').to_dict(),
'unit': '',
'legend_parameters': pass_fail_lpar.to_dict()
}
}
try:
if not os.path.exists(output_folder):
os.mkdir(output_folder)
for metric, data in metric_info_dict.items():
if not os.path.exists(os.path.join(output_folder, metric)):
os.mkdir(os.path.join(output_folder, metric))
file_path = os.path.join(output_folder, metric, 'vis_metadata.json')
with open(file_path, 'w') as fp:
json.dump(data, fp, indent=4)
except Exception:
_logger.exception('Failed to write the visualization metadata files.')
sys.exit(1)
else:
sys.exit(0)
2 changes: 1 addition & 1 deletion honeybee_radiance_postprocess/cli/well.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""honeybee-radiance-postprocess WELL commands."""
import sys
import logging
import click
import json
import os
import click

from ladybug.color import Color
from ladybug.datatype.generic import GenericType
Expand Down
Loading