Skip to content

Bug fix: erroneous rotation in turbine locations in horizontal flowfield plots#663

Merged
rafmudaf merged 5 commits intoNatLabRockies:developfrom
Bartdoekemeijer:bugfix/plot_with_fi_rotation
Jun 1, 2023
Merged

Bug fix: erroneous rotation in turbine locations in horizontal flowfield plots#663
rafmudaf merged 5 commits intoNatLabRockies:developfrom
Bartdoekemeijer:bugfix/plot_with_fi_rotation

Conversation

@Bartdoekemeijer
Copy link
Copy Markdown
Collaborator

Bug fix: Turbine locations in horizontal flow field plot

In the release version of FLORIS v3.4, the turbine locations are always rotated with respect to the wind direction in functions visualization.plot_turbines and visualization.plot_turbines_with_fi. However, with the recent change in horizontal flow field plots #578 where the turbine locations remain fixed and instead the flow field rotates, this puts the turbines in the wrong locations in the plot.

Related issue

N/A

Impacted areas of the software

Visualization.

Additional supporting information

Test results, if applicable

Here is a minimal script to reproduce the issue:

import matplotlib.pyplot as plt

import floris.tools.visualization as wakeviz
from floris.tools import FlorisInterface
from floris.tools.visualization import plot_turbines_with_fi

# Load FLORIS
fi = FlorisInterface("inputs/gch.yaml")
fi.reinitialize(wind_directions=[245.0])
horizontal_plane = fi.calculate_horizontal_plane(height=90.0)

# Create the plots
fig, ax = plt.subplots()
wakeviz.visualize_cut_plane(horizontal_plane, ax=ax, title="Horizontal")
plot_turbines_with_fi(fi=fi, ax=ax)
plt.show()

With the current develop branch and FLORIS v3.4, we find:
image

With this Pull Request, we find:
image

@Bartdoekemeijer Bartdoekemeijer changed the title Remove rotation in turbine locations when doing horizontal flow field slice plot Bug fix: erroneous rotation in turbine locations in horizontal flowfield plots May 26, 2023
@Bartdoekemeijer Bartdoekemeijer added bug Something isn't working v3 Label to denote focus on v3 labels May 26, 2023
@rafmudaf rafmudaf self-assigned this May 30, 2023
@rafmudaf rafmudaf self-requested a review May 30, 2023 14:59
Copy link
Copy Markdown
Collaborator

@rafmudaf rafmudaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, we allow to pass yaw angles to plot_turbines_with_fi in order to rotate the lines plotted representing the turbines. However, plot_turbines does not take yaw angles so these two now have different functionality despite their intent to be equivalent. Also, note that both yaw angles and the wind direction are needed to rotate the yaw angles correctly. Somehow this difference between the two should be resolved, though I'm not sure what is best aside from finally dealing with how FLORIS handles yaw angles.

We could consider dropping plot_turbines in favor of the function requiring a FlorisInterface object for simplicity - it's the one I always use anyway.

@paulf81
Copy link
Copy Markdown
Collaborator

paulf81 commented May 30, 2023

I would favor the dropping plot_turbines, I also prefer the with_fi version.

Also, just confirming I pulled this down and runs correctly on my machine

@Bartdoekemeijer
Copy link
Copy Markdown
Collaborator Author

That sounds good to me! We can maybe add a disclaimer when people run plot_turbines for now warning that this function will be deprecated in v3.5? Just so that we don't do anything API breaking immediately.

@paulf81
Copy link
Copy Markdown
Collaborator

paulf81 commented May 31, 2023

I like this approach, @rafmudaf?

@rafmudaf
Copy link
Copy Markdown
Collaborator

I agree. I'll make the change here.

@rafmudaf
Copy link
Copy Markdown
Collaborator

rafmudaf commented May 31, 2023

I've made the change suggested above. The warning message looks like this:

(floris) >>mbp@floris/examples (pr/Bartdoekemeijer/663 *$)$ python 01_opening_floris_computing_power.py 
floris/examples/01_opening_floris_computing_power.py:15: DeprecationWarning: The `plot_turbines` method is deprecated and will be removed in v3.5, use `plot_turbines_with_fi` instead.
  plot_turbines()

Note I used the stdlib warnings module instead of the floris logging module because this is a specific Python idiom. See here for more info.

@rafmudaf
Copy link
Copy Markdown
Collaborator

And also here's a modified script to demo that includes a yawed leading turbine:

import matplotlib.pyplot as plt
import numpy as np
import floris.tools.visualization as wakeviz
from floris.tools import FlorisInterface
from floris.tools.visualization import plot_turbines_with_fi

fi = FlorisInterface("inputs/gch.yaml")
fi.reinitialize(wind_directions=[245.0])
horizontal_plane = fi.calculate_horizontal_plane(height=90.0)

fig, ax = plt.subplots()
wakeviz.visualize_cut_plane(horizontal_plane, ax=ax, title="Horizontal")
yaw_angles = np.zeros((1,1,3))
yaw_angles[0,0,0] = 20
plot_turbines_with_fi(fi=fi, ax=ax, yaw_angles=yaw_angles)
wakeviz.show_plots()

@rafmudaf rafmudaf requested a review from paulf81 May 31, 2023 23:13
Copy link
Copy Markdown
Collaborator

@paulf81 paulf81 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you!

@rafmudaf
Copy link
Copy Markdown
Collaborator

rafmudaf commented Jun 1, 2023

I've made note of this API change in #488.

And with that, I'll go ahead and merge. Thanks for the fix @Bartdoekemeijer.

@rafmudaf rafmudaf merged commit d91953a into NatLabRockies:develop Jun 1, 2023
@Bartdoekemeijer Bartdoekemeijer deleted the bugfix/plot_with_fi_rotation branch July 4, 2023 12:50
@rafmudaf rafmudaf mentioned this pull request Oct 26, 2023
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working v3 Label to denote focus on v3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants