Skip to content
Snippets Groups Projects
Commit f496131d authored by Mads M. Pedersen's avatar Mads M. Pedersen
Browse files

add normalize_with parameter in plot functions

parent ab2a5cdd
No related branches found
No related tags found
No related merge requests found
......@@ -96,7 +96,8 @@ class FlowMap(FlowBox):
"""
return self.aep_xylk(wt_type, normalize_probabilities, with_wake_loss).sum(['wd', 'ws'])
def plot(self, data, clabel, levels=100, cmap=None, plot_colorbar=True, plot_windturbines=True, ax=None):
def plot(self, data, clabel, levels=100, cmap=None, plot_colorbar=True, plot_windturbines=True,
normalize_with=1, ax=None):
"""Plot data as contouf map
Parameters
......@@ -123,6 +124,7 @@ class FlowMap(FlowBox):
cmap = 'Blues_r'
if ax is None:
ax = plt.gca()
n = normalize_with
if self.plane[0] == "YZ":
y = self.X[0]
x = np.zeros_like(y) + self.plane[1]
......@@ -134,32 +136,33 @@ class FlowMap(FlowBox):
y = np.arange(y.min(), y.max())
x = np.zeros_like(y) + self.plane[1]
z = self.simulationResult.windFarmModel.site.elevation(x, y)
ax.plot(y, z, 'k')
ax.plot(y / n, z / n, 'k')
else:
# xarray gives strange levels
# c = data.isel(h=0).plot(levels=levels, cmap=cmap, ax=ax, add_colorbar=plot_colorbar)
c = ax.contourf(self.X, self.Y, data.isel(h=0).data, levels=levels, cmap=cmap)
c = ax.contourf(self.X / n, self.Y / n, data.isel(h=0).data, levels=levels, cmap=cmap)
if plot_colorbar:
plt.colorbar(c, label=clabel, ax=ax)
if plot_windturbines:
self.plot_windturbines(ax=ax)
self.plot_windturbines(normalize_with=normalize_with, ax=ax)
return c
def plot_windturbines(self, ax=None):
def plot_windturbines(self, normalize_with=1, ax=None):
fm = self.windFarmModel
yaw = self.simulationResult.Yaw.sel(wd=self.wd[0]).mean(['ws']).data
if self.plane[0] == "YZ":
x_i, y_i = self.simulationResult.x.values, self.simulationResult.y.values
h_i = self.simulationResult.h.values
z_i = self.simulationResult.windFarmModel.site.elevation(x_i, y_i)
fm.windTurbines.plot_yz(y_i, z_i, h_i, wd=self.wd, yaw=yaw, ax=ax)
fm.windTurbines.plot_yz(y_i, z_i, h_i, wd=self.wd, yaw=yaw, normalize_with=normalize_with, ax=ax)
else: # self.plane[0] == "XY":
fm.windTurbines.plot_xy(self.simulationResult.x, self.simulationResult.y, self.simulationResult.type.data,
wd=self.wd, yaw=yaw, ax=ax)
wd=self.wd, yaw=yaw, normalize_with=normalize_with, ax=ax)
def plot_wake_map(self, levels=100, cmap=None, plot_colorbar=True, plot_windturbines=True, ax=None):
def plot_wake_map(self, levels=100, cmap=None, plot_colorbar=True, plot_windturbines=True,
normalize_with=1, ax=None):
"""Plot effective wind speed contourf map
Parameters
......@@ -179,7 +182,7 @@ class FlowMap(FlowBox):
"""
return self.plot(self.WS_eff.mean(['wd', 'ws']), clabel='wind speed [m/s]',
levels=levels, cmap=cmap, plot_colorbar=plot_colorbar,
plot_windturbines=plot_windturbines, ax=ax)
plot_windturbines=plot_windturbines, normalize_with=normalize_with, ax=ax)
def plot_ti_map(self, levels=100, cmap=None, plot_colorbar=True, plot_windturbines=True, ax=None):
"""Plot effective turbulence intensity contourf map
......
......@@ -195,7 +195,7 @@ class WindTurbines():
self.power_funcs = add_grad(self.power_splines)
self.ct_funcs = add_grad(self.ct_splines)
def plot_xy(self, x, y, types=None, wd=None, yaw=0, ax=None):
def plot_xy(self, x, y, types=None, wd=None, yaw=0, normalize_with=1, ax=None):
"""Plot wind farm layout including type name and diameter
Parameters
......@@ -225,7 +225,10 @@ class WindTurbines():
assert len(x) == len(y)
types = (np.zeros_like(x) + types).astype(int) # ensure same length as x
yaw = np.zeros_like(x) + yaw
for i, (x_, y_, d, t, yaw_) in enumerate(zip(x, y, self.diameter(types), types, yaw)):
x, y, D = [np.asarray(v) / normalize_with for v in [x, y, self.diameter(types)]]
for i, (x_, y_, d, t, yaw_) in enumerate(zip(x, y, D, types, yaw)):
if wd is None or len(np.atleast_1d(wd)) > 1:
circle = Circle((x_, y_), d / 2, ec=colors[t], fc="None")
ax.add_artist(circle)
......@@ -244,7 +247,7 @@ class WindTurbines():
ax.legend(loc=1)
ax.axis('equal')
def plot_yz(self, y, z=None, h=None, types=None, wd=270, yaw=0, ax=None):
def plot_yz(self, y, z=None, h=None, types=None, wd=270, yaw=0, normalize_with=1, ax=None):
"""Plot wind farm layout in yz-plane including type name and diameter
Parameters
......@@ -280,8 +283,9 @@ class WindTurbines():
from matplotlib.patches import Circle
yaw = np.zeros_like(y) + yaw
y, z, h, D = [v / normalize_with for v in [y, z, h, self.diameter(types)]]
for i, (y_, z_, h_, d, t, yaw_) in enumerate(
zip(y, z, h, self.diameter(types), types, yaw)):
zip(y, z, h, D, types, yaw)):
circle = Ellipse((y_, h_ + z_), d * np.sin(np.deg2rad(wd - yaw_)), d, ec=colors[t], fc="None")
ax.add_artist(circle)
ax.plot([y_, y_], [z_, z_ + h_], 'k')
......@@ -290,13 +294,13 @@ class WindTurbines():
for t, m, c in zip(np.unique(types), markers, colors):
ax.plot([], [], '2', color=c, label=self._names[int(t)])
for i, (y_, z_, h_, d) in enumerate(zip(y, z, h, self.diameter(types))):
for i, (y_, z_, h_, d) in enumerate(zip(y, z, h, D)):
ax.annotate(i, (y_ + d / 2, z_ + h_ + d / 2), fontsize=7)
ax.legend(loc=1)
ax.axis('equal')
def plot(self, x, y, types=None, wd=None, yaw=0, ax=None):
return self.plot_xy(x, y, types, wd, yaw, ax)
def plot(self, x, y, types=None, wd=None, yaw=0, normalize_with=1, ax=None):
return self.plot_xy(x, y, types, wd, yaw, normalize_with, ax)
@staticmethod
def from_WindTurbines(wt_lst):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment