Skip to content

Commit

Permalink
Add docstrings to tuner utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
paulf81 committed Jul 24, 2024
1 parent 932e25e commit fb98225
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions flasc/utilities/tuner_utilities.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
"""Utilities for tuning FLORIS parameters.
This module contains utilities for tuning FLORIS parameters. This includes
functions for resimulating FLORIS with SCADA data, and functions for setting
parameters in a FLORIS model.
"""


from pathlib import Path
from typing import Any, Dict, List, Optional

Expand All @@ -8,27 +17,24 @@
from flasc.data_processing import dataframe_manipulations as dfm
from flasc.utilities.utilities_examples import load_floris_smarteole

# from floris import ParallelComputingInterface


def replicate_nan_values(df_1: pd.DataFrame, df_2: pd.DataFrame):
"""
Replicate NaN Values in DataFrame df_2 to Match DataFrame df_1.
"""Replicate NaN Values in DataFrame df_2 to Match DataFrame df_1.
For columns that are common between df_1 and df_2, this function ensures that
NaN values in df_2 appear in the same locations as NaN values in df_1. This is
primarily useful when df_2 represents a FLORIS resimulation of
df_1, and you want to ensure that missing data is consistent between the two DataFrames.
Parameters:
- df_1 (pandas.DataFrame): The reference DataFrame containing NaN values.
- df_2 (pandas.DataFrame): The DataFrame to be updated to match NaN positions in df_1.
Args:
df_1 (pandas.DataFrame): The reference DataFrame containing NaN values.
df_2 (pandas.DataFrame): The DataFrame to be updated to match NaN positions in df_1.
Returns:
- pandas.DataFrame: A new DataFrame with NaN values in df_2 replaced to match df_1.
pandas.DataFrame: A new DataFrame with NaN values in df_2 replaced to match df_1.
"""
# For columns which df_1 and df_2 have in common, make sure
# occurences of NaNs which appear in df_1
# occurrences of NaNs which appear in df_1
# appear in the same location in df_2
# This function is primarily for the case where df_2 is
# a FLORIS resimulation of df_1 and making sure
Expand All @@ -47,6 +53,7 @@ def replicate_nan_values(df_1: pd.DataFrame, df_2: pd.DataFrame):

def nested_get(dic: Dict[str, Any], keys: List[str]) -> Any:
"""Get a value from a nested dictionary using a list of keys.
Based on: stackoverflow.com/questions/14692690/access-nested-dictionary-items-via-a-list-of-keys
Args:
Expand All @@ -63,6 +70,7 @@ def nested_get(dic: Dict[str, Any], keys: List[str]) -> Any:

def nested_set(dic: Dict[str, Any], keys: List[str], value: Any, idx: Optional[int] = None) -> None:
"""Set a value in a nested dictionary using a list of keys.
Based on: stackoverflow.com/questions/14692690/access-nested-dictionary-items-via-a-list-of-keys
Args:
Expand All @@ -89,13 +97,28 @@ def nested_set(dic: Dict[str, Any], keys: List[str], value: Any, idx: Optional[i


def resim_floris(fm_in: FlorisModel, df_scada: pd.DataFrame, yaw_angles: np.array = None):
"""Resimulate FLORIS with SCADA data.
This function takes a FlorisModel and a SCADA dataframe, and resimulates the
FlorisModel with the SCADA data. The SCADA data is expected to contain columns
for wind speed, wind direction, and power reference. The function returns a
dataframe containing the power output of each turbine in the FlorisModel.
Args:
fm_in (FlorisModel): The FlorisModel to resimulate.
df_scada (pd.DataFrame): The SCADA data to use for resimulation.
yaw_angles (np.array, optional): The yaw angles to use for resimulation. Defaults to None.
Returns:
pd.DataFrame: A DataFrame containing the power output of each turbine in the FlorisModel.
"""
# Get wind speeds and directions
wind_speeds = df_scada["ws"].values
wind_directions = df_scada["wd"].values
# TODO: better handling of TIs?
turbulence_intensities = fm_in.turbulence_intensities[0] * np.ones_like(wind_speeds)

# Get the number of turbiens
# Get the number of turbines
num_turbines = dfm.get_num_turbines(df_scada)

# Set up the FLORIS model
Expand Down

0 comments on commit fb98225

Please sign in to comment.