def test_windrose_set_legend_parameters(): """Test setting legend params property""" epw_path = os.path.join(os.getcwd(), 'tests/fixtures/epw/tokyo.epw') epw = EPW(epw_path) w = WindRose(epw.wind_direction, epw.wind_speed, 5) # Default assert w._legend_parameters is None assert isinstance(w.legend_parameters, LegendParameters) assert w.legend_parameters.segment_count == pytest.approx(11.0, abs=1e-10) # Check setting wrong input with pytest.raises(AssertionError): w.legend_parameters = 'string' # Check setting w.legend_parameters = LegendParameters(segment_count=16) assert w.legend_parameters.segment_count == pytest.approx(16, abs=1e-10) # Check resetting w.legend_parameters = None assert isinstance(w.legend_parameters, LegendParameters) assert w.legend_parameters.segment_count == pytest.approx(11.0, abs=1e-10)
def test_wind_polygons(): """Test colors for different windrose types.""" # 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, 300, 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) # 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] # # [[1], [], [145], [189], [], []], # 0-49, 100-149, 150-199 # [[10, 15], [], [150], [], [], [259, 300]], # 0-49, 150-199,, 250-299 # [[], [100], [], [], [], []], # 100-149 # [[5], [], [], [], [], [301]] # 0-49, 300-349 # Check freq=True, zeros=False w = WindRose(dir_data, spd_data, 4) w.show_freq, w.show_zeros = True, False w.frequency_hours = 2 w.legend_parameters = LegendParameters(segment_count=6) chk_poly_num = sum([3, 3, 1, 2]) assert chk_poly_num == len(w.windrose_lines) # For averaged w.show_freq = False chk_poly_num = 4 w.colored_mesh assert chk_poly_num == len(w.windrose_lines)
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] windrose.legend_parameters = lpar if _freq_hours_ is not None: windrose.frequency_hours = _freq_hours_ # Add and check optional visualization parameters if _max_freq_lines_ is not None: windrose.frequency_intervals_compass = _max_freq_lines_ if _freq_dist_ is not None: windrose.frequency_spacing_distance = _freq_dist_ windrose.north = north_ windrose.show_freq = _show_freq_ calm_text = ''
def test_color_array(): """Test colors for different windrose types.""" # 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, 300, 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) data_step = 50.0 min_val = 1 # 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] # # [[1], [], [145], [189], [], [], # 0-49, 100-149, 150-199 # [[10, 15], [], [150], [], [], [259, 300]], # 0-49, 150-199,, 250-299 # [[], [100], [], [], [], []], # 100-149 # [[5], [], [], [], [], [301]] # 0-49, 300-349 # Check freq=True, zeros=False w = WindRose(dir_data, spd_data, 4) w.show_freq, w.show_zeros = True, False w.frequency_hours = 2 w.legend_parameters = LegendParameters(segment_count=7) w.colored_mesh # color index corresponds to hourly interval indices # [1-50, 51-100, 101-150, 151-200, 201-250, 251-300, 301-350] chk_color_array = [0, 2, 3, 0, 2, 5, 1, 0, 5] chk_color_array = [(c * data_step) + min_val for c in chk_color_array] assert len(chk_color_array) == len(w._color_array) for cc, c in zip(chk_color_array, w._color_array): assert abs(cc - c) < 1e-10 # Check freq=True, zeros=True # Modify range for easier calcs 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, 149, 299, 259, 99, 5, 300] zero_spd_data = HourlyDiscontinuousCollection(spd_header, spd_vals, dates) zero_dir_data = HourlyDiscontinuousCollection(dir_header, dir_vals, dates) zero_data_step = 50 zero_min_val = 0 w = WindRose(zero_dir_data, zero_spd_data, 4) w.show_freq, w.show_zeros = True, True w.frequency_hours = 2 w.legend_parameters = LegendParameters(segment_count=7) w.colored_mesh # color index corresponds to hourly interval indices chk_color_array = [1, 3, 4, 1, 3, 6, 2, 1, 6] chk_color_array = [(c * zero_data_step) + zero_min_val for c in chk_color_array] chk_color_array += [0, 0, 0, 0] assert len(chk_color_array) == len(w._color_array) for cc, c in zip(chk_color_array, w._color_array): assert abs(cc - c) < 1e-10 # Check freq=False, zeros=False w = WindRose(dir_data, spd_data, 4) w.show_freq, w.show_zeros = False, False w.frequency_hours = 2 w.legend_parameters = LegendParameters(segment_count=7) w.colored_mesh # color index corresponds to hourly interval indices chk_color_array = [111 + 2/3, 146.8, 100, 153] assert len(chk_color_array) == len(w._color_array) for cc, c in zip(chk_color_array, w._color_array): assert abs(cc - c) < 1e-10 # Check freq=False, zeros=True w = WindRose(dir_data, spd_data, 4) w.show_freq, w.show_zeros = False, True w.frequency_hours = 2 w.legend_parameters = LegendParameters(segment_count=7) w.colored_mesh # color index corresponds to hourly interval indices chk_color_array = [111 + 2/3, 146.8, 100, 153] chk_color_array += [0, 0, 0, 0] assert len(chk_color_array) == len(w._color_array) for cc, c in zip(chk_color_array, w._color_array): assert abs(cc - c) < 1e-10