Skip to content

Commit

Permalink
Fix incorrect rotated turbine locations in horizontal plots (#663)
Browse files Browse the repository at this point in the history
* Remove rotation in turbine locations when doing horizontal flow field slice plot

* Update docstring

* Denote plot_turbines as deprecated

* Consolidate turbine plotting functionality

* Fix isort

---------

Co-authored-by: Rafael M Mudafort <rafmudaf@gmail.com>
  • Loading branch information
Bartdoekemeijer and rafmudaf authored Jun 1, 2023
1 parent 5e5bb7f commit d91953a
Showing 1 changed file with 32 additions and 27 deletions.
59 changes: 32 additions & 27 deletions floris/tools/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from __future__ import annotations

import copy
import warnings
from typing import Union

import matplotlib as mpl
Expand All @@ -40,31 +41,31 @@ def plot_turbines(
yaw_angles,
rotor_diameters,
color: str | None = None,
wind_direction: float = 270.0,
):
"""
This function is deprecated and will be removed in v3.5, use `plot_turbines_with_fi` instead.
Plot wind plant layout from turbine locations.
Args:
ax (:py:class:`matplotlib.pyplot.axes`): Figure axes.
layout_x (np.array): Wind turbine locations (east-west).
layout_y (np.array): Wind turbine locations (north-south).
yaw_angles (np.array): Yaw angles of each wind turbine.
D (float): Wind turbine rotor diameter.
color (str): Pyplot color option to plot the turbines.
wind_direction (float): Wind direction (rotates farm)
rotor_diameters (np.array): Wind turbine rotor diameter.
color (str): pyplot color option to plot the turbines.
"""
warnings.warn(
"The `plot_turbines` function is deprecated and will be removed in v3.5, "
"use `plot_turbines_with_fi` instead.",
DeprecationWarning,
stacklevel=2 # This prints the calling function and this function in the warning
)

if color is None:
color = "k"

# Rotate layout to inertial frame for plotting turbines relative to wind direction
coordinates_array = np.array([[x, y, 0.0] for x, y in list(zip(layout_x, layout_y))])
layout_x, layout_y, _, _, _ = rotate_coordinates_rel_west(
np.array([wind_direction]),
coordinates_array
)

for x, y, yaw, d in zip(layout_x[0,0], layout_y[0,0], yaw_angles, rotor_diameters):
for x, y, yaw, d in zip(layout_x, layout_y, yaw_angles, rotor_diameters):
R = d / 2.0
x_0 = x + np.sin(np.deg2rad(yaw)) * R
x_1 = x - np.sin(np.deg2rad(yaw)) * R
Expand All @@ -75,14 +76,16 @@ def plot_turbines(

def plot_turbines_with_fi(
fi: FlorisInterface,
ax=None,
color=None,
wd=None,
yaw_angles=None,
ax: plt.Axes = None,
color: str = None,
wd: np.ndarray = None,
yaw_angles: np.ndarray = None,
):
"""
Wrapper function to plot turbines which extracts the data
from a FLORIS interface object
Plot the wind plant layout from turbine locations gotten from a FlorisInterface object.
Note that this function automatically uses the first wind direction and first wind speed.
Generally, it is most explicit to create a new FlorisInterface with only the single
wind condition that should be plotted.
Args:
fi (:py:class:`floris.tools.floris_interface.FlorisInterface`): FlorisInterface object.
Expand All @@ -101,15 +104,17 @@ def plot_turbines_with_fi(
# Rotate yaw angles to inertial frame for plotting turbines relative to wind direction
yaw_angles = yaw_angles - wind_delta(np.array(wd))

plot_turbines(
ax,
fi.layout_x,
fi.layout_y,
yaw_angles.flatten(),
fi.floris.farm.rotor_diameters.flatten(),
color=color,
wind_direction=fi.floris.flow_field.wind_directions[0],
)
if color is None:
color = "k"

rotor_diameters = fi.floris.farm.rotor_diameters.flatten()
for x, y, yaw, d in zip(fi.layout_x, fi.layout_y, yaw_angles[0,0], rotor_diameters):
R = d / 2.0
x_0 = x + np.sin(np.deg2rad(yaw)) * R
x_1 = x - np.sin(np.deg2rad(yaw)) * R
y_0 = y - np.cos(np.deg2rad(yaw)) * R
y_1 = y + np.cos(np.deg2rad(yaw)) * R
ax.plot([x_0, x_1], [y_0, y_1], color=color)


def add_turbine_id_labels(fi: FlorisInterface, ax: plt.Axes, **kwargs):
Expand Down

0 comments on commit d91953a

Please sign in to comment.