Skip to content

Commit

Permalink
formatting wind data
Browse files Browse the repository at this point in the history
  • Loading branch information
ejsimley committed Feb 23, 2024
1 parent d204ee1 commit ecb5c2a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
3 changes: 1 addition & 2 deletions examples/34_wind_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import matplotlib.pyplot as plt
import numpy as np

Expand Down Expand Up @@ -52,7 +51,7 @@
# Plot the wind rose
fig, ax = plt.subplots(subplot_kw={"polar": True})
wind_ti_rose.plot_wind_rose(ax=ax)
wind_ti_rose.plot_wind_rose(ax=ax,wind_rose_var="ti")
wind_ti_rose.plot_wind_rose(ax=ax, wind_rose_var="ti")

# Now set up a FLORIS model and initialize it using the time series and wind rose
fi = FlorisInterface("inputs/gch.yaml")
Expand Down
48 changes: 26 additions & 22 deletions floris/tools/wind_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from __future__ import annotations

from abc import abstractmethod
Expand Down Expand Up @@ -383,7 +382,7 @@ def plot_ti_over_ws(
if ax is None:
_, ax = plt.subplots()

ax.plot(self.ws_flat, self.ti_table_flat*100, marker=marker, ls=ls, color=color)
ax.plot(self.ws_flat, self.ti_table_flat * 100, marker=marker, ls=ls, color=color)
ax.set_xlabel("Wind Speed (m/s)")
ax.set_ylabel("Turbulence Intensity (%)")
ax.grid(True)
Expand Down Expand Up @@ -432,7 +431,7 @@ def __init__(

if not isinstance(wind_speeds, np.ndarray):
raise TypeError("wind_speeds must be a NumPy array")

if not isinstance(turbulence_intensities, np.ndarray):
raise TypeError("turbulence_intensities must be a NumPy array")

Expand All @@ -449,10 +448,14 @@ def __init__(
if not freq_table.shape[1] == len(wind_speeds):
raise ValueError("freq_table second dimension must equal len(wind_speeds)")
if not freq_table.shape[2] == len(turbulence_intensities):
raise ValueError("freq_table third dimension must equal len(turbulence_intensities)")
raise ValueError(
"freq_table third dimension must equal len(turbulence_intensities)"
)
self.freq_table = freq_table
else:
self.freq_table = np.ones((len(wind_directions), len(wind_speeds), len(turbulence_intensities)))
self.freq_table = np.ones(
(len(wind_directions), len(wind_speeds), len(turbulence_intensities))
)

# Normalize freq table
self.freq_table = self.freq_table / np.sum(self.freq_table)
Expand All @@ -465,7 +468,9 @@ def __init__(
if not value_table.shape[1] == len(wind_speeds):
raise ValueError("value_table second dimension must equal len(wind_speeds)")
if not value_table.shape[2] == len(turbulence_intensities):
raise ValueError("value_table third dimension must equal len(turbulence_intensities)")
raise ValueError(
"value_table third dimension must equal len(turbulence_intensities)"
)
self.value_table = value_table

# Save whether zero occurrence cases should be computed
Expand Down Expand Up @@ -573,13 +578,11 @@ def resample_wind_rose(self, wd_step=None, ws_step=None, ti_step=None):
if ti_step is None:
if len(self.turbulence_intensities) >= 2:
ti_step = self.turbulence_intensities[1] - self.turbulence_intensities[0]
else: # wind rose will have only a single turbulence intensity, and we assume a ti_step of 1
else: # wind rose will have only a single TI, and we assume a ti_step of 1
ti_step = 1.0

# Pass the flat versions of each quantity to build a TimeSeries model
time_series = TimeSeries(
self.wd_flat, self.ws_flat, self.ti_flat, self.value_table_flat
)
time_series = TimeSeries(self.wd_flat, self.ws_flat, self.ti_flat, self.value_table_flat)

# Now build a new wind rose using the new steps
return time_series.to_wind_ti_rose(
Expand Down Expand Up @@ -628,21 +631,23 @@ def plot_wind_rose(
"""

if wind_rose_var not in {"ws", "ti"}:
raise ValueError("wind_rose_var must be either \"ws\" or \"ti\" for wind speed or turbulence intensity, respectively.")
raise ValueError(
'wind_rose_var must be either "ws" or "ti" for wind speed or turbulence intensity.'
)

# Get a resampled wind_rose
if wind_rose_var == "ws":
if wind_rose_var_step is None:
wind_rose_var_step = 5.0
wind_rose_resample = self.resample_wind_rose(wd_step, ws_step=wind_rose_var_step)
var_bins = wind_rose_resample.wind_speeds
freq_table = wind_rose_resample.freq_table.sum(2) # sum along TI dimension
else: # wind_rose_var == "ti"
freq_table = wind_rose_resample.freq_table.sum(2) # sum along TI dimension
else: # wind_rose_var == "ti"
if wind_rose_var_step is None:
wind_rose_var_step = 0.04
wind_rose_resample = self.resample_wind_rose(wd_step, ti_step=wind_rose_var_step)
var_bins = wind_rose_resample.turbulence_intensities
freq_table = wind_rose_resample.freq_table.sum(1) # sum along wind speed dimension
freq_table = wind_rose_resample.freq_table.sum(1) # sum along wind speed dimension

wd_bins = wind_rose_resample.wind_directions

Expand Down Expand Up @@ -678,7 +683,6 @@ def plot_wind_rose(

return ax


def plot_ti_over_ws(
self,
ax=None,
Expand Down Expand Up @@ -708,9 +712,9 @@ def plot_ti_over_ws(

# get mean TI for each wind speed by averaging along wind direction and
# TI dimensions
mean_ti_values = (self.ti_grid*self.freq_table).sum((0,2))/self.freq_table.sum((0,2))
mean_ti_values = (self.ti_grid * self.freq_table).sum((0, 2)) / self.freq_table.sum((0, 2))

ax.plot(self.wind_speeds, mean_ti_values*100, marker=marker, ls=ls, color=color)
ax.plot(self.wind_speeds, mean_ti_values * 100, marker=marker, ls=ls, color=color)
ax.set_xlabel("Wind Speed (m/s)")
ax.set_ylabel("Mean Turbulence Intensity (%)")
ax.grid(True)
Expand Down Expand Up @@ -972,7 +976,7 @@ def to_wind_rose(

# Return a WindRose
return WindRose(wd_centers, ws_centers, freq_table, ti_table, value_table)

def to_wind_ti_rose(
self,
wd_step=2.0,
Expand All @@ -981,7 +985,7 @@ def to_wind_ti_rose(
wd_edges=None,
ws_edges=None,
ti_edges=None,
bin_weights=None
bin_weights=None,
):
"""
Converts the TimeSeries data to a WindRose.
Expand Down Expand Up @@ -1010,11 +1014,11 @@ def to_wind_ti_rose(
- If `ti_edges` is not defined, it determines `ti_edges` from the step and data.
"""

# If turbulence_intensities is None, a WindTIRose object cannot be created.
# If turbulence_intensities is None, a WindTIRose object cannot be created.
if self.turbulence_intensities is None:
raise ValueError(
"turbulence_intensities must be defined to export to a WindTIRose object."
)
"turbulence_intensities must be defined to export to a WindTIRose object."
)

# If wd_edges is defined, then use it to produce the bin centers
if wd_edges is not None:
Expand Down

0 comments on commit ecb5c2a

Please sign in to comment.