Welcome!#
Welcome to Tutorial AM2: PV Systems Modeling with Python, an Interactive Introduction
There are many open source PV modeling tools available that you can use to simulate and study PV systems. This tutorial will focus on teaching attendees PV modeling in Python through the use of pvlib python, a community supported tool for simulating the performance of PV energy systems. Python is becoming one of the scientific languages of choice, because it is so well supported by many open-source tools for math, science, statistics, and data exploration and visulation.
In this interactive tutorial we will go from getting acquainted with some common data used or measured in pv systems (i.e. weather), to modeling the AC energy output of a single-axis tracker system. This includes learning and simulating sun position, plane of array irradiances (POA), temperature models, single-diode models (SDM), and more.
We will review common vocabulary around Python and data aggregation
by hour, week, month, and visualization.
The tutorial will present hands-on examples in Python, enabled via Jupyter notebooks and Google Colaboratory (a remote hosted server for Jupyter notebooks with Python and the most common data science libraries) so you, the attendee, don’t have to install anything, and can follow along while we go over the theory and code! However, attendees will still require at least a computer.
The tutorial will wrap up with an overview of other available open-source tools for other aspects of modeling PV systems.
More on your teachers:#
The instructors are experienced in data, coding, and PV field performance modeling, so we look forward to all of your questions.
Silvana Ovaitt (nee Ayala Pelaez)I am a research scientist at NREL, focusing mostly on bifacial PV system’s performance, and circular economy. Python is my daily bread and butter for data analysis and building tools. Silvana has made substantial contributions to the NREL bifacialvf pvmismatch and bifacial radiance software packages. |
|
Mark MikofskiI am a principal solar engineer at DNV and product manager for SolarFarmer. I research, analyze, and predict PV system performance, degradation, and reliability. I have contributed to a few Python projects like pvlib python, PVMismatch, and SciPy. |
Learning Objectives#
Access weather data (TMY3), understand irradiance data, and visualize it monthly.
Calculate sun position, plane of array irradiance, and aggregate irradiance data into average daily insolation by month and year.
Calculate module temperature from ambient data.
Use POA and module temperature to forecast a module’s performance.
Overview#
The sketch below from the Sandia PV Performance Modeling Collaborative (PVPMC) outlines the topics we will cover in this tutorial:
Why learn this?#
PV-lib is a library of algorithms and routines that you might encounter the need to use if you’re doing anything PV-modeling related. It is managed by members of the PV research community, who make sure the formulas and code are not only sleek but accurate.
You want to know the sun position? No need to code from zero the SPA (Solar Position algorithm), it’s in PVlib.
You want to reproduce the Sandia-King model to calculate module performance? It’s there, also.
You can find the most well-known models, as well as recently accepted values and approaches in published PV literature.
We hope adding this tool to your skillset will empower you to do better, faster research with an already solid foundation. Don’t reinvent the wheel!
How to use this tutorial?#
This tutorial is a Jupyter notebook. Jupyter is a browser based interactive tool that combines text, images, equations, and code that can be shared with others. Please see the setup section in the README to learn more about how to get started.
Useful links#
Tutorial Structure#
This tutorial is made up of multiple Jupyter Notebooks. These notebooks mix code, text, visualization, and exercises.
If you haven’t used JupyterLab before, it’s similar to the Jupyter Notebook. If you haven’t used the Notebook, the quick intro is
There are two modes:
command
andedit
From
command
mode, pressEnter
to edit a cell (like this markdown cell)From
edit
mode, pressEsc
to change to command modePress
shift+enter
to execute a cell and move to the next cell.The toolbar has commands for executing, converting, and creating cells.
The layout of the tutorial will be as follows:
# if running on google colab, uncomment the next line and execute this cell to install the dependencies and prevent "ModuleNotFoundError" in later cells:
# !pip install -r https://raw.githubusercontent.com/PVSC-Python-Tutorials/PVSC50/main/requirements.txt
Exercise: Print Hello, world!#
Each notebook will have exercises for you to solve. You’ll be given a blank or partially completed cell, followed by a hidden cell with a solution. For example.
Print the text “Hello, world!”.
# Your code here
print("Hello, world!")
Hello, world!
Exercise 1: Modify to print something else:#
my_string = # Add your text here. Remember to put it inside of single quotes or double quotes ( " " or '' )
print(my_string)
Cell In[3], line 1
my_string = # Add your text here. Remember to put it inside of single quotes or double quotes ( " " or '' )
^
SyntaxError: invalid syntax
Let’s go over some Python Concepts#
(A lot of this examples were shamely taken from https://jckantor.github.io/CBE30338/01.01-Getting-Started-with-Python-and-Jupyter-Notebooks.html :$)
Basic Arithmetic Operations#
Basic arithmetic operations are built into the Python langauge. Here are some examples. In particular, note that exponentiation is done with the ** operator.
a = 2
b = 3
print(a + b)
print(a ** b)
print(a / b)
5
8
0.6666666666666666
Python Libraries#
The Python language has only very basic operations. Most math functions are in various math libraries. The numpy library is convenient library. This next cell shows how to import numpy with the prefix np, then use it to call a common mathematical functions.
import numpy as np
# mathematical constants
print(np.pi)
print(np.e)
# trignometric functions
angle = np.pi/4
print(np.sin(angle))
print(np.cos(angle))
print(np.tan(angle))
3.141592653589793
2.718281828459045
0.7071067811865476
0.7071067811865476
0.9999999999999999
Lists are a versatile way of organizing your data in Python. Here are some examples, more can be found on this Khan Academy video.
xList = [1, 2, 3, 4]
xList
[1, 2, 3, 4]
Concatenation#
Concatentation is the operation of joining one list to another.
x = [1, 2, 3, 4];
y = [5, 6, 7, 8];
x + y
[1, 2, 3, 4, 5, 6, 7, 8]
np.sum(x)
10
Loops#
for x in xList:
print("sin({0}) = {1:8.5f}".format(x,np.sin(x)))
sin(1) = 0.84147
sin(2) = 0.90930
sin(3) = 0.14112
sin(4) = -0.75680
Working with Dictionaries#
Dictionaries are useful for storing and retrieving data as key-value pairs. For example, here is a short dictionary of molar masses. The keys are molecular formulas, and the values are the corresponding molar masses.
States_SolarInstallations2020 = {'Arizona': 16.04, 'California': 30.02, 'Texas':18.00, 'Colorado': 44.01} # GW
States_SolarInstallations2020
{'Arizona': 16.04, 'California': 30.02, 'Texas': 18.0, 'Colorado': 44.01}
We can a value to an existing dictionary.
States_SolarInstallations2020['New Mexico'] = 22.4
Plotting#
Importing the matplotlib.pyplot library gives IPython notebooks plotting functionality very similar to Matlab’s. Here are some examples using functions from the
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0,10)
y = np.sin(x)
z = np.cos(x)
plt.plot(x,y,'b',x,z,'r')
plt.xlabel('Radians');
plt.ylabel('Value');
plt.title('Plotting Demonstration')
plt.legend(['Sin','Cos'])
plt.grid()

Going Deeper#
We’ve designed the notebooks above to cover the basics of pvlib from beginning to end. To help you go deeper, we’ve also create a list of notebooks that demonstrate real-world applications of pvlib in a variety of use cases. These need not be explored in any particular sequence, instead they are meant to provide a sampling of what pvlib can be used for.
PVLIB and Weather/Climate Model Data#
Check out the pvlib python examples gallery. Start with Sun path diagram, then feel free to explore the rest of the notebooks.
Open PV Tools#
There is a curated list of open source PV tools from “Review of Open Source Tools for PV Modeling” by Will Holmgren, et al. at IEEE 7th World Conference on PV Energy Conversion 2018.
This work is licensed under a Creative Commons Attribution 4.0 International License.