Assignment #07

Unit 07

Until next week, work through the material provided in Unit 7 and solve the following exercises.

This week, we continue working with our module solar to run some real-life calculations. By setting up a local development package that contains “all the math equations and functions” and running our computations and visualizations in a notebook, this assignment demonstrates you how a larger project could be split into packaged code and analysis code. Furthermore, this week’s exercise will allow you to work on your computational/logical thinking by writing rule-based code using if statements.

Your own development package

Exercise #07-01: mytoolbox
  1. Download mytoolbox from ILIAS and unzip it into your directory $SCIPRO. Install the local package mytoolbox into your conda environment scipro2023
  2. In your directory $SCIPRO/07_unit, start a new notebook and see whether you can import the module solar from mytoolbox by
from mytoolbox import solar
  1. If that worked and you have access to all the functionalities that come with solar, add a new variable to solar: check123 = "Successfully installed local package in dev mode!". Save the file.
  2. Go back to your notebook and reload solar like that
from importlib import reload
reload(solar)
<module 'mytoolbox.solar' from '/home/flo/documents/fhv/LV_programming_NES/WS2023_24/mytoolbox/mytoolbox/solar.py'>
  1. Run solar.check123. Do you see the string? Do you understand what that means?

Note: Don’t get hung up if you can’t get the local package installed in development mode! Try the method of modifying sys.path by adding the directory that contains the solar module to your path (should be ../06_unit/). If that doesn’t work either, just copy and paste solar.py into your current working directory.

Energy generated by a PV module

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.

Exercise #07-02: Energy trading

In this exercise you will manage the distribution of energy in a household setting: A user needs electric power that they can either get from a company, a PV module on their roof, or a battery. If they generate more power than they need, they can also sell the power back to the company.

Read 06_unit/solar_Dornbirn.csv and 07_unit/powerusage.csv.

  1. Inspect the datetime of the new spreadsheet. Concatenate the two data frames on their DatetimeIndex using pd.concat() and subset the resulting data frame to the first week of April.
  2. Compute the hourly time series of power generated by a PV module facing south at an angle of \(50^\circ\) in Dornbirn during the first week of April under idealized clear-sky conditions. Use our module solar for your calculations. The PV module has an area of 10m2. Add the time series as a new column in your data frame.
  3. Calculate and visualize the hourly (i) power bought from the electricity company, (ii) power sold to the electricity company, (iii) percentage of battery energy level (max storage capacity of 5 kWh). Also include the power generated by the PV module and the power usage into your figure. Here are more necessary decision points to run the calculations:
    • If the battery capacity is less than 20 %, send all generated power from the current hour to the battery, irrespective of the current power demand by the user
    • Using power from the PV module or battery is preferred to buying power
    • Storing power in the battery is preferred to selling power
Exercise#07-03: Violin plots

Run the same calculations as above, but change the angle of the PV module to \(30^\circ\). Create a violinplot of the percentage of battery level for the two scenarios (i.e., one violin per angle of PV module). Use the matplotlib axes method .violinplot(). The function takes an array or a sequence of vectors as input data.