import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from importlib import reload
import solar
reload(solar)
= pd.read_csv('solar_Dornbirn.csv', parse_dates=True, index_col='datetime')
sdo print(sdo)
Assignment #08
Unit 08
Until next week, work through the material provided in Unit 8 and solve the following exercise.
This week focuses on solving complex, real-world tasks using gridded data and visualizing your results. This exercise provides yet another opportunity to enhance your proficiency in matrix indexing and for-loops.
Before you get started with your own code, make sure you download my version of the solar module that implements the set of equations from last unit and the spreadsheet solar_Dornbirn.csv that contains information about the position of the sun and its irradiance over one year in Dornbirn.
After you have done that, start a notebook and try to solve the task. The following code blocks give you some starting points.
We will perform the grid search by calling a function that implements the required computations at each iteration for us. In other words, this function computes the energy produced by the PV module. In the following, I define that function and within the function body I have left you an opportunity for exercise. This task is not essential to continue with the remaining tasks. Do not get hung up here. Tip: Use the method pd.Series.diff()
and the timedelta method .dt.total_seconds()
to compute the time sampling in hours. If the time sampling is not equal between all time steps, raise an error.
You can either put the function into solar
or directly into your notebook.
Energy generated by a PV module. The function implements the following physical considerations:
The power \(P\) generated by a PV module is the irradiance G (W/m2) multiplied by the area of the module A (m2) and the efficiency of the module \(\eta\), which in turn depends on temperature and a variety of other things. Let’s simplify and use \(\eta = 0.2\) for this exercise. The energy E generated by the module is then \(E = \sum P \cdot \Delta t\), where \(\Delta t\) is the sampling interval.
## Define a function that will compute the energy produced by the PV module
def comp_energy_produced(iswr0, beta, pvazimuth, elevangle, azimuth, datetime = None, efficiency=0.2, area=1):
"""
Calculate the energy produced by a PV module based on solar irradiance data.
Parameters
----------
iswr0 (pandas.Series): Solar irradiance data onto horizontal surface.
beta (float): Incline angle of the PV module (in degrees).
pvazimuth (float): Azimuth angle of the PV module (in degrees, 0 in the south).
elevangle (array-like): Elevation angle of the sun (in degrees).
azimuth (array-like): Azimuth angle of the sun (in degrees, 0 in the south).
datetime (pandas.Series or None, optional): Timestamps associated with the irradiance data. If None,
the function assumes regular time intervals based on the index of 'iswr0'.
efficiency (float, optional): Efficiency of the photovoltaic system (default is 0.2).
area (float, optional): Area of the PV module (default is 1).
Returns
-------
float: Total energy produced by the photovoltaic system (in Wh).
If 'datetime' is not provided, the function assumes regular time intervals based on the index of 'iswr0'.
The function raises a ValueError if the time intervals are irregular.
"""
if datetime is None:
= iswr0.index.to_series()
datetime
= 1 # hard coded time sampling of 1 hour
dt
# Replace the hard coded time sampling dt:
# Retrieve unique time sampling dt of `datetime` in (hours) and
# raise an error if datetime is irregularly sampled
#
# < your code goes here >
# Calculate iswr onto inclined PV module
= solar.comp_irradiance_incline(iswr0,
iswr_beta
solar.comp_cos_incidenceangle(elevangle, azimuth, beta, pvazimuth),
elevangle)# Calculate generated power and energy
= iswr_beta * area * efficiency
power = power.sum() * dt
energy
return energy
Finally, you can perform the grid search. Use the code block below to get you started and read my instructions and comments carefully:
## Perform the grid search
= np.arange(-180, 180, 5) # azimuth angle of PV module (0 in the south, -90 West, 90 East)
alpha_pv = np.arange(0, 95, 5) # incline of PV module
beta_pv
## Create a grid Z based on the previous PV parameters
## and iterate through each element of Z
# Each element of Z can be computed by `comp_energy_produced()`
# The data frame `sdo` holds the elevangle (h), solar azimuth (alpha) and iswr0 (iswr_clearsky)
# The PV parameters are defined above.
# Tip: If you don't know how to setup the loop, read the Notes section of the documentation of np.meshgrid().
# < your code goes here >
## Normalize Z with the maximum value of Z that is not NaN
# < your code goes here >
## Plot the contour map
# < your code goes here >