def weibull(self, column=None, ws_intervals=1, method='EuroAtlas', plot='matplotlib'): '''Calculate distribution and weibull parameters from data Parameters: ___________ column: tuple, default None Column to perform weibull analysis on ws_intervals: float, default=1 Wind Speed intervals on which to bin method: string, default 'LeastSq' Weibull calculation method. plot: string, default 'matplotlib' Choose whether or not to plot your data, and what method. Currently only supporting matplotlib, but hoping to add Bokeh as that library evolves. Returns: ________ DataFrame with hourly data distributions ''' ws_data = self.data[column] ws_range = np.arange(0, ws_data.max() + ws_intervals, ws_intervals) binned = pd.cut(ws_data, ws_range) dist_10min = pd.value_counts(binned).reindex(binned.levels) dist = pd.DataFrame({'Binned: 10Min': dist_10min}) dist['Binned: Hourly'] = dist['Binned: 10Min'] / 6 dist = dist.fillna(0) normed = dist['Binned: 10Min'] / dist['Binned: 10Min'].sum() ws_normed = normed.values x = np.arange(0, len(ws_normed), ws_intervals) if method == 'EuroAtlas': A, k = west.euro_atlas(ws_data) elif method == 'LeastSq': A, k = west.least_sq(ws_normed, x) A = round(A, 3) k = round(k, 3) rv = spystats.exponweib(1, k, scale=A, floc=0) if plot == 'matplotlib': smooth = np.arange(0, 100, 0.1) plottools.weibull(smooth, rv.pdf(smooth), binned=True, binned_x=x, binned_data=dist['Binned: Hourly'], align='edge') return {'Weibull A': A, 'Weibull k': k, 'Dist': dist}
def weibull_hourly(k=None, A=None, Vmean=None, bins=np.arange(0, 41, 1), plot='matplotlib'): '''Calculate weibull distribution and annual hours from weibull k and A or Vmean parameters. This distribution is based on multiplying the PDF by the annual hours for each wind speed bin. Defaults to Vmean for calculation of A if both Vmean and A are provided. Parameters: ---------- k: float, int Weibull k parameters A: float, int Weibull A parameter Vmean: float, int Mean wind speed, for calculating weibull with Vmean and k only bins: array, default np.arange(0, 41, 1) Wind speed bins for estimating and plotting weibull plot: string, default 'matplotlib' Choose whether or not to plot your data, and what method. Currently only supporting matplotlib, but hoping to add Bokeh as that library evolves. Returns: ________ Dataframe of wind-speed binned annual hours and normed values ''' if Vmean: A = Vmean / (gamma(1 + 1 / k)) step_size = bins[1] - bins[0] rv = spystats.exponweib(1, k, scale=A, floc=0) hourly = rv.pdf(bins) * 8760 * step_size df_hourly = pd.DataFrame( { 'Annual Hours': hourly, 'Normalized': hourly / hourly.sum() }, index=bins) cont_bins = np.arange(0, 100, 0.1) if plot == 'matplotlib': plottools.weibull(cont_bins, rv.pdf(cont_bins), binned=True, binned_x=bins, binned_data=hourly, align='center') return df_hourly
def weibull(self, column=None, ws_intervals=1, method='EuroAtlas', plot='matplotlib'): '''Calculate distribution and weibull parameters from data Parameters: ___________ column: tuple, default None Column to perform weibull analysis on ws_intervals: float, default=1 Wind Speed intervals on which to bin method: string, default 'LeastSq' Weibull calculation method. plot: string, default 'matplotlib' Choose whether or not to plot your data, and what method. Currently only supporting matplotlib, but hoping to add Bokeh as that library evolves. Returns: ________ DataFrame with hourly data distributions ''' ws_data = self.data[column] ws_range = np.arange(0, ws_data.max()+ws_intervals, ws_intervals) binned = pd.cut(ws_data, ws_range) dist_10min = pd.value_counts(binned).reindex(binned.levels) dist = pd.DataFrame({'Binned: 10Min': dist_10min}) dist['Binned: Hourly'] = dist['Binned: 10Min']/6 dist = dist.fillna(0) normed = dist['Binned: 10Min']/dist['Binned: 10Min'].sum() ws_normed = normed.values x = np.arange(0, len(ws_normed), ws_intervals) if method == 'EuroAtlas': A, k = west.euro_atlas(ws_data) elif method == 'LeastSq': A, k = west.least_sq(ws_normed, x) A = round(A, 3) k = round(k, 3) rv = spystats.exponweib(1, k, scale=A, floc=0) if plot == 'matplotlib': smooth = np.arange(0, 100, 0.1) plottools.weibull(smooth, rv.pdf(smooth), binned=True, binned_x=x, binned_data=dist['Binned: Hourly'], align='edge') return {'Weibull A': A, 'Weibull k': k, 'Dist': dist}
def weibull_hourly(k=None, A=None, Vmean=None, bins=np.arange(0, 41, 1), plot='matplotlib'): '''Calculate weibull distribution and annual hours from weibull k and A or Vmean parameters. This distribution is based on multiplying the PDF by the annual hours for each wind speed bin. Defaults to Vmean for calculation of A if both Vmean and A are provided. Parameters: ---------- k: float, int Weibull k parameters A: float, int Weibull A parameter Vmean: float, int Mean wind speed, for calculating weibull with Vmean and k only bins: array, default np.arange(0, 41, 1) Wind speed bins for estimating and plotting weibull plot: string, default 'matplotlib' Choose whether or not to plot your data, and what method. Currently only supporting matplotlib, but hoping to add Bokeh as that library evolves. Returns: ________ Dataframe of wind-speed binned annual hours and normed values ''' if Vmean: A = Vmean/(gamma(1+1/k)) step_size = bins[1]-bins[0] rv = spystats.exponweib(1, k, scale=A, floc=0) hourly = rv.pdf(bins)*8760*step_size df_hourly = pd.DataFrame({'Annual Hours': hourly, 'Normalized': hourly/hourly.sum()}, index=bins) cont_bins = np.arange(0, 100, 0.1) if plot == 'matplotlib': plottools.weibull(cont_bins, rv.pdf(cont_bins), binned=True, binned_x=bins, binned_data=hourly, align='center') return df_hourly