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

Feature: Add external library functionality #521

Closed
Closed
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
repos:
- repo: https://github.com/timothycrosley/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
name: isort
stages: [commit]

- repo: https://github.com/psf/black
rev: 22.6.0
rev: 23.1.0
hooks:
- id: black
name: black
Expand All @@ -23,7 +23,7 @@ repos:
# args: [--no-strict-optional, --ignore-missing-imports]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -37,7 +37,7 @@ repos:
args: [--autofix]

- repo: https://github.com/pycqa/flake8
rev: '4.0.1'
rev: '6.0.0'
hooks:
- id: flake8
args: [--max-line-length=120]
25 changes: 0 additions & 25 deletions docs/dev_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,31 +58,6 @@ to fit a specific use case or purpose. If significant development has
happened locally, then [merge conflicts](https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts)
are likely and should be resolved as early as possible.


## Code quality tools

FLORIS is configured to use tools to automatically check and enforce
aspects of code quality. In general, these should be adopted by all
developers and incorporated into the development workflow. Most
tools are configured in [pyproject.toml](https://github.com/NREL/floris/blob/main/pyproject.toml),
but some may have a dedicated configuration file.

### isort

Import lines can easily get out of hand and cause unnecessary distraction
in source code files. [isort](https://pycqa.github.io/isort/index.html)
it used to automatically manage imports in the source code. It can be run
directly with the following command:

```bash
isort <path to file>
isort dir/*
```

This tool was initially configured in [#535](https://github.com/NREL/floris/pull/535),
and additional information on specific decisions can be found there.


## Testing

In order to maintain a level of confidence in the software, FLORIS is expected
Expand Down
10 changes: 0 additions & 10 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ impact on wind turbine wakes.
Load an input file that describes a wind farm with two turbines
of different types and plot the wake profiles.

### 23_visualize_layout.py
Use the visualize_layout function to provide diagram visualization
of a turbine layout within FLORIS


## Optimization

Expand All @@ -112,12 +108,6 @@ Construct wind farm yaw settings for a full wind rose based on the
optimized yaw settings at a single wind speed. Then, compare
results to the baseline no-yaw configuration.

### 12_optimize_yaw_in_parallel.py
Comparable to the above but perform all the computations using
parallel processing. In the current example, use 16 cores
simultaneously to calculate the AEP and perform a wake steering
yaw angle optimization for multiple wind speeds.

### 13_optimize_yaw_with_neighboring_farm.py
Same as above but considering the effects of a nearby wind farm.

Expand Down
2 changes: 1 addition & 1 deletion examples/01_opening_floris_computing_power.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
# See https://floris.readthedocs.io for documentation


import matplotlib.pyplot as plt
import numpy as np

from floris.tools import FlorisInterface


"""
This example creates a FLORIS instance
1) Makes a two-turbine layout
Expand Down
16 changes: 8 additions & 8 deletions examples/02_visualizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

import matplotlib.pyplot as plt

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

from floris.tools.visualization import visualize_cut_plane
from floris.tools.visualization import plot_rotor_values

"""
This example initializes the FLORIS software, and then uses internal
Expand Down Expand Up @@ -52,9 +52,9 @@
# Create the plots
fig, ax_list = plt.subplots(3, 1, figsize=(10, 8))
ax_list = ax_list.flatten()
wakeviz.visualize_cut_plane(horizontal_plane, ax=ax_list[0], title="Horizontal")
wakeviz.visualize_cut_plane(y_plane, ax=ax_list[1], title="Streamwise profile")
wakeviz.visualize_cut_plane(cross_plane, ax=ax_list[2], title="Spanwise profile")
visualize_cut_plane(horizontal_plane, ax=ax_list[0], title="Horizontal")
visualize_cut_plane(y_plane, ax=ax_list[1], title="Streamwise profile")
visualize_cut_plane(cross_plane, ax=ax_list[2], title="Spanwise profile")

# FLORIS further includes visualization methods for visualing the rotor plane of each
# Turbine in the simulation
Expand All @@ -64,7 +64,7 @@
fi.calculate_wake()

# Plot the values at each rotor
fig, axes, _ , _ = wakeviz.plot_rotor_values(fi.floris.flow_field.u, wd_index=0, ws_index=0, n_rows=1, n_cols=3, return_fig_objects=True)
fig, axes, _ , _ = plot_rotor_values(fi.floris.flow_field.u, wd_index=0, ws_index=0, n_rows=1, n_cols=3, return_fig_objects=True)
fig.suptitle("Rotor Plane Visualization, Original Resolution")

# FLORIS supports multiple types of grids for capturing wind speed
Expand All @@ -86,7 +86,7 @@
fi.calculate_wake()

# Plot the values at each rotor
fig, axes, _ , _ = wakeviz.plot_rotor_values(fi.floris.flow_field.u, wd_index=0, ws_index=0, n_rows=1, n_cols=3, return_fig_objects=True)
fig, axes, _ , _ = plot_rotor_values(fi.floris.flow_field.u, wd_index=0, ws_index=0, n_rows=1, n_cols=3, return_fig_objects=True)
fig.suptitle("Rotor Plane Visualization, 10x10 Resolution")

wakeviz.show_plots()
plt.show()
35 changes: 17 additions & 18 deletions examples/03_making_adjustments.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
import matplotlib.pyplot as plt
import numpy as np

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

from floris.tools import visualize_cut_plane #, plot_turbines_with_fi

"""
This example makes changes to the given input file through the script.
Expand All @@ -39,53 +38,53 @@

# Plot a horizatonal slice of the initial configuration
horizontal_plane = fi.calculate_horizontal_plane(height=90.0)
wakeviz.visualize_cut_plane(horizontal_plane, ax=axarr[0], title="Initial setup", min_speed=MIN_WS, max_speed=MAX_WS)
visualize_cut_plane(horizontal_plane, ax=axarr[0], title="Initial setup", minSpeed=MIN_WS, maxSpeed=MAX_WS)


# Change the wind speed
horizontal_plane = fi.calculate_horizontal_plane(ws=[7.0], height=90.0)
wakeviz.visualize_cut_plane(horizontal_plane, ax=axarr[1], title="Wind speed at 7 m/s", min_speed=MIN_WS, max_speed=MAX_WS)
visualize_cut_plane(horizontal_plane, ax=axarr[1], title="Wind speed at 7 m/s", minSpeed=MIN_WS, maxSpeed=MAX_WS)


# Change the wind shear, reset the wind speed, and plot a vertical slice
fi.reinitialize( wind_shear=0.2, wind_speeds=[8.0] )
y_plane = fi.calculate_y_plane(crossstream_dist=0.0)
wakeviz.visualize_cut_plane(y_plane, ax=axarr[2], title="Wind shear at 0.2", min_speed=MIN_WS, max_speed=MAX_WS)
visualize_cut_plane(y_plane, ax=axarr[2], title="Wind shear at 0.2", minSpeed=MIN_WS, maxSpeed=MAX_WS)


# # Change the farm layout
# Change the farm layout
N = 3 # Number of turbines per row and per column
X, Y = np.meshgrid(
5.0 * fi.floris.farm.rotor_diameters[0][0][0] * np.arange(0, N, 1),
5.0 * fi.floris.farm.rotor_diameters[0][0][0] * np.arange(0, N, 1),
)
fi.reinitialize(layout_x=X.flatten(), layout_y=Y.flatten(), wind_directions=[360.0])
fi.reinitialize(layout_x=X.flatten(), layout_y=Y.flatten())
horizontal_plane = fi.calculate_horizontal_plane(height=90.0)
wakeviz.visualize_cut_plane(horizontal_plane, ax=axarr[3], title="3x3 Farm", min_speed=MIN_WS, max_speed=MAX_WS)
wakeviz.add_turbine_id_labels(fi, axarr[3], color="w", backgroundcolor="k")
wakeviz.plot_turbines_with_fi(fi, axarr[3])
visualize_cut_plane(horizontal_plane, ax=axarr[3], title="3x3 Farm", minSpeed=MIN_WS, maxSpeed=MAX_WS)


# Change the yaw angles and configure the plot differently
yaw_angles = np.zeros((1, 1, N * N))

## First row
yaw_angles[:,:,0] = 30.0
yaw_angles[:,:,3] = -30.0
yaw_angles[:,:,6] = 30.0
yaw_angles[:,:,1] = -30.0
yaw_angles[:,:,2] = 30.0

## Second row
yaw_angles[:,:,1] = -30.0
yaw_angles[:,:,3] = -30.0
yaw_angles[:,:,4] = 30.0
yaw_angles[:,:,7] = -30.0
yaw_angles[:,:,5] = -30.0

horizontal_plane = fi.calculate_horizontal_plane(yaw_angles=yaw_angles, height=90.0)
wakeviz.visualize_cut_plane(horizontal_plane, ax=axarr[4], title="Yawesome art", cmap="PuOr", min_speed=MIN_WS, max_speed=MAX_WS)
wakeviz.plot_turbines_with_fi(fi, axarr[4], yaw_angles=yaw_angles, color="c")
visualize_cut_plane(horizontal_plane, ax=axarr[4], title="Yawesome art", cmap="PuOr", minSpeed=MIN_WS, maxSpeed=MAX_WS)
# plot_turbines_with_fi(axarr[8], fi)


# Plot the cross-plane of the 3x3 configuration
cross_plane = fi.calculate_cross_plane(yaw_angles=yaw_angles, downstream_dist=610.0)
wakeviz.visualize_cut_plane(cross_plane, ax=axarr[5], title="Cross section at 610 m", min_speed=MIN_WS, max_speed=MAX_WS)
visualize_cut_plane(cross_plane, ax=axarr[5], title="Cross section at 610 m", minSpeed=MIN_WS, maxSpeed=MAX_WS)
axarr[5].invert_xaxis()


wakeviz.show_plots()
plt.show()
2 changes: 1 addition & 1 deletion examples/04_sweep_wind_directions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import numpy as np

from floris.tools import FlorisInterface
from floris.tools.visualization import visualize_cut_plane


"""
Expand Down Expand Up @@ -71,5 +72,4 @@
ax.legend()
ax.set_xlabel('Wind Direction (deg)')
ax.set_ylabel('Power (kW)')

plt.show()
2 changes: 1 addition & 1 deletion examples/05_sweep_wind_speeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import numpy as np

from floris.tools import FlorisInterface

from floris.tools.visualization import visualize_cut_plane

"""
05_sweep_wind_speeds
Expand Down
2 changes: 1 addition & 1 deletion examples/06_sweep_wind_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
# See https://floris.readthedocs.io for documentation


import enum
import matplotlib.pyplot as plt
import numpy as np

from floris.tools import FlorisInterface


"""
06_sweep_wind_conditions

Expand Down
2 changes: 0 additions & 2 deletions examples/07_calc_aep_from_rose.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
import numpy as np
import pandas as pd
from scipy.interpolate import NearestNDInterpolator

from floris.tools import FlorisInterface


"""
This example demonstrates how to calculate the Annual Energy Production (AEP)
of a wind farm using wind rose information stored in a .csv file.
Expand Down
28 changes: 8 additions & 20 deletions examples/08_calc_aep_from_rose_use_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@

# See https://floris.readthedocs.io for documentation

import numpy as np

import floris.tools.visualization as wakeviz
from floris.tools import (
FlorisInterface,
wind_rose,
WindRose
)

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.interpolate import NearestNDInterpolator
from floris.tools import FlorisInterface, WindRose, wind_rose

"""
This example demonstrates how to calculate the Annual Energy Production (AEP)
Expand All @@ -47,8 +44,7 @@
# floris object and assign the layout, wind speed and wind direction arrays.
D = 126.0 # Rotor diameter for the NREL 5 MW
fi.reinitialize(
layout_x=[0.0, 5* D, 10 * D],
layout_y=[0.0, 0.0, 0.0],
layout=[[0.0, 5* D, 10 * D], [0.0, 0.0, 0.0]]
)

# Compute the AEP using the default settings
Expand All @@ -68,19 +64,11 @@
)
print("Farm AEP (with cut_in/out specified): {:.3f} GWh".format(aep / 1.0e9))

# Compute the AEP a final time, this time marking one of the turbines as
# belonging to another farm by setting its weight to 0
turbine_weights = np.array([1.0, 1.0, 0.0])
aep = fi.get_farm_AEP_wind_rose_class(
wind_rose=wind_rose,
turbine_weights= turbine_weights
)
print("Farm AEP (one turbine removed from power calculation): {:.3f} GWh".format(aep / 1.0e9))

# Finally, we can also compute the AEP while ignoring all wake calculations.
# This can be useful to quantity the annual wake losses in the farm. Such
# calculations can be facilitated by enabling the 'no_wake' handle.
aep_no_wake = fi.get_farm_AEP_wind_rose_class(wind_rose=wind_rose, no_wake=True)
print("Farm AEP (no_wake=True): {:.3f} GWh".format(aep_no_wake / 1.0e9))

wakeviz.show_plots()

plt.show()
5 changes: 2 additions & 3 deletions examples/09_compare_farm_power_with_neighbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
# See https://floris.readthedocs.io for documentation


import matplotlib.pyplot as plt
import numpy as np

import pandas as pd
from floris.tools import FlorisInterface

import matplotlib.pyplot as plt

"""
This example demonstrates how to use turbine_wieghts to define a set of turbines belonging to a neighboring farm which
Expand Down
8 changes: 4 additions & 4 deletions examples/10_opt_yaw_single_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

# See https://floris.readthedocs.io for documentation

import matplotlib.pyplot as plt
import numpy as np

import matplotlib.pyplot as plt
from floris.tools import FlorisInterface
from floris.tools.optimization.yaw_optimization.yaw_optimizer_sr import YawOptimizationSR

from floris.tools.optimization.yaw_optimization.yaw_optimizer_sr import (
YawOptimizationSR,
)

"""
This example demonstrates how to perform a yaw optimization for multiple wind directions and 1 wind speed.
Expand Down
8 changes: 4 additions & 4 deletions examples/11_opt_yaw_multiple_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

# See https://floris.readthedocs.io for documentation

import matplotlib.pyplot as plt
import numpy as np

import matplotlib.pyplot as plt
from floris.tools import FlorisInterface
from floris.tools.optimization.yaw_optimization.yaw_optimizer_sr import YawOptimizationSR

from floris.tools.optimization.yaw_optimization.yaw_optimizer_sr import (
YawOptimizationSR,
)

"""
This example demonstrates how to perform a yaw optimization for multiple wind directions and multiple wind speeds.
Expand Down
7 changes: 3 additions & 4 deletions examples/12_optimize_yaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@


from time import perf_counter as timerpc

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

from floris.tools import FlorisInterface
from floris.tools.optimization.yaw_optimization.yaw_optimizer_sr import YawOptimizationSR

from floris.tools.optimization.yaw_optimization.yaw_optimizer_sr import (
YawOptimizationSR,
)

"""
This example demonstrates how to perform a yaw optimization and evaluate the performance over a full wind rose.
Expand Down
Loading