{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Working on a Windows 10\n", "Python version 3.11.8 | packaged by conda-forge | (main, Feb 16 2024, 20:40:50) [MSC v.1937 64 bit (AMD64)]\n", "Pandas version 2.2.3\n", "bifacial_radiance version 0.5.0b2.dev4+gedb973d.d20250924\n" ] } ], "source": [ "# This information helps with debugging and getting support :)\n", "import sys, platform\n", "import pandas as pd\n", "import bifacial_radiance as br\n", "print(\"Working on a \", platform.system(), platform.release())\n", "print(\"Python version \", sys.version)\n", "print(\"Pandas version \", pd.__version__)\n", "print(\"bifacial_radiance version \", br.__version__)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 7 - Multiple Scene Objects\n", "\n", "This journal shows how to:\n", "\n", "* Create multiple scene objects in the same scene.\n", "* Analyze multiple scene objects in the same scene \n", "* Add a marker to find the origin (0,0) on a scene (for sanity-checks/visualization).\n", "\n", "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:\n", "\n", "![multiple Scene Objects Example](../images_wiki/Journal_example_multiple_objects.PNG)\n", "\n", "\n", "### Steps:\n", "\n", "1. Generating the setups\n", " 1. Generating the firt scene object\n", " 2. Generating the second scene object.\n", "2. Add a Marker at the Origin (coordinates 0,0) for help with visualization \n", "3. Combine all scene Objects into one OCT file & Visualize \n", "4. Analysis for Each sceneObject " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 1. Generating the Setups" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Your simulation will be stored in C:\\Users\\cdeline\\Documents\\Python Scripts\\Bifacial_Radiance\\bifacial_radiance\\TEMP\\Tutorial_07\n" ] } ], "source": [ "import os\n", "import numpy as np\n", "import pandas as pd\n", "from pathlib import Path\n", "\n", "testfolder = str(Path().resolve().parent.parent / 'bifacial_radiance' / 'TEMP' / 'Tutorial_07')\n", "if not os.path.exists(testfolder):\n", " os.makedirs(testfolder)\n", " \n", "print (\"Your simulation will be stored in %s\" % testfolder)\n", " \n", "from bifacial_radiance import RadianceObj, AnalysisObj " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### A. Generating the first scene object\n", "\n", "This is a standard fixed-tilt setup for one hour. Gencumsky could be used too for the whole year.\n", "\n", "The key here is that we are setting in sceneDict the variable **appendRadfile** to true." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "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", " ... OK!\n", "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.\n", "Coercing year to 2001\n", "Saving file EPWs\\metdata_temp.csv, # points: 8760\n", "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", "Pre-existing .rad file objects\\test-moduleA.rad will be overwritten\n", "\n" ] } ], "source": [ "demo = RadianceObj(\"tutorial_7\", path = testfolder) \n", "demo.setGround(0.62)\n", "epwfile = demo.getEPW(lat = 37.5, lon = -77.6) \n", "metdata = demo.readWeatherFile(epwfile, coerce_year=2001) \n", "fullYear = True\n", "timestamp = metdata.datetime.index(pd.to_datetime('2001-06-17 13:0:0 -5')) # Noon, June 17th \n", "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} \n", "sceneObj1 = demo.makeScene(mymodule, sceneDict) " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Checking values after Scene for the scene Object created" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "SceneObj1 modulefile: objects\\test-moduleA.rad\n", "SceneObj1 SceneFile: ['objects\\\\test-moduleA_C_0.20_rtr_1.50_tilt_10_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.20_rtr_1.50_tilt_10_5modsx2rows_origin0,0.rad']\n" ] } ], "source": [ "print (\"SceneObj1 modulefile: %s\" % sceneObj1.modulefile)\n", "print (\"SceneObj1 SceneFile: %s\" %sceneObj1.radfiles)\n", "print (\"SceneObj1 GCR: %s\" % round(sceneObj1.gcr,2))\n", "print (\"FileLists: \\n %s\" % demo.getfilelist())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### B. Generating the second scene object.\n", "\n", "Creating a different Scene. Same Module, different values.\n", "Notice we are passing a different **originx** and **originy** to displace the center of this new sceneObj to that location.\n", "\n", "To make this work, we **need** to use `append=True`. Otherwise the second scene will overwrite the first.\n" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Module Name: test-moduleB\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": 5, "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, append=True) \n", "\n", "demo.sceneNames()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "SceneObj1 modulefile: objects\\test-moduleA.rad\n", "SceneObj1 SceneFile: ['objects\\\\test-moduleA_C_0.20_rtr_1.50_tilt_10_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.00_rtr_5.00_tilt_30_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.20_rtr_1.50_tilt_10_5modsx2rows_origin0,0.rad', 'objects\\\\test-moduleB_C_1.00_rtr_5.00_tilt_30_5modsx1rows_origin0,3.5.rad']\n" ] } ], "source": [ "# Checking values for both scenes after creating new SceneObj\n", "print (\"SceneObj1 modulefile: %s\" % sceneObj1.modulefile)\n", "print (\"SceneObj1 SceneFile: %s\" %sceneObj1.radfiles)\n", "print (\"SceneObj1 GCR: %s\" % round(sceneObj1.gcr,2))\n", "\n", "print (\"\\nSceneObj2 modulefile: %s\" % sceneObj2.modulefile)\n", "print (\"SceneObj2 SceneFile: %s\" %sceneObj2.radfiles)\n", "print (\"SceneObj2 GCR: %s\" % round(sceneObj2.gcr,2))\n", "\n", "#getfilelist should have info for the rad file created by BOTH scene objects.\n", "print (\"NEW FileLists: \\n %s\" % demo.getfilelist())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 2. Add a Marker at the Origin (coordinates 0,0) for help with visualization\n", "\n", "Creating 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).\n", "\n", "
\n", "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. \n", "
\n" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Custom Object Name objects\\Post1.rad\n" ] } ], "source": [ "# 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", "customRadfile = demo.makeCustomObject(name,text)\n", "sceneObj1.appendtoScene(customObject=customRadfile)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 3. Combine all scene Objects into one OCT file & Visualize\n", "Marking this as its own steps because this is the step that joins our Scene Objects 1, 2 and the appended Post.\n", "Run makeOCT to make the scene with both scene objects AND the marker in it, the ground and the skies." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Created tutorial_7.oct\n" ] } ], "source": [ "octfile = demo.makeOct(demo.getfilelist()) " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "At this point you should be able to go into a command window (cmd.exe) and check the geometry. Example:\n", "\n", "##### rvu -vf views\\front.vp -e .01 -pe 0.3 -vp 1 -7.5 12 tutorial_7.oct\n" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "\n", "## Comment the ! line below to run rvu from the Jupyter notebook instead of your terminal.\n", "## Simulation will stop until you close the rvu window\n", "\n", "#!rvu -vf views\\front.vp -e .01 -pe 0.3 -vp 1 -7.5 12 tutorial_7.oct\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "It should look something like this:\n", "\n", "![multiple Scene Objects Example](../images_wiki/Journal_example_multiple_objects.PNG)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 4. Analysis for Each sceneObject\n", "\n", "a **sceneDict** is saved for each scene. When calling the Analysis, you should reference the scene object you want." ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'tilt': 10,\n", " 'pitch': 1.5,\n", " 'clearance_height': 0.2,\n", " 'azimuth': 180,\n", " 'nMods': 5,\n", " 'nRows': 2,\n", " 'axis_tilt': 0,\n", " 'originx': 0,\n", " 'originy': 0}" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sceneObj1.sceneDict" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'tilt': 30,\n", " 'pitch': 5,\n", " 'clearance_height': 1,\n", " 'azimuth': 180,\n", " 'nMods': 5,\n", " 'nRows': 1,\n", " 'originx': 0,\n", " 'originy': 3.5,\n", " 'appendRadfile': True,\n", " 'axis_tilt': 0}" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sceneObj2.sceneDict" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "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.129 \n" ] } ], "source": [ "analysis = AnalysisObj(octfile, demo.basename) \n", "frontscan, backscan = analysis.moduleAnalysis(sceneObj1)\n", "frontdict, backdict = analysis.analysis(octfile, \"FirstObj\", frontscan, backscan) # compare the back vs front irradiance \n", "print('Annual bifacial ratio First Set of Panels: %0.3f ' %( np.mean(analysis.Wm2Back) / np.mean(analysis.Wm2Front)) )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's do a Sanity check for first object:\n", "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.....\"\"" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", "\n", "[-0.3982 -0.2998 -0.2012 -0.1028 -0.00415 0.0945 0.1926 0.2913\n", " 0.39 ]\n", "\n", "['a2.0.a0.test-moduleA.6457' 'a2.0.a0.test-moduleA.6457'\n", " 'a2.0.a0.test-moduleA.6457' 'a2.0.a0.test-moduleA.6457'\n", " 'a2.0.a0.test-moduleA.6457' 'a2.0.a0.test-moduleA.6457'\n", " 'a2.0.a0.test-moduleA.6457' 'a2.0.a0.test-moduleA.6457'\n", " 'a2.0.a0.test-moduleA.6457']\n" ] } ], "source": [ "print (frontdict['x'])\n", "print (\"\")\n", "print (frontdict['y'])\n", "print (\"\")\n", "print (frontdict['mattype'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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.\n" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "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.294 \n" ] } ], "source": [ "analysis2 = AnalysisObj(octfile, demo.basename) \n", "modWanted = 4\n", "rowWanted = 1\n", "sensorsy=4\n", "frontscan, backscan = analysis2.moduleAnalysis(sceneObj2, modWanted = modWanted, rowWanted = rowWanted, sensorsy=sensorsy)\n", "frontdict2, backdict2 = analysis2.analysis(octfile, \"SecondObj\", frontscan, backscan) \n", "print('Annual bifacial ratio Second Set of Panels: %0.3f ' %( np.mean(analysis2.Wm2Back) / np.mean(analysis2.Wm2Front)) )" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "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" ] } ], "source": [ "analysis2 = AnalysisObj(octfile, demo.basename) \n", "modWanted = 4\n", "rowWanted = 1\n", "sensorsy=4\n", "frontscan, backscan = analysis2.moduleAnalysis(sceneObj2, modWanted = modWanted, rowWanted = rowWanted, sensorsy=sensorsy)\n", "frontdict2, backdict2 = analysis2.analysis(octfile, \"SecondObj\", frontscan, backscan) \n", "print('Annual bifacial ratio Second Set of Panels: %0.3f ' %( np.mean(analysis2.Wm2Back) / np.mean(analysis2.Wm2Front)) )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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.\n" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "x coordinate points: [1.01 1.01 1.01 1.01]\n", "\n", "y coordinate points: [2.617 3.197 3.777 4.36 ]\n", "\n", "Elements intersected at each point: ['a3.0.a0.test-moduleB.6457' 'a3.0.a0.test-moduleB.6457'\n", " 'a3.0.a1.test-moduleB.6457' 'a3.0.a1.test-moduleB.6457']\n" ] } ], "source": [ "print (\"x coordinate points:\" , frontdict2['x'])\n", "print (\"\")\n", "print (\"y coordinate points:\", frontdict2['y'])\n", "print (\"\")\n", "print (\"Elements intersected at each point: \", frontdict2['mattype'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Visualizing the coordinates and module analyzed with an image:\n", " \n", "![multiple Scene Objects Example](../images_wiki/AdvancedJournals/MultipleSceneObject_AnalysingSceneObj2_Row1_Module4.PNG)\n" ] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.13" } }, "nbformat": 4, "nbformat_minor": 1 }