diff --git a/honeybee_radiance_postprocess/cli/well.py b/honeybee_radiance_postprocess/cli/well.py index 74b8a1c8..0d7f97de 100644 --- a/honeybee_radiance_postprocess/cli/well.py +++ b/honeybee_radiance_postprocess/cli/well.py @@ -2,6 +2,12 @@ import sys import logging import click +import json +import os + +from ladybug.color import Color +from ladybug.datatype.generic import GenericType +from ladybug.legend import LegendParameters from ..well.well import well_annual_daylight @@ -45,6 +51,7 @@ def well_daylight( Args: folder: Results folder. This folder is an output folder of annual daylight recipe. The daylight simulation must include aperture groups. + daylight_hours: Daylight hours schedule for EN 17037. """ with open(daylight_hours) as hourly_schedule: daylight_hours = [int(float(v)) for v in hourly_schedule] @@ -58,3 +65,46 @@ def well_daylight( sys.exit(1) else: sys.exit(0) + + +@well.command('well-daylight-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 well_daylight_vis(output_folder): + """Write visualization metadata files for WELL Daylight.""" + colors = [Color(220, 0, 0), Color(0, 220, 0)] + pass_fail_lpar = \ + LegendParameters(min=0, max=1, colors=colors, segment_count=2, title='Pass/Fail') + pass_fail_lpar.ordinal_dictionary = {0: "Fail", 1: "Pass"} + + metric_info_dict = { + 'L01': { + 'type': 'VisualizationMetaData', + 'data_type': GenericType('sDA200,40%', '').to_dict(), + 'unit': '', + 'legend_parameters': pass_fail_lpar.to_dict() + }, + 'L06': { + 'type': 'VisualizationMetaData', + 'data_type': GenericType('sDA300,50%', '').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) diff --git a/honeybee_radiance_postprocess/well/well.py b/honeybee_radiance_postprocess/well/well.py index d548d1c3..d8373687 100644 --- a/honeybee_radiance_postprocess/well/well.py +++ b/honeybee_radiance_postprocess/well/well.py @@ -5,8 +5,8 @@ import numpy as np from ladybug.analysisperiod import AnalysisPeriod -from ladybug.datatype.generic import GenericType from ladybug.datacollection import HourlyContinuousCollection +from ladybug.datatype.generic import GenericType from ladybug.header import Header from honeybee.model import Model from honeybee.units import conversion_factor_to_meters @@ -458,6 +458,27 @@ def to_datacollection(aperture_group: str, values: np.ndarray): da_file.parent.mkdir(parents=True, exist_ok=True) np.savetxt(da_file, da, fmt='%.2f') + sda_pf_folder = ies_lm_folder.joinpath('pass_fail') + sda_pf_folder.mkdir(parents=True, exist_ok=True) + for l01_pf, grid_info in zip(l01_pass_sda_grids, grids_info): + grid_id = grid_info['full_id'] + l01_sda_pf_folder = sda_pf_folder.joinpath('L01') + l01_sda_pf_folder.mkdir(parents=True, exist_ok=True) + l01_pf_file = l01_sda_pf_folder.joinpath(f'{grid_id}.pf') + l01_pf = l01_pf.astype(int) + np.savetxt(l01_pf_file, l01_pf, fmt='%d') + grids_info_file = l01_sda_pf_folder.joinpath('grids_info.json') + grids_info_file.write_text(json.dumps(grids_info, indent=2)) + for l06_pf, grid_info in zip(l06_pass_sda_grids, grids_info): + grid_id = grid_info['full_id'] + l06_sda_pf_folder = sda_pf_folder.joinpath('L06') + l06_sda_pf_folder.mkdir(parents=True, exist_ok=True) + l06_pf_file = l06_sda_pf_folder.joinpath(f'{grid_id}.pf') + l06_pf = l06_pf.astype(int) + np.savetxt(l06_pf_file, l06_pf, fmt='%d') + grids_info_file = l06_sda_pf_folder.joinpath('grids_info.json') + grids_info_file.write_text(json.dumps(grids_info, indent=2)) + da_grids_info_file = l06_ies_lm_folder.joinpath( 'results', 'da', 'grids_info.json') da_grids_info_file.write_text(json.dumps(grids_info, indent=2))