Software for identifying the ideal setup of a solar panel based on surroundings

In this article I will present a program that can identify the most efficient angle of a solar panel, taking into account any objects that may cast a shadow on the panels. I will explain each step of the program.

The source code can be found at https://github.com/mnigmann/solar

Finding the sky

The program takes as an input an image of a spherical projection of the surroundings, such as the image below:
To identify the regions of sky, the program applies a Sobel filter, dilates the image, and applies a threshold. This causes regions where the color does not change much (such as the sky) to be black and regions where the color changes a lot to be white (such as trees, grass, buildings, etc.). For the above image:
The user must then click on the regions of the image containing sky. Using the cv2.floodFill function, the program identifies the rest of the sky, as seen below:

Finding the position of the sun

The program calculates the position of the sun based on some formulas from this PDF and this Wikipedia page.

First, one must calculate the equation of time. This describes the difference between the actual position of the sun and the position of an "ideal" sun that moves at a constant speed. This is done using the following four formulas $$ P = \frac{2\pi\left(N+10\right)}{365.14} $$ $$ Q = P + 0.0334\sin\left(\frac{2\pi\left(D-2\right)}{365.24}\right) $$ $$ R = \frac{P - \arctan\left(\frac{\tan\left(Q\right)}{0.91747714052}\right)}{\pi} $$ $$ E = 720\left(R - \operatorname{round}\left(R\right)\right) $$ where \(N\) is the time in days since midnight on January 1st and \(E\left(N\right)\) is the equation of time. Next, one must caculate the declination of the sun. To do this, one first calculates the fractional year \(\gamma\): $$ \gamma = \frac{2\pi}{365}\left(N + \frac{H-12}{24}\right) $$ where \(H\) is the hour. Then: $$ \delta = 0.006918 - 0.399912\cos\left(\gamma\right) + 0.070257\sin\left(\gamma\right) - 0.006758\cos\left(2\gamma\right) + 0.000907\sin\left(2\gamma\right) - 0.002697\cos\left(3\gamma\right) + 0.00148\sin\left(3\gamma\right) $$ where \(\delta\) is the declination of the sun. Then, one computes the hour angle: $$ W = \frac{\pi}{720}\left(60H + M + \frac{S}{60} + E + 4\phi - 60T\right) - \pi $$ where \(M\) and \(S\) are the minute and second, \(\phi\) is the longitude in degrees, and \(T\) is the time zone offset. If the hour angle is less than \(\pi\), one must add \(2\pi\) to it. Then, one can calculate the zenith angle of the sun: $$ Z = \arccos\left(\sin\right(\lambda\left)\sin\left(\delta\right) + \cos\left(\lambda\right)\cos\left(\delta\right)\cos\left(W\right)\right) $$ where \(\lambda\) is the latitude. Finally, one can calculate the azimuth angle (clockwise from north) $$ A = \pi - \arccos\left(\frac{\sin\left(\lambda\right)\cos\left(Z\right) - \sin\left(\delta\right)}{\cos\left(\lambda\right)\sin\left(Z\right)}\right) $$ The positions of the sun, displayed in 15 minute increments, are shown by the red dots in the image below:

Finding total solar energy

The power absorbed by a solar panel that is always aimed at the sun is called the "direct insolation". The following formula can be used to calculate this: $$ I_d = \left\{\begin{matrix} 1353\cdot\left(0.7\right)^{\left(\cos Z\right)^{-0.678}} & \text{if sun visible} \\ 0 & \text{if sun hidden} \end{matrix}\right. $$ where \(I_d\) is the direct insolation in \(Wm^{-2}\) and \(Z\) is the zenith angle of the sun. Note that if the sun is not visible, i.e. behind an obstacle, then \(I_d\) is zero. As not all panels track the sun, and even those that do may only use one axis, the panel is not necessarily pointed at the sun. Thus, the efficiency of the solar panel will vary throughout the day and year. The power \(P\) absorbed by a solar panel is \(I_d\left(\vec{V_P}\cdot \vec{V_s}\right)\), where \(I_d\) is the direct insolation, \(\vec{V_P}\) is the unit vector normal to the panel, and \(\vec{V_s}\) is the unit vector pointing at the sun. For the following calculations, assume the vector normal to the solar panel has an azimuth angle of \(P_a\) and a zenith angle of \(P_z\).
To convert the azimuth and zenith angles to Cartesian coordinates, one starts with a unit vector along the y-axis (pointing north) and rotates it twice. Thus: $$ \vec{V_P} = \langle\sin\left(P_a\right)\sin\left(P_z\right), \cos\left(P_a\right)\sin\left(P_z\right), \cos\left(P_z\right)\rangle $$ $$ \vec{V_s} = \langle\sin\left(A\right)\sin\left(Z\right), \cos\left(A\right)\sin\left(Z\right), \cos\left(Z\right)\rangle $$ The power is thus given by: $$ P = I_d\left(\sin\left(P_a\right)\sin\left(P_z\right)\sin\left(A\right)\sin\left(Z\right) + \cos\left(P_a\right)\sin\left(P_z\right)\cos\left(A\right)\sin\left(Z\right) + \cos\left(P_z\right)\cos\left(Z\right)\right) $$ To get the total energy collected throughout the entire year, one must integrate the power over the length of the year $$ E = \int_{year} I_d\left(\sin\left(P_a\right)\sin\left(P_z\right)\sin\left(A\right)\sin\left(Z\right) + \cos\left(P_a\right)\sin\left(P_z\right)\cos\left(A\right)\sin\left(Z\right) + \cos\left(P_z\right)\cos\left(Z\right)\right) dt $$ This form can then be used to derive the optimal parameters for several types of solar panel.

Fixed panel

For a fixed panel, \(P_z\) and \(P_a\) are constant and can be factored out $$ E = I_d\sin\left(P_a\right)\sin\left(P_z\right)\int_{year} \cos\left(A\right)\sin\left(Z\right)dt + I_d\cos\left(P_a\right)\sin\left(P_z\right)\int_{year} \cos\left(A\right)\sin\left(Z\right)dt + I_d\cos\left(P_z\right)\int_{year} \cos\left(Z\right)dt $$ In this form, one can see that the integrals do not change with respect to \(P_a\) and \(P_z\). These can be approximated by iterating over the entire year in fixed intervals (for example, with a 15 minute interval), and adding up all of the caluclated powers multiplied by \(15\cdot 60\) (only when the sun is actually visible) to get a value in \(Jm^{-2}\).
To find the best angle for the solar panel, maximise the above function. Extrema occur when the gradient is zero. Let the three intergals in the previous equation be \(I_{ss}\), \(I_{cs}\), and \(I_c\) respectively. The derivatives are: $$ \frac{\partial E}{\partial P_a} = \cos\left(P_a\right)\cdot I_{ss}\sin\left(P_z\right) - \sin\left(P_a\right)\cdot I_{cs}\sin\left(P_z\right) $$ $$ \frac{\partial E}{\partial P_z} = \cos\left(P_z\right)\left(I_{ss}\sin\left(P_a\right) + I_{cs}\cos\left(P_a\right)\right) - \sin(P_z)\cdot I_c $$ Setting both derivatives to zero yields the solution: $$ P_a = \arctan\left(\frac{I_{ss}}{I_{cs}}\right) $$ $$ P_z = \arctan\left(\frac{I_{ss}\sin\left(P_a\right) + I_{cs}\cos\left(P_a\right)}{I_c}\right) = \arctan\left(\frac{\sqrt{I_{ss}^2 + I_{cs}^2}}{I_c}\right)$$

Panel that can rotate horizontally to point at the sun

In this type of panel, \(P_a = A\), and \(P_z\) is constant: $$ E = \int_{year} I_d\left(\sin\left(P_a\right)\sin\left(P_z\right)\sin\left(A\right)\sin\left(Z\right) + \cos\left(P_a\right)\sin\left(P_z\right)\cos\left(A\right)\sin\left(Z\right) + \cos\left(P_z\right)\cos\left(Z\right)\right) dt $$ $$ E = \int_{year} I_d\left(\sin\left(A\right)\sin\left(P_z\right)\sin\left(A\right)\sin\left(Z\right) + \cos\left(A\right)\sin\left(P_z\right)\cos\left(A\right)\sin\left(Z\right) + \cos\left(P_z\right)\cos\left(Z\right)\right) dt $$ $$ E = \int_{year} I_d\left(\sin\left(P_z\right)\sin\left(Z\right)\left(\sin ^2\left(A\right) + \cos ^2\left(A\right)\right) + \cos\left(P_z\right)\cos\left(Z\right)\right) dt $$ $$ E = \int_{year} I_d\left(\sin\left(P_z\right)\sin\left(Z\right) + \cos\left(P_z\right)\cos\left(Z\right)\right) dt $$ $$ E = \sin\left(P_z\right)\int_{year} I_d\sin\left(Z\right) dt + \cos\left(P_z\right)\int_{year} I_d\cos\left(Z\right) dt $$ Let the three integrals in the previous equation be \(I_s\) and \(I_c\) respectively. As above, one can find the best \(P_z\) by finding the values of \(P_z\) for which \(\frac{dE}{dP_z}\) is zero. $$ \frac{dE}{dP_z} = I_s\cos\left(P_z\right) - I_c\sin\left(P_z\right) $$ Solving for \(\frac{dE}{dP_z}=0\) yields: $$ P_z = \arctan\left(\frac{I_s}{I_c}\right) $$

Panel that fully tracks the sun

By definition above, the power received by the panel when it is pointed directly at the sun is \(I_d\). Thus, \(E = \int_{year} I_d dt\), and there is nothing to maximize.

Comments

Popular posts from this blog

Improving and calibrating the capacitive water sensor

Turn a buck converter module into a buck-boost converter with only two components

Self-starting inverter