Exemple #1
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)
Exemple #2
0
    def data_collection(self, date=Date(1, 1), schedule_type_limit=None, timestep=1):
        """Get a ladybug DataCollection representing this schedule at a given timestep.

        Note that ladybug DataCollections always follow the "Ladybug Tools
        Interpretation" of date time values as noted in the values_at_timestep
        documentation.

        Args:
            date: A ladybug Date object for the day of the year the DataCollection
                is representing. (Default: 1 Jan)
            schedule_type_limit: A ScheduleTypeLimit object that describes the schedule,
                which will be used to make the header for the DataCollection. If None,
                a generic "Unknown" type will be used. (Default: None)
            timestep: An integer for the number of steps per hour at which to make
                the resulting DataCollection.
        """
        assert isinstance(date, Date), \
            'Expected ladybug Date. Got {}.'.format(type(date))
        if schedule_type_limit is not None:
            assert isinstance(schedule_type_limit, ScheduleTypeLimit), 'Expected ' \
                'Honeybee ScheduleTypeLimit. Got {}.'.format(type(schedule_type_limit))
            d_type = schedule_type_limit.data_type
            unit = schedule_type_limit.unit
        else:
            d_type = GenericType('Unknown Data Type', 'unknown')
            unit = 'unknown'
        a_period = AnalysisPeriod(date.month, date.day, 0, date.month, date.day, 23,
                                  timestep, date.leap_year)
        header = Header(d_type, unit, a_period, metadata={'schedule': self.identifier})
        return HourlyContinuousCollection(header, self.values_at_timestep(timestep))
Exemple #3
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
Exemple #4
0
def test_interpolate_holes():
    """Test the interoplate holes method on the discontinuous collection."""
    a_per = AnalysisPeriod(6, 21, 0, 6, 21, 23)
    dt1, dt2 = DateTime(6, 21, 12), DateTime(6, 21, 14)
    v1, v2 = 20, 25
    dc1 = HourlyDiscontinuousCollection(Header(Temperature(), 'C', a_per),
                                        [v1, v2], [dt1, dt2])
    with pytest.raises(Exception):
        interp_coll1 = dc1.interpolate_holes()
    dc2 = dc1.validate_analysis_period()
    interp_coll1 = dc2.interpolate_holes()
    assert isinstance(interp_coll1, HourlyContinuousCollection)
    assert len(interp_coll1.values) == 24
    assert interp_coll1[0] == 20
    assert interp_coll1[12] == 20
    assert interp_coll1[13] == 22.5
    assert interp_coll1[14] == 25
    assert interp_coll1[23] == 25

    values = list(xrange(24))
    test_header = Header(GenericType('Test Type', 'test'), 'test',
                         AnalysisPeriod(end_month=1, end_day=1))
    dc3 = HourlyContinuousCollection(test_header, values)
    interp_coll2 = dc3.interpolate_holes()
    assert isinstance(interp_coll2, HourlyContinuousCollection)
    assert len(interp_coll2.values) == 24
Exemple #5
0
def test_histogram_data_nested():

    # 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 example w segs == bin num
    w = WindRose(dir_data, spd_data, 4)
    #w.legend_parameters = LegendParameters(segment_count=5)
    w.frequency_hours = 1

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

    # interval_num: [2, 3, 1, 2]
    chk_histstack = [
        [10, 10, 10],
        [85, 90, 90, 90, 95],
        [170.],
        [285, 288]]

    # Testing
    histstack = WindRose._histogram_data_nested(w.histogram_data, 1)
    for chkh, h in zip(chk_histstack, histstack):
        for c, _h in zip(chkh, h):
            assert abs(c - _h) <= 1e-10

    # Init complex dir set divided by 4
    w = WindRose(dir_data, spd_data, 4)
    w.frequency_hours = 2

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

    # interval_num: [2, 3, 1, 2]
    chk_histstack = [
        [10, 10],
        [87.5, 90, 95.],
        [170.],
        [286.5]]

    # Testing
    histstack = WindRose._histogram_data_nested(w.histogram_data, 2)
    for chkh, h in zip(chk_histstack, histstack):
        for c, _h in zip(chkh, h):
            assert abs(c - _h) <= 1e-10
Exemple #6
0
def test_xticks_radial():
    """Test polar coordinate array"""

    # 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
    xticks = w.orientation_lines
    xticks = [xtick.scale(1 / w.compass_radius) for xtick in xticks]
    # w.angles - 90: [225, -45, 45, 135, 225]

    # Since frequencies are for xticks, no need to scale vectors.
    chk_xticks = [
        [(0, 0), (cos(f(225)), -sin(f(225)))],  # v0
        [(0, 0), (cos(f(-45)), -sin(f(-45)))],  # v1 bin 0
        [(0, 0), (cos(f(-45)), -sin(f(-45)))],  # v2
        [(0, 0), (cos(f(45)), -sin(f(45)))],  # v3 bin 1
        [(0, 0), (cos(f(45)), -sin(f(45)))],  # v4
        [(0, 0), (cos(f(135)), -sin(f(135)))],  # v5 bin 2
        [(0, 0), (cos(f(135)), -sin(f(135)))],  # v6
        [(0, 0), (cos(f(225)), -sin(f(225)))]
    ]  # v7 bin 3

    for i, (chk_xtick, xtick) in enumerate(zip(chk_xticks, xticks)):
        # Check x, y
        # print(chk_xtick[1][0], xtick.to_array()[1][0])
        # print(chk_xtick[1][1], xtick.to_array()[1][1])
        assert abs(chk_xtick[1][0] - xtick.to_array()[1][0]) < 1e-10
        assert abs(chk_xtick[1][1] - xtick.to_array()[1][1]) < 1e-10
Exemple #7
0
 def _get_lb_data_type_and_unit(self):
     """Get the ladybug data type and unit from the schedule_type_limit."""
     if self.schedule_type_limit is not None:
         data_type = self.schedule_type_limit.data_type
         unit = self.schedule_type_limit.unit
     else:
         unit = 'unknown'
         data_type = GenericType('Unknown Data Type', unit)
     return data_type, unit
Exemple #8
0
def test_radial_histogram_plot():
    """ 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.)
    hist = w.histogram_data

    speeds = [val for bin in w.histogram_data for val in bin]
    min_speed, max_speed = min(speeds), max(speeds)
    speed_interval = (max_speed - min_speed) / w.legend_parameters.segment_count
    histstack, _ = w._histogram_data_nested(
        hist, (min_speed, max_speed), speed_interval)

    show_freq = False
    vecs = WindRose._histogram_array_radial(bin_vecs, vec_cpt, hist, histstack,
                                            radius_arr, show_freq)

    # 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])
Exemple #9
0
def test_interpolate_to_timestep():
    """Test the interoplation method on the continuous collection."""
    values = list(xrange(24))
    test_header = Header(GenericType('Test Type', 'test'), 'test',
                         AnalysisPeriod(end_month=1, end_day=1))
    dc2 = HourlyContinuousCollection(test_header, values)

    # check the interpolate data functions
    interp_coll1 = dc2.interpolate_to_timestep(2)
    interp_coll2 = dc2.interpolate_to_timestep(2, True)
    assert interp_coll1[1] == 0.5
    assert interp_coll2[1] == 0.25
    assert 'Minute' in interp_coll1.timestep_text
Exemple #10
0
def test_bin_vectors():
    """Bin vectors"""

    # Testing vals
    dir_vals = [3, 3, 3, 10, 85, 90, 95, 170, 230, 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)
    f = _deg2rad
    cos, sin = math.cos, math.sin

    # Testing
    # Check angles
    a = w.angles
    chk_a = [315, 45, 135, 225, 315]
    for _a, _chk_a in zip(a, chk_a):
        assert abs(_a - _chk_a) < 1e-10, (_a, _chk_a)

    # Check vectors
    bin_vecs = w.bin_vectors
    a = [_deg2rad(_a) for _a in a]
    chk_bin_vecs = [[(cos(f(225)),  -sin(f(225))),   # 0
                     (cos(f(-45)),  -sin(f(-45)))],
                    [(cos(f(-45)),  -sin(f(-45))),   # 1
                     (cos(f(45)),   -sin(f(45)))],
                    [(cos(f(45)),   -sin(f(45))),    # 2
                     (cos(f(135)),  -sin(f(135)))],
                    [(cos(f(135)),  -sin(f(135))),   # 3
                     (cos(f(225)),  -sin(f(225)))]]

    # Check len
    assert len(bin_vecs) == len(chk_bin_vecs)

    # Check coords
    for i, (chk_vec, vec) in enumerate(zip(chk_bin_vecs, bin_vecs)):
        # left vec
        assert abs(chk_vec[0][0] - vec[0][0]) < 1e-5, (i, chk_vec[0][0], vec[0][0])
        assert abs(chk_vec[0][1] - vec[0][1]) < 1e-5, (i, chk_vec[0][1], vec[0][1])
        # right vec
        assert abs(chk_vec[1][0] - vec[1][0]) < 1e-5, (i, chk_vec[1][0], vec[1][0])
        assert abs(chk_vec[1][1] - vec[1][1]) < 1e-5, (i, chk_vec[1][1], vec[1][1])
Exemple #11
0
def test_xticks_radial():
    """Test polar coordinate array"""

    # 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)
Exemple #12
0
def test_bin_vectors():
    """Bin vectors"""

    # 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)
Exemple #13
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)
Exemple #14
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)
Exemple #15
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)
Exemple #16
0
    leap_year = True if dts[0].year % 4 == 0 else False
    a_period = AnalysisPeriod(dts[0].month,
                              dts[0].day,
                              0,
                              dts[-1].month,
                              dts[-1].day,
                              23,
                              timestep=timestep,
                              is_leap_year=leap_year)
    return a_period


# data types for the various outputs from OpenDSS
is_over = GenericType('Is Overloaded',
                      'condition',
                      unit_descr={
                          1: 'Overloaded',
                          0: 'Normal'
                      })
volt_cond = GenericType('Voltage Condition',
                        'condition',
                        unit_descr={
                            -1: 'Undervoltage',
                            0: 'Normal',
                            1: 'Overvoltage'
                        })

if all_required_inputs(ghenv.Component):
    factors, condition = [], []
    for result_file in _dss_csv:
        # parse the data and figure out the timeseries properties
        data = csv_to_matrix(result_file)
Exemple #17
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
Exemple #18
0
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
Exemple #19
0
            if slp_info[0] != '99999':
                slp.append(float(slp_info[0]) * 10)
                slp_dates.append(date_row)

            # parse the sky cover info if it exists
            if sc_col is not None and row[sc_col] != '':
                sc_info = row[sc_col].split(',')
                sc_oktas = int(sc_info[0])
                sc_tenths = sc_oktas * (10 / 8) if sc_oktas != 9 else 10
                sc.append(sc_tenths)
                sc_dates.append(date_row)

    # get the most predominant year in the file to make sure all data is for one year
    dom_yr = int(max(set(all_years), key=all_years.count))
    model_year = build_collection(
        all_years, all_dates, GenericType('Years', 'yr'), 'yr', t_offset, dom_yr)

    # build data collections from the imported values
    dry_bulb_temp = build_collection(
        db_t, db_t_dates, DryBulbTemperature(), 'C', t_offset, dom_yr)
    dew_point_temp = build_collection(
        dp_t, dp_t_dates, DewPointTemperature(), 'C', t_offset, dom_yr)
    wind_speed = build_collection(
        ws, ws_dates, WindSpeed(), 'm/s', t_offset, dom_yr)
    wind_direction = build_collection(
        wd, wd_dates, WindDirection(), 'degrees', t_offset, dom_yr)
    ceiling_height = build_collection(
        ceil, ceil_dates, CeilingHeight(), 'm', t_offset, dom_yr)
    visibility = build_collection(
        vis, vis_dates, Visibility(), 'km', t_offset, dom_yr)
    atmos_pressure = build_collection(
            of a Ladybug DataCollection.
"""

ghenv.Component.Name = "LB Construct Data Type"
ghenv.Component.NickName = 'ConstrType'
ghenv.Component.Message = '1.0.0'
ghenv.Component.Category = 'Ladybug'
ghenv.Component.SubCategory = '1 :: Analyze Data'
ghenv.Component.AdditionalHelpFromDocStrings = '1'

try:
    from ladybug.datatype.generic import GenericType
except ImportError as e:
    raise ImportError('\nFailed to import ladybug:\n\t{}'.format(e))

try:
    from ladybug_rhino.grasshopper import all_required_inputs
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))

if all_required_inputs(ghenv.Component):
    # process the categories_ if they are supplied
    unit_descr = None
    if categories_ != []:
        unit_descr = {}
        for prop in categories_:
            key, value = prop.split(':')
            unit_descr[int(key)] = value.strip()

    type = GenericType(_name, _unit, unit_descr=unit_descr)
Exemple #21
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)
ghenv.Component.Message = '1.5.1'
ghenv.Component.Category = 'Ladybug'
ghenv.Component.SubCategory = '1 :: Analyze Data'
ghenv.Component.AdditionalHelpFromDocStrings = '1'

try:
    from ladybug.datatype.generic import GenericType
except ImportError as e:
    raise ImportError('\nFailed to import ladybug:\n\t{}'.format(e))

try:
    from ladybug_rhino.grasshopper import all_required_inputs
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))


if all_required_inputs(ghenv.Component):
    # process the categories_ if they are supplied
    unit_descr = None
    if categories_ != []:
        unit_descr = {}
        for prop in categories_:
            key, value = prop.split(':')
            unit_descr[int(key)] = value.strip()

    if cumulative_:
        type = GenericType(_name, _unit, unit_descr=unit_descr,
                           point_in_time=False, cumulative=True)
    else:
        type = GenericType(_name, _unit, unit_descr=unit_descr)
Exemple #23
0
def test_prevailing_direction():
    """Test prevailing direction getter"""

    # Test with single prevailing dir
    dir_vals = [
        0,
        3,
        10,  # 315 - 45
        85,
        90,
        95,  # 45 - 135
        140,
        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)
    test_prev_dir = 180

    assert w.prevailing_direction[0] == test_prev_dir

    # Testing with two max prevailing values
    dir_vals = [
        3,
        3,
        10,  # 315 - 45
        85,
        90,
        90,
        100,  # 45 - 135
        170,
        170,
        170,
        180,  # 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)
    test_prev_dir = set((90, 180))

    assert set(w.prevailing_direction) == test_prev_dir

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

    # Test 5 directions
    w = WindRose(epw.wind_direction, epw.wind_speed, 5)
    assert w.prevailing_direction[0] == 216.0