From 76cc1729780f152b28135485b18856bd5d06f2e3 Mon Sep 17 00:00:00 2001 From: MarlonSchlemminger Date: Sun, 18 Mar 2018 09:31:10 +0100 Subject: [PATCH 1/9] new calculation --- .../renpass_gis/simple_feedin/db.py | 16 +- .../simple_feedin/simple_feedin.py | 144 +++++++++++++++--- .../ego_simple-feedin_per_scenario.sql | 86 +++++++++++ 3 files changed, 223 insertions(+), 23 deletions(-) diff --git a/preprocessing/python_scripts/renpass_gis/simple_feedin/db.py b/preprocessing/python_scripts/renpass_gis/simple_feedin/db.py index e51f9cb0..b02eba0b 100644 --- a/preprocessing/python_scripts/renpass_gis/simple_feedin/db.py +++ b/preprocessing/python_scripts/renpass_gis/simple_feedin/db.py @@ -84,6 +84,8 @@ def meta_definition(meta, conn): meta.reflect(bind=conn, schema='coastdat') meta.reflect(bind=conn, schema='model_draft', only=['ego_weather_measurement_point']) + meta.reflect(bind=conn, schema='model_draft', + only=['ego_wind_turbine_data']) #meta.reflect(bind=conn, schema='public', # only=['weather_measurement_point']) # table with given/ own defined points @@ -141,17 +143,21 @@ class Typified(Base): Base.prepare() # simplify class names -Datatype, Projection, Spatial, Timeseries, Year, Point =\ +Datatype, Projection, Spatial, Timeseries, Year, Point, Turbine =\ Base.classes.datatype, Base.classes.projection, Base.classes.spatial,\ Base.classes.timeseries, Base.classes.year,\ - Base.classes.ego_weather_measurement_point + Base.classes.ego_weather_measurement_point,\ + Base.classes.ego_wind_turbine_data # Base.classes.weather_measurement_point session = sessionmaker(bind=conn)() print('Retrieve data...') -query = session.query(Point.coastdat_id, Point.type_of_generation, Point.geom) -Points = [(coastdat_id, type_of_generation, shape.to_shape(geom)) - for coastdat_id, type_of_generation, geom in query.all()] +query = session.query(Point.coastdat_id, Point.type_of_generation, Point.wea_type, Point.geom) +Points = [(coastdat_id, type_of_generation, wea_type, shape.to_shape(geom)) + for coastdat_id, type_of_generation, wea_type, geom in query.all()] +query = session.query(Turbine.type_of_generation, Turbine.wea, Turbine.d_rotor, Turbine.h_hub) +Turbines = [(type_of_generation, wea, d_rotor, h_hub) + for type_of_generation, wea, d_rotor, h_hub in query.all()] print('Done!') diff --git a/preprocessing/python_scripts/renpass_gis/simple_feedin/simple_feedin.py b/preprocessing/python_scripts/renpass_gis/simple_feedin/simple_feedin.py index b480ef93..e4549da8 100644 --- a/preprocessing/python_scripts/renpass_gis/simple_feedin/simple_feedin.py +++ b/preprocessing/python_scripts/renpass_gis/simple_feedin/simple_feedin.py @@ -51,6 +51,7 @@ from sqlalchemy import (Column, Text, Integer, Float, ARRAY) from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import text +import re points = db.Points conn = db.conn @@ -83,6 +84,64 @@ def asnumber(x): except ValueError: return x +def compatibility_windlib(turbines, default_onshore, default_offshore): + + for index, row in turbines.iterrows(): + if row['wea'].split(' ', 1)[0] == 'Adwen/Areva': + if row['type_of_generation'] == 'wind_offshore': + turbines.iloc[index, 4] = default_offshore + elif row['type_of_generation'] == 'wind_onshore': + turbines.iloc[index, 4] = default_onshore + + elif row['wea'].split(' ', 1)[0] == 'Enercon': + turbines.iloc[index, 4] = turbines.iloc[index, 1].replace('-', ' ') + turbines.iloc[index, 4] = turbines.iloc[index, 4].replace('/', ' ') + turbines.iloc[index, 4] = turbines.iloc[index, 4].replace('50', '00') + + elif row['wea'].split(' ', 1)[0] == 'Eno': + turbines.iloc[index, 4] = turbines.iloc[index, 1][4:9] + turbines.iloc[index, 4] = turbines.iloc[index, 4][:3] + ' ' +\ + turbines.iloc[index, 4][3:] + + elif row['wea'].split(' ', 1)[0] == 'GE': + if row['type_of_generation'] == 'wind_offshore': + turbines.iloc[index, 4] = default_offshore + elif row['type_of_generation'] == 'wind_onshore': + turbines.iloc[index, 4] = default_onshore + + elif row['wea'].split(' ', 1)[0] == 'Nordex': + turbines.iloc[index, 4] = turbines.iloc[index, 1].replace('AW', 'S') + turbines.iloc[index, 4] = turbines.iloc[index, 4][:8] + ' ' +\ + turbines.iloc[index, 4][8:] + turbines.iloc[index, 4] = turbines.iloc[index, 4].replace('/', ' ') + + elif row['wea'].split(' ', 1)[0] == 'Senvion/REpower': + turbines.iloc[index, 4] = turbines.iloc[index, 1].replace('Senvion/REpower', 'REPOWER') + turbines.iloc[index, 4] = turbines.iloc[index, 4].replace('/', ' ') + split = re.split('(\d+)', turbines.iloc[index, 4]) + if split[0] == 'REPOWER MM': + turbines.iloc[index, 4] = split[0]+' '+split[1]+split[2]+split[3] + elif split[0] == 'REPOWER S': + turbines.iloc[index, 4] = 'REPOWER '+str(float(split[3])/1000)+\ + ' M'+split[1] + + elif row['wea'].split(' ', 1)[0] == 'Siemens': + split = re.split('(\d+)', turbines.iloc[index, 1]) + turbines.iloc[index, 4] = split[0]+' '+str(float(split[3])/1000)+\ + ' '+split[1] + + elif row['wea'].split(' ', 1)[0] == 'Vensys': + split = re.split('(\d+)', turbines.iloc[index, 1]) + turbines.iloc[index, 4] = 'Vensys '+split[1] + + elif row['wea'].split(' ', 1)[0] == 'Vestas': + split = re.split('(\d+)', turbines.iloc[index, 1]) + turbines.iloc[index, 4] = split[0]+' '+split[1]+' '+split[3] + + turbines['wea_windlib'] = turbines['wea_windlib'].str.upper() + + return turbines + def df_to_renewable_feedin(df, weather_year, weather_scenario_id): print('Creating table ego_renewable_feedin..') Base = declarative_base() @@ -132,17 +191,14 @@ class Ego_renewable_feedin(Base): print('Done!') - def to_dictionary(cfg, section): """ Writes section data of a configuration file to a dictionary - Parameters ---------- cfg : configparser.ConfigParser Used for configuration file parser language. section : str Section in configuration file. - Returns ------- dict @@ -152,6 +208,32 @@ def to_dictionary(cfg, section): return {k: asnumber(v) for k, v in cfg.items(section)} +def wind_dict(wea_type, type_of_generation, turbines): + """ Writes section data of a configuration file to a dictionary + + Parameters + ---------- + cfg : configparser.ConfigParser + Used for configuration file parser language. + section : str + Section in configuration file. + + Returns + ------- + dict + Dictionary containing section data. + """ + + return {'d_rotor': turbines[(turbines['wea'] == wea_type) & + (turbines['type_of_generation'] == + type_of_generation)].d_rotor.item(), + 'h_hub': turbines[(turbines['wea'] == wea_type) &\ + (turbines['type_of_generation'] ==\ + type_of_generation)].h_hub.item(), + 'wind_conv_type': turbines[(turbines['wea'] == wea_type) &\ + (turbines['type_of_generation'] ==\ + type_of_generation)].wea_windlib.item()} + def main(): """ """ @@ -161,13 +243,12 @@ def main(): cfg = db.readcfg(config) temp = {} powerplants = {} - + columns = ['type_of_generation', 'wea', 'd_rotor', 'h_hub'] + default_offshore = 'SIEMENS SWT 3.6 120' + default_onshore = 'ENERCON E 70 2000' + turbines = pd.DataFrame(db.Turbines, columns=columns) + turbines['wea_windlib'] = '' # instatiate feedinlib models in dictionary - powerplants['wind_onshore'] = plants.WindPowerPlant( - **to_dictionary(cfg=cfg, section='WindTurbineOnshore')) - - powerplants['wind_offshore'] = plants.WindPowerPlant( - **to_dictionary(cfg=cfg, section='WindTurbineOffshore')) powerplants['solar'] = plants.Photovoltaic( **to_dictionary(cfg=cfg, section='Photovoltaic')) @@ -175,11 +256,14 @@ def main(): print('Calculating feedins...') #toDo # calculate feedins applying correction factors - - #count = 0 - for coastdat_id, type_of_generation, geom in points: - #count += 1 - #print(count) + turbines = compatibility_windlib(turbines, default_onshore, default_offshore) + count = 0 + default = 0 + specific = 0 + for coastdat_id, type_of_generation, wea_type, geom in points: + + count += 1 + print(count) try: weather = coastdat.get_weather(conn, geom, weather_year) except IndexError: @@ -187,11 +271,31 @@ def main(): continue if type_of_generation == 'wind_offshore': - feedin = correction_offshore * powerplants[type_of_generation].\ - feedin(weather=weather, installed_capacity=1) + plant = wind_dict(wea_type, type_of_generation, turbines) + try: + feedin = correction_offshore * plants.WindPowerPlant(**plant).\ + feedin(weather=weather, installed_capacity=1) + specific += 1 + except: + print(wea_type+' not found.') + plant['wind_conv_type'] = default_offshore + feedin = correction_offshore * plants.WindPowerPlant(**plant).\ + feedin(weather=weather, installed_capacity=1) + default += 1 + elif type_of_generation == 'wind_onshore': - feedin = powerplants[type_of_generation].\ - feedin(weather=weather, installed_capacity=1) + plant = wind_dict(wea_type, type_of_generation, turbines) + try: + feedin = plants.WindPowerPlant(**plant).\ + feedin(weather=weather, installed_capacity=1) + specific += 1 + except: + print(wea_type+' not found.') + plant['wind_conv_type'] = default_onshore + feedin = plants.WindPowerPlant(**plant).\ + feedin(weather=weather, installed_capacity=1) + default += 1 + elif type_of_generation == 'solar': feedin = correction_solar * powerplants[type_of_generation].\ feedin(weather=weather, peak_power=1) @@ -202,6 +306,10 @@ def main(): #print('Writing results to %s.' % filename) # write results to file + print('specific: ') + print(specific) + print('default: ') + print(default) df = pd.DataFrame(temp) df_to_renewable_feedin(df, weather_year, weather_scenario_id) print('Done!') diff --git a/preprocessing/sql_snippets/ego_simple-feedin_per_scenario.sql b/preprocessing/sql_snippets/ego_simple-feedin_per_scenario.sql index 81f7f2f0..e12ff758 100644 --- a/preprocessing/sql_snippets/ego_simple-feedin_per_scenario.sql +++ b/preprocessing/sql_snippets/ego_simple-feedin_per_scenario.sql @@ -144,6 +144,7 @@ CREATE TABLE model_draft.ego_weather_measurement_point ( coastdat_id bigint NOT NULL, type_of_generation text NOT NULL, + wea_type text, geom geometry(Point,4326), CONSTRAINT weather_measurement_point_pkey PRIMARY KEY (coastdat_id, type_of_generation) ) @@ -218,6 +219,91 @@ FROM climate.cosmoclmgrid AS coastdat, WHERE ST_Intersects(neighbour.geom, coastdat.geom) ON CONFLICT DO NOTHING; +-- set wea_type +UPDATE model_draft.ego_weather_measurement_point +SET wea_type = wea +FROM (SELECT gid, wea_manufacturer||' '||wea_type AS wea + FROM + (SELECT gid, wea_manufacturer, wea_type, COUNT(*) as cnt, + ROW_NUMBER() OVER (PARTITION BY gid ORDER BY COUNT(*) DESC) AS rnk + FROM climate.cosmoclmgrid a, model_draft.bnetza_eeg_anlagenstammdaten_wind_classification b + WHERE ST_Intersects(a.geom, ST_Transform(b.geom, 4326)) + AND wea_type <> 'na' + AND seelage IS NULL + GROUP BY gid, wea_manufacturer, wea_type + ) as tg + WHERE rnk = 1 + ) a +WHERE coastdat_id = gid +AND type_of_generation = 'wind_onshore'; + +UPDATE model_draft.ego_weather_measurement_point +SET wea_type = wea +FROM (SELECT gid, wea_manufacturer||' '||wea_type AS wea + FROM + (SELECT gid, wea_manufacturer, wea_type, COUNT(*) as cnt, + ROW_NUMBER() OVER (PARTITION BY gid ORDER BY COUNT(*) DESC) AS rnk + FROM climate.cosmoclmgrid a, model_draft.bnetza_eeg_anlagenstammdaten_wind_classification b + WHERE ST_Intersects(a.geom, ST_Transform(b.geom, 4326)) + AND wea_type <> 'na' + AND seelage IS NOT NULL + GROUP BY gid, wea_manufacturer, wea_type + ) as tg + WHERE rnk = 1 + ) a +WHERE coastdat_id = gid +AND type_of_generation = 'wind_offshore'; + +DELETE FROM model_draft.ego_weather_measurement_point +WHERE wea_type IS NULL +AND type_of_generation IN ('wind_onshore', 'wind_offshore'); + +-- get data for most used wind turbines +DROP TABLE IF EXISTS model_draft.ego_wind_turbine_data; + +CREATE TABLE model_draft.ego_wind_turbine_data +( + type_of_generation text NOT NULL, + wea text NOT NULL, + d_rotor double precision NOT NULL, + h_hub double precision NOT NULL, + CONSTRAINT wind_turbine_data_pkey PRIMARY KEY (type_of_generation, wea) + ); + +INSERT INTO model_draft.ego_wind_turbine_data (type_of_generation, wea, d_rotor, h_hub) + (SELECT 'wind_onshore', + wea_manufacturer||' '||wea_type, + rotordurchmesser, + nabenhöhe + FROM + (SELECT wea_manufacturer, wea_type, rotordurchmesser, nabenhöhe, COUNT(*) AS cnt, + ROW_NUMBER() OVER (PARTITION BY wea_type ORDER BY COUNT(*) DESC) AS rnk + FROM model_draft.bnetza_eeg_anlagenstammdaten_wind_classification + WHERE wea_type <> 'na' + AND seelage IS NULL + GROUP BY wea_manufacturer, wea_type, rotordurchmesser, nabenhöhe + ) AS tg + WHERE rnk = 1 + AND wea_manufacturer||' '||wea_type IN (SELECT wea_type FROM model_draft.ego_weather_measurement_point) + ); + +INSERT INTO model_draft.ego_wind_turbine_data (type_of_generation, wea, d_rotor, h_hub) + (SELECT 'wind_offshore', + wea_manufacturer||' '||wea_type, + rotordurchmesser, + nabenhöhe + FROM + (SELECT wea_manufacturer, wea_type, rotordurchmesser, nabenhöhe, COUNT(*) AS cnt, + ROW_NUMBER() OVER (PARTITION BY wea_type ORDER BY COUNT(*) DESC) AS rnk + FROM model_draft.bnetza_eeg_anlagenstammdaten_wind_classification + WHERE wea_type <> 'na' + AND seelage IS NOT NULL + GROUP BY wea_manufacturer, wea_type, rotordurchmesser, nabenhöhe + ) AS tg + WHERE rnk = 1 + AND wea_manufacturer||' '||wea_type IN (SELECT wea_type FROM model_draft.ego_weather_measurement_point) + ); + COMMENT ON TABLE model_draft.ego_weather_measurement_point IS '{ "title": "model_draft.ego_weather_measurement_point", "description": "Geometry of weather points for feedin timeseries calculation", From 45e8d902785771e77d2251acba1614e452b35595 Mon Sep 17 00:00:00 2001 From: MarlonSchlemminger Date: Fri, 23 Mar 2018 10:03:30 +0100 Subject: [PATCH 2/9] implementation of new calculation --- .../ego_dp_powerflow_assignment_generator.sql | 18 +- .../ego_dp_powerflow_timeseries_generator.sql | 21 +- .../renpass_gis/simple_feedin/db.py | 14 +- .../renpass_gis/simple_feedin/wind_onshore.py | 544 ++++++++++++++++++ .../ego_simple-feedin_per_scenario.sql | 38 +- 5 files changed, 614 insertions(+), 21 deletions(-) create mode 100644 preprocessing/python_scripts/renpass_gis/simple_feedin/wind_onshore.py diff --git a/dataprocessing/sql_snippets/ego_dp_powerflow_assignment_generator.sql b/dataprocessing/sql_snippets/ego_dp_powerflow_assignment_generator.sql index 21ef91b4..cd196d52 100644 --- a/dataprocessing/sql_snippets/ego_dp_powerflow_assignment_generator.sql +++ b/dataprocessing/sql_snippets/ego_dp_powerflow_assignment_generator.sql @@ -30,6 +30,7 @@ CREATE TABLE model_draft.ego_supply_pf_generator_single ( efficiency double precision, w_id bigint, aggr_id bigint, + power_class bigint, source_name character varying, CONSTRAINT generator_single_data_pkey PRIMARY KEY (scn_name, generator_id), CONSTRAINT generator_data_source_fk FOREIGN KEY (source) @@ -250,7 +251,16 @@ UPDATE model_draft.ego_supply_pf_generator_single a AND ST_Intersects(result.geom, b.geom) AND generator_id = result.un_id; +UPDATE model_draft.ego_supply_pf_generator_single a + SET power_class = b.power_class_id + FROM model_draft.ego_power_class b + WHERE a.p_nom >= b.lower_limit + AND a.p_nom < b.upper_limit + AND a.source IN (SELECT source_id from model_draft.ego_grid_pf_hv_source WHERE name IN('wind_onshore')); +UPDATE model_draft.ego_supply_pf_generator_single a + SET power_class = 0 + WHERE source IN (SELECT source_id from model_draft.ego_grid_pf_hv_source WHERE name IN('wind_offshore', 'solar')); -- Create aggregate IDs in pf_generator_single @@ -269,15 +279,17 @@ UPDATE model_draft.ego_supply_pf_generator_single a FROM (SELECT b.bus, b.w_id, b.source, + b.power_class, b.scn_name, nextval('model_draft.ego_supply_pf_generator_single_aggr_id') as aggr_id FROM model_draft.ego_supply_pf_generator_single b WHERE p_nom < 50 AND source IN (SELECT source_id from model_draft.ego_grid_pf_hv_source WHERE name IN('wind_onshore', 'wind_offshore', 'solar')) - GROUP BY b.bus, b.w_id, b.source, b.scn_name) AS result + GROUP BY b.bus, b.w_id, b.source, b.power_class, b.scn_name) AS result WHERE a.bus = result.bus AND a.w_id = result.w_id AND a.source = result.source + AND a.power_class = result.power_class AND a.scn_name = result.scn_name; -- source <> (wind and solar) and p_nom < 50 MW @@ -308,7 +320,7 @@ DELETE FROM model_draft.ego_supply_pf_generator_single WHERE p_nom IS NULL OR p_ DELETE FROM model_draft.ego_grid_pf_hv_generator WHERE scn_name IN ('Status Quo', 'NEP 2035', 'eGo 100'); --- source = (wind and solar) and p_nom < 50 MW +-- source = wind_onshore and p_nom < 50 MW INSERT INTO model_draft.ego_grid_pf_hv_generator ( scn_name, generator_id, @@ -339,7 +351,7 @@ INSERT INTO model_draft.ego_grid_pf_hv_generator ( AND a.aggr_id IS NOT NULL AND source IN (SELECT source_id from model_draft.ego_grid_pf_hv_source WHERE name IN('wind_onshore', 'wind_offshore', 'solar')) - GROUP BY a. scn_name, a.aggr_id, a.bus, a.w_id, a.source; + GROUP BY a. scn_name, a.aggr_id, a.bus, a.w_id, a.power_class, a.source; -- source <> (wind and solar) and p_nom < 50 MW INSERT INTO model_draft.ego_grid_pf_hv_generator ( diff --git a/dataprocessing/sql_snippets/ego_dp_powerflow_timeseries_generator.sql b/dataprocessing/sql_snippets/ego_dp_powerflow_timeseries_generator.sql index 31eaa59b..3c2a6c35 100644 --- a/dataprocessing/sql_snippets/ego_dp_powerflow_timeseries_generator.sql +++ b/dataprocessing/sql_snippets/ego_dp_powerflow_timeseries_generator.sql @@ -74,14 +74,16 @@ FROM (SELECT aggr_id AS generator_id, w_id, + power_class, source FROM model_draft.ego_supply_pf_generator_single WHERE source IN (12, 13, 17) AND scn_name = 'Status Quo' - GROUP BY aggr_id, w_id, source) AS gen, + GROUP BY aggr_id, w_id, power_class, source) AS gen, (SELECT w_id, + power_class, CASE WHEN source LIKE '%%solar%%' THEN 12 WHEN source LIKE '%%wind_onshore%%' THEN 13 @@ -90,7 +92,8 @@ FROM feedin FROM model_draft.ego_renewable_feedin) AS feedin WHERE gen.source = feedin.source - AND gen.w_id = feedin.w_id; +AND gen.w_id = feedin.w_id +AND gen.power_class = feedin.power_class; -- @@ -179,14 +182,16 @@ FROM (SELECT aggr_id AS generator_id, w_id, + power_class, source FROM model_draft.ego_supply_pf_generator_single WHERE source IN (12, 13, 17) AND scn_name = 'NEP 2035' - GROUP BY aggr_id, w_id, source) AS gen, + GROUP BY aggr_id, w_id, power_class, source) AS gen, (SELECT w_id, + power_class, CASE WHEN source LIKE '%%solar%%' THEN 12 WHEN source LIKE '%%wind_onshore%%' THEN 13 @@ -195,7 +200,8 @@ FROM feedin FROM model_draft.ego_renewable_feedin) AS feedin WHERE gen.source = feedin.source - AND gen.w_id = feedin.w_id; +AND gen.w_id = feedin.w_id +AND gen.power_class = feedin.power_class; -- construct array per aggr_id according to source timeseries INSERT into model_draft.ego_grid_pf_hv_generator_pq_set (scn_name, generator_id, temp_id, p_set) @@ -280,14 +286,16 @@ FROM (SELECT aggr_id AS generator_id, w_id, + power_class, source FROM model_draft.ego_supply_pf_generator_single WHERE source IN (12, 13, 17) AND scn_name = 'eGo 100' - GROUP BY aggr_id, w_id, source) AS gen, + GROUP BY aggr_id, w_id, power_class, source) AS gen, (SELECT w_id, + power_class, CASE WHEN source LIKE '%%solar%%' THEN 12 WHEN source LIKE '%%wind_onshore%%' THEN 13 @@ -296,7 +304,8 @@ FROM feedin FROM model_draft.ego_renewable_feedin) AS feedin WHERE gen.source = feedin.source - AND gen.w_id = feedin.w_id; +AND gen.w_id = feedin.w_id +AND gen.power_class = feedin.power_class; -- construct array per aggr_id according to source timeseries INSERT into model_draft.ego_grid_pf_hv_generator_pq_set (scn_name, generator_id, temp_id, p_set) diff --git a/preprocessing/python_scripts/renpass_gis/simple_feedin/db.py b/preprocessing/python_scripts/renpass_gis/simple_feedin/db.py index b02eba0b..5888c11f 100644 --- a/preprocessing/python_scripts/renpass_gis/simple_feedin/db.py +++ b/preprocessing/python_scripts/renpass_gis/simple_feedin/db.py @@ -84,8 +84,6 @@ def meta_definition(meta, conn): meta.reflect(bind=conn, schema='coastdat') meta.reflect(bind=conn, schema='model_draft', only=['ego_weather_measurement_point']) - meta.reflect(bind=conn, schema='model_draft', - only=['ego_wind_turbine_data']) #meta.reflect(bind=conn, schema='public', # only=['weather_measurement_point']) # table with given/ own defined points @@ -143,21 +141,17 @@ class Typified(Base): Base.prepare() # simplify class names -Datatype, Projection, Spatial, Timeseries, Year, Point, Turbine =\ +Datatype, Projection, Spatial, Timeseries, Year, Point=\ Base.classes.datatype, Base.classes.projection, Base.classes.spatial,\ Base.classes.timeseries, Base.classes.year,\ Base.classes.ego_weather_measurement_point,\ - Base.classes.ego_wind_turbine_data # Base.classes.weather_measurement_point session = sessionmaker(bind=conn)() print('Retrieve data...') -query = session.query(Point.coastdat_id, Point.type_of_generation, Point.wea_type, Point.geom) -Points = [(coastdat_id, type_of_generation, wea_type, shape.to_shape(geom)) - for coastdat_id, type_of_generation, wea_type, geom in query.all()] +query = session.query(Point.coastdat_id, Point.type_of_generation, Point.geom) +Points = [(coastdat_id, type_of_generation, shape.to_shape(geom)) + for coastdat_id, type_of_generation, geom in query.all()] -query = session.query(Turbine.type_of_generation, Turbine.wea, Turbine.d_rotor, Turbine.h_hub) -Turbines = [(type_of_generation, wea, d_rotor, h_hub) - for type_of_generation, wea, d_rotor, h_hub in query.all()] print('Done!') diff --git a/preprocessing/python_scripts/renpass_gis/simple_feedin/wind_onshore.py b/preprocessing/python_scripts/renpass_gis/simple_feedin/wind_onshore.py new file mode 100644 index 00000000..a29c63c3 --- /dev/null +++ b/preprocessing/python_scripts/renpass_gis/simple_feedin/wind_onshore.py @@ -0,0 +1,544 @@ +# -*- coding: utf-8 -*- +""" +Created on Wed Mar 14 14:30:54 2018 + +__author__ = "MarlonSchlemminger" +""" + +import pandas as pd +import db +from sqlalchemy import (MetaData, and_, or_, Column, Text, text, Integer, Float, ARRAY) +from sqlalchemy.ext.automap import automap_base +from operator import itemgetter +from functions import C_choice_of_windgenerator +import pkg_resources +import re +from feedinlib import powerplants as plants +from oemof.db import coastdat +from sqlalchemy.ext.declarative import declarative_base + +points = db.Points +conn = db.conn +session = db.session +meta = MetaData() + +config = 'config.ini' +correction_offshore = 0.83 +correction_solar = 0.8 +weather_year = 2011 +weather_scenario_id = 1 + +def asnumber(x): + """ Tries to convert a string to a numeric format + + Parameters + ---------- + x : str + + Returs + ------ + x : int or float or str + """ + + try: + return int(x) + except ValueError: + try: + return float(x) + except ValueError: + return x + + +def collect_bnetza_data(): + """ + Collects data of wind turbines available in the BNetzA Anlagenstammdaten. + + Parameters + ---------- + + Returns + ------- + plants : DataFrame of all wind generators in BNetzA + """ + meta.reflect(bind=conn, schema='model_draft', + only=['bnetza_eeg_anlagenstammdaten_wind_classification']) + Base = automap_base(metadata=meta) + Base.prepare() + + Bnetza = Base.classes.bnetza_eeg_anlagenstammdaten_wind_classification + + query = session.query(Bnetza.installierte_leistung, + Bnetza.wea_manufacturer, + Bnetza.wea_type, + Bnetza.nabenhöhe, + Bnetza.rotordurchmesser).filter(Bnetza.seelage == None) + plants = [(installierte_leistung, + wea_manufacturer, + wea_type, + nabenhöhe, + rotordurchmesser) + for installierte_leistung, wea_manufacturer, wea_type, nabenhöhe, rotordurchmesser + in query.all()] + plants.sort(key=itemgetter(0)) + columns = ['capacity', 'manufacturer', 'type', 'hub', 'rotor'] + plants = pd.DataFrame(plants, columns=columns) + + return plants + + +def collect_ego_turbines(): + """ + Collects data of wind turbines used in the eGo database. + + Parameters + ---------- + + Returns + ------- + generators : capacity of turbines used in the eGo database + """ + meta.reflect(bind=conn, schema='model_draft', + only=['ego_dp_supply_res_powerplant']) + Base = automap_base(metadata=meta) + Base.prepare() + + Dp = Base.classes.ego_dp_supply_res_powerplant + + query = session.query(Dp.electrical_capacity).\ + filter(and_(Dp.generation_subtype == 'wind_onshore',\ + Dp.electrical_capacity < 7600 ,\ + Dp.start_up_date > '1998-01-01 00:00:00',\ + Dp.start_up_date < '2018-01-01 00:00:00')) + + Gens = [(electrical_capacity) for electrical_capacity in query.all()] + generators = [] + for i in range(0, len(Gens)): + generators.append(float(Gens[i][0])) + generators.sort() + + return generators + + +def collect_energymap_data(): + """ + Collects data of wind turbines available in the energy map table. + + Parameters + ---------- + + Returns + ------- + windgenerator : DataFrame of all wind generators in energy_map + """ + meta.reflect(bind=conn,schema='app_renpassgis',only=['renewable_energy_map_1']) + Base = automap_base(metadata=meta) + Base.prepare() + + SQL_data = Base.classes.renewable_energy_map_1 + + plants = session.query(SQL_data).\ + filter(and_(SQL_data.energietraeger == 'Wind Land',or_\ + (SQL_data.stillgelegt!='Ja',\ + SQL_data.stillgelegt == None))).all() + + windgenerator = [[],[],[],[],[]] + + # index 0 : power in kW + # index 1 : manufacturer of the windgenerator + # index 2 : type of the generator + # index 3 : hub height in meter + # index 4 : rotor diameter in meter + + # power of each generator, but it's sorted by size + sorted_windgenerator = [] + + for plant in plants: + sorted_windgenerator.append(float(plant.installierte_leistung)) + + windgenerator[0].append(float(plant.installierte_leistung)) + windgenerator[1].append(plant.windanlagenhersteller) + windgenerator[2].append(plant.anlagentyp) + windgenerator[3].append(plant.nabenhoehe) + windgenerator[4].append(plant.rotordurchmesser) + + sorted_windgenerator.sort() + windgenerator[1] = C_choice_of_windgenerator.upper_string(windgenerator[1]) + windgenerator[2] = C_choice_of_windgenerator.upper_string(windgenerator[2]) + windgenerator = pd.DataFrame(windgenerator).transpose() + columns = ['capacity', 'manufacturer', 'type', 'h_hub', 'd_rotor'] + windgenerator.columns = columns + return windgenerator + + +def df_to_renewable_feedin(df, weather_year, weather_scenario_id): + print('Creating table ego_renewable_feedin..') + Base = declarative_base() + + class Ego_renewable_feedin(Base): + __tablename__ = 'ego_renewable_feedin' + __table_args__ = {'schema': 'model_draft'} + + weather_scenario_id = Column(Integer(), primary_key=True) + w_id = Column(Integer(), primary_key=True) + source = Column(Text(), primary_key=True) + weather_year = Column(Integer(), primary_key=True) + power_class = Column(Integer(), primary_key=True) + feedin = Column(ARRAY(Float)) + + conn.execute(text("DROP TABLE IF EXISTS model_draft.ego_renewable_feedin CASCADE")) + +# try: +# Ego_renewable_feedin.__table__.drop(conn) +# except: +# pass + + Base.metadata.create_all(conn) + + print('Importing feedin to database..') + + # prepare DataFrames + session = db.session + #Points = db.Base.classes.ego_weather_measurement_point + mappings = [] + + # Insert Data to DB + for k in df.columns: + weather_scenario_id = weather_scenario_id + w_id = k[0] + source = k[1] + weather_year = weather_year + power_class = k[2] + feedin = df[k].values.tolist() + info = Ego_renewable_feedin(w_id=w_id, + weather_scenario_id=weather_scenario_id, + source=source, + weather_year=weather_year, + power_class=power_class, + feedin=feedin) + mappings.append(info) + + session.bulk_save_objects(mappings) + session.commit() + + print('Done!') + + +def get_power_classes(capacity): + """ + Gets power classes. + + Parameters + ---------- + capacity : list of capacities of all turbines used in the eGo database + + Returns + ------- + power_classes : list with thresholds for power classes + """ + max_power = max(capacity) + power_classes = [max_power] + + x = 0 + + # Variable to guarantee to use the right parts in the loop + new_class = True + + # Counter for number of windgenerators + i = 0 + + while(i < len(capacity)): + if ((new_class == True) and (capacity[i] < power_classes[x])): + power_classes.insert(x, round(capacity[i], -2)) + new_class = False + + elif(capacity[i] < power_classes[x+1]): + t=power_classes.pop(x) + power_classes.insert(x, round(capacity[i], -2)) + + percent_of_plants_in_classes = C_choice_of_windgenerator.percent(capacity, power_classes) + + if ((percent_of_plants_in_classes[x] >= 0.1)): + if((round(capacity[i], -2)) == (round(capacity[i+1], -2))): + new_class = False + i+=1 + else: + x+=1 + new_class = True + i+=1 + else: + i+=1 + + # change the last boarder, so that only the last boarder have a percentage + # under 0.1 + i = 0 + while(i < len(power_classes)): + if((percent_of_plants_in_classes[len(power_classes)-1] <= 0.1) + and + (percent_of_plants_in_classes[len(power_classes)-2] <= 0.1)): + power_classes.pop(len(power_classes)-2) + percent_of_plants_in_classes =\ + C_choice_of_windgenerator.percent(capacity, power_classes) + else: + break + + i+=1 + + return power_classes + +def get_plant_per_class(windgenerator, power_classes): + """ + Calculates the most used plant per power class. If a turbine is not available + in windlib, the second, third,.. most used turbine is taken until one is + available in windlib. + + Parameters + ---------- + windgenerator : DataFrame of all wind generators in energy_map + power_classes : list with threshold for power classes + + Returns + ------- + selected_plants : DataFrame with most used turbines + """ + + windgenerator = windgenerator.sort_values(by='capacity') + plants_per_classes = [] + lower = 0 + for upper in power_classes: + plants_per_classes.append( + windgenerator[(windgenerator['capacity'] >= lower) + & (windgenerator['capacity'] < upper)]) + lower = upper + + numbers = [] + for element in plants_per_classes: + numbers.append(element.groupby(element.columns.tolist(), as_index=False). + size().reset_index().rename(columns={0:'count'})) + + selected_plants = [] + for element in numbers: + selected_plants.append(element.sort_values(by='count', ascending=False).iloc[0]) + + selected_plants = pd.DataFrame(selected_plants) + selected_plants['power_class'] = power_classes + + not_in_windlib = turbine_in_windlib(selected_plants) + position = 1 + + while not_in_windlib.empty == False: + for index, row in not_in_windlib.iterrows(): + numbers_index = power_classes.index(row['power_class']) + power_class = selected_plants.ix[index]['power_class'] + selected_plants.ix[index] = numbers[numbers_index].\ + sort_values(by='count', ascending=False).iloc[position] + selected_plants['power_class'][index] = power_class + + not_in_windlib = turbine_in_windlib(selected_plants) + position += 1 + + selected_plants['type'] = selected_plants['manufacturer']+' '+\ + selected_plants['type']+' '+\ + selected_plants['capacity'].map(int).map(str) + + return selected_plants + +def power_class_to_db(power_classes, selected_plants): + + print('Creating table power_class..') + Base = declarative_base() + + class Ego_power_class(Base): + __tablename__ = 'ego_power_class' + __table_args__ = {'schema': 'model_draft'} + + power_class_id = Column(Integer(), primary_key=True) + lower_limit = Column(Float()) + upper_limit = Column(Float()) + wea = Column(Text()) + + + conn.execute(text("DROP TABLE IF EXISTS model_draft.ego_power_class CASCADE")) + + Base.metadata.create_all(conn) + + print('Importing power classes to database..') + + # prepare DataFrames + session = db.session + #Points = db.Base.classes.ego_weather_measurement_point + mappings = [] + lower = 0 + power_class_id = 1 + # Insert Data to DB + for upper in power_classes: + wea = selected_plants['type'][selected_plants['power_class'] == upper].item() + if power_class_id == len(power_classes): + info = Ego_power_class(power_class_id=power_class_id, + lower_limit=lower/1000, + upper_limit=1000000000, + wea=wea) + mappings.append(info) + else: + info = Ego_power_class(power_class_id=power_class_id, + lower_limit=lower/1000, + upper_limit=upper/1000, + wea=wea) + mappings.append(info) + + lower = upper + power_class_id += 1 + + session.bulk_save_objects(mappings) + session.commit() + + print('Done!') + +def turbine_in_windlib(plants): + """ + Checks if a given dataframe of turbines is available in the windlib cp_values + file. Deletes all turbines from the dataframe which are available and returns + the ones that are not. + + Parameters + ---------- + plants : DataFrame of turbines + + Returns + ------- + plants : modified dataframes without turbines available in windlib + """ + + resource_package = 'windpowerlib' + resource_path = '/'.join(('data', 'cp_values.csv')) + + template = pkg_resources.resource_stream(resource_package, resource_path) + cp_generators = pd.DataFrame.from_csv(template) + for index, row in plants.iterrows(): + for name in cp_generators['rli_anlagen_id']: + if row['type'] in name: + split = re.split('(\d+)', name) + if int(row[0]) == int(split[3]): + plants = plants.drop(row.name) + break + + return plants + +def wind_dict(row): + """ Writes section data of a configuration file to a dictionary + + Parameters + ---------- + cfg : configparser.ConfigParser + Used for configuration file parser language. + section : str + Section in configuration file. + + Returns + ------- + dict + Dictionary containing section data. + """ + + return {'d_rotor': float(row['d_rotor']), + 'h_hub': float(row['h_hub']), + 'wind_conv_type': row['type']} + + +def main(): + windgenerator = collect_energymap_data() + capacity = collect_ego_turbines() + power_classes = get_power_classes(capacity) + selected_plants = get_plant_per_class(windgenerator, power_classes) + power_class_to_db(power_classes, selected_plants) + + cfg = db.readcfg(config) + temp = {} + powerplants = {} + powerplants['solar'] = plants.Photovoltaic( + **{k: asnumber(v) for k, v in cfg.items('Photovoltaic')}) + + powerplants['wind_offshore'] = plants.WindPowerPlant( + **{k: asnumber(v) for k, v in cfg.items('WindTurbineOffshore')}) + + print('Calculating feedins...') + + count = 0 + for coastdat_id, type_of_generation, geom in points: + + count += 1 + print(count) + try: + weather = coastdat.get_weather(conn, geom, weather_year) + except IndexError: + print('Geometry cannot be handled: %s, %s' % (geom.x, geom.y)) + continue + + if type_of_generation == 'wind_offshore': + feedin = correction_offshore * powerplants[type_of_generation].\ + feedin(weather=weather, installed_capacity=1) + power_class = 0 + temp[(coastdat_id, type_of_generation, power_class)] = feedin.values + + elif type_of_generation == 'wind_onshore': + power_class = 1 + for index, row in selected_plants.iterrows(): + plant = wind_dict(row) + feedin = plants.WindPowerPlant(**plant).\ + feedin(weather=weather, installed_capacity=1) + temp[(coastdat_id, type_of_generation, power_class)] = feedin.values + power_class += 1 + + elif type_of_generation == 'solar': + feedin = correction_solar * powerplants[type_of_generation].\ + feedin(weather=weather, peak_power=1) + power_class = 0 + temp[(coastdat_id, type_of_generation, power_class)] = feedin.values + else: + continue + + #temp[(coastdat_id, type_of_generation)] = feedin.values + + df = pd.DataFrame(temp) + df_to_renewable_feedin(df, weather_year, weather_scenario_id) + print('Done!') + + +if __name__ == '__main__': + main() + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/preprocessing/sql_snippets/ego_simple-feedin_per_scenario.sql b/preprocessing/sql_snippets/ego_simple-feedin_per_scenario.sql index e12ff758..2a90d653 100644 --- a/preprocessing/sql_snippets/ego_simple-feedin_per_scenario.sql +++ b/preprocessing/sql_snippets/ego_simple-feedin_per_scenario.sql @@ -219,7 +219,7 @@ FROM climate.cosmoclmgrid AS coastdat, WHERE ST_Intersects(neighbour.geom, coastdat.geom) ON CONFLICT DO NOTHING; --- set wea_type +set wea_type UPDATE model_draft.ego_weather_measurement_point SET wea_type = wea FROM (SELECT gid, wea_manufacturer||' '||wea_type AS wea @@ -236,6 +236,40 @@ FROM (SELECT gid, wea_manufacturer||' '||wea_type AS wea ) a WHERE coastdat_id = gid AND type_of_generation = 'wind_onshore'; +-- +-- UPDATE model_draft.ego_weather_measurement_point +-- SET wea_type = wea +-- FROM (SELECT gid, wea_manufacturer||' '||wea_type AS wea +-- FROM +-- (SELECT gid, wea_manufacturer, wea_type, COUNT(*) as cnt, +-- ROW_NUMBER() OVER (PARTITION BY gid ORDER BY COUNT(*) DESC) AS rnk +-- FROM climate.cosmoclmgrid a, model_draft.bnetza_eeg_anlagenstammdaten_wind_classification b +-- WHERE ST_Intersects(a.geom, ST_Transform(b.geom, 4326)) +-- AND wea_type <> 'na' +-- AND seelage IS NOT NULL +-- GROUP BY gid, wea_manufacturer, wea_type +-- ) as tg +-- WHERE rnk = 1 +-- ) a +-- WHERE coastdat_id = gid +-- AND type_of_generation = 'wind_offshore'; + +UPDATE model_draft.ego_weather_measurement_point +SET wea_type = wea +FROM (SELECT gid, windanlagenhersteller||' '||anlagentyp AS wea + FROM + (SELECT a.gid, windanlagenhersteller, anlagentyp, COUNT(*) as cnt, + ROW_NUMBER() OVER (PARTITION BY a.gid ORDER BY COUNT(*) DESC) AS rnk + FROM climate.cosmoclmgrid a, app_renpassgis.renewable_energy_map_1 b + WHERE ST_Intersects(a.geom, ST_Transform(b.geom, 4326)) + AND energietraeger = 'Wind Land' + AND (stillgelegt <> 'Ja' OR stillgelegt IS NULL) + GROUP BY a.gid, windanlagenhersteller, anlagentyp + ) as tg + WHERE rnk = 1 + ) a +WHERE coastdat_id = gid +AND type_of_generation = 'wind_onshore'; UPDATE model_draft.ego_weather_measurement_point SET wea_type = wea @@ -243,7 +277,7 @@ FROM (SELECT gid, wea_manufacturer||' '||wea_type AS wea FROM (SELECT gid, wea_manufacturer, wea_type, COUNT(*) as cnt, ROW_NUMBER() OVER (PARTITION BY gid ORDER BY COUNT(*) DESC) AS rnk - FROM climate.cosmoclmgrid a, model_draft.bnetza_eeg_anlagenstammdaten_wind_classification b + FROM climate.cosmoclmgrid a, app_renpassgis.renewable_energy_map_1 b WHERE ST_Intersects(a.geom, ST_Transform(b.geom, 4326)) AND wea_type <> 'na' AND seelage IS NOT NULL From e133c34fd5a7d9fbb34b78b19d37b6e202038006 Mon Sep 17 00:00:00 2001 From: MarlonSchlemminger Date: Fri, 23 Mar 2018 13:01:17 +0100 Subject: [PATCH 3/9] change in power_class --- .../renpass_gis/simple_feedin/wind_onshore.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/preprocessing/python_scripts/renpass_gis/simple_feedin/wind_onshore.py b/preprocessing/python_scripts/renpass_gis/simple_feedin/wind_onshore.py index a29c63c3..bd50d1c4 100644 --- a/preprocessing/python_scripts/renpass_gis/simple_feedin/wind_onshore.py +++ b/preprocessing/python_scripts/renpass_gis/simple_feedin/wind_onshore.py @@ -355,6 +355,8 @@ class Ego_power_class(Base): lower_limit = Column(Float()) upper_limit = Column(Float()) wea = Column(Text()) + h_hub = Column(Float()) + d_rotor = Column(Float()) conn.execute(text("DROP TABLE IF EXISTS model_draft.ego_power_class CASCADE")) @@ -372,17 +374,23 @@ class Ego_power_class(Base): # Insert Data to DB for upper in power_classes: wea = selected_plants['type'][selected_plants['power_class'] == upper].item() + h_hub = selected_plants['h_hub'][selected_plants['power_class'] == upper].item() + d_rotor = selected_plants['d_rotor'][selected_plants['power_class'] == upper].item() if power_class_id == len(power_classes): info = Ego_power_class(power_class_id=power_class_id, lower_limit=lower/1000, upper_limit=1000000000, - wea=wea) + wea=wea, + h_hub=h_hub, + d_rotor=d_rotor) mappings.append(info) else: info = Ego_power_class(power_class_id=power_class_id, lower_limit=lower/1000, upper_limit=upper/1000, - wea=wea) + wea=wea, + h_hub=h_hub, + d_rotor=d_rotor) mappings.append(info) lower = upper From 1afeaef92e51a5c3d931efd03f562f0b9c020618 Mon Sep 17 00:00:00 2001 From: MarlonSchlemminger Date: Mon, 26 Mar 2018 15:16:37 +0200 Subject: [PATCH 4/9] new simplefeedi and minor changes --- .../ego_dp_powerflow_timeseries_generator.sql | 3 + .../simple_feedin/simple_feedin.py | 617 +++++++++++++----- .../renpass_gis/simple_feedin/wind_onshore.py | 29 +- .../ego_simple-feedin_per_scenario.sql | 127 +--- 4 files changed, 469 insertions(+), 307 deletions(-) diff --git a/dataprocessing/sql_snippets/ego_dp_powerflow_timeseries_generator.sql b/dataprocessing/sql_snippets/ego_dp_powerflow_timeseries_generator.sql index 3c2a6c35..f5439e27 100644 --- a/dataprocessing/sql_snippets/ego_dp_powerflow_timeseries_generator.sql +++ b/dataprocessing/sql_snippets/ego_dp_powerflow_timeseries_generator.sql @@ -668,6 +668,7 @@ FROM feedin.feedin FROM model_draft.ego_renewable_feedin AS feedin + WHERE power_class IN (0, 4) ) AS B, (SELECT generators.generator_id, @@ -768,6 +769,7 @@ FROM feedin.feedin FROM model_draft.ego_renewable_feedin AS feedin + WHERE power_class IN (0, 4) ) AS B, (SELECT generators.generator_id, @@ -868,6 +870,7 @@ FROM feedin.feedin FROM model_draft.ego_renewable_feedin AS feedin + WHERE power_class IN (0, 4) ) AS B, (SELECT generators.generator_id, diff --git a/preprocessing/python_scripts/renpass_gis/simple_feedin/simple_feedin.py b/preprocessing/python_scripts/renpass_gis/simple_feedin/simple_feedin.py index e4549da8..83baf838 100644 --- a/preprocessing/python_scripts/renpass_gis/simple_feedin/simple_feedin.py +++ b/preprocessing/python_scripts/renpass_gis/simple_feedin/simple_feedin.py @@ -1,68 +1,33 @@ -#!/bin/python # -*- coding: utf-8 -*- """ -Module to calculate solar, windonshore and windoffshore feedins based on -feedinlib. (https://github.com/oemof/feedinlib) Exports the data to a CSV-file. - -Attributes ----------- -points : list - List of data tuples. -filename : str - File path for results CSV-file. -config : str - File path of configuration file. -weather_year: int - Year of CoastDat2 data. -conn : sqlalchemy.engine.Engine - Database containing CoastDat2 schema. -correction_offshore : float - Correction factor for windoffshore feedin. -correction_solar : float - Correction factor for solar feedin. - -Notes ------ - db.Points has the following form. Type can be either windonshore, - windoffshore or solar. - - [(, , ), - (, ...)] - - Introduction of correction factors based on Wiese 2015, p.83 - http://www.reiner-lemoine-stiftung.de/pdf/dissertationen/Dissertation_Frauke_Wiese.pdf - -TODO ----- - How to handle different timezones? - Add scenario case -""" - +Created on Wed Mar 14 14:30:54 2018 -__copyright__ = "ZNES" -__license__ = "GNU Affero General Public License Version 3 (AGPL-3.0)" -__url__ = "https://github.com/openego/data_processing/blob/master/LICENSE" -__author__ = "s3pp, MarlonSchlemminger" +__author__ = "MarlonSchlemminger, s3pp" +""" +import pandas as pd +import db +from sqlalchemy import (MetaData, and_, or_, Column, Text, text, Integer, Float, ARRAY) +from sqlalchemy.ext.automap import automap_base +from operator import itemgetter +from functions import C_choice_of_windgenerator +import pkg_resources +import re from feedinlib import powerplants as plants from oemof.db import coastdat -import db -import pandas as pd -from sqlalchemy import (Column, Text, Integer, Float, ARRAY) from sqlalchemy.ext.declarative import declarative_base -from sqlalchemy import text -import re points = db.Points conn = db.conn -scenario_name = 'Status Quo' -weather_year = 2011 -weather_scenario_id = 1 -filename = '2017-08-21_simple_feedin_ego-100-wj2011_all.csv' +session = db.session +meta = MetaData() + config = 'config.ini' correction_offshore = 0.83 correction_solar = 0.8 - +correction_onshore = 0.6 +weather_year = 2011 +weather_scenario_id = 1 def asnumber(x): """ Tries to convert a string to a numeric format @@ -83,66 +48,143 @@ def asnumber(x): return float(x) except ValueError: return x - -def compatibility_windlib(turbines, default_onshore, default_offshore): - - for index, row in turbines.iterrows(): - if row['wea'].split(' ', 1)[0] == 'Adwen/Areva': - if row['type_of_generation'] == 'wind_offshore': - turbines.iloc[index, 4] = default_offshore - elif row['type_of_generation'] == 'wind_onshore': - turbines.iloc[index, 4] = default_onshore - - elif row['wea'].split(' ', 1)[0] == 'Enercon': - turbines.iloc[index, 4] = turbines.iloc[index, 1].replace('-', ' ') - turbines.iloc[index, 4] = turbines.iloc[index, 4].replace('/', ' ') - turbines.iloc[index, 4] = turbines.iloc[index, 4].replace('50', '00') - - elif row['wea'].split(' ', 1)[0] == 'Eno': - turbines.iloc[index, 4] = turbines.iloc[index, 1][4:9] - turbines.iloc[index, 4] = turbines.iloc[index, 4][:3] + ' ' +\ - turbines.iloc[index, 4][3:] - - elif row['wea'].split(' ', 1)[0] == 'GE': - if row['type_of_generation'] == 'wind_offshore': - turbines.iloc[index, 4] = default_offshore - elif row['type_of_generation'] == 'wind_onshore': - turbines.iloc[index, 4] = default_onshore - - elif row['wea'].split(' ', 1)[0] == 'Nordex': - turbines.iloc[index, 4] = turbines.iloc[index, 1].replace('AW', 'S') - turbines.iloc[index, 4] = turbines.iloc[index, 4][:8] + ' ' +\ - turbines.iloc[index, 4][8:] - turbines.iloc[index, 4] = turbines.iloc[index, 4].replace('/', ' ') - - elif row['wea'].split(' ', 1)[0] == 'Senvion/REpower': - turbines.iloc[index, 4] = turbines.iloc[index, 1].replace('Senvion/REpower', 'REPOWER') - turbines.iloc[index, 4] = turbines.iloc[index, 4].replace('/', ' ') - split = re.split('(\d+)', turbines.iloc[index, 4]) - if split[0] == 'REPOWER MM': - turbines.iloc[index, 4] = split[0]+' '+split[1]+split[2]+split[3] - elif split[0] == 'REPOWER S': - turbines.iloc[index, 4] = 'REPOWER '+str(float(split[3])/1000)+\ - ' M'+split[1] - - elif row['wea'].split(' ', 1)[0] == 'Siemens': - split = re.split('(\d+)', turbines.iloc[index, 1]) - turbines.iloc[index, 4] = split[0]+' '+str(float(split[3])/1000)+\ - ' '+split[1] - - elif row['wea'].split(' ', 1)[0] == 'Vensys': - split = re.split('(\d+)', turbines.iloc[index, 1]) - turbines.iloc[index, 4] = 'Vensys '+split[1] - - elif row['wea'].split(' ', 1)[0] == 'Vestas': - split = re.split('(\d+)', turbines.iloc[index, 1]) - turbines.iloc[index, 4] = split[0]+' '+split[1]+' '+split[3] + + +def collect_bnetza_data(): + """ + Collects data of wind turbines available in the BNetzA Anlagenstammdaten. - turbines['wea_windlib'] = turbines['wea_windlib'].str.upper() - - return turbines + Parameters + ---------- + + Returns + ------- + plants : DataFrame of all wind generators in BNetzA + """ + meta.reflect(bind=conn, schema='model_draft', + only=['bnetza_eeg_anlagenstammdaten_wind_classification']) + Base = automap_base(metadata=meta) + Base.prepare() + + Bnetza = Base.classes.bnetza_eeg_anlagenstammdaten_wind_classification + + query = session.query(Bnetza.installierte_leistung, + Bnetza.wea_manufacturer, + Bnetza.wea_type, + Bnetza.nabenhöhe, + Bnetza.rotordurchmesser).filter(Bnetza.seelage == None) + plants = [(installierte_leistung, + wea_manufacturer, + wea_type, + nabenhöhe, + rotordurchmesser) + for installierte_leistung, wea_manufacturer, wea_type, nabenhöhe, rotordurchmesser + in query.all()] + plants.sort(key=itemgetter(0)) + columns = ['capacity', 'manufacturer', 'type', 'hub', 'rotor'] + plants = pd.DataFrame(plants, columns=columns) + + return plants + + +def collect_ego_turbines(): + """ + Collects data of wind turbines used in the eGo database. + + Parameters + ---------- + + Returns + ------- + generators : capacity of turbines used in the eGo database + """ + meta.reflect(bind=conn, schema='model_draft', + only=['ego_dp_supply_res_powerplant']) + Base = automap_base(metadata=meta) + Base.prepare() + + Dp = Base.classes.ego_dp_supply_res_powerplant + + query = session.query(Dp.electrical_capacity).\ + filter(and_(Dp.generation_subtype == 'wind_onshore',\ + Dp.electrical_capacity < 7600 ,\ + Dp.start_up_date > '1998-01-01 00:00:00',\ + Dp.start_up_date < '2018-01-01 00:00:00')) + + Gens = [(electrical_capacity) for electrical_capacity in query.all()] + generators = [] + for i in range(0, len(Gens)): + generators.append(float(Gens[i][0])) + generators.sort() + + return generators + + +def collect_energymap_data(): + """ + Collects data of wind turbines available in the energy map table. + + Parameters + ---------- + + Returns + ------- + windgenerator : DataFrame of all wind generators in energy_map + """ + meta.reflect(bind=conn,schema='app_renpassgis',only=['renewable_energy_map_1']) + Base = automap_base(metadata=meta) + Base.prepare() + + SQL_data = Base.classes.renewable_energy_map_1 + + plants = session.query(SQL_data).\ + filter(and_(SQL_data.energietraeger == 'Wind Land',or_\ + (SQL_data.stillgelegt!='Ja',\ + SQL_data.stillgelegt == None))).all() + + windgenerator = [[],[],[],[],[]] + + # index 0 : power in kW + # index 1 : manufacturer of the windgenerator + # index 2 : type of the generator + # index 3 : hub height in meter + # index 4 : rotor diameter in meter + + # power of each generator, but it's sorted by size + sorted_windgenerator = [] + + for plant in plants: + sorted_windgenerator.append(float(plant.installierte_leistung)) + windgenerator[0].append(float(plant.installierte_leistung)) + windgenerator[1].append(plant.windanlagenhersteller) + windgenerator[2].append(plant.anlagentyp) + windgenerator[3].append(plant.nabenhoehe) + windgenerator[4].append(plant.rotordurchmesser) + + sorted_windgenerator.sort() + windgenerator[1] = C_choice_of_windgenerator.upper_string(windgenerator[1]) + windgenerator[2] = C_choice_of_windgenerator.upper_string(windgenerator[2]) + windgenerator = pd.DataFrame(windgenerator).transpose() + columns = ['capacity', 'manufacturer', 'type', 'h_hub', 'd_rotor'] + windgenerator.columns = columns + return windgenerator + + def df_to_renewable_feedin(df, weather_year, weather_scenario_id): + """ + Transfers the calculated feedin timeseries into the database table + ego_renewable_feedin. + + Parameters + df : DataFrame with feedin timeseries + weather_year : weather year of weather data + weather_scenario_id : weather scenario id + ---------- + + Returns + ------- + """ print('Creating table ego_renewable_feedin..') Base = declarative_base() @@ -154,6 +196,7 @@ class Ego_renewable_feedin(Base): w_id = Column(Integer(), primary_key=True) source = Column(Text(), primary_key=True) weather_year = Column(Integer(), primary_key=True) + power_class = Column(Integer(), primary_key=True) feedin = Column(ARRAY(Float)) conn.execute(text("DROP TABLE IF EXISTS model_draft.ego_renewable_feedin CASCADE")) @@ -178,11 +221,13 @@ class Ego_renewable_feedin(Base): w_id = k[0] source = k[1] weather_year = weather_year + power_class = k[2] feedin = df[k].values.tolist() info = Ego_renewable_feedin(w_id=w_id, weather_scenario_id=weather_scenario_id, source=source, weather_year=weather_year, + power_class=power_class, feedin=feedin) mappings.append(info) @@ -191,24 +236,227 @@ class Ego_renewable_feedin(Base): print('Done!') -def to_dictionary(cfg, section): - """ Writes section data of a configuration file to a dictionary + +def get_power_classes(capacity): + """ + Gets power classes. + Parameters ---------- - cfg : configparser.ConfigParser - Used for configuration file parser language. - section : str - Section in configuration file. + capacity : list of capacities of all turbines used in the eGo database + Returns ------- - dict - Dictionary containing section data. + power_classes : list with thresholds for power classes """ + max_power = max(capacity) + power_classes = [max_power] + + x = 0 + + # Variable to guarantee to use the right parts in the loop + new_class = True + + # Counter for number of windgenerators + i = 0 + + while(i < len(capacity)): + if ((new_class == True) and (capacity[i] < power_classes[x])): + power_classes.insert(x, round(capacity[i], -2)) + new_class = False + + elif(capacity[i] < power_classes[x+1]): + t=power_classes.pop(x) + power_classes.insert(x, round(capacity[i], -2)) + + percent_of_plants_in_classes = C_choice_of_windgenerator.percent(capacity, power_classes) + + if ((percent_of_plants_in_classes[x] >= 0.1)): + if((round(capacity[i], -2)) == (round(capacity[i+1], -2))): + new_class = False + i+=1 + else: + x+=1 + new_class = True + i+=1 + else: + i+=1 + + # change the last boarder, so that only the last boarder have a percentage + # under 0.1 + i = 0 + while(i < len(power_classes)): + if((percent_of_plants_in_classes[len(power_classes)-1] <= 0.1) + and + (percent_of_plants_in_classes[len(power_classes)-2] <= 0.1)): + power_classes.pop(len(power_classes)-2) + percent_of_plants_in_classes =\ + C_choice_of_windgenerator.percent(capacity, power_classes) + else: + break + + i+=1 - return {k: asnumber(v) for k, v in cfg.items(section)} + return power_classes +def get_plant_per_class(windgenerator, power_classes): + """ + Calculates the most used plant per power class. If a turbine is not available + in windlib, the second, third,.. most used turbine is taken until one is + available in windlib. + + Parameters + ---------- + windgenerator : DataFrame of all wind generators in energy_map + power_classes : list with threshold for power classes + + Returns + ------- + selected_plants : DataFrame with most used turbines + """ + + windgenerator = windgenerator.sort_values(by='capacity') + plants_per_classes = [] + lower = 0 + for upper in power_classes: + plants_per_classes.append( + windgenerator[(windgenerator['capacity'] >= lower) + & (windgenerator['capacity'] < upper)]) + lower = upper + + numbers = [] + for element in plants_per_classes: + numbers.append(element.groupby(element.columns.tolist(), as_index=False). + size().reset_index().rename(columns={0:'count'})) + + selected_plants = [] + for element in numbers: + selected_plants.append(element.sort_values(by='count', ascending=False).iloc[0]) + + selected_plants = pd.DataFrame(selected_plants) + selected_plants['power_class'] = power_classes + + not_in_windlib = turbine_in_windlib(selected_plants) + position = 1 + + while not_in_windlib.empty == False: + for index, row in not_in_windlib.iterrows(): + numbers_index = power_classes.index(row['power_class']) + power_class = selected_plants.ix[index]['power_class'] + selected_plants.ix[index] = numbers[numbers_index].\ + sort_values(by='count', ascending=False).iloc[position] + selected_plants['power_class'][index] = power_class + + not_in_windlib = turbine_in_windlib(selected_plants) + position += 1 + + selected_plants['type'] = selected_plants['manufacturer']+' '+\ + selected_plants['type']+' '+\ + selected_plants['capacity'].map(int).map(str) + + return selected_plants + +def power_class_to_db(power_classes, selected_plants): + """ + Inserts the power classes used for the timeseries calculation into the + database table ego_power_class + + Parameters + ---------- + + Returns + ------- + windgenerator : DataFrame of all wind generators in energy_map + """ + + print('Creating table power_class..') + Base = declarative_base() + + class Ego_power_class(Base): + __tablename__ = 'ego_power_class' + __table_args__ = {'schema': 'model_draft'} + + power_class_id = Column(Integer(), primary_key=True) + lower_limit = Column(Float()) + upper_limit = Column(Float()) + wea = Column(Text()) + h_hub = Column(Float()) + d_rotor = Column(Float()) -def wind_dict(wea_type, type_of_generation, turbines): + + conn.execute(text("DROP TABLE IF EXISTS model_draft.ego_power_class CASCADE")) + + Base.metadata.create_all(conn) + + print('Importing power classes to database..') + + # prepare DataFrames + session = db.session + #Points = db.Base.classes.ego_weather_measurement_point + mappings = [] + lower = 0 + power_class_id = 1 + # Insert Data to DB + for upper in power_classes: + wea = selected_plants['type'][selected_plants['power_class'] == upper].item() + h_hub = selected_plants['h_hub'][selected_plants['power_class'] == upper].item() + d_rotor = selected_plants['d_rotor'][selected_plants['power_class'] == upper].item() + if power_class_id == len(power_classes): + info = Ego_power_class(power_class_id=power_class_id, + lower_limit=lower/1000, + upper_limit=1000000000, + wea=wea, + h_hub=h_hub, + d_rotor=d_rotor) + mappings.append(info) + else: + info = Ego_power_class(power_class_id=power_class_id, + lower_limit=lower/1000, + upper_limit=upper/1000, + wea=wea, + h_hub=h_hub, + d_rotor=d_rotor) + mappings.append(info) + + lower = upper + power_class_id += 1 + + session.bulk_save_objects(mappings) + session.commit() + + print('Done!') + +def turbine_in_windlib(plants): + """ + Checks if a given dataframe of turbines is available in the windlib cp_values + file. Deletes all turbines from the dataframe which are available and returns + the ones that are not. + + Parameters + ---------- + plants : DataFrame of turbines + + Returns + ------- + plants : modified dataframes without turbines available in windlib + """ + + resource_package = 'windpowerlib' + resource_path = '/'.join(('data', 'cp_values.csv')) + + template = pkg_resources.resource_stream(resource_package, resource_path) + cp_generators = pd.DataFrame.from_csv(template) + for index, row in plants.iterrows(): + for name in cp_generators['rli_anlagen_id']: + if row['type'] in name: + split = re.split('(\d+)', name) + if int(row[0]) == int(split[3]): + plants = plants.drop(row.name) + break + + return plants + +def wind_dict(row): """ Writes section data of a configuration file to a dictionary Parameters @@ -224,46 +472,31 @@ def wind_dict(wea_type, type_of_generation, turbines): Dictionary containing section data. """ - return {'d_rotor': turbines[(turbines['wea'] == wea_type) & - (turbines['type_of_generation'] == - type_of_generation)].d_rotor.item(), - 'h_hub': turbines[(turbines['wea'] == wea_type) &\ - (turbines['type_of_generation'] ==\ - type_of_generation)].h_hub.item(), - 'wind_conv_type': turbines[(turbines['wea'] == wea_type) &\ - (turbines['type_of_generation'] ==\ - type_of_generation)].wea_windlib.item()} - + return {'d_rotor': float(row['d_rotor']), + 'h_hub': float(row['h_hub']), + 'wind_conv_type': row['type']} + + def main(): - """ - """ - - global points + windgenerator = collect_energymap_data() + capacity = collect_ego_turbines() + power_classes = get_power_classes(capacity) + selected_plants = get_plant_per_class(windgenerator, power_classes) + power_class_to_db(power_classes, selected_plants) cfg = db.readcfg(config) temp = {} powerplants = {} - columns = ['type_of_generation', 'wea', 'd_rotor', 'h_hub'] - default_offshore = 'SIEMENS SWT 3.6 120' - default_onshore = 'ENERCON E 70 2000' - turbines = pd.DataFrame(db.Turbines, columns=columns) - turbines['wea_windlib'] = '' - # instatiate feedinlib models in dictionary - powerplants['solar'] = plants.Photovoltaic( - **to_dictionary(cfg=cfg, section='Photovoltaic')) - + **{k: asnumber(v) for k, v in cfg.items('Photovoltaic')}) + + powerplants['wind_offshore'] = plants.WindPowerPlant( + **{k: asnumber(v) for k, v in cfg.items('WindTurbineOffshore')}) + print('Calculating feedins...') - #toDo - # calculate feedins applying correction factors - turbines = compatibility_windlib(turbines, default_onshore, default_offshore) - count = 0 - default = 0 - specific = 0 - for coastdat_id, type_of_generation, wea_type, geom in points: + + for coastdat_id, type_of_generation, geom in points: - count += 1 - print(count) try: weather = coastdat.get_weather(conn, geom, weather_year) except IndexError: @@ -271,49 +504,71 @@ def main(): continue if type_of_generation == 'wind_offshore': - plant = wind_dict(wea_type, type_of_generation, turbines) - try: - feedin = correction_offshore * plants.WindPowerPlant(**plant).\ - feedin(weather=weather, installed_capacity=1) - specific += 1 - except: - print(wea_type+' not found.') - plant['wind_conv_type'] = default_offshore - feedin = correction_offshore * plants.WindPowerPlant(**plant).\ - feedin(weather=weather, installed_capacity=1) - default += 1 + feedin = correction_offshore * powerplants[type_of_generation].\ + feedin(weather=weather, installed_capacity=1) + power_class = 0 + temp[(coastdat_id, type_of_generation, power_class)] = feedin.values elif type_of_generation == 'wind_onshore': - plant = wind_dict(wea_type, type_of_generation, turbines) - try: - feedin = plants.WindPowerPlant(**plant).\ + power_class = 1 + for index, row in selected_plants.iterrows(): + plant = wind_dict(row) + feedin = correction_onshore * plants.WindPowerPlant(**plant).\ feedin(weather=weather, installed_capacity=1) - specific += 1 - except: - print(wea_type+' not found.') - plant['wind_conv_type'] = default_onshore - feedin = plants.WindPowerPlant(**plant).\ - feedin(weather=weather, installed_capacity=1) - default += 1 + temp[(coastdat_id, type_of_generation, power_class)] = feedin.values + power_class += 1 elif type_of_generation == 'solar': feedin = correction_solar * powerplants[type_of_generation].\ feedin(weather=weather, peak_power=1) + power_class = 0 + temp[(coastdat_id, type_of_generation, power_class)] = feedin.values else: continue - temp[(coastdat_id, type_of_generation)] = feedin.values - - #print('Writing results to %s.' % filename) - # write results to file - print('specific: ') - print(specific) - print('default: ') - print(default) + #temp[(coastdat_id, type_of_generation)] = feedin.values + df = pd.DataFrame(temp) df_to_renewable_feedin(df, weather_year, weather_scenario_id) print('Done!') if __name__ == '__main__': - main() + main() + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/preprocessing/python_scripts/renpass_gis/simple_feedin/wind_onshore.py b/preprocessing/python_scripts/renpass_gis/simple_feedin/wind_onshore.py index bd50d1c4..3e097f6d 100644 --- a/preprocessing/python_scripts/renpass_gis/simple_feedin/wind_onshore.py +++ b/preprocessing/python_scripts/renpass_gis/simple_feedin/wind_onshore.py @@ -2,7 +2,7 @@ """ Created on Wed Mar 14 14:30:54 2018 -__author__ = "MarlonSchlemminger" +__author__ = "MarlonSchlemminger, s3pp" """ import pandas as pd @@ -25,6 +25,7 @@ config = 'config.ini' correction_offshore = 0.83 correction_solar = 0.8 +correction_onshore = 0.6 weather_year = 2011 weather_scenario_id = 1 @@ -171,6 +172,19 @@ def collect_energymap_data(): def df_to_renewable_feedin(df, weather_year, weather_scenario_id): + """ + Transfers the calculated feedin timeseries into the database table + ego_renewable_feedin. + + Parameters + df : DataFrame with feedin timeseries + weather_year : weather year of weather data + weather_scenario_id : weather scenario id + ---------- + + Returns + ------- + """ print('Creating table ego_renewable_feedin..') Base = declarative_base() @@ -343,6 +357,17 @@ def get_plant_per_class(windgenerator, power_classes): return selected_plants def power_class_to_db(power_classes, selected_plants): + """ + Inserts the power classes used for the timeseries calculation into the + database table ego_power_class + + Parameters + ---------- + + Returns + ------- + windgenerator : DataFrame of all wind generators in energy_map + """ print('Creating table power_class..') Base = declarative_base() @@ -491,7 +516,7 @@ def main(): power_class = 1 for index, row in selected_plants.iterrows(): plant = wind_dict(row) - feedin = plants.WindPowerPlant(**plant).\ + feedin = correction_onshore * plants.WindPowerPlant(**plant).\ feedin(weather=weather, installed_capacity=1) temp[(coastdat_id, type_of_generation, power_class)] = feedin.values power_class += 1 diff --git a/preprocessing/sql_snippets/ego_simple-feedin_per_scenario.sql b/preprocessing/sql_snippets/ego_simple-feedin_per_scenario.sql index 2a90d653..11cce20e 100644 --- a/preprocessing/sql_snippets/ego_simple-feedin_per_scenario.sql +++ b/preprocessing/sql_snippets/ego_simple-feedin_per_scenario.sql @@ -1,6 +1,5 @@ /* Setup simple feedin weather measurement point - __copyright__ = "Europa-Universität Flensburg, Centre for Sustainable Energy Systems" __license__ = "GNU Affero General Public License Version 3 (AGPL-3.0)" __url__ = "https://github.com/openego/data_processing/blob/master/LICENSE" @@ -76,7 +75,7 @@ __author__ = "wolfbunke, MarlonSchlemminger" -- Where ST_Intersects(B.geom,C.geom); -- -DROP TABLE IF EXISTS model_draft.ego_neighbours_offshore_point; +DROP TABLE IF EXISTS model_draft.ego_neighbours_offshore_point CASCADE; CREATE TABLE model_draft.ego_neighbours_offshore_point ( @@ -144,15 +143,14 @@ CREATE TABLE model_draft.ego_weather_measurement_point ( coastdat_id bigint NOT NULL, type_of_generation text NOT NULL, - wea_type text, geom geometry(Point,4326), CONSTRAINT weather_measurement_point_pkey PRIMARY KEY (coastdat_id, type_of_generation) ) WITH ( OIDS=FALSE ); --- ALTER TABLE model_draft.ego_weather_measurement_point --- OWNER TO oeuser; +ALTER TABLE model_draft.ego_weather_measurement_point + OWNER TO oeuser; -- german points INSERT INTO model_draft.ego_weather_measurement_point (coastdat_id, type_of_generation, geom) @@ -219,125 +217,6 @@ FROM climate.cosmoclmgrid AS coastdat, WHERE ST_Intersects(neighbour.geom, coastdat.geom) ON CONFLICT DO NOTHING; -set wea_type -UPDATE model_draft.ego_weather_measurement_point -SET wea_type = wea -FROM (SELECT gid, wea_manufacturer||' '||wea_type AS wea - FROM - (SELECT gid, wea_manufacturer, wea_type, COUNT(*) as cnt, - ROW_NUMBER() OVER (PARTITION BY gid ORDER BY COUNT(*) DESC) AS rnk - FROM climate.cosmoclmgrid a, model_draft.bnetza_eeg_anlagenstammdaten_wind_classification b - WHERE ST_Intersects(a.geom, ST_Transform(b.geom, 4326)) - AND wea_type <> 'na' - AND seelage IS NULL - GROUP BY gid, wea_manufacturer, wea_type - ) as tg - WHERE rnk = 1 - ) a -WHERE coastdat_id = gid -AND type_of_generation = 'wind_onshore'; --- --- UPDATE model_draft.ego_weather_measurement_point --- SET wea_type = wea --- FROM (SELECT gid, wea_manufacturer||' '||wea_type AS wea --- FROM --- (SELECT gid, wea_manufacturer, wea_type, COUNT(*) as cnt, --- ROW_NUMBER() OVER (PARTITION BY gid ORDER BY COUNT(*) DESC) AS rnk --- FROM climate.cosmoclmgrid a, model_draft.bnetza_eeg_anlagenstammdaten_wind_classification b --- WHERE ST_Intersects(a.geom, ST_Transform(b.geom, 4326)) --- AND wea_type <> 'na' --- AND seelage IS NOT NULL --- GROUP BY gid, wea_manufacturer, wea_type --- ) as tg --- WHERE rnk = 1 --- ) a --- WHERE coastdat_id = gid --- AND type_of_generation = 'wind_offshore'; - -UPDATE model_draft.ego_weather_measurement_point -SET wea_type = wea -FROM (SELECT gid, windanlagenhersteller||' '||anlagentyp AS wea - FROM - (SELECT a.gid, windanlagenhersteller, anlagentyp, COUNT(*) as cnt, - ROW_NUMBER() OVER (PARTITION BY a.gid ORDER BY COUNT(*) DESC) AS rnk - FROM climate.cosmoclmgrid a, app_renpassgis.renewable_energy_map_1 b - WHERE ST_Intersects(a.geom, ST_Transform(b.geom, 4326)) - AND energietraeger = 'Wind Land' - AND (stillgelegt <> 'Ja' OR stillgelegt IS NULL) - GROUP BY a.gid, windanlagenhersteller, anlagentyp - ) as tg - WHERE rnk = 1 - ) a -WHERE coastdat_id = gid -AND type_of_generation = 'wind_onshore'; - -UPDATE model_draft.ego_weather_measurement_point -SET wea_type = wea -FROM (SELECT gid, wea_manufacturer||' '||wea_type AS wea - FROM - (SELECT gid, wea_manufacturer, wea_type, COUNT(*) as cnt, - ROW_NUMBER() OVER (PARTITION BY gid ORDER BY COUNT(*) DESC) AS rnk - FROM climate.cosmoclmgrid a, app_renpassgis.renewable_energy_map_1 b - WHERE ST_Intersects(a.geom, ST_Transform(b.geom, 4326)) - AND wea_type <> 'na' - AND seelage IS NOT NULL - GROUP BY gid, wea_manufacturer, wea_type - ) as tg - WHERE rnk = 1 - ) a -WHERE coastdat_id = gid -AND type_of_generation = 'wind_offshore'; - -DELETE FROM model_draft.ego_weather_measurement_point -WHERE wea_type IS NULL -AND type_of_generation IN ('wind_onshore', 'wind_offshore'); - --- get data for most used wind turbines -DROP TABLE IF EXISTS model_draft.ego_wind_turbine_data; - -CREATE TABLE model_draft.ego_wind_turbine_data -( - type_of_generation text NOT NULL, - wea text NOT NULL, - d_rotor double precision NOT NULL, - h_hub double precision NOT NULL, - CONSTRAINT wind_turbine_data_pkey PRIMARY KEY (type_of_generation, wea) - ); - -INSERT INTO model_draft.ego_wind_turbine_data (type_of_generation, wea, d_rotor, h_hub) - (SELECT 'wind_onshore', - wea_manufacturer||' '||wea_type, - rotordurchmesser, - nabenhöhe - FROM - (SELECT wea_manufacturer, wea_type, rotordurchmesser, nabenhöhe, COUNT(*) AS cnt, - ROW_NUMBER() OVER (PARTITION BY wea_type ORDER BY COUNT(*) DESC) AS rnk - FROM model_draft.bnetza_eeg_anlagenstammdaten_wind_classification - WHERE wea_type <> 'na' - AND seelage IS NULL - GROUP BY wea_manufacturer, wea_type, rotordurchmesser, nabenhöhe - ) AS tg - WHERE rnk = 1 - AND wea_manufacturer||' '||wea_type IN (SELECT wea_type FROM model_draft.ego_weather_measurement_point) - ); - -INSERT INTO model_draft.ego_wind_turbine_data (type_of_generation, wea, d_rotor, h_hub) - (SELECT 'wind_offshore', - wea_manufacturer||' '||wea_type, - rotordurchmesser, - nabenhöhe - FROM - (SELECT wea_manufacturer, wea_type, rotordurchmesser, nabenhöhe, COUNT(*) AS cnt, - ROW_NUMBER() OVER (PARTITION BY wea_type ORDER BY COUNT(*) DESC) AS rnk - FROM model_draft.bnetza_eeg_anlagenstammdaten_wind_classification - WHERE wea_type <> 'na' - AND seelage IS NOT NULL - GROUP BY wea_manufacturer, wea_type, rotordurchmesser, nabenhöhe - ) AS tg - WHERE rnk = 1 - AND wea_manufacturer||' '||wea_type IN (SELECT wea_type FROM model_draft.ego_weather_measurement_point) - ); - COMMENT ON TABLE model_draft.ego_weather_measurement_point IS '{ "title": "model_draft.ego_weather_measurement_point", "description": "Geometry of weather points for feedin timeseries calculation", From ff193aa673977188b5aa20d57920ce72a9fa12f6 Mon Sep 17 00:00:00 2001 From: MarlonSchlemminger Date: Mon, 26 Mar 2018 15:21:25 +0200 Subject: [PATCH 5/9] delete redundant file --- .../renpass_gis/simple_feedin/wind_onshore.py | 577 ------------------ 1 file changed, 577 deletions(-) delete mode 100644 preprocessing/python_scripts/renpass_gis/simple_feedin/wind_onshore.py diff --git a/preprocessing/python_scripts/renpass_gis/simple_feedin/wind_onshore.py b/preprocessing/python_scripts/renpass_gis/simple_feedin/wind_onshore.py deleted file mode 100644 index 3e097f6d..00000000 --- a/preprocessing/python_scripts/renpass_gis/simple_feedin/wind_onshore.py +++ /dev/null @@ -1,577 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Created on Wed Mar 14 14:30:54 2018 - -__author__ = "MarlonSchlemminger, s3pp" -""" - -import pandas as pd -import db -from sqlalchemy import (MetaData, and_, or_, Column, Text, text, Integer, Float, ARRAY) -from sqlalchemy.ext.automap import automap_base -from operator import itemgetter -from functions import C_choice_of_windgenerator -import pkg_resources -import re -from feedinlib import powerplants as plants -from oemof.db import coastdat -from sqlalchemy.ext.declarative import declarative_base - -points = db.Points -conn = db.conn -session = db.session -meta = MetaData() - -config = 'config.ini' -correction_offshore = 0.83 -correction_solar = 0.8 -correction_onshore = 0.6 -weather_year = 2011 -weather_scenario_id = 1 - -def asnumber(x): - """ Tries to convert a string to a numeric format - - Parameters - ---------- - x : str - - Returs - ------ - x : int or float or str - """ - - try: - return int(x) - except ValueError: - try: - return float(x) - except ValueError: - return x - - -def collect_bnetza_data(): - """ - Collects data of wind turbines available in the BNetzA Anlagenstammdaten. - - Parameters - ---------- - - Returns - ------- - plants : DataFrame of all wind generators in BNetzA - """ - meta.reflect(bind=conn, schema='model_draft', - only=['bnetza_eeg_anlagenstammdaten_wind_classification']) - Base = automap_base(metadata=meta) - Base.prepare() - - Bnetza = Base.classes.bnetza_eeg_anlagenstammdaten_wind_classification - - query = session.query(Bnetza.installierte_leistung, - Bnetza.wea_manufacturer, - Bnetza.wea_type, - Bnetza.nabenhöhe, - Bnetza.rotordurchmesser).filter(Bnetza.seelage == None) - plants = [(installierte_leistung, - wea_manufacturer, - wea_type, - nabenhöhe, - rotordurchmesser) - for installierte_leistung, wea_manufacturer, wea_type, nabenhöhe, rotordurchmesser - in query.all()] - plants.sort(key=itemgetter(0)) - columns = ['capacity', 'manufacturer', 'type', 'hub', 'rotor'] - plants = pd.DataFrame(plants, columns=columns) - - return plants - - -def collect_ego_turbines(): - """ - Collects data of wind turbines used in the eGo database. - - Parameters - ---------- - - Returns - ------- - generators : capacity of turbines used in the eGo database - """ - meta.reflect(bind=conn, schema='model_draft', - only=['ego_dp_supply_res_powerplant']) - Base = automap_base(metadata=meta) - Base.prepare() - - Dp = Base.classes.ego_dp_supply_res_powerplant - - query = session.query(Dp.electrical_capacity).\ - filter(and_(Dp.generation_subtype == 'wind_onshore',\ - Dp.electrical_capacity < 7600 ,\ - Dp.start_up_date > '1998-01-01 00:00:00',\ - Dp.start_up_date < '2018-01-01 00:00:00')) - - Gens = [(electrical_capacity) for electrical_capacity in query.all()] - generators = [] - for i in range(0, len(Gens)): - generators.append(float(Gens[i][0])) - generators.sort() - - return generators - - -def collect_energymap_data(): - """ - Collects data of wind turbines available in the energy map table. - - Parameters - ---------- - - Returns - ------- - windgenerator : DataFrame of all wind generators in energy_map - """ - meta.reflect(bind=conn,schema='app_renpassgis',only=['renewable_energy_map_1']) - Base = automap_base(metadata=meta) - Base.prepare() - - SQL_data = Base.classes.renewable_energy_map_1 - - plants = session.query(SQL_data).\ - filter(and_(SQL_data.energietraeger == 'Wind Land',or_\ - (SQL_data.stillgelegt!='Ja',\ - SQL_data.stillgelegt == None))).all() - - windgenerator = [[],[],[],[],[]] - - # index 0 : power in kW - # index 1 : manufacturer of the windgenerator - # index 2 : type of the generator - # index 3 : hub height in meter - # index 4 : rotor diameter in meter - - # power of each generator, but it's sorted by size - sorted_windgenerator = [] - - for plant in plants: - sorted_windgenerator.append(float(plant.installierte_leistung)) - - windgenerator[0].append(float(plant.installierte_leistung)) - windgenerator[1].append(plant.windanlagenhersteller) - windgenerator[2].append(plant.anlagentyp) - windgenerator[3].append(plant.nabenhoehe) - windgenerator[4].append(plant.rotordurchmesser) - - sorted_windgenerator.sort() - windgenerator[1] = C_choice_of_windgenerator.upper_string(windgenerator[1]) - windgenerator[2] = C_choice_of_windgenerator.upper_string(windgenerator[2]) - windgenerator = pd.DataFrame(windgenerator).transpose() - columns = ['capacity', 'manufacturer', 'type', 'h_hub', 'd_rotor'] - windgenerator.columns = columns - return windgenerator - - -def df_to_renewable_feedin(df, weather_year, weather_scenario_id): - """ - Transfers the calculated feedin timeseries into the database table - ego_renewable_feedin. - - Parameters - df : DataFrame with feedin timeseries - weather_year : weather year of weather data - weather_scenario_id : weather scenario id - ---------- - - Returns - ------- - """ - print('Creating table ego_renewable_feedin..') - Base = declarative_base() - - class Ego_renewable_feedin(Base): - __tablename__ = 'ego_renewable_feedin' - __table_args__ = {'schema': 'model_draft'} - - weather_scenario_id = Column(Integer(), primary_key=True) - w_id = Column(Integer(), primary_key=True) - source = Column(Text(), primary_key=True) - weather_year = Column(Integer(), primary_key=True) - power_class = Column(Integer(), primary_key=True) - feedin = Column(ARRAY(Float)) - - conn.execute(text("DROP TABLE IF EXISTS model_draft.ego_renewable_feedin CASCADE")) - -# try: -# Ego_renewable_feedin.__table__.drop(conn) -# except: -# pass - - Base.metadata.create_all(conn) - - print('Importing feedin to database..') - - # prepare DataFrames - session = db.session - #Points = db.Base.classes.ego_weather_measurement_point - mappings = [] - - # Insert Data to DB - for k in df.columns: - weather_scenario_id = weather_scenario_id - w_id = k[0] - source = k[1] - weather_year = weather_year - power_class = k[2] - feedin = df[k].values.tolist() - info = Ego_renewable_feedin(w_id=w_id, - weather_scenario_id=weather_scenario_id, - source=source, - weather_year=weather_year, - power_class=power_class, - feedin=feedin) - mappings.append(info) - - session.bulk_save_objects(mappings) - session.commit() - - print('Done!') - - -def get_power_classes(capacity): - """ - Gets power classes. - - Parameters - ---------- - capacity : list of capacities of all turbines used in the eGo database - - Returns - ------- - power_classes : list with thresholds for power classes - """ - max_power = max(capacity) - power_classes = [max_power] - - x = 0 - - # Variable to guarantee to use the right parts in the loop - new_class = True - - # Counter for number of windgenerators - i = 0 - - while(i < len(capacity)): - if ((new_class == True) and (capacity[i] < power_classes[x])): - power_classes.insert(x, round(capacity[i], -2)) - new_class = False - - elif(capacity[i] < power_classes[x+1]): - t=power_classes.pop(x) - power_classes.insert(x, round(capacity[i], -2)) - - percent_of_plants_in_classes = C_choice_of_windgenerator.percent(capacity, power_classes) - - if ((percent_of_plants_in_classes[x] >= 0.1)): - if((round(capacity[i], -2)) == (round(capacity[i+1], -2))): - new_class = False - i+=1 - else: - x+=1 - new_class = True - i+=1 - else: - i+=1 - - # change the last boarder, so that only the last boarder have a percentage - # under 0.1 - i = 0 - while(i < len(power_classes)): - if((percent_of_plants_in_classes[len(power_classes)-1] <= 0.1) - and - (percent_of_plants_in_classes[len(power_classes)-2] <= 0.1)): - power_classes.pop(len(power_classes)-2) - percent_of_plants_in_classes =\ - C_choice_of_windgenerator.percent(capacity, power_classes) - else: - break - - i+=1 - - return power_classes - -def get_plant_per_class(windgenerator, power_classes): - """ - Calculates the most used plant per power class. If a turbine is not available - in windlib, the second, third,.. most used turbine is taken until one is - available in windlib. - - Parameters - ---------- - windgenerator : DataFrame of all wind generators in energy_map - power_classes : list with threshold for power classes - - Returns - ------- - selected_plants : DataFrame with most used turbines - """ - - windgenerator = windgenerator.sort_values(by='capacity') - plants_per_classes = [] - lower = 0 - for upper in power_classes: - plants_per_classes.append( - windgenerator[(windgenerator['capacity'] >= lower) - & (windgenerator['capacity'] < upper)]) - lower = upper - - numbers = [] - for element in plants_per_classes: - numbers.append(element.groupby(element.columns.tolist(), as_index=False). - size().reset_index().rename(columns={0:'count'})) - - selected_plants = [] - for element in numbers: - selected_plants.append(element.sort_values(by='count', ascending=False).iloc[0]) - - selected_plants = pd.DataFrame(selected_plants) - selected_plants['power_class'] = power_classes - - not_in_windlib = turbine_in_windlib(selected_plants) - position = 1 - - while not_in_windlib.empty == False: - for index, row in not_in_windlib.iterrows(): - numbers_index = power_classes.index(row['power_class']) - power_class = selected_plants.ix[index]['power_class'] - selected_plants.ix[index] = numbers[numbers_index].\ - sort_values(by='count', ascending=False).iloc[position] - selected_plants['power_class'][index] = power_class - - not_in_windlib = turbine_in_windlib(selected_plants) - position += 1 - - selected_plants['type'] = selected_plants['manufacturer']+' '+\ - selected_plants['type']+' '+\ - selected_plants['capacity'].map(int).map(str) - - return selected_plants - -def power_class_to_db(power_classes, selected_plants): - """ - Inserts the power classes used for the timeseries calculation into the - database table ego_power_class - - Parameters - ---------- - - Returns - ------- - windgenerator : DataFrame of all wind generators in energy_map - """ - - print('Creating table power_class..') - Base = declarative_base() - - class Ego_power_class(Base): - __tablename__ = 'ego_power_class' - __table_args__ = {'schema': 'model_draft'} - - power_class_id = Column(Integer(), primary_key=True) - lower_limit = Column(Float()) - upper_limit = Column(Float()) - wea = Column(Text()) - h_hub = Column(Float()) - d_rotor = Column(Float()) - - - conn.execute(text("DROP TABLE IF EXISTS model_draft.ego_power_class CASCADE")) - - Base.metadata.create_all(conn) - - print('Importing power classes to database..') - - # prepare DataFrames - session = db.session - #Points = db.Base.classes.ego_weather_measurement_point - mappings = [] - lower = 0 - power_class_id = 1 - # Insert Data to DB - for upper in power_classes: - wea = selected_plants['type'][selected_plants['power_class'] == upper].item() - h_hub = selected_plants['h_hub'][selected_plants['power_class'] == upper].item() - d_rotor = selected_plants['d_rotor'][selected_plants['power_class'] == upper].item() - if power_class_id == len(power_classes): - info = Ego_power_class(power_class_id=power_class_id, - lower_limit=lower/1000, - upper_limit=1000000000, - wea=wea, - h_hub=h_hub, - d_rotor=d_rotor) - mappings.append(info) - else: - info = Ego_power_class(power_class_id=power_class_id, - lower_limit=lower/1000, - upper_limit=upper/1000, - wea=wea, - h_hub=h_hub, - d_rotor=d_rotor) - mappings.append(info) - - lower = upper - power_class_id += 1 - - session.bulk_save_objects(mappings) - session.commit() - - print('Done!') - -def turbine_in_windlib(plants): - """ - Checks if a given dataframe of turbines is available in the windlib cp_values - file. Deletes all turbines from the dataframe which are available and returns - the ones that are not. - - Parameters - ---------- - plants : DataFrame of turbines - - Returns - ------- - plants : modified dataframes without turbines available in windlib - """ - - resource_package = 'windpowerlib' - resource_path = '/'.join(('data', 'cp_values.csv')) - - template = pkg_resources.resource_stream(resource_package, resource_path) - cp_generators = pd.DataFrame.from_csv(template) - for index, row in plants.iterrows(): - for name in cp_generators['rli_anlagen_id']: - if row['type'] in name: - split = re.split('(\d+)', name) - if int(row[0]) == int(split[3]): - plants = plants.drop(row.name) - break - - return plants - -def wind_dict(row): - """ Writes section data of a configuration file to a dictionary - - Parameters - ---------- - cfg : configparser.ConfigParser - Used for configuration file parser language. - section : str - Section in configuration file. - - Returns - ------- - dict - Dictionary containing section data. - """ - - return {'d_rotor': float(row['d_rotor']), - 'h_hub': float(row['h_hub']), - 'wind_conv_type': row['type']} - - -def main(): - windgenerator = collect_energymap_data() - capacity = collect_ego_turbines() - power_classes = get_power_classes(capacity) - selected_plants = get_plant_per_class(windgenerator, power_classes) - power_class_to_db(power_classes, selected_plants) - - cfg = db.readcfg(config) - temp = {} - powerplants = {} - powerplants['solar'] = plants.Photovoltaic( - **{k: asnumber(v) for k, v in cfg.items('Photovoltaic')}) - - powerplants['wind_offshore'] = plants.WindPowerPlant( - **{k: asnumber(v) for k, v in cfg.items('WindTurbineOffshore')}) - - print('Calculating feedins...') - - count = 0 - for coastdat_id, type_of_generation, geom in points: - - count += 1 - print(count) - try: - weather = coastdat.get_weather(conn, geom, weather_year) - except IndexError: - print('Geometry cannot be handled: %s, %s' % (geom.x, geom.y)) - continue - - if type_of_generation == 'wind_offshore': - feedin = correction_offshore * powerplants[type_of_generation].\ - feedin(weather=weather, installed_capacity=1) - power_class = 0 - temp[(coastdat_id, type_of_generation, power_class)] = feedin.values - - elif type_of_generation == 'wind_onshore': - power_class = 1 - for index, row in selected_plants.iterrows(): - plant = wind_dict(row) - feedin = correction_onshore * plants.WindPowerPlant(**plant).\ - feedin(weather=weather, installed_capacity=1) - temp[(coastdat_id, type_of_generation, power_class)] = feedin.values - power_class += 1 - - elif type_of_generation == 'solar': - feedin = correction_solar * powerplants[type_of_generation].\ - feedin(weather=weather, peak_power=1) - power_class = 0 - temp[(coastdat_id, type_of_generation, power_class)] = feedin.values - else: - continue - - #temp[(coastdat_id, type_of_generation)] = feedin.values - - df = pd.DataFrame(temp) - df_to_renewable_feedin(df, weather_year, weather_scenario_id) - print('Done!') - - -if __name__ == '__main__': - main() - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From 1b3bfff5788077eb586345b1b0454309064e0057 Mon Sep 17 00:00:00 2001 From: MarlonSchlemminger Date: Mon, 26 Mar 2018 15:43:42 +0200 Subject: [PATCH 6/9] add comment for power class --- .../ego_setup_renewable_feedin.sql | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/preprocessing/sql_snippets/ego_setup_renewable_feedin.sql b/preprocessing/sql_snippets/ego_setup_renewable_feedin.sql index f7de5f04..795fd7b7 100644 --- a/preprocessing/sql_snippets/ego_setup_renewable_feedin.sql +++ b/preprocessing/sql_snippets/ego_setup_renewable_feedin.sql @@ -33,5 +33,44 @@ {"name": "feedin", "description": "Feedin timeseries", "unit": "pu"} ] } ], "metadata_version": "1.3"}'; +-- select description +SELECT obj_description('model_draft.ego_renewable_feedin' ::regclass) ::json; + +COMMENT ON TABLE model_draft.ego_power_class IS '{ + "title": "model_draft.ego_power_class", + "description": "Power classes used for feedin timeseries", + "language": [], + "spatial": + {"location": "", + "extent": "", + "resolution": ""}, + "temporal": + {"reference_date": "", + "start": "", + "end": "", + "resolution": ""}, + "sources": [ + {"name": "open_eGo preprocessing", "description": "", "url": "https://github.com/openego/data_processing/tree/master/preprocessing", "license": "", "copyright": ""} ], + "license": + {"id": "", + "name": "", + "version": "", + "url": "", + "instruction": "", + "copyright": ""}, + "contributors": [ + {"name": "Marlon Schlemminger", "email": "marlon@wmkamp46a.de", "date": "26.03.2018", "comment": ""}], + "resources": [ + {"name": "", + "format": "PostgreSQL", + "fields": [ + {"name": "power_class_id", "description": "Identifier for power class", "unit": ""}, + {"name": "lower_limit", "description": "Lower limit of the power class", "unit": "MW"}, + {"name": "upper_limit", "description": "Upper limit of the power class", "unit": "MW"}, + {"name": "wea", "description": "Type of WEA used in this powerclass", "unit": ""}, + {"name": "h_hub", "description": "Hub height of WEA", "unit": "m"}, + {"name": "d_rotor", "description": "Rotor diameter of WEA", "unit": "m"} ] } ], + "metadata_version": "1.3"}'; + -- select description SELECT obj_description('model_draft.ego_renewable_feedin' ::regclass) ::json; \ No newline at end of file From 0976f8ff93484c15f3c0c60873cfd1e7addcf0f5 Mon Sep 17 00:00:00 2001 From: MarlonSchlemminger Date: Mon, 26 Mar 2018 15:51:39 +0200 Subject: [PATCH 7/9] delete comma --- preprocessing/python_scripts/renpass_gis/simple_feedin/db.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/preprocessing/python_scripts/renpass_gis/simple_feedin/db.py b/preprocessing/python_scripts/renpass_gis/simple_feedin/db.py index 5888c11f..b1badd3d 100644 --- a/preprocessing/python_scripts/renpass_gis/simple_feedin/db.py +++ b/preprocessing/python_scripts/renpass_gis/simple_feedin/db.py @@ -144,7 +144,7 @@ class Typified(Base): Datatype, Projection, Spatial, Timeseries, Year, Point=\ Base.classes.datatype, Base.classes.projection, Base.classes.spatial,\ Base.classes.timeseries, Base.classes.year,\ - Base.classes.ego_weather_measurement_point,\ + Base.classes.ego_weather_measurement_point # Base.classes.weather_measurement_point session = sessionmaker(bind=conn)() From 1825ed268945b30c5dc6667cddcbd74ebe97af07 Mon Sep 17 00:00:00 2001 From: WolfBunke Date: Tue, 27 Mar 2018 14:17:40 +0200 Subject: [PATCH 8/9] change schema and table name --- .../renpass_gis/simple_feedin/simple_feedin.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/preprocessing/python_scripts/renpass_gis/simple_feedin/simple_feedin.py b/preprocessing/python_scripts/renpass_gis/simple_feedin/simple_feedin.py index 83baf838..5facca2c 100644 --- a/preprocessing/python_scripts/renpass_gis/simple_feedin/simple_feedin.py +++ b/preprocessing/python_scripts/renpass_gis/simple_feedin/simple_feedin.py @@ -131,11 +131,11 @@ def collect_energymap_data(): ------- windgenerator : DataFrame of all wind generators in energy_map """ - meta.reflect(bind=conn,schema='app_renpassgis',only=['renewable_energy_map_1']) + meta.reflect(bind=conn,schema='model_draft',only=['ego_supply_renewable_bneta_full_attribute']) Base = automap_base(metadata=meta) Base.prepare() - SQL_data = Base.classes.renewable_energy_map_1 + SQL_data = Base.classes.ego_supply_renewable_bneta_full_attribute plants = session.query(SQL_data).\ filter(and_(SQL_data.energietraeger == 'Wind Land',or_\ @@ -571,4 +571,4 @@ def main(): - \ No newline at end of file + From b2b7a9f39c760016713ced147fc0843ba782d207 Mon Sep 17 00:00:00 2001 From: WolfBunke Date: Tue, 27 Mar 2018 14:32:43 +0200 Subject: [PATCH 9/9] Update simple_feedin.py --- .../python_scripts/renpass_gis/simple_feedin/simple_feedin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/preprocessing/python_scripts/renpass_gis/simple_feedin/simple_feedin.py b/preprocessing/python_scripts/renpass_gis/simple_feedin/simple_feedin.py index 5facca2c..aa26f03e 100644 --- a/preprocessing/python_scripts/renpass_gis/simple_feedin/simple_feedin.py +++ b/preprocessing/python_scripts/renpass_gis/simple_feedin/simple_feedin.py @@ -131,7 +131,7 @@ def collect_energymap_data(): ------- windgenerator : DataFrame of all wind generators in energy_map """ - meta.reflect(bind=conn,schema='model_draft',only=['ego_supply_renewable_bneta_full_attribute']) + meta.reflect(bind=conn,schema='model_draft',only=['ego_supply_renewable_bnetza_full_attribute']) Base = automap_base(metadata=meta) Base.prepare()