Skip to content

Commit

Permalink
Sync: Merge v1.3.1 bug fixes into develop (#96)
Browse files Browse the repository at this point in the history
* Merge in changes from `main` branch (v1.3 -> v1.3.1) into `develop`, notably:

- Feature: Add PyPI integration by @Bartdoekemeijer in #87
- Bug fix: various small corrections by @Bartdoekemeijer in #86

---------

Co-authored-by: paulf81 <paul.fleming@nrel.gov>
Co-authored-by: Rafael M Mudafort <rafael.mudafort@nrel.gov>
  • Loading branch information
3 people authored Jul 3, 2023
1 parent 16520b5 commit d3b2deb
Show file tree
Hide file tree
Showing 13 changed files with 346 additions and 95 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

name: Upload Python Package

on:
release:
types: [published]

jobs:
deploy:
if: github.repository_owner == 'NREL'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
==========
=============================================
FLORIS-based Analysis for SCADA data (FLASC)
==========
=============================================

**Further documentation is available at http://flasc.readthedocs.io/.**

Expand Down
1 change: 0 additions & 1 deletion flasc/dataframe_operations/dataframe_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ def df_mark_turbdata_as_faulty(df, cond, turbine_list, exclude_columns=[]):
turbine_list = [turbine_list]

for ti in turbine_list:
N_init = df_get_no_faulty_measurements(df, ti)
cols = [s for s in df.columns if s[-4::] == ('_%03d' % ti)
and s not in exclude_columns]
df.loc[cond, cols] = None # Delete measurements
Expand Down
35 changes: 19 additions & 16 deletions flasc/dataframe_operations/dataframe_manipulations.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ def df_reduce_precision(df_in, verbose=False):
Returns:
df_out ([pd.DataFrame]): Reduced dataframe
"""
df_out = pd.DataFrame()
list_out = []
dtypes = df_in.dtypes
for ii, c in enumerate(df_in.columns):
datatype = str(dtypes[c])
Expand All @@ -711,42 +711,45 @@ def df_reduce_precision(df_in, verbose=False):
df_in[c], equal_nan=True))):
unique_values = np.unique(df_in[c])
if np.array_equal(unique_values, [0, 1]):
df_out[c] = df_in[c].astype(bool)
var_downsampled = df_in[c].astype(bool)
elif np.max(df_in[c]) < np.iinfo(np.int8).max:
df_out[c] = df_in[c].astype(np.int8)
var_downsampled = df_in[c].astype(np.int8)
elif np.max(df_in[c]) < np.iinfo(np.int16).max:
df_out[c] = df_in[c].astype(np.int16)
var_downsampled = df_in[c].astype(np.int16)
elif np.max(df_in[c]) < np.iinfo(np.int32).max:
df_out[c] = df_in[c].astype(np.int32)
var_downsampled = df_in[c].astype(np.int32)
else:
df_out[c] = df_in[c].astype(np.int64)
var_downsampled = df_in[c].astype(np.int64)
else: # If not, just simplify as float32
df_out[c] = df_in[c].astype(np.float32)
max_error = np.max(np.abs(df_out[c]-df_in[c]))
var_downsampled = df_in[c].astype(np.float32)
max_error = np.max(np.abs(var_downsampled-df_in[c]))
if verbose:
print("Column %s ['%s'] was downsampled to %s."
% (c, datatype, df_out.dtypes[ii]))
% (c, datatype, var_downsampled.dtypes))
print( "Max error: ", max_error)
elif ((datatype == 'int64') or
(datatype == 'int32') or
(datatype == 'int')):
if all(np.unique(df_in[c]) == [0, 1]):
df_out[c] = df_in[c].astype(bool)
if np.array_equal(np.unique(df_in[c]), [0, 1]):
var_downsampled = df_in[c].astype(bool)
elif len(np.unique(df_in[c])) < 100:
df_out[c] = df_in[c].astype(np.int16)
var_downsampled = df_in[c].astype(np.int16)
else:
df_out[c] = df_in[c].astype(np.int32)
max_error = np.max(np.abs(df_out[c]-df_in[c]))
var_downsampled = df_in[c].astype(np.int32)
max_error = np.max(np.abs(var_downsampled-df_in[c]))
if verbose:
print("Column %s ['%s'] was downsampled to %s."
% (c, datatype, df_out.dtypes[ii]))
% (c, datatype, var_downsampled.dtypes))
print( "Max error: ", max_error)
else:
if verbose:
print("Datatype '%s' not recognized. Not downsampling."
% datatype)
df_out[c] = df_in[c]
var_downsampled = df_in[c]

list_out.append(var_downsampled)

df_out = pd.concat(list_out, axis=1, ignore_index=False)
return df_out


Expand Down
31 changes: 23 additions & 8 deletions flasc/energy_ratio/energy_ratio_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,29 @@ def plot(
for ii, df in enumerate(energy_ratios):
df = df.copy()

if df.shape[0] < 2:
# Do not plot single values
continue

# Get x-axis values
x = np.array(df["wd_bin"], dtype=float)

# Add NaNs to avoid connecting plots over gaps
dwd = np.min(x[1::] - x[0:-1])
jumps = np.where(np.diff(x) > dwd * 1.50)[0]
if len(jumps) > 0:
df = df.append(
pd.DataFrame(
{
"wd_bin": x[jumps] + dwd / 2.0,
"N_bin": [0] * len(jumps),
}
)
df = pd.concat(
[
df,
pd.DataFrame(
{
"wd_bin": x[jumps] + dwd / 2.0,
"N_bin": [0] * len(jumps),
}
)
],
axis=0,
ignore_index=False,
)
df = df.iloc[np.argsort(df["wd_bin"])].reset_index(drop=True)
x = np.array(df["wd_bin"], dtype=float)
Expand Down Expand Up @@ -176,7 +185,13 @@ def plot(
)

# Plot the bin count
if df_freqs is not None:
is_none = False
if df_freqs is None:
is_none = True
elif isinstance(df_freqs, list):
is_none = np.any([c is None for c in df_freqs])

if not is_none:
for ii, df_freq in enumerate(df_freqs):
wd_bins = df_freq["wd_bin"].unique()
n_ws_bins = len(df_freq["ws_bin_edges"].unique())
Expand Down
2 changes: 1 addition & 1 deletion flasc/energy_ratio/energy_ratio_wd_bias_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def cost_fun(wd_bias):
xtol=0.1, disp=True)
)

dran = opt_search_range[1]-opt_search_range[0]
dran = opt_search_range[1] - opt_search_range[0]
x_opt, J_opt, x, J = opt.brute(
func=cost_fun,
ranges=[opt_search_range],
Expand Down
6 changes: 5 additions & 1 deletion flasc/optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,11 @@ def match_y_curves_by_offset(yref, ytest, dy_eval=None, angle_wrapping=True):
ytest_cor = ytest - dy
y_error = np.abs(yref-ytest_cor)

J = np.nanmean(y_error**2.0)
if np.all(np.isnan(y_error)) | (len(y_error) < 1):
J = np.nan
else:
J = np.nanmean(y_error**2.0)

if np.isnan(J_opt):
if not np.isnan(J):
J_opt = J
Expand Down
Loading

0 comments on commit d3b2deb

Please sign in to comment.