Skip to content

Commit

Permalink
Add linear wind condition upsampling method to WindRose (#544)
Browse files Browse the repository at this point in the history
* Add LinearNDInterpolant to wind_rose

* Change from returning interpolant to immediately interpolating to values

* Add example to docstring

---------

Co-authored-by: Paul <[email protected]>
Co-authored-by: Rafael M Mudafort <[email protected]>
  • Loading branch information
3 people committed Feb 7, 2023
1 parent 70336ab commit dc2196a
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions floris/tools/wind_rose.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from scipy.interpolate import LinearNDInterpolator, NearestNDInterpolator

import floris.utilities as geo

Expand Down Expand Up @@ -446,6 +447,68 @@ def internal_resample_average_ws_by_wd(self, wd=np.arange(0, 360, 5.0)):
# Update internal data frame
self.df = self.resample_average_ws_by_wd(self.df)

def interpolate(
self,
wind_directions: np.ndarray,
wind_speeds: np.ndarray,
mirror_0_to_360=True,
fill_value=0.0,
method="linear"
):
"""
This method returns a linear interpolant that will return the occurrence
frequency for any given wind direction and wind speed combination(s).
This can be particularly useful when evaluating the wind rose at a
higher frequency than the input data is provided.
Args:
wind_directions (np.ndarray): One or multi-dimensional array containing
the wind direction values at which the wind rose frequency of occurrence
should be evaluated.
wind_speeds (np.ndarray): One or multi-dimensional array containing
the wind speed values at which the wind rose frequency of occurrence
should be evaluated.
mirror_0_to_360 (bool, optional): This function copies the wind rose
frequency values from 0 deg to 360 deg. This can be useful when, for example,
the wind rose is only calculated until 357 deg but then interpolant is
requesting values at 359 deg. Defaults to True.
fill_value (float, optional): Fill value for the interpolant when
interpolating values outside of the data region. Defaults to 0.0.
method (str, optional): The interpolation method. Options are 'linear' and
'nearest'. Recommended usage is 'linear'. Defaults to 'linear'.
Returns:
scipy.interpolate.LinearNDInterpolant: Linear interpolant for the
wind rose currently available in the class (self.df).
Example:
wr = wind_rose.WindRose()
wr.make_wind_rose_from_user_data(...)
freq_floris = wr.interpolate(floris_wind_direction_grid, floris_wind_speed_grid)
"""
if method == "linear":
interpolator = LinearNDInterpolator
elif method == "nearest":
interpolator = NearestNDInterpolator
else:
UserWarning("Unknown interpolation method: '{:s}'".format(method))

# Load windrose information from self
df = self.df.copy()

if mirror_0_to_360:
# Copy values from 0 deg over to 360 deg
df_copy = df[df["wd"] == 0.0].copy()
df_copy["wd"] = 360.0
df = pd.concat([df, df_copy], axis=0)

interp = interpolator(
points=df[["wd", "ws"]],
values=df["freq_val"],
fill_value=fill_value
)
return interp(wind_directions, wind_speeds)

def weibull(self, x, k=2.5, lam=8.0):
"""
This method returns a Weibull distribution corresponding to the input
Expand Down

0 comments on commit dc2196a

Please sign in to comment.