Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
cumulative sky matrix for honeybee[+]
# create cumulative sky
fp = r"original.smx"
tp = r"cumulative.smx"
header = \
r"""#?RADIANCE
cumulative sky generated by Honeybee
LATLONG= 37.37000000 -121.92000000
NROWS=146
NCOLS=1
NCOMP=3
FORMAT=ascii
"""
with open(fp, 'rb') as inf:
# parse header
for line in inf:
if line.startswith('NROWS'):
patch_count = int(line.split('=')[-1])
print('number of sky patches: %d' % patch_count)
# total length will be patch_count * (hour_count = 1 in cumulative)
results = [[0, 0, 0] for p in range(patch_count)]
elif line.startswith('NCOLS'):
hour_count = int(line.split('=')[-1])
print('number of hours: %d' % hour_count)
elif line.startswith('FORMAT'):
# end of header, pass the next empty line
inf.next()
break
for patch_number in range(patch_count):
# sum_up the values in all the hours
for hour in range(hour_count):
r, g, b = inf.next().split()
results[patch_number][0] += float(r)
results[patch_number][1] += float(g)
results[patch_number][2] += float(b)
# pass extra line
inf.next()
with open(tp, 'wb') as outf:
outf.write(header)
for rgb in results:
outf.write(' '.join(('%.2f' % d for d in rgb)) + '\n')
outf.write('\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.