Beispiel #1
0
def test_histogram_data_stacked():

    # 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

    # Bin values to divide into colors
    # 315-45:  [10, 10, 10];         2 intervals
    # 45-135:  [85, 90, 90, 90, 95]; 3 intervals, [85. , 88.3, 91.7, 95. ]
    # 135-225: [170];                1 intervals
    # 225-315: [285, 288];           2 intervals, [285. , 286.5, 288. ]

    # interval_num: [2, 3, 1, 2]
    chk_histstack = [[(10 + 10) / 2., (10 + 10) / 2.],
                     [(85 + 88.3) / 2., (88.3 + 91.7) / 2., (91.7 + 95) / 2.],
                     [170.], [(285 + 286.5) / 2., (286.5 + 288) / 2.]]

    # Testing
    histstack = WindRose._histogram_data_stacked(w.histogram_data, 3)
    for chkh, h in zip(chk_histstack, histstack):
        for c, _h in zip(chkh, h):
            assert abs(c - _h) <= 1e-1
Beispiel #2
0
def test_radial_histogram():
    """ Test circular histogram"""
    # Testing vals
    dir_vals = [0, 0, 0, 10, 85, 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)

    # Testing
    bin_vecs = w.bin_vectors
    vec_cpt = (0, 0)
    radius_arr = (0., 1.)
    ytick_num = 1
    hist = w.histogram_data
    histstack = w._histogram_data_stacked(hist, ytick_num)
    show_stack = False
    vecs = WindRose._histogram_array_radial(bin_vecs, vec_cpt, hist, histstack,
                                            radius_arr, show_stack)
Beispiel #3
0
def test_radial_histogram():
    """ Test circular histogram"""
    # Testing vals ensure all histogram heights are equal.
    dir_vals = [
        3,
        3,
        10,  #  315 - 45
        85,
        90,
        95,  #  45 - 135
        170,
        170,
        170,  #  135 - 225
        230,
        285,
        288
    ]  #  225 - 315
    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)
    f = _deg2rad
    cos, sin = math.cos, math.sin

    # Testing
    bin_vecs = w.bin_vectors
    vec_cpt = (0, 0)
    radius_arr = (0., 1.)
    ytick_num = 1
    hist = w.histogram_data
    histstack = w._histogram_data_stacked(hist, ytick_num)
    show_stack = False
    vecs = WindRose._histogram_array_radial(bin_vecs, vec_cpt, hist, histstack,
                                            radius_arr, show_stack)

    # Make bins of equal height (unit circle)
    chk_bin_vecs = [
        [
            (cos(f(225)), -sin(f(225))),  # 0 west
            (cos(f(-45)), -sin(f(-45)))
        ],
        [
            (cos(f(-45)), -sin(f(-45))),  # 1 north
            (cos(f(45)), -sin(f(45)))
        ],
        [
            (cos(f(45)), -sin(f(45))),  # 2 east
            (cos(f(135)), -sin(f(135)))
        ],
        [
            (cos(f(135)), -sin(f(135))),  # 3 south
            (cos(f(225)), -sin(f(225)))
        ]
    ]

    for i in range(len(chk_bin_vecs)):
        vec2, vec1 = chk_bin_vecs[i][0], chk_bin_vecs[i][1]
        chk_pts = [vec1, vec2]
        pts = vecs[i][1:]  # Get rid of cpt (0, 0)

        for p, cp in zip(pts, chk_pts):
            assert abs(p[0] - cp[0]) < 1e-10, (p[0], cp[0])
            assert abs(p[1] - cp[1]) < 1e-10, (p[1], cp[1])