Commit 024a4e96 authored by sp2668's avatar sp2668

cleaned tutorial-6

parent 3756f002
...@@ -7,3 +7,4 @@ ...@@ -7,3 +7,4 @@
**/__pycache__/ **/__pycache__/
*.lp *.lp
*.slides.html *.slides.html
tutorial-6/network_data/
...@@ -3,9 +3,11 @@ channels: ...@@ -3,9 +3,11 @@ channels:
- conda-forge - conda-forge
- defaults - defaults
dependencies: dependencies:
- basemap # check: conda install -c anaconda basemap
- jupyter - jupyter
- matplotlib - matplotlib
- nb_conda - nb_conda
- netcdf4
- numpy - numpy
- pandas - pandas
- python - python
......
No preview for this file type
...@@ -766,9 +766,8 @@ ...@@ -766,9 +766,8 @@
} }
], ],
"metadata": { "metadata": {
"celltoolbar": "Slideshow",
"kernelspec": { "kernelspec": {
"display_name": "Python [default]", "display_name": "Python 3",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
...@@ -782,7 +781,7 @@ ...@@ -782,7 +781,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.6.5" "version": "3.6.4"
}, },
"nav_menu": {}, "nav_menu": {},
"toc": { "toc": {
......
No preview for this file type
This diff is collapsed.
This diff is collapsed.
...@@ -8,6 +8,7 @@ import matplotlib as mpl ...@@ -8,6 +8,7 @@ import matplotlib as mpl
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import matplotlib.lines as mlines import matplotlib.lines as mlines
from sklearn.cluster import KMeans, SpectralClustering from sklearn.cluster import KMeans, SpectralClustering
from mpl_toolkits.basemap import Basemap
### FUNCTIONS ### FUNCTIONS
...@@ -74,7 +75,7 @@ def plot_network(network,option="AC_DC",basemap="no"): ...@@ -74,7 +75,7 @@ def plot_network(network,option="AC_DC",basemap="no"):
violet_line=mlines.Line2D([], [], color='violet',label='DC') violet_line=mlines.Line2D([], [], color='violet',label='DC')
plt.legend(handles=[blue_line,green_line,orange_line,red_line,violet_line]) plt.legend(handles=[blue_line,green_line,orange_line,red_line,violet_line])
def find_kmeans_busmap(n_clusters, n, n_weightings, **kwargs): def find_kmeans_busmap(n_clusters, n, n_weightings, **kwargs):
kmeans = KMeans(init='k-means++', n_clusters=n_clusters, ** kwargs) kmeans = KMeans(init='k-means++', n_clusters=n_clusters, ** kwargs)
...@@ -88,7 +89,7 @@ def weighting(network): ...@@ -88,7 +89,7 @@ def weighting(network):
load = (network.loads_t.p_set.mean() load = (network.loads_t.p_set.mean()
.groupby(network.loads.bus).sum() .groupby(network.loads.bus).sum()
.reindex(network.buses.index, fill_value=0.)) .reindex(network.buses.index, fill_value=0.))
return load return load
...@@ -129,13 +130,13 @@ def plot_line_loading(network): ...@@ -129,13 +130,13 @@ def plot_line_loading(network):
Z = [[0,0],[max(abs(loading)),0]] Z = [[0,0],[max(abs(loading)),0]]
CS3 = plt.contourf(Z, cmap=plt.cm.jet) CS3 = plt.contourf(Z, cmap=plt.cm.jet)
plt.colorbar(fraction=0.01, pad=0.01) plt.colorbar(fraction=0.01, pad=0.01)
def plot_bus_status(network): def plot_bus_status(network):
fig, ax = plt.subplots() fig, ax = plt.subplots()
ax.set_ylim([35,72]) ax.set_ylim([35,72])
fig.set_size_inches(15,15) fig.set_size_inches(15,15)
bus_status= pd.DataFrame({'status': network.loads_t.p_set.values[0]*-1, bus_status= pd.DataFrame({'status': network.loads_t.p_set.values[0]*-1,
'pmax':network.loads_t.p_set.values[0]*0, 'pmax':network.loads_t.p_set.values[0]*0,
'p':network.loads_t.p_set.values[0]*0, 'p':network.loads_t.p_set.values[0]*0,
'ponpmax':network.loads_t.p_set.values[0]*0}) 'ponpmax':network.loads_t.p_set.values[0]*0})
...@@ -152,9 +153,9 @@ def plot_bus_status(network): ...@@ -152,9 +153,9 @@ def plot_bus_status(network):
bus_status.ponpmax.loc[i]=bus_status.p.loc[i]/bus_status.pmax.loc[i] bus_status.ponpmax.loc[i]=bus_status.p.loc[i]/bus_status.pmax.loc[i]
except: except:
print(i) print(i)
bus_color=(bus_status.status/p_nc_25.loads_t.p_set.values[0]).values bus_color=(bus_status.status/p_nc_25.loads_t.p_set.values[0]).values
#print(loading_dc) #print(loading_dc)
#print(pd.concat(dict(Line=abs(loading),Link=abs(loading_dc)))) #print(pd.concat(dict(Line=abs(loading),Link=abs(loading_dc))))
#network.plot(line_colors=abs(loading),line_cmap=plt.cm.jet,title="Line loading", #network.plot(line_colors=abs(loading),line_cmap=plt.cm.jet,title="Line loading",
...@@ -166,7 +167,7 @@ def plot_bus_status(network): ...@@ -166,7 +167,7 @@ def plot_bus_status(network):
Z = [[min(bus_color),0],[max(bus_color),0]] Z = [[min(bus_color),0],[max(bus_color),0]]
CS3 = plt.contourf(Z, cmap=plt.cm.jet) CS3 = plt.contourf(Z, cmap=plt.cm.jet)
plt.colorbar(fraction=0.01, pad=0.01) plt.colorbar(fraction=0.01, pad=0.01)
def plot_line_loading_bus_status(network): def plot_line_loading_bus_status(network):
fig, ax = plt.subplots() fig, ax = plt.subplots()
ax.set_ylim([35,72]) ax.set_ylim([35,72])
...@@ -177,8 +178,8 @@ def plot_line_loading_bus_status(network): ...@@ -177,8 +178,8 @@ def plot_line_loading_bus_status(network):
loading_dc = network.links_t.p0.loc[network.snapshots[0]]/network.links.p_nom/0.7 loading_dc = network.links_t.p0.loc[network.snapshots[0]]/network.links.p_nom/0.7
loading_dc=loading_dc.fillna(0) loading_dc=loading_dc.fillna(0)
loading_dc=loading_dc.append(pd.Series(1)) loading_dc=loading_dc.append(pd.Series(1))
bus_status= pd.DataFrame({'status': network.loads_t.p_set.values[0]*-1, bus_status= pd.DataFrame({'status': network.loads_t.p_set.values[0]*-1,
'pmax':network.loads_t.p_set.values[0]*0, 'pmax':network.loads_t.p_set.values[0]*0,
'p':network.loads_t.p_set.values[0]*0, 'p':network.loads_t.p_set.values[0]*0,
'ponpmax':network.loads_t.p_set.values[0]*0}) 'ponpmax':network.loads_t.p_set.values[0]*0})
...@@ -194,12 +195,12 @@ def plot_line_loading_bus_status(network): ...@@ -194,12 +195,12 @@ def plot_line_loading_bus_status(network):
bus_status.ponpmax.loc[i]=bus_status.p.loc[i]/bus_status.pmax.loc[i] bus_status.ponpmax.loc[i]=bus_status.p.loc[i]/bus_status.pmax.loc[i]
except: except:
print(i) print("Error at {}".format(i))
bus_color=(bus_status.status/network.loads_t.p_set.values[0]).values bus_color=(bus_status.status/network.loads_t.p_set.values[0]).values
bus_color[bus_color>1.5]=1.5 bus_color[bus_color>1.5]=1.5
#print(loading_dc) #print(loading_dc)
#print(pd.concat(dict(Line=abs(loading),Link=abs(loading_dc)))) #print(pd.concat(dict(Line=abs(loading),Link=abs(loading_dc))))
#network.plot(line_colors=abs(loading),line_cmap=plt.cm.jet,title="Line loading", #network.plot(line_colors=abs(loading),line_cmap=plt.cm.jet,title="Line loading",
...@@ -216,4 +217,4 @@ def plot_line_loading_bus_status(network): ...@@ -216,4 +217,4 @@ def plot_line_loading_bus_status(network):
plt.colorbar(fraction=0.01, pad=0.06) plt.colorbar(fraction=0.01, pad=0.06)
Z2 = [[min(bus_color),0],[max(bus_color),0]] Z2 = [[min(bus_color),0],[max(bus_color),0]]
CS4 = plt.contourf(Z2, cmap=plt.cm.jet) CS4 = plt.contourf(Z2, cmap=plt.cm.jet)
plt.colorbar(fraction=0.01, pad=0.01) plt.colorbar(fraction=0.01, pad=0.01)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment