Skip to content

Commit

Permalink
append to Scene as modelchain input
Browse files Browse the repository at this point in the history
  • Loading branch information
shirubana committed Aug 4, 2022
1 parent 414360d commit a1cc7c3
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 33 deletions.
28 changes: 19 additions & 9 deletions bifacial_radiance/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2156,7 +2156,7 @@ def addPiles(self, spacingPiles=6, pile_lenx=0.2, pile_leny=0.2, pile_height=Non


def makeScene(self, module=None, sceneDict=None, radname=None,
moduletype=None):
moduletype=None, appendtoScene=None):
"""
Create a SceneObj which contains details of the PV system configuration including
tilt, row pitch, height, nMods per row, nRows in the system...
Expand All @@ -2175,6 +2175,11 @@ def makeScene(self, module=None, sceneDict=None, radname=None,
radname : str
Gives a custom name to the scene file. Useful when parallelizing.
moduletype: DEPRECATED. use the `module` kwarg instead.
appendtoScene : str
Appends to the scene a custom text pointing to a custom object
created by the user; format of the text should start with the rad
file path and name, and then any other geometry transformations
native to Radiance necessary.
Returns
-------
Expand Down Expand Up @@ -2245,9 +2250,13 @@ def makeScene(self, module=None, sceneDict=None, radname=None,
print( "Radfile APPENDAGE created!")
else:
self.radfiles = [sceneRAD]

if appendtoScene is not None:
self.appendtoScene(self.radfiles[0], customObject = appendtoScene)

return self.scene

def appendtoScene(self, radfile=None, customObject=None, text='!xform -rz 0 '):
def appendtoScene(self, radfile=None, customObject=None):
"""
Appends to the `Scene radfile` in folder `\objects` the text command in Radiance
lingo created by the user.
Expand All @@ -2259,11 +2268,7 @@ def appendtoScene(self, radfile=None, customObject=None, text='!xform -rz 0 '):
Directory and name of where .rad scene file is stored
customObject : str
Directory and name of custom object .rad file is stored
text : str
Command that starts the appended file to the radfile so Radiance
can properly load the object. Default
is set to not modify the object added (rotation by 0).
Default includes a space already at the end.
Returns
-------
Expand All @@ -2274,7 +2279,7 @@ def appendtoScene(self, radfile=None, customObject=None, text='!xform -rz 0 '):
#TODO: Add a custom name and replace radfile name

# py2 and 3 compatible: binary write, encode text first
text2 = '\n' + text + customObject
text2 = '\n !xform -rx 0 ' + customObject

debug = False
if debug:
Expand All @@ -2287,7 +2292,7 @@ def appendtoScene(self, radfile=None, customObject=None, text='!xform -rz 0 '):


def makeScene1axis(self, trackerdict=None, module=None, sceneDict=None,
cumulativesky=None, moduletype=None):
cumulativesky=None, moduletype=None, appendtoScene=None):
"""
Creates a SceneObj for each tracking angle which contains details of the PV
system configuration including row pitch, hub_height, nMods per row, nRows in the system...
Expand Down Expand Up @@ -2471,6 +2476,11 @@ def makeScene1axis(self, trackerdict=None, module=None, sceneDict=None,
count+=1
print('{} Radfiles created in /objects/'.format(count))


if appendtoScene is not None:
for key in trackerdict:
self.appendtoScene(trackerdict[key]['radfile'], customObject = appendtoScene)

self.trackerdict = trackerdict
self.nMods = sceneDict['nMods'] #assign nMods and nRows to RadianceObj
self.nRows = sceneDict['nRows']
Expand Down
13 changes: 10 additions & 3 deletions bifacial_radiance/modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def runModelChain(simulationParamsDict, sceneParamsDict, timeControlParamsDict=N
'axisofrotationTorqueTube']
"""
kwargs = moduleParamsDict

if torquetubeParamsDict:
if not 'visible' in torquetubeParamsDict:
torquetubeParamsDict['visible'] = simulationParamsDict['torqueTube']
Expand All @@ -138,15 +139,21 @@ def runModelChain(simulationParamsDict, sceneParamsDict, timeControlParamsDict=N
frameParams=frameParamsDict,
omegaParams=omegaParamsDict,
cellModule=cellModule, **kwargs)


if "customObject" in sceneParamsDict:
customObject = sceneParamsDict['customObject']
print("Custom Object Found, will be added to all Scenes.")
else:
customObject = None

if 'gcr' not in sceneParamsDict: # didn't get gcr passed - need to calculate it
sceneParamsDict['gcr'] = module.sceney / \
sceneParamsDict['pitch']

if simulationParamsDict['tracking'] == False and simulationParamsDict['cumulativeSky'] == True:
# Fixed gencumsky condition
scene = demo.makeScene(module=simulationParamsDict['moduletype'],
sceneDict=sceneParamsDict)
sceneDict=sceneParamsDict, appendtoScene=customObject)
demo.genCumSky(demo.gencumsky_metfile)

if pilesParamsDict:
Expand Down Expand Up @@ -191,7 +198,7 @@ def runModelChain(simulationParamsDict, sceneParamsDict, timeControlParamsDict=N
trackerdict = demo.makeScene1axis(trackerdict=trackerdict,
module=simulationParamsDict['moduletype'],
sceneDict=sceneParamsDict,
cumulativesky=simulationParamsDict['cumulativeSky'])
cumulativesky=simulationParamsDict['cumulativeSky'], appendtoScene=customObject)

trackerdict = demo.makeOct1axis(trackerdict=trackerdict)

Expand Down
37 changes: 19 additions & 18 deletions tests/simulation3.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[simulationParamsDict]
weatherFile = USA_CO_Boulder.724699_TMY2.epw
getEPW = False
getEPW = True
simulationname = _test_fixedtilt_end_to_end
moduletype = test-module
rewriteModule = True
Expand All @@ -13,41 +12,43 @@ cumulativeSky = False
selectTimes = True
latitude = 37.5
longitude = -77.6
testfolder = C:\Users\sayala\Documents\GitHub\bifacial_radiance\tests
testfolder = C:\Users\sayala\Documents\GitHub\bifacial_radiance\bifacial_radiance\TEMP\Modelchain
saveImage = True

[sceneParamsDict]
albedo = 0.62
nMods = 10
nRows = 3
nMods = 4
nRows = 2
gcrorpitch = pitch
pitch = 1.5
pitch = 4.0
azimuth = 180.0
clearance_height = 0.2
tilt = 10.0
customObject = customFixedObject.rad | xform -t 0 0 0
clearance_height = 0.4
tilt = 15.0
customObject = C:\Users\sayala\Documents\GitHub\bifacial_radiance\tests\customFixedObject.rad | xform -t 0 0 0

[timeControlParamsDict]
starttime = 06_17_13
endtime = 06_17_13

[moduleParamsDict]
bifi = 0.9
numpanels = 1
xgap = 0.0
ygap = 0.0
numpanels = 2
xgap = 0.05
ygap = 0.15
zgap = 0.0
x = 1.59
y = 0.95
customtext = !xform -rz 0 C:\Users\sayala\Documents\GitHub\bifacial_radiance\tests\customTT.rad | xform -t 0 0 -0.15
x = 1
y = 1.59
customtext = !xform -rz 0 C:\Users\sayala\Documents\GitHub\bifacial_radiance\tests\customTT.rad | xform -rz 90 -t 0.5 0 -0.15

[trackingParamsDict]

[torquetubeParamsDict]

[analysisParamsDict]
sensorsy = 9
modWanted = 5
rowWanted = 2
sensorsy = [1,9]
sensorsx = [1,1]
modWanted = 2
rowWanted = 1

[cellLevelModuleParamsDict]

Expand Down
5 changes: 2 additions & 3 deletions tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,12 @@ def test_CellLevelModule():
name = "_test_CellLevelModule"
demo = bifacial_radiance.RadianceObj(name) # Create a RadianceObj 'object'

module = demo.makeModule(name='test-module', rewriteModulefile=True, cellModule=cellParams, customtext=' | xform -t 0 0.181 0')
module = demo.makeModule(name='test-module', rewriteModulefile=True, cellModule=cellParams, customtext=r'!xform -rz 0 customTT.rad | xform -rz 90 -t 0.5 0 -0.15')
assert module.x == 1.036
assert module.y == 1.74
assert module.scenex == 1.046
assert module.sceney == 1.74
assert module.text == '! genbox black cellPVmodule 0.156 0.156 0.02 | xform -t -0.44 -0.87 0 -a 6 -t 0.176 0 0 -a 10 -t 0 0.176 0 -a 1 -t 0 1.74 0 | xform -t 0 0.181 0'

assert module.text == '! genbox black cellPVmodule 0.156 0.156 0.02 | xform -t -0.44 -0.87 0 -a 6 -t 0.176 0 0 -a 10 -t 0 0.176 0 -a 1 -t 0 1.74 0\n!xform -rz 0 customTT.rad | xform -rz 90 -t 0.5 0 -0.15'
module.addCellModule(**cellParams, centerJB=0.01) #centerJB simulations still under development.
# assert module.text == '! genbox black cellPVmodule 0.156 0.156 0.02 | xform -t -0.44 -0.87 0 -a 6 -t 0.176 0 0 -a 5.0 -t 0 0.176 0 -a 2 -t 0 0.772 0 | xform -t 0 0.181 0 -a 1 -t 0 1.73 0'

Expand Down

0 comments on commit a1cc7c3

Please sign in to comment.