Skip to content

Commit

Permalink
Disable filter_convert function
Browse files Browse the repository at this point in the history
While this was useful early in the v3 redesign, we’ve converged to a design where this is no longer used.
  • Loading branch information
rafmudaf committed Dec 6, 2023
1 parent 36d9012 commit 6155830
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 98 deletions.
49 changes: 0 additions & 49 deletions floris/simulation/turbine.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,51 +36,6 @@
from floris.utilities import cosd


def _filter_convert(
ix_filter: NDArrayFilter | Iterable[int] | None, sample_arg: NDArrayFloat | NDArrayInt
) -> NDArrayFloat | None:
"""This function selects turbine indeces from the given array of turbine properties
over the simulation's atmospheric conditions (wind directions / wind speeds).
It converts the ix_filter to a standard format of `np.ndarray`s for filtering
certain arguments.
Args:
ix_filter (NDArrayFilter | Iterable[int] | None): The indices, or truth
array-like object to use for filtering. None implies that all indeces in the
sample_arg should be selected.
sample_arg (NDArrayFloat | NDArrayInt): Any argument that will be filtered, to be used for
creating the shape. This should be of shape:
(n wind directions, n wind speeds, n turbines)
Returns:
NDArrayFloat | None: Returns an array of a truth or index list if a list is
passed, a truth array if ix_filter is None, or None if ix_filter is None
and the `sample_arg` is a single value.
"""
# Check that the ix_filter is either None or an Iterable. Otherwise,
# there's nothing we can do with it.
if not isinstance(ix_filter, Iterable) and ix_filter is not None:
raise TypeError("Expected ix_filter to be an Iterable or None")

# Check that the sample_arg is a Numpy array. If it isn't, we
# can't get its shape.
if not isinstance(sample_arg, np.ndarray):
raise TypeError("Expected sample_arg to be a float or integer np.ndarray")

# At this point, the arguments have this type:
# ix_filter: Union[Iterable, None]
# sample_arg: np.ndarray

# Return all values in the turbine-dimension
# if the index filter is None
if ix_filter is None:
return np.ones(sample_arg.shape[-1], dtype=bool)

# Finally, we should have an index filter list of type Iterable,
# so cast it to Numpy array and return
return np.array(ix_filter)


def _rotor_velocity_yaw_correction(
pP: float,
yaw_angle: NDArrayFloat,
Expand Down Expand Up @@ -178,7 +133,6 @@ def rotor_effective_velocity(

# Down-select inputs if ix_filter is given
if ix_filter is not None:
ix_filter = _filter_convert(ix_filter, yaw_angle)
velocities = velocities[:, :, ix_filter]
yaw_angle = yaw_angle[:, :, ix_filter]
tilt_angle = tilt_angle[:, :, ix_filter]
Expand Down Expand Up @@ -255,7 +209,6 @@ def power(

# Down-select inputs if ix_filter is given
if ix_filter is not None:
ix_filter = _filter_convert(ix_filter, rotor_effective_velocities)
rotor_effective_velocities = rotor_effective_velocities[:, :, ix_filter]
turbine_type_map = turbine_type_map[:, :, ix_filter]

Expand Down Expand Up @@ -322,7 +275,6 @@ def Ct(

# Down-select inputs if ix_filter is given
if ix_filter is not None:
ix_filter = _filter_convert(ix_filter, yaw_angle)
velocities = velocities[:, :, ix_filter]
yaw_angle = yaw_angle[:, :, ix_filter]
tilt_angle = tilt_angle[:, :, ix_filter]
Expand Down Expand Up @@ -425,7 +377,6 @@ def axial_induction(
)

# Then, process the input arguments as needed for this function
ix_filter = _filter_convert(ix_filter, yaw_angle)
if ix_filter is not None:
yaw_angle = yaw_angle[:, :, ix_filter]
tilt_angle = tilt_angle[:, :, ix_filter]
Expand Down
4 changes: 0 additions & 4 deletions floris/simulation/turbine_multi_dim.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
TiltTable,
Turbine,
)
from floris.simulation.turbine import _filter_convert
from floris.type_dec import (
NDArrayBool,
NDArrayFilter,
Expand Down Expand Up @@ -79,7 +78,6 @@ def power_multidim(

# Down-select inputs if ix_filter is given
if ix_filter is not None:
ix_filter = _filter_convert(ix_filter, rotor_effective_velocities)
power_interp = power_interp[:, :, ix_filter]
rotor_effective_velocities = rotor_effective_velocities[:, :, ix_filter]
# Loop over each turbine to get power for all turbines
Expand Down Expand Up @@ -141,7 +139,6 @@ def Ct_multidim(

# Down-select inputs if ix_filter is given
if ix_filter is not None:
ix_filter = _filter_convert(ix_filter, yaw_angle)
velocities = velocities[:, :, ix_filter]
yaw_angle = yaw_angle[:, :, ix_filter]
tilt_angle = tilt_angle[:, :, ix_filter]
Expand Down Expand Up @@ -240,7 +237,6 @@ def axial_induction_multidim(
)

# Then, process the input arguments as needed for this function
ix_filter = _filter_convert(ix_filter, yaw_angle)
if ix_filter is not None:
yaw_angle = yaw_angle[:, :, ix_filter]
tilt_angle = tilt_angle[:, :, ix_filter]
Expand Down
45 changes: 0 additions & 45 deletions tests/turbine_unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
Turbine,
)
from floris.simulation.turbine import (
_filter_convert,
_rotor_velocity_tilt_correction,
_rotor_velocity_yaw_correction,
compute_tilt_angles_for_floating_turbines,
Expand Down Expand Up @@ -132,50 +131,6 @@ def test_rotor_area():
assert turbine.rotor_area == np.pi


def test_filter_convert():
N = 4

# When the index filter is not None or a Numpy array,
# the function should return None
ix_filter = 1
sample_arg = np.arange(N)
with pytest.raises(TypeError):
_filter_convert(ix_filter, sample_arg)

# When the sample_arg is not a Numpy array, the function
# should return None
ix_filter = None
sample_arg = [1, 2, 3]
with pytest.raises(TypeError):
_filter_convert(ix_filter, sample_arg)

# When the sample_arg is a Numpy array and the index filter
# is None, a boolean array containing all True should be
# returned with the same shape as the sample_arg.
ix_filter = None
sample_arg = np.arange(N)
ix_filter = _filter_convert(ix_filter, sample_arg)
assert ix_filter.sum() == N
assert ix_filter.shape == (N,)

# When the index filter is given as a Python list, the
# function should return the values cast to a Numpy array
ix_filter = [1, 2]
sample_arg = np.arange(N).reshape(1, 1, N)
ix_filter = _filter_convert(ix_filter, sample_arg)
np.testing.assert_array_equal(ix_filter, np.array([1, 2]))

# Test that a 1-D boolean truth array is returned
# When the index filter is None and the sample_arg
# is a Numpy array of values, the returned filter indices
# should be all True and have the shape of the turbine-dimension
ix_filter = None
sample_arg = np.arange(N).reshape(1, 1, N)
ix_filter = _filter_convert(ix_filter, sample_arg)
assert ix_filter.sum() == N
assert ix_filter.shape == (N,)


def test_average_velocity():
# TODO: why do we use cube root - mean - cube (like rms) instead of a simple average (np.mean)?
# Dimensions are (n wind directions, n wind speeds, n turbines, grid x, grid y)
Expand Down

0 comments on commit 6155830

Please sign in to comment.