Repository: https://github.com/openego/oedialect
Please report bugs and improvements here: https://github.com/OpenEnergyPlatform/examples/issues
How to get started with Jupyter Notebooks can be found here: https://github.com/OpenEnergyPlatform/oeplatform/wiki
Please ensure you have read the Terms of use here: https://openenergy-platform.org/legal/tou/
__copyright__ = "Reiner Lemoine Institut, Zentrum für nachhaltige Energiesysteme Flensburg"
__license__ = "GNU Affero General Public License Version 3 (AGPL-3.0)"
__url__ = "https://github.com/openego/data_processing/blob/master/LICENSE"
__author__ = "wolfbunke, Ludee"
This tutorial gives you an overview of the OpenEnergy Platform and how you can work with the REST-full-HTTP API in Python.
The full API documentaion can be found on ReadtheDocs.io.
0 Setup token
1 Select data
2 Make a pandas dataframe
3 Plot a dataframe (geo plot)
import requests
import pandas as pd
from IPython.core.display import HTML
from token_config import oep_url, get_oep_token
# token
your_token = get_oep_token()
import geopandas as gpd
from shapely.geometry import Point
import shapely.wkt
from shapely import wkb
from geoalchemy2.shape import to_shape
# select powerplant data
schema = 'supply'
table = 'ego_dp_conv_powerplant'
where = 'version=v0.2.10'
conv_powerplants = requests.get(oep_url+'/api/v0/schema/'+schema+'/tables/'+table+'/rows/?where='+where, )
conv_powerplants.status_code
# select borders
schema = 'boundaries'
table = 'bkg_vg250_2_lan_mview'
vg = requests.get(oep_url+'/api/v0/schema/'+schema+'/tables/'+table+'/rows/')
vg.status_code
# Create dataframe from json format
df_pp = pd.DataFrame(conv_powerplants.json())
df_vg = pd.DataFrame(vg.json())
# Show metadata for a specific dataframe.
df_pp.info()
# List all column names for a specific dataframe.
df_pp.columns
#Print the df_pp dataframe as table.
df_vg
import geopandas as gpd
import shapely
import matplotlib.pyplot as plt
%matplotlib inline
# transform WKB to WKT / Geometry
df_pp['geom'] = df_pp['geom'].apply(lambda x:shapely.wkb.loads(x, hex=True))
df_vg['geom'] = df_vg['geom'].apply(lambda x:shapely.wkb.loads(x, hex=True))
# plot powerplants
crs = {'init' :'epsg:4326'}
gdf_pp = gpd.GeoDataFrame(df_pp, crs=crs, geometry=df_pp.geom)
base1 = gdf_pp.plot(color='white', edgecolor='black',figsize=(8, 8))
gdf_pp.plot(ax=base1, color='green')
plt.show()
# plot borders
crs = {'init' :'epsg:4326'}
gdf_vg = gpd.GeoDataFrame(df_vg, geometry=df_vg.geom)
base2 = gdf_vg.plot(color='white', edgecolor='black',figsize=(8, 8))
gdf_vg.plot(ax=base2)
plt.show()
# transform WKB to WKT / Geometry
crs1 = {'init' :'epsg:4326'}
crs2 = {'init' :'epsg:3035'}
gdf_pp = gpd.GeoDataFrame(df_pp, crs=crs1, geometry=df_pp.geom)
gdf_vg = gpd.GeoDataFrame(df_vg, crs=crs2, geometry=df_vg.geom)
base = gdf_vg.plot(color='white', edgecolor='black',figsize=(10, 10))
gdf_pp.plot(ax=base, marker='o', markersize=5)
# gdf_vg.plot(ax=base)
plt.show()
from shapely import geos
from geoalchemy2.shape import to_shape
from shapely.geometry import Point
# from ipywidgets import widgets
from IPython.display import display
from IPython.core.display import HTML
from geoalchemy2 import Geometry, WKTElement
import requests
import pandas as pd
# import mplleaflet
plants_data = requests.get(oep_url+'/api/v0/schema/model_draft/tables/ego_dp_supply_conv_powerplant/rows/?where=scenario=Status+Quo&limit=910',)
regions = requests.get(oep_url+'/api/v0/schema/model_draft/tables/renpass_gis_parameter_region/rows/?where=stat_level=999',)
regions.status_code
plants_data.status_code
sq_plants = pd.DataFrame(plants_data.json())
renpass_region_df = pd.DataFrame(regions.json())
# transform WKB to WKT / Geometry
crs = {'init' :'epsg:4326'}
sq_plants['geom'] =sq_plants['geom'].apply(lambda x:shapely.wkb.loads(x, hex=True))
renpass_region_df['geom'] =renpass_region_df['geom'].apply(lambda x:shapely.wkb.loads(x, hex=True))
gdf_plants = gpd.GeoDataFrame(sq_plants, crs=crs, geometry=sq_plants.geom)
gdf_regions = gpd.GeoDataFrame(renpass_region_df, crs=crs, geometry=renpass_region_df.geom)
base = gdf_regions.plot(color='white', edgecolor='black',figsize=(10, 10))
gdf_plants.plot(ax=base)
plt.show()
import folium
from folium import plugins
import matplotlib.pyplot as plt
%matplotlib inline
# define map region
map = folium.Map(location=[51, 9], zoom_start=6)
# Use column lon / lat in order to plot map
for name, row in gdf_pp.iloc[:1000].iterrows():
folium.Marker([row["lat"], row["lon"]], popup=row["type"] ).add_to(map)
#map.create_map('plants.html')
map
stops_heatmap = folium.Map(location=[51, 9], zoom_start=6)
stops_heatmap.add_child(plugins.HeatMap([[row["lat"], row["lon"]] for capacity, row in df_pp.iloc[:1000].iterrows()]))
stops_heatmap.save("heatmap.html")
stops_heatmap
If you find bugs or if you have ideas to improve the Open Energy Platform, you are
welcome to add your comments to the existing issues on GitHub.
You can also fork the project and get involved.
Please note that the platform is still under construction and therefore the design of this page is still highly volatile!