You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
289 lines
9.8 KiB
Python
289 lines
9.8 KiB
Python
import matplotlib.pyplot as plt
|
|
from matplotlib.font_manager import FontProperties
|
|
import pandas as pd
|
|
|
|
# Importing data
|
|
|
|
med = pd.read_csv('med.csv')
|
|
med_discri = pd.read_csv('med_discri.csv')
|
|
data_plot= pd.read_csv('data_plot.csv')
|
|
|
|
############## FILTERING DATA ##############
|
|
|
|
# 24 Hrs light intensity
|
|
luxes = med.iloc[0:288,0]
|
|
|
|
#Plotting Luxes data
|
|
plt.plot(luxes,'.k')
|
|
plt.xlabel('Sample Number')
|
|
plt.ylabel('[Lx]', rotation=90)
|
|
plt.show()
|
|
|
|
# The data filtering function depending on the time. B and e sets upper and lower limits.
|
|
def FilteringData(b,e):
|
|
filtered_med = med[(med['hh'] >= b ) & (med['hh'] <= e)]
|
|
#Saving luxes, temp, hum and power data
|
|
luxesf = filtered_med.iloc[:,0].tolist()
|
|
tempf = filtered_med.iloc[:,1].tolist()
|
|
humf = filtered_med.iloc[:,2].tolist()
|
|
powf = filtered_med.iloc[:,5].tolist()
|
|
|
|
return luxesf, tempf, humf, powf
|
|
|
|
# Pearson and Spearman correlation
|
|
def Correlation(l,t,h,p,c):
|
|
# Empty 4x4 array
|
|
arr = np.empty((4,4))
|
|
# Joints luxesf, tempf, humf, powf in one array
|
|
l=np.array(l).reshape(-1,1)
|
|
t=np.array(t).reshape(-1,1)
|
|
h=np.array(h).reshape(-1,1)
|
|
p=np.array(p).reshape(-1,1)
|
|
aa=np.hstack((l,t,h,p))
|
|
|
|
for a in range(0,4):
|
|
for t in range (0,4):
|
|
if c=='p':corr, j = pearsonr(aa[:,a],aa[:,t]) # If c iquals s, pearson correlation is calculated
|
|
elif c=='s': corr, j = spearmanr(aa[:,a],aa[:,t]) # If c iquals s, pearson correlation is calculated
|
|
else: print("Elija un tipo de correlacion valida: pearson(p) o spearman(s)")
|
|
arr[a][t]=corr
|
|
return arr
|
|
# Table of correlation Function
|
|
def Tablecorrelation(data,title):
|
|
fig, ax = plt.subplots()
|
|
table = ax.table(cellText=np.around(data, decimals=4),
|
|
rowLabels=['Lux','Temp','Hum','Pow'],
|
|
colLabels=['Lux','Temp','Hum','Pow'],
|
|
loc='center')
|
|
table.set_fontsize(10)
|
|
table.scale(1.2,1.2)
|
|
ax.axis('off')
|
|
plt.title(title)
|
|
plt.savefig(f'{title}.png')
|
|
plt.show()
|
|
#Filtered data from 9Hrs to 16Hrs
|
|
l, t, h, p = FilteringData(9,16)
|
|
#Importing scipy library
|
|
from scipy.stats import pearsonr
|
|
from scipy.stats import spearmanr
|
|
#Correlation calculation
|
|
#SPEARMAN
|
|
Spearmancorrelation = Correlation(l, t, h, p,'s')
|
|
print('Spearman correlation')
|
|
print(Spearmancorrelation)
|
|
Tablecorrelation(Spearmancorrelation,'Spearman correlation')
|
|
#PEARSON
|
|
pearsoncorreltaion = Correlation(l, t, h, p,'p')
|
|
print('Pearson correlation')
|
|
print(pearsoncorreltaion)
|
|
Tablecorrelation(pearsoncorreltaion,'Pearson correltaion')
|
|
############## PLOTTING DATA FUNCTION ##############
|
|
#Inputs: Luxes, Temperature, Humidity and Power
|
|
#Output: Vs graph 4x4
|
|
|
|
def GenGraph(luxesf, tempf, humf, powf):
|
|
# Generates a figure of size 4x4
|
|
figure, axis = plt.subplots(4,4, figsize=(8,6))
|
|
# Defines limits for plotting luxes, temperature, humidity and power
|
|
luxlim=(2055,48000)
|
|
templim=(13,50)
|
|
humlim=(12,88)
|
|
powlim=(0.68,11.61)
|
|
#Text fontsize
|
|
fontsize=16
|
|
Tfont = FontProperties(family='serif', style='normal',size=fontsize)
|
|
#Tiles fontsize, family font
|
|
font = FontProperties(family='serif',style='italic',size=fontsize)
|
|
#Positon for subplots titles
|
|
Tx=1.15
|
|
Ty=0.36
|
|
|
|
#Plotting luxes vs temp, hum, pow: (0,0)-(0,3)
|
|
#Positions the Lux title at thge coordinates (0,0)
|
|
axis[0,0].text(0.5,0.5,'Lux', verticalalignment='center', horizontalalignment='center',font = Tfont)
|
|
# Clears the frame and spines
|
|
for spine in axis[0,0].spines.values():
|
|
spine.set_visible(False)
|
|
|
|
axis[0,1].scatter(luxesf,tempf, s=5, c='none', marker='.', facecolors='none', edgecolors='black', alpha=1)
|
|
axis[0,1].set(xlim=luxlim,ylim=templim)
|
|
axis[0,1].set_title('a)',y=Ty, x=Tx)
|
|
|
|
axis[0,2].scatter(luxesf,humf, s=5, c='none', marker='.', facecolors='none', edgecolors='black', alpha=1)
|
|
axis[0,2].set(xlim=luxlim,ylim=humlim)
|
|
axis[0,2].set_title('b)',y=Ty, x=Tx)
|
|
|
|
axis[0,3].scatter(luxesf,powf, s=5, c='none', marker='.', facecolors='none', edgecolors='black', alpha=1)
|
|
axis[0,3].set(xlim=luxlim,ylim=powlim)
|
|
axis[0,3].set_title('c)',y=Ty, x=Tx)
|
|
|
|
#Plotting temp vs luxes, hum and pow: (1,0)-(1,3)
|
|
axis[1,0].scatter(tempf,luxesf, s=5, c='none', marker='o', facecolors='none', edgecolors='black', alpha=0.3)
|
|
axis[1,0].set_title('d)',y=Ty, x=Tx)
|
|
axis[1,0].set(xlim=templim,ylim=luxlim)
|
|
axis[1,0].set_ylim(luxlim)
|
|
|
|
#Positions the Temp title at thge coordinates (1,1)
|
|
axis[1,1].text(0.5,0.5,'Temp', fontsize=fontsize, verticalalignment='center', horizontalalignment='center', font = Tfont)
|
|
#Clears the frame and spines
|
|
for spine in axis[1,1].spines.values():
|
|
spine.set_visible(False)
|
|
|
|
axis[1,2].scatter(tempf,humf, s=5, c='none', marker='.', facecolors='none', edgecolors='black', alpha=1)
|
|
axis[1,2].set_title('e)',y=Ty, x=Tx)
|
|
axis[1,2].set(xlim=templim,ylim=humlim)
|
|
|
|
axis[1,3].scatter(tempf,powf, s=5, c='none', marker='.', facecolors='none', edgecolors='black', alpha=1)
|
|
axis[1,3].set_title('f)',y=Ty, x=Tx)
|
|
axis[1,3].set(xlim=templim,ylim=powlim)
|
|
|
|
#Plotting hum vs luxes, temp and pow: (2,0)-(2,3)
|
|
axis[2,0].scatter(humf,luxesf, s=5, c='none', marker='o', facecolors='none', edgecolors='black', alpha=0.3)
|
|
axis[2,0].set_title('g)',y=Ty, x=Tx)
|
|
axis[2,0].set(xlim=humlim,ylim=luxlim)
|
|
|
|
axis[2,1].scatter(humf,tempf, s=5, c='none', marker='o', facecolors='none', edgecolors='black', alpha=0.3)
|
|
axis[2,1].set_title('h)',y=Ty, x=Tx)
|
|
axis[2,1].set(xlim=humlim,ylim=templim)
|
|
|
|
#Positions the Hum title at thge coordinates (2,2)
|
|
axis[2,2].text(0.5,0.5,'Hum', fontsize=fontsize, verticalalignment='center', horizontalalignment='center', font = Tfont)
|
|
#Clears the frame and spines
|
|
for spine in axis[2,2].spines.values():
|
|
spine.set_visible(False)
|
|
|
|
axis[2,3].scatter(humf,powf, s=5, c='none', marker='.', facecolors='none', edgecolors='black', alpha=1)
|
|
axis[2,3].set_title('i)',y=Ty, x=Tx)
|
|
axis[2,3].set(xlim=humlim,ylim=powlim)
|
|
|
|
#Plottign power vs luxes, temp and hum: (3,0)-(3,3)
|
|
axis[3,0].scatter(powf,luxesf, s=5, c='none', marker='o', facecolors='none', edgecolors='black', alpha=0.3)
|
|
axis[3,0].set_title('j)',y=Ty, x=Tx)
|
|
axis[3,0].set(xlim=powlim,ylim=luxlim)
|
|
|
|
axis[3,1].scatter(powf,tempf, s=5, c='none', marker='o', facecolors='none', edgecolors='black', alpha=0.3)
|
|
axis[3,1].set_title('k)',y=Ty, x=Tx)
|
|
axis[3,1].set(xlim=powlim,ylim=templim)
|
|
|
|
axis[3,2].scatter(powf,humf, s=5, c='none', marker='o', facecolors='none', edgecolors='black', alpha=0.3)
|
|
axis[3,2].set_title('l)',y=Ty, x=Tx)
|
|
axis[3,2].set(xlim=powlim,ylim=humlim)
|
|
|
|
#Positions the Hum title at thge coordinates (2,2)
|
|
axis[3,3].text(0.5,0.5,'Pow', fontsize=fontsize, verticalalignment='center', horizontalalignment='center', font = Tfont)
|
|
#Clears the frame and spines
|
|
for spine in axis[3,3].spines.values():
|
|
spine.set_visible(False)
|
|
|
|
#Clears all graphic's spines and ticks label
|
|
for ax in axis.flat:
|
|
ax.set_xticklabels([])
|
|
ax.set_xticks([])
|
|
ax.set_yticklabels([])
|
|
ax.set_yticks([])
|
|
for text in [ax.title]:
|
|
text.set_font_properties(font)
|
|
|
|
#Defines width space and height space
|
|
plt.subplots_adjust(wspace=0.4,hspace=0.06)
|
|
plt.savefig("Graph.png")
|
|
plt.show()
|
|
|
|
############## PLOTTING TEMPERATUR BAR FUNCTION ##############
|
|
# Inputs: x data, y data, x limits (xmin,xmax), y limits (ymin,ymax), x title, y title, temperature
|
|
# Output: Vs Graph with Temperature bar
|
|
|
|
import numpy as np
|
|
def GenGraphTemp(x,y,xlim,ylim,xtitle,ytitle,temp):
|
|
|
|
fig, ax = plt.subplots(figsize=(7,6))
|
|
scatter = ax.scatter(x,y, c=temp, cmap='gray', s=50, edgecolors='none', linewidths=1.5, vmin=0, vmax=70)
|
|
ax.set(xlim=xlim,ylim=ylim, xlabel=xtitle, ylabel=ytitle)
|
|
ax.grid(True, linestyle='--', linewidth=0.5,alpha=0.7)
|
|
ax.tick_params(axis='both', direction='in',length=5,width=1, top=True, right=True)
|
|
ColorBar = fig.colorbar(scatter,ax=ax,label='Temp[°C]')
|
|
plt.savefig(f"{xtitle} vs {ytitle}",".png")
|
|
plt.show()
|
|
|
|
############## PLOTTING DATA IN 4X4 ##############
|
|
|
|
# Own filtered data
|
|
luxesf, tempf, humf, powf = FilteringData(9,19)
|
|
GenGraph(luxesf,tempf,humf,powf)
|
|
|
|
# Data_plot data base
|
|
|
|
luxesplt = data_plot.iloc[:,0].tolist()
|
|
tempplt = data_plot.iloc[:,1].tolist()
|
|
humplt = data_plot.iloc[:,2].tolist()
|
|
powplt = data_plot.iloc[:,3].tolist()
|
|
GenGraph(luxesplt,tempplt,humplt,powplt)
|
|
|
|
# med data base
|
|
|
|
luxesm = med.iloc[:,0].tolist()
|
|
tempm = med.iloc[:,1].tolist()
|
|
humm = med.iloc[:,2].tolist()
|
|
powm = med.iloc[:,5].tolist()
|
|
GenGraph(luxesm,tempm,humm,powm)
|
|
|
|
# med_discri data base
|
|
|
|
luxesdi = med_discri.iloc[:,0].tolist()
|
|
tempdi = med_discri.iloc[:,1].tolist()
|
|
humdi = med_discri.iloc[:,2].tolist()
|
|
powdi = med_discri.iloc[:,5].tolist()
|
|
GenGraph(luxesdi,tempdi,humdi,powdi)
|
|
|
|
############## PLOTTING DATA USING TEMPERATURE BAR ##############
|
|
|
|
# Luxes vs Power
|
|
xlim=(2055,51000)
|
|
ylim=(1,12)
|
|
# Own filtered data
|
|
GenGraphTemp(luxesf,powf,xlim,ylim,'Luxes[lx]',"PV's Power[W]",tempf)
|
|
# Data_plot data base
|
|
GenGraphTemp(luxesplt,powplt,xlim,ylim,'Luxes[lx]',"PV's Power[W]",tempplt)
|
|
# med data base
|
|
GenGraphTemp(luxesm,powm,xlim,ylim,'Luxes[lx]',"PV's Power[W]",tempm)
|
|
# med_discri data base
|
|
GenGraphTemp(luxesdi,powdi,xlim,ylim,'Luxes[lx]',"PV's Power[W]",tempdi)
|
|
|
|
# Humidity vs Power
|
|
xlim2=(15,100)
|
|
# Own filtered data
|
|
GenGraphTemp(humf,powf,xlim2,ylim,'Luxes[lx]',"PV's Power[W]",tempf)
|
|
# Data_plot data base
|
|
GenGraphTemp(humplt,powplt,xlim2,ylim,'Luxes[lx]',"PV's Power[W]",tempplt)
|
|
# med data base
|
|
GenGraphTemp(humm,powm,xlim,ylim2,'Luxes[lx]',"PV's Power[W]",tempm)
|
|
# med_discri data base
|
|
GenGraphTemp(humdi,powdi,xlim2,ylim,'Luxes[lx]',"PV's Power[W]",tempdi)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|