Skip to content

Commit

Permalink
Finished oconv commands
Browse files Browse the repository at this point in the history
This commit addresses #37 and #25
  • Loading branch information
mostaphaRoudsari committed Apr 6, 2016
1 parent 3644e9a commit f76a878
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 98 deletions.
4 changes: 2 additions & 2 deletions honeybee/radiance/command/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__all__ = ["oconv"]
__all__ = ["gendaymtx", "oconv", "rcontrib", "rtrace"]

import oconv
import gendaymtx, oconv, rcontrib, rtrace
24 changes: 22 additions & 2 deletions honeybee/radiance/command/commandbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ def checkInputFiles(self, radString=""):
% (self.__class__.__name__, radString)

for f in self.inputFiles:
# this is for oconv where it has list of files which are not
# RadiancePath
if isinstance(f, str):
continue
assert hasattr(f, 'normpath'), _msg
assert f.normpath is not None, _msg

Expand Down Expand Up @@ -136,9 +140,13 @@ def onExecution(self):
"""
pass

# TODO: Add Error handling
# TODO: Add post process of the analysis and handle errors for Radiance comments
def execute(self):
"""Execute the command."""
"""Execute the command.
Returns:
Return fullpath to the result file if any as a string.
"""
# check if the files exist on the computer
self.__checkFiles()

Expand All @@ -151,6 +159,18 @@ def execute(self):
print line,
p.wait()

try:
if os.path.split(self.outputFile.normpath)[0] == "":
# add directory to file if it's not a full path
return os.path.join(os.getcwd(),
self.outputFile.normpath)
# return output file
return self.outputFile

except AttributeError:
# this command doesn't have an output file
pass

def __repr__(self):
"""Class representation."""
return self.toRadString()
147 changes: 91 additions & 56 deletions honeybee/radiance/command/oconv.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# coding=utf-8
"""oconv-create an octree from a RADIANCE scene description."""
from commandbase import RadianceCommand
from ..datatype import RadiancePath
from ..parameters.oconv import OconvParameters

import os


Expand All @@ -8,77 +13,107 @@ class Oconv(RadianceCommand):
Read more at: http://radsite.lbl.gov/radiance/man_html/oconv.1.html
Attributes:
outputName: oct filename which is usually the same as the project name
outputName: Output oct file which is usually the same as the project name
(Default: untitled)
inputFiles: Sorted list of full path to input rad files (Default: [])
resolution: An integer that "specifies the maximum octree resolution.
This should be greater than or equal to the ratio of the largest and
smallest dimensions in the scene (ie. surface size or distance between
surfaces)" (default:16384)
n: An integer that "specifies the maximum surface set size for each voxel.
Larger numbers result in quicker octree generation, but potentially
slower rendering. Smaller values may or may not produce faster renderings,
since the default number (6) is close to optimal for most scenes.
freeze: A Boolean to produce "a frozen octree containing all the scene
information. Normally, only a reference to the scene files is stored
in the octree, and changes to those files may invalidate the result.
The freeze option is useful when the octree file's integrity and
loading speed is more important than its size, or when the octree is
to be relocated to another directory, and is especially useful for
creating library objects for the "instance" primitive type. If the
input octree is frozen, the output will be also. (default: True)
sceneFiles: A list of radiance files (e.g. sky files, material files,
geometry files) in the order that they should show up in oconv
command. Make sure to put files with modifiers (e.g materials,
sources) before the files that are using them (e.g geometry files).
oconvParameters: Radiance parameters for oconv. If None Default
parameters will be set. You can use self.oconvParameters to view,
add or remove the parameters before executing the command.
Usage:
from honeybee.radiance.parameters.oconv import OconvParameters
from honeybee.radiance.command.oconv import Oconv
# generate oconv parameters
rcp = OconvParameters()
# trun off turn off warnings
rcp.turnOffWarns = True
# create an oconv command
oconv = Oconv(outputName="C:/ladybug/test3/gridbased/test3.oct",
sceneFiles=((r"C:/ladybug/test3/gridbased/test3.mat",
r"c:/ladybug/test3/gridbased/test3.rad")),
oconvParameters=rcp
)
# print command line to check
print oconv.toRadString()
> c:/radiance/bin/oconv -f C:/ladybug/test3/gridbased/test3.mat
c:/ladybug/test3/gridbased/test3.rad > test3.oct
# execute the command
outputFilePath = oconv.execute()
print outputFilePath
> C:/ladybug/test3/gridbased/test3.oct
"""

def __init__(self, outputName="untitled", inputFiles=[], resolution=16384,
n=6, freeze=True):
outputFile = RadiancePath("oct", "octree file", extension=".oct")

def __init__(self, outputName="untitled", sceneFiles=[],
oconvParameters=None):
"""Initialize the class."""
# Initialize base class to make sure path to radiance is set correctly
RadianceCommand.__init__(self)

self.outputName = outputName
"""oct file name which is usually the same as the project name (Default: untitled)"""
self.outputFile = outputName if outputName.lower().endswith(".oct") \
else outputName + ".oct"
"""results file for coefficients (Default: untitled)"""

self.inputFiles = inputFiles
self.sceneFiles = sceneFiles
"""Sorted list of full path to input rad files (Default: [])"""

self.r = int(resolution)
""" An integer that "specifies the maximum octree resolution.
This should be greater than or equal to the ratio of the largest and
smallest dimensions in the scene (ie. surface size or distance between
surfaces)" (default:16384)"""

self.n = int(n)
"""An integer that "specifies the maximum surface set size for each voxel.
Larger numbers result in quicker octree generation, but potentially
slower rendering. Smaller values may or may not produce faster renderings,
since the default number (6) is close to optimal for most scenes."""

self.freeze = freeze
"""A Boolean to produce "a frozen octree containing all the scene information.
Normally, only a reference to the scene files is stored in the octree,
and changes to those files may invalidate the result. The freeze option
is useful when the octree file's integrity and loading speed is more
important than its size, or when the octree is to be relocated to another
directory, and is especially useful for creating library objects for
the "instance" primitive type. If the input octree is frozen, the output
will be also. (default: True)"""
self.oconvParameters = oconvParameters
"""Radiance parameters for oconv. If None Default parameters will be
set. You can use self.oconvParameters to view, add or remove the
parameters before executing the command.
"""

@property
def inputFiles(self):
"""Return input files by user."""
return self.__inputFiles
def oconvParameters(self):
"""Get and set gendaymtxParameters."""
return self.__oconvParameters

@oconvParameters.setter
def oconvParameters(self, parameters):
self.__oconvParameters = parameters if parameters is not None \
else OconvParameters()

assert hasattr(self.oconvParameters, "isRadianceParameters"), \
"input oconvParameters is not a valid parameters type."

@property
def sceneFiles(self):
"""Get and set scene files."""
return self.__sceneFiles

@sceneFiles.setter
def sceneFiles(self, files):
self.__sceneFiles = [os.path.normpath(f) for f in files]

@inputFiles.setter
def inputFiles(self, inputFiles):
self.__inputFiles = inputFiles
def addFileToScene(self, filePath):
"""Add a new file to the scene."""
self.sceneFiles.append(os.path.normpath(filePath))

def toRadString(self, relativePath=False):
"""Return full command as a string."""
return "%s -r %d %s %s > %s" % (
radString = "%s %s %s > %s" % (
os.path.join(self.radbinPath, "oconv"),
self.r,
"-f" if self.freeze else "",
" ".join(self.inputFiles),
self.outputName if self.outputName.lower().endswith(".oct")
else self.outputName + ".oct"
self.oconvParameters.toRadString(),
" ".join(self.sceneFiles),
self.outputFile.toRadString()
)

# make sure input files are set by user
self.checkInputFiles(radString)
return radString

@property
def inputFiles(self):
"""Return input files by user."""
return self.sceneFiles
2 changes: 1 addition & 1 deletion honeybee/radiance/command/rcontrib.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
"""Radiance rcontrib command."""
"""RADIANCE rcontrib command."""
from commandbase import RadianceCommand
from ..datatype import RadiancePath
from ..parameters.rcontrib import RcontribParameters
Expand Down
4 changes: 2 additions & 2 deletions honeybee/radiance/parameters/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__all__ = ["gridbased", "gendaymtx", "rcontrib"]
__all__ = ["gridbased", "gendaymtx", "rcontrib", "oconv"]

import gridbased, gendaymtx, rcontrib
import gridbased, gendaymtx, rcontrib, oconv
9 changes: 4 additions & 5 deletions honeybee/radiance/parameters/_advancedparametersbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ def addRadianceBoolFlag(self, name, descriptiveName=None, defaultValue=None,
self.appendParameterToDynamicKeys(_attrname)

def addRadianceTuple(self, name, descriptiveName=None, validRange=None,
acceptedInputs=None, tupleSize=None, numType=None,
defaultValue=None, attributeName=None):
acceptedInputs=None, tupleSize=None, numType=None,
defaultValue=None, attributeName=None):
"""Add a radiance numeric tuple e.g (0.5,0.3,0.2).
Attributes:
Expand Down Expand Up @@ -276,9 +276,8 @@ def addRadianceTuple(self, name, descriptiveName=None, validRange=None,
_attrname = attributeName if attributeName is not None else name
setattr(self.__class__,
_attrname,
RadianceTuple(name, descriptiveName, validRange,
acceptedInputs, tupleSize, numType,
defaultValue)
RadianceTuple(name, descriptiveName, validRange, acceptedInputs,
tupleSize, numType, defaultValue)
)

# add name of the attribute to dynamic keys
Expand Down
69 changes: 69 additions & 0 deletions honeybee/radiance/parameters/oconv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# coding=utf-8
"""Radiance oconv Parameters."""
from ._advancedparametersbase import AdvancedRadianceParameters


# TODO: Implement -i and -b
class OconvParameters(AdvancedRadianceParameters):
u"""Radiance Parameters for rcontrib command including rtrace parameters.
Read more:
https://www.radiance-online.org/learning/documentation/manual-pages/pdfs/oconv.pdf
Attributes:
freeze: [-f] A Boolean to produce "a frozen octree containing all the scene
information. Normally, only a reference to the scene files is stored
in the octree, and changes to those files may invalidate the result.
The freeze option is useful when the octree file's integrity and
loading speed is more important than its size, or when the octree is
to be relocated to another directory, and is especially useful for
creating library objects for the "instance" primitive type. If the
input octree is frozen, the output will be also. (default: True)
resolution: [-r] An integer that "specifies the maximum octree resolution.
This should be greater than or equal to the ratio of the largest and
smallest dimensions in the scene (ie. surface size or distance between
surfaces)" (default:16384)
maxSetSize: [-n] An integer that "specifies the maximum surface set size
for each voxel. Larger numbers result in quicker octree generation,
but potentially slower rendering. Smaller values may or may not
produce faster renderings, since the default number (6) is close to
optimal for most scenes (Default: 6).
turnOffWarns: [-w] A Boolean to suppress warnings (Default: False).
* For the full list of attributes try self.keys
** values between []'s indicate Radiance equivalent keys for advanced users
Usage:
# generate default oconv parameters
ocvp = OconvParameters()
# default values.
print ocvp.toRadString()
> -f
# add modifiers file
ocvp.turnOffWarns = True
# check radiance parameters with the new values
print ocvp.toRadString()
> -f -w
"""

def __init__(self, freeze=True, resolution=None, maxSetSize=None,
turnOffWarns=None):
"""Init paramters."""
AdvancedRadianceParameters.__init__(self)

# add parameters
self.addRadianceBoolFlag('f', 'freeze octree', defaultValue=freeze,
attributeName='freeze')
self.addRadianceNumber('r', 'maximum octree resolution',
defaultValue=resolution, checkPositive=True,
attributeName='resolution')
self.addRadianceNumber('n', 'maximum surface set size for each voxel',
defaultValue=maxSetSize, checkPositive=True,
attributeName='maxSetSize')
self.addRadianceBoolFlag('w', 'suppress warnings',
defaultValue=turnOffWarns,
attributeName='turnOffWarns')
51 changes: 21 additions & 30 deletions test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from honeybee.radiance.parameters.rcontrib import RcontribParameters
from honeybee.radiance.command.rcontrib import Rcontrib
from honeybee.radiance.parameters.oconv import OconvParameters
from honeybee.radiance.command.oconv import Oconv
import os

print os.getcwd()
# sky = radSky(1000)
# rp = HBGridBasedAnalysisRecipe(sky, pointGroups=[0, 0, 0])
#
Expand All @@ -10,36 +13,24 @@
# print rp.results(flattenResults=True)


# generate sky matrix with default values
rcp = RcontribParameters()

# ask only for direct sun
# print rcp.toRadString()

rcp.modFile = "c:/ladybug/suns.txt"
# print rcp.toRadString()

rcp.I = True
rcp.ab = 0
rcp.ad = 10000
# print rcp.toRadString()

rcp.quality = 1
# print rcp.toRadString()
# generate oconv parameters
rcp = OconvParameters()

rcontrib = Rcontrib(outputName="test3",
octreeFile=r"C:\ladybug\test3\gridbased\test3.oct",
pointsFile=r"C:\ladybug\test3\gridbased\test3.pts")
# trun off turn off warnings
rcp.turnOffWarns = True

rcontrib.rcontribParameters.modFile = r"C:\ladybug\test3\sunlist.txt"
rcontrib.rcontribParameters.I = True
rcontrib.rcontribParameters.ab = 0
rcontrib.rcontribParameters.ad = 10000
# create an oconv command
oconv = Oconv(outputName="test3",
sceneFiles=((r"C:\ladybug\test3\gridbased\Uniform_CIE_1000.sky",
r"C:\ladybug\test3\gridbased\test3.mat",
r"c:\ladybug\test3\gridbased\test3.rad")),
oconvParameters=rcp
)

print rcontrib.toRadString()
# print command line to check
print oconv.toRadString()

rcontrib.execute()
# execute the command
outputFilePath = oconv.execute()

# dmtx = Gendaymtx(weaFile="C:\ladybug\IZMIR_TUR\IZMIR_TUR.wea")
# dmtx.gendaymtxParameters.verboseReport = False
# dmtx.execute()
print outputFilePath

0 comments on commit f76a878

Please sign in to comment.