Example #1
0
def test_windrose_frequency_lines():
    """Test frequency Polygon2Ds"""

    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)

    # Without calmrose
    w.show_zeros = False
    w.show_freq = True
    _ = w.colored_mesh

    freqs = w.frequency_lines

    assert isinstance(freqs[0], Polygon2D)
    assert not freqs[0].vertices[0].is_equivalent(freqs[0].vertices[-1], 1e-10)

    # With calmrose
    w.show_zeros = True
    w.show_freq = True
    _ = w.colored_mesh

    freqs = w.frequency_lines

    assert isinstance(freqs[0], Polygon2D)
    assert not freqs[0].vertices[0].is_equivalent(freqs[0].vertices[-1], 1e-10)
Example #2
0
def test_windrose_mesh():
    # Plot windrose
    epw_path = os.path.join(os.getcwd(), 'tests/fixtures/epw/tokyo.epw')
    epw = EPW(epw_path)

    w = WindRose(epw.wind_direction, epw.wind_speed, 16)
    w.legend_parameters.segment_count = 3

    # Test the plot grid
    assert isinstance(w.frequency_lines[0], Polygon2D)
    assert isinstance(w.orientation_lines[0], LineSegment2D)

    # Test False, False
    w.show_zeros = False
    w.show_freq = False
    assert isinstance(w.colored_mesh, Mesh2D)

    # Test True, False
    w.show_zeros = True
    w.show_freq = False
    assert isinstance(w.colored_mesh, Mesh2D)

    # Test False, True
    w.show_zeros = False
    w.show_freq = True
    assert isinstance(w.colored_mesh, Mesh2D)

    # Test True, True
    w.show_zeros = True
    w.show_freq = True
    assert isinstance(w.colored_mesh, Mesh2D)
Example #3
0
def test_windrose_mesh_number_of_directions():
    # Test if mesh number of directions

    epw_path = os.path.join(os.getcwd(), 'tests/fixtures/epw/tokyo.epw')
    epw = EPW(epw_path)

    # Test 16 directions
    w = WindRose(epw.wind_direction, epw.wind_speed, 16)
    w.legend_parameters.segment_count = 3
    w.show_zeros = True
    w.show_freq = True

    assert len(w.histogram_data) == 16

    # Test error if number of directions < 0
    with pytest.raises(AssertionError):
        WindRose(epw.wind_direction, epw.wind_speed, 0)

    # Test error if number of directions < 3
    w = WindRose(epw.wind_direction, epw.wind_speed, 2)
    with pytest.raises(AssertionError):
        w.colored_mesh

    w = WindRose(epw.wind_direction, epw.wind_speed, 3)
    assert isinstance(w.colored_mesh, Mesh2D)
Example #4
0
def test_frequency_intervals():
    """Test the distance of frequency_intervals"""

    # Plot windrose
    epw_path = os.path.join(os.getcwd(), 'tests/fixtures/epw/tokyo.epw')
    epw = EPW(epw_path)

    w = WindRose(epw.wind_direction, epw.wind_speed, 3)
    w.show_zeros = False
    w.show_freq = False
    w.frequency_hours = 200.0

    test_freq_int = int(math.ceil(w.real_freq_max / 200.0))
    assert w.frequency_intervals_compass == pytest.approx(test_freq_int, abs=1e-10)
    assert w.frequency_intervals_mesh == pytest.approx(test_freq_int, abs=1e-10)

    # Test changing interals from 18
    # Reduce
    w.frequency_intervals_compass = 10.0
    test_freq_int = 10.0
    assert w.frequency_maximum == pytest.approx(10 * 200.0, abs=1e-10)
    assert w.frequency_intervals_compass == pytest.approx(test_freq_int, abs=1e-10)
    assert w.frequency_intervals_mesh == pytest.approx(test_freq_int, abs=1e-10)

    # Check that resetting frequency_max works
    w._frequency_intervals_compass = None
    # w.real_freq_max: 4406
    chk_max = int(math.ceil(4406 / 200)) * 200

    assert w.frequency_maximum == pytest.approx(chk_max, abs=1e-10)
    assert w.frequency_intervals_compass == pytest.approx(23, abs=1e-10)
    assert w.frequency_intervals_mesh == pytest.approx(23, abs=1e-10)
Example #5
0
def test_windrose_graphic_analysis_values():
    """Test visualization analysis values"""

    # Test w/ zeros
    epw_path = os.path.join(os.getcwd(), 'tests/fixtures/epw/tokyo.epw')
    epw = EPW(epw_path)

    # Test 16 directions
    w1 = WindRose(epw.wind_direction, epw.wind_speed, 16)
    w1.legend_parameters.segment_count = 3
    w1.show_zeros = True
    w1.show_freq = True
    _ = w1.colored_mesh
    assert min(w1.container.values) < 1e-10

    # Test 16 directions
    w2 = WindRose(epw.wind_direction, epw.wind_speed, 16)
    w2.legend_parameters.segment_count = 3
    w2.show_zeros = False
    w2.show_freq = False
    _ = w2.colored_mesh
    assert min(w2.container.values) > 1e-10
Example #6
0
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)
Example #7
0
def test_simple_windrose_mesh():
    # Testing vals
    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
    w.show_zeros = False
    w.show_freq = False
    mesh = w.colored_mesh
    assert isinstance(mesh, Mesh2D)

    # All true
    w = WindRose(dir_data, spd_data, 4)
    w.legend_parameters.segment_count = 10
    w.show_zeros = True
    w.show_freq = True
    mesh = w.colored_mesh
    assert isinstance(mesh, Mesh2D)

    # Init simple dir set divided by 8
    w = WindRose(dir_data, spd_data, 4)
    w.legend_parameters.segment_count = 3
    w.show_zeros = False
    w.show_freq = False
    mesh = w.colored_mesh
    assert isinstance(mesh, Mesh2D)
Example #8
0
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)
            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 = ''
        if isinstance(speed_data.header.data_type, Speed):
            windrose.show_zeros = _show_calmrose_
            calm_text = '\nCalm for {}% of the time = {} hours.'.format(
                round(
                    windrose._zero_count / len(windrose.analysis_values) *
                    100.0, 2), windrose._zero_count)
        windrose.base_point = Point2D(center_pt_2d.x, center_pt_2d.y)

        # Make the mesh
        mesh = from_mesh2d(windrose.colored_mesh, _center_pt_.z)

        # Make the graphic outputs
        legend = legend_objects(windrose.legend)
            else filt_wind_dir
        windrose = WindRose(win_dir, speed_data, _dir_count_)

        # set the wind rose properties
        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
        windrose.frequency_hours = _freq_hours_
        if _max_freq_lines_ is not None:
            windrose.frequency_intervals_compass = _max_freq_lines_
        windrose.frequency_spacing_distance = _freq_dist_
        windrose.north = north_
        windrose.show_freq = show_freq_

        calm_text = ''
        if isinstance(speed_data.header.data_type, Speed):
            windrose.show_zeros = show_calm_
            calm_text = '\nCalm for {}% of the time = {} hours.'.format(
                round(windrose._zero_count / 
                len(windrose.analysis_values) * 100.0, 2),
                windrose._zero_count)
        windrose.base_point = Point2D(center_pt_2d.x, center_pt_2d.y)

        # Make the mesh
        msh = from_mesh2d(windrose.colored_mesh, _center_pt_.z)

        # Make the other graphic outputs
        legend = legend_objects(windrose.legend)
Example #11
0
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
Example #12
0
def test_windrose_frequency_distribution():
    """Test frequency distribution"""

    # Testing mesh scaling
    dir_vals = [1, 2, 3, 4, 5, 6,
                90, 91, 92, 93, 94, 95,
                180, 181, 182, 183, 184, 185,
                270, 271, 272, 273, 274, 275]
    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.frequency_hours = 3
    assert w.frequency_intervals_mesh == 2
    assert w.real_freq_max == 6
    assert w.frequency_maximum == 6

    freqs = WindRose._histogram_data_nested(w.histogram_data, 3)
    north_hbin = freqs[0]

    assert north_hbin[0] == 2.0  # [1, 2, 3]
    assert north_hbin[1] == 5.0  # [4, 5, 6]
    assert north_hbin[0] == sum(w.histogram_data[0][:3]) / 3.0

    # Test w/ epw
    epw_path = os.path.join(os.getcwd(), 'tests/fixtures/epw/tokyo.epw')
    epw = EPW(epw_path)

    # Test 16 directions
    w = WindRose(epw.wind_direction, epw.wind_speed, 3)
    w.show_zeros = False
    w.show_freq = True

    # w.real_freq_max: 4406
    # w.frequency_maximum: 4600

    # Test w/ no stacking
    w.frequency_hours = 4600  # 1 bin
    ytick_num = w.frequency_intervals_mesh
    assert ytick_num == 1

    freqs = WindRose._histogram_data_nested(w.histogram_data, 4600)
    hbin = freqs[0]

    test_val = sum(w.histogram_data[0]) / len(w.histogram_data[0])
    assert hbin[0] == pytest.approx(test_val, abs=1e-10)

    # Test w/ stacking
    w.frequency_hours = 5  # 1 bin
    h = w.frequency_hours

    freqs = WindRose._histogram_data_nested(w.histogram_data, h)
    hbin = freqs[0]

    sort_hist_bar = sorted(w.histogram_data[0])
    test_val = sum(sort_hist_bar[:5]) / 5.0
    assert hbin[0] == pytest.approx(test_val, abs=1e-10)