Skip to content

Commit

Permalink
style: update names and docstring
Browse files Browse the repository at this point in the history
Updated function names and improved the docstring based on feedback on the PR.
  • Loading branch information
mostaphaRoudsari committed Oct 4, 2021
1 parent 02bc4e7 commit c9641b8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
27 changes: 14 additions & 13 deletions honeybee_radiance_folder/gridutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
import json


def distribute_sensors(
def redistribute_sensors(
input_folder, output_folder, grid_count, min_sensor_count=2000, verbose=False
):
"""Create new sensor grids folder with evenly distribute sensors.
"""Create new sensor grids folder with evenly distributed sensors.
This function creates a new folder with evenly distributed sensor grids. The folder
will include a ``_dist_info.json`` file which has the information to recreate the
will include a ``_redist_info.json`` file which has the information to recreate the
original input files from this folder and the results generated based on the grids
in this folder.
``_dist_info.json`` file includes an array of JSON objects. Each object has the
``_redist_info.json`` file includes an array of JSON objects. Each object has the
``id`` or the original file and the distribution information. The distribution
information includes the id of the new files that the sensors has been distributed
to and the start and end line in the target file.
Expand Down Expand Up @@ -47,7 +47,8 @@ def distribute_sensors(
the simulations in parallel.
min_sensor_count: Minimum number of sensors in each output grid. Use this number
to ensure the number of sensors in output grids never gets very small. To
ignore this limitation set the value to 1. Default: 2000.
ignore this limitation set the value to 1. This value always takes precedence
over grid_count. Default: 2000.
verbose: Set to True to get verbose reporting. Default: False.
Returns:
Expand Down Expand Up @@ -163,7 +164,7 @@ def get_target_file(index):
}
out_grid_info.append(out_data)

dist_info_file = os.path.join(output_folder, '_dist_info.json')
dist_info_file = os.path.join(output_folder, '_redist_info.json')
with open(dist_info_file, 'w') as dist_out_file:
json.dump(dist_info, dist_out_file, indent=2)

Expand All @@ -179,9 +180,9 @@ def get_target_file(index):
return grid_count, sensor_per_grid


def restructure_distributed_data(
def restore_original_distribution(
input_folder, output_folder, extension='pts', dist_info=None):
"""Restructure files based on the distribution info.
"""Restructure files to the original distribution based on the distribution info.
Args:
input_folder: Path to input folder.
Expand All @@ -190,17 +191,17 @@ def restructure_distributed_data(
sensor files. Another common extension is ``ill`` for the results of daylight
studies.
dist_info: Path to dist_info.json file. If not provided the function will try
to load ``_dist_info.json`` file from inside the input_folder. Default: None
to load ``_redist_info.json`` file from inside the input_folder. Default: None
"""
if not dist_info:
_dist_info_file = os.path.join(input_folder, '_dist_info.json')
_redist_info_file = os.path.join(input_folder, '_redist_info.json')
else:
_dist_info_file = dist_info
_redist_info_file = dist_info

assert os.path.isfile(_dist_info_file), 'Failed to find %s' % _dist_info_file
assert os.path.isfile(_redist_info_file), 'Failed to find %s' % _redist_info_file

with open(_dist_info_file) as inf:
with open(_redist_info_file) as inf:
data = json.load(inf)

# create output folder
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions tests/grid_dist_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
import json
import filecmp

from honeybee_radiance_folder.gridutil import distribute_sensors, \
restructure_distributed_data
from honeybee_radiance_folder.gridutil import redistribute_sensors, \
restore_original_distribution
from honeybee_radiance_folder.folderutil import _nukedir


def test_dist_grids():
input_folder = r'./tests/assets/grids'
output_folder = r'./tests/assets/temp'
_nukedir(output_folder, False)
distribute_sensors(
redistribute_sensors(
input_folder, output_folder, grid_count=9, min_sensor_count=2000
)
files = list(os.listdir(output_folder))
assert len(files) == 11
assert '_info.json' in files
assert '_dist_info.json' in files
assert '_redist_info.json' in files
with open(os.path.join(output_folder, '_info.json')) as inf:
data = json.load(inf)
assert len(data) == 9
Expand All @@ -32,7 +32,7 @@ def test_rebuild_grids():
input_folder = r'./tests/assets/grids_dist'
output_folder = r'./tests/assets/temp'
_nukedir(output_folder, False)
restructure_distributed_data(input_folder, output_folder)
restore_original_distribution(input_folder, output_folder)
files = [f for f in os.listdir(output_folder) if f.endswith('.pts')]
# compare the newly created files with the original files and ensure they are
# identical
Expand Down

0 comments on commit c9641b8

Please sign in to comment.