CodingMaster24/SolarPlantAnalysisApp
0
1import streamlit as st
2import pandas as pd
3import matplotlib.pyplot as plt
4from statsmodels.tsa.stattools import adfuller
5from statsmodels.tsa.arima.model import ARIMA
6from statsmodels.tsa.statespace.sarimax import SARIMAX
7from sklearn.model_selection import train_test_split
8
9# Function to load CSV files from GitHub
10def load_data(url):
11 try:
12 data = pd.read_csv(url)
13 return data
14 except Exception as e:
15 st.error(f"Error loading data from {url}: {e}")
16 return None
17
18# GitHub raw CSV links
19plant_1_generation_url = 'https://raw.githubusercontent.com/Sivatech24/DataSetsForTheModel/0deb87623911b017969be1ab482da725a0ae720c/DataSetsCsvFiles/Plant_1_Generation_Data.csv'
20plant_1_weather_url = 'https://raw.githubusercontent.com/Sivatech24/DataSetsForTheModel/0deb87623911b017969be1ab482da725a0ae720c/DataSetsCsvFiles/Plant_1_Weather_Sensor_Data.csv'
21plant_2_generation_url = 'https://raw.githubusercontent.com/Sivatech24/DataSetsForTheModel/0deb87623911b017969be1ab482da725a0ae720c/DataSetsCsvFiles/Plant_2_Generation_Data.csv'
22plant_2_weather_url = 'https://raw.githubusercontent.com/Sivatech24/DataSetsForTheModel/0deb87623911b017969be1ab482da725a0ae720c/DataSetsCsvFiles/Plant_2_Weather_Sensor_Data.csv'
23
24# Load datasets
25st.title('Solar Power Plant Data Overview')
26
27st.subheader('Plant 1 Generation Data')
28gen_data = load_data(plant_1_generation_url)
29if gen_data is not None:
30 st.write(gen_data)
31
32st.subheader('Plant 1 Weather Sensor Data')
33weather_data = load_data(plant_1_weather_url)
34if weather_data is not None:
35 st.write(weather_data)
36
37# Data Processing and Visualization
38if gen_data is not None and weather_data is not None:
39 # st.subheader('Convert DATE_TIME columns to datetime')
40 gen_data['DATE_TIME'] = pd.to_datetime(gen_data['DATE_TIME'], format='%d-%m-%Y %H:%M')
41 weather_data['DATE_TIME'] = pd.to_datetime(weather_data['DATE_TIME'], format='%Y-%m-%d %H:%M:%S')
42
43 # st.subheader('Resampling generation data daily')
44 gen_data_daily = gen_data.set_index('DATE_TIME').resample('D').sum().reset_index()
45
46 st.subheader('Plotting generation data')
47 fig, ax = plt.subplots(nrows=2, ncols=1, figsize=(15, 10))
48 gen_data.plot(x='DATE_TIME', y=['DAILY_YIELD', 'TOTAL_YIELD'], ax=ax[0], title="Daily and Total Yield (Generation Data)")
49 gen_data.plot(x='DATE_TIME', y=['AC_POWER', 'DC_POWER'], ax=ax[1], title="AC Power & DC Power (Generation Data)")
50 st.pyplot(fig)
51
52 st.subheader('Plotting weather data')
53 fig, ax = plt.subplots(nrows=2, ncols=1, figsize=(15, 10))
54 weather_data.plot(x='DATE_TIME', y='IRRADIATION', ax=ax[0], title="Irradiation (Weather Data)")
55 weather_data.plot(x='DATE_TIME', y=['AMBIENT_TEMPERATURE', 'MODULE_TEMPERATURE'], ax=ax[1], title="Ambient & Module Temperature (Weather Data)")
56 st.pyplot(fig)
57
58 st.subheader('Calculating DC Power Converted')
59 gen_data['DC_POWER_CONVERTED'] = gen_data['DC_POWER'] * 0.98 # Assume 2% loss in conversion
60 fig, ax = plt.subplots(figsize=(15, 5))
61 gen_data.plot(x='DATE_TIME', y='DC_POWER_CONVERTED', ax=ax, title="DC Power Converted")
62 st.pyplot(fig)
63
64 st.subheader('Filtering for day time hours')
65 day_data_gen = gen_data[(gen_data['DATE_TIME'].dt.hour >= 6) & (gen_data['DATE_TIME'].dt.hour <= 18)]
66 fig, ax = plt.subplots(figsize=(15, 5))
67 day_data_gen.plot(x='DATE_TIME', y='DC_POWER', ax=ax, title="DC Power Generated During Day Hours")
68 st.pyplot(fig)
69
70 st.subheader('Inverter performance analysis')
71 inverter_performance = gen_data.groupby('SOURCE_KEY')['DC_POWER'].mean().sort_values()
72 st.write(f"Underperforming inverter: {inverter_performance.idxmin()}")
73
74 st.subheader('Inverter specific data')
75 inverter_data = gen_data[gen_data['SOURCE_KEY'] == 'bvBOhCH3iADSZry']
76 fig, ax = plt.subplots(figsize=(15, 5))
77 inverter_data.plot(x='DATE_TIME', y=['AC_POWER', 'DC_POWER'], ax=ax, title="Inverter bvBOhCH3iADSZry")
78 st.pyplot(fig)
79
80 st.subheader('Daily yield analysis')
81 df_daily_gen = gen_data_daily[['DATE_TIME', 'DAILY_YIELD']].set_index('DATE_TIME')
82 result = adfuller(df_daily_gen['DAILY_YIELD'].dropna())
83 st.write(f'ADF Statistic: {result[0]}')
84 st.write(f'p-value: {result[1]}')
85
86 # st.subheader('Splitting the dataset for ARIMA modeling')
87 train_gen, test_gen = train_test_split(df_daily_gen, test_size=0.2, shuffle=False)
88
89 st.subheader('ARIMA model')
90 arima_model_gen = ARIMA(train_gen['DAILY_YIELD'], order=(5, 1, 0))
91 arima_fit_gen = arima_model_gen.fit()
92 forecast_arima_gen = arima_fit_gen.forecast(steps=len(test_gen))
93 test_gen['Forecast_ARIMA'] = forecast_arima_gen
94
95 st.subheader('Plotting ARIMA results')
96 fig, ax = plt.subplots(figsize=(15, 5))
97 train_gen['DAILY_YIELD'].plot(ax=ax, label='Training Data')
98 test_gen['DAILY_YIELD'].plot(ax=ax, label='Test Data')
99 test_gen['Forecast_ARIMA'].plot(ax=ax, label='ARIMA Forecast')
100 plt.legend()
101 st.pyplot(fig)
102
103 st.subheader('SARIMA model')
104 sarima_model = SARIMAX(train_gen['DAILY_YIELD'], order=(1, 1, 1), seasonal_order=(1, 1, 1, 12))
105 sarima_fit = sarima_model.fit(disp=False)
106 sarima_forecast = sarima_fit.forecast(steps=len(test_gen))
107 test_gen['Forecast_SARIMA'] = sarima_forecast
108
109 st.subheader('Plotting SARIMA results')
110 fig, ax = plt.subplots(figsize=(15, 5))
111 train_gen['DAILY_YIELD'].plot(label='Train')
112 test_gen['DAILY_YIELD'].plot(label='Test')
113 test_gen['Forecast_SARIMA'].plot(label='SARIMA Forecast')
114 plt.legend()
115 st.pyplot(fig)
116
117 st.subheader('Comparing ARIMA and SARIMA forecasts')
118 plt.figure(figsize=(15, 5))
119 plt.plot(test_gen.index, test_gen['DAILY_YIELD'], label='Actual Test Data')
120 plt.plot(test_gen.index, test_gen['Forecast_ARIMA'], label='ARIMA Forecast')
121 plt.plot(test_gen.index, test_gen['Forecast_SARIMA'], label='SARIMA Forecast')
122 plt.legend()
123 plt.title("ARIMA vs SARIMA Forecast Comparison (Generation Data)")
124 st.pyplot(plt)