Skip to content

Commit

Permalink
add scene.appendtoScene, which is basically a duplicate of radianceOb…
Browse files Browse the repository at this point in the history
…j.appendtoScene.

Update runs of tutorials 7 and 19, which are working.
  • Loading branch information
cdeline committed Nov 10, 2023
1 parent 35f6f6b commit bd3c73c
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 44 deletions.
48 changes: 46 additions & 2 deletions bifacial_radiance/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,9 @@ def returnMaterialFiles(self, material_path=None):
self.materialfiles = materialfilelist
return materialfilelist

def sceneNames(self):
return [scene.name for scene in self.scenes]

def setGround(self, material=None, material_file=None):
"""
Use GroundObj constructor class and return a ground object
Expand Down Expand Up @@ -2304,7 +2307,7 @@ def makeCustomObject(self, name=None, text=None):
f.write(text.encode('ascii'))

print("\nCustom Object Name", customradfile)
self.customradfile = customradfile
#self.customradfile = customradfile
return customradfile


Expand Down Expand Up @@ -2453,7 +2456,7 @@ def makeScene(self, module=None, sceneDict=None, radname=None,
return
scene = SceneObj(module, hpc=self.hpc, name=f'Scene{self.scenes.__len__()}')
if self.scenes.__len__() >=1:
print(f"Additional scene {scene.name} created! See list of names with RadianceObj.scenes")
print(f"Additional scene {scene.name} created! See list of names with RadianceObj.scenes and sceneNames")

if sceneDict is None:
print('makeScene(moduletype, sceneDict, nMods, nRows). '+\
Expand Down Expand Up @@ -3557,6 +3560,47 @@ def _makeSceneNxR(self, modulename=None, sceneDict=None, radname=None):
# self.hub_height = hubheight
return radfile

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.
Useful when using addCustomObject to the scene.
Parameters
----------
customObject : str
Directory and name of custom object .rad file is stored, and any geometry
modifications needed for it.
Returns
-------
Nothing, the radfile must already be created and assigned when running this.
"""

#TODO: Add a custom name and replace radfile name

# py2 and 3 compatible: binary write, encode text first

if radfile: #append radfile to list
if type(self.radfiles) == list:
self.radfiles.append(radfile)
else:
self.radfiles = [self.radfiles, radfile]
else:
radfile = self.radfiles

if customObject:
text2 = '\n!xform -rx 0 ' + customObject

debug = False
if debug:
print (text2)

with open(radfile, 'a+') as f:
f.write(text2)


def showScene(self):
"""
Expand Down
36 changes: 22 additions & 14 deletions docs/tutorials/19 - East & West Facing Sheds.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
{
"data": {
"text/plain": [
"'0.3.4+406.g49eb243.dirty'"
"'0.4.2+191.g35f6f6b.dirty'"
]
},
"execution_count": 2,
Expand All @@ -62,7 +62,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"path = C:\\Users\\sayala\\Documents\\GitHub\\bifacial_radiance\\bifacial_radiance\\Tutorial_01\n",
"path = C:\\Users\\cdeline\\Documents\\Python Scripts\\Bifacial_Radiance\\bifacial_radiance\\Tutorial_01\n",
"Making path: images\n",
"Making path: objects\n",
"Making path: results\n",
Expand Down Expand Up @@ -200,7 +200,15 @@
"execution_count": 7,
"id": "baefeae4",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Additional scene Scene1 created! See list of names with RadianceObj.scenes and sceneNames\n"
]
}
],
"source": [
"sceneDict = {'tilt':tilt,'pitch':pitch,'clearance_height':clearance_height,'azimuth':90, 'nMods': nMods, 'nRows': nRows, \n",
" 'appendRadfile':True} \n",
Expand Down Expand Up @@ -253,12 +261,12 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 12,
"id": "30db75b0",
"metadata": {},
"outputs": [],
"source": [
"#!rvu -vf views\\front.vp -e .01 -pe 0.3 -vp 1 -45 40 -vd 0 0.7 -0.7 MultipleObj.oct"
"#!rvu -vf views\\front.vp -e .01 -pe 0.3 -vp 1 -45 40 -vd 0 0.7 -0.7 tutorial_19.oct"
]
},
{
Expand All @@ -271,12 +279,12 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 11,
"id": "e8f92da0",
"metadata": {},
"outputs": [],
"source": [
"# !rvu -vf views\\front.vp -e .01 -pe 0.3 -vp -4 -29 3.5 -vd 0 1 0 MultipleObj.oct"
"# !rvu -vf views\\front.vp -e .01 -pe 0.3 -vp -4 -29 3.5 -vd 0 1 0 tutorial_19.oct"
]
},
{
Expand All @@ -291,20 +299,20 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 13,
"id": "b07a3e03",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Linescan in process: EastFacingShed_Front\n",
"Linescan in process: EastFacingShed_Back\n",
"Saved: results\\irr_EastFacingShed.csv\n",
"Linescan in process: WestFacingShed_Front\n",
"Linescan in process: WestFacingShed_Back\n",
"Saved: results\\irr_WestFacingShed.csv\n"
"Linescan in process: EastFacingShed_Row4_Module11_Front\n",
"Linescan in process: EastFacingShed_Row4_Module11_Back\n",
"Saved: results\\irr_EastFacingShed_Row4_Module11.csv\n",
"Linescan in process: WestFacingShed_Row4_Module11_Front\n",
"Linescan in process: WestFacingShed_Row4_Module11_Back\n",
"Saved: results\\irr_WestFacingShed_Row4_Module11.csv\n"
]
}
],
Expand Down
10 changes: 5 additions & 5 deletions docs/tutorials/19 - East & West Facing Sheds.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,25 +116,25 @@
#
# Top view:

# In[9]:
# In[12]:


#!rvu -vf views\front.vp -e .01 -pe 0.3 -vp 1 -45 40 -vd 0 0.7 -0.7 MultipleObj.oct
#!rvu -vf views\front.vp -e .01 -pe 0.3 -vp 1 -45 40 -vd 0 0.7 -0.7 tutorial_19.oct


# another view, close up:

# In[10]:
# In[11]:


# !rvu -vf views\front.vp -e .01 -pe 0.3 -vp -4 -29 3.5 -vd 0 1 0 MultipleObj.oct
# !rvu -vf views\front.vp -e .01 -pe 0.3 -vp -4 -29 3.5 -vd 0 1 0 tutorial_19.oct


# ## Analysis
#
# We have to analyze the East and the West shed independently.

# In[11]:
# In[13]:


sensorsy=4 # 1 per module. consider increasing the number but be careful with sensors in the space between modules.
Expand Down
56 changes: 36 additions & 20 deletions docs/tutorials/7 - Multiple Scene Objects.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Your simulation will be stored in C:\\Users\\sayala\\Documents\\GitHub\\bifacial_radiance\\bifacial_radiance\\TEMP\\Tutorial_07\n"
"Your simulation will be stored in C:\\Users\\cdeline\\Documents\\Python Scripts\\Bifacial_Radiance\\bifacial_radiance\\TEMP\\Tutorial_07\n"
]
}
],
Expand Down Expand Up @@ -96,7 +96,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"path = C:\\Users\\sayala\\Documents\\GitHub\\bifacial_radiance\\bifacial_radiance\\TEMP\\Tutorial_07\n",
"path = C:\\Users\\cdeline\\Documents\\Python Scripts\\Bifacial_Radiance\\bifacial_radiance\\TEMP\\Tutorial_07\n",
"Loading albedo, 1 value(s), 0.620 avg\n",
"1 nonzero albedo values.\n",
"Getting weather file: USA_VA_Richmond.724010_TMY2.epw\n",
Expand All @@ -107,7 +107,9 @@
"Calculating Sun position for Metdata that is right-labeled with a delta of -30 mins. i.e. 12 is 11:30 sunpos\n",
"\n",
"Module Name: test-moduleA\n",
"Module test-moduleA updated in module.json\n"
"Module test-moduleA updated in module.json\n",
"Pre-existing .rad file objects\\test-moduleA.rad will be overwritten\n",
"\n"
]
}
],
Expand All @@ -121,7 +123,7 @@
"demo.gendaylit(timestamp) \n",
"module_type = 'test-moduleA' \n",
"mymodule = demo.makeModule(name=module_type,y=1,x=1.7)\n",
"sceneDict = {'tilt':10,'pitch':1.5,'clearance_height':0.2,'azimuth':180, 'nMods': 5, 'nRows': 2, 'appendRadfile':True} \n",
"sceneDict = {'tilt':10,'pitch':1.5,'clearance_height':0.2,'azimuth':180, 'nMods': 5, 'nRows': 2} \n",
"sceneObj1 = demo.makeScene(mymodule, sceneDict) "
]
},
Expand All @@ -142,7 +144,7 @@
"output_type": "stream",
"text": [
"SceneObj1 modulefile: objects\\test-moduleA.rad\n",
"SceneObj1 SceneFile: objects\\test-moduleA_C_0.20000_rtr_1.50000_tilt_10.00000_5modsx2rows_origin0,0.rad\n",
"SceneObj1 SceneFile: ['objects\\\\test-moduleA_C_0.20000_rtr_1.50000_tilt_10.00000_5modsx2rows_origin0,0.rad']\n",
"SceneObj1 GCR: 0.67\n",
"FileLists: \n",
" ['materials\\\\ground.rad', 'skies\\\\sky2_37.5_-77.33_2001-06-17_1300.rad', 'objects\\\\test-moduleA_C_0.20000_rtr_1.50000_tilt_10.00000_5modsx2rows_origin0,0.rad']\n"
Expand Down Expand Up @@ -184,16 +186,31 @@
"text": [
"\n",
"Module Name: test-moduleB\n",
"Module test-moduleB updated in module.json\n"
"Module test-moduleB updated in module.json\n",
"Pre-existing .rad file objects\\test-moduleB.rad will be overwritten\n",
"\n",
"Additional scene Scene1 created! See list of names with RadianceObj.scenes and sceneNames\n"
]
},
{
"data": {
"text/plain": [
"['Scene0', 'Scene1']"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sceneDict2 = {'tilt':30,'pitch':5,'clearance_height':1,'azimuth':180, \n",
" 'nMods': 5, 'nRows': 1, 'originx': 0, 'originy': 3.5, 'appendRadfile':True} \n",
"module_type2='test-moduleB'\n",
"mymodule2 = demo.makeModule(name=module_type2,x=1,y=1.6, numpanels=2, ygap=0.15)\n",
"sceneObj2 = demo.makeScene(mymodule2, sceneDict2) \n"
"sceneObj2 = demo.makeScene(mymodule2, sceneDict2) \n",
"\n",
"demo.sceneNames()"
]
},
{
Expand All @@ -206,11 +223,11 @@
"output_type": "stream",
"text": [
"SceneObj1 modulefile: objects\\test-moduleA.rad\n",
"SceneObj1 SceneFile: objects\\test-moduleA_C_0.20000_rtr_1.50000_tilt_10.00000_5modsx2rows_origin0,0.rad\n",
"SceneObj1 SceneFile: ['objects\\\\test-moduleA_C_0.20000_rtr_1.50000_tilt_10.00000_5modsx2rows_origin0,0.rad']\n",
"SceneObj1 GCR: 0.67\n",
"\n",
"SceneObj2 modulefile: objects\\test-moduleB.rad\n",
"SceneObj2 SceneFile: objects\\test-moduleB_C_1.00000_rtr_5.00000_tilt_30.00000_5modsx1rows_origin0,3.5.rad\n",
"SceneObj2 SceneFile: ['objects\\\\test-moduleB_C_1.00000_rtr_5.00000_tilt_30.00000_5modsx1rows_origin0,3.5.rad']\n",
"SceneObj2 GCR: 0.67\n",
"NEW FileLists: \n",
" ['materials\\\\ground.rad', 'skies\\\\sky2_37.5_-77.33_2001-06-17_1300.rad', 'objects\\\\test-moduleA_C_0.20000_rtr_1.50000_tilt_10.00000_5modsx2rows_origin0,0.rad', 'objects\\\\test-moduleB_C_1.00000_rtr_5.00000_tilt_30.00000_5modsx1rows_origin0,3.5.rad']\n"
Expand Down Expand Up @@ -271,8 +288,8 @@
"# NOTE: offsetting translation by 0.1 so the center of the marker (with sides of 0.2) is at the desired coordinate.\n",
"name='Post1'\n",
"text='! genbox black originMarker 0.2 0.2 1 | xform -t -0.1 -0.1 0'\n",
"customObject = demo.makeCustomObject(name,text)\n",
"demo.appendtoScene(sceneObj1.radfiles, customObject, '!xform -rz 0')"
"customRadfile = demo.makeCustomObject(name,text)\n",
"sceneObj1.appendtoScene(customRadfile)"
]
},
{
Expand Down Expand Up @@ -370,7 +387,6 @@
" 'azimuth': 180,\n",
" 'nMods': 5,\n",
" 'nRows': 2,\n",
" 'appendRadfile': True,\n",
" 'axis_tilt': 0,\n",
" 'originx': 0,\n",
" 'originy': 0}"
Expand Down Expand Up @@ -423,10 +439,10 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Linescan in process: FirstObj_Front\n",
"Linescan in process: FirstObj_Back\n",
"Saved: results\\irr_FirstObj.csv\n",
"Annual bifacial ratio First Set of Panels: 0.129 \n"
"Linescan in process: FirstObj_Row1_Module3_Front\n",
"Linescan in process: FirstObj_Row1_Module3_Back\n",
"Saved: results\\irr_FirstObj_Row1_Module3.csv\n",
"Annual bifacial ratio First Set of Panels: 0.130 \n"
]
}
],
Expand Down Expand Up @@ -486,10 +502,10 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Linescan in process: SecondObj_Front\n",
"Linescan in process: SecondObj_Back\n",
"Saved: results\\irr_SecondObj.csv\n",
"Annual bifacial ratio Second Set of Panels: 0.292 \n"
"Linescan in process: SecondObj_Row1_Module4_Front\n",
"Linescan in process: SecondObj_Row1_Module4_Back\n",
"Saved: results\\irr_SecondObj_Row1_Module4.csv\n",
"Annual bifacial ratio Second Set of Panels: 0.293 \n"
]
}
],
Expand Down
8 changes: 5 additions & 3 deletions docs/tutorials/7 - Multiple Scene Objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
demo.gendaylit(timestamp)
module_type = 'test-moduleA'
mymodule = demo.makeModule(name=module_type,y=1,x=1.7)
sceneDict = {'tilt':10,'pitch':1.5,'clearance_height':0.2,'azimuth':180, 'nMods': 5, 'nRows': 2, 'appendRadfile':True}
sceneDict = {'tilt':10,'pitch':1.5,'clearance_height':0.2,'azimuth':180, 'nMods': 5, 'nRows': 2}
sceneObj1 = demo.makeScene(mymodule, sceneDict)


Expand Down Expand Up @@ -96,6 +96,8 @@
mymodule2 = demo.makeModule(name=module_type2,x=1,y=1.6, numpanels=2, ygap=0.15)
sceneObj2 = demo.makeScene(mymodule2, sceneDict2)

demo.sceneNames()


# In[5]:

Expand Down Expand Up @@ -130,8 +132,8 @@
# NOTE: offsetting translation by 0.1 so the center of the marker (with sides of 0.2) is at the desired coordinate.
name='Post1'
text='! genbox black originMarker 0.2 0.2 1 | xform -t -0.1 -0.1 0'
customObject = demo.makeCustomObject(name,text)
demo.appendtoScene(sceneObj1.radfiles, customObject, '!xform -rz 0')
customRadfile = demo.makeCustomObject(name,text)
sceneObj1.appendtoScene(customRadfile)


# <a id='step3'></a>
Expand Down

0 comments on commit bd3c73c

Please sign in to comment.