license:mit climate region:us
Images taken from the Sage Waggle Node's top camera and the solar irradiance values were taken from the Argonne National Laboratory 
tower readings. We made sure to exclude night time photos since there is no sun and we exclusively used summer-time photos as we wanted 
to stick to a seasonal model that would be able to make estimates more consistently. Furthermore we also eventually downsized the images 
original 2000x2000 images to 500x500 images since the training was taking a bit too long when the images were larger.
# @InProceedings{huggingface:dataset,
# title = {A great new dataset},
# author={huggingface, Inc.
# },
# year={2020}
# }
#
---
dataset_info:
  features:
  - name: image
    dtype: image
  - name: irradiance
    dtype: float32
  splits:
  - name: full
    num_bytes: 13466250
    num_examples: 1000
  download_size: 14234112
  dataset_size: 13466250
tags:
- climate
license: mit
---
# Estimating Solar Irradiance with Image Regression
- **Homepage:** [Sage Continuum](https://sagecontinuum.org/)
- **Author:** Alex Shen, Northwestern University
- **Mentors:** Bhupendra Raut, Seongha Park
- **Repository:** [GitHub Repository](https://github.com/waggle-sensor/summer2023/tree/main/Shen)

# Goal and Importance
Our goal was to create a model to estimate solar irradiance in the sky based on ground images taken from waggle nodes. This could help in the following ways:
- Solar energy generation: It could help in predicting energy generation more accurately resulting in improved efficiency and grid management
- Weather forecasting- Could assist meteorologists in predicting weather patterns using solar irradiance levels, and in analyzing current weather conditions
- Climate change: Would help with modeling climate change, could contribute to understanding and assist in mitigating global warming
- Smart Homes: Would be able to help smart homes manage energy more efficiently (control certain devices based on irradiance levels) 

# Data Preprocessing
In the data preprocessing stage we created a csv file that stored all the images to their matching solar irradiance values. The images were taken from the Sage Waggle Node's top camera and the solar irradiance values were taken from the Argonne National Laboratory tower readings. We made sure to exclude night time photos since there is no sun and we exclusively used summer-time photos as we wanted to stick to a seasonal model that would be able to make estimates more consistently. Furthermore we also eventually downsized the images original 2000x2000 images to 500x500 images since the training was taking a bit too long when the images were larger.

![alt text](md_images/top_camera.jpg)
*Example training image taken from waggle node W039*, 2000x2000 pixels

# Training and Model
In our training, before the image was transformed to a tensor, the image was resized down to 224x224 to stay consistent with the pre-trained models. The image was also randomly flipped with a 50% chance and rotated randomly between 0-359 degrees so the model would be able to generalize better. For our model we compared all of the  pretrained ResNet models and the VGG-16 model. However we replaced the last fc layer so that the model would give us a continuous value as an estimate instead of a range. We found that the ResNet 50 model performed the best with the lowest mean absolute error of 82. All in all, I think that the error was small enough to justify creating the plugin. In the plugin the waggle node simply snaps an image of the sky using its top camera, and notes the solar irradiance that the model predicts and publishes it to the Beehive Repository.

# Graphs
![alt text](md_images/Occurance_graph.png)

<br>

_Graph showing the # of times that each margin of error appeared in our tesing images. For example, the model predicting 10 when the irradiance is 20 would result in an error of 10, raising the first bar of the bar graph 1 occurence higher_

<br>

![alt text](md_images/predvsactual.png)

_This graph plots the predicted irradiance of a test image against its actual irradiance value. The dots are centering mostly around the y=x line meaning the model is predicting accurately on average. Also since there are points both above and below the line the model is not biased towards either overestimating or underestimating also causing it to predict well on average_

# Future Directions
- Increase training data to decrease MAE
- Work around identifying through the thin cloud layers since it causes mistakes in the model by severely underestimating the irradiance value due to thin clouds covering the image
- Work on identifying correct irradiance values during sunsets and sunrises. The model occasionally overestimates irradiance when the sun is at its perimeter due to greater light exposure in the image
- Implement a feature to forecast solar irradiance levels based on the patterns of data gathered 
