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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(sky): Add tests for ABNT NBR 15575 skies #860

Merged
merged 2 commits into from
Jun 5, 2024
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
77 changes: 77 additions & 0 deletions honeybee_radiance/cli/sky.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,3 +465,80 @@ def leed_illuminance(wea, north, folder, name, log_file):
except Exception:
_logger.exception('Failed to create LEED skies.')
sys.exit(1)


@sky.command('abnt-nbr-15575')
@click.argument('wea', type=click.Path(
exists=True, file_okay=True, dir_okay=False, resolve_path=True))
@click.option(
'--north', '-n', type=float, default=0, show_default=True, help='A '
'number between -360 and 360 for the counterclockwise difference between '
'the North and the positive Y-axis in degrees. 90 is West; 270 is East')
@click.option('--folder', type=click.Path(
exists=False, file_okay=False, dir_okay=True, resolve_path=True), default='.',
help='Output folder for the two generated .sky files.')
@click.option(
'--log-file', help='Optional log file to output the information about the two '
'generated sky files. By default the list will be printed out to stdout',
type=click.File('w'), default='-')
def abnt_nbr_15575(wea, north, folder, log_file):
"""Generate four CIE skies for ABNT NBR 15575.

The four skies are:
- April 23rd at 9:30AM and 3:30PM.
- October 23rd at 9:30AM and 3:30PM.

\b
Args:
wea: Path to a Typical Meteorological Year (TMY) .wea file. This can
also be an .epw. The file is only used to extract the location.
"""
try:
with open(wea) as inf:
first_word = inf.read(5)
is_wea = True if first_word == 'place' else False
if not is_wea:
wea = Wea.from_epw_file(wea)
else:
wea = Wea.from_file(wea)

sky_obj_4_930am = hbsky.CIE.from_location(
wea.location, 4, 23, 9.5, sky_type=5, north_angle=north)
sky_obj_4_330pm = hbsky.CIE.from_location(
wea.location, 4, 23, 15.5, sky_type=5, north_angle=north)
sky_obj_10_930am = hbsky.CIE.from_location(
wea.location, 10, 23, 9.5, sky_type=5, north_angle=north)
sky_obj_10_330pm = hbsky.CIE.from_location(
wea.location, 10, 23, 15.5, sky_type=5, north_angle=north)

# write out the sky files and the log file
output_4_930am = sky_obj_4_930am.to_file(folder, '4_930AM.sky', True)
output_4_330pm = sky_obj_4_330pm.to_file(folder, '4_330PM.sky', True)
output_10_930am = sky_obj_10_930am.to_file(folder, '10_930AM.sky', True)
output_10_330pm = sky_obj_10_330pm.to_file(folder, '10_330PM.sky', True)
files = [
{
'id': '4_930AM',
'path': os.path.relpath(output_4_930am, folder),
'full_path': output_4_930am
},
{
'id': '4_330PM',
'path': os.path.relpath(output_4_330pm, folder),
'full_path': output_4_330pm
},
{
'id': '10_930AM',
'path': os.path.relpath(output_10_930am, folder),
'full_path': output_10_930am
},
{
'id': '10_330PM',
'path': os.path.relpath(output_10_330pm, folder),
'full_path': output_10_330pm
}
]
log_file.write(json.dumps(files))
except Exception:
_logger.exception('Failed to create ABNT NBR 15575 skies.')
sys.exit(1)
32 changes: 31 additions & 1 deletion tests/cli/sky_cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from click.testing import CliRunner
from honeybee_radiance.cli.sky import sky_cie, sky_climate_based, \
sky_with_certain_irrad, sky_with_certain_illum, sky_dome, \
sunpath_from_wea_rad, leed_illuminance
sunpath_from_wea_rad, leed_illuminance, abnt_nbr_15575
from ladybug.futil import nukedir

import uuid
Expand Down Expand Up @@ -151,3 +151,33 @@ def test_leed_illuminance_epw():
for sky in out_files:
assert os.path.isfile(sky['full_path'])
nukedir(folder)


def test_abnt_nbr_15575():
wea_file = './tests/assets/wea/denver.wea'
folder = './tests/assets/temp/leed'
runner = CliRunner()
result = runner.invoke(
abnt_nbr_15575, [wea_file, '--folder', folder]
)
assert result.exit_code == 0
out_files = json.loads(result.output)
# check the files are created
for sky in out_files:
assert os.path.isfile(sky['full_path'])
nukedir(folder)


def test_abnt_nbr_15575_epw():
wea_file = './tests/assets/epw/denver.epw'
folder = './tests/assets/temp/leed'
runner = CliRunner()
result = runner.invoke(
abnt_nbr_15575, [wea_file, '--folder', folder]
)
assert result.exit_code == 0
out_files = json.loads(result.output)
# check the files are created
for sky in out_files:
assert os.path.isfile(sky['full_path'])
nukedir(folder)
Loading