tutorial banner

Welcome!#

Welcome to the PV Software 101: from Sun position to AC Output! tutorial

Modeling tools for all aspects of photovoltaic systems are rapidly growing, and there are solutions for many of the things you might want to simulate. Python is becoming one of the scientific languages of choice, and many open-source tools are available for PV modeling. This tutorial will focus on teaching attendees PV modeling in python through the use of PVlib.

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, temperature models, single-diode models 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 a Jupyterhub (remote hosted server for jupyter notebooks and python language) so you, the attendee, don’t have to install anything, and can follow along while we go over the theory and code! In case it’s not obvious, a computer is required.

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 three of us have ample experience in data, coding, and PV field performance modeling, so we look forward to all of your questions.

Mark Mikofski

Mark Mikofski


I 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

Silvana Ayala Pelaez

Silvana 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.

Kevin Anderson

Kevin Anderson


I am a research scientist at NREL doing cool stuff! I have contributed to work on slope aware backtracking, clipping loss errors in hourly yield estimates, and am a maintainer for pvlib python and a frequent contributor to RdTools.

Learning Objectives#

  1. Access weather data (TMY3), understand irradiance data, and visualize it monthly.

  2. Calculate sun position, plane of array irradiance, and aggregate irradiance data into average daily insolation by month and year.

  3. Calculate module temperature from ambient data.

  4. 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:

Overview

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.

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

  1. There are two modes: command and edit

  2. From command mode, press Enter to edit a cell (like this markdown cell)

  3. From edit mode, press Esc to change to command mode

  4. Press shift+enter to execute a cell and move to the next cell.

  5. The toolbar has commands for executing, converting, and creating cells.

The layout of the tutorial will be as follows:

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)
  File "/tmp/ipykernel_1744/3863091146.py", 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()
_images/cb4c149607b1918f53871059b07ca01acd6e2b116a92199bdc88a7a2c91bb7d8.png

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.

Creative Commons License

This work is licensed under a Creative Commons Attribution 4.0 International License.