**at [FMI](http://en.ilmatieteenlaitos.fi/download-observations#!/). Plot radiation **
pip install -r requirements.txt
ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt'
WARNING: You are using pip version 20.1.1; however, version 21.3.1 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
Note: you may need to restart the kernel to use updated packages.
#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
#Uploading the temperature from this day in Lappeenranta
#http://en.ilmatieteenlaitos.fi/download-observations#!/
#Note parse_dates to combine the first columns, also note that the separator from
#decimal is "." and data separator is ","
Temperature = pd.read_csv("sjk_temp.csv",dayfirst=True,sep=",",
header=0,decimal=b".",index_col=0,
parse_dates= [[0, 1, 2, 3]],usecols=[0,1,2,3,5])
Temperature.info()
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 2905 entries, 2019-11-01 00:00:00 to 2020-03-01 00:00:00
Data columns (total 1 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Air temperature (degC) 2877 non-null float64
dtypes: float64(1)
memory usage: 45.4 KB
#Uploading the temperature from this day in Lappeenranta
#http://en.ilmatieteenlaitos.fi/download-observations#!/
#Note parse_dates to combine the first columns, also note that the separator from
#decimal is "." and data separator is ","
Prec = pd.read_csv("sjk_prec.csv",dayfirst=True,sep=",",
header=0,decimal=b".",index_col=0,
parse_dates= [[0, 1, 2, 3]],usecols=[0,1,2,3,5])
Prec.info()
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 2905 entries, 2019-11-01 00:00:00 to 2020-03-01 00:00:00
Data columns (total 1 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Precipitation amount (mm) 2862 non-null float64
dtypes: float64(1)
memory usage: 45.4 KB
#plotting
plt.figure(figsize=(16,6))
plt.plot(Temperature,color='blue', marker='x',linestyle='-')
plt.title("Air temperature in 2019-2020, at Seinajoki")
plt.ylabel("Temperature in [°C]")
plt.grid(True)
plt.show()
#plotting
plt.figure(figsize=(16,6))
plt.plot(Prec,color='black', marker='x',linestyle='-')
plt.title("Precipitation amount in 2019-2020, at Seinajoki")
plt.ylabel("Precipitation amount in [mm/h]")
plt.grid(True)
plt.show()
3#plotting
aux=(Temperature['2019-11'].values<5) | (Prec['2019-11'].values>1)
#aux2=(Temperature['2019-11'].values>5) | (Prec['2019-11'].values>0.5)
plt.figure(figsize=(16,6))
plt.title("11-2019 / the need for heating ")
plt.plot(Temperature['2019-11'].index, aux,color='black', marker='*',linestyle='')
#plt.plot(Prec['2019-11'].index, aux2, color='green', marker='*',linestyle='')
plt.grid(True)
plt.show()
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:2: FutureWarning: Indexing a DataFrame with a datetimelike index using a single string to slice the rows, like `frame[string]`, is deprecated and will be removed in a future version. Use `frame.loc[string]` instead.
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:6: FutureWarning: Indexing a DataFrame with a datetimelike index using a single string to slice the rows, like `frame[string]`, is deprecated and will be removed in a future version. Use `frame.loc[string]` instead.
3#plotting
aux=(Temperature['2019-12'].values<5) | (Prec['2019-12'].values>1)
#aux2=(Temperature['2019-11'].values>5) | (Prec['2019-11'].values>0.5)
plt.figure(figsize=(16,6))
plt.title("12-2019 / the need for heating ")
plt.plot(Temperature['2019-12'].index, aux,color='black', marker='*',linestyle='')
#plt.plot(Prec['2019-11'].index, aux2, color='green', marker='*',linestyle='')
plt.grid(True)
plt.show()
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:2: FutureWarning: Indexing a DataFrame with a datetimelike index using a single string to slice the rows, like `frame[string]`, is deprecated and will be removed in a future version. Use `frame.loc[string]` instead.
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:6: FutureWarning: Indexing a DataFrame with a datetimelike index using a single string to slice the rows, like `frame[string]`, is deprecated and will be removed in a future version. Use `frame.loc[string]` instead.
3#plotting
aux=(Temperature['2020-1'].values<5) | (Prec['2020-1'].values>1)
#aux2=(Temperature['2019-11'].values>5) | (Prec['2019-11'].values>0.5)
plt.figure(figsize=(16,6))
plt.title("1-2020 / the need for heating ")
plt.plot(Temperature['2020-1'].index, aux,color='red', marker='*',linestyle='')
#plt.plot(Prec['2019-11'].index, aux2, color='green', marker='*',linestyle='')
plt.grid(True)
plt.show()
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:2: FutureWarning: Indexing a DataFrame with a datetimelike index using a single string to slice the rows, like `frame[string]`, is deprecated and will be removed in a future version. Use `frame.loc[string]` instead.
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:6: FutureWarning: Indexing a DataFrame with a datetimelike index using a single string to slice the rows, like `frame[string]`, is deprecated and will be removed in a future version. Use `frame.loc[string]` instead.
3#plotting
aux=(Temperature['2020-2'].values<5) | (Prec['2020-2'].values>1)
#aux2=(Temperature['2019-11'].values>5) | (Prec['2019-11'].values>0.5)
plt.figure(figsize=(16,6))
plt.title("2-2020 / the need for heating ")
plt.plot(Temperature['2020-2'].index, aux,color='red', marker='*',linestyle='')
#plt.plot(Prec['2019-11'].index, aux2, color='green', marker='*',linestyle='')
plt.grid(True)
plt.show()
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:2: FutureWarning: Indexing a DataFrame with a datetimelike index using a single string to slice the rows, like `frame[string]`, is deprecated and will be removed in a future version. Use `frame.loc[string]` instead.
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:6: FutureWarning: Indexing a DataFrame with a datetimelike index using a single string to slice the rows, like `frame[string]`, is deprecated and will be removed in a future version. Use `frame.loc[string]` instead.
#install missing libraries
! pip install --upgrade networkx
! pip install --upgrade scipy
Collecting networkx
Downloading networkx-2.6.3-py3-none-any.whl (1.9 MB)
|████████████████████████████████| 1.9 MB 20.9 MB/s
Installing collected packages: networkx
Successfully installed networkx-2.6.3
WARNING: You are using pip version 20.1.1; however, version 21.3.1 is available.
You should consider upgrading via the '/root/venv/bin/python -m pip install --upgrade pip' command.
Requirement already up-to-date: scipy in /shared-libs/python3.7/py/lib/python3.7/site-packages (1.7.2)
Requirement already satisfied, skipping upgrade: numpy<1.23.0,>=1.16.5 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from scipy) (1.19.5)
WARNING: You are using pip version 20.1.1; however, version 21.3.1 is available.
You should consider upgrading via the '/root/venv/bin/python -m pip install --upgrade pip' command.
#Import libraries -->> If an error happens (no library), you need to install the missing libraries (see above)
import networkx as nx #https://networkx.github.io/
import matplotlib.pyplot as plt #https://matplotlib.org/
import scipy as sp
import numpy as np
#checking versions
print(nx.__version__)
2.6.3
#Adding nodes in different ways
#Creating a graph
G = nx.Graph()
#Adding nodes in different ways
#One node
G.add_node(1)
#Two or more nodes
G.add_nodes_from([2, 3, 4, 5, 6, 7])
G.add_edge(1, 7)
G.add_edge(1, 6)
G.add_edge(1, 5)
G.add_edge(1, 4)
G.add_edge(1, 3)
G.add_edge(1, 2)
#Plot the graph
nx.draw_networkx(G, node_color='black', font_color='white', edge_color='black', font_weight='bold', node_size=700)
plt.axis('off')
plt.show()
#Adding a new node number 0 to node 1
G.add_node(0)
G.add_edge(0, 1)
#
nx.draw_networkx(G, node_color='black', font_color='white', edge_color='black', font_weight='bold', node_size=700)
plt.axis('off')
plt.show()
A=nx.adjacency_matrix(G)
print(A.todense())
[[0 1 1 1 1 1 1 1]
[1 0 0 0 0 0 0 0]
[1 0 0 0 0 0 0 0]
[1 0 0 0 0 0 0 0]
[1 0 0 0 0 0 0 0]
[1 0 0 0 0 0 0 0]
[1 0 0 0 0 0 0 0]
[1 0 0 0 0 0 0 0]]
G.degree()
nx.clustering(G)
nx.diameter(G)