<jupyter_start><jupyter_text>7 - Advanced topics - Multiple SceneObjects ExampleThis journal shows how to:     Create multiple scene objects in the same scene.      Analyze multiple scene objects in the same scene      Add a marker to find the origin (0,0) on a scene (for sanity-checks/visualization). A scene Object is defined as an array of modules, with whatever parameters you want to give it. In this case, we are modeling one array of 2 rows of 5 modules in landscape, and one array of 1 row of 5 modules in 2-UP, portrait configuration, as the image below:![multiple Scene Objects Example](../images_wiki/Journal_example_multiple_objects.PNG) Steps:      Generating the setups              Generating the firt scene object          Generating the second scene object.          Add a Marker at the Origin (coordinates 0,0) for help with visualization          Combine all scene Objects into one OCT file  & Visualize       Analysis for Each sceneObject    1. Generating the Setups<jupyter_code>import os
import numpy as np
import pandas as pd
from pathlib import Path

testfolder = str(Path().resolve().parent.parent / 'bifacial_radiance' / 'TEMP' / 'Tutorial_07')
if not os.path.exists(testfolder):
    os.makedirs(testfolder)
    
print ("Your simulation will be stored in %s" % testfolder)
    
from bifacial_radiance import RadianceObj, AnalysisObj<jupyter_output>Your simulation will be stored in C:\Users\sayala\Documents\GitHub\bifacial_radiance\bifacial_radiance\TEMP\Tutorial_07<jupyter_text>A. Generating the first scene objectThis is a standard fixed-tilt setup for one hour. Gencumsky could be used too for the whole year.The key here is that we are setting in sceneDict the variable **appendRadfile** to true.<jupyter_code>demo = RadianceObj("tutorial_7", path = testfolder) 
demo.setGround(0.62)
epwfile = demo.getEPW(lat = 37.5, lon = -77.6)    
metdata = demo.readWeatherFile(epwfile, coerce_year=2001) 
fullYear = True
timestamp = metdata.datetime.index(pd.to_datetime('2001-06-17 13:0:0 -5'))  # Noon, June 17th  
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} 
sceneObj1 = demo.makeScene(mymodule, sceneDict)<jupyter_output>path = C:\Users\sayala\Documents\GitHub\bifacial_radiance\bifacial_radiance\TEMP\Tutorial_07
Loading albedo, 1 value(s), 0.620 avg
1 nonzero albedo values.
Getting weather file: USA_VA_Richmond.724010_TMY2.epw
 ... OK!
8760 line in WeatherFile. Assuming this is a standard hourly WeatherFile for the year for purposes of saving Gencumulativesky temporary weather files in EPW folder.
Coercing year to 2001
Saving file EPWs\metdata_temp.csv, # points: 8760
Calculating Sun position for Metdata that is right-labeled  with a delta of -30 mins. i.e. 12 is 11:30 sunpos

Module Name: test-moduleA
Module test-moduleA updated in module.json<jupyter_text>Checking values after Scene for the scene Object created<jupyter_code>print ("SceneObj1 modulefile: %s" % sceneObj1.modulefile)
print ("SceneObj1 SceneFile: %s" %sceneObj1.radfiles)
print ("SceneObj1 GCR: %s" % round(sceneObj1.gcr,2))
print ("FileLists: \n %s" % demo.getfilelist())<jupyter_output>SceneObj1 modulefile: objects\test-moduleA.rad
SceneObj1 SceneFile: objects\test-moduleA_C_0.20000_rtr_1.50000_tilt_10.00000_5modsx2rows_origin0,0.rad
SceneObj1 GCR: 0.67
FileLists: 
 ['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']<jupyter_text>B. Generating the second scene object.Creating a different Scene. Same Module, different values.Notice we are passing a different **originx** and **originy** to displace the center of this new sceneObj to that location.<jupyter_code>sceneDict2 = {'tilt':30,'pitch':5,'clearance_height':1,'azimuth':180, 
              'nMods': 5, 'nRows': 1, 'originx': 0, 'originy': 3.5, 'appendRadfile':True} 
module_type2='test-moduleB'
mymodule2 = demo.makeModule(name=module_type2,x=1,y=1.6, numpanels=2, ygap=0.15)
sceneObj2 = demo.makeScene(mymodule2, sceneDict2)  

# Checking values for both scenes after creating new SceneObj
print ("SceneObj1 modulefile: %s" % sceneObj1.modulefile)
print ("SceneObj1 SceneFile: %s" %sceneObj1.radfiles)
print ("SceneObj1 GCR: %s" % round(sceneObj1.gcr,2))

print ("\nSceneObj2 modulefile: %s" % sceneObj2.modulefile)
print ("SceneObj2 SceneFile: %s" %sceneObj2.radfiles)
print ("SceneObj2 GCR: %s" % round(sceneObj2.gcr,2))

#getfilelist should have info for the rad file created by BOTH scene objects.
print ("NEW FileLists: \n %s" % demo.getfilelist())<jupyter_output>SceneObj1 modulefile: objects\test-moduleA.rad
SceneObj1 SceneFile: objects\test-moduleA_C_0.20000_rtr_1.50000_tilt_10.00000_5modsx2rows_origin0,0.rad
SceneObj1 GCR: 0.67

SceneObj2 modulefile: objects\test-moduleB.rad
SceneObj2 SceneFile: objects\test-moduleB_C_1.00000_rtr_5.00000_tilt_30.00000_5modsx1rows_origin0,3.5.rad
SceneObj2 GCR: 0.67
NEW FileLists: 
 ['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']<jupyter_text>2. Add a Marker at the Origin (coordinates 0,0) for help with visualizationCreating a "markers" for the geometry is useful to orient one-self when doing sanity-checks (for example, marke where 0,0 is, or where 5,0 coordinate is).Note that if you analyze the module that intersects with the marker, some of the sensors will be wrong. To perform valid analysis, do so without markers, as they are 'real' objects on your scene.<jupyter_code># 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')<jupyter_output>Custom Object Name objects\Post1.rad<jupyter_text>3. Combine all scene Objects into one OCT file & VisualizeMarking this as its own steps because this is the step that joins our Scene Objects 1, 2 and the appended Post.Run makeOCT to make the scene with both scene objects AND the marker in it, the ground and the skies.<jupyter_code>octfile = demo.makeOct(demo.getfilelist())<jupyter_output>Created tutorial_7.oct<jupyter_text>At this point you should be able to go into a command window (cmd.exe) and check the geometry. Example: rvu -vf views\front.vp -e .01 -pe 0.3 -vp 1 -7.5 12 tutorial_7.oct<jupyter_code>## Comment the ! line below to run rvu from the Jupyter notebook instead of your terminal.
## Simulation will stop until you close the rvu window

#!rvu -vf views\front.vp -e .01 -pe 0.3 -vp 1 -7.5 12 tutorial_7.oct<jupyter_output><empty_output><jupyter_text>It should look something like this:![multiple Scene Objects Example](../images_wiki/Journal_example_multiple_objects.PNG)   4. Analysis for Each sceneObjecta **sceneDict** is saved for each scene. When calling the Analysis, you should reference the scene object you want.<jupyter_code>sceneObj1.sceneDict
sceneObj2.sceneDict
analysis = AnalysisObj(octfile, demo.basename)  
frontscan, backscan = analysis.moduleAnalysis(sceneObj1)
frontdict, backdict = analysis.analysis(octfile, "FirstObj", frontscan, backscan)  # compare the back vs front irradiance  
print('Annual bifacial ratio First Set of Panels: %0.3f ' %( np.mean(analysis.Wm2Back) / np.mean(analysis.Wm2Front)) )<jupyter_output>Linescan in process: FirstObj_Front
Linescan in process: FirstObj_Back
Saved: results\irr_FirstObj.csv
Annual bifacial ratio First Set of Panels: 0.129<jupyter_text>Let's do a Sanity check for first object:Since we didn't pass any desired module, it should grab the center module of the center row (rounding down). For 2 rows and 5 modules, that is row 1, module 3 ~ indexed at 0, a2.0.a0.PVmodule.....""<jupyter_code>print (frontdict['x'])
print ("")
print (frontdict['y'])
print ("")
print (frontdict['mattype'])<jupyter_output>[4.868825e-17, 3.662783e-17, 2.456741e-17, 1.2507e-17, 4.465811e-19, -1.161384e-17, -2.367425e-17, -3.573467e-17, -4.779509e-17]

[-0.3975697, -0.2990889, -0.2006082, -0.1021274, -0.003646612, 0.09483416, 0.1933149, 0.2917957, 0.3902765]

['a2.0.a0.test-moduleA.6457', 'a2.0.a0.test-moduleA.6457', 'a2.0.a0.test-moduleA.6457', 'a2.0.a0.test-moduleA.6457', 'a2.0.a0.test-moduleA.6457', 'a2.0.a0.test-moduleA.6457', 'a2.0.a0.test-moduleA.6457', 'a2.0.a0.test-moduleA.6457', 'a2.0.a0.test-moduleA.6457']<jupyter_text>Let's analyze a module in sceneobject 2 now. Remember we can specify which module/row we want. We only have one row in this Object though.<jupyter_code>analysis2 = AnalysisObj(octfile, demo.basename)  
modWanted = 4
rowWanted = 1
sensorsy=4
frontscan, backscan = analysis2.moduleAnalysis(sceneObj2, modWanted = modWanted, rowWanted = rowWanted, sensorsy=sensorsy)
frontdict2, backdict2 = analysis2.analysis(octfile, "SecondObj", frontscan, backscan)  
print('Annual bifacial ratio Second Set of Panels: %0.3f ' %( np.mean(analysis2.Wm2Back) / np.mean(analysis2.Wm2Front)) )<jupyter_output>Linescan in process: SecondObj_Front
Linescan in process: SecondObj_Back
Saved: results\irr_SecondObj.csv
Annual bifacial ratio Second Set of Panels: 0.292<jupyter_text>Sanity check for first object. Since we didn't pass any desired module, it should grab the center module of the center row (rounding down). For 1 rows, that is row 0, module 4 ~ indexed at 0, a3.0.a0.Longi... and a3.0.a1.Longi since it is a 2-UP system.<jupyter_code>print ("x coordinate points:" , frontdict2['x'])
print ("")
print ("y coordinate points:", frontdict2['y'])
print ("")
print ("Elements intersected at each point: ", frontdict2['mattype'])<jupyter_output>x coordinate points: [1.01, 1.01, 1.01, 1.01]

y coordinate points: [2.619144, 3.199381, 3.779619, 4.359856]

Elements intersected at each point:  ['a3.0.a0.test-moduleB.6457', 'a3.0.a0.test-moduleB.6457', 'a3.0.a1.test-moduleB.6457', 'a3.0.a1.test-moduleB.6457']
{'fraction_non_alphanumeric': 0.10993740219092332, 'fraction_numerical': 0.07110719874804382, 'mean_word_length': 5.189467312348668, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '41823', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 3990, 'n_tokens_neox': 3550, 'n_words': 1035, 'path': 'docs/tutorials/7 - Advanced topics - Multiple SceneObjects Example.ipynb', 'repo_name': 'kperrynrel/bifacial_radiance', 'size': '10224'}