Skip to content

Commit

Permalink
Remove unnessary passing of dfnames
Browse files Browse the repository at this point in the history
  • Loading branch information
paulf81 committed Aug 21, 2023
1 parent 0c2bfc2 commit 321e810
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
20 changes: 6 additions & 14 deletions flasc/energy_ratio/energy_ratio.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ def _compute_energy_ratio_single(df_,

# Bootstrap function wraps the _compute_energy_ratio function
def _compute_energy_ratio_bootstrap(er_in,
df_names,
ref_cols,
test_cols,
wd_cols,
Expand All @@ -155,7 +154,6 @@ def _compute_energy_ratio_bootstrap(er_in,
Args:
er_in (EnergyRatioInput): An EnergyRatioInput object containing the data to use in the calculation.
df_names (list): A list of names to give to the dataframes.
ref_cols (list[str]): A list of columns to use as the reference turbines
test_cols (list[str]): A list of columns to use as the test turbines
wd_cols (list[str]): A list of columns to derive the wind directions from
Expand All @@ -181,7 +179,7 @@ def _compute_energy_ratio_bootstrap(er_in,
# Otherwise run the function N times and concatenate the results to compute statistics
if parallell_interface == "serial":
df_concat = pl.concat([_compute_energy_ratio_single(er_in.resample_energy_table(i),
df_names,
er_in.df_names,
ref_cols,
test_cols,
wd_cols,
Expand Down Expand Up @@ -216,7 +214,7 @@ def _compute_energy_ratio_bootstrap(er_in,

# Assemble the agurments
multiargs = [(er_in.resample_energy_table(i),
df_names,
er_in.df_names,
ref_cols,
test_cols,
wd_cols,
Expand All @@ -240,23 +238,22 @@ def _compute_energy_ratio_bootstrap(er_in,
df_concat = pl.concat(out)

if 'uplift' in df_concat.columns:
df_names_with_uplift = df_names + ['uplift']
df_names_with_uplift = er_in.df_names + ['uplift']
else:
df_names_with_uplift = df_names
df_names_with_uplift = er_in.df_names

return (df_concat
.groupby(['wd_bin'], maintain_order=True)
.agg([pl.first(n) for n in df_names_with_uplift] +
[pl.quantile(n, percentiles[0]/100).alias(n + "_ub") for n in df_names_with_uplift] +
[pl.quantile(n, percentiles[1]/100).alias(n + "_lb") for n in df_names_with_uplift] +
[pl.first(f'count_{n}') for n in df_names]
[pl.first(f'count_{n}') for n in er_in.df_names]
)
.sort('wd_bin')
)


def compute_energy_ratio(er_in: EnergyRatioInput,
df_names=None,
ref_turbines=None,
test_turbines= None,
wd_turbines=None,
Expand All @@ -283,7 +280,6 @@ def compute_energy_ratio(er_in: EnergyRatioInput,
Args:
er_in (EnergyRatioInput): An EnergyRatioInput object containing the data to use in the calculation.
df_names (list): A list of names to give to the dataframes.
ref_turbines (list[int]): A list of turbine numbers to use as the reference.
test_turbines (list[int]): A list of turbine numbers to use as the test.
ws_turbines (list[int]): A list of turbine numbers to use for the wind speeds
Expand Down Expand Up @@ -380,8 +376,6 @@ def compute_energy_ratio(er_in: EnergyRatioInput,
else:
wd_cols = ['wd']

if df_names is None:
df_names = df_['df_name'].unique().to_list()

# Convert the numbered arrays to appropriate column names
test_cols = [f'pow_{i:03d}' for i in test_turbines]
Expand All @@ -392,7 +386,7 @@ def compute_energy_ratio(er_in: EnergyRatioInput,
print("percentiles can only be used with bootstrapping (N > 1).")
# Compute the energy ratio
df_res = _compute_energy_ratio_single(df_,
df_names,
er_in.df_names,
ref_cols,
test_cols,
wd_cols,
Expand All @@ -413,7 +407,6 @@ def compute_energy_ratio(er_in: EnergyRatioInput,
"upper and lower desired percentiles.")

df_res = _compute_energy_ratio_bootstrap(er_in,
df_names,
ref_cols,
test_cols,
wd_cols,
Expand All @@ -435,7 +428,6 @@ def compute_energy_ratio(er_in: EnergyRatioInput,

# Return the results as an EnergyRatioOutput object
return EnergyRatioOutput(df_res,
df_names,
er_in,
ref_cols,
test_cols,
Expand Down
14 changes: 6 additions & 8 deletions flasc/energy_ratio/energy_ratio_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ class EnergyRatioOutput:
"""
def __init__(self,
df_result: pl.DataFrame,
df_names: List[str],
eri: EnergyRatioInput,
er_in: EnergyRatioInput,
ref_cols: List[str],
test_cols: List[str],
wd_cols: List[str],
Expand All @@ -38,7 +37,6 @@ def __init__(self,
Args:
df_result (pl.DataFrame): The energy ratio results.
df_names (List[str]): The names of the dataframes used in the energy ratio calculation.
eri (EnergyRatioInput): The energy table used in the energy ratio calculation.
ref_cols (List[str]): The column names of the reference turbines.
test_cols (List[str]): The column names of the test wind turbines.
Expand All @@ -55,9 +53,9 @@ def __init__(self,
N (int): The number of bootstrap iterations used in the energy ratio calculation.
"""
self.df_result = df_result
self.df_names = df_names
self.num_df = len(df_names)
self.eri = eri
self.df_names = er_in.df_names
self.num_df = len(self.df_names)
self.er_in = er_in
self.ref_cols = ref_cols
self.test_cols = test_cols
self.wd_cols = wd_cols
Expand All @@ -79,7 +77,7 @@ def _compute_df_freq(self):
#TODO: I don't think so, but should this function count overlapping bins?

# Temporary copy of energy table
df_ = self.eri.get_df()
df_ = self.er_in.get_df()

# Filter df_ that all the columns are not null
df_ = df_.filter(pl.all(pl.col(self.ref_cols + self.test_cols + self.ws_cols + self.wd_cols).is_not_null()))
Expand Down Expand Up @@ -310,7 +308,7 @@ def plot_energy_ratios(self,

ax = axarr[2]

sns.scatterplot(data=df_min, x='wd_bin', y='ws_bin', size='count', ax=ax, legend=True, color='k')
sns.scatterplot(data=df_min, x='wd_bin', y='ws_bin', size='count',hue='count',cmap='jet', ax=ax, legend=True, color='k')
ax.set_xlabel('Wind Direction (deg)')
ax.set_ylabel('Wind Speed (m/s)')
ax.set_title('Minimum Number of Points per Bin')
Expand Down

0 comments on commit 321e810

Please sign in to comment.