def plot_sector_ratio(sec_ratio, wdir, sec_ratio_dist, col_names, boom_dir_1=-1, boom_dir_2=-1): """ Accepts a DataFrame table, along with 2 anemometer names, and one wind vane name and plots the speed ratio by sector. Optionally can include anemometer boom directions also. :param sec_ratio: Series of sector_ratios :type sec_ratio: pandas.Series :param wdir: Direction series :type wdir: pandas.Series :param sec_ratio_dist: DataFrame from SectorRatio.by_sector() :type sec_ratio_dist; pandas.Series :param boom_dir_1: Boom direction in degrees of speed_col_name_1. Defaults to -1. :type boom_dir_1: float :param boom_dir_2: Boom direction in degrees of speed_col_name_2. Defaults to -1. :type boom_dir_2: float :param col_names: A list of strings containing column names of wind speeds, first string is divisor and second is dividend :type col_names: list(str) :returns A speed ratio plot showing average speed ratio by sector and scatter of individual data points. """ radians = np.radians(utils._get_dir_sector_mid_pts(sec_ratio_dist.index)) fig = plt.figure(figsize=(10, 10)) ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True) ax.set_theta_zero_location('N') ax.set_theta_direction(-1) ax.set_thetagrids(utils._get_dir_sector_mid_pts(sec_ratio_dist.index)) ax.plot(np.append(radians, radians[0]), sec_ratio_dist['Mean_Sector_Ratio'].append(sec_ratio_dist.iloc[0]), color=bw_colors('green'), linewidth=4) # plt.title('Speed Ratio by Direction') # Get max and min levels and set chart axes max_level = sec_ratio_dist['Mean_Sector_Ratio'].max() + 0.05 min_level = sec_ratio_dist['Mean_Sector_Ratio'].min() - 0.1 ax.set_ylim(min_level, max_level) # Add boom dimensions to chart, if required width = np.pi / 108 radii = max_level annotate = False annotation_text = '* Plot generated using ' if boom_dir_1 >= 0: boom_dir_1 = np.radians(boom_dir_1) ax.bar(boom_dir_1, radii, width=width, bottom=min_level, color='#659CEF') if boom_dir_2 == -1: annotation_text += col_names[1] + ' (top mounted) divided by ' + col_names[0] + ' (blue boom)' annotate = True if boom_dir_2 >= 0: boom_dir_2 = np.radians(boom_dir_2) ax.bar(boom_dir_2, radii, width=width, bottom=min_level, color='#DCF600') if boom_dir_1 == -1: annotation_text += col_names[1] + ' (yellow green boom) divided by ' + col_names[0] + ' (top mounted)' annotate = True if boom_dir_2 >= 0 and boom_dir_1 >= 0: annotation_text += col_names[1] + ' (yellow green boom) divided by ' + col_names[0] + ' (blue boom)' annotate = True if annotate: ax.annotate(annotation_text, xy=(0.5, 0.035), xycoords='figure fraction', horizontalalignment='center') ax.scatter(np.radians(wdir), sec_ratio, color=bw_colors('asphault'), alpha=0.3, s=1) return ax.get_figure()
def plot_TI_by_sector(turbulence, wdir, ti): radians = np.radians(utils._get_dir_sector_mid_pts(ti.index)) fig = plt.figure(figsize=(10, 10)) ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True) ax.set_theta_zero_location('N') ax.set_theta_direction(-1) ax.set_thetagrids(utils._get_dir_sector_mid_pts(ti.index)) ax.plot(np.append(radians, radians[0]), ti.append(ti.iloc[0])['Mean_TI'], color=bw_colors('green'), linewidth=4, figure=fig) maxlevel = ti['Mean_TI'].max() + 0.1 ax.set_ylim(0, maxlevel) ax.scatter(np.radians(wdir), turbulence, color=bw_colors('asphault'), alpha=0.3, s=1) ax.legend(loc=8, framealpha=1) return ax.get_figure()
def plot_shear_by_sector(shear, wdir, shear_dist): radians = np.radians(utils._get_dir_sector_mid_pts(shear_dist.index)) fig = plt.figure(figsize=(10, 10)) ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True) ax.set_theta_zero_location('N') ax.set_theta_direction(-1) ax.set_thetagrids(utils._get_dir_sector_mid_pts(shear_dist.index)) ax.plot(np.append(radians, radians[0]), shear_dist.append(shear_dist.iloc[0])['Mean_Shear'], color=bw_colors('green'), linewidth=4) # ax.set_title('Shear by Direction') maxlevel = shear_dist['Mean_Shear'].max() + 0.1 ax.set_ylim(0, maxlevel) ax.scatter(np.radians(wdir), shear, color=bw_colors('asphault'), alpha=0.3, s=1) ax.legend(loc=8, framealpha=1) return ax.get_figure()
def plot_sector_ratio(sec_ratio, wddir, sec_ratio_dist, col_names, boom_dir_1=-1, boom_dir_2=-1): """ Accepts a dataframe table, along with 2 anemometer names, and one wind vane name and plots the speed ratio by sector. Optionally can include anemometer boom directions also. :param sec_ratio: :param wddir: :param sec_ratio_dist: Dataframe from SectorRation.by_speed() :param boom_dir_1: Boom direction in degrees of speed_col_name_1. Defaults to 0. :param boom_dir_2: Boom direction in degrees of speed_col_name_2. Defaults to 0. :param col_names: A list of strings containing column names of wind speeds :returns A speed ratio plot showing average speed ratio by sector and scatter of individual datapoints. """ radians = np.radians(utils._get_dir_sector_mid_pts(sec_ratio_dist.index)) fig = plt.figure(figsize=(10, 10)) ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True) ax.set_theta_zero_location('N') ax.set_theta_direction(-1) ax.set_thetagrids(utils._get_dir_sector_mid_pts(sec_ratio_dist.index)) ax.plot(np.append(radians, radians[0]), sec_ratio_dist['Mean_Sector_Ratio'].append(sec_ratio_dist.iloc[0]), c=bw_colors('green'), linewidth=4) # plt.title('Speed Ratio by Direction') # Get max and min levels and set chart axes maxlevel = sec_ratio_dist['Mean_Sector_Ratio'].max() + 0.05 minlevel = sec_ratio_dist['Mean_Sector_Ratio'].min() - 0.1 ax.set_ylim(minlevel, maxlevel) # Add boom dimensions to chart, if required width = np.pi / 108 radii = maxlevel ctr = 0 if boom_dir_1 >= 0: boom_dir_1 = np.radians(boom_dir_1) ax.bar(boom_dir_1, radii, width=width, bottom=minlevel, color='#659CEF') ctr += 1 if boom_dir_2 >= 0: boom_dir_2 = np.radians(boom_dir_2) ax.bar(boom_dir_2, radii, width=width, bottom=minlevel, color='#DCF600') ctr += 1 if ctr == 2: ax.annotate('*Plot generated using ' + col_names[1] + ' (yellow green boom) divided by' + col_names[0] + ' (blue boom)', xy=(20, 10), xycoords='figure pixels') ax.scatter(np.radians(wddir), sec_ratio, c=bw_colors('asphault'), alpha=0.3, s=1) return ax.get_figure()
def plot_shear_by_sector(scale_variable, wind_rose_data, calc_method='power_law'): result = wind_rose_data.copy(deep=False) radians = np.radians(utils._get_dir_sector_mid_pts(scale_variable.index)) sectors = len(result) fig = plt.figure(figsize=(12, 12), ) ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True) ax.set_theta_zero_location('N') ax.set_theta_direction(-1) bin_edges = pd.Series([]) for i in range(sectors): bin_edges[i] = float( re.findall(r"[-+]?\d*\.\d+|\d+", wind_rose_data.index[i])[0]) if i == sectors - 1: bin_edges[i + 1] = abs( float( re.findall(r"[-+]?\d*\.\d+|\d+", wind_rose_data.index[i])[1])) label = '' if calc_method == 'power_law': label = 'Mean_Shear' if calc_method == 'log_law': label = 'Mean_Roughness_Coefficient' scale_variable_y = np.append(scale_variable, scale_variable[0]) plot_x = np.append(radians, radians[0]) scale_to_fit = max(scale_variable) / max(result / 100) wind_rose_r = (result / 100) * scale_to_fit bin_edges = np.array(bin_edges) width = pd.Series([]) for i in range(len(bin_edges) - 1): if bin_edges[i + 1] == 0: width[i] = 2 * np.pi * (360 - bin_edges[i]) / 360 - (np.pi / 180) elif bin_edges[i + 1] > bin_edges[i]: width[i] = 2 * np.pi * ( (bin_edges[i + 1] - bin_edges[i]) / 360) - (np.pi / 180) else: width[i] = 2 * np.pi * (( (360 + bin_edges[i + 1]) - bin_edges[i]) / 360) - (np.pi / 180) ax.bar(radians, wind_rose_r, width=width, color=COLOR_PALETTE.secondary, align='center', edgecolor=[COLOR_PALETTE.secondary for i in range(len(result))], alpha=0.8, label='Wind_Directional_Frequency') maxlevel = (max(scale_variable_y)) + max(scale_variable_y) * .1 ax.set_thetagrids(radians * 180 / np.pi) ax.plot(plot_x, scale_variable_y, color=COLOR_PALETTE.primary, linewidth=4, label=label) ax.set_ylim(0, top=maxlevel) ax.legend(loc=8, framealpha=1) return ax.get_figure()