Skip to content

Commit 8c01b15

Browse files
authored
Update imported package usage to avoid deprecation warnings (#253)
1 parent 68202a5 commit 8c01b15

17 files changed

Lines changed: 805 additions & 803 deletions

examples_artificial_data/03_energy_ratio/01_demo_energy_ratio_options.ipynb

Lines changed: 62 additions & 63 deletions
Large diffs are not rendered by default.

examples_smarteole/02_download_and_format_dataset.ipynb

Lines changed: 684 additions & 694 deletions
Large diffs are not rendered by default.

flasc/analysis/energy_ratio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def _compute_energy_ratio_single(
137137
.with_columns(energy_ratio=pl.col("test_energy") / pl.col("ref_energy"))
138138
.pivot(
139139
values=["energy_ratio", "count"],
140-
columns="df_name",
140+
on="df_name",
141141
index="wd_bin",
142142
aggregate_function="first",
143143
)

flasc/analysis/energy_ratio_output.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ def _compute_ws_counts(self):
564564
)
565565

566566
# Get the bin count by wd, ws and df_name
567-
df_group = df_.group_by(["wd_bin", "ws_bin", "df_name"]).count()
567+
df_group = df_.group_by(["wd_bin", "ws_bin", "df_name"]).len().rename({"len": "count"})
568568

569569
# Collect the minimum number of points per bin
570570
df_return = (

flasc/analysis/expected_power_analysis_by.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def plot(
308308
# If the color dict is empty fill using a matplotlib palette
309309
if len(color_dict) == 0:
310310
num_uplift_names = len(self.uplift_names)
311-
c_pal = plt.cm.get_cmap("tab10", num_uplift_names)
311+
c_pal = plt.get_cmap("tab10", num_uplift_names)
312312
color_dict = {
313313
uplift_name: c_pal(up_idx) for up_idx, uplift_name in enumerate(self.uplift_names)
314314
}
@@ -703,7 +703,7 @@ def total_uplift_expected_power_by_wd_shift_ws_min(
703703
labels = [f"ws_min = {ws_min_loop:.1f}" for ws_min_loop in ws_min_values]
704704

705705
# Define the color dict
706-
c_pal = plt.cm.get_cmap("viridis", n_step)
706+
c_pal = plt.get_cmap("viridis", n_step)
707707
color_dict = {label: c_pal(idx) for idx, label in enumerate(labels)}
708708

709709
# Declare a figure

flasc/analysis/total_uplift_power_ratio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def _total_uplift_power_ratio_single(
137137
)
138138
.pivot(
139139
values=["power_ratio"],
140-
columns="df_name",
140+
on="df_name",
141141
index=bin_cols_without_df_name + ["weight", "weighted_pow_ref"],
142142
aggregate_function="first",
143143
)

flasc/data_processing/energy_ratio_wd_bias_estimation.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
import os as os
6-
from typing import Callable, List, Union
6+
from typing import Callable, Iterable, List, Union
77

88
import matplotlib.pyplot as plt
99
import numpy as np
@@ -89,7 +89,7 @@ def __init__(
8989

9090
def _load_a_input_for_wd_bias(
9191
self,
92-
wd_bias,
92+
wd_bias: float,
9393
):
9494
"""Load AnalysisInput objects with bias.
9595
@@ -158,16 +158,16 @@ def _load_a_input_for_wd_bias(
158158

159159
def _get_energy_ratios_allbins(
160160
self,
161-
wd_bias,
162-
time_mask=None,
163-
ws_mask=(6.0, 10.0),
164-
wd_mask=None,
165-
ti_mask=None,
166-
wd_step=3.0,
167-
ws_step=1.0,
168-
wd_bin_width=3.0,
169-
N_btstrp=1,
170-
plot_iter_path=None,
161+
wd_bias: float,
162+
time_mask: None = None,
163+
ws_mask: Iterable[float, float] = (6.0, 10.0),
164+
wd_mask: Iterable[float, float] | None = None,
165+
ti_mask: None = None,
166+
wd_step: float = 3.0,
167+
ws_step: float = 1.0,
168+
wd_bin_width: float = 3.0,
169+
N_btstrp: int = 1,
170+
plot_iter_path: str | None = None,
171171
):
172172
"""Calculate the energy ratios.
173173
@@ -177,8 +177,7 @@ def _get_energy_ratios_allbins(
177177
the data based on this variable. Defaults to None.
178178
ws_mask ([iterable], optional): Wind speed mask. Should be an
179179
iterable of length 2, e.g., [6.0, 10.0], defining the lower
180-
and upper bound, respectively. If not specified, will not
181-
mask the data based on this variable. Defaults to (6, 10).
180+
and upper bound, respectively. Defaults to (6, 10).
182181
wd_mask ([iterable], optional): Wind direction mask. Should
183182
be an iterable of length 2, e.g., [0.0, 180.0], defining
184183
the lower and upper bound, respectively. If not specified,
@@ -233,7 +232,7 @@ def _get_energy_ratios_allbins(
233232

234233
for ii, ti in enumerate(self.test_turbines):
235234
self.logger.info(
236-
" Determining energy ratios for test turbine = %03d." % (ti)
235+
" Determining energy ratios for test turbine = %03d." % ti
237236
+ " WD bias: %.3f deg." % wd_bias
238237
)
239238

@@ -420,9 +419,14 @@ def estimate_wd_bias(
420419
"""
421420
self.logger.info("Estimating the wind direction bias")
422421

423-
def cost_fun(wd_bias):
422+
def cost_fun(x: np.ndarray):
423+
"""Cost function to minimize.
424+
425+
Args:
426+
x (np.ndarray): Wind direction bias to evaluate. 1D array with 1 element.
427+
"""
424428
self._get_energy_ratios_allbins(
425-
wd_bias=wd_bias,
429+
wd_bias=x[0], # pass as float
426430
time_mask=time_mask,
427431
ws_mask=ws_mask,
428432
wd_mask=wd_mask,
@@ -467,7 +471,7 @@ def opt_finish(func, x0, args=()):
467471
# workers=opt_workers,
468472
)
469473

470-
wd_bias = x_opt
474+
wd_bias = x_opt[0]
471475
self.opt_wd_bias = wd_bias
472476
self.opt_cost = J_opt
473477
self.opt_wd_grid = x
@@ -476,7 +480,7 @@ def opt_finish(func, x0, args=()):
476480
# End with optimal results and bootstrapping
477481
self.logger.info(" Evaluating optimal solution with bootstrapping")
478482
self._get_energy_ratios_allbins(
479-
wd_bias=x_opt,
483+
wd_bias=wd_bias,
480484
time_mask=time_mask,
481485
ws_mask=ws_mask,
482486
wd_mask=wd_mask,
@@ -530,7 +534,7 @@ def plot_energy_ratios(
530534
er_out_test_turbine_list_scada_copy = self.er_out_test_turbine_list_scada.copy()
531535
# (Re)compute case with wd_bias=0
532536
self._get_energy_ratios_allbins(
533-
wd_bias=0,
537+
wd_bias=0.0,
534538
time_mask=self._input_args["time_mask"],
535539
ws_mask=self._input_args["ws_mask"],
536540
wd_mask=self._input_args["wd_mask"],

flasc/data_processing/filtering.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,14 @@ def filter_by_condition(
311311
if not apply_filters_to_df:
312312
df_in = df_in.copy()
313313

314-
# Mark data as faulty on the dataframe
314+
# Mark data as faulty on the dataframe, omitting boolean type columns.
315315
N_pre = [df_get_no_faulty_measurements(df_in, tii) for tii in ti]
316-
df_out = df_mark_turbdata_as_faulty(df=df_in, cond=condition, turbine_list=ti)
316+
df_out = df_mark_turbdata_as_faulty(
317+
df=df_in,
318+
cond=condition,
319+
turbine_list=ti,
320+
exclude_columns=df_in.select_dtypes(include=["bool"]).columns.tolist(),
321+
)
317322

318323
# Print the reduction in useful data to the console, if verbose
319324
if verbose:
@@ -1379,6 +1384,7 @@ def filter_df_by_faulty_impacting_turbines(df, ti, df_impacting_turbines, verbos
13791384
df=df,
13801385
cond=test_turbine_impacted,
13811386
turbine_list=[ti],
1387+
exclude_columns=df.select_dtypes(include=["bool"]).columns.tolist(),
13821388
)
13831389
N_post = df_get_no_faulty_measurements(df_out, ti)
13841390

flasc/data_processing/time_operations.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,21 @@ def df_movingaverage(
5656
# Carry out the mean calculations
5757
df_regular = (
5858
df[cols_regular] # Select only non-angular columns
59-
.rolling(window_width, center=center, axis=0, min_periods=min_periods)
59+
.rolling(window_width, center=center, min_periods=min_periods)
6060
.mean()
6161
)
6262

6363
df_cos = (
6464
df[cols_angular] # Select only angular columns
6565
.pipe(lambda df_: np.cos(df_ * np.pi / 180.0))
66-
.rolling(window_width, center=center, axis=0, min_periods=min_periods)
66+
.rolling(window_width, center=center, min_periods=min_periods)
6767
.mean()
6868
)
6969

7070
df_sin = (
7171
df[cols_angular] # Select only angular columns
7272
.pipe(lambda df_: np.sin(df_ * np.pi / 180.0))
73-
.rolling(window_width, center=center, axis=0, min_periods=min_periods)
73+
.rolling(window_width, center=center, min_periods=min_periods)
7474
.mean()
7575
)
7676

@@ -83,7 +83,7 @@ def df_movingaverage(
8383

8484
if calc_median_min_max_std: # if including other statistics
8585
df_regular_stats = (
86-
df.rolling(window_width, center=center, axis=0, min_periods=min_periods)
86+
df.rolling(window_width, center=center, min_periods=min_periods)
8787
.agg(["median", "min", "max", "std"])
8888
.pipe(lambda df_: flatten_cols(df_))
8989
)
@@ -168,7 +168,7 @@ def df_downsample(
168168

169169
# Now calculate downsampled dataframe, automatically
170170
# mark by label on the right (i.e., "past 10 minutes").
171-
df_resample = df.resample(window_width, label="right", axis=0)
171+
df_resample = df.resample(window_width, label="right")
172172

173173
# First calculate mean values of non-angular columns
174174
df_mean = df_resample[cols_regular].mean().copy()
@@ -204,7 +204,7 @@ def df_downsample(
204204
# Compute the stats for the non_angular columns
205205
df_stats_regular = (
206206
df_stats[cols_regular] # Select non-angular columns
207-
.resample(window_width, label="right", axis=0) # Resample to desired window
207+
.resample(window_width, label="right") # Resample to desired window
208208
.agg(["median", "min", "max", "std"]) # Perform aggregations
209209
.pipe(lambda df_: flatten_cols(df_)) # Flatten columns
210210
)
@@ -224,7 +224,7 @@ def df_downsample(
224224
.add(180) # Shift up by 180 (start of sequence for -180/180 wrap)
225225
.mod(360) # Wrap by 360
226226
.subtract(180) # Remove shift (end of sequence for -180/180 wrap)
227-
.resample(window_width, label="right", axis=0) # Resample to desired window
227+
.resample(window_width, label="right") # Resample to desired window
228228
)
229229

230230
# Now create the individual statistics
@@ -297,7 +297,7 @@ def df_downsample(
297297

298298
if return_index_mapping:
299299
df_tmp = pd.DataFrame(data={"time": df.reset_index()["time"], "tmp": 1}).resample(
300-
window_width, on="time", label="right", axis=0
300+
window_width, on="time", label="right"
301301
)
302302

303303
# Grab index of first and last time entry for each window

flasc/model_fitting/yaw_pow_fitting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def set_df(self, df, df_upstream, ti):
6767
if df_upstream is not None:
6868
df_upstr_ti = df_upstream[[ti in tl for tl in df_upstream["turbines"]]]
6969
df_upstr_ti = df_upstr_ti.reset_index(drop=True)
70-
in_range = [False for _ in range(df.shape[0])]
70+
in_range = np.array([False for _ in range(df.shape[0])])
7171
for i in range(df_upstr_ti.shape[0]):
7272
wd_min = df_upstr_ti.loc[i, "wd_min"]
7373
wd_max = df_upstr_ti.loc[i, "wd_max"]

0 commit comments

Comments
 (0)