#Upgrading the library to v2.3
! pip install --upgrade networkx
import networkx as nx #https://networkx.github.io/
import matplotlib.pyplot as plt #https://matplotlib.org/
import scipy as sp
import numpy as np
G = nx.DiGraph()
#Graph with 4 ring nodes and one hub node
G.add_node("A")
G.add_node("B")
G.add_node("C")
G.add_node("D")
G.add_node("E")
#Add directional edges to create a hub structure
G.add_edges_from([("B", "A"),("C", "A"),("D", "A"),("E", "A")])
nx.draw_networkx(G, node_color='black', font_color='white', edge_color='black', font_weight='bold', node_size=700)
plt.axis('off')
plt.show()
#Import libraries
import pandas as pd #https://pandas.pydata.org/
import matplotlib.pyplot as plt #https://matplotlib.org/
import matplotlib.dates as mdates #https://matplotlib.org/
import numpy as np #http://www.numpy.org/
#from datetime import date #https://docs.python.org/3/library/datetime.html
#Read csv file using pandas
#Node B - Temperature
NodeB = pd.read_csv("NodeB_LPRAirport_temperature_072018.csv",dayfirst=True,sep=",",
header=0,decimal=b".",index_col=0,
parse_dates=[[0,1,2,3]], usecols=[0,1,2,3,5])
#Node D - Temperature
NodeD = pd.read_csv("NodeD_LPRLepola_temperature_072018.csv",dayfirst=True,sep=",",
header=0,decimal=b".",index_col=0,
parse_dates=[[0,1,2,3]], usecols=[0,1,2,3,5])
#Node C - Wind
NodeC = pd.read_csv("NodeC_LPRAirport_wind_072018.csv",dayfirst=True,sep=",",
header=0,decimal=b".",index_col=0,
parse_dates=[[0,1,2,3]], usecols=[0,1,2,3,5])
#Node E - Wind
NodeE = pd.read_csv("NodeE_LPRLepola_wind_072018.csv",dayfirst=True,sep=",",
header=0,decimal=b".",index_col=0,
parse_dates=[[0,1,2,3]], usecols=[0,1,2,3,5])
#NodeB.head()
#Original values can also be presented if needed
#plt.figure(figsize=(20,9))
#plt.plot(NodeB,color='blue', marker='.', linestyle = 'none')
#plt.title("Air Temperature 07/2018 NodeB")
#plt.ylabel("Celsius")
#plt.grid(True)
#plt.show()
#Update values for Node B
for row in NodeB.itertuples():
if NodeB.at[row.Index, "Air temperature (degC)"] > 25:
NodeB.at[row.Index, "Air temperature (degC)"] = 1
else:
NodeB.at[row.Index, "Air temperature (degC)"] = 0
plt.figure(figsize=(20,9))
plt.plot(NodeB,color='blue', marker='.', linestyle = 'none')
plt.title("Air Temperature 07/2018 NodeB")
plt.ylabel("Celsius")
plt.grid(True)
plt.show()
#Update values for Node D
for row in NodeD.itertuples():
if NodeD.at[row.Index, "Air temperature (degC)"] > 25:
NodeD.at[row.Index, "Air temperature (degC)"] = 1
else:
NodeD.at[row.Index, "Air temperature (degC)"] = 0
plt.figure(figsize=(20,9))
plt.plot(NodeD,color='red', marker='.', linestyle = 'none')
plt.title("Air Temperature 07/2018 NodeD")
plt.ylabel("Celsius")
plt.grid(True)
plt.show()
#Update values for Node C
for row in NodeC.itertuples():
if NodeC.at[row.Index, "Wind speed (m/s)"] > 5:
NodeC.at[row.Index, "Wind speed (m/s)"] = 1
else:
NodeC.at[row.Index, "Wind speed (m/s)"] = 0
plt.figure(figsize=(20,9))
plt.plot(NodeD,color='green', marker='.', linestyle = 'none')
plt.title("Wind Speed 07/2018 NodeC")
plt.ylabel("Celsius")
plt.grid(True)
plt.show()
#Update values for Node E
for row in NodeC.itertuples():
if NodeE.at[row.Index, "Wind speed (m/s)"] > 5:
NodeE.at[row.Index, "Wind speed (m/s)"] = 1
else:
NodeE.at[row.Index, "Wind speed (m/s)"] = 0
plt.figure(figsize=(20,9))
plt.plot(NodeD,color='brown', marker='.', linestyle = 'none')
plt.title("Wind Speed 07/2018 NodeE")
plt.ylabel("Celsius")
plt.grid(True)
plt.show()
#plotting
#if temperature in airport of Lepola is above 25 AND wind in airport or Lepola is above 5 send binary 1. Otherwise send 0. Input values are ready as binary
#summary=((NodeB['2018-07'].values > 25) | (NodeD['2018-07'].values > 25)) & ((NodeC['2018-07'].values > 5) | (NodeE['2018-07'].values > 5))
summary=((NodeB['2018-07'].values == 1) | (NodeD['2018-07'].values ==1)) & ((NodeC['2018-07'].values ==1) | (NodeE['2018-07'].values ==1))
plt.figure(figsize=(16,6))
plt.plot(NodeB['2018-07'].index, summary,color='black', marker='.',linestyle='')
plt.title("Output for Node A 07/2018")
plt.grid(True)
plt.show()