Skip to content

Commit

Permalink
Adds classes to structure wind energy data for FLORIS model (#775)
Browse files Browse the repository at this point in the history
* move files around to get started

* move files around to get started

* ignore unused in __init__ files

* Consolidate wind rose and time series into one module

* Update init

* Update tests

* Add unpack functions

* Add grid and unpack tests

* Small refactor

* Add resample function

* Test resample

* Add plot wind rose function

* Add new wind rose usage example

* Delete old code

* add super class to import

* Add a super class and inheritance

* Add wind_data to reinitialize (also ruffing)

* Show example of reinit off wind_data objects

* Update how compute 0 freq works

* Test computing all cases

* add n_findex calculation and test

* Add unpack_freq function

* Get aep using wind data

* Move unpack_for functions to super class

* simplify get_farm_AEP_with_wind_data

* Add docstrings

* bugfix

* Finalize example

* Rename module file and base class

* Add description to example explaining plan for updates.

* providing unpack() on base class; renaming example.

* Inheritance clarified; some cleanup.

* Remove copy()s (can point to same memory).

* Small fixes throughout.

* Python back compatibility type-hinting issue.

* Maintain consistent formatting

This preserves the style defined in v3 style guide (#292)

* Spell check

* Remove outdated comments

* Expand docs for wind data unit tests

* Add dimensions to doc string

* Add context to to_wind_rose test comments

* Add error to reinitialize

* Explain what happens in default cases for WindRose

* Rename price to value

* Add check on ti and  value

* Fix bin minimum

* remove wind data import

* Import WindDataBase correctly

* Spell check and formatting

---------

Co-authored-by: misi9170 <[email protected]>
Co-authored-by: Rafael M Mudafort <[email protected]>
  • Loading branch information
3 people authored Jan 25, 2024
1 parent e08f266 commit 420fb0f
Show file tree
Hide file tree
Showing 8 changed files with 1,031 additions and 2,168 deletions.
84 changes: 84 additions & 0 deletions examples/34_wind_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Copyright 2024 NREL

# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

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

import matplotlib.pyplot as plt
import numpy as np

from floris.tools import (
FlorisInterface,
TimeSeries,
WindRose,
)
from floris.utilities import wrap_360


"""
This example is meant to be temporary and may be updated by a later pull request. Before we
release v4, we intend to propagate the TimeSeries and WindRose objects through the other relevant
examples, and change this example to demonstrate more advanced (as yet, not implemented)
functionality of the WindData objects (such as electricity pricing etc).
"""


# Generate a random time series of wind speeds, wind directions and turbulence intensities
N = 500
wd_array = wrap_360(270 * np.ones(N) + np.random.randn(N) * 20)
ws_array = np.clip(8 * np.ones(N) + np.random.randn(N) * 8, 3, 50)
ti_array = np.clip(0.1 * np.ones(N) + np.random.randn(N) * 0.05, 0, 0.25)

fig, axarr = plt.subplots(3, 1, sharex=True, figsize=(7, 4))
ax = axarr[0]
ax.plot(wd_array, marker=".", ls="None")
ax.set_ylabel("Wind Direction")
ax = axarr[1]
ax.plot(ws_array, marker=".", ls="None")
ax.set_ylabel("Wind Speed")
ax = axarr[2]
ax.plot(ti_array, marker=".", ls="None")
ax.set_ylabel("Turbulence Intensity")


# Build the time series
time_series = TimeSeries(wd_array, ws_array) # , turbulence_intensity=ti_array)

# Now build the wind rose
wind_rose = time_series.to_wind_rose()

# Plot the wind rose
fig, ax = plt.subplots(subplot_kw={"polar": True})
wind_rose.plot_wind_rose(ax=ax)

# Now set up a FLORIS model and initialize it using the time series and wind rose
fi = FlorisInterface("inputs/gch.yaml")
fi.reinitialize(layout_x=[0, 500.0], layout_y=[0.0, 0.0])

fi_time_series = fi.copy()
fi_wind_rose = fi.copy()

fi_time_series.reinitialize(wind_data=time_series)
fi_wind_rose.reinitialize(wind_data=wind_rose)

fi_time_series.calculate_wake()
fi_wind_rose.calculate_wake()

time_series_power = fi_time_series.get_farm_power()
wind_rose_power = fi_wind_rose.get_farm_power()

time_series_aep = fi_time_series.get_farm_AEP_with_wind_data(time_series)
wind_rose_aep = fi_wind_rose.get_farm_AEP_with_wind_data(wind_rose)

print(f"AEP from TimeSeries {time_series_aep / 1e9:.2f} GWh")
print(f"AEP from WindRose {wind_rose_aep / 1e9:.2f} GWh")

plt.show()
25 changes: 14 additions & 11 deletions floris/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,21 @@
visualize_cut_plane,
visualize_quiver,
)
from .wind_rose import WindRose
from .wind_data import (
TimeSeries,
WindRose,
)


# from floris.tools import (
# cut_plane,
# floris_interface,
# interface_utilities,
# layout_functions,
# optimization,
# plotting,
# power_rose,
# rews,
# visualization,
# wind_rose,
# cut_plane,
# floris_interface,
# interface_utilities,
# layout_functions,
# optimization,
# plotting,
# power_rose,
# rews,
# visualization,
# wind_rose,
# )
Loading

0 comments on commit 420fb0f

Please sign in to comment.