*3.4. Detection Accuracy*

In order to test how accurate the system is, a day in which the system can always detect the Sun has been chosen, then, as reference the position given by the segmentation process, the positions generated by both the particle filter and the Pysolar model position have been compared. In Figure 22, the trajectories of the Sun given by the three proposed strategies are shown.

**Figure 22.** Trajectory of the Sun given by the segmentation process (red dots), the particle filter (green dots), and the estimated position (blue dots), during the day.

In Figure 23, each of the three trajectories have been plotted to clearly show their behavior. It can be observed that the estimated position (position given by the Pysolar model) diverges considerably from the trajectory of the Sun in the image, while the position given by the particle filter remains close. Nevertheless, as was mentioned before, when the system cannot segment the Sun, the only information it has is the result of the position model.

**Figure 23.** Trajectory of the Sun during a day where we can always detect it.

To evaluate the system quantitatively, the solar zenith angle (SZA) has been calculated as follows. From each point (*Pdome* with coordinates (*x*, *y*)) of the positions of the Sun in the dome given by the segmentation process, particle filter and Pysolar model, the distance to the center of the dome has been calculated (this distance is denoted as *dp* in Figure 24).

**Figure 24.** Sun position in the dome.

Then, each of these distances is normalized by dividing them by the radius (defined as *rdome* in Figure 24) of the dome. Thus, it is possible to compute the solar zenith angle on a unit sphere according to the following expression,

$$SZA\_i = \arctan\left(\frac{d\_{p\_i}/r\_{\text{dome}}}{\sqrt{1 - \left( (x\_i/r\_{\text{dome}})^2 + (y\_i/r\_{\text{dome}})^2 \right)}}\right), \qquad i \in \{1, \dots, N\}$$

By doing this for the *N* Sun's positions given by the segmentation process, the particle filter and the Pysolar model, the set of plots shown in the Figure 25 results.

**Figure 25.** Solar zenith angle (SZA).

Using the SZA of the segmentation process as the reference, the error from the SZA for both the particle filter and Pysolar model have been calculated.

As can be seen in Figure 26, the SZA given by the particle filter deviated about 0.86◦ away on average from the SZA given by the segmentation process; this indicates that the position of the particle filter remained practically in the center of the circumsolar area of the Sun. On the other hand, the SZA given by the Pysolar model was around 4.51◦ away on average from the SZA given by the segmentation process; thus, using only this information can result in significant errors in later processes, for instance the irradiance estimation.

**Figure 26.** Solar zenith error.

Besides of the SZA calculation, the solar azimuth angle (SAA) has also been calculated using the following expression:

$$SAA\_i = \arctan\left(\frac{y\_i/r\_{domu}}{x\_i/r\_{domu}}\right), \qquad i \in \{1, \dots, N\}$$

Figure 27 shows the set of plots of the azimuth angles of the segmentation process, the particle filter, and the Pysolar model.

**Figure 27.** Solar azimuth angle (SAA).

Similar to the previous case, taking as a reference the SAA of the segmentation process, the error of both the SAA of the particle filter and the SAA of the Pysolar model have been computed; in Figure 28, these errors are shown.

**Figure 28.** Solar azimuth error.

The behavior of the SAA errors was similar to the behavior of the SZA errors, the SAA of the particle filter having an average error of 2.47◦ while the SAA of the Pysolar model was around of 6.88◦ on average.

From the results obtained, it can be observed that clouds occluding the Sun generated the perception of changing the size of the Sun depending on the water vapor concentration of the cloud. "Thin" clouds (low water vapor concentration) tended to generate a perception of growth in the Sun size. On the other hand, when "heavy" clouds were present (high water vapor concentration), the sunlight was obstructed completely, and the Sun position could not be determined. Nevertheless, having the position of the Sun, at any moment, was crucial, and this could only be accomplished by a combination of algorithms that was ready for all the sky scenarios. In addition, mapping sky coordinates to image coordinates allowed working in a new reference system that avoided hardware errors.

#### **4. Conclusions**

A novel methodology based on the implementation of several image processing techniques to achieve a robust and automatic detection of the position of the Sun from a set of images, acquired with a low-cost artificial vision system, was proposed. The methodology allowed not only detecting the position of the Sun in a clear-sky day, but also in a cloudy one, even if the Sun was completely occluded. The proposed methodology has been tested using a set of images of three different scenarios, clear-sky day, a partially sunny day, and a cloudy day. Experimental results demonstrated that regardless of the conditions of the day, the computed position of the Sun was within the circumsolar area. It is important to mention that knowing an accurate position of the Sun at any moment allows performing other processes, for instance knowing not only the position of a cloud with respect to the position of the Sun to identify if an occlusion will occur, but also the time it will take, which is fundamental in the implementation of better solar resource assessment systems.

**Supplementary Materials:** A supporting video is available at: https://youtu.be/HY2plwtBR-4.

**Author Contributions:** Conceptualization and methodology, L.V. and M.I.P.-C.; software, L.V. and C.M.P.-M.; formal analysis, L.V., M.I.P.-C., and Daniela Moctezuma; writing, original draft preparation, L.V., D.M., and M.I.P.-C.; writing, review and editing, C.A.P.-A. and A.D.-P.

**Funding:** This research was partially funded by project CONACyT-Problemas Nacionales, grant number 2015-01-1651.

**Acknowledgments:** The authors acknowledge CONACyT for the partial financial support to the project Problemas Nacionales 2015-01-1651.

**Conflicts of Interest:** The authors declare no conflict of interest.
