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(translate): Add delimiter option to command #187

Merged
merged 2 commits into from
Sep 2, 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
13 changes: 9 additions & 4 deletions honeybee_radiance_postprocess/cli/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ def translate():
type=click.Path(exists=False, file_okay=False, dir_okay=True, resolve_path=True)
)
@click.option(
'--extension', '-ext', help='Output file extension', default='.txt', show_default=True
'--extension', '-ext', help='Output file extension', default='txt', show_default=True
)
@click.option(
'--output-format', '-fmt', help='Output format for each element in the array',
default='%.7e', show_default=True
)
def npy_to_txt(npy_file, name, output_folder, extension, output_format):
@click.option(
'--delimiter', '-d', help='Delimiter in the text file.', default='\t',
type=click.Choice(['\t', ' ', ',', ';', 'tab', 'space', 'comma', 'semicolon'])
)
def npy_to_txt(npy_file, name, output_folder, extension, output_format, delimiter):
"""Convert a npy file to text file.

This command reads a NumPy array from a npy file and saves it as readable file. The
Expand All @@ -47,10 +51,11 @@ def npy_to_txt(npy_file, name, output_folder, extension, output_format):
npy-file: Path to npy file.
"""
try:
delimiter = get_delimiter(delimiter)
array = np.load(npy_file)
output = Path(output_folder, name + extension)
output = Path(output_folder, f'{name}.{extension}')
output.parent.mkdir(parents=True, exist_ok=True)
np.savetxt(output, array, fmt=output_format, delimiter='\t')
np.savetxt(output, array, fmt=output_format, delimiter=delimiter)

except Exception:
_logger.exception('Converting npy file to text file failed.')
Expand Down
8 changes: 4 additions & 4 deletions honeybee_radiance_postprocess/vis_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
def _abnt_nbr_15575_daylight_levels_vis_metadata():
"""Return visualization metadata for ABNT NBR 15575 Daylight levels."""
level_value = {
0: 'Nao atende',
1: 'Minimo',
2: 'Intermediario',
0: 'Não atende',
1: 'Mínimo',
2: 'Intermediário',
3: 'Superior'
}

colors = [Color(255, 198, 143), Color(255, 255, 209), Color(192, 231, 189), Color(83, 169, 206)]
illuminance_levels_lpar = \
LegendParameters(min=0, max=3, colors=colors, segment_count=4,
title='Niveis de iluminamento')
title='Níveis de iluminamento')
illuminance_levels_lpar.ordinal_dictionary = level_value

metric_info_dict = {
Expand Down
Loading