def plot_cdf(self, x: ndarray, *, show_ecdf: bool = False, **kwargs): cdf_value = self.cdf_estimate(x=x) if show_ecdf: if not isinstance(self.univariate_data, ndarray): raise Exception( "Should specify 'univariate_data' to include the empirical cdf plot" ) else: protect = kwargs.pop('label') if 'label' in kwargs else None ax = self.plot_ecdf(x=x, color='r', linestyle='--', linewidth=1.0, label='Empirical cdf', **kwargs) kwargs.setdefault('label', protect) else: ax = None return series(x, cdf_value, ax=ax, y_label='Cumulative probability', color='k', linestyle='-', linewidth=0.5, **kwargs)
def plot_pdf(self, x: ndarray, pdf_value=None, show_hist: bool = False, ax=None, *args, **kwargs): pdf_value = pdf_value if pdf_value is not None else self.pdf_estimate( x=x) if show_hist: if not isinstance(self.univariate_data, ndarray): raise Exception( "Should specify 'univariate_data' to include the histogram plot" ) else: protect = kwargs.pop('label') if 'label' in kwargs else None bins = kwargs.pop('bins') if 'bins' in kwargs else None ax = self.plot_hist(ax, density=True, color='darkorange', label='histogram', bins=bins, *args, **kwargs) kwargs.setdefault('label', protect) color = kwargs.pop('color') if 'color' in kwargs else 'k' linestyle = kwargs.pop('linestyle') if 'linestyle' in kwargs else '-' return series(x, pdf_value, ax=ax, y_label='Probability density', color=color, linestyle=linestyle, linewidth=1, *args, **kwargs)
def plot_one_model_uncertainty_and_save_csv(model_name, y_linestyle: str, *, save_csv_name: str = None): if model_name == 'two_dim_mc': model_results = two_dim_mc_results elif model_name == 'cvine_gmcm': model_results = cvine_gmcm_results elif model_name == 'empirical': model_results = empirical_results else: raise y1 = model_results['pout_by_what_model_5'][time_mask_pure] / 3000 y2 = model_results['pout_by_what_model_95'][time_mask_pure] / 3000 y_mean = model_results['pout_by_what_model_mean'][ time_mask_pure] / 3000 ax = series_uncertainty_plot( xx, y1=test_data['test_pout_actual_5'][time_mask_pure] / 3000, y2=test_data['test_pout_actual_95'][time_mask_pure] / 3000, facecolor='g', edgecolor='g', hatch='/' * 6, linestyle='-', linewidth=1, alpha=0.2) ax = series_uncertainty_plot(xx, y1=y1, y2=y2, ax=ax, facecolor='b', edgecolor='b', hatch='\\' * 6, linestyle='-', linewidth=1, alpha=0.2) ax = series(x=xx, y=test_data.get('test_pout_actual')[time_mask_pure] / 3000, ax=ax, linestyle='-', color=[0, 1, 0]) ax = series(xx, y_mean, ax=ax, linestyle=y_linestyle, color='b', save_file_=cvine_gmcm_path + model_name, x_label='Time stamp (x-th day in the season)', y_label='Power output (p.u.)', x_lim=(xx[0] - 0.01, xx[-1] + 0.01), y_lim=(-0.01, 1.01)) if save_csv_name is not None: f = open(cvine_gmcm_path + save_csv_name + '.csv', 'w', encoding='utf-8') csv_writer = csv.writer(f) header = [ 'actual_Pout_mean', 'actual_Pout_5_percentile', 'actual_Pout_95_percentile' ] header_extend = [ '_model_mean', '_model_5_percentile', '_model_95_percentile' ] header_extend = [model_name + x for x in header_extend] header.extend(header_extend) csv_writer.writerow(header) rows = np.stack( (test_data['test_pout_actual'][time_mask_pure] / 3000, test_data['test_pout_actual_5'][time_mask_pure] / 3000, test_data['test_pout_actual_95'][time_mask_pure] / 3000, y_mean, y1, y2), axis=1) csv_writer.writerows(rows.tolist())
def find_extreme_wind_speed_for_rated_power_sasa(rated_power=3000, bin_step=0.5): # histogram measurements = load_old_wind_farm_corrected() measurements.iloc[:, -1] /= 3000 measurements.iloc[:, -1] /= 0.98 # 画10-min的 bivariate = Bivariate(measurements['Wind speed'].values, measurements.iloc[:, -1].values, bin_step=bin_step) key = bivariate.find_mob_key_according_to_mob_or_mob_fitting_like_dict( 23, bivariate.mob)['accurate_bin_key'] _5_percentile_in_mob = bivariate.cal_mob_statistic_eg_quantile( np.array([0.05])) _5_percentile_in_mob *= 0.99 _95_percentile_in_mob = bivariate.cal_mob_statistic_eg_quantile( np.array([0.95])) # ax = vlines(_5_percentile_in_mob[key, 1], color='k', linestyles=':', # label='5$^\mathrm{th}$ percentile') # ax = vlines(_95_percentile_in_mob[key, 1], color='r', linestyles='-', # label='95$^\mathrm{th}$ percentile', # ax=ax) # hist(bivariate.mob[key]['dependent_var_in_this_bin'], # x_label='Power output (p.u.) in wind speed bin = [22.75, 23.25) (m/s)', # y_label='Probability density', # x_lim=(0, 1.03), # y_lim=(0, 26), # bins=np.arange(0, 1.025, 0.0125) + 0.0125 / 2, # normed=True, # ax=ax, # label='WF data', # legend_loc='upper left') tt = 1 # resample # ws, pout = measurements['Wind speed'].values, measurements.iloc[:, -1].values # ws = ws.reshape(-1, 6) # pout = pout.reshape(-1, 6) # ws = np.nanmean(ws, axis=1) # pout = np.nanmean(pout, axis=1) # scatter(ws, pout) # bivariate = Bivariate(ws, pout, bin_step=bin_step) # 基于所有的原始数据,画风速-power的scatter ax = scatter( measurements['Wind speed'].values, measurements.iloc[:, -1], x_lim=(0, 28.5), y_lim=(-0.0125, 1.05), c=(0.6, 0.6, 0.6), # label='WF wind speed - power output data', alpha=0.2, figure_size=(5, 5 * 0.618 + 0.22)) # 画5/95 ax = series( bivariate.array_of_bin_boundary[:, 1], _5_percentile_in_mob[:, -1], linestyle=':', color='k', label='5$^\mathrm{th}$ percentile power curve', ax=ax, linewidth=2.5, ) ax = vlines(bivariate.mob[28]['this_bin_boundary'][1], ax=ax, color='cyan', linewidth=2.5) ax = vlines(bivariate.mob[45]['this_bin_boundary'][1], ax=ax, color='g', linestyles='-.', linewidth=2.5) ax = series( bivariate.array_of_bin_boundary[:, 1], _95_percentile_in_mob[:, -1], ax=ax, color='r', x_label='Wind Speed (m/s)', y_label='Power Output (p.u.)', x_lim=(0, 28.5), y_lim=(-0.0125, 1.05), label='95$^\mathrm{th}$ percentile power curve', legend_loc='upper left', linewidth=2.5, ) ax.legend(bbox_to_anchor=(-0.12, 1.02, 1.12, .102), loc=3, ncol=2, mode="expand", borderaxespad=0.) ax.annotate("14.5 m/s", xy=(14.5, -0.0125), xytext=(10.5, 0.2), arrowprops=dict(arrowstyle="->")) ax.annotate("23 m/s", xy=(23, -0.0125), xytext=(19, 0.2), arrowprops=dict(arrowstyle="->")) tt = 1
def plot_pdf_like_ndarray(self, *args, **kwargs): return series(self.pdf_like_ndarray[:, 1], self.pdf_like_ndarray[:, 0], *args, **kwargs)
def plot_ecdf(self, x: ndarray = None, **kwargs): return series(x, self.ecdf(x), **kwargs)