Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collect all layout visualization tools in FLORIS #805

Merged
merged 36 commits into from
Mar 6, 2024

Conversation

paulf81
Copy link
Collaborator

@paulf81 paulf81 commented Feb 15, 2024

Collect all layout visualization tools in FLORIS

Presently, tools for interrogating/plotting the layouts existing, sometimes in duplicate, across FLORIS and FLASC, and even within FLORIS, tools were duplicated between visualizations.py and layout_functions.py. The purpose of this pull request are pulling all the tools into one module (layout_functions.py) in FLORIS, and then importing into FLASC. This pull request also seeks to resolve Issue #804 by ensuring all functions accept turbine_names.

In this PR (and companion pull request in flasc (NREL/flasc#174)), functions are all moved to layout_functions.py, and their form and usage is standardized.

A new example (to be re-organized later (23_layout_visualizations is introduced). This example demonstrates the preferred usage of importing the layout_functions module as lf, and calling each function via lf.xxx().

In each case, either a pyplot axes is passed in or else a new one is created and returned. Also in each case, a FlorisInterface object is passed in to get the locations of the turbines.

The functions in layout_functions.py are intended to each implement one plotting action and can be called sequentially to add layers to the plot.

  • plot_turbine_points: Plot turbines as points on axis
  • plot_turbine_labels: Label the turbines, in default case given FLORIS' 0-index value as a label, but can also accept provided turbine names
  • plot_turbines_rotors: Indicate the turbine rotors (including yaw) on a plot. This is usually most useful for indicating turbine position onto flow visualizaitons
  • plot_waking_directions Draw labeled lines in-between each turbine and label the distance (in D) and wind directions in which the turbines wake each other.
  • shade_region: Add a shaded region to an existing plot, can be useful to identify specific areas, or boundary boxes or phases/farms
  • plot_farm_terrain: Use the hub-height information in FLORIS to make a contour plot of elevation

An example plotting script would be:

import matplotlib.pyplot as plt
import floris.tools.layout_functions as lf
from floris.tools import FlorisInterface

fi = FlorisInterface("inputs/gch.yaml")
fig, ax = plt.subplots()
lf.plot_turbine_points(fi, ax=ax)
lf.plot_turbine_labels(fi, ax=ax)
lf.plot_waking_directions(fi, ax=ax)
plt.show()

A small test module is started (layout_functions_test.py).

Finally, as shown in example above, we removed calls to plt.show() from within functions inside layout_functions.py and adopt a convention that this call should be made by user.

Related issue

#804

@paulf81 paulf81 added enhancement An improvement of an existing feature v4 Focus of FLORIS v4 labels Feb 15, 2024
@paulf81 paulf81 added this to the v4.0 milestone Feb 15, 2024
@paulf81 paulf81 self-assigned this Feb 15, 2024
@paulf81 paulf81 marked this pull request as ready for review February 19, 2024 19:50
@paulf81
Copy link
Collaborator Author

paulf81 commented Feb 20, 2024

@rafmudaf and @misi9170 this is now ready for your review

@rafmudaf
Copy link
Collaborator

Heads up the tests are still failing

@paulf81
Copy link
Collaborator Author

paulf81 commented Feb 20, 2024

Heads up the tests are still failing

Its the examples, that is my bad, I'll get it

floris/tools/__init__.py Outdated Show resolved Hide resolved
floris/tools/layout_functions.py Outdated Show resolved Hide resolved
floris/tools/layout_functions.py Outdated Show resolved Hide resolved
floris/tools/layout_functions.py Outdated Show resolved Hide resolved
floris/tools/layout_functions.py Outdated Show resolved Hide resolved
floris/tools/layout_functions.py Outdated Show resolved Hide resolved
floris/tools/layout_functions.py Outdated Show resolved Hide resolved
floris/tools/visualization.py Show resolved Hide resolved
@misi9170
Copy link
Collaborator

misi9170 commented Mar 3, 2024

I've added a small, indirectly related bugfix to this PR, introduced in #823: I noticed in a place where fi.reinitialize() was accidentally still being called (with argument layout_x, among others) that the error raised was
TypeError: FlorisInterface.reinitialize() got an unexpected keyword argument 'layout_x',
which is confusing when in fact, reinitialize() has been deprecated.

The solution I have was to allow the empty reinitialize() function (as well as calculate_wake()) to accept (and ignore) arbitrary keyword arguments. Now, the intended
NotImplementedError: The reinitialize method has been removed. Please use the set method. See https://nrel.github.io/floris/upgrade_guides/v3_to_v4.html for more information.
is raised when reinitialize() is called with arguments. Hope that's ok to tack on here.

Copy link
Collaborator

@misi9170 misi9170 left a comment

Choose a reason for hiding this comment

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

Approving this now, but I do think @rafmudaf is right that the name of the file should be something more clearly to do with plotting/visualization than layout_functions.py. I've added a suggestion on that above.


def test_plotting_functions():

fi = FlorisInterface(configuration=YAML_INPUT)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Include test for plot_turbines_rotors

Copy link
Collaborator

Choose a reason for hiding this comment

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

I've added this test, but it would also be good to test plot_farm_terrain.
Also, I think I know the answer to this, but is there a better test available? It's good to run these functions, but as is this is only testing that the inputs are of the correct general data type.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, this was a puzzle for me, since they end in a plot, my main thought was just to make sure the functions can run all the way through without erroring. I wasn't sure how to confirm if the plot is "right"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can add the test for plot_farm_terrain, then merge you think if I do it tonight?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep sounds good to me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok great, done and merging!

@rafmudaf rafmudaf self-requested a review March 5, 2024 21:57
@paulf81 paulf81 merged commit 8ac93bf into NREL:v4 Mar 6, 2024
8 checks passed
@paulf81 paulf81 deleted the feature/all_layout_vis_in_floris branch March 6, 2024 03:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An improvement of an existing feature v4 Focus of FLORIS v4
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants