def test_windrose_mesh_size(): # Testing mesh scaling dir_vals = [0, 0, 0, 10, 10, 10, 85, 90, 90, 90, 95, 170, 285, 288] spd_vals = dir_vals # Make into fake data collections a_per = AnalysisPeriod(6, 21, 12, 6, 21, 13) dates = [DateTime(6, 21, i) for i in range(len(dir_vals))] spd_header = Header(Speed(), 'm/s', a_per) dir_header = Header(GenericType('Direction', 'deg'), 'deg', a_per) spd_data = HourlyDiscontinuousCollection(spd_header, spd_vals, dates) dir_data = HourlyDiscontinuousCollection(dir_header, dir_vals, dates) # Init simple dir set divided by 4 w = WindRose(dir_data, spd_data, 4) w.legend_parameters.segment_count = 3 # Test the size of the windrose w = WindRose(dir_data, spd_data, 4) w.legend_parameters.segment_count = 3 w.show_zeros = False w.show_freq = True w.frequency_spacing_distance = 200.0 _ = w.colored_mesh hdist = w.frequency_spacing_hypot_distance intervals = w.real_freq_max / w.frequency_hours assert w.mesh_radius == pytest.approx(intervals * hdist, abs=1e-10) # Add calmrose w.show_zeros = True zero_dist = w._zero_mesh_radius _ = w.colored_mesh hdist = w.frequency_spacing_hypot_distance intervals = w.real_freq_max / w.frequency_hours assert w.mesh_radius == pytest.approx(zero_dist + (intervals * hdist)) # Test size with windrose from actual epw data epw_path = os.path.join(os.getcwd(), 'tests/fixtures/epw/chicago.epw') epw = EPW(epw_path) w = WindRose(epw.wind_direction, epw.wind_speed, 3)
all_legends = [] all_title = [] all_calm_hours = [] all_histograms = [] # Calculate _max_freq_lines_ if it's not already set, to use to # determine spacing for multiple plots. if len(_data) > 1 and _max_freq_lines_ is None: max_freqs = [] for i, _data_item in enumerate(_data): win_dir = _wind_direction w = WindRose(win_dir, _data_item, _dir_count_) if _freq_hours_ is not None: w.frequency_hours = _freq_hours_ if _freq_dist_ is not None: w.frequency_spacing_distance = _freq_dist_ max_freqs.append(w.frequency_intervals_compass) _max_freq_lines_ = max(max_freqs) # Plot the windroses for i, speed_data in enumerate(_data): # Make the windrose win_dir = _wind_direction windrose = WindRose(win_dir, speed_data, _dir_count_) if len(legend_par_) > 0: try: # sense when several legend parameters are connected lpar = legend_par_[i] except IndexError: lpar = legend_par_[-1]
def test_histogram_data_nested(): # Testing vals dir_vals = [0, 0, 0, 0, 10, 10, 10, 85, 90, 90, 90, 95, 170, 285, 310] spd_vals = [0, 0, 0, 0, 1, 145, 189, 15, 10, 150, 299, 259, 100, 5, 301] # Make into fake data collections a_per = AnalysisPeriod(6, 21, 12, 6, 21, 13) dates = [DateTime(6, 21, i) for i in range(len(dir_vals))] spd_header = Header(Speed(), 'm/s', a_per) dir_header = Header(GenericType('Direction', 'deg'), 'deg', a_per) spd_data = HourlyDiscontinuousCollection(spd_header, spd_vals, dates) dir_data = HourlyDiscontinuousCollection(dir_header, dir_vals, dates) # Init complex dir set divided by 4, and 2 hourly intervals w = WindRose(dir_data, spd_data, 4) w.frequency_hours = 2 w.legend_parameters.segment_count = 7 # Bin values to divide into 6 intervals = 10 - 310 = 300 / 6 = 50 m/s # intervals: [1-50, 51-100, 101-150, 151-200, 201-250, 251-300, 301-350] # # each frequency interval = 1/6 ~ 0.166 of total speed # 315-45: [1, 145, 189]; 3 bands [0-49, 100-149, 150-199] # 45-135: [15, 10, 150, 299, 259]; 3 bands, [0-49, 150-199,, 250-299] # 135-225: [100]; 1 bands, [100-149] # 225-315: [5, 300]; 2 bands, [0-49, 300, 249] # interval_num: [3, 3, 1, 2] chk_histstack = [ [[1], [], [145], [189], [], []], # 0-49, 100-149, 150-199 [[10, 15], [], [150], [], [], [259, 299]], # 0-49, 150-199,, 250-299 [[], [100], [], [], [], []], # 100-149 [[5], [], [], [], [], [301]]] # 0-49, 300-349 # Testing speeds = [val for bin in w.histogram_data for val in bin] min_speed, max_speed = min(speeds), max(speeds) histstack, bins = WindRose._histogram_data_nested( w.histogram_data, (min_speed, max_speed), w.legend_parameters.segment_count) # Check assert len(chk_histstack) == len(histstack) for cbins, bins in zip(chk_histstack, histstack): assert len(cbins) == len(bins) for cbin, bin in zip(cbins, bins): assert len(cbin) == len(bin) for cval, val in zip(cbin, bin): assert abs(cval - val) <= 1e-10, (cval, val) # Check with zeros w.show_zeros = True w.frequency_hours = 1.0 w.frequency_spacing_distance = 25.0 hypot_dist = w.frequency_spacing_hypot_distance assert abs(w._zero_mesh_radius - hypot_dist) < 1e-10 # Check with zeros 2 # Testing vals dir_vals = [0, 0, 0, 0, 0, 0, 10, 10, 10, 85, 90, 90, 90, 95, 170, 285, 310] spd_vals = [0, 0, 0, 0, 0, 0, 1, 145, 189, 15, 10, 150, 299, 259, 100, 5, 301] # Make into fake data collections a_per = AnalysisPeriod(6, 21, 12, 6, 21, 13) dates = [DateTime(6, 21, i) for i in range(len(dir_vals))] spd_header = Header(Speed(), 'm/s', a_per) dir_header = Header(GenericType('Direction', 'deg'), 'deg', a_per) spd_data = HourlyDiscontinuousCollection(spd_header, spd_vals, dates) dir_data = HourlyDiscontinuousCollection(dir_header, dir_vals, dates) # Init complex dir set divided by 4, and 2 hourly intervals w = WindRose(dir_data, spd_data, 4) w.show_zeros = True w.frequency_hours = 1.0 w.frequency_spacing_distance = 25.0 hypot_dist = w.frequency_spacing_hypot_distance * 1.5 assert abs(w._zero_mesh_radius - hypot_dist) < 1e-10