ladybug-tools / ladybug-dynamo

:beetle: :blue_book: Ladybug library and plugin for DynamoBIM
http://www.ladybug.tools/ladybug.html
GNU General Public License v3.0
31 stars 13 forks source link

Implement radiance-based sunlighthours calculation for sunlight hours #9

Closed mostaphaRoudsari closed 8 years ago

mostaphaRoudsari commented 8 years ago
import sys
sys.path.append(r"C:\Program Files\Dynamo 0.9")

# add IronPython path to sys
IronPythonLib = 'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(IronPythonLib)

# Now that the path to IronPython is established we can import libraries
import os
import clr
clr.AddReference('DynamoCore')
def getDynamoPath():
    return os.path.split(clr.References[2].Location)[0]

# append ladybug path to sys.path
sys.path.append(getDynamoPath())
import Dynamo

clr.AddReference('ProtoInterface')
from Autodesk.DesignScript.Interfaces import *

def splitList(li, step = 3):
    return [li[x:x+step] for x in range(0, len(li), step)]

def getPoints(rp):
    pts = list(rp.MeshVertices)
    # split values in xyz
    xyz = splitList(splitList(pts))
    del(rp)
    return xyz

surfaces = IN[0]
rpFactory = Dynamo.Visualization.DefaultRenderPackageFactory()
tp =TessellationParameters()
tp.MaxTessellationDivisions = 25
tp.Tolerance = -1
pts = []
for surface in surfaces:
    rp = rpFactory.CreateRenderPackage()
    surface.Tessellate(rp, tp)
    pts.append(getPoints(rp))

OUT = pts
mostaphaRoudsari commented 8 years ago

1 - Using honeybee library I need to create .pts, material file and geometry file. 2 - I can use sunpath library to generate sun vectors for any custom time period and write them to two files. For each sun position sun geometry file looks like: solar1 source sun1 0 0 4 sunvector.X sunvector.Y sunvector.Z 0.533

where solar1 is a material in sun material file: void light [materialName] 0 0 3 1.0 1.0 1.0.

There is also a third file which all the modifier names are listed (one name for each sun position.

solar1
solar2
solar3
...

3 - Now that it's all set running these two lines generates the results in a rct file.

oconv [material file] [geometry file] [sun materials file] [sun geometries file] > [octree file]
rcontrib -ab 0 -ad 10000 -I -M [sunlist.txt] -dc 1 [octree file]< [pts file] > [rcontrib results file]

The result file looks like this where each line after line 11 is the results for a test point and each 3 values are R, G, B values for one of the sun positions. In this case there is only 1 test point (1 line) and 8 sun positions (24 values).

#?RADIANCE
oconv [material file] [geometry file] [sun materials file] [sun geometries file] > [octree file]
rcontrib -ab 0 -ad 10000 -I -M [sunlist.txt] -dc 1 [octree file]< [pts file] > [rcontrib results file]
SOFTWARE= RADIANCE 5.0a lastmod 10:30:00 by googs on rgugliel-W7-VM
CAPDATE= 2016:03:27 19:19:44
GMT= 2016:03:27 23:19:44
NCOMP=3
NCOLS=8
FORMAT=ascii

0.000000e+000   0.000000e+000   0.000000e+000   0.000000e+000   0.000000e+000   0.000000e+000   0.000000e+000   0.000000e+000   0.000000e+000   0.000000e+000   0.000000e+000   0.000000e+000   0.000000e+000   0.000000e+000   0.000000e+000   0.000000e+000   0.000000e+000   0.000000e+000   1.863716e-005   1.863716e-005   1.863716e-005   8.653568e-006   8.653568e-006   8.653568e-006   

4 - Finally, we only care if the point sees the sun or not and the coefficient values itself doesn't really matter. Something like this will get us what we need for each test point.

def parseline(line):
    _values = line.strip().split("\t")
    _rgb = [_values[x:x + 3] for x in xrange(0, len(_values), 3)]

    return [1 if sum(map(float, v)) > 0 else 0 for v in _rgb]

with open(resultFile, 'rb', 10) as inf:
    for c, line in enumerate(inf):
        if c < 10: continue
        # here is the results for the test point
        results = parseline(line)
        print "{} Hours >> {}".format(sum(results), results)

>> 2  Hours >>  [0, 0, 0, 0, 0, 0, 1, 1]