Commit 3756f002 authored by sp2668's avatar sp2668
Browse files

minor renaming

parent 21058521
......@@ -4,5 +4,6 @@
*.synctex.gz
**/dconf/
**/.ipynb_checkpoints/
**/__pycache__/
*.lp
*.slides.html
......@@ -9,5 +9,6 @@ dependencies:
- numpy
- pandas
- python
- scikit-learn
- pip:
- pypsa
%% Cell type:markdown id: tags:
 
# Energy System Modelling - Tutorial 06
 
Clustering the European Grid
 
 
 
%% Cell type:markdown id: tags:
 
**Tasks:**
>-Load a European Power Grid <br>
>-Calculate order and size <br>
>-Use clustering algorithm <br>
>-Study the impact of the number of clusters on minimum installed capacities <br>
 
%% Cell type:code id: tags:
 
``` python
import yaml
import pypsa
import numpy as np
import xarray as xr
import pandas as pd
#
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.lines as mlines
from sklearn.cluster import KMeans
#
%matplotlib inline
import time
 
import tutorial
import tutorial6utilities
```
 
%% Cell type:markdown id: tags:
 
## Introduction – the European grid
 
%% Cell type:markdown id: tags:
 
**Import base.nc, <br>
plot it with library.plot_network(network_base,option="kV",basemap="no") <br>
and calculate its order and size **
 
%% Cell type:code id: tags:
 
``` python
network_base = pypsa.Network("./networks/base.nc")
```
 
%% Output
 
INFO:pypsa.io:Imported network base.nc has buses, lines, links, transformers
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-3-0a9bcb0e3368> in <module>()
----> 1 network_base = pypsa.Network("./networks/base.nc")
~/software/anaconda3/lib/python3.6/site-packages/pypsa/components.py in __init__(self, import_name, name, ignore_standard_types, override_components, override_component_attrs, **kwargs)
295 self.import_from_hdf5(import_name)
296 elif import_name[-3:] == ".nc":
--> 297 self.import_from_netcdf(import_name)
298 else:
299 self.import_from_csv_folder(import_name)
~/software/anaconda3/lib/python3.6/site-packages/pypsa/io.py in import_from_netcdf(network, path, skip_time)
487
488 basename = os.path.basename(path) if isinstance(path, string_types) else None
--> 489 with ImporterNetCDF(path=path) as importer:
490 _import_from_importer(network, importer, basename=basename,
491 skip_time=skip_time)
~/software/anaconda3/lib/python3.6/site-packages/pypsa/io.py in __init__(self, path)
200 self.path = path
201 if isinstance(path, string_types):
--> 202 self.ds = xr.open_dataset(path)
203 else:
204 self.ds = path
~/software/anaconda3/lib/python3.6/site-packages/xarray/backends/api.py in open_dataset(filename_or_obj, group, decode_cf, mask_and_scale, decode_times, autoclose, concat_characters, decode_coords, engine, chunks, lock, cache, drop_variables, backend_kwargs)
322 store = backends.ScipyDataStore(filename_or_obj,
323 autoclose=autoclose,
--> 324 **backend_kwargs)
325 elif engine == 'pydap':
326 store = backends.PydapDataStore.open(filename_or_obj,
~/software/anaconda3/lib/python3.6/site-packages/xarray/backends/scipy_.py in __init__(self, filename_or_obj, mode, format, group, writer, mmap, autoclose, lock)
144 filename=filename_or_obj,
145 mode=mode, mmap=mmap, version=version)
--> 146 self._ds = opener()
147 self._autoclose = autoclose
148 self._isopen = True
~/software/anaconda3/lib/python3.6/site-packages/xarray/backends/scipy_.py in _open_scipy_netcdf(filename, mode, mmap, version)
91 try:
92 return scipy.io.netcdf_file(filename, mode=mode, mmap=mmap,
---> 93 version=version)
94 except TypeError as e: # netcdf3 message is obscure in this case
95 errmsg = e.args[0]
~/software/anaconda3/lib/python3.6/site-packages/scipy/io/netcdf.py in __init__(self, filename, mode, mmap, version, maskandscale)
250 self.filename = filename
251 omode = 'r+' if mode == 'a' else mode
--> 252 self.fp = open(self.filename, '%sb' % omode)
253 if mmap is None:
254 # Mmapped files on PyPy cannot be usually closed
FileNotFoundError: [Errno 2] No such file or directory: '/home/ws/sp2668/bwSyncAndShare/lectures/esm_tutorials/tutorial-6/networks/base.nc'
 
%% Cell type:code id: tags:
 
``` python
tutorial.plot_network(network_base,option="kV",basemap="no")
```
 
%% Output
 
 
%% Cell type:code id: tags:
 
``` python
## Calculate its order and its size
 
###Order
def order(network):
return network.buses.shape[0]
 
###Size
def gsize(network):
return network.lines.shape[0]+network.links.shape[0]
 
 
print("Base Graph order:", order(network_base))
print("Base Graph size:", gsize(network_base))
```
 
%% Output
 
Base Graph order: 4977
Base Graph size: 6048
 
%% Cell type:markdown id: tags:
 
**Import elec_s.nc,<br> plot it <br>and calculate its order and size**
 
%% Cell type:code id: tags:
 
``` python
network_bef_cluster = pypsa.Network("./networks/elec_s.nc")
```
 
%% Output
 
INFO:pypsa.io:Imported network elec_s.nc has buses, carriers, generators, lines, links, loads, storage_units
 
%% Cell type:code id: tags:
 
``` python
tutorial.plot_network(network_bef_cluster)
print("Graph order:", order(network_bef_cluster))
print("Graph size:", gsize(network_bef_cluster))
```
 
%% Output
 
Graph order: 3242
Graph size: 4839