Skip to content

Commit

Permalink
Updating to v1.1
Browse files Browse the repository at this point in the history
Updating to v1.1
  • Loading branch information
bayc authored Oct 26, 2022
2 parents 87210e5 + 3b26fc2 commit 8b6a21e
Show file tree
Hide file tree
Showing 20 changed files with 801 additions and 303 deletions.
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
author = 'Bart Doekemeijer, Paul Fleming, Eric Simley'

# The full version, including alpha/beta/rc tags
release = '0.1'
release = '1.1'


# -- General configuration ---------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import floris.tools as wfct
from floris.logging_manager import configure_console_log
from pandas.core.base import DataError
from pandas.errors import DataError

from flasc import floris_sensitivity_analysis as fsasa

Expand Down
2 changes: 1 addition & 1 deletion examples/demo_dataset/demo_floris_input.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ logging:
level: INFO
name: floris_input_file_example
solver:
turbine_grid_points: 5
turbine_grid_points: 3
type: turbine_grid
wake:
enable_secondary_steering: true
Expand Down
18 changes: 16 additions & 2 deletions examples/wake_steering_design/00_analyze_single_ws_vs_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
from matplotlib import pyplot as plt

from flasc.wake_steering.lookup_table_tools import get_yaw_angles_interpolant
from flasc.wake_steering.yaw_optimizer_visualization import plot_uplifts_by_atmospheric_conditions
from flasc.visualization import plot_floris_layout
from flasc.wake_steering.yaw_optimizer_visualization import \
plot_uplifts_by_atmospheric_conditions, plot_offsets_wswd_heatmap, plot_offsets_wd
from flasc.visualization import plot_floris_layout, plot_layout_with_waking_directions

from _local_helper_functions import load_floris, optimize_yaw_angles, evaluate_optimal_yaw_angles

Expand All @@ -25,6 +26,7 @@
# Load FLORIS model and plot layout (and additional information)
fi = load_floris()
plot_floris_layout(fi)
plot_layout_with_waking_directions(fi, limit_dist_D=5, limit_num=3)

# Compare optimizing over all wind speeds vs. optimizing over a single wind speed
AEP_baseline_array = []
Expand All @@ -47,6 +49,18 @@
AEP_opt_array.append(AEP_opt)
df_out_array.append(df_out.copy())

# Vizualize optimal wake steering schedule for all wind speeds
# for a single turbine (index 2)
ax, cbar = plot_offsets_wswd_heatmap(df_offsets=df_opt, turb_id=2)
ax.set_title("T02 offset schedule")

ax = plot_offsets_wd(df_offsets=df_opt, turb_id=2, ws_plot=[5, 12],
alpha=0.5)
ax = plot_offsets_wd(df_offsets=df_opt, turb_id=2, ws_plot=7.0,
color="C0", label="7.0 m/s", ax=ax)
ax.set_title("T02 offset schedule")
ax.legend()

# Calculate AEP uplifts
uplift_one_ws = (
100.0 * (AEP_opt_array[0] - AEP_baseline_array[0]) /
Expand Down
4 changes: 2 additions & 2 deletions flasc/dataframe_operations/dataframe_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def plot_highlight_data_by_conds(df, conds, ti):
conds = [conds]

# Convert time arrays to a string with 'year+week'
tfull = [int('%04d%02d' % (i.year, i.week)) for i in df.time]
tfull = [int('%04d%02d' % (i.isocalendar().year, i.isocalendar().week)) for i in df.time]
time_array = np.unique(tfull)

# Get number of non-NaN entries before filtering
Expand All @@ -113,7 +113,7 @@ def plot_highlight_data_by_conds(df, conds, ti):
# Convert time array of occurrences to year+week no.
conds_new = conds[ii] & (~conds_combined)
conds_combined = (conds_combined | np.array(conds[ii], dtype=bool))
subset_time_array = [int('%04d%02d' % (i.year, i.week)) for i in df.loc[conds_new, 'time']]
subset_time_array = [int('%04d%02d' % (i.isocalendar().year, i.isocalendar().week)) for i in df.loc[conds_new, 'time']]

for iii in range(len(time_array)):
# Count occurrences for condition
Expand Down
10 changes: 7 additions & 3 deletions flasc/energy_ratio/energy_ratio.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import pandas as pd

from floris.utilities import wrap_360
from pandas.core.base import DataError
from pandas.errors import DataError

from ..dataframe_operations import dataframe_manipulations as dfm
from ..energy_ratio import energy_ratio_visualization as ervis
Expand Down Expand Up @@ -479,16 +479,20 @@ def get_energy_ratio_fast(
energy_ratios = df_summed.reset_index(drop=False)
return energy_ratios

def plot_energy_ratio(self):
def plot_energy_ratio(self, hide_uq_labels=True):
"""This function plots the energy ratio against the wind direction,
potentially with uncertainty bounds if N > 1 was specified by
the user. One must first run get_energy_ratio() before attempting
to plot the energy ratios.
Args:
hide_uq_labels (bool, optional): If true, do not specifically label
the confidence intervals in the plot
Returns:
ax [plt.Axes]: Axis handle for the figure.
"""
return ervis.plot(self.energy_ratio_out)
return ervis.plot(self.energy_ratio_out, hide_uq_labels=hide_uq_labels)


# Support functions not included in energy_ratio class
Expand Down
10 changes: 6 additions & 4 deletions flasc/energy_ratio/energy_ratio_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import numpy as np
import pandas as pd
from pandas.core.base import DataError
from pandas.errors import DataError
from scipy.interpolate import NearestNDInterpolator

from ..energy_ratio import energy_ratio as er
Expand Down Expand Up @@ -625,7 +625,7 @@ def get_energy_ratios_fast(

return self.df_list

def plot_energy_ratios(self, superimpose=True):
def plot_energy_ratios(self, superimpose=True, hide_uq_labels=True):
"""This function plots the energy ratios of each dataset against
the wind direction, potentially with uncertainty bounds if N > 1
was specified by the user. One must first run get_energy_ratios()
Expand All @@ -636,19 +636,21 @@ def plot_energy_ratios(self, superimpose=True):
of all datasets into the same figure. If False, will plot the
energy ratio of each dataset into a separate figure. Defaults
to True.
hide_uq_labels (bool, optional): If true, do not specifically label
the confidence intervals in the plot
Returns:
ax [plt.Axes]: Axis handle for the figure.
"""
if superimpose:
results_array = [df["er_results"] for df in self.df_list]
labels_array = [df["name"] for df in self.df_list]
fig, ax = vis.plot(results_array, labels_array)
fig, ax = vis.plot(results_array, labels_array, hide_uq_labels=hide_uq_labels)

else:
ax = []
for df in self.df_list:
fig, axi = vis.plot(df["er_results"], df["name"])
fig, axi = vis.plot(df["er_results"], df["name"], hide_uq_labels=hide_uq_labels)
ax.append(axi)

return ax
Expand Down
7 changes: 6 additions & 1 deletion flasc/energy_ratio/energy_ratio_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from floris import tools as wfct


def plot(energy_ratios, labels=None):
def plot(energy_ratios, labels=None, hide_uq_labels=True):
"""This function plots energy ratios against the reference wind
direction. The plot may or may not include uncertainty bounds,
depending on the information contained in the provided energy ratio
Expand All @@ -43,6 +43,8 @@ def plot(energy_ratios, labels=None):
with UQ.
labels ([iteratible], optional): Label for each of the energy ratio
dataframes. Defaults to None.
hide_uq_labels (bool, optional): If true, do not specifically label
the confidence intervals in the plot
Returns:
fig ([plt.Figure]): Figure in which energy ratios are plotted.
Expand All @@ -60,6 +62,9 @@ def plot(energy_ratios, labels=None):
else:
uq_labels = ["%s confidence bounds" % lb for lb in labels]

if hide_uq_labels:
uq_labels = ['_nolegend_' for l in uq_labels]

N = len(energy_ratios)
fig, ax = plt.subplots(nrows=2, sharex=True, figsize=(10, 5))

Expand Down
2 changes: 1 addition & 1 deletion flasc/floris_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from pandas.core.base import DataError
from pandas.errors import DataError
from scipy import interpolate
from time import perf_counter as timerpc

Expand Down
2 changes: 1 addition & 1 deletion flasc/model_estimation/floris_sensitivity_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from SALib.sample import saltelli
from SALib.analyze import sobol

from pandas.core.base import DataError
from pandas.errors import DataError

from .. import floris_tools as ftools

Expand Down
2 changes: 1 addition & 1 deletion flasc/optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import copy
from datetime import timedelta as td
import numpy as np
from pandas.core.base import DataError
from pandas.errors import DataError
import scipy.optimize as opt
import scipy.stats as spst

Expand Down
25 changes: 22 additions & 3 deletions flasc/raw_data_handling/sqldatabase_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ def print_properties(self):
print(" N.o. columns: %d." % len(cols))
print("")

def launch_gui(self):
def launch_gui(self, turbine_names=None, sort_columns=False):
root = tk.Tk()
sql_db_explorer_gui(master=root, dbc=self)

sql_db_explorer_gui(master=root, dbc=self, turbine_names=turbine_names, sort_columns=sort_columns)
root.mainloop()

def get_column_names(self, table_name):
Expand Down Expand Up @@ -256,7 +257,7 @@ def send_data(


class sql_db_explorer_gui:
def __init__(self, master, dbc):
def __init__(self, master, dbc, turbine_names = None, sort_columns=False):

# Create the options container
frame_1 = tk.Frame(master)
Expand Down Expand Up @@ -408,6 +409,12 @@ def mapper_func(evt):
# Set up the database connection
self.dbc = dbc

# Save the turbine names
self.turbine_names = turbine_names

# Save the sort columns
self.sort_columns = sort_columns

def channel_add(self):
if self.N_channels < self.N_channels_max:
ci = self.N_channels # New channel
Expand Down Expand Up @@ -463,11 +470,23 @@ def load_data(self):
]
col_mapping = dict(zip(old_col_names, new_col_names))
df = df.rename(columns=col_mapping)

# If specific turbine names are supplied apply them here
if self.turbine_names is not None:
columns = df.columns
for t in range(len(self.turbine_names)):
columns = [c.replace('%03d' % t,self.turbine_names[t]) for c in columns]
df.columns = columns

df_array.append(df)

# Merge dataframes
self.df = pd.concat(df_array, axis=1).reset_index(drop=False)

# If sorting the columns do it now
if self.sort_columns:
self.df = self.df[sorted(self.df.columns)]

self.update_channel_cols()
self.create_figures()
# # Clear all axes
Expand Down
Loading

0 comments on commit 8b6a21e

Please sign in to comment.