Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix] Cast yaw angles to np.ndarray on set #828

Merged
merged 6 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion floris/tools/floris_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def _set_operation(
"""
# Add operating conditions to the floris object
if yaw_angles is not None:
self.floris.farm.yaw_angles = yaw_angles
self.floris.farm.yaw_angles = np.array(yaw_angles)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the only place where yaw angles are going to be set? If not, you might consider adding a setter method on Farm to do this always:

class Farm:
    def set_yaw_angles(yaw_angles):
        # Do lots of checks
        ...
        # Cast to Numpy array
        self.yaw_angles = np.array(yaw_angles)

You could also use the @property decorator the way we used to do, if you think maintaining the attribute-style use is important.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, there's already a function with this name at https://github.com/NREL/floris/blob/v4/floris/simulation/farm.py#L332

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah and I just read #828 (comment), sorry to say the same thing @misi9170

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem---I'm going to try to do this (use a setter method), it seems like a better approach


if power_setpoints is not None:
power_setpoints = np.array(power_setpoints)
Expand Down
25 changes: 25 additions & 0 deletions tests/floris_interface_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,31 @@ def test_read_yaml():
fi = FlorisInterface(configuration=YAML_INPUT)
assert isinstance(fi, FlorisInterface)

def test_assign_setpoints():

fi = FlorisInterface(configuration=YAML_INPUT)
fi.set(layout_x=[0, 0], layout_y=[0, 1000])

# Test setting yaw angles via a list, integers, numpy array
fi.set(yaw_angles=[[20.0, 30.0]])
fi.set(yaw_angles=[[20, 30]])
fi.set(yaw_angles=np.array([[20.0, 30.0]]))

# Test setting power setpoints in various ways
fi.set(power_setpoints=[[1e6, 2e6]])
fi.set(power_setpoints=np.array([[1e6, 2e6]]))

# Disable turbines
fi.set(disable_turbines=[[True, False]])
fi.set(disable_turbines=np.array([[True, False]]))

# Combination
fi.set(yaw_angles=[[0, 30]], power_setpoints=np.array([[1e6, None]]))

# power_setpoints and disable_turbines (disable_turbines overrides power_setpoints)
fi.set(power_setpoints=[[1e6, 2e6]], disable_turbines=[[True, False]])
assert np.allclose(fi.floris.farm.power_setpoints, np.array([[0.001, 2e6]]))

def test_set_run():
"""
These tests are designed to test the set / run sequence to ensure that inputs are
Expand Down
Loading