From 8dfe698316fb7b4d7cc269d1770ab0086a258108 Mon Sep 17 00:00:00 2001 From: kumar10725 <48549256+kumar10725@users.noreply.github.com> Date: Tue, 15 Sep 2020 16:46:57 +0800 Subject: [PATCH 1/4] Speed Improvement in "power_curve_density_correction" Convert Pandas Series to Numpy Array for faster numpy interpolation (np.interp) on larger dataset. --- windpowerlib/power_output.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/windpowerlib/power_output.py b/windpowerlib/power_output.py index d254200c..41a161f9 100644 --- a/windpowerlib/power_output.py +++ b/windpowerlib/power_output.py @@ -172,14 +172,11 @@ def power_curve( def power_curve_density_correction( - wind_speed, power_curve_wind_speeds, power_curve_values, density -): + wind_speed, power_curve_wind_speeds, power_curve_values, density): r""" Calculates the turbine power output using a density corrected power curve. - This function is carried out when the parameter `density_correction` of an instance of the :class:`~.modelchain.ModelChain` class is True. - Parameters ---------- wind_speed : :pandas:`pandas.Series` or numpy.array @@ -192,21 +189,17 @@ def power_curve_density_correction( `power_curve_wind_speeds`. density : :pandas:`pandas.Series` or numpy.array Density of air at hub height in kg/m³. - Returns ------- :pandas:`pandas.Series` or numpy.array Electrical power output of the wind turbine in W. Data type depends on type of `wind_speed`. - Notes ----- The following equation is used for the site specific power curve wind speeds [1]_ [2]_ [3]_: - .. math:: v_{site}=v_{std}\cdot\left(\frac{\rho_0} {\rho_{site}}\right)^{p(v)} - with: .. math:: p=\begin{cases} \frac{1}{3} & v_{std} \leq 7.5\text{ m/s}\\ @@ -214,19 +207,15 @@ def power_curve_density_correction( \text{ m/s} Date: Tue, 15 Sep 2020 10:05:43 +0000 Subject: [PATCH 2/4] Fixing style errors. --- windpowerlib/power_output.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/windpowerlib/power_output.py b/windpowerlib/power_output.py index 41a161f9..d0277893 100644 --- a/windpowerlib/power_output.py +++ b/windpowerlib/power_output.py @@ -172,7 +172,8 @@ def power_curve( def power_curve_density_correction( - wind_speed, power_curve_wind_speeds, power_curve_values, density): + wind_speed, power_curve_wind_speeds, power_curve_values, density +): r""" Calculates the turbine power output using a density corrected power curve. This function is carried out when the parameter `density_correction` of an @@ -235,16 +236,16 @@ def power_curve_density_correction( + "height is needed." ) - #NOTE : CHANGES ARE MADE HERE FOR SPEED IMPROVEMENT + # NOTE : CHANGES ARE MADE HERE FOR SPEED IMPROVEMENT # create a flag for pandas Series type Panda_series = False - + if isinstance(wind_speed, pd.Series): - #save the indexes for later conversion to pd.Series + # save the indexes for later conversion to pd.Series indexes = wind_speed.index - # change the wind speed Series to numpy array + # change the wind speed Series to numpy array wind_speed = wind_speed.values - # Set the panda flag True + # Set the panda flag True Panda_series = True power_output = [ @@ -267,10 +268,10 @@ def power_curve_density_correction( ] # Power_output as pd.Series if wind_speed is pd.Series (else: np.array) - if Panda_series: #use the flag to check + if Panda_series: # use the flag to check power_output = pd.Series( data=power_output, - index=indexes, # Use previously saved indexes + index=indexes, # Use previously saved indexes name="feedin_power_plant", ) else: From 11a321011cdb253742dab5044670e9e13f56abcb Mon Sep 17 00:00:00 2001 From: Kumar Shivam <48549256+kumar10725@users.noreply.github.com> Date: Tue, 15 Sep 2020 21:38:59 +0800 Subject: [PATCH 3/4] Update power_output.py --- windpowerlib/power_output.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/windpowerlib/power_output.py b/windpowerlib/power_output.py index d0277893..684009f7 100644 --- a/windpowerlib/power_output.py +++ b/windpowerlib/power_output.py @@ -236,17 +236,16 @@ def power_curve_density_correction( + "height is needed." ) - # NOTE : CHANGES ARE MADE HERE FOR SPEED IMPROVEMENT - # create a flag for pandas Series type - Panda_series = False - + # Convert pandas.Series to a numpy array to speed up the interpolation below. if isinstance(wind_speed, pd.Series): # save the indexes for later conversion to pd.Series - indexes = wind_speed.index + wind_speed_indexes = wind_speed.index # change the wind speed Series to numpy array wind_speed = wind_speed.values - # Set the panda flag True - Panda_series = True + # Set the panda series flag True + panda_series = True + else: + panda_series = False power_output = [ ( @@ -268,10 +267,10 @@ def power_curve_density_correction( ] # Power_output as pd.Series if wind_speed is pd.Series (else: np.array) - if Panda_series: # use the flag to check + if panda_series: # use the flag to check if the data should be converted back to pandas.Series power_output = pd.Series( data=power_output, - index=indexes, # Use previously saved indexes + index=wind_speed_indexes, # Use previously saved wind speed indexes name="feedin_power_plant", ) else: From 7c497637e7cacfb90cb8647e0395512fbb3164b6 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Tue, 15 Sep 2020 13:39:05 +0000 Subject: [PATCH 4/4] Fixing style errors. --- windpowerlib/power_output.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/windpowerlib/power_output.py b/windpowerlib/power_output.py index 684009f7..8b1425e7 100644 --- a/windpowerlib/power_output.py +++ b/windpowerlib/power_output.py @@ -236,7 +236,7 @@ def power_curve_density_correction( + "height is needed." ) - # Convert pandas.Series to a numpy array to speed up the interpolation below. + # Convert pandas.Series to a numpy array to speed up the interpolation below. if isinstance(wind_speed, pd.Series): # save the indexes for later conversion to pd.Series wind_speed_indexes = wind_speed.index @@ -267,7 +267,9 @@ def power_curve_density_correction( ] # Power_output as pd.Series if wind_speed is pd.Series (else: np.array) - if panda_series: # use the flag to check if the data should be converted back to pandas.Series + if ( + panda_series + ): # use the flag to check if the data should be converted back to pandas.Series power_output = pd.Series( data=power_output, index=wind_speed_indexes, # Use previously saved wind speed indexes