From 0a2b4757a1109d660c4c206af565e1e86e0ce3e5 Mon Sep 17 00:00:00 2001 From: Chris Mackey Date: Wed, 17 Nov 2021 14:17:50 -0500 Subject: [PATCH] fix(gridutil): Allow .ill files with headers to be restored The fact that I could not pass .ill files with headers to this function meant that I couldn't use it correctly in the comfort maps and annual-irradaince recipes, where we process the direct results separately from the total. This allows the i'll files with headers to be restructured without changing the runtime significantly. --- honeybee_radiance_folder/gridutil.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/honeybee_radiance_folder/gridutil.py b/honeybee_radiance_folder/gridutil.py index 0df6fca..15fe42b 100644 --- a/honeybee_radiance_folder/gridutil.py +++ b/honeybee_radiance_folder/gridutil.py @@ -218,9 +218,20 @@ def restore_original_distribution( st = src_info['st_ln'] end = src_info['end_ln'] with open(src_file) as srf: - # go to start line + # remove the header if it is there + first_line = next(srf) + if first_line[:10] == '#?RADIANCE': + for line in srf: + if line[:7] == 'FORMAT=': + # pass next empty line + next(srf) + first_line = next(srf) + break + continue + # go to the start line and write it for _ in range(st): - next(srf) - # write the lines to the output file - for _ in range(end - st + 1): + first_line = next(srf) + outf.write(first_line) + # write the other lines to the output file + for _ in range(end - st): outf.write(next(srf))