Skip to content

Commit

Permalink
fixed bug in line smoothing
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Eggimann committed Sep 28, 2018
1 parent 7b640ef commit b3bb4c6
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 130 deletions.
2 changes: 1 addition & 1 deletion energy_demand/main.py
Expand Up @@ -10,7 +10,7 @@
# MAKE SIMLPLE TABLE FOR READING IN FUELS
# correction factors on LAD level disaggregation? (load non-residential demand)
# Improve plotting and processing (e.g. saisonal plots)
# test if smoothing and plots
# Weather station cleaning: Replace days with missing values
Note
Expand Down
38 changes: 6 additions & 32 deletions energy_demand/plotting/_scrap.py
@@ -1,34 +1,8 @@
import pandas as pd
import geopandas
from shapely.geometry import Point
import matplotlib.pyplot as plt

df = pd.DataFrame(
{'City': ['Buenos Aires', 'Brasilia', 'Santiago', 'Bogota', 'Caracas'],
'Country': ['Argentina', 'Brazil', 'Chile', 'Colombia', 'Venezuela'],
'Latitude': [-34.58, -15.78, -33.45, 4.60, 10.48],
'Longitude': [-58.66, -47.91, -70.66, -74.08, -66.86]})

df['Coordinates'] = list(zip(df.Longitude, df.Latitude))


df['Coordinates'] = df['Coordinates'].apply(Point)

gdf = geopandas.GeoDataFrame(df, geometry='Coordinates')

world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))


# We restrict to South America.
#ax = world[world.continent == 'South America'].plot(
# color='white', edgecolor='black')
ax = world[world.name == "United Kingdom"].plot(
color='white', edgecolor='black')
#uk = world[world.name == "United Kingdom"]

# We can now plot our GeoDataFrame.
gdf.plot(ax=ax, color='red')

plt.show()
import math
import numpy as np
import matplotlib.pyplot as plt
import pylab
from scipy.interpolate import interp1d
from scipy.interpolate import spline

print("aa")
80 changes: 61 additions & 19 deletions energy_demand/plotting/basic_plot_functions.py
Expand Up @@ -19,54 +19,93 @@ def cm2inch(*tupl):
else:
return tuple(i/inch for i in tupl)

def smooth_data(x_list, y_list, num=500, spider=False):
def simple_smooth(x_list, y_list, num=500, spider=False, interpol_kind='quadratic'):

nr_x_values = len(x_list)
min_x_val = min(x_list)
max_x_val = max(x_list)

x_values = np.linspace(min_x_val, max_x_val, num=nr_x_values, endpoint=True)

f2 = interp1d(x_values, y_list, kind=interpol_kind)

smoothed_data_x = np.linspace(
min_x_val,
max_x_val,
num=num,
endpoint=True)

smoothed_data_y = f2(smoothed_data_x)

return smoothed_data_x, smoothed_data_y

def smooth_data(
x_list,
y_list,
num=500,
spider=False,
interpol_kind='quadratic'
):
"""Smooth data
x_list : list
List with x values
y_list : list
List with y values
num : int
New number of interpolation points
spider : bool
Criteria whether spider plot or not
# https://docs.scipy.org/doc/scipy/reference/tutorial/interpolate.html
Note:
------
- needs at least 4 entries in lists
- https://docs.scipy.org/doc/scipy/reference/tutorial/interpolate.html
"""

if spider:

nr_x_values = len(x_list)
min_x_val = min(x_list)
max_x_val = math.pi * 2 #max is tow pi

x_values = np.linspace(min_x_val, max_x_val, num=nr_x_values, endpoint=True)

f2 = interp1d(x_values, y_list, kind='quadratic') #quadratic cubic

smoothed_data_x = np.linspace(
x_values = np.linspace(
min_x_val,
max_x_val,
num=num,
num=len(x_list),
endpoint=True)
else:
nr_x_values = len(x_list)
min_x_val = min(x_list)
max_x_val = max(x_list)

x_values = np.linspace(min_x_val, max_x_val, num=nr_x_values, endpoint=True)

f2 = interp1d(x_values, y_list, kind='cubic')
f2 = interp1d(
x_values,
y_list,
kind='quadratic') #quadratic cubic

smoothed_data_x = np.linspace(
x_smooth = np.linspace(
min_x_val,
max_x_val,
num=num,
endpoint=True)

smoothed_data_y = f2(smoothed_data_x)
#y_smooth = f2(x_smooth)

return smoothed_data_x, smoothed_data_y
else:
# Smooth x data
x_smooth = np.linspace(
min(x_list),
max(x_list),
num=num)

f2 = interp1d(
x_list,
y_list,
kind=interpol_kind)

# smooth
y_smooth = f2(x_smooth)

return x_smooth, y_smooth

def smooth_line(
input_x_line_data,
Expand All @@ -78,6 +117,9 @@ def smooth_line(
nr_line_points : int
represents number of points to make between input_line_data.min and T.max
"""
input_x_line_data = np.array(input_x_line_data)
input_y_line_data = np.array(input_y_line_data)

smooth_x_line_data = np.linspace(
input_x_line_data.min(),
input_x_line_data.max(),
Expand Down
25 changes: 16 additions & 9 deletions energy_demand/plotting/fig_load_profile_dh_multiple.py
Expand Up @@ -36,10 +36,8 @@ def run(
"""
fig = plt.figure(
figsize=basic_plot_functions.cm2inch(14, 25))

ax = fig.add_subplot(
nrows=4,
ncols=2)

ax = fig.add_subplot(nrows=4, ncols=2)

plot_nr = 0
row = -1
Expand Down Expand Up @@ -232,8 +230,6 @@ def run(
round(std_dev_abs, 2),
fontdict=font_additional_info))
plt.title(title_info, loc='left', fontdict=font_additional_info)
#plt.ylabel("hours")
#plt.ylabel("average electricity [GW]")

# ------------
# Plot legend
Expand Down Expand Up @@ -358,14 +354,25 @@ def plot_radar_plot(
linestyle='--',
linewidth=0.5)

# plot data points
'''ax.scatter(angles, values, color="blue", s=10)'''

'''line_zeros = np.zeros(len(angles_smoothed))
ax.fill_between(
angles_smoothed, #zero coordinates
line_zeros, # line 1
values_smoothed, # line 2
color='blue',
alpha=0.1)'''

# Fill below
ax.fill(
angles,
values,
angles_smoothed, #angles,
values_smoothed, #values,
'blue', #b
alpha=0.1)

# Save fig
print("fig_name: " + str(fig_name))
plt.savefig(fig_name)

if plotshow:
Expand Down

0 comments on commit b3bb4c6

Please sign in to comment.