diff --git a/README.rst b/README.rst index a04a82b2..3e2d816d 100644 --- a/README.rst +++ b/README.rst @@ -16,14 +16,14 @@ A speciality in this context is that transmission grids are described by the 380 Installing Developer Version ============================ -Create a virtualenvironment (where you like it) and activate it: +Create a virtualenvironment (where you like it) and activate it: .. code-block:: $ virtualenv eGo --clear -p python3.5 $ source venv/bin/activate - $ pip install -e git+https://github.com/openego/eGo@dev#egg=eGo + $ pip3 install -e git+https://github.com/openego/eGo@dev#egg=eGo --process-dependency-links --allow-all-external Copyleft diff --git a/doc/api.rst b/doc/api.rst index 220f8a31..83b7a11a 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -2,6 +2,7 @@ .. toctree:: :maxdepth: 7 + :glob: :titlesonly: API diff --git a/doc/conf.py b/doc/conf.py index fc0941fa..2dc759c1 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -1,4 +1,4 @@ -"""This file is part of +"""This file is part of It is developed in the project open_eGo: https://openegoproject.wordpress.com @@ -37,6 +37,10 @@ #sys.path.insert(0, os.path.abspath('.')) sys.path.insert(0, os.path.abspath('../')) + +sys.path + + # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. @@ -52,14 +56,18 @@ 'sphinx.ext.coverage', 'sphinx.ext.imgmath' , 'sphinx.ext.viewcode', -# 'sphinx.ext.autosummary', + 'sphinx.ext.autosummary', # 'sphinxcontrib.napoleon',#enable Napoleon interpreter of docstrings Sphinx v<=1.2 'sphinx.ext.napoleon', #enable Napoleon Sphinx v>1.3 # 'sphinx_paramlinks',#to have links to the types of the parameters of the functions 'numpydoc', + 'sphinxcontrib.httpdomain', # for restfull API + 'sphinxcontrib.autohttp.flask', 'sphinx.ext.extlinks' # enables external links with a key ] + + # Napoleon settings napoleon_google_docstring = True napoleon_numpy_docstring = True @@ -84,8 +92,51 @@ 'Shapely object') } +# test oedb implementation +def rstjinja(app, docname, source): + """ + Render our pages as a jinja template for fancy templating goodness. + """ + # Make sure we're outputting HTML + if app.builder.format != 'html': + return + src = source[0] + rendered = app.builder.templates.render_string( + src, app.config.html_context + ) + source[0] = rendered + +def setup(app): + app.connect("source-read", rstjinja) +import requests +oep_url= 'http://oep.iks.cs.ovgu.de/' + +# get data from oedb test +power_class = requests.get(oep_url+'/api/v0/schema/model_draft/tables/ego_power_class/rows/', ).json() + +import json +path = os.getcwd() +json_file ='../ego/scenario_setting.json' + +with open(path +'/'+json_file) as f: + scn_set = json.load(f) + + + +html_context = { + 'power_class': power_class, + 'scn_setting': scn_set +} + + + + + + +# add RestFull API +httpexample_scheme = 'https' # Add any paths that contain templates here, relative to this directory. @@ -104,7 +155,7 @@ # General information about the project. project = u'eGo' -copyright = u'2015-2017, open_eGo-Team' +copyright = u'2015-2018, open_eGo-Team' author = u'open_eGo-Team' @@ -113,7 +164,7 @@ # built documents. # # The short X.Y version. -version = '0.0.1' +version = '0.1.0' # The full version, including alpha/beta/rc tags. release = '0.0.1dev' @@ -175,11 +226,11 @@ def __getattr__(cls, name): MOCK_MODULES = ['ding0', 'ding0.results', 'shapely'] sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES) - - MOCK_MODULES = ['libgeos', 'geos', 'libgeos_c', 'geos_c','libgeos_c.so.1', + + MOCK_MODULES = ['libgeos', 'geos', 'libgeos_c', 'geos_c','libgeos_c.so.1', 'libgeos_c.so', 'shapely', 'geoalchemy2', 'geoalchemy2.shape '] - + # -- Options for HTML output ---------------------------------------------- diff --git a/doc/developer.rst b/doc/developer.rst index fc5737d6..c0bdce24 100644 --- a/doc/developer.rst +++ b/doc/developer.rst @@ -28,7 +28,7 @@ eDisGo units ------------ .. csv-table:: List of variables and units - :file: https://raw.githubusercontent.com/openego/eDisGo/dev/doc/units_table.csv + :url: https://raw.githubusercontent.com/openego/eDisGo/dev/doc/units_table.csv :delim: ; :header-rows: 1 :widths: 5, 1, 1, 5 diff --git a/doc/getting_started.rst b/doc/getting_started.rst index 74f86f12..5628ae13 100644 --- a/doc/getting_started.rst +++ b/doc/getting_started.rst @@ -27,7 +27,7 @@ Installation ``` With your activated environment `cd` to the cloned directory and run -``pip3 install -e eGo`` . This will install all needed packages into your environment. +``pip3 install -e eGo --process-dependency-links --allow-all-external`` . This will install all needed packages into your environment. .. warning:: @@ -42,14 +42,16 @@ With your activated environment `cd` to the cloned directory and run ``pip3 install -e git+https://github.com/openego/PyPSA.git@dev#egg=PyPSA`` and Folium for an web based ploting with ``pip3 install -e git+git@github.com:python-visualization/folium.git@5739244acb9868d001032df288500a047b232857#egg=folium`` - - Check if the `config.json `_ + + Check if the `config.json `_ file from eTraGo is installed in your libary ``/lib/python3.5/site-packages/etrago/tools`` . - If not copy and paste this file into this folder. + If not copy and paste this file into this folder. + + If Database connection or table erros appears use: ``pip3 install -e git+git@github.com:openego/ego.io.git@3b76dfddea14d67eb4421b6223bf981d8851e4e6#egg=ego.io`` + Using eGo: ========== 1. check and prepare your eGo setting in ``ego/scenario_setting.json`` -2. Start your calculation with in the directory of ``eGo/ego`` with - ``python3 ego_main.py`` +2. Start your calculation with in the directory of ``eGo/ego`` with ``python3 ego_main.py`` diff --git a/doc/whatsnew.rst b/doc/whatsnew.rst index b93262f9..2542fbc9 100644 --- a/doc/whatsnew.rst +++ b/doc/whatsnew.rst @@ -9,5 +9,5 @@ See what's new as per release! :backlinks: top +.. include:: whatsnew/v0-1-0.rst .. include:: whatsnew/v0-0-1.rst -.. incluede:: whatsnew/v0-1-0.rst diff --git a/doc/whatsnew/v0-1-0.rst b/doc/whatsnew/v0-1-0.rst index 39a183a9..345eaa98 100644 --- a/doc/whatsnew/v0-1-0.rst +++ b/doc/whatsnew/v0-1-0.rst @@ -1,7 +1,8 @@ -Release v0.1.0 (March 26, 2018) +Release v0.1.0 (March 29, 2018) +++++++++++++++++++++++++++++++ -As this is the second release of eGo. This Release is still under construction and not ready for a normal use. +As this is the second release of eGo. This Release introduce the resulte class +and is still under construction and not ready for a normal use. @@ -10,7 +11,11 @@ Added features -------------- * Update of Interface between eTraGo and eDisGo (specs) -* New structure of eGo module -* Restructuring of functions +* New structure of eGo module / resulte class +* Restructuring of functions * Add import function of eTraGo results form oedb +Notes +----- + +* The 'direct_specs' function is not working and needs to be set to ``false`` diff --git a/ego/data/ding0_grids/ding0_grids__1802.pkl b/ego/data/ding0_grids/ding0_grids__1802.pkl new file mode 100644 index 00000000..13ec6307 Binary files /dev/null and b/ego/data/ding0_grids/ding0_grids__1802.pkl differ diff --git a/ego/ego_main.py b/ego/ego_main.py index a9671af1..82164c99 100644 --- a/ego/ego_main.py +++ b/ego/ego_main.py @@ -34,6 +34,20 @@ logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) +## Logging +logging.basicConfig(format='%(asctime)s %(message)s',level=logging.INFO) + +logger = logging.getLogger(__name__) +ego_logger = logging.getLogger('ego') + +fh = logging.FileHandler('ego.log', mode='w') +fh.setLevel(logging.INFO) +formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') +fh.setFormatter(formatter) + +logger.addHandler(fh) +ego_logger.addHandler(fh) + if __name__ == '__main__': # import scenario settings **args of eTraGo @@ -66,8 +80,6 @@ if args['global']['recover']: eTraGo = etrago_from_oedb(session,args) - - # use eTraGo results from ego calculations if true # ToDo make function edisgo_direct_specs() @@ -105,6 +117,7 @@ mv_grid = get_mvgrid_from_bus_id(session, bus_id) # This function can be used to call the correct MV grid if args['global']['eDisGo']: + logging.info('Starting eDisGo') # ToDo move part as function to utilities or specs @@ -115,7 +128,7 @@ # ToDo get ding0 grids over db # ToDo implemente iteration - file_path = '/home/dozeumbuw/ego_dev/src/ding0_grids__1802.pkl' + file_path = 'data/ding0_grids/ding0_grids__1802.pkl' #mv_grid = open(file_path) @@ -127,7 +140,7 @@ scenario = Scenario(etrago_specs=specs, power_flow=(), mv_grid_id=mv_grid_id, - scenario_name= args['global']['scn_name']) + scenario_name= args['eTraGo']['scn_name']) network = Network.import_from_ding0(file_path, id=mv_grid_id, @@ -170,6 +183,3 @@ # possible aggregation of results # exports: total system costs, plots, csv export files - -if __name__ == '__main__': - pass diff --git a/ego/scenario_setting.json b/ego/scenario_setting.json index 89a18dae..bb19ccdf 100644 --- a/ego/scenario_setting.json +++ b/ego/scenario_setting.json @@ -1,7 +1,7 @@ { "global": { "eTraGo": true, - "eDisGo": false, + "eDisGo": true, "db": "oedb", "result_id": 359, "recover": false, @@ -11,30 +11,30 @@ "db": "oedb", "gridversion": null, "method": "lopf", - "pf_post_lopf": true, - "start_snapshot": 4000, - "end_snapshot" : 4001, + "pf_post_lopf": false, + "start_snapshot": 1, + "end_snapshot" : 5, "scn_name": "SH NEP 2035", "solver": "gurobi", "lpfile": false, "results": false, "export": false, - "storage_extendable": true, + "storage_extendable": false, "generator_noise": true, "reproduce_noise": false, "minimize_loading": false, - "k_mean_clustering": 15, + "k_mean_clustering": false, "network_clustering": false, "parallelisation": false, "skip_snapshots": false, "line_grouping": false, - "branch_capacity_factor": 0.1, + "branch_capacity_factor": 1, "load_shedding": false, "comments": null }, "eDisGo": { "direct_specs": false, - "specs": false, - "comments": "Malte Test cf 0.1, SH SQ" + "specs": true, + "comments": "make a comment, SH SQ" } } diff --git a/ego/tools/economics.py b/ego/tools/economics.py index 7d4a7cb8..09d1b89a 100644 --- a/ego/tools/economics.py +++ b/ego/tools/economics.py @@ -22,8 +22,8 @@ def annuity_per_period(capex, n, wacc, t): wacc : float Weighted average cost of capital - ToDo: - ----- + ToDo + ---- t : int Timesteps in hours i : float diff --git a/ego/tools/io.py b/ego/tools/io.py index 87e00e4f..b16ed583 100644 --- a/ego/tools/io.py +++ b/ego/tools/io.py @@ -1,5 +1,5 @@ """ -Input & output functions of eGo +Input & output functions of eGo """ __copyright__ = "ZNES" @@ -31,10 +31,16 @@ def geolocation_buses(network, session): of Countries from RenpassGisParameterRegion in order to locate the buses - ToDo: - 1) check eTrago stack generation plots and - other in order of adaptation + Parameters + ---------- + network : Network + eTraGo Network + session : sqlalchemy + session to oedb + ToDo + ---- + - check eTrago stack generation plots and other in order of adaptation """ # Start db connetion @@ -114,7 +120,7 @@ def etrago_from_oedb(session, args): """ Function with import eTraGo results for the Database. - Parameter: + Parameters ---------- session (obj): sqlalchemy session to the OEDB @@ -122,8 +128,8 @@ def etrago_from_oedb(session, args): args (dict): args from eGo scenario_setting.json - ToDo: - ----- + ToDo + ---- add Mapping for grid schema make it more generic -> class? """ @@ -178,7 +184,9 @@ def series_results(name, column, session, meta_args, result_id, ormclass): """ Function to get Time Series as pandas DataFrames by the result_id - # TODO: check index of bus_t and soon is wrong! + ToDo + ---- + - check index of bus_t and soon is wrong! """ # TODO: pls make more robust diff --git a/ego/tools/plots.py b/ego/tools/plots.py index c60b2d5d..45ad147b 100644 --- a/ego/tools/plots.py +++ b/ego/tools/plots.py @@ -1,10 +1,10 @@ """ Module to collect useful functions for plotting results of eGo -ToDo: - histogram - etc. - Implement plotly +ToDo +- histogram +- etc. +- Implement plotly """ __copyright__ = "tba" __license__ = "tba" @@ -102,29 +102,26 @@ def igeoplot(network, session, tiles=None, geoloc=None, args=None): Parameters ---------- - network (PyPSA): + network : PyPSA PyPSA network container - tiles (str): - Folium background map style 'None' as OSM - or 'Nasa' - geoloc (list): - Define center of map as (lon,lat) - - Results: - -------- - HTML Plot page - - ToDos: - ------ - implement eDisGo Polygons - fix version problems of data - use grid.ego_dp_hvmv_substation subst_id and otg_id - - use cluster or boxes to limit data volumn - - Legend - Map - http://nbviewer.jupyter.org/gist/BibMartin/f153aa957ddc5fadc64929abdee9ff2e + tiles : str + Folium background map style `None` as OSM or `Nasa` + geoloc : list of str + Define center of map as (lon,lat) + + Returns + ------- + + HTML Plot page + + ToDo + ---- + - implement eDisGo Polygons + - fix version problems of data + - use grid.ego_dp_hvmv_substation subst_id and otg_id + - use cluster or boxes to limit data volumn + - add Legend + - Map see: http://nbviewer.jupyter.org/gist/BibMartin/f153aa957ddc5fadc64929abdee9ff2e """ if geoloc is None: @@ -303,8 +300,8 @@ def total_power_costs_plot(eTraGo): """ plot power price of eTraGo - Parameter - --------- + Parameters + ---------- eTraGo :class:`etrago.io.NetworkScenario` Returns @@ -346,7 +343,7 @@ def total_power_costs_plot(eTraGo): def plot_etrago_production(ego): """ - input eGO + input eGo Bar plot all etrago costs """ diff --git a/ego/tools/results.py b/ego/tools/results.py index 01e08ca0..cc55f2c5 100644 --- a/ego/tools/results.py +++ b/ego/tools/results.py @@ -1,11 +1,12 @@ +# -*- coding: utf-8 -*- """ Module of eGo results with functions for writing, creating and results of eGo - -ToDo: - add eDisGo - write results to database - integrate plot and other functions ad methods to the class eGo +ToDo +---- + - add eDisGo + - write results to database + - integrate plot and other functions ad methods to the class eGo """ @@ -24,23 +25,23 @@ import numpy as np from etrago.tools.plot import (plot_line_loading, plot_stacked_gen, curtailment, gen_dist, - storage_distribution, - plot_voltage,plot_residual_load) + storage_distribution, + plot_voltage,plot_residual_load) class egoBasic(): -""" -eGo basics class. + """eGo basics class. -Parameters ----------- + Parameters + ---------- -eTraGo : Network - Network container of eTraGo based on PyPSA -eDisGo : Network - Network container of eDisGo based on PyPSA -args : dict - Dict of the scenario_setting.json -""" + eTraGo : Network + Network container of eTraGo based on PyPSA + eDisGo : Network + Network container of eDisGo based on PyPSA + args : dict + Dict of the scenario_setting.json + + """ def __init__(self, eTraGo, *args, **kwargs): @@ -59,21 +60,26 @@ def __repr__(self): class eTraGoResults(egoBasic): -"""eTraGo Results + """eTraGo Results -This module contains all results of eTraGo for eGo. + This module contains all results of eTraGo for eGo. -Example --------- -The module can be used by etg = eTraGoResults(eTraGo=network) + Examples + -------- -See Also --------- -`The eTraGo documentation on Extensions -`_ + The module can be used by ``etg = eTraGoResults()`` -""" + See also + -------- + The `eTraGo`_ documentation. + + References + ---------- + .. _eTraGo: + `eTraGo `_, \ + eTraGo Documentation. + """ def __init__(self,eTraGo, *args, **kwargs): super().__init__(eTraGo, *args, **kwargs) @@ -107,15 +113,16 @@ def __init__(self,eTraGo, *args, **kwargs): class eDisGoResults(egoBasic): -""" eDisGo Results + """ eDisGo Results -This module contains all results of eDisGo for eGo. + This module contains all results of eDisGo for eGo. -ToDo: - add eDisGo - add iteration for multiple ding0 grids + ToDo + ---- + - add eDisGo + - add iteration for multiple ding0 grids -""" + """ def __init__(self,eDisGo): super().__init__(eDisGo) self.edisgo = pd.DataFrame() @@ -124,31 +131,28 @@ def __init__(self,eDisGo): class eGo(eTraGoResults): -"""Main eGo module which including all results and main functionalities. + """Main eGo module which including all results and main functionalities. -Parameters ----------- -eTraGo : Network - -eDisGo : Network - + Parameters + ---------- + eTraGo : Network + eDisGo : Network -ToDo: - add eDisGo -""" + + + ToDo + ---- + - add eDisGo + """ def __init__(self,eTraGo, scn_name): super().__init__(eTraGo, scn_name) #super().__init__(eDisGo) self.total = pd.DataFrame() # add total results here - - - - def write_results_to_db(): - pass + # write_results_to_db(): pass @@ -174,7 +178,7 @@ def total_storage_charges(network): results : pandas.DataFrame Return ... - Note: + Notes ----- charge : Quantity of charged Energy in MWh over scenario time steps @@ -225,12 +229,12 @@ def etrago_storages(network): ---------- network : eTraGo Network - ... + eTraGo Network Class based on PyPSA - Returns: - -------- + Returns + ------- storages : pandas.DataFrame - .... + DataFrame with cumulated results of storages """ # Charge / discharge (MWh) and installed capacity MW @@ -243,24 +247,26 @@ def etrago_storages(network): def etrago_operating_costs(network): """ Function to get all operating costs of eTraGo. - Parameter - --------- + Parameters + ---------- network : Network of eTraGo - .... + Network of eTraGo Returns ------- + power_price : :class:`~.pd.DataFrame` + Examples + -------- - Example - ------- - losses: - grid losses: amount and costs - use calc_line_losses(network): from etrago pf_post_lopf + - losses + - grid losses : amount and costs + - use calc_line_losses(network) from etrago pf_post_lopf - TodDo: - change naming and function structure - seperate operation costs in other functions ? + ToDo + ---- + - change naming and function structure + - seperate operation costs in other functions ? """ etg = network @@ -300,14 +306,16 @@ def etrago_grid_investment(network): Parameters ---------- + network : Network eTraGo Returns ------- - ToDo: - add new release of etrago 0.7 + ToDo + ---- + - add new release of etrago 0.7 """ pass @@ -316,11 +324,9 @@ def etrago_grid_investment(network): def edisgo_grid_investment(network): """Function to get all costs of grid investment of eDisGo. - ToDO: - add iteration and container of all costs of edisgo network - .... - - + Notes + ----- + - ToDo add iteration and container of all costs of edisgo network """ pass @@ -328,9 +334,11 @@ def get_generator_investment(network, scn_name): """ Get investment costs per carrier/gernator. work around later db table -> check capital_cost as cost input?!? - ToDo: - change values in csv - add values to database + + ToDo + ---- + - change values in csv + - add values to database """ etg = network @@ -373,7 +381,9 @@ def investment_costs(network): Line extentation Storage costs? - ToDo: add edisgo + ToDo + ---- + - add edisgo """ etg = network @@ -426,9 +436,9 @@ def create_etrago_results(network,scn_name): """ Create eTraGo results - results + Returns ------- - results.etrago :obj: + etrago : :obj:pd.DataFrame """ diff --git a/ego/tools/utilities.py b/ego/tools/utilities.py index 5348d73c..6f8e6454 100644 --- a/ego/tools/utilities.py +++ b/ego/tools/utilities.py @@ -11,7 +11,7 @@ def get_scenario_setting(json_file='scenario_setting.json'): """ Get and open json file with scenaio settings of eGo - Parameter: + Parameters ---------- json_file (str): @@ -19,7 +19,7 @@ def get_scenario_setting(json_file='scenario_setting.json'): Name of scenario setting json file """ path = os.getcwd() - # add try ego/ + # add try ego/ print(path) with open(path +'/'+json_file) as f: scn_set = json.load(f) @@ -39,12 +39,12 @@ def get_scenario_setting(json_file='scenario_setting.json'): def get_time_steps(args): """ Get time step of calculation by scenario settings. - Parameter: + Parameters ---------- args (dict): dict of 'scenario_setting.json' - Result: + Returns ------- time_step (int): Number of timesteps of the calculation. diff --git a/requirements.txt b/requirements.txt index 65513402..0c733bb6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,10 @@ # Packages for read the docs # Using single requirments for docs, see: -# https://github.com/rtfd/readthedocs.org/issues/2070 +# https://github.com/rtfd/readthedocs.org/issues/2070 sphinx_rtd_theme pandas >=0.20.3, <=0.20.3 pypsa >= 0.11.0, <= 0.11.0 numpy == 1.12.1 numpydoc == 0.7.0 +sphinxcontrib-httpdomain +aiohttp_jinja2 diff --git a/setup.py b/setup.py index 50547382..afe0df17 100644 --- a/setup.py +++ b/setup.py @@ -10,13 +10,13 @@ author='wolfbunke, maltesc', author_email='', description='A python package for distribution and transmission grid analysis and optimization based eDisGo and eTraGo', - version='0.0.1', + version='0.1.0', url='https://github.com/openego/eGo', license="GNU Affero General Public License Version 3 (AGPL-3.0)", packages=find_packages(), include_package_data=True, install_requires=['egoio == 0.3.0', - 'eDisGo == 0.0.1', + 'eDisGo == 0.0.2', 'pandas ==0.20.3', 'sqlalchemy >= 1.0.15, <= 1.2.0', 'geoalchemy2 >= 0.3.0, <=0.4.0', @@ -32,10 +32,12 @@ extras_require={ 'docs': [ 'sphinx >= 1.4', - 'sphinx_rtd_theme']}, + 'sphinx_rtd_theme', + 'sphinxcontrib-httpdomain']}, package_data={ 'ego': [ os.path.join('*.json'), - os.path.join('tools','*.json'),] + os.path.join('tools','*.json'), + os.path.join('data','*.csv') ] } )