def test_sector_ratio(): data = bw.load_csv(bw.datasets.shell_flats_80m_csv) sec_rat_data = bw.sector_ratio(data['WS70mA100NW_Avg'], data['WS70mA100SE_Avg'], data['WD50mW200PNW_VAvg'], sectors=72, boom_dir_1=315, boom_dir_2=135, return_data=True)[1] data = bw.load_csv(bw.datasets.demo_data) bw.sector_ratio(data[['Spd40mN']], data.Spd60mN, wdir=data[['Dir38mS']]) bw.sector_ratio(data.Spd40mN, data.Spd60mN, wdir=data.Dir38mS, direction_bin_array=[0, 45, 135, 180, 220, 360], boom_dir_1=160, boom_dir_2=340) assert True
def test_monthly_means(): # Load data bw.monthly_means(bw.load_csv(bw.datasets.shell_flats_80m_csv)) bw.monthly_means(bw.load_csv(bw.datasets.shell_flats_80m_csv)[['WS70mA100NW_Avg']]) bw.monthly_means(bw.load_csv(bw.datasets.shell_flats_80m_csv)[['WS70mA100NW_Avg','WS70mA100SE_Avg', 'WS50mA100NW_Avg','WS50mA100SE_Avg', 'WS20mA100CB1_Avg','WS20mA100CB2_Avg']], return_data=True) bw.monthly_means(bw.load_csv(bw.datasets.shell_flats_80m_csv).WS80mWS425NW_Avg, return_data=True) assert True
def test_load_csv(): data = bw.load_csv('../datasets/demo/demo_data.csv') data2 = bw.load_csv('../datasets/demo/demo_data2.csv', dayfirst=True) data3 = bw.load_csv('../datasets/demo/demo_data3.csv', dayfirst=True) data4 = bw.load_csv('../datasets/demo/demo_data4.csv', dayfirst=True) assert (data['2016-01-09 15:30:00':'2016-01-10 23:50:00'].fillna(-999) == data2['2016-01-09 15:30:00':'2016-01-10 23:50:00'].fillna(-999) ).all().all() assert (data['2016-01-09 15:30:00':'2016-01-10 23:50:00'].fillna(-999) == data3['2016-01-09 15:30:00':'2016-01-10 23:50:00'].fillna(-999) ).all().all() assert (data['2016-01-09 15:30:00':'2016-01-10 23:50:00'].fillna(-999) == data4['2016-01-09 15:30:00':'2016-01-10 23:50:00'].fillna(-999) ).all().all()
def test_plot_timeseries(): data = bw.load_csv(bw.datasets.demo_data) bw.plot_timeseries(data[['Spd40mN', 'Spd60mS', 'T2m']]) bw.plot_timeseries(data.Spd40mN, date_from='2017-09-01') bw.plot_timeseries(data.Spd40mN, date_to='2017-10-01') bw.plot_timeseries(data.Spd40mN, date_from='2017-09-01', date_to='2017-10-01') bw.plot_timeseries(data.Spd40mN, date_from='2017-09-01', date_to='2017-10-01', y_limits=(0, None)) bw.plot_timeseries(data.Spd40mN, date_from='2017-09-01', date_to='2017-10-01', y_limits=None) bw.plot_timeseries(data.Spd40mN, date_from='2017-09-01', date_to='2017-10-01', y_limits=(0, 25)) bw.plot_timeseries(data.Spd40mN, date_from='2017-09-01', date_to='2017-10-01', y_limits=(None, 25)) assert True
def test_TimeOfDay(): # Load data # load data as dataframe data = bw.load_csv(bw.datasets.demo_data) # Specify columns in data which contain the anemometer measurements from which to calculate shear anemometers = data[['Spd80mN', 'Spd60mN', 'Spd40mN']] # Specify the heights of these anemometers heights = [80, 60, 40] # Test initialisation shear_by_tod_power_law = bw.Shear.TimeOfDay(anemometers, heights) shear_by_tod_power_law = bw.Shear.TimeOfDay(anemometers, heights, by_month=False) shear_by_tod_log_law = bw.Shear.TimeOfDay(anemometers, heights, calc_method='log_law') shear_by_tod_log_law = bw.Shear.TimeOfDay(anemometers, heights, by_month=False, calc_method='log_law') # Test attributes shear_by_tod_power_law.alpha shear_by_tod_log_law.roughness # Test apply shear_by_tod_power_law.apply(data['Spd80mN'], 40, 60) shear_by_tod_log_law.apply(data['Spd80mN'], 40, 60) assert True
def test_BySector(): # load data as dataframe data = bw.load_csv(bw.datasets.demo_data) # Specify columns in data which contain the anemometer measurements from which to calculate shear anemometers = data[['Spd80mN', 'Spd60mN', 'Spd40mN']] # Specify the heights of these anemometers heights = [80, 60, 40] # Specify directions directions = data['Dir78mS'] # custom bins custom_bins = [0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330, 360] # Test initialisation shear_by_sector_power_law = bw.Shear.BySector(anemometers, heights, directions) shear_by_sector_log_law = bw.Shear.BySector(anemometers, heights, directions, calc_method='log_law') shear_by_sector_custom_bins = bw.Shear.BySector( anemometers, heights, directions, direction_bin_array=custom_bins) # test attributes shear_by_sector_power_law.plot shear_by_sector_power_law.alpha shear_by_sector_custom_bins.plot shear_by_sector_custom_bins.alpha # Test apply shear_by_sector_power_law.apply(data['Spd80mN'], directions, 40, 60) shear_by_sector_log_law.apply(data['Spd80mN'], directions, 40, 60) shear_by_sector_custom_bins.apply(data['Spd80mN'], directions, 40, 60) assert True
def test_basic_stats(): data = bw.load_csv(bw.datasets.shell_flats_80m_csv) bw.basic_stats(data) bs1 = bw.basic_stats(data[['WS70mA100NW_Avg']]) bs2 = bw.basic_stats(data['WS70mA100NW_Avg']) assert (bs2['count'] == 58874.0).bool() and((bs2['mean']-9.169382) < 1e-6).bool() and \ ((bs2['std']-4.932851) < 1e-6).bool() and (bs2['max'] == 27.66).bool() and (bs2['min'] == 0.0).bool()
def test_freq_distribution(): df = bw.load_csv(bw.datasets.demo_data) spd_dist = bw.freq_distribution(df.Spd80mN, max_speed=30, max_y_value=10, return_data=False) assert True
def test_dist_of_wind_speed(): df = bw.load_csv(bw.datasets.demo_data) spd_dist = bw.dist_of_wind_speed(df.Spd80mN, max_speed=30, max_y_value=10, return_data=False) assert True
def test_time_continuity_gaps(): import pandas as pd data = bw.load_csv(bw.datasets.shell_flats_80m_csv) gaps = bw.time_continuity_gaps(data['WS70mA100NW_Avg'][:400]) assert gaps.iloc[0, 0] == pd.Timestamp('2011-07-16 17:50:00') assert gaps.iloc[0, 1] == pd.Timestamp('2011-07-16 18:10:00') assert gaps.iloc[1, 0] == pd.Timestamp('2011-07-16 23:00:00') assert gaps.iloc[1, 1] == pd.Timestamp('2011-07-16 23:20:00') assert abs(gaps.iloc[0, 2] - 0.01388) < 1e-5 assert abs(gaps.iloc[1, 2] - 0.01388) < 1e-5
def test_scale(): # load data as dataframe data = bw.load_csv(bw.datasets.demo_data) # Specify columns in data which contain the anemometer measurements from which to calculate shear bw.Shear.scale(data['Spd40mN'], 40, 60, alpha=.2) bw.Shear.scale(data['Spd40mN'], 40, 60, calc_method='log_law', roughness=.03) assert True
def test_plot_scatter(): data = bw.load_csv(bw.datasets.demo_data) graph = bw.plot_scatter(data.Spd80mN, data.Spd80mS) graph = bw.plot_scatter(data.Spd80mN, data[['Spd80mS']]) bw.plot_scatter(data.Dir78mS, data.Dir58mS, x_axis_title='Dir78mS', y_axis_title='Dir58mS', x_limits=(50, 300), y_limits=(250, 300)) bw.plot_scatter_wdir(data.Dir78mS, data.Dir58mS, x_axis_title='Reference', y_axis_title='Target', x_limits=(50, 300), y_limits=(250, 300)) bw.plot_scatter_wspd(data.Spd80mN, data.Spd80mS, x_axis_title='Speed at 80m North', y_axis_title='Speed at 80m South', x_limits=(0, 25), y_limits=(0, 25)) assert True
def test_dist_12x24(): df = bw.load_csv(bw.datasets.demo_data) graph, table12x24 = bw.dist_12x24(df[['Spd40mN']], return_data=True) graph, table12x24 = bw.dist_12x24(df.Spd40mN, var_name_label='wind speed', return_data=True) graph = bw.dist_12x24(df.PrcpTot, aggregation_method='sum') def custom_agg(x): return x.mean() + (2 * x.std()) graph, table12x24 = bw.dist_12x24(df.PrcpTot, aggregation_method=custom_agg, return_data=True) assert True
def test_sector_ratio_by_sector(): data = bw.load_csv(bw.datasets.shell_flats_80m_csv) bw.SectorRatio.by_sector(data['WS70mA100NW_Avg'], data['WS70mA100SE_Avg'], data['WD50mW200PNW_VAvg'], sectors=72, boom_dir_1=315, boom_dir_2=135, return_data=True)[1] data = bw.load_campbell_scientific(bw.datasets.demo_site_data) bw.SectorRatio.by_sector(data.Spd40mN, data.Spd60mN, wdir=data.Dir38mS, direction_bin_array=[0, 45, 135, 180, 220, 360], boom_dir_1=160, boom_dir_2=340) assert True
def test_Average(): # Load data # load data as dataframe data = bw.load_csv(bw.datasets.demo_data) # Specify columns in data which contain the anemometer measurements from which to calculate shear anemometers = data[['Spd80mN', 'Spd60mN', 'Spd40mN']] # Specify the heights of these anemometers heights = [80, 60, 40] # Test initialisation shear_avg_power_law = bw.Shear.Average(anemometers, heights) shear_avg_log_law = bw.Shear.Average(anemometers, heights, calc_method='log_law') # Test attributes shear_avg_power_law.alpha shear_avg_log_law.roughness # Test apply shear_avg_power_law.apply(data['Spd80mN'], 40, 60) shear_avg_log_law.apply(data['Spd80mN'], 40, 60) assert True # Test specific values wspds = [7.74, 8.2, 8.57] heights = [60, 80, 100] specific_test = bw.Shear.Average(wspds, heights) assert round(specific_test.alpha, 9) == 0.199474297 wspds = [8, 8.365116] heights = [80, 100] specific_test = bw.Shear.Average(wspds, heights) assert round(specific_test.alpha, 1) == 0.2 specific_test_log = bw.Shear.Average(wspds, heights, calc_method='log_law') assert round(specific_test_log.roughness, 9) == 0.602156994