Exemple #1
0
    def __init__(self, location, direct_normal_solar, diffuse_horizontal_solar,
                 longwave_mrt, fraction_body_exposed=None, sky_exposure=None,
                 floor_reflectance=None, window_transmittance=None,
                 solarcal_body_parameter=None):
        """Initialize Indoor SolarCal object.
        """
        # set up the object using radiation as a base
        self._radiation_check(direct_normal_solar, 'direct_normal_solar')
        self._radiation_check(diffuse_horizontal_solar, 'diffuse_horizontal_solar')
        self._input_collections = [direct_normal_solar, diffuse_horizontal_solar]
        self._calc_length = len(direct_normal_solar.values)
        self._base_collection = direct_normal_solar

        # check required inputs
        _SolarCalBase.__init__(self, location, fraction_body_exposed, floor_reflectance,
                               solarcal_body_parameter)
        self._dir_norm = direct_normal_solar.values
        self._diff_horiz = diffuse_horizontal_solar.values
        self._l_mrt = self._check_input(longwave_mrt, Temperature, 'C', 'longwave_mrt')

        # check optional inputs
        self._sky_exp = self._fraction_input_check(
            sky_exposure, 'sky_exposure', 1)
        self._win_trans = self._fraction_input_check(
            window_transmittance, 'window_transmittance', 0.4)

        # check that all input data collections are aligned.
        HourlyDiscontinuousCollection.are_collections_aligned(self._input_collections)

        # compute SolarCal
        self._calculate_solarcal()
Exemple #2
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 #3
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)
    def test_get_aligned_collection(self):
        """Test the method for getting an aligned discontinuous collection."""
        header = Header(Temperature(), 'C',
                        AnalysisPeriod(end_month=1, end_day=1))
        values = list(xrange(24))
        dc1 = HourlyDiscontinuousCollection(header, values,
                                            header.analysis_period.datetimes)
        dc2 = dc1.get_aligned_collection(50, RelativeHumidity(), '%')
        assert dc2.header.data_type.name == 'Relative Humidity'
        assert dc2.header.unit == '%'
        assert isinstance(dc2, HourlyDiscontinuousCollection)
        assert dc2.is_mutable is True

        dc3 = dc1.get_aligned_collection(50,
                                         RelativeHumidity(),
                                         '%',
                                         mutable=False)
        assert dc3.header.data_type.name == 'Relative Humidity'
        assert dc3.header.unit == '%'
        assert isinstance(dc3, HourlyDiscontinuousCollectionImmutable)
        assert dc3.is_mutable is False

        dc4 = dc1.get_aligned_collection(50,
                                         RelativeHumidity(),
                                         '%',
                                         mutable=True)
        assert dc4.header.data_type.name == 'Relative Humidity'
        assert dc4.header.unit == '%'
        assert isinstance(dc4, HourlyDiscontinuousCollection)
        assert dc4.is_mutable is True
Exemple #5
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 #6
0
    def __init__(self, location, direct_normal_solar, diffuse_horizontal_solar,
                 horizontal_infrared, surface_temperatures,
                 fraction_body_exposed=None, sky_exposure=None,
                 floor_reflectance=None, solarcal_body_parameter=None):
        """Initialize Outdoor SolarCal object.
        """
        # set up the object using radiation as a base
        self._radiation_check(direct_normal_solar, 'direct_normal_solar')
        self._radiation_check(diffuse_horizontal_solar, 'diffuse_horizontal_solar')
        self._input_collections = [direct_normal_solar, diffuse_horizontal_solar]
        self._calc_length = len(direct_normal_solar.values)
        self._base_collection = direct_normal_solar

        # check required inputs
        _SolarCalBase.__init__(self, location, fraction_body_exposed, floor_reflectance,
                               solarcal_body_parameter)
        self._dir_norm = direct_normal_solar.values
        self._diff_horiz = diffuse_horizontal_solar.values
        self._horiz_ir = self._check_input(
            horizontal_infrared, HorizontalInfraredRadiationIntensity, 'W/m2',
            'horizontal_infrared')
        self._srf_temp = self._check_input(
            surface_temperatures, Temperature, 'C', 'surface_temperatures')

        # check optional inputs
        self._sky_exp = self._fraction_input_check(sky_exposure, 'sky_exposure', 1)

        # check that all input data collections are aligned.
        HourlyDiscontinuousCollection.are_collections_aligned(self._input_collections)

        # compute SolarCal
        self._calculate_solarcal()
Exemple #7
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 #8
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 #9
0
def test_filter_by_pattern():
    """Test filter by pattern."""
    a_per = AnalysisPeriod(end_month=1, end_day=2)
    header1 = Header(Temperature(), 'C', a_per)
    values = list(xrange(48))
    dc1 = HourlyDiscontinuousCollection(header1, values, a_per.datetimes)

    dc2 = dc1.filter_by_pattern([True, False] * 24)
    assert len(dc2) == 24
Exemple #10
0
def test_dict_methods():
    """Test the to/from dict methods for discontinuous collections."""
    header = Header(Temperature(), 'C', AnalysisPeriod(end_month=1, end_day=1))
    values = list(xrange(24))
    dc = HourlyDiscontinuousCollection(header, values,
                                       header.analysis_period.datetimes)
    dc_dict = dc.to_dict()
    reconstruced_dc = HourlyDiscontinuousCollection.from_dict(dc_dict)
    assert dc_dict == reconstruced_dc.to_dict()
Exemple #11
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 #12
0
def test_group_by_day_discontinuous():
    """Test the group by day method for dicontinuous collections."""
    header = Header(Temperature(), 'C', AnalysisPeriod())
    values = list(xrange(8760))
    dc = HourlyDiscontinuousCollection(header, values,
                                       AnalysisPeriod().datetimes)
    day_dict = dc.group_by_day()
    assert list(day_dict.keys()) == list(xrange(1, 366))
    for val in day_dict.values():
        assert len(val) == 24
Exemple #13
0
def test_group_by_month_discontinuous():
    """Test the group by month method for dicontinuous collections."""
    header = Header(Temperature(), 'C', AnalysisPeriod())
    values = list(xrange(8760))
    dc = HourlyDiscontinuousCollection(header, values,
                                       AnalysisPeriod().datetimes)
    day_dict = dc.group_by_month()
    assert list(day_dict.keys()) == list(xrange(1, 13))
    days_per_month = AnalysisPeriod().NUMOFDAYSEACHMONTH
    for i, val in enumerate(day_dict.values()):
        assert len(val) == 24 * days_per_month[i]
Exemple #14
0
def test_filter_by_hoys():
    """Test filter_by_hoys method."""
    a_per = AnalysisPeriod(st_month=3, end_month=3)
    header = Header(Temperature(), 'C', a_per)
    values = list(xrange(24 * 31))
    dc = HourlyDiscontinuousCollection(header, values, a_per.datetimes)
    hoys = AnalysisPeriod(st_hour=9, end_hour=17).hoys
    filt_dc = dc.filter_by_hoys(hoys)
    assert len(filt_dc) == 31 * 9
    assert filt_dc.datetimes[0] == DateTime(3, 1, 9)
    assert filt_dc.datetimes[-1] == DateTime(3, 31, 17)
Exemple #15
0
def test_filter_by_conditional_statement():
    """Test filter by conditional statement."""
    a_per = AnalysisPeriod(end_month=1, end_day=2)
    header1 = Header(Temperature(), 'C', a_per)
    values = list(xrange(48))
    dc1 = HourlyDiscontinuousCollection(header1, values, a_per.datetimes)

    dc2 = dc1.filter_by_conditional_statement('a > 23')
    assert len(dc2) == 24
    for d in dc2.values:
        assert d > 23
Exemple #16
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
Exemple #17
0
def test_filter_by_analysis_period_hourly():
    """Test filtering by analysis period on hourly discontinuous collection."""
    header = Header(Temperature(), 'C', AnalysisPeriod())
    values = list(xrange(8760))
    dc = HourlyDiscontinuousCollection(header, values,
                                       header.analysis_period.datetimes)
    dc = dc.validate_analysis_period()
    a_per = AnalysisPeriod(st_month=3, end_month=3)
    filt_dc = dc.filter_by_analysis_period(a_per)
    assert len(filt_dc) == 31 * 24
    assert filt_dc.header.analysis_period == a_per
    assert filt_dc.datetimes[0] == DateTime(3, 1, 0)
    assert filt_dc.datetimes[-1] == DateTime(3, 31, 23)
Exemple #18
0
def test_duplicate():
    """Test the duplicate method on the discontinuous collections."""
    header = Header(Temperature(), 'C', AnalysisPeriod(end_month=1, end_day=1))
    values = list(xrange(24))
    dc1 = HourlyDiscontinuousCollection(header, values,
                                        header.analysis_period.datetimes)
    dc2 = dc1.duplicate()
    assert dc1.header.data_type.name == dc2.header.data_type.name
    assert dc1.header.unit == dc2.header.unit
    assert dc1.header.analysis_period == dc2.header.analysis_period
    assert dc1.header.metadata == dc2.header.metadata
    assert dc1.values == dc2.values
    assert dc1.datetimes == dc2.datetimes
Exemple #19
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 #20
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 #21
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 #22
0
def test_cull_to_timestep():
    """Test the test_cull_to_timestep method on the discontinuous collection."""
    a_per = AnalysisPeriod(6, 21, 0, 6, 21, 23)
    dt1, dt2, dt3 = DateTime(6, 21, 12), DateTime(6, 21,
                                                  13), DateTime(6, 21, 12, 30)
    v1, v2 = 20, 25
    dc1 = HourlyDiscontinuousCollection(Header(Temperature(), 'C', a_per),
                                        [v1, v2, v2], [dt1, dt3, dt2])
    dc1_new = dc1.validate_analysis_period()
    dc2_new = dc1.cull_to_timestep()
    assert dc1_new.header.analysis_period.timestep == 2
    assert dc2_new.header.analysis_period.timestep == 1
    assert len(dc1_new.values) == 3
    assert len(dc2_new.values) == 2

    dc1_new.convert_to_culled_timestep()
    assert dc1_new.header.analysis_period.timestep == 1
    assert len(dc1_new.values) == 2
Exemple #23
0
def test_get_aligned_collection():
    """Test the method for getting an aligned discontinuous collection."""
    header = Header(Temperature(), 'C', AnalysisPeriod(end_month=1, end_day=1))
    values = list(xrange(24))
    dc1 = HourlyDiscontinuousCollection(header, values,
                                        header.analysis_period.datetimes)
    dc2 = dc1.get_aligned_collection(50)
    assert dc1.header.data_type.name == dc2.header.data_type.name
    assert dc1.header.unit == dc2.header.unit
    assert dc1.header.analysis_period == dc2.header.analysis_period
    assert dc1.header.metadata == dc2.header.metadata
    assert dc1.datetimes == dc2.datetimes
    assert len(dc1.values) == len(dc2.values)
    assert dc2.values == tuple([50] * 24)

    dc3 = dc1.get_aligned_collection(50, RelativeHumidity(), '%')
    assert dc3.header.data_type.name == 'Relative Humidity'
    assert dc3.header.unit == '%'
Exemple #24
0
def build_collection(values, dates, data_type, unit, time_offset, year):
    """Build a data collection from raw noaa data and process it to the timestep.

    Args:
        values: A list of values to be included in the data collection.
        dates: A list of datetime strings that align with the values.
        data_type: Ladybug data type for the data collection.
        unit: Text for the unit of the collection.
        time_offset: Python timedelta object to correct for the time zone.
        year: Integer for the year of the data.
    """
    if values == []:
        return None

    # convert date codes into datetimes and ensure no duplicates
    leap_yr = True if year % 4 == 0 else False
    datetimes = []
    clean_values = []
    for i, (dat, val) in enumerate(zip(dates, values)):
        if dat != dates[i - 1]:
            yr, month, day, hr, minute = int(dat[:4]), int(dat[5:7]), \
                int(dat[8:10]), int(dat[11:13]), int(dat[14:16])
            py_dat = datetime.datetime(yr, month, day, hr, minute) + time_offset
            if py_dat.year == year:
                lb_dat = DateTime(py_dat.month, py_dat.day, py_dat.hour,
                                  py_dat.minute, leap_year=leap_yr)
                datetimes.append(lb_dat)
                clean_values.append(val)

    # make a discontinuous cata collection
    data_header = Header(data_type, unit, AnalysisPeriod(is_leap_year=leap_yr))
    data_init = HourlyDiscontinuousCollection(data_header, clean_values, datetimes)
    data_final = data_init.validate_analysis_period()

    # cull out unwanted timesteps.
    if _timestep_:
        data_final.convert_to_culled_timestep(_timestep_)
    else:
        data_final.convert_to_culled_timestep(1)

    return data_final
Exemple #25
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 #26
0
    def __init__(self,
                 location,
                 direct_horizontal_solar,
                 diffuse_horizontal_solar,
                 reflected_horizontal_solar,
                 longwave_mrt,
                 fraction_body_exposed=None,
                 solarcal_body_parameter=None):
        """Initialize Horizontal SolarCal object.
        """
        # set up the object using radiation as a base
        self._radiation_check(direct_horizontal_solar,
                              'direct_horizontal_solar')
        self._radiation_check(diffuse_horizontal_solar,
                              'diffuse_horizontal_solar')
        self._radiation_check(reflected_horizontal_solar,
                              'reflected_horizontal_solar')
        self._input_collections = [
            direct_horizontal_solar, diffuse_horizontal_solar,
            reflected_horizontal_solar
        ]
        self._calc_length = len(direct_horizontal_solar)
        self._base_collection = direct_horizontal_solar

        # check required inputs
        _SolarCalBase.__init__(self, location, fraction_body_exposed, None,
                               solarcal_body_parameter)
        self._dir_horiz = direct_horizontal_solar.values
        self._diff_horiz = diffuse_horizontal_solar.values
        self._ref_horiz = reflected_horizontal_solar.values
        self._l_mrt = self._check_input(longwave_mrt, Temperature, 'C',
                                        'longwave_mrt')

        # check that all input data collections are aligned.
        HourlyDiscontinuousCollection.are_collections_aligned(
            self._input_collections)

        # compute SolarCal
        self._calculate_solarcal()
Exemple #27
0
def test_setting_values():
    """Test the methods for setting values on the data collection"""
    header = Header(Temperature(), 'C', AnalysisPeriod())
    values = list(xrange(8760))
    dc = HourlyDiscontinuousCollection(header, values,
                                       header.analysis_period.datetimes)
    # test the contains and reversed methods
    assert 10 in dc
    assert list(reversed(dc)) == list(reversed(values))

    # test setting individual values
    assert dc[0] == 0
    dc[0] = 10
    assert dc[0] == 10

    # try setting the whole list of values
    val_rev = list(reversed(values))
    dc.values = val_rev
    assert dc[0] == 8759

    # make sure that people can't change the values without changing datetimes
    with pytest.raises(Exception):
        dc.values.append(10)
Exemple #28
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 #29
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 #30
0
def test_init_hourly():
    """Test the init methods for dicontinuous collections."""
    a_per = AnalysisPeriod(6, 21, 12, 6, 21, 13)
    dt1, dt2 = DateTime(6, 21, 12), DateTime(6, 21, 13)
    v1, v2 = 20, 25
    avg = (v1 + v2) / 2
    # Setup data collection
    dc1 = HourlyDiscontinuousCollection(Header(Temperature(), 'C', a_per),
                                        [v1, v2], [dt1, dt2])

    assert dc1.datetimes == (dt1, dt2)
    assert dc1.values == (v1, v2)
    assert dc1.average == avg
    assert dc1.is_continuous is False
    str(dc1)  # Test the string representation of the collection
    str(dc1.header)  # Test the string representation of the header