Skip to content

Commit

Permalink
fix(cli): expose image scale and text height
Browse files Browse the repository at this point in the history
  • Loading branch information
mostaphaRoudsari committed Mar 19, 2023
1 parent 230165a commit 8f7f43e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
9 changes: 7 additions & 2 deletions honeybee_vtk/cli/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,13 @@ def grid_images(
'--image-height', '-ih', type=int, default=1088, help='Height of images in pixels.'
'If not set, Radiance default y dimension of view will be used.', show_default=True
)
@click.option(
'--image-scale', '-is', type=int, default=1, help='Scale of the image. Default '
' is set to 1.', show_default=True
)
def time_step_images(
hbjson_file, config, time_step_file, folder,
grid_filter, full_match, label, image_width, image_height):
grid_filter, full_match, label, image_width, image_height, image_scale):
"""Export images of the grids for the Honeybee Model created from the HBJSON file.
\b
Expand Down Expand Up @@ -395,7 +399,8 @@ def time_step_images(
full_match=full_match,
label_images=label,
image_width=image_width,
image_height=image_height)
image_height=image_height,
image_scale=image_scale)
output = folder
except Exception:
traceback.print_exc()
Expand Down
9 changes: 7 additions & 2 deletions honeybee_vtk/cli/post_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,13 @@ def post_process():
' duration. If set to 0, the last frame will not linger. Setting it to 3 will make'
' the last frame linger for 3 times the duration. Defaults to 3.'
)
@click.option(
'--text-height', '-th', type=int, default=20, show_default=True,
help='An integer to set the text height for date and time on the image.'
' Default is set to 20.'
)
def export_gif(images_folder, folder, gradient_transparency, duration,
loop_count, linger_last_frame):
loop_count, linger_last_frame, text_height):
"""Write a gif from a set of images.
\b
Expand All @@ -65,7 +70,7 @@ def export_gif(images_folder, folder, gradient_transparency, duration,
"""
try:
output = write_gif(images_folder, folder, gradient_transparency,
duration, loop_count, linger_last_frame)
duration, loop_count, linger_last_frame, text_height)
except Exception:
traceback.print_exc()
sys.exit(1)
Expand Down
14 changes: 8 additions & 6 deletions honeybee_vtk/image_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def _gif(temp_folder: Path, images_folder: Path, target_folder: Path,
image_paths = _files_in_order(temp_folder, images_folder.stem, number_of_images)
images = [Image.open(image_path) for image_path in image_paths]
image = images[0]
rest_of_images = images[1:] + [images[-1]]*linger_last_frame
rest_of_images = images[1:] + [images[-1]] * linger_last_frame
image.save(f'{target_folder}/{gif_name}.gif', save_all=True,
append_images=rest_of_images, duration=gif_duration, loop=gif_loop_count,
transparency=0, format='GIF', disposal=2)
Expand Down Expand Up @@ -205,7 +205,7 @@ def _hoy_to_text(image_path: Path) -> str:
image_path: A path to a hoy image.
Returns:
A text that is the HOY converted into a humand readable form.
A text that is the HOY converted into a human readable form.
"""
hoy = float(image_path.stem.split('_')[0])
text = DateTime.from_hoy(hoy).to_simple_string()
Expand Down Expand Up @@ -365,11 +365,11 @@ def _files_in_order(temp_folder: Path, parent: str,

def _transparent_translucent(temp_folder: Path, images_folder: Path,
translucency: bool = True) -> Path:
"""Appply transparency to images and make the background translucent.
"""Apply transparency to images and make the background translucent.
Args:
temp_folder: Path to the temp folder.
images_folder: The folder containing the images to appply transparency to.
images_folder: The folder containing the images to apply transparency to.
translucency: A boolean to determine if the transparency should be applied.
Defaults to True.
Expand Down Expand Up @@ -399,7 +399,8 @@ def write_gif(time_step_images_path: str, target_path: str = '.',
gradient_transparency: bool = False,
duration: int = 1000,
loop_count: int = 0,
linger_last_frame: int = 3) -> str:
linger_last_frame: int = 3,
text_height: int = 20) -> str:
"""Export a GIF from a time step images.
This function will generate one folder for each grid found in the model.
Expand All @@ -421,6 +422,7 @@ def write_gif(time_step_images_path: str, target_path: str = '.',
than the duration. If set to 0, the last frame will not linger. Setting it
to 3 will make the last frame linger for 3 times the duration. Defaults to
3.
text_height: An integer to set the text height in pixels. Default is set to 20.
Returns:
The path to the folder where GIFs are exported.
Expand Down Expand Up @@ -457,7 +459,7 @@ def write_gif(time_step_images_path: str, target_path: str = '.',
len(time_stamp_strings))

annotated_folder = _annotated_folder(temp_folder, gif_images_folder,
time_stamp_strings, 20,
time_stamp_strings, text_height,
len(time_stamp_strings))

_gif(temp_folder, annotated_folder,
Expand Down
7 changes: 5 additions & 2 deletions honeybee_vtk/time_step_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ def export_time_step_images(hbjson_path: str, config_path: str,
full_match: bool = False,
label_images: bool = True,
image_width: int = 1920,
image_height: int = 1088) -> str:
image_height: int = 1088,
image_scale=1) -> str:
"""Export images of grids for each time step in the time stamps file.
This function will find all the time stamps between the start and end datetimes
Expand All @@ -398,6 +399,7 @@ def export_time_step_images(hbjson_path: str, config_path: str,
or not. Defaults to True.
image_width: Width of the images. Defaults to 1920.
image_height: Height of the images. Defaults to 1088.
image_scale: An integer value as a scale factor. Defaults to 1.
Returns:
A path to the target folder where all the images are written.
Expand Down Expand Up @@ -445,7 +447,8 @@ def export_time_step_images(hbjson_path: str, config_path: str,
time_step.color[2])
],
image_width=image_width,
image_height=image_height)
image_height=image_height,
image_scale=image_scale)

try:
shutil.rmtree(parent_temp_folder)
Expand Down

0 comments on commit 8f7f43e

Please sign in to comment.