Last active
January 17, 2018 13:31
-
-
Save gplssm/339c9136fdb216aff4f6046927378a1b to your computer and use it in GitHub Desktop.
Run ding0 across 20 representative grid districts and append version suffix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import pandas as pd | |
from egoio.tools import db | |
from ding0.core import NetworkDing0 | |
from ding0.tools.logger import setup_logger | |
from ding0.tools.results import save_nd_to_pickle | |
from sqlalchemy.orm import sessionmaker | |
# define logger | |
logger = setup_logger() | |
# define suffixes, paths, ... | |
suffix = '_v0.3.0_shapely_1.6.3' | |
data_path = 'data' | |
# database connection | |
engine = db.connection(section='oedb') | |
session = sessionmaker(bind=engine)() | |
# define MV Grid Districts that should be treated | |
# original list of 20 representative grids | |
# mv_grid_districts = [3196, 3040, 274, 1099, 1977, 2682, 2882, 1476, 1426, 3608, | |
# 294, 2490, 525, 1147, 239, 3230, 1103, 1364, 2035, 3021] | |
# list reduced by faulty one | |
mv_grid_districts = [3196, 3040, 274, 1977, 2682, 2882, 1476, 1426, | |
294, 2490, 525, 1147, 239, 3230, 1103, 1364, 2035, 3021] | |
faulty_mvgds = {} | |
for mvgd in mv_grid_districts: | |
try: | |
# instantiate new ding0 network object | |
nd = NetworkDing0(name='network') | |
# run DING0 on selected MV Grid District | |
nd.run_ding0(session=session, | |
mv_grid_districts_no=[mvgd]) | |
# export grid to file (pickle) | |
filename = os.path.join(data_path, | |
'ding0_grids_{mvgd}{suffix}.pkl'.format( | |
mvgd=mvgd, suffix=suffix)) | |
save_nd_to_pickle( | |
nd, | |
filename=filename) | |
except Exception as e: | |
faulty_mvgds.update({mvgd: e}) | |
pd.DataFrame.from_dict(faulty_mvgds, orient='index').to_csv( | |
os.path.join(data_path, 'faulty_mvgds{suffix}.csv'.format(suffix=suffix))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment