Skip to content

Commit

Permalink
Wind direction resampling 2 (#946)
Browse files Browse the repository at this point in the history
* Update remaining double appends to concats.

* Fix comments.

* Ruff.

* Remove redundant code block

---------

Co-authored-by: Paul <paul.fleming@nrel.gov>
  • Loading branch information
misi9170 and paulf81 authored Jul 18, 2024
1 parent 4004c03 commit d2c27ca
Showing 1 changed file with 73 additions and 53 deletions.
126 changes: 73 additions & 53 deletions floris/wind_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def __init__(
# If heterogeneous_inflow_config_by_wd is not None, then create a HeterogeneousMap object
# using the dictionary
if heterogeneous_inflow_config_by_wd is not None:
# TODO: In future, add deprectation warning for this parameter here
# TODO: In future, add deprecation warning for this parameter here

self.heterogeneous_map = HeterogeneousMap(**heterogeneous_inflow_config_by_wd)

Expand Down Expand Up @@ -597,17 +597,27 @@ def upsample(self, wd_step=None, ws_step=None, method="linear", inplace=False):
value_matrix = np.vstack((value_matrix[-1, :], value_matrix, value_matrix[0, :]))

Check warning on line 597 in floris/wind_data.py

View check run for this annotation

Codecov / codecov/patch

floris/wind_data.py#L597

Added line #L597 was not covered by tests

# Pad out the wind speeds
wind_speed_column = np.append(ws_range_min_current, wind_speed_column)
ti_matrix = np.hstack((ti_matrix[:, 0].reshape((-1, 1)), ti_matrix))
freq_matrix = np.hstack((freq_matrix[:, 0].reshape((-1, 1)), freq_matrix))
if self.value_table is not None:
value_matrix = np.hstack((value_matrix[:, 0].reshape((-1, 1)), value_matrix))

wind_speed_column = np.append(wind_speed_column, ws_range_max_current)
ti_matrix = np.hstack((ti_matrix, ti_matrix[:, -1].reshape((-1, 1))))
freq_matrix = np.hstack((freq_matrix, freq_matrix[:, -1].reshape((-1, 1))))
wind_speed_column = np.concatenate(
(
np.array([ws_range_min_current]),
wind_speed_column,
np.array([ws_range_max_current])
)
)
ti_matrix = np.hstack(
(ti_matrix[:, 0].reshape((-1, 1)), ti_matrix, ti_matrix[:, -1].reshape((-1, 1)))
)
freq_matrix = np.hstack(
(freq_matrix[:, 0].reshape((-1, 1)), freq_matrix, freq_matrix[:, -1].reshape((-1, 1)))
)
if self.value_table is not None:
value_matrix = np.hstack((value_matrix, value_matrix[:, -1].reshape((-1, 1))))
value_matrix = np.hstack(

Check warning on line 614 in floris/wind_data.py

View check run for this annotation

Codecov / codecov/patch

floris/wind_data.py#L614

Added line #L614 was not covered by tests
(
value_matrix[:, 0].reshape((-1, 1)),
value_matrix,
value_matrix[:, -1].reshape((-1, 1))
)
)

# Grid wind directions and wind speeds to match the ti_matrix and freq_matrix when flattened
wd_grid, ws_grid = np.meshgrid(wind_direction_column, wind_speed_column, indexing="ij")
Expand Down Expand Up @@ -1540,19 +1550,25 @@ def upsample(self, wd_step=None, ws_step=None, ti_step=None, method="linear", in
# This is the case when wind directions doesn't cover the full range of possible
# degrees (0-360)
if np.abs((wd_range_min_current % 360.0) - (wd_range_max_current % 360.0)) > 1e-6:
wind_direction_column = np.append(wd_range_min_current, wind_direction_column)
freq_matrix = np.concatenate((freq_matrix[0, :, :][None, :, :], freq_matrix), axis=0)
if self.value_table is not None:
value_matrix = np.concatenate(
(value_matrix[0, :, :][None, :, :], value_matrix), axis=0
wind_direction_column = np.concatenate(
(
np.array([wd_range_min_current]),
wind_direction_column,
np.array([wd_range_max_current])
)

# Add the max range to the wind direction column
wind_direction_column = np.append(wind_direction_column, wd_range_max_current)
freq_matrix = np.concatenate((freq_matrix, freq_matrix[-1, :, :][None, :, :]), axis=0)
)
freq_matrix = np.concatenate(
(freq_matrix[0, :, :][None, :, :], freq_matrix, freq_matrix[-1, :, :][None, :, :]),
axis=0
)
if self.value_table is not None:
value_matrix = np.concatenate(
(value_matrix, value_matrix[-1, :, :][None, :, :]), axis=0
(
value_matrix[0, :, :][None, :, :],
value_matrix,
value_matrix[-1, :, :][None, :, :]
),
axis=0
)

# In the alternative case, where the wind directions cover the full range
Expand Down Expand Up @@ -1582,47 +1598,51 @@ def upsample(self, wd_step=None, ws_step=None, ti_step=None, method="linear", in
)

# Pad out the wind speeds
wind_speed_column = np.append(ws_range_min_current, wind_speed_column)
freq_matrix = np.concatenate((freq_matrix[:, 0, :][:, None, :], freq_matrix), axis=1)
if self.value_table is not None:
value_matrix = np.concatenate((value_matrix[:, 0, :][:, None, :], value_matrix), axis=1)

wind_speed_column = np.append(wind_speed_column, ws_range_max_current)
freq_matrix = np.concatenate((freq_matrix, freq_matrix[:, -1, :][:, None, :]), axis=1)
wind_speed_column = np.concatenate(
(
np.array([ws_range_min_current]),
wind_speed_column,
np.array([ws_range_max_current])
)
)
freq_matrix = np.concatenate(
(freq_matrix[:, 0, :][:, None, :], freq_matrix, freq_matrix[:, -1, :][:, None, :]),
axis=1
)
if self.value_table is not None:
value_matrix = np.concatenate(

Check warning on line 1613 in floris/wind_data.py

View check run for this annotation

Codecov / codecov/patch

floris/wind_data.py#L1613

Added line #L1613 was not covered by tests
(value_matrix, value_matrix[:, -1, :][:, None, :]), axis=1
(
value_matrix[:, 0, :][:, None, :],
value_matrix,
value_matrix[:, -1, :][:, None, :]
),
axis=1
)

# Pad out the turbulence intensities
turbulence_intensity_column = np.append(ti_range_min_current, turbulence_intensity_column)
freq_matrix = np.concatenate((freq_matrix[:, :, 0][:, :, None], freq_matrix), axis=2)
if self.value_table is not None:
value_matrix = np.concatenate((value_matrix[:, :, 0][:, :, None], value_matrix), axis=2)

turbulence_intensity_column = np.append(turbulence_intensity_column, ti_range_max_current)
freq_matrix = np.concatenate((freq_matrix, freq_matrix[:, :, -1][:, :, None]), axis=2)
turbulence_intensity_column = np.concatenate(
(
np.array([ti_range_min_current]),
turbulence_intensity_column,
np.array([ti_range_max_current])
)
)
freq_matrix = np.concatenate(
(freq_matrix[:, :, 0][:, :, None], freq_matrix, freq_matrix[:, :, -1][:, :, None]),
axis=2
)
if self.value_table is not None:
value_matrix = np.concatenate(

Check warning on line 1635 in floris/wind_data.py

View check run for this annotation

Codecov / codecov/patch

floris/wind_data.py#L1635

Added line #L1635 was not covered by tests
(value_matrix, value_matrix[:, :, -1][:, :, None]), axis=2
)

# If wd_range_min_current is less than 0, then pad the wind_direction column with
# that value + 360 and expand the matrices accordingly (this avoids interpolation errors)
if wd_range_min_current < 0:
# Pad wind direction column with min_wd + 360
wind_direction_column = np.append(
wind_direction_column, np.min(self.wind_directions) + 360.0
(
value_matrix[:, :, 0][:, :, None],
value_matrix,
value_matrix[:, :, -1][:, :, None]
),
axis=2
)

# Pad the remaining with the appropriate value
freq_matrix = np.concatenate((freq_matrix, freq_matrix[0, :, :][None, :, :]), axis=0)
if self.value_table is not None:
value_matrix = np.concatenate(
(value_matrix, value_matrix[0, :, :][None, :, :]), axis=0
)

# Grid wind directions and wind speeds to match the ti_matrix and freq_matrix when flattened
# Grid wind directions, wind speeds and turbulence intensities to match the
# freq_matrix when flattened
wd_grid, ws_grid, ti_grid = np.meshgrid(
wind_direction_column, wind_speed_column, turbulence_intensity_column, indexing="ij"
)
Expand Down

0 comments on commit d2c27ca

Please sign in to comment.