Skip to content

Commit

Permalink
Tutorial notebook updates. Add py3.12 support
Browse files Browse the repository at this point in the history
  • Loading branch information
cdeline committed Oct 14, 2024
1 parent 5f2a2b3 commit 69b3d65
Show file tree
Hide file tree
Showing 10 changed files with 266 additions and 238 deletions.
232 changes: 114 additions & 118 deletions docs/tutorials/1 - Fixed Tilt Yearly Results.ipynb

Large diffs are not rendered by default.

53 changes: 33 additions & 20 deletions docs/tutorials/1 - Fixed Tilt Yearly Results.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# coding: utf-8

# In[2]:
# In[1]:


# This information helps with debugging and getting support :)
Expand Down Expand Up @@ -67,7 +67,7 @@
#
#

# In[1]:
# In[2]:


import os
Expand All @@ -86,7 +86,7 @@

# This will load bifacial_radiance and other libraries from python that will be useful for this Jupyter Journal:

# In[2]:
# In[3]:


try:
Expand All @@ -101,7 +101,7 @@

# ## 2. Create a Radiance Object

# In[3]:
# In[4]:


# Create a RadianceObj 'object' named bifacial_example. no whitespace allowed
Expand All @@ -119,7 +119,7 @@

# To see more options of ground materials available (located on ground.rad), run this function without any input.

# In[4]:
# In[5]:


# Input albedo number or material name like 'concrete'.
Expand All @@ -128,7 +128,7 @@

# If a number between 0 and 1 is passed, it assumes it's an albedo value. For this example, we want a high-reflectivity rooftop albedo surface, so we will set the albedo to 0.62

# In[5]:
# In[6]:


albedo = 0.62
Expand All @@ -141,7 +141,7 @@
#
# There are various options provided in bifacial_radiance to load weatherfiles. getEPW is useful because you just set the latitude and longitude of the location and it donwloads the meteorologicla data for any location.

# In[6]:
# In[7]:


# Pull in meteorological data using pyEPW for any global lat/lon
Expand All @@ -152,7 +152,7 @@
#
# To load the data, use readWeatherFile. This reads EPWs, TMY meterological data, or even your own data as long as it follows TMY data format (With any time resoultion).

# In[7]:
# In[8]:


# Read in the weather data pulled in above.
Expand All @@ -167,7 +167,7 @@
# or using gencumulativesky to generate a cumulativesky for the entire year.
#

# In[8]:
# In[9]:


fullYear = True
Expand Down Expand Up @@ -196,7 +196,8 @@
# </div>
#

# In[9]:
# In[10]:



module_type = 'test-module'
Expand All @@ -206,7 +207,8 @@

# In case you want to use a pre-defined module or a module you've created previously, they are stored in a JSON format in data/module.json, and the options available can be called with printModules:

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



availableModules = demo.printModules()
Expand All @@ -221,15 +223,17 @@
# Azimuth gets measured from N = 0, so for South facing modules azimuth should equal 180 degrees
#

# In[11]:
# In[12]:



sceneDict = {'tilt':10,'pitch':3,'clearance_height':0.2,'azimuth':180, 'nMods': 20, 'nRows': 7}


# To make the scene we have to create a Scene Object through the method makeScene. This method will create a .rad file in the objects folder, with the parameters specified in sceneDict and the module created above. You can alternatively pass a string with the name of the `moduletype`.

# In[12]:
# In[13]:



scene = demo.makeScene(module,sceneDict)
Expand All @@ -242,15 +246,17 @@
# Radiance requires an "Oct" file that combines the ground, sky and the scene object into it.
# The method makeOct does this for us.

# In[13]:
# In[14]:



octfile = demo.makeOct(demo.getfilelist())


# To see what files got merged into the octfile, you can use the helper method getfilelist. This is useful for advanced simulations too, specially when you want to have different Scene objects in the same simulation, or if you want to add other custom elements to your scene (like a building, for example)

# In[14]:
# In[15]:



demo.getfilelist()
Expand All @@ -265,15 +271,17 @@

# First let's create the Analysis Object

# In[15]:
# In[16]:



analysis = AnalysisObj(octfile, demo.basename)


# Then let's specify the sensor location. If no parameters are passed to moduleAnalysis, it will scan the center module of the center row:

# In[16]:
# In[17]:



frontscan, backscan = analysis.moduleAnalysis(scene)
Expand All @@ -284,15 +292,17 @@
# ![Simple example for south facing module](../images_wiki/Journal1Pics/frontscan_backscan.png)
# Analysis saves the measured irradiances in the front and in the back on the results folder. Prints out the ratio of the average of the rear and front irradiance values along a chord of the module.

# In[17]:
# In[18]:



results = analysis.analysis(octfile, demo.basename, frontscan, backscan)


# The results are also automatically saved in the results folder. Some of our input/output functions can be used to read the results and work with them, for example:

# In[18]:
# In[19]:



load.read1Result('results\irr_tutorial_1.csv')
Expand All @@ -304,7 +314,8 @@
#
# Assuming that our module has a bifaciality factor (rear to front performance) of 90%, our <u> bifacial gain </u> is of:

# In[19]:
# In[20]:



bifacialityfactor = 0.9
Expand All @@ -323,6 +334,7 @@
# In[20]:



## Comment the ! line below to run rvu from the Jupyter notebook instead of your terminal.
## Simulation will stop until you close the rvu window

Expand All @@ -338,6 +350,7 @@
# In[21]:



## Comment the line below to run rvu from the Jupyter notebook instead of your terminal.
## Simulation will stop until you close the rvu window

Expand Down
40 changes: 21 additions & 19 deletions docs/tutorials/11 - AgriPV Systems.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# coding: utf-8

# In[ ]:
# In[1]:


# This information helps with debugging and getting support :)
Expand Down Expand Up @@ -56,7 +56,7 @@
#
# The magic is that, for doing the carport we see in the figure, we are going to do a 4-up configuration of modules (**numpanels**), and we are going to repeat that 3-UP 6 times (**nMods**)

# In[1]:
# In[2]:


import os
Expand All @@ -70,15 +70,15 @@
print ("Your simulation will be stored in %s" % testfolder)


# In[2]:
# In[3]:


from bifacial_radiance import *
import numpy as np
import pandas as pd


# In[3]:
# In[4]:


simulationname = 'tutorial_11'
Expand Down Expand Up @@ -147,7 +147,8 @@
#
# ***rvu -vf views\front.vp -e .01 tutorial_11.oct***

# In[4]:
# In[5]:



## Comment the ! line below to run rvu from the Jupyter notebook instead of your terminal.
Expand All @@ -168,7 +169,7 @@
#
# Positions of the piles could be done more programatically, but they are kinda estimated at the moment.

# In[5]:
# In[7]:


torquetubelength = module.scenex*(nMods)
Expand All @@ -192,7 +193,7 @@
demo.appendtoScene(radfile=scene.radfiles, customObject=customObject, text="!xform -rz 0")


# In[6]:
# In[8]:


name='Pile'
Expand Down Expand Up @@ -220,7 +221,8 @@
#
#

# In[7]:
# In[9]:



## Comment the ! line below to run rvu from the Jupyter notebook instead of your terminal.
Expand All @@ -240,21 +242,21 @@
#
# We are also increasign the number of points sampled accross the collector width, with the variable **sensorsy** passed to **moduleanalysis**. We are also increasing the step between sampling points, to be able to sample in between the rows.

# In[8]:
# In[10]:


analysis = AnalysisObj(octfile, demo.name)
sensorsy = 20
frontscan, backscan = analysis.moduleAnalysis(scene, sensorsy=sensorsy)


# In[9]:
# In[11]:


groundscan = frontscan


# In[10]:
# In[12]:


groundscan['zstart'] = 0.05 # setting it 5 cm from the ground.
Expand All @@ -263,7 +265,7 @@
groundscan


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


analysis.analysis(octfile, simulationname+"_groundscan", groundscan, backscan) # compare the back vs front irradiance
Expand All @@ -281,13 +283,13 @@

# ![AgriPV modeled step 4](../images_wiki/AdvancedJournals/spacing_between_modules.PNG)

# In[12]:
# In[14]:


import seaborn as sns


# In[13]:
# In[ ]:


sensorsx = 20
Expand All @@ -306,7 +308,7 @@

# Read all the files generated into one dataframe

# In[14]:
# In[ ]:


filestarter = "irr_tutorial_11_groundscan_"
Expand Down Expand Up @@ -347,21 +349,21 @@

# Creating a new dataframe where each element in the front irradiance list is a column. Also transpose and reverse so it looks like a top-down view of the ground.

# In[15]:
# In[ ]:


df3 = pd.DataFrame(resultsdf['br_Wm2Front'].to_list())
reversed_df = df3.T.iloc[::-1]


# In[16]:
# In[ ]:


sns.set(rc={'figure.figsize':(11.7,8.27)})
print(sns)


# In[17]:
# In[ ]:


# Plot
Expand All @@ -381,7 +383,7 @@
#
#

# In[18]:
# In[ ]:


name='Center_Grass'
Expand Down
Loading

0 comments on commit 69b3d65

Please sign in to comment.